aboutsummaryrefslogtreecommitdiffstats
path: root/lib/libzfs/libzfs_iter.c
diff options
context:
space:
mode:
authoryouzhongyang <[email protected]>2021-10-20 19:07:19 -0400
committerGitHub <[email protected]>2021-10-20 16:07:19 -0700
commitec64fdb93d144ab1884097cfd36e18b62a2db848 (patch)
treeb0f072cb457e720ab25a074989440e55845f72a3 /lib/libzfs/libzfs_iter.c
parent1886cdfcfb970d57d4a2ae40b56d2dab2f029e2b (diff)
Skip snapshot in zfs_iter_mounted()
The intention of the zfs_iter_mounted() is to traverse the dataset and its descendants, not the snapshots. The current code can cause a mounted snapshot to be included and thus zfs_open() on the snapshot with ZFS_TYPE_FILESYSTEM would print confusing message such as "cannot open 'rpool/fs@snap': snapshot delimiter '@' is not expected here". Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Youzhong Yang <[email protected]> Closes #12447 Closes #12448
Diffstat (limited to 'lib/libzfs/libzfs_iter.c')
-rw-r--r--lib/libzfs/libzfs_iter.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/libzfs/libzfs_iter.c b/lib/libzfs/libzfs_iter.c
index 7806e21cd..3c537be79 100644
--- a/lib/libzfs/libzfs_iter.c
+++ b/lib/libzfs/libzfs_iter.c
@@ -575,8 +575,11 @@ zfs_iter_mounted(zfs_handle_t *zhp, zfs_iter_f func, void *data)
/* Ignore datasets not within the provided dataset */
if (strncmp(entry.mnt_special, zhp->zfs_name, namelen) != 0 ||
- (entry.mnt_special[namelen] != '/' &&
- entry.mnt_special[namelen] != '@'))
+ entry.mnt_special[namelen] != '/')
+ continue;
+
+ /* Skip snapshot of any child dataset */
+ if (strchr(entry.mnt_special, '@') != NULL)
continue;
if ((mtab_zhp = zfs_open(zhp->zfs_hdl, entry.mnt_special,