Author: avg
Date: Fri Jun 12 11:21:35 2015
New Revision: 284309
URL: https://svnweb.freebsd.org/changeset/base/284309

Log:
  zfs clone should not mount the clone if canmount == noauto
  
  Creation of a new filesystem does not imply an intent to mount it.
  
  Since canmount property is not inherited and its default value is 'on',
  the only scenario where this matters is zfs clone -o canmount=noauto.
  zfs create -o canmount=noauto already does not mount the new filesystem.
  
  Also see:
  https://www.illumos.org/issues/5984
  https://reviews.csiden.org/r/228/
  
https://github.com/FransUrbo/zfs/commit/dd0e0e69f5b1c83bf2895ac00a0b83af77473175
  https://github.com/zfsonlinux/zfs/issues/2241
  
  Reviewed by:  mahrens
  MFC after:    8 days
  Sponsored by: ClusterHQ

Modified:
  head/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c

Modified: head/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c
==============================================================================
--- head/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c    Fri Jun 12 11:16:43 
2015        (r284308)
+++ head/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c    Fri Jun 12 11:21:35 
2015        (r284309)
@@ -593,6 +593,17 @@ finish_progress(char *done)
 }
 
 /*
+ * Check if the dataset is mountable and should be automatically mounted.
+ */
+static boolean_t
+should_auto_mount(zfs_handle_t *zhp)
+{
+       if (!zfs_prop_valid_for_type(ZFS_PROP_CANMOUNT, zfs_get_type(zhp)))
+               return (B_FALSE);
+       return (zfs_prop_get_int(zhp, ZFS_PROP_CANMOUNT) == ZFS_CANMOUNT_ON);
+}
+
+/*
  * zfs clone [-p] [-o prop=value] ... <snap> <fs | vol>
  *
  * Given an existing dataset, create a writable copy whose initial contents
@@ -677,9 +688,22 @@ zfs_do_clone(int argc, char **argv)
 
                clone = zfs_open(g_zfs, argv[1], ZFS_TYPE_DATASET);
                if (clone != NULL) {
-                       if (zfs_get_type(clone) != ZFS_TYPE_VOLUME)
-                               if ((ret = zfs_mount(clone, NULL, 0)) == 0)
-                                       ret = zfs_share(clone);
+                       /*
+                        * If the user doesn't want the dataset
+                        * automatically mounted, then skip the mount/share
+                        * step.
+                        */
+                       if (should_auto_mount(clone)) {
+                               if ((ret = zfs_mount(clone, NULL, 0)) != 0) {
+                                       (void) fprintf(stderr, gettext("clone "
+                                           "successfully created, "
+                                           "but not mounted\n"));
+                               } else if ((ret = zfs_share(clone)) != 0) {
+                                       (void) fprintf(stderr, gettext("clone "
+                                           "successfully created, "
+                                           "but not shared\n"));
+                               }
+                       }
                        zfs_close(clone);
                }
        }
@@ -728,7 +752,6 @@ zfs_do_create(int argc, char **argv)
        int ret = 1;
        nvlist_t *props;
        uint64_t intval;
-       int canmount = ZFS_CANMOUNT_OFF;
 
        if (nvlist_alloc(&props, NV_UNIQUE_NAME, 0) != 0)
                nomem();
@@ -868,19 +891,15 @@ zfs_do_create(int argc, char **argv)
                goto error;
 
        ret = 0;
-       /*
-        * if the user doesn't want the dataset automatically mounted,
-        * then skip the mount/share step
-        */
-       if (zfs_prop_valid_for_type(ZFS_PROP_CANMOUNT, type))
-               canmount = zfs_prop_get_int(zhp, ZFS_PROP_CANMOUNT);
 
        /*
         * Mount and/or share the new filesystem as appropriate.  We provide a
         * verbose error message to let the user know that their filesystem was
         * in fact created, even if we failed to mount or share it.
+        * If the user doesn't want the dataset automatically mounted,
+        * then skip the mount/share step altogether.
         */
-       if (!nomount && canmount == ZFS_CANMOUNT_ON) {
+       if (!nomount && should_auto_mount(zhp)) {
                if (zfs_mount(zhp, NULL, 0) != 0) {
                        (void) fprintf(stderr, gettext("filesystem "
                            "successfully created, but not mounted\n"));
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to