Changeset View
Changeset View
Standalone View
Standalone View
head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa_config.c
Show First 20 Lines • Show All 220 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
void | void | ||||
spa_write_cachefile(spa_t *target, boolean_t removing, boolean_t postsysevent) | spa_write_cachefile(spa_t *target, boolean_t removing, boolean_t postsysevent) | ||||
{ | { | ||||
spa_config_dirent_t *dp, *tdp; | spa_config_dirent_t *dp, *tdp; | ||||
nvlist_t *nvl; | nvlist_t *nvl; | ||||
boolean_t ccw_failure; | boolean_t ccw_failure; | ||||
int error; | int error; | ||||
char *pool_name; | |||||
ASSERT(MUTEX_HELD(&spa_namespace_lock)); | ASSERT(MUTEX_HELD(&spa_namespace_lock)); | ||||
if (rootdir == NULL || !(spa_mode_global & FWRITE)) | if (rootdir == NULL || !(spa_mode_global & FWRITE)) | ||||
return; | return; | ||||
/* | /* | ||||
* Iterate over all cachefiles for the pool, past or present. When the | * Iterate over all cachefiles for the pool, past or present. When the | ||||
Show All 32 Lines | while ((spa = spa_next(spa)) != NULL) { | ||||
strcmp(tdp->scd_path, dp->scd_path) != 0) { | strcmp(tdp->scd_path, dp->scd_path) != 0) { | ||||
mutex_exit(&spa->spa_props_lock); | mutex_exit(&spa->spa_props_lock); | ||||
continue; | continue; | ||||
} | } | ||||
if (nvl == NULL) | if (nvl == NULL) | ||||
nvl = fnvlist_alloc(); | nvl = fnvlist_alloc(); | ||||
fnvlist_add_nvlist(nvl, spa->spa_name, | if (spa->spa_import_flags & ZFS_IMPORT_TEMP_NAME) { | ||||
pool_name = fnvlist_lookup_string(spa->spa_config, | |||||
ZPOOL_CONFIG_POOL_NAME); | |||||
} else { | |||||
pool_name = spa_name(spa); | |||||
} | |||||
fnvlist_add_nvlist(nvl, pool_name, | |||||
spa->spa_config); | spa->spa_config); | ||||
mutex_exit(&spa->spa_props_lock); | mutex_exit(&spa->spa_props_lock); | ||||
if (nvlist_lookup_nvlist(nvl, spa->spa_name, &nvroot) == 0) | if (nvlist_lookup_nvlist(nvl, pool_name, &nvroot) == 0) | ||||
spa_config_clean(nvroot); | spa_config_clean(nvroot); | ||||
} | } | ||||
error = spa_config_write(dp, nvl); | error = spa_config_write(dp, nvl); | ||||
if (error != 0) | if (error != 0) | ||||
ccw_failure = B_TRUE; | ccw_failure = B_TRUE; | ||||
nvlist_free(nvl); | nvlist_free(nvl); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | |||||
nvlist_t * | nvlist_t * | ||||
spa_config_generate(spa_t *spa, vdev_t *vd, uint64_t txg, int getstats) | spa_config_generate(spa_t *spa, vdev_t *vd, uint64_t txg, int getstats) | ||||
{ | { | ||||
nvlist_t *config, *nvroot; | nvlist_t *config, *nvroot; | ||||
vdev_t *rvd = spa->spa_root_vdev; | vdev_t *rvd = spa->spa_root_vdev; | ||||
unsigned long hostid = 0; | unsigned long hostid = 0; | ||||
boolean_t locked = B_FALSE; | boolean_t locked = B_FALSE; | ||||
uint64_t split_guid; | uint64_t split_guid; | ||||
char *pool_name; | |||||
if (vd == NULL) { | if (vd == NULL) { | ||||
vd = rvd; | vd = rvd; | ||||
locked = B_TRUE; | locked = B_TRUE; | ||||
spa_config_enter(spa, SCL_CONFIG | SCL_STATE, FTAG, RW_READER); | spa_config_enter(spa, SCL_CONFIG | SCL_STATE, FTAG, RW_READER); | ||||
} | } | ||||
ASSERT(spa_config_held(spa, SCL_CONFIG | SCL_STATE, RW_READER) == | ASSERT(spa_config_held(spa, SCL_CONFIG | SCL_STATE, RW_READER) == | ||||
(SCL_CONFIG | SCL_STATE)); | (SCL_CONFIG | SCL_STATE)); | ||||
/* | /* | ||||
* If txg is -1, report the current value of spa->spa_config_txg. | * If txg is -1, report the current value of spa->spa_config_txg. | ||||
*/ | */ | ||||
if (txg == -1ULL) | if (txg == -1ULL) | ||||
txg = spa->spa_config_txg; | txg = spa->spa_config_txg; | ||||
/* | |||||
* Originally, users had to handle spa namespace collisions by either | |||||
* exporting the already imported pool or by specifying a new name for | |||||
* the pool with a conflicting name. In the case of root pools from | |||||
* virtual guests, neither approach to collision resolution is | |||||
* reasonable. This is addressed by extending the new name syntax with | |||||
* an option to specify that the new name is temporary. When specified, | |||||
* ZFS_IMPORT_TEMP_NAME will be set in spa->spa_import_flags to tell us | |||||
* to use the previous name, which we do below. | |||||
*/ | |||||
if (spa->spa_import_flags & ZFS_IMPORT_TEMP_NAME) { | |||||
pool_name = fnvlist_lookup_string(spa->spa_config, | |||||
ZPOOL_CONFIG_POOL_NAME); | |||||
} else { | |||||
pool_name = spa_name(spa); | |||||
} | |||||
config = fnvlist_alloc(); | config = fnvlist_alloc(); | ||||
fnvlist_add_uint64(config, ZPOOL_CONFIG_VERSION, spa_version(spa)); | fnvlist_add_uint64(config, ZPOOL_CONFIG_VERSION, spa_version(spa)); | ||||
fnvlist_add_string(config, ZPOOL_CONFIG_POOL_NAME, spa_name(spa)); | fnvlist_add_string(config, ZPOOL_CONFIG_POOL_NAME, pool_name); | ||||
fnvlist_add_uint64(config, ZPOOL_CONFIG_POOL_STATE, spa_state(spa)); | fnvlist_add_uint64(config, ZPOOL_CONFIG_POOL_STATE, spa_state(spa)); | ||||
fnvlist_add_uint64(config, ZPOOL_CONFIG_POOL_TXG, txg); | fnvlist_add_uint64(config, ZPOOL_CONFIG_POOL_TXG, txg); | ||||
fnvlist_add_uint64(config, ZPOOL_CONFIG_POOL_GUID, spa_guid(spa)); | fnvlist_add_uint64(config, ZPOOL_CONFIG_POOL_GUID, spa_guid(spa)); | ||||
if (spa->spa_comment != NULL) { | if (spa->spa_comment != NULL) { | ||||
fnvlist_add_string(config, ZPOOL_CONFIG_COMMENT, | fnvlist_add_string(config, ZPOOL_CONFIG_COMMENT, | ||||
spa->spa_comment); | spa->spa_comment); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 145 Lines • Show Last 20 Lines |