Print this page
*** NO COMMENTS ***

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libbe/common/be_utils.c
          +++ new/usr/src/lib/libbe/common/be_utils.c
↓ open down ↓ 16 lines elided ↑ open up ↑
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  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  /*
  27      - * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
       27 + * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
  28   28   */
  29   29  
  30   30  
  31   31  /*
  32   32   * System includes
  33   33   */
  34   34  #include <assert.h>
  35   35  #include <errno.h>
  36   36  #include <libgen.h>
  37   37  #include <libintl.h>
↓ open down ↓ 8 lines elided ↑ open up ↑
  46   46  #include <sys/vfstab.h>
  47   47  #include <sys/param.h>
  48   48  #include <sys/systeminfo.h>
  49   49  #include <ctype.h>
  50   50  #include <time.h>
  51   51  #include <unistd.h>
  52   52  #include <fcntl.h>
  53   53  #include <deflt.h>
  54   54  #include <wait.h>
  55   55  #include <libdevinfo.h>
       56 +#include <libgen.h>
  56   57  
  57   58  #include <libbe.h>
  58   59  #include <libbe_priv.h>
  59   60  
  60   61  /* Private function prototypes */
  61   62  static int update_dataset(char *, int, char *, char *, char *);
  62   63  static int _update_vfstab(char *, char *, char *, char *, be_fs_list_data_t *);
  63   64  static int be_open_menu(char *, char *, FILE **, char *, boolean_t);
  64   65  static int be_create_menu(char *, char *, FILE **, char *);
  65   66  static char *be_get_auto_name(char *, char *, boolean_t);
↓ open down ↓ 157 lines elided ↑ open up ↑
 223  224   *              None
 224  225   * Scope:
 225  226   *              Semi-private (library wide use only)
 226  227   */
 227  228  void
 228  229  be_make_root_ds(const char *zpool, const char *be_name, char *be_root_ds,
 229  230      int be_root_ds_size)
 230  231  {
 231  232          struct be_defaults be_defaults;
 232  233          be_get_defaults(&be_defaults);
      234 +        char    *root_ds = NULL;
 233  235  
 234      -        if (be_defaults.be_deflt_rpool_container)
 235      -                (void) snprintf(be_root_ds, be_root_ds_size, "%s/%s", zpool,
 236      -                    be_name);
 237      -        else
 238      -                (void) snprintf(be_root_ds, be_root_ds_size, "%s/%s/%s", zpool,
 239      -                    BE_CONTAINER_DS_NAME, be_name);
      236 +        if (getzoneid() == GLOBAL_ZONEID) {
      237 +                if (be_defaults.be_deflt_rpool_container) {
      238 +                        (void) snprintf(be_root_ds, be_root_ds_size,
      239 +                            "%s/%s", zpool, be_name);
      240 +                } else {
      241 +                        (void) snprintf(be_root_ds, be_root_ds_size,
      242 +                            "%s/%s/%s", zpool, BE_CONTAINER_DS_NAME, be_name);
      243 +                }
      244 +        } else {
      245 +                /*
      246 +                 * In non-global zone we can use path from mounted root dataset
      247 +                 * to generate BE's root dataset string.
      248 +                 */
      249 +                if ((root_ds = be_get_ds_from_dir("/")) != NULL) {
      250 +                        (void) snprintf(be_root_ds, be_root_ds_size, "%s/%s",
      251 +                            dirname(root_ds), be_name);
      252 +                } else {
      253 +                        be_print_err(gettext("be_make_root_ds: zone root "
      254 +                            "dataset is not mounted\n"));
      255 +                        return;
      256 +                }
      257 +        }
 240  258  }
 241  259  
 242  260  /*
 243  261   * Function:    be_make_container_ds
 244  262   * Description: Generate string for the BE container dataset given a pool name.
 245  263   * Parameters:
 246  264   *              zpool - pointer zpool name.
 247  265   *              container_ds - pointer to buffer to return BE container
 248  266   *                      dataset in.
 249  267   *              container_ds_size - size of container_ds
↓ open down ↓ 1 lines elided ↑ open up ↑
 251  269   *              None
 252  270   * Scope:
 253  271   *              Semi-private (library wide use only)
 254  272   */
 255  273  void
 256  274  be_make_container_ds(const char *zpool,  char *container_ds,
 257  275      int container_ds_size)
 258  276  {
 259  277          struct be_defaults be_defaults;
 260  278          be_get_defaults(&be_defaults);
      279 +        char    *root_ds = NULL;
 261  280  
 262      -        if (be_defaults.be_deflt_rpool_container)
 263      -                (void) snprintf(container_ds, container_ds_size, "%s", zpool);
 264      -        else
 265      -                (void) snprintf(container_ds, container_ds_size, "%s/%s", zpool,
 266      -                    BE_CONTAINER_DS_NAME);
      281 +        if (getzoneid() == GLOBAL_ZONEID) {
      282 +                if (be_defaults.be_deflt_rpool_container) {
      283 +                        (void) snprintf(container_ds, container_ds_size,
      284 +                            "%s", zpool);
      285 +                } else {
      286 +                        (void) snprintf(container_ds, container_ds_size,
      287 +                            "%s/%s", zpool, BE_CONTAINER_DS_NAME);
      288 +                }
      289 +        } else {
      290 +                if ((root_ds = be_get_ds_from_dir("/")) != NULL) {
      291 +                        (void) strlcpy(container_ds, dirname(root_ds),
      292 +                            container_ds_size);
      293 +                } else {
      294 +                        be_print_err(gettext("be_make_container_ds: zone root "
      295 +                            "dataset is not mounted\n"));
      296 +                        return;
      297 +                }
      298 +        }
 267  299  }
 268  300  
 269  301  /*
 270  302   * Function:    be_make_name_from_ds
 271  303   * Description: This function takes a dataset name and strips off the
 272  304   *              BE container dataset portion from the beginning.  The
 273  305   *              returned name is allocated in heap storage, so the caller
 274  306   *              is responsible for freeing it.
 275  307   * Parameters:
 276  308   *              dataset - dataset to get name from.
↓ open down ↓ 2152 lines elided ↑ open up ↑
2429 2461   * Scope:
2430 2462   *              Semi-private (library wide use only)
2431 2463   */
2432 2464  int
2433 2465  be_zpool_find_current_be_callback(zpool_handle_t *zlp, void *data)
2434 2466  {
2435 2467          be_transaction_data_t   *bt = data;
2436 2468          zfs_handle_t            *zhp = NULL;
2437 2469          const char              *zpool =  zpool_get_name(zlp);
2438 2470          char                    be_container_ds[MAXPATHLEN];
     2471 +        char                    *zpath = NULL;
2439 2472  
2440 2473          /*
2441 2474           * Generate string for BE container dataset
2442 2475           */
2443      -        be_make_container_ds(zpool, be_container_ds, sizeof (be_container_ds));
     2476 +        if (getzoneid() != GLOBAL_ZONEID) {
     2477 +                if ((zpath = be_get_ds_from_dir("/")) != NULL) {
     2478 +                        (void) strlcpy(be_container_ds, dirname(zpath),
     2479 +                            sizeof (be_container_ds));
     2480 +                } else {
     2481 +                        be_print_err(gettext(
     2482 +                            "be_zpool_find_current_be_callback: "
     2483 +                            "zone root dataset is not mounted\n"));
     2484 +                        return (0);
     2485 +                }
     2486 +        } else {
     2487 +                be_make_container_ds(zpool, be_container_ds,
     2488 +                    sizeof (be_container_ds));
     2489 +        }
2444 2490  
2445 2491          /*
2446 2492           * Check if a BE container dataset exists in this pool.
2447 2493           */
2448 2494          if (!zfs_dataset_exists(g_zfs, be_container_ds, ZFS_TYPE_FILESYSTEM)) {
2449 2495                  zpool_close(zlp);
2450 2496                  return (0);
2451 2497          }
2452 2498  
2453 2499          /*
↓ open down ↓ 1323 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX