Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/ufs/lfs Sprinkle lock ownership assertions.



details:   https://anonhg.NetBSD.org/src/rev/6c89b00622f0
branches:  trunk
changeset: 823053:6c89b00622f0
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Tue Apr 11 05:48:04 2017 +0000

description:
Sprinkle lock ownership assertions.

diffstat:

 sys/ufs/lfs/lfs_vnops.c  |  140 +++++++++++++++++++++++++++++++++++-----------
 sys/ufs/lfs/ulfs_vnops.c |   63 +++++++++++++++++---
 2 files changed, 159 insertions(+), 44 deletions(-)

diffs (truncated from 587 to 300 lines):

diff -r 11b02d2d47f2 -r 6c89b00622f0 sys/ufs/lfs/lfs_vnops.c
--- a/sys/ufs/lfs/lfs_vnops.c   Tue Apr 11 04:43:12 2017 +0000
+++ b/sys/ufs/lfs/lfs_vnops.c   Tue Apr 11 05:48:04 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs_vnops.c,v 1.310 2017/04/01 17:34:21 maya Exp $     */
+/*     $NetBSD: lfs_vnops.c,v 1.311 2017/04/11 05:48:04 riastradh Exp $        */
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -125,7 +125,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.310 2017/04/01 17:34:21 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.311 2017/04/11 05:48:04 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -407,6 +407,7 @@
        if (error)
                goto bad;
        *vpp = tvp;
+       KASSERT(VOP_ISLOCKED(*vpp) == LK_EXCLUSIVE);
        return (0);
 
  bad:
@@ -438,17 +439,20 @@
                off_t offhi;
        } */ *ap = v;
        struct vnode *vp = ap->a_vp;
-       int error, wait;
+       int wait;
        struct inode *ip = VTOI(vp);
        struct lfs *fs = ip->i_lfs;
+       int error = 0;
+
+       KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
 
        /* If we're mounted read-only, don't try to sync. */
        if (fs->lfs_ronly)
-               return 0;
+               goto out;
 
        /* If a removed vnode is being cleaned, no need to sync here. */
        if ((ap->a_flags & FSYNC_RECLAIM) != 0 && ip->i_mode == 0)
-               return 0;
+               goto out;
 
        /*
         * Trickle sync simply adds this vnode to the pager list, as if
@@ -465,7 +469,7 @@
                        cv_broadcast(&lfs_writerd_cv);
                        mutex_exit(&lfs_lock);
                }
-               return 0;
+               goto out;
        }
 
        /*
@@ -491,7 +495,7 @@
                }
        } while (error == EAGAIN);
        if (error)
-               return error;
+               goto out;
 
        if ((ap->a_flags & FSYNC_DATAONLY) == 0)
                error = lfs_update(vp, NULL, NULL, wait ? UPDATE_WAIT : 0);
@@ -504,6 +508,8 @@
        if (wait && !VPISEMPTY(vp))
                LFS_SET_UINO(ip, IN_MODIFIED);
 
+out:
+       KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
        return error;
 }
 
@@ -517,6 +523,8 @@
                struct vnode *a_vp;
        } */ *ap = v;
 
+       KASSERT(VOP_ISLOCKED(ap->a_vp) == LK_EXCLUSIVE);
+
        lfs_unmark_vnode(ap->a_vp);
 
        /*
@@ -552,8 +560,8 @@
        struct lfs *fs;
        int error;
 
-       KASSERT(VOP_ISLOCKED(dvp));
-       KASSERT(vp == NULL || VOP_ISLOCKED(vp));
+       KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
+       KASSERT(vp == NULL || VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
 
        fs = VTOI(dvp)->i_lfs;
 
@@ -701,6 +709,7 @@
        dvp = ap->a_dvp;
        vpp = ap->a_vpp;
 
+       KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
        KASSERT(vpp != NULL);
        KASSERT(*vpp == NULL);
        KASSERT(ap->a_vap->va_type == VLNK);
@@ -723,6 +732,7 @@
        if (error) {
                goto out;
        }
+       KASSERT(VOP_ISLOCKED(*vpp) == LK_EXCLUSIVE);
 
        VN_KNOTE(ap->a_dvp, NOTE_WRITE);
        ip = VTOI(*vpp);
@@ -787,9 +797,10 @@
        vpp = ap->a_vpp;
        vap = ap->a_vap;
 
+       KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
        KASSERT(vpp != NULL);
        KASSERT(*vpp == NULL);
-       
+
        /* XXX should handle this material another way */
        ulr = &VTOI(dvp)->i_crap;
        ULFS_CHECK_CRAPCOUNTER(VTOI(dvp));
@@ -816,6 +827,7 @@
                *vpp = NULL;
                return (error);
        }
+       KASSERT(VOP_ISLOCKED(*vpp) == LK_EXCLUSIVE);
 
        VN_KNOTE(dvp, NOTE_WRITE);
        ip = VTOI(*vpp);
@@ -864,6 +876,7 @@
        vpp = ap->a_vpp;
        vap = ap->a_vap;
 
+       KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
        KASSERT(vpp != NULL);
        KASSERT(*vpp == NULL);
 
@@ -885,6 +898,7 @@
        if (error) {
                goto out;
        }
+       KASSERT(VOP_ISLOCKED(*vpp) == LK_EXCLUSIVE);
        VN_KNOTE(dvp, NOTE_WRITE);
        VOP_UNLOCK(*vpp);
 
@@ -927,6 +941,8 @@
        cnp = ap->a_cnp;
        vap = ap->a_vap;
 
+       KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
+
        dp = VTOI(dvp);
        ip = NULL;
 
@@ -1078,6 +1094,10 @@
 
        dvp = ap->a_dvp;
        vp = ap->a_vp;
+
+       KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
+       KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
+
        ip = VTOI(vp);
        if ((error = lfs_set_dirop(dvp, vp)) != 0) {
                if (dvp == vp)
@@ -1118,6 +1138,10 @@
        int error;
 
        vp = ap->a_vp;
+
+       KASSERT(VOP_ISLOCKED(ap->a_dvp) == LK_EXCLUSIVE);
+       KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
+
        ip = VTOI(vp);
        if ((error = lfs_set_dirop(ap->a_dvp, ap->a_vp)) != 0) {
                if (ap->a_dvp == vp)
@@ -1158,6 +1182,8 @@
 
        dvp = ap->a_dvp;
 
+       KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
+
        fs = VFSTOULFS(dvp->v_mount)->um_lfs;
        ASSERT_NO_SEGLOCK(fs);
        if (fs->lfs_ronly) {
@@ -1188,9 +1214,14 @@
                kauth_cred_t a_cred;
        } */ *ap = v;
        struct vnode *vp = ap->a_vp;
-       struct inode *ip = VTOI(vp);
+       struct inode *ip;
        struct vattr *vap = ap->a_vap;
-       struct lfs *fs = ip->i_lfs;
+       struct lfs *fs;
+
+       KASSERT(VOP_ISLOCKED(vp));
+
+       ip = VTOI(vp);
+       fs = ip->i_lfs;
 
        /*
         * Copy from inode table
@@ -1246,6 +1277,7 @@
        } */ *ap = v;
        struct vnode *vp = ap->a_vp;
 
+       KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
        lfs_check(vp, LFS_UNUSED_LBN, 0);
        return ulfs_setattr(v);
 }
@@ -1297,8 +1329,13 @@
                kauth_cred_t a_cred;
        } */ *ap = v;
        struct vnode *vp = ap->a_vp;
-       struct inode *ip = VTOI(vp);
-       struct lfs *fs = ip->i_lfs;
+       struct inode *ip;
+       struct lfs *fs;
+
+       KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
+
+       ip = VTOI(vp);
+       fs = ip->i_lfs;
 
        if ((ip->i_number == ULFS_ROOTINO || ip->i_number == LFS_IFILE_INUM) &&
            fs->lfs_stoplwp == curlwp) {
@@ -1335,6 +1372,9 @@
        struct inode    *ip;
 
        vp = ap->a_vp;
+
+       KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
+
        ip = VTOI(vp);
        if (vp->v_usecount > 1) {
                LFS_ITIMES(ip, NULL, NULL, NULL);
@@ -1359,6 +1399,9 @@
        struct inode    *ip;
 
        vp = ap->a_vp;
+
+       KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
+
        ip = VTOI(vp);
        if (ap->a_vp->v_usecount > 1) {
                LFS_ITIMES(ip, NULL, NULL, NULL);
@@ -1377,10 +1420,13 @@
                struct vnode *a_vp;
        } */ *ap = v;
        struct vnode *vp = ap->a_vp;
-       struct inode *ip = VTOI(vp);
-       struct lfs *fs = ip->i_lfs;
+       struct inode *ip;
+       struct lfs *fs;
        int error;
 
+       ip = VTOI(vp);
+       fs = ip->i_lfs;
+
        /*
         * The inode must be freed and updated before being removed
         * from its hash chain.  Other threads trying to gain a hold
@@ -2194,9 +2240,14 @@
                kauth_cred_t a_cred;
                struct proc *a_p;
        } */ *ap = v;
-       struct inode *ip = VTOI(ap->a_vp);
-       struct ulfsmount *ump = ip->i_ump;
-       //struct lfs *fs = ip->i_lfs;
+       struct vnode *vp = ap->a_vp;
+       struct inode *ip;
+       struct ulfsmount *ump;
+
+       KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
+
+       ip = VTOI(vp);
+       ump = ip->i_ump;
 
        /* Not supported for ULFS1 file systems. */
        if (ump->um_fstype == ULFS1)
@@ -2215,9 +2266,14 @@
                kauth_cred_t a_cred;
                struct proc *a_p;
        } */ *ap = v;
-       struct inode *ip = VTOI(ap->a_vp);
-       struct ulfsmount *ump = ip->i_ump;
-       //struct lfs *fs = ip->i_lfs;
+       struct vnode *vp = ap->a_vp;
+       struct inode *ip;
+       struct ulfsmount *ump;
+
+       KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
+
+       ip = VTOI(ap->a_vp);
+       ump = ip->i_ump;
 



Home | Main Index | Thread Index | Old Index