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 <behlendorf1@llnl.gov>
Signed-off-by: Youzhong Yang <yyang@mathworks.com>
Closes #12447
Closes #12448
This commit is contained in:
youzhongyang
2021-10-20 19:07:19 -04:00
committed by GitHub
parent 1886cdfcfb
commit ec64fdb93d
3 changed files with 59 additions and 6 deletions
+5 -2
View File
@@ -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,