From owner-svn-src-head@freebsd.org Thu Feb 22 13:06:28 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E5C65F0128A; Thu, 22 Feb 2018 13:06:27 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 9B22C815BA; Thu, 22 Feb 2018 13:06:27 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 92E2F27F77; Thu, 22 Feb 2018 13:06:27 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w1MD6Rjq089740; Thu, 22 Feb 2018 13:06:27 GMT (envelope-from avg@FreeBSD.org) Received: (from avg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w1MD6R4E089737; Thu, 22 Feb 2018 13:06:27 GMT (envelope-from avg@FreeBSD.org) Message-Id: <201802221306.w1MD6R4E089737@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: avg set sender to avg@FreeBSD.org using -f From: Andriy Gapon Date: Thu, 22 Feb 2018 13:06:27 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r329823 - in head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs: . sys X-SVN-Group: head X-SVN-Commit-Author: avg X-SVN-Commit-Paths: in head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs: . sys X-SVN-Commit-Revision: 329823 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Feb 2018 13:06:28 -0000 Author: avg Date: Thu Feb 22 13:06:27 2018 New Revision: 329823 URL: https://svnweb.freebsd.org/changeset/base/329823 Log: another rework of getzfsvfs / getzfsvfs_impl code This change is designed to account for yet another difference between illumos and FreeBSD VFS. In FreeBSD a filesystem driver is supposed to clean up mnt_data in its VFS_UNMOUNT method because it's the last call into the driver before a struct mount object is destroyed. The VFS drains all references to the object before destroying it, but for the driver it's already as good as gone. In contrast, illumos VFS provides another method, VFS_FREEVFS, that is called when all references are drained. So, the driver can keep its data after VFS_UNMOUNT and clean it up in VFS_FREEVFS after all references are gone. This is what ZFS does on illumos. So there a reference to a filesystem is sufficient to guarantee that the ZFS specific data, aka zfsvfs_t, stays around (even if the filesystem gets unmounted). In FreeBSD we need to vfs_busy the filesystem to get the same guarantee. vfs_ref guarantees only that the struct mount is kept. The following rules should be observed in getzfsvfs / getzfsvfs_impl on FreeBSD: - if we need access to zfsvfs_t then we must use vfs_busy - if only we need to access struct mount (aka vfs_t), then vfs_ref is enough - when illumos code actually needs only the vfs_t, they still can pass the zfsvfs_t and get the vfs_t from it; that can work in FreeBSD if the filesystem is busied, but when it's just referenced then we have to pass the vfs_t explicitly - we cannot call vfs_busy while holding a dataset because that creates a LOR with dp_config_rwlock As a result: - getzfsvfs_impl now only references the filesystem, same as in illumos, but unlike illumos it has to return the vfs_t - the consumers are updated to account for the change - getzfsvfs busies the filesystem (and drops the reference from getzfsvfs_impl) Also, zfs_unmount_snap() now gets a busied a filesystem, references it and then unbusies it essentially reverting actions done in getzfsvfs. This is needed because the code may perform some checks that require the zfsvfs_t. So, those are done before the unbusying. MFC after: 2 weeks Modified: head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfs_ioctl.h head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zcp_get.c head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c Modified: head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfs_ioctl.h ============================================================================== --- head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfs_ioctl.h Thu Feb 22 12:31:28 2018 (r329822) +++ head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfs_ioctl.h Thu Feb 22 13:06:27 2018 (r329823) @@ -426,7 +426,11 @@ extern int zfs_secpolicy_destroy_perms(const char *, c extern int zfs_busy(void); extern void zfs_unmount_snap(const char *); extern void zfs_destroy_unmount_origin(const char *); +#ifdef illumos extern int getzfsvfs_impl(struct objset *, struct zfsvfs **); +#else +extern int getzfsvfs_impl(struct objset *, vfs_t **); +#endif extern int getzfsvfs(const char *, struct zfsvfs **); /* Modified: head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zcp_get.c ============================================================================== --- head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zcp_get.c Thu Feb 22 12:31:28 2018 (r329822) +++ head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zcp_get.c Thu Feb 22 13:06:27 2018 (r329823) @@ -226,7 +226,9 @@ get_temporary_prop(dsl_dataset_t *ds, zfs_prop_t zfs_p return (0); #else int error; +#ifdef illumos zfsvfs_t *zfvp; +#endif vfs_t *vfsp; objset_t *os; uint64_t tmp = *val; @@ -235,12 +237,12 @@ get_temporary_prop(dsl_dataset_t *ds, zfs_prop_t zfs_p if (error != 0) return (error); - error = getzfsvfs_impl(os, &zfvp); + error = getzfsvfs_impl(os, &vfsp); if (error != 0) return (error); - +#ifdef illumos vfsp = zfvp->z_vfs; - +#endif switch (zfs_prop) { case ZFS_PROP_ATIME: if (vfs_optionisset(vfsp, MNTOPT_NOATIME, NULL)) Modified: head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c ============================================================================== --- head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c Thu Feb 22 12:31:28 2018 (r329822) +++ head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c Thu Feb 22 13:06:27 2018 (r329823) @@ -1448,9 +1448,9 @@ put_nvlist(zfs_cmd_t *zc, nvlist_t *nvl) } int -getzfsvfs_impl(objset_t *os, zfsvfs_t **zfvp) +getzfsvfs_impl(objset_t *os, vfs_t **vfsp) { - vfs_t *vfsp; + zfsvfs_t *zfvp; int error = 0; if (dmu_objset_type(os) != DMU_OST_ZFS) { @@ -1458,9 +1458,10 @@ getzfsvfs_impl(objset_t *os, zfsvfs_t **zfvp) } mutex_enter(&os->os_user_ptr_lock); - *zfvp = dmu_objset_get_user(os); - if (*zfvp) { - vfs_ref((*zfvp)->z_vfs); + zfvp = dmu_objset_get_user(os); + if (zfvp) { + *vfsp = zfvp->z_vfs; + vfs_ref(zfvp->z_vfs); } else { error = SET_ERROR(ESRCH); } @@ -1468,57 +1469,31 @@ getzfsvfs_impl(objset_t *os, zfsvfs_t **zfvp) return (error); } -#ifdef illumos int getzfsvfs(const char *dsname, zfsvfs_t **zfvp) { objset_t *os; + vfs_t *vfsp; int error; error = dmu_objset_hold(dsname, FTAG, &os); if (error != 0) return (error); - - error = getzfsvfs_impl(os, zfvp); + error = getzfsvfs_impl(os, &vfsp); dmu_objset_rele(os, FTAG); - return (error); -} - -#else - -static int -getzfsvfs_ref(const char *dsname, zfsvfs_t **zfvp) -{ - objset_t *os; - int error; - - error = dmu_objset_hold(dsname, FTAG, &os); if (error != 0) return (error); - error = getzfsvfs_impl(os, zfvp); - dmu_objset_rele(os, FTAG); - return (error); -} - -int -getzfsvfs(const char *dsname, zfsvfs_t **zfvp) -{ - objset_t *os; - int error; - - error = getzfsvfs_ref(dsname, zfvp); - if (error != 0) - return (error); - error = vfs_busy((*zfvp)->z_vfs, 0); - vfs_rel((*zfvp)->z_vfs); + error = vfs_busy(vfsp, 0); + vfs_rel(vfsp); if (error != 0) { *zfvp = NULL; error = SET_ERROR(ESRCH); + } else { + *zfvp = vfsp->vfs_data; } return (error); } -#endif /* * Find a zfsvfs_t for a mounted filesystem, or create our own, in which @@ -3597,7 +3572,7 @@ zfs_unmount_snap(const char *snapname) if (strchr(snapname, '@') == NULL) return; - int err = getzfsvfs_ref(snapname, &zfsvfs); + int err = getzfsvfs(snapname, &zfsvfs); if (err != 0) { ASSERT3P(zfsvfs, ==, NULL); return; @@ -3619,6 +3594,8 @@ zfs_unmount_snap(const char *snapname) #ifdef illumos (void) dounmount(vfsp, MS_FORCE, kcred); #else + vfs_ref(vfsp); + vfs_unbusy(vfsp); (void) dounmount(vfsp, MS_FORCE, curthread); #endif }