Print this page
5882 Temporary pool names
Reviewed by: Matt Ahrens <matt@delphix.com>
Reviewed by: Igor Kozhukhov <igor@dilos.org>
Reviewed by: John Kennedy <john.kennedy@delphix.com>
Approved by: Dan McDonald <danmcd@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/fs/zfs/spa_config.c
          +++ new/usr/src/uts/common/fs/zfs/spa_config.c
↓ open down ↓ 200 lines elided ↑ open up ↑
 201  201   * contain the correct information to open the pool and an explicit import
 202  202   * would be required.
 203  203   */
 204  204  void
 205  205  spa_write_cachefile(spa_t *target, boolean_t removing, boolean_t postsysevent)
 206  206  {
 207  207          spa_config_dirent_t *dp, *tdp;
 208  208          nvlist_t *nvl;
 209  209          boolean_t ccw_failure;
 210  210          int error;
      211 +        char *pool_name;
 211  212  
 212  213          ASSERT(MUTEX_HELD(&spa_namespace_lock));
 213  214  
 214  215          if (rootdir == NULL || !(spa_mode_global & FWRITE))
 215  216                  return;
 216  217  
 217  218          /*
 218  219           * Iterate over all cachefiles for the pool, past or present.  When the
 219  220           * cachefile is changed, the new one is pushed onto this list, allowing
 220  221           * us to update previous cachefiles that no longer contain this pool.
↓ open down ↓ 26 lines elided ↑ open up ↑
 247  248                          if (spa->spa_config == NULL ||
 248  249                              tdp->scd_path == NULL ||
 249  250                              strcmp(tdp->scd_path, dp->scd_path) != 0) {
 250  251                                  mutex_exit(&spa->spa_props_lock);
 251  252                                  continue;
 252  253                          }
 253  254  
 254  255                          if (nvl == NULL)
 255  256                                  nvl = fnvlist_alloc();
 256  257  
 257      -                        fnvlist_add_nvlist(nvl, spa->spa_name,
      258 +                        if (spa->spa_import_flags & ZFS_IMPORT_TEMP_NAME) {
      259 +                                pool_name = fnvlist_lookup_string(
      260 +                                    spa->spa_config, ZPOOL_CONFIG_POOL_NAME);
      261 +                        } else {
      262 +                                pool_name = spa_name(spa);
      263 +                        }
      264 +
      265 +                        fnvlist_add_nvlist(nvl, pool_name,
 258  266                              spa->spa_config);
 259  267                          mutex_exit(&spa->spa_props_lock);
 260  268                  }
 261  269  
 262  270                  error = spa_config_write(dp, nvl);
 263  271                  if (error != 0)
 264  272                          ccw_failure = B_TRUE;
 265  273                  nvlist_free(nvl);
 266  274          }
 267  275  
↓ open down ↓ 84 lines elided ↑ open up ↑
 352  360   * based on whether vd is the root vdev.
 353  361   */
 354  362  nvlist_t *
 355  363  spa_config_generate(spa_t *spa, vdev_t *vd, uint64_t txg, int getstats)
 356  364  {
 357  365          nvlist_t *config, *nvroot;
 358  366          vdev_t *rvd = spa->spa_root_vdev;
 359  367          unsigned long hostid = 0;
 360  368          boolean_t locked = B_FALSE;
 361  369          uint64_t split_guid;
      370 +        char *pool_name;
 362  371  
 363  372          if (vd == NULL) {
 364  373                  vd = rvd;
 365  374                  locked = B_TRUE;
 366  375                  spa_config_enter(spa, SCL_CONFIG | SCL_STATE, FTAG, RW_READER);
 367  376          }
 368  377  
 369  378          ASSERT(spa_config_held(spa, SCL_CONFIG | SCL_STATE, RW_READER) ==
 370  379              (SCL_CONFIG | SCL_STATE));
 371  380  
 372  381          /*
 373  382           * If txg is -1, report the current value of spa->spa_config_txg.
 374  383           */
 375  384          if (txg == -1ULL)
 376  385                  txg = spa->spa_config_txg;
 377  386  
      387 +        /*
      388 +         * Originally, users had to handle spa namespace collisions by either
      389 +         * exporting the already imported pool or by specifying a new name for
      390 +         * the pool with a conflicting name. In the case of root pools from
      391 +         * virtual guests, neither approach to collision resolution is
      392 +         * reasonable. This is addressed by extending the new name syntax with
      393 +         * an option to specify that the new name is temporary. When specified,
      394 +         * ZFS_IMPORT_TEMP_NAME will be set in spa->spa_import_flags to tell us
      395 +         * to use the previous name, which we do below.
      396 +         */
      397 +        if (spa->spa_import_flags & ZFS_IMPORT_TEMP_NAME) {
      398 +                pool_name = fnvlist_lookup_string(spa->spa_config,
      399 +                    ZPOOL_CONFIG_POOL_NAME);
      400 +        } else {
      401 +                pool_name = spa_name(spa);
      402 +        }
      403 +
 378  404          config = fnvlist_alloc();
 379  405  
 380  406          fnvlist_add_uint64(config, ZPOOL_CONFIG_VERSION, spa_version(spa));
 381      -        fnvlist_add_string(config, ZPOOL_CONFIG_POOL_NAME, spa_name(spa));
      407 +        fnvlist_add_string(config, ZPOOL_CONFIG_POOL_NAME, pool_name);
 382  408          fnvlist_add_uint64(config, ZPOOL_CONFIG_POOL_STATE, spa_state(spa));
 383  409          fnvlist_add_uint64(config, ZPOOL_CONFIG_POOL_TXG, txg);
 384  410          fnvlist_add_uint64(config, ZPOOL_CONFIG_POOL_GUID, spa_guid(spa));
 385  411          if (spa->spa_comment != NULL) {
 386  412                  fnvlist_add_string(config, ZPOOL_CONFIG_COMMENT,
 387  413                      spa->spa_comment);
 388  414          }
 389  415  
 390  416          hostid = zone_get_hostid(NULL);
 391  417  
↓ open down ↓ 156 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX