tech-kern archive

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

vget() patch



Hi,
unless someone objects I'll commit the attached patch and request
pullup to netbsd-5 next week-end. This is he same as the one posted in the
"panic due to lost vnode flag" thread. 
Althoug it doesn't fix this special issue, it seems to fix
kern/41147 in a better way, and I also hope kern/42205.
I've been running with this patch on several servers (and the previous
fix for kern/41147 commented out as in the patch below) without
problems; this is also being tested by others.

-- 
Manuel Bouyer, LIP6, Universite Paris VI.           
Manuel.Bouyer%lip6.fr@localhost
     NetBSD: 26 ans d'experience feront toujours la difference
--
Index: sys/ufs/ufs/ufs_ihash.c
===================================================================
RCS file: /cvsroot/src/sys/ufs/ufs/ufs_ihash.c,v
retrieving revision 1.26.10.1
diff -u -p -u -r1.26.10.1 ufs_ihash.c
--- sys/ufs/ufs/ufs_ihash.c     28 Sep 2009 01:43:02 -0000      1.26.10.1
+++ sys/ufs/ufs/ufs_ihash.c     24 Oct 2009 13:33:23 -0000
@@ -152,6 +152,7 @@ ufs_ihashget(dev_t dev, ino_t inum, int 
                                mutex_exit(&ufs_ihash_lock);
                                if (vget(vp, flags | LK_INTERLOCK))
                                        goto loop;
+#if 0
                                if (VTOI(vp) != ip ||
                                    ip->i_number != inum || ip->i_dev != dev) {
                                        /* lost race against vclean() */
@@ -161,6 +162,7 @@ ufs_ihashget(dev_t dev, ino_t inum, int 
                                        vp = NULL;
                                        goto loop;
                                }
+#endif
                        }
                        return (vp);
                }
Index: sys/kern/vfs_subr.c
===================================================================
RCS file: /cvsroot/src/sys/kern/vfs_subr.c,v
retrieving revision 1.357.4.5
diff -u -p -u -r1.357.4.5 vfs_subr.c
--- sys/kern/vfs_subr.c 21 Jul 2009 00:31:58 -0000      1.357.4.5
+++ sys/kern/vfs_subr.c 24 Oct 2009 13:33:23 -0000
@@ -370,6 +370,17 @@ try_nextlist:
        vp->v_freelisthd = NULL;
        mutex_exit(&vnode_free_list_lock);
 
+       if (vp->v_usecount != 0) {
+               /*
+                * was referenced again before we got the interlock
+                * Don't return to freelist - the holder of the last
+                * reference will destroy it.
+                */
+               vrelel(vp, 0); /* releases vp->v_interlock */
+               mutex_enter(&vnode_free_list_lock);
+               goto retry;
+       }
+
        /*
         * The vnode is still associated with a file system, so we must
         * clean it out before reusing it.  We need to add a reference
@@ -1288,6 +1299,22 @@ vget(vnode_t *vp, int flags)
                vrelel(vp, 0);
                return ENOENT;
        }
+
+       if ((vp->v_iflag & VI_INACTNOW) != 0) {
+               /*
+                * if it's being desactived, wait for it to complete.
+                * Make sure to not return a clean vnode.
+                */
+                if ((flags & LK_NOWAIT) != 0) {
+                       vrelel(vp, 0);
+                       return EBUSY;
+               }
+               vwait(vp, VI_INACTNOW);
+               if ((vp->v_iflag & VI_CLEAN) != 0) {
+                       vrelel(vp, 0);
+                       return ENOENT;
+               }
+       }
        if (flags & LK_TYPE_MASK) {
                error = vn_lock(vp, flags | LK_INTERLOCK);
                if (error != 0) {
@@ -1427,6 +1454,7 @@ vrelel(vnode_t *vp, int flags)
                        if (++vrele_pending > (desiredvnodes >> 8))
                                cv_signal(&vrele_cv); 
                        mutex_exit(&vrele_lock);
+                       cv_broadcast(&vp->v_cv);
                        mutex_exit(&vp->v_interlock);
                        return;
                }
@@ -1451,6 +1479,7 @@ vrelel(vnode_t *vp, int flags)
                VOP_INACTIVE(vp, &recycle);
                mutex_enter(&vp->v_interlock);
                vp->v_iflag &= ~VI_INACTNOW;
+               cv_broadcast(&vp->v_cv);
                if (!recycle) {
                        if (vtryrele(vp)) {
                                mutex_exit(&vp->v_interlock);


Home | Main Index | Thread Index | Old Index