The branch main has been updated by kib:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=4a21bcb24174438e0944d6e4d6633290a067b7a8

commit 4a21bcb24174438e0944d6e4d6633290a067b7a8
Author:     Konstantin Belousov <k...@freebsd.org>
AuthorDate: 2021-01-24 13:02:27 +0000
Commit:     Konstantin Belousov <k...@freebsd.org>
CommitDate: 2021-02-12 01:02:21 +0000

    nfsserver: use VOP_VPUT_PAIR().
    
    Apply VOP_VPUT_PAIR() to the end of vnode operations after the
    VOP_MKNOD(), VOP_MKDIR(), VOP_LINK(), VOP_SYMLINK(), VOP_CREATE().
    
    Reviewed by:    chs, mckusick
    Tested by:      pho
    MFC after:      2 weeks
    Sponsored by:   The FreeBSD Foundation
---
 sys/fs/nfsserver/nfs_nfsdport.c | 38 ++++++++++++++++++++++----------------
 1 file changed, 22 insertions(+), 16 deletions(-)

diff --git a/sys/fs/nfsserver/nfs_nfsdport.c b/sys/fs/nfsserver/nfs_nfsdport.c
index b781503a6815..4d19c73dfa06 100644
--- a/sys/fs/nfsserver/nfs_nfsdport.c
+++ b/sys/fs/nfsserver/nfs_nfsdport.c
@@ -1105,7 +1105,8 @@ nfsvno_createsub(struct nfsrv_descript *nd, struct 
nameidata *ndp,
                                nfsrv_pnfscreate(ndp->ni_vp, &nvap->na_vattr,
                                    nd->nd_cred, p);
                        }
-                       vput(ndp->ni_dvp);
+                       VOP_VPUT_PAIR(ndp->ni_dvp, error == 0 ? &ndp->ni_vp :
+                           NULL, false);
                        nfsvno_relpathbuf(ndp);
                        if (!error) {
                                if (*exclusive_flagp) {
@@ -1140,7 +1141,8 @@ nfsvno_createsub(struct nfsrv_descript *nd, struct 
nameidata *ndp,
                        nvap->na_rdev = rdev;
                        error = VOP_MKNOD(ndp->ni_dvp, &ndp->ni_vp,
                            &ndp->ni_cnd, &nvap->na_vattr);
-                       vput(ndp->ni_dvp);
+                       VOP_VPUT_PAIR(ndp->ni_dvp, error == 0 ? &ndp->ni_vp :
+                           NULL, false);
                        nfsvno_relpathbuf(ndp);
                        vrele(ndp->ni_startdir);
                        if (error)
@@ -1221,7 +1223,8 @@ nfsvno_mknod(struct nameidata *ndp, struct nfsvattr 
*nvap, struct ucred *cred,
                vrele(ndp->ni_startdir);
                error = VOP_CREATE(ndp->ni_dvp, &ndp->ni_vp,
                    &ndp->ni_cnd, &nvap->na_vattr);
-               vput(ndp->ni_dvp);
+               VOP_VPUT_PAIR(ndp->ni_dvp, error == 0 ? &ndp->ni_vp : NULL,
+                   false);
                nfsvno_relpathbuf(ndp);
        } else {
                if (nvap->na_type != VFIFO &&
@@ -1233,7 +1236,8 @@ nfsvno_mknod(struct nameidata *ndp, struct nfsvattr 
*nvap, struct ucred *cred,
                }
                error = VOP_MKNOD(ndp->ni_dvp, &ndp->ni_vp,
                    &ndp->ni_cnd, &nvap->na_vattr);
-               vput(ndp->ni_dvp);
+               VOP_VPUT_PAIR(ndp->ni_dvp, error == 0 ? &ndp->ni_vp : NULL,
+                   false);
                nfsvno_relpathbuf(ndp);
                vrele(ndp->ni_startdir);
                /*
@@ -1268,7 +1272,7 @@ nfsvno_mkdir(struct nameidata *ndp, struct nfsvattr 
*nvap, uid_t saved_uid,
        }
        error = VOP_MKDIR(ndp->ni_dvp, &ndp->ni_vp, &ndp->ni_cnd,
            &nvap->na_vattr);
-       vput(ndp->ni_dvp);
+       VOP_VPUT_PAIR(ndp->ni_dvp, error == 0 ? &ndp->ni_vp : NULL, false);
        nfsvno_relpathbuf(ndp);
 
 out:
@@ -1300,17 +1304,15 @@ nfsvno_symlink(struct nameidata *ndp, struct nfsvattr 
*nvap, char *pathcp,
 
        error = VOP_SYMLINK(ndp->ni_dvp, &ndp->ni_vp, &ndp->ni_cnd,
            &nvap->na_vattr, pathcp);
-       vput(ndp->ni_dvp);
-       vrele(ndp->ni_startdir);
-       nfsvno_relpathbuf(ndp);
        /*
         * Although FreeBSD still had the lookup code in
         * it for 7/current, there doesn't seem to be any
         * point, since VOP_SYMLINK() returns the ni_vp.
         * Just vput it for v2.
         */
-       if (!not_v2 && !error)
-               vput(ndp->ni_vp);
+       VOP_VPUT_PAIR(ndp->ni_dvp, &ndp->ni_vp, !not_v2 && error == 0);
+       vrele(ndp->ni_startdir);
+       nfsvno_relpathbuf(ndp);
 
 out:
        NFSEXITCODE(error);
@@ -1595,11 +1597,13 @@ nfsvno_link(struct nameidata *ndp, struct vnode *vp, 
struct ucred *cred,
                        error = VOP_LINK(ndp->ni_dvp, vp, &ndp->ni_cnd);
                else
                        error = EPERM;
-               if (ndp->ni_dvp == vp)
+               if (ndp->ni_dvp == vp) {
                        vrele(ndp->ni_dvp);
-               else
-                       vput(ndp->ni_dvp);
-               NFSVOPUNLOCK(vp);
+                       NFSVOPUNLOCK(vp);
+               } else {
+                       vref(vp);
+                       VOP_VPUT_PAIR(ndp->ni_dvp, &vp, true);
+               }
        } else {
                if (ndp->ni_dvp == ndp->ni_vp)
                        vrele(ndp->ni_dvp);
@@ -1793,7 +1797,8 @@ nfsvno_open(struct nfsrv_descript *nd, struct nameidata 
*ndp,
                                nfsrv_pnfscreate(ndp->ni_vp, &nvap->na_vattr,
                                    cred, p);
                        }
-                       vput(ndp->ni_dvp);
+                       VOP_VPUT_PAIR(ndp->ni_dvp, nd->nd_repstat == 0 ?
+                           &ndp->ni_vp : NULL, false);
                        nfsvno_relpathbuf(ndp);
                        if (!nd->nd_repstat) {
                                if (*exclusive_flagp) {
@@ -4106,7 +4111,8 @@ nfsrv_dscreate(struct vnode *dvp, struct vattr *vap, 
struct vattr *nvap,
        error = NFSVOPLOCK(dvp, LK_EXCLUSIVE);
        if (error == 0) {
                error = VOP_CREATE(dvp, &nvp, &named.ni_cnd, vap);
-               NFSVOPUNLOCK(dvp);
+               vref(dvp);
+               VOP_VPUT_PAIR(dvp, error == 0 ? &nvp : NULL, false);
                if (error == 0) {
                        /* Set the ownership of the file. */
                        error = VOP_SETATTR(nvp, nvap, tcred);
_______________________________________________
dev-commits-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-all
To unsubscribe, send any mail to "dev-commits-src-all-unsubscr...@freebsd.org"

Reply via email to