]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
Prevent VLRUQ race in ShakeLooseVCaches
authorSimon Wilkinson <sxw@inf.ed.ac.uk>
Wed, 4 Nov 2009 23:40:39 +0000 (23:40 +0000)
committerDerrick Brashear <shadow|account-1000005@unknown>
Thu, 17 Dec 2009 14:00:14 +0000 (06:00 -0800)
When ShakeLooseVCaches is called from afs_Daemon, the xvcache lock
is not held. This means that if the GLOCK is dropped for any reason
(for example, whilst purging the dentry cache), then
ShakeLooseVCaches can be raced, end we can end up attempting to
flush the same vcache twice.

The symptoms of this in Linux are that we oops in clear_inode.

Get the xvcache lock in afs_Daemon(), before calling
ShakeLooseVCaches. Also, remove the conditional GLOCK code from
that function. If we don't have the GLOCK on entry, then we're really
in trouble (and both code paths - afs_Daemon and afs_NewVCache should
get the GLOCK for us, anyway)

FIXES 125589

(cherry picked from 95770bf95ad766207252ea0c2d2b5ab2415c896f)
Change-Id: I3fe5b41a661cd162ec73c51492925ad87c6d4c13
Reviewed-on: http://gerrit.openafs.org/781
Reviewed-by: Marc Dionne <marc.c.dionne@gmail.com>
Tested-by: Derrick Brashear <shadow@dementia.org>
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Reviewed-on: http://gerrit.openafs.org/986

src/afs/afs_daemons.c
src/afs/afs_vcache.c

index 84dc396ca137eb9cc22e9dabde9dec52487434f5..bd5bba88ec5dbf9413f5ba861c179c0612e77361 100644 (file)
@@ -109,6 +109,11 @@ extern int vfs_context_ref;
 #else
 #define vfs_context_ref 1
 #endif
+
+/* This function always holds the GLOCK whilst it is running. The caller
+ * gets the GLOCK before invoking it, and afs_osi_Sleep drops the GLOCK
+ * whilst we are sleeping, and regains it when we're woken up.
+ */
 void
 afs_Daemon(void)
 {
@@ -201,10 +206,13 @@ afs_Daemon(void)
         else
         anumber = VCACHE_FREE + (afs_maxvcount - afs_cacheStats);
 
-        afs_ShakeLooseVCaches(anumber);
-        last5MinCheck = now;
+       ObtainWriteLock(&afs_xvcache, 734);
+       afs_ShakeLooseVCaches(anumber);
+       ReleaseWriteLock(&afs_xvcache);
+       last5MinCheck = now;
     }
 #endif
+
        if (!afs_CheckServerDaemonStarted) {
            /* Do the check here if the correct afsd is not installed. */
            if (!cs_warned) {
index 5568e429fed742b56c521637e6f24cfbf3d5d191..201bae7f17be8558196413adb0d2907c2d930099 100644 (file)
@@ -642,13 +642,6 @@ afs_ShakeLooseVCaches(afs_int32 anumber)
     struct afs_q *tq, *uq;
     int code, fv_slept;
     afs_int32 target = anumber;
-    int haveGlock = 1;
-
-    /* Should probably deal better */
-    if (!ISAFS_GLOCK()) {
-       haveGlock = 0;
-       AFS_GLOCK();
-    }
 
     if (
 #ifdef AFS_MAXVCOUNT_ENV
@@ -747,8 +740,6 @@ restart:
 /*
     printf("recycled %d entries\n", target-anumber);
 */
-    if (!haveGlock)
-       AFS_GUNLOCK();
 #endif
     return 0;
 }