Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 6 Nov 2018 22:50:50 +0000 (UTC)
From:      Rick Macklem <rmacklem@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r340207 - head/sys/fs/nfsclient
Message-ID:  <201811062250.wA6Moo1Q037368@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: rmacklem
Date: Tue Nov  6 22:50:50 2018
New Revision: 340207
URL: https://svnweb.freebsd.org/changeset/base/340207

Log:
  Change nfs_advlock() so that the NFSVOPUNLOCK() is mostly done at the end.
  
  Prior to this patch, nfs_advlock() did NFSVOPUNLOCK(); return (error);
  in many places. This patch replaces these code sequenences with a "goto out;"
  and does the NFSVOPUNLOCK(); return (error); at the end of the function
  in order to make the vnode locking simpler.
  This patch does not change the semantics of nfs_advlock().
  
  Suggested by:	kib
  Reviewed by:	kib
  Differential Revision:	https://reviews.freebsd.org/D17853

Modified:
  head/sys/fs/nfsclient/nfs_clvnops.c

Modified: head/sys/fs/nfsclient/nfs_clvnops.c
==============================================================================
--- head/sys/fs/nfsclient/nfs_clvnops.c	Tue Nov  6 22:33:36 2018	(r340206)
+++ head/sys/fs/nfsclient/nfs_clvnops.c	Tue Nov  6 22:50:50 2018	(r340207)
@@ -3030,16 +3030,16 @@ nfs_advlock(struct vop_advlock_args *ap)
 	struct proc *p = (struct proc *)ap->a_id;
 	struct thread *td = curthread;	/* XXX */
 	struct vattr va;
-	int ret, error = EOPNOTSUPP;
+	int ret, error;
 	u_quad_t size;
 	
-	ret = NFSVOPLOCK(vp, LK_SHARED);
-	if (ret != 0)
+	error = NFSVOPLOCK(vp, LK_SHARED);
+	if (error != 0)
 		return (EBADF);
 	if (NFS_ISV4(vp) && (ap->a_flags & (F_POSIX | F_FLOCK)) != 0) {
 		if (vp->v_type != VREG) {
-			NFSVOPUNLOCK(vp, 0);
-			return (EINVAL);
+			error = EINVAL;
+			goto out;
 		}
 		if ((ap->a_flags & F_POSIX) != 0)
 			cred = p->p_ucred;
@@ -3047,8 +3047,8 @@ nfs_advlock(struct vop_advlock_args *ap)
 			cred = td->td_ucred;
 		NFSVOPLOCK(vp, LK_UPGRADE | LK_RETRY);
 		if (vp->v_iflag & VI_DOOMED) {
-			NFSVOPUNLOCK(vp, 0);
-			return (EBADF);
+			error = EBADF;
+			goto out;
 		}
 
 		/*
@@ -3077,21 +3077,21 @@ nfs_advlock(struct vop_advlock_args *ap)
 					return (EINTR);
 				NFSVOPLOCK(vp, LK_EXCLUSIVE | LK_RETRY);
 				if (vp->v_iflag & VI_DOOMED) {
-					NFSVOPUNLOCK(vp, 0);
-					return (EBADF);
+					error = EBADF;
+					goto out;
 				}
 			}
 		} while (ret == NFSERR_DENIED && (ap->a_flags & F_WAIT) &&
 		     ap->a_op == F_SETLK);
 		if (ret == NFSERR_DENIED) {
-			NFSVOPUNLOCK(vp, 0);
-			return (EAGAIN);
+			error = EAGAIN;
+			goto out;
 		} else if (ret == EINVAL || ret == EBADF || ret == EINTR) {
-			NFSVOPUNLOCK(vp, 0);
-			return (ret);
+			error = ret;
+			goto out;
 		} else if (ret != 0) {
-			NFSVOPUNLOCK(vp, 0);
-			return (EACCES);
+			error = EACCES;
+			goto out;
 		}
 
 		/*
@@ -3121,8 +3121,6 @@ nfs_advlock(struct vop_advlock_args *ap)
 			np->n_flag |= NHASBEENLOCKED;
 			mtx_unlock(&np->n_mtx);
 		}
-		NFSVOPUNLOCK(vp, 0);
-		return (0);
 	} else if (!NFS_ISV4(vp)) {
 		if ((VFSTONFS(vp->v_mount)->nm_flag & NFSMNT_NOLOCKD) != 0) {
 			size = VTONFS(vp)->n_size;
@@ -3146,8 +3144,11 @@ nfs_advlock(struct vop_advlock_args *ap)
 				NFSVOPUNLOCK(vp, 0);
 			}
 		}
+		return (error);
 	} else
-		NFSVOPUNLOCK(vp, 0);
+		error = EOPNOTSUPP;
+out:
+	NFSVOPUNLOCK(vp, 0);
 	return (error);
 }
 



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