Print this page
*** NO COMMENTS ***

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 ↓ 15 lines elided ↑ open up ↑
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  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      - * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
       26 + * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
  27   27   */
  28   28  
  29   29  /*
  30   30   * System includes
  31   31   */
  32   32  #include <assert.h>
  33   33  #include <errno.h>
       34 +#include <libgen.h>
  34   35  #include <libintl.h>
  35   36  #include <libnvpair.h>
  36   37  #include <libzfs.h>
  37   38  #include <stdio.h>
  38   39  #include <stdlib.h>
  39   40  #include <string.h>
  40   41  #include <sys/mntent.h>
  41   42  #include <sys/mnttab.h>
  42   43  #include <sys/mount.h>
  43   44  #include <sys/stat.h>
↓ open down ↓ 275 lines elided ↑ open up ↑
 319  320                          be_print_err(gettext("be_mount: failed to "
 320  321                              "make temporary mountpoint\n"));
 321  322                          ZFS_CLOSE(zhp);
 322  323                          return (ret);
 323  324                  }
 324  325                  gen_tmp_altroot = B_TRUE;
 325  326          } else {
 326  327                  tmp_altroot = *altroot;
 327  328          }
 328  329  
      330 +        md.altroot = tmp_altroot;
      331 +        md.shared_fs = flags & BE_MOUNT_FLAG_SHARED_FS;
      332 +        md.shared_rw = flags & BE_MOUNT_FLAG_SHARED_RW;
      333 +
 329  334          /* Mount the BE's root file system */
 330      -        if ((ret = be_mount_root(zhp, tmp_altroot)) != BE_SUCCESS) {
 331      -                be_print_err(gettext("be_mount: failed to "
 332      -                    "mount BE root file system\n"));
 333      -                if (gen_tmp_altroot)
 334      -                        free(tmp_altroot);
 335      -                ZFS_CLOSE(zhp);
 336      -                return (ret);
      335 +        if (getzoneid() == GLOBAL_ZONEID) {
      336 +                if ((ret = be_mount_root(zhp, tmp_altroot)) != BE_SUCCESS) {
      337 +                        be_print_err(gettext("be_mount: failed to "
      338 +                            "mount BE root file system\n"));
      339 +                        if (gen_tmp_altroot)
      340 +                                free(tmp_altroot);
      341 +                        ZFS_CLOSE(zhp);
      342 +                        return (ret);
      343 +                }
      344 +        } else {
      345 +                /* Legacy mount the zone root dataset */
      346 +                if ((ret = be_mount_zone_root(zhp, &md)) != BE_SUCCESS) {
      347 +                        be_print_err(gettext("be_mount: failed to "
      348 +                            "mount BE zone root file system\n"));
      349 +                        free(md.altroot);
      350 +                        ZFS_CLOSE(zhp);
      351 +                        return (ret);
      352 +                }
 337  353          }
 338  354  
 339  355          /* Iterate through BE's children filesystems */
 340  356          if ((err = zfs_iter_filesystems(zhp, be_mount_callback,
 341  357              tmp_altroot)) != 0) {
 342  358                  be_print_err(gettext("be_mount: failed to "
 343  359                      "mount BE (%s) on %s\n"), bt.obe_name, tmp_altroot);
 344  360                  if (gen_tmp_altroot)
 345  361                          free(tmp_altroot);
 346  362                  ZFS_CLOSE(zhp);
 347  363                  return (err);
 348  364          }
 349  365  
 350      -        md.altroot = tmp_altroot;
 351      -        md.shared_fs = flags & BE_MOUNT_FLAG_SHARED_FS;
 352      -        md.shared_rw = flags & BE_MOUNT_FLAG_SHARED_RW;
 353      -
 354  366          /*
 355  367           * Mount shared file systems if mount flag says so.
 356  368           */
 357  369          if (md.shared_fs) {
 358  370                  /*
 359  371                   * Mount all ZFS file systems not under the BE's root dataset
 360  372                   */
 361  373                  (void) zpool_iter(g_zfs, zpool_shared_fs_callback, &md);
 362  374  
 363  375                  /* TODO: Mount all non-ZFS file systems - Not supported yet */
↓ open down ↓ 157 lines elided ↑ open up ↑
 521  533          /* Unmount all children datasets under the BE's root dataset */
 522  534          if ((zret = zfs_iter_filesystems(zhp, be_unmount_callback,
 523  535              &ud)) != 0) {
 524  536                  be_print_err(gettext("be_unmount: failed to "
 525  537                      "unmount BE (%s)\n"), bt.obe_name);
 526  538                  ZFS_CLOSE(zhp);
 527  539                  return (zret);
 528  540          }
 529  541  
 530  542          /* Unmount this BE's root filesystem */
 531      -        if ((ret = be_unmount_root(zhp, &ud)) != BE_SUCCESS) {
 532      -                ZFS_CLOSE(zhp);
 533      -                return (ret);
      543 +        if (getzoneid() == GLOBAL_ZONEID) {
      544 +                if ((ret = be_unmount_root(zhp, &ud)) != BE_SUCCESS) {
      545 +                        ZFS_CLOSE(zhp);
      546 +                        return (ret);
      547 +                }
      548 +        } else {
      549 +                if ((ret = be_unmount_zone_root(zhp, &ud)) != BE_SUCCESS) {
      550 +                        ZFS_CLOSE(zhp);
      551 +                        return (ret);
      552 +                }
 534  553          }
 535  554  
 536  555          ZFS_CLOSE(zhp);
 537  556  
 538  557          return (BE_SUCCESS);
 539  558  }
 540  559  
 541  560  /*
 542  561   * Function:    be_mount_zone_root
 543  562   * Description: Mounts the zone root dataset for a zone.
↓ open down ↓ 2 lines elided ↑ open up ↑
 546  565   *              md - be_mount_data_t pointer to data for zone to be mounted
 547  566   * Returns:
 548  567   *              BE_SUCCESS - Success
 549  568   *              be_errno_t - Failure
 550  569   * Scope:
 551  570   *              Semi-private (library wide use only)
 552  571   */
 553  572  int
 554  573  be_mount_zone_root(zfs_handle_t *zhp, be_mount_data_t *md)
 555  574  {
      575 +        struct stat buf;
 556  576          char    mountpoint[MAXPATHLEN];
 557  577          int     err = 0;
 558  578  
 559  579          /* Get mountpoint property of dataset */
 560  580          if (zfs_prop_get(zhp, ZFS_PROP_MOUNTPOINT, mountpoint,
 561  581              sizeof (mountpoint), NULL, NULL, 0, B_FALSE) != 0) {
 562  582                  be_print_err(gettext("be_mount_zone_root: failed to "
 563  583                      "get mountpoint property for %s: %s\n"), zfs_get_name(zhp),
 564  584                      libzfs_error_description(g_zfs));
 565  585                  return (zfs_err_to_be_err(g_zfs));
↓ open down ↓ 3 lines elided ↑ open up ↑
 569  589           * Make sure zone's root dataset is set to 'legacy'.  This is
 570  590           * currently a requirement in this implementation of zones
 571  591           * support.
 572  592           */
 573  593          if (strcmp(mountpoint, ZFS_MOUNTPOINT_LEGACY) != 0) {
 574  594                  be_print_err(gettext("be_mount_zone_root: "
 575  595                      "zone root dataset mountpoint is not 'legacy'\n"));
 576  596                  return (BE_ERR_ZONE_ROOT_NOT_LEGACY);
 577  597          }
 578  598  
      599 +        /* Create the mountpoint if it doesn't exist */
      600 +        if (lstat(md->altroot, &buf) != 0) {
      601 +                if (mkdirp(md->altroot, 0755) != 0) {
      602 +                        err = errno;
      603 +                        be_print_err(gettext("be_mount_zone_root: failed "
      604 +                            "to create mountpoint %s\n"), md->altroot);
      605 +                        return (errno_to_be_err(err));
      606 +                }
      607 +        }
      608 +
 579  609          /*
 580  610           * Legacy mount the zone root dataset.
 581  611           *
 582  612           * As a workaround for 6176743, we mount the zone's root with the
 583  613           * MS_OVERLAY option in case an alternate BE is mounted, and we're
 584  614           * mounting the root for the zone from the current BE here.  When an
 585  615           * alternate BE is mounted, it ties up the zone's zoneroot directory
 586  616           * for the current BE since the zone's zonepath is loopback mounted
 587  617           * from the current BE.
 588  618           *
↓ open down ↓ 2115 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX