Print this page
patch zone-auto-create-be

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libbe/common/be_mount.c
          +++ new/usr/src/lib/libbe/common/be_mount.c
↓ open down ↓ 17 lines elided ↑ open up ↑
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  24   24   */
  25   25  /*
  26   26   * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
  27   27   * Copyright 2015 EveryCity Ltd.
       28 + * Copyright 2015 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
  28   29   */
  29   30  
  30   31  /*
  31   32   * System includes
  32   33   */
  33   34  #include <assert.h>
  34   35  #include <errno.h>
  35   36  #include <libgen.h>
  36   37  #include <libintl.h>
  37   38  #include <libnvpair.h>
↓ open down ↓ 2297 lines elided ↑ open up ↑
2335 2336   *              md - be_mount_data_t pointer to data for global BE.
2336 2337   * Returns:
2337 2338   *              BE_SUCCESS - Success
2338 2339   *              be_errno_t - Failure
2339 2340   * Scope:
2340 2341   *              Private
2341 2342   */
2342 2343  static int
2343 2344  be_mount_zones(zfs_handle_t *be_zhp, be_mount_data_t *md)
2344 2345  {
2345      -        zoneBrandList_t *brands = NULL;
2346 2346          zoneList_t      zlst = NULL;
2347 2347          char            *zonename = NULL;
2348 2348          char            *zonepath = NULL;
2349 2349          char            *zonepath_ds = NULL;
2350 2350          int             k;
2351 2351          int             ret = BE_SUCCESS;
     2352 +        boolean_t       auto_create;
2352 2353  
2353 2354          z_set_zone_root(md->altroot);
2354 2355  
2355      -        if ((brands = be_get_supported_brandlist()) == NULL) {
2356      -                be_print_err(gettext("be_mount_zones: "
2357      -                    "no supported brands\n"));
     2356 +        zlst = z_get_nonglobal_branded_zone_list();
     2357 +        if (zlst == NULL)
2358 2358                  return (BE_SUCCESS);
2359      -        }
2360      -
2361      -        zlst = z_get_nonglobal_zone_list_by_brand(brands);
2362      -        if (zlst == NULL) {
2363      -                z_free_brand_list(brands);
2364      -                return (BE_SUCCESS);
2365      -        }
2366 2359  
2367 2360          for (k = 0; (zonename = z_zlist_get_zonename(zlst, k)) != NULL; k++) {
     2361 +                if (z_zlist_is_zone_auto_create_be(zlst, k, &auto_create) != 0) {
     2362 +                        be_print_err(gettext("be_mount_zones: failed to"
     2363 +                            " get auto-create-be brand property\n"));
     2364 +                        goto done;
     2365 +                }
     2366 +
     2367 +                if (!auto_create)
     2368 +                        continue;
     2369 +
2368 2370                  if (z_zlist_get_current_state(zlst, k) ==
2369 2371                      ZONE_STATE_INSTALLED) {
2370 2372                          zonepath = z_zlist_get_zonepath(zlst, k);
2371 2373  
2372 2374                          /*
2373 2375                           * Get the dataset of this zonepath in current BE.
2374 2376                           * If its not a dataset, skip it.
2375 2377                           */
2376 2378                          if ((zonepath_ds = be_get_ds_from_dir(zonepath))
2377 2379                              == NULL)
↓ open down ↓ 32 lines elided ↑ open up ↑
2410 2412                          if (ret != BE_SUCCESS) {
2411 2413                                  be_print_err(gettext("be_mount_zones: "
2412 2414                                      "failed to mount zone %s under "
2413 2415                                      "altroot %s\n"), zonename, md->altroot);
2414 2416                                  goto done;
2415 2417                          }
2416 2418                  }
2417 2419          }
2418 2420  
2419 2421  done:
2420      -        z_free_brand_list(brands);
2421 2422          z_free_zone_list(zlst);
2422 2423          /*
2423 2424           * libinstzones caches mnttab and uses cached version for resolving lofs
2424 2425           * mounts when we call z_resolve_lofs. It creates the cached version
2425 2426           * when the first call to z_resolve_lofs happens. So, library's cached
2426 2427           * mnttab doesn't contain entries for lofs mounts created in the above
2427 2428           * loop. Because of this, subsequent calls to z_resolve_lofs would fail
2428 2429           * to resolve these lofs mounts. So, here we destroy library's cached
2429 2430           * mnttab to force its recreation when the next call to z_resolve_lofs
2430 2431           * happens.
↓ open down ↓ 10 lines elided ↑ open up ↑
2441 2442   *              ud - unmount_data_t pointer data for the global BE.
2442 2443   * Returns:
2443 2444   *              BE_SUCCESS - Success
2444 2445   *              be_errno_t - Failure
2445 2446   * Scope:
2446 2447   *              Private
2447 2448   */
2448 2449  static int
2449 2450  be_unmount_zones(be_unmount_data_t *ud)
2450 2451  {
2451      -        zoneBrandList_t         *brands = NULL;
2452 2452          zoneList_t              zlst = NULL;
2453 2453          char                    *zonename = NULL;
2454 2454          char                    *zonepath = NULL;
2455 2455          char                    alt_zonepath[MAXPATHLEN];
2456 2456          char                    *zonepath_ds = NULL;
2457 2457          int                     k;
2458 2458          int                     ret = BE_SUCCESS;
     2459 +        boolean_t               auto_create;
2459 2460  
2460 2461          z_set_zone_root(ud->altroot);
2461 2462  
2462      -        if ((brands = be_get_supported_brandlist()) == NULL) {
2463      -                be_print_err(gettext("be_unmount_zones: "
2464      -                    "no supported brands\n"));
     2463 +        zlst = z_get_nonglobal_branded_zone_list();
     2464 +        if (zlst == NULL)
2465 2465                  return (BE_SUCCESS);
2466      -        }
2467      -
2468      -        zlst = z_get_nonglobal_zone_list_by_brand(brands);
2469      -        if (zlst == NULL) {
2470      -                z_free_brand_list(brands);
2471      -                return (BE_SUCCESS);
2472      -        }
2473 2466  
2474 2467          for (k = 0; (zonename = z_zlist_get_zonename(zlst, k)) != NULL; k++) {
     2468 +                if (z_zlist_is_zone_auto_create_be(zlst, k, &auto_create) != 0) {
     2469 +                        be_print_err(gettext("be_unmount_zones: failed to"
     2470 +                            " get auto-create-be brand property\n"));
     2471 +                        goto done;
     2472 +                }
     2473 +
     2474 +                if (!auto_create)
     2475 +                        continue;
     2476 +
2475 2477                  if (z_zlist_get_current_state(zlst, k) ==
2476 2478                      ZONE_STATE_INSTALLED) {
2477 2479                          zonepath = z_zlist_get_zonepath(zlst, k);
2478 2480  
2479 2481                          /* Build zone's zonepath wrt the global BE altroot */
2480 2482                          (void) snprintf(alt_zonepath, sizeof (alt_zonepath),
2481 2483                              "%s%s", ud->altroot, zonepath);
2482 2484  
2483 2485                          /*
2484 2486                           * Get the dataset of this zonepath.  If its not
↓ open down ↓ 23 lines elided ↑ open up ↑
2508 2510                          if (ret != BE_SUCCESS) {
2509 2511                                  be_print_err(gettext("be_unmount_zones:"
2510 2512                                      " failed to unmount zone %s from "
2511 2513                                      "altroot %s\n"), zonename, ud->altroot);
2512 2514                                  goto done;
2513 2515                          }
2514 2516                  }
2515 2517          }
2516 2518  
2517 2519  done:
2518      -        z_free_brand_list(brands);
2519 2520          z_free_zone_list(zlst);
2520 2521          return (ret);
2521 2522  }
2522 2523  
2523 2524  /*
2524 2525   * Function:    be_mount_one_zone
2525 2526   * Description: This function is called to mount one zone for a given
2526 2527   *              global BE.
2527 2528   * Parameters:
2528 2529   *              be_zhp - zfs_handle_t pointer to the root dataset of the
↓ open down ↓ 202 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX