Use VOP_VPUT_PAIR() for eligible VFS syscalls.

The current list is limited to the cases where UFS needs to handle
vput(dvp) specially. Which means VOP_CREATE(), VOP_MKDIR(), VOP_MKNOD(),
VOP_LINK(), and VOP_SYMLINK().

Reviewed by:	chs, mkcusick
Tested by:	pho
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
This commit is contained in:
Konstantin Belousov 2021-01-29 00:31:30 +02:00
parent e4aaf35ab5
commit 3b2aa36024
3 changed files with 18 additions and 21 deletions

View File

@ -669,8 +669,8 @@ uipc_bindat(int fd, struct socket *so, struct sockaddr *nam, struct thread *td)
if (error == 0)
error = VOP_CREATE(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &vattr);
NDFREE(&nd, NDF_ONLY_PNBUF);
vput(nd.ni_dvp);
if (error) {
VOP_VPUT_PAIR(nd.ni_dvp, NULL, true);
vn_finished_write(mp);
if (error == ERELOOKUP)
goto restart;
@ -686,7 +686,8 @@ uipc_bindat(int fd, struct socket *so, struct sockaddr *nam, struct thread *td)
unp->unp_addr = soun;
unp->unp_flags &= ~UNP_BINDING;
UNP_PCB_UNLOCK(unp);
VOP_UNLOCK(vp);
vref(vp);
VOP_VPUT_PAIR(nd.ni_dvp, &vp, true);
vn_finished_write(mp);
free(buf, M_TEMP);
return (0);

View File

@ -1370,13 +1370,12 @@ kern_mknodat(struct thread *td, int fd, const char *path, enum uio_seg pathseg,
else {
error = VOP_MKNOD(nd.ni_dvp, &nd.ni_vp,
&nd.ni_cnd, &vattr);
if (error == 0)
vput(nd.ni_vp);
}
}
NDFREE(&nd, NDF_ONLY_PNBUF);
vput(nd.ni_dvp);
VOP_VPUT_PAIR(nd.ni_dvp, error == 0 && !whiteout ? &nd.ni_vp : NULL,
true);
vn_finished_write(mp);
NDFREE(&nd, NDF_ONLY_PNBUF);
if (error == ERELOOKUP)
goto restart;
return (error);
@ -1457,12 +1456,10 @@ kern_mkfifoat(struct thread *td, int fd, const char *path,
goto out;
#endif
error = VOP_MKNOD(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &vattr);
if (error == 0)
vput(nd.ni_vp);
#ifdef MAC
out:
#endif
vput(nd.ni_dvp);
VOP_VPUT_PAIR(nd.ni_dvp, error == 0 ? &nd.ni_vp : NULL, true);
vn_finished_write(mp);
NDFREE(&nd, NDF_ONLY_PNBUF);
if (error == ERELOOKUP)
@ -1629,10 +1626,10 @@ kern_linkat_vp(struct thread *td, struct vnode *vp, int fd, const char *path,
return (EAGAIN);
}
error = VOP_LINK(nd.ni_dvp, vp, &nd.ni_cnd);
VOP_UNLOCK(vp);
vput(nd.ni_dvp);
VOP_VPUT_PAIR(nd.ni_dvp, &vp, true);
vn_finished_write(mp);
NDFREE(&nd, NDF_ONLY_PNBUF);
vp = NULL;
} else {
vput(nd.ni_dvp);
NDFREE(&nd, NDF_ONLY_PNBUF);
@ -1640,7 +1637,8 @@ kern_linkat_vp(struct thread *td, struct vnode *vp, int fd, const char *path,
return (EAGAIN);
}
}
vrele(vp);
if (vp != NULL)
vrele(vp);
return (error);
}
@ -1710,6 +1708,7 @@ kern_symlinkat(struct thread *td, const char *path1, int fd, const char *path2,
else
vput(nd.ni_dvp);
vrele(nd.ni_vp);
nd.ni_vp = NULL;
error = EEXIST;
goto out;
}
@ -1730,14 +1729,12 @@ kern_symlinkat(struct thread *td, const char *path1, int fd, const char *path2,
goto out2;
#endif
error = VOP_SYMLINK(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &vattr, syspath);
if (error == 0)
vput(nd.ni_vp);
#ifdef MAC
out2:
#endif
NDFREE(&nd, NDF_ONLY_PNBUF);
vput(nd.ni_dvp);
VOP_VPUT_PAIR(nd.ni_dvp, error == 0 ? &nd.ni_vp : NULL, true);
vn_finished_write(mp);
NDFREE(&nd, NDF_ONLY_PNBUF);
if (error == ERELOOKUP)
goto restart;
out:
@ -3794,9 +3791,7 @@ kern_mkdirat(struct thread *td, int fd, const char *path, enum uio_seg segflg,
out:
#endif
NDFREE(&nd, NDF_ONLY_PNBUF);
vput(nd.ni_dvp);
if (error == 0)
vput(nd.ni_vp);
VOP_VPUT_PAIR(nd.ni_dvp, error == 0 ? &nd.ni_vp : NULL, true);
vn_finished_write(mp);
if (error == ERELOOKUP)
goto restart;

View File

@ -274,8 +274,9 @@ vn_open_cred(struct nameidata *ndp, int *flagp, int cmode, u_int vn_open_flags,
if (error == 0)
#endif
error = VOP_CREATE(ndp->ni_dvp, &ndp->ni_vp,
&ndp->ni_cnd, vap);
vput(ndp->ni_dvp);
&ndp->ni_cnd, vap);
VOP_VPUT_PAIR(ndp->ni_dvp, error == 0 ? &ndp->ni_vp :
NULL, false);
vn_finished_write(mp);
if (error) {
NDFREE(ndp, NDF_ONLY_PNBUF);