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
This commit is contained in:
rmacklem 2018-11-06 22:50:50 +00:00
parent 5eb6ee13ac
commit 0c7244beba

View File

@ -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);
}