From d092f79489a00e3ccc2d7784e7a18e19aba4c35f Mon Sep 17 00:00:00 2001 From: Andriy Gapon Date: Tue, 12 Sep 2017 06:04:01 +0000 Subject: [PATCH] zfs_get_vfs: reference a requested filesystem instead of vfs_busy-ing it The only consumer of zfs_get_vfs, zfs_unmount_snap, does not need the filesystem to be busy, it just need a reference that it can pass to dounmount. Also, previously the code was racy as it unbusied the filesystem before taking a reference on it. Now the code should be simpler and safer. MFC after: 2 weeks Sponsored by: Panzura --- .../opensolaris/uts/common/fs/zfs/zfs_ioctl.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c index 425aed567404..156c55c59e7a 100644 --- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c +++ b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c @@ -3049,13 +3049,11 @@ zfs_get_vfs(const char *resource) mtx_lock(&mountlist_mtx); TAILQ_FOREACH(vfsp, &mountlist, mnt_list) { if (strcmp(refstr_value(vfsp->vfs_resource), resource) == 0) { - if (vfs_busy(vfsp, MBF_MNTLSTLOCK) != 0) - vfsp = NULL; + vfs_ref(vfsp); break; } } - if (vfsp == NULL) - mtx_unlock(&mountlist_mtx); + mtx_unlock(&mountlist_mtx); return (vfsp); } @@ -3545,7 +3543,9 @@ zfs_unmount_snap(const char *snapname) { vfs_t *vfsp; zfsvfs_t *zfsvfs; +#ifdef illumos int err; +#endif if (strchr(snapname, '@') == NULL) return (0); @@ -3557,23 +3557,19 @@ zfs_unmount_snap(const char *snapname) zfsvfs = vfsp->vfs_data; ASSERT(!dsl_pool_config_held(dmu_objset_pool(zfsvfs->z_os))); - err = vn_vfswlock(vfsp->vfs_vnodecovered); #ifdef illumos + err = vn_vfswlock(vfsp->vfs_vnodecovered); VFS_RELE(vfsp); -#else - vfs_unbusy(vfsp); -#endif if (err != 0) return (SET_ERROR(err)); +#endif /* * Always force the unmount for snapshots. */ - #ifdef illumos (void) dounmount(vfsp, MS_FORCE, kcred); #else - vfs_ref(vfsp); (void) dounmount(vfsp, MS_FORCE, curthread); #endif return (0);