From cb8da70329ad0806ca33263f18f3a72150aa7c62 Mon Sep 17 00:00:00 2001 From: Umer Saleem Date: Fri, 20 Dec 2024 01:02:58 +0500 Subject: [PATCH] Skip iterating over snapshots for share properties Setting sharenfs and sharesmb properties on a dataset can become costly if there are large number of snapshots, since setting the share properties iterates over all snapshots present for a dataset. If it is the root dataset for which we are trying to set the share property, snapshots for all child datasets and their children will also be iterated. There is no need to iterate over snapshots for share properties because we do not allow share properties or any other property, to be set on a snapshot itself execpt for user properties. This commit skips iterating over snapshots for share properties, instead iterate over all child dataset and their children for share properties. Reviewed-by: Brian Behlendorf Reviewed-by: Alexander Motin Signed-off-by: Umer Saleem Closes #16877 --- lib/libzfs/libzfs_changelist.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/libzfs/libzfs_changelist.c b/lib/libzfs/libzfs_changelist.c index 4db1cbce9..47df86631 100644 --- a/lib/libzfs/libzfs_changelist.c +++ b/lib/libzfs/libzfs_changelist.c @@ -563,8 +563,15 @@ change_one(zfs_handle_t *zhp, void *data) cn = NULL; } - if (!clp->cl_alldependents) - ret = zfs_iter_children_v2(zhp, 0, change_one, data); + if (!clp->cl_alldependents) { + if (clp->cl_prop != ZFS_PROP_MOUNTPOINT) { + ret = zfs_iter_filesystems_v2(zhp, 0, + change_one, data); + } else { + ret = zfs_iter_children_v2(zhp, 0, change_one, + data); + } + } /* * If we added the handle to the changelist, we will re-use it @@ -738,6 +745,11 @@ changelist_gather(zfs_handle_t *zhp, zfs_prop_t prop, int gather_flags, changelist_free(clp); return (NULL); } + } else if (clp->cl_prop != ZFS_PROP_MOUNTPOINT) { + if (zfs_iter_filesystems_v2(zhp, 0, change_one, clp) != 0) { + changelist_free(clp); + return (NULL); + } } else if (zfs_iter_children_v2(zhp, 0, change_one, clp) != 0) { changelist_free(clp); return (NULL);