aboutsummaryrefslogtreecommitdiff
path: root/lib/libzfs/libzfs_changelist.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libzfs/libzfs_changelist.c')
-rw-r--r--lib/libzfs/libzfs_changelist.c55
1 files changed, 34 insertions, 21 deletions
diff --git a/lib/libzfs/libzfs_changelist.c b/lib/libzfs/libzfs_changelist.c
index d31bbc4a3b42..4db1cbce9568 100644
--- a/lib/libzfs/libzfs_changelist.c
+++ b/lib/libzfs/libzfs_changelist.c
@@ -6,7 +6,7 @@
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -105,6 +105,15 @@ changelist_prefix(prop_changelist_t *clp)
clp->cl_prop != ZFS_PROP_SHARESMB)
return (0);
+ /*
+ * If CL_GATHER_DONT_UNMOUNT is set, don't want to unmount/unshare and
+ * later (re)mount/(re)share the filesystem in postfix phase, so we
+ * return from here. If filesystem is mounted or unmounted, leave it
+ * as it is.
+ */
+ if (clp->cl_gflags & CL_GATHER_DONT_UNMOUNT)
+ return (0);
+
if ((walk = uu_avl_walk_start(clp->cl_tree, UU_WALK_ROBUST)) == NULL)
return (-1);
@@ -129,8 +138,6 @@ changelist_prefix(prop_changelist_t *clp)
*/
switch (clp->cl_prop) {
case ZFS_PROP_MOUNTPOINT:
- if (clp->cl_gflags & CL_GATHER_DONT_UNMOUNT)
- break;
if (zfs_unmount(cn->cn_handle, NULL,
clp->cl_mflags) != 0) {
ret = -1;
@@ -164,9 +171,8 @@ changelist_prefix(prop_changelist_t *clp)
* reshare the filesystems as necessary. In changelist_gather() we recorded
* whether the filesystem was previously shared or mounted. The action we take
* depends on the previous state, and whether the value was previously 'legacy'.
- * For non-legacy properties, we only remount/reshare the filesystem if it was
- * previously mounted/shared. Otherwise, we always remount/reshare the
- * filesystem.
+ * For non-legacy properties, we always remount/reshare the filesystem,
+ * if CL_GATHER_DONT_UNMOUNT is not set.
*/
int
changelist_postfix(prop_changelist_t *clp)
@@ -174,11 +180,18 @@ changelist_postfix(prop_changelist_t *clp)
prop_changenode_t *cn;
uu_avl_walk_t *walk;
char shareopts[ZFS_MAXPROPLEN];
- int errors = 0;
boolean_t commit_smb_shares = B_FALSE;
boolean_t commit_nfs_shares = B_FALSE;
/*
+ * If CL_GATHER_DONT_UNMOUNT is set, it means we don't want to (un)mount
+ * or (re/un)share the filesystem, so we return from here. If filesystem
+ * is mounted or unmounted, leave it as it is.
+ */
+ if (clp->cl_gflags & CL_GATHER_DONT_UNMOUNT)
+ return (0);
+
+ /*
* If we're changing the mountpoint, attempt to destroy the underlying
* mountpoint. All other datasets will have inherited from this dataset
* (in which case their mountpoints exist in the filesystem in the new
@@ -240,17 +253,16 @@ changelist_postfix(prop_changelist_t *clp)
needs_key = (zfs_prop_get_int(cn->cn_handle,
ZFS_PROP_KEYSTATUS) == ZFS_KEYSTATUS_UNAVAILABLE);
- mounted = (clp->cl_gflags & CL_GATHER_DONT_UNMOUNT) ||
- zfs_is_mounted(cn->cn_handle, NULL);
+ mounted = zfs_is_mounted(cn->cn_handle, NULL);
if (!mounted && !needs_key && (cn->cn_mounted ||
- ((sharenfs || sharesmb || clp->cl_waslegacy) &&
+ (((clp->cl_prop == ZFS_PROP_MOUNTPOINT &&
+ clp->cl_prop == clp->cl_realprop) ||
+ sharenfs || sharesmb || clp->cl_waslegacy) &&
(zfs_prop_get_int(cn->cn_handle,
ZFS_PROP_CANMOUNT) == ZFS_CANMOUNT_ON)))) {
- if (zfs_mount(cn->cn_handle, NULL, 0) != 0)
- errors++;
- else
+ if (zfs_mount(cn->cn_handle, NULL, 0) == 0)
mounted = TRUE;
}
@@ -262,19 +274,19 @@ changelist_postfix(prop_changelist_t *clp)
const enum sa_protocol nfs[] =
{SA_PROTOCOL_NFS, SA_NO_PROTOCOL};
if (sharenfs && mounted) {
- errors += zfs_share(cn->cn_handle, nfs);
+ zfs_share(cn->cn_handle, nfs);
commit_nfs_shares = B_TRUE;
} else if (cn->cn_shared || clp->cl_waslegacy) {
- errors += zfs_unshare(cn->cn_handle, NULL, nfs);
+ zfs_unshare(cn->cn_handle, NULL, nfs);
commit_nfs_shares = B_TRUE;
}
const enum sa_protocol smb[] =
{SA_PROTOCOL_SMB, SA_NO_PROTOCOL};
if (sharesmb && mounted) {
- errors += zfs_share(cn->cn_handle, smb);
+ zfs_share(cn->cn_handle, smb);
commit_smb_shares = B_TRUE;
} else if (cn->cn_shared || clp->cl_waslegacy) {
- errors += zfs_unshare(cn->cn_handle, NULL, smb);
+ zfs_unshare(cn->cn_handle, NULL, smb);
commit_smb_shares = B_TRUE;
}
}
@@ -288,7 +300,7 @@ changelist_postfix(prop_changelist_t *clp)
zfs_commit_shares(proto);
uu_avl_walk_end(walk);
- return (errors ? -1 : 0);
+ return (0);
}
/*
@@ -552,7 +564,7 @@ change_one(zfs_handle_t *zhp, void *data)
}
if (!clp->cl_alldependents)
- ret = zfs_iter_children(zhp, change_one, data);
+ ret = zfs_iter_children_v2(zhp, 0, change_one, data);
/*
* If we added the handle to the changelist, we will re-use it
@@ -721,11 +733,12 @@ changelist_gather(zfs_handle_t *zhp, zfs_prop_t prop, int gather_flags,
return (NULL);
}
} else if (clp->cl_alldependents) {
- if (zfs_iter_dependents(zhp, B_TRUE, change_one, clp) != 0) {
+ if (zfs_iter_dependents_v2(zhp, 0, B_TRUE, change_one,
+ clp) != 0) {
changelist_free(clp);
return (NULL);
}
- } else if (zfs_iter_children(zhp, change_one, clp) != 0) {
+ } else if (zfs_iter_children_v2(zhp, 0, change_one, clp) != 0) {
changelist_free(clp);
return (NULL);
}