The branch main has been updated by kib:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=3b2aa36024abcb2d8fdbf3a6ecc7438b073b04e4

commit 3b2aa36024abcb2d8fdbf3a6ecc7438b073b04e4
Author:     Konstantin Belousov <[email protected]>
AuthorDate: 2021-01-28 22:31:30 +0000
Commit:     Konstantin Belousov <[email protected]>
CommitDate: 2021-02-12 01:02:20 +0000

    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
---
 sys/kern/uipc_usrreq.c  |  5 +++--
 sys/kern/vfs_syscalls.c | 29 ++++++++++++-----------------
 sys/kern/vfs_vnops.c    |  5 +++--
 3 files changed, 18 insertions(+), 21 deletions(-)

diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c
index 0809f5180cc1..ca23ccbdb05e 100644
--- a/sys/kern/uipc_usrreq.c
+++ b/sys/kern/uipc_usrreq.c
@@ -669,8 +669,8 @@ restart:
        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 @@ restart:
        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);
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index 35a56510e9ef..aba3d62936bb 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -1370,13 +1370,12 @@ restart:
                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 @@ restart:
                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 @@ restart:
                else
                        vput(nd.ni_dvp);
                vrele(nd.ni_vp);
+               nd.ni_vp = NULL;
                error = EEXIST;
                goto out;
        }
@@ -1730,14 +1729,12 @@ restart:
                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 @@ restart:
 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;
diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c
index f70bcdab4208..f8943b3c07e7 100644
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -274,8 +274,9 @@ restart:
                        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);
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to