Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 13 Jul 2016 09:40:53 +0000 (UTC)
From:      Andriy Gapon <avg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r302735 - in stable/10/sys/cddl: compat/opensolaris/kern contrib/opensolaris/uts/common/fs/zfs
Message-ID:  <201607130940.u6D9er1m094496@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: avg
Date: Wed Jul 13 09:40:53 2016
New Revision: 302735
URL: https://svnweb.freebsd.org/changeset/base/302735

Log:
  MFC r299902,299938: mount_snapshot: consolidate all error handling

Modified:
  stable/10/sys/cddl/compat/opensolaris/kern/opensolaris_vfs.c
  stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ctldir.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/cddl/compat/opensolaris/kern/opensolaris_vfs.c
==============================================================================
--- stable/10/sys/cddl/compat/opensolaris/kern/opensolaris_vfs.c	Wed Jul 13 09:37:50 2016	(r302734)
+++ stable/10/sys/cddl/compat/opensolaris/kern/opensolaris_vfs.c	Wed Jul 13 09:40:53 2016	(r302735)
@@ -121,34 +121,39 @@ mount_snapshot(kthread_t *td, vnode_t **
 	struct ucred *cr;
 	int error;
 
+	ASSERT_VOP_ELOCKED(*vpp, "mount_snapshot");
+
+	vp = *vpp;
+	*vpp = NULL;
+	error = 0;
+
 	/*
 	 * Be ultra-paranoid about making sure the type and fspath
 	 * variables will fit in our mp buffers, including the
 	 * terminating NUL.
 	 */
 	if (strlen(fstype) >= MFSNAMELEN || strlen(fspath) >= MNAMELEN)
-		return (ENAMETOOLONG);
-
-	vfsp = vfs_byname_kld(fstype, td, &error);
-	if (vfsp == NULL)
-		return (ENODEV);
-
-	vp = *vpp;
-	if (vp->v_type != VDIR)
-		return (ENOTDIR);
+		error = ENAMETOOLONG;
+	if (error == 0 && (vfsp = vfs_byname_kld(fstype, td, &error)) == NULL)
+		error = ENODEV;
+	if (error == 0 && vp->v_type != VDIR)
+		error = ENOTDIR;
 	/*
 	 * We need vnode lock to protect v_mountedhere and vnode interlock
 	 * to protect v_iflag.
 	 */
-	vn_lock(vp, LK_SHARED | LK_RETRY);
-	VI_LOCK(vp);
-	if ((vp->v_iflag & VI_MOUNT) != 0 || vp->v_mountedhere != NULL) {
+	if (error == 0) {
+		VI_LOCK(vp);
+		if ((vp->v_iflag & VI_MOUNT) == 0 && vp->v_mountedhere == NULL)
+			vp->v_iflag |= VI_MOUNT;
+		else
+			error = EBUSY;
 		VI_UNLOCK(vp);
-		VOP_UNLOCK(vp, 0);
-		return (EBUSY);
 	}
-	vp->v_iflag |= VI_MOUNT;
-	VI_UNLOCK(vp);
+	if (error != 0) {
+		vput(vp);
+		return (error);
+	}
 	VOP_UNLOCK(vp, 0);
 
 	/*
@@ -198,7 +203,6 @@ mount_snapshot(kthread_t *td, vnode_t **
 		vfs_unbusy(mp);
 		vfs_freeopts(mp->mnt_optnew);
 		vfs_mount_destroy(mp);
-		*vpp = NULL;
 		return (error);
 	}
 

Modified: stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ctldir.c
==============================================================================
--- stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ctldir.c	Wed Jul 13 09:37:50 2016	(r302734)
+++ stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ctldir.c	Wed Jul 13 09:40:53 2016	(r302735)
@@ -1112,6 +1112,7 @@ domount:
 	(void) snprintf(mountpoint, mountpoint_len,
 	    "%s/" ZFS_CTLDIR_NAME "/snapshot/%s",
 	    dvp->v_vfsp->mnt_stat.f_mntonname, nm);
+	VERIFY0(vn_lock(*vpp, LK_EXCLUSIVE));
 	err = mount_snapshot(curthread, vpp, "zfs", mountpoint, snapname, 0);
 	kmem_free(mountpoint, mountpoint_len);
 	if (err == 0) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201607130940.u6D9er1m094496>