afs: consolidate duplicated wait-for-cache-drain code 78/13278/8
authorMark Vitale <mvitale@sinenomine.net>
Thu, 9 Aug 2018 21:40:09 +0000 (17:40 -0400)
committerBenjamin Kaduk <kaduk@mit.edu>
Sun, 6 Dec 2020 22:38:01 +0000 (17:38 -0500)
Consolidate duplicated logic into a new routine
afs_MaybeWaitForCacheDrain().

Change-Id: I2e23b86eeaabe3bc559e3ddca5c1e03082af6a3f
Reviewed-on: https://gerrit.openafs.org/13278
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>

src/afs/SOLARIS/osi_vnodeops.c
src/afs/afs_dcache.c
src/afs/afs_prototypes.h

index 81147d5..a765449 100644 (file)
@@ -695,13 +695,7 @@ afs_nfsrdwr(struct vcache *avc, struct uio *auio, enum uio_rw arw,
     afs_MaybeWakeupTruncateDaemon();
     while ((arw == UIO_WRITE)
           && (afs_blocksUsed > PERCENT(CM_WAITFORDRAINPCT, afs_cacheBlocks))) {
-       if (afs_blocksUsed - afs_blocksDiscarded >
-           PERCENT(CM_WAITFORDRAINPCT, afs_cacheBlocks)) {
-           if (afs_WaitForCacheDrain == 0)
-               afs_WaitForCacheDrainCount++;
-           afs_WaitForCacheDrain = 1;
-           afs_osi_Sleep(&afs_WaitForCacheDrain);
-       }
+       afs_MaybeWaitForCacheDrain();
        afs_MaybeFreeDiscardedDCache();
        afs_MaybeWakeupTruncateDaemon();
     }
index 41eeb84..1e11b15 100644 (file)
@@ -408,6 +408,21 @@ afs_MaybeWakeupTruncateDaemon(void)
 }
 
 /*!
+ * Wait for cache drain if conditions warrant.
+ *   */
+void
+afs_MaybeWaitForCacheDrain(void)
+{
+    if (afs_blocksUsed - afs_blocksDiscarded >
+       PERCENT(CM_WAITFORDRAINPCT, afs_cacheBlocks)) {
+       if (afs_WaitForCacheDrain == 0)
+           afs_WaitForCacheDrainCount++;
+       afs_WaitForCacheDrain = 1;
+       afs_osi_Sleep(&afs_WaitForCacheDrain);
+    }
+}
+
+/*!
  * /struct CTD_stats
  *
  * Keep statistics on run time for afs_CacheTruncateDaemon. This is a
@@ -2438,10 +2453,7 @@ afs_GetDCache(struct vcache *avc, afs_size_t abyte,
            ReleaseReadLock(&avc->lock);
            while ((afs_blocksUsed - afs_blocksDiscarded) >
                   PERCENT(CM_WAITFORDRAINPCT, afs_cacheBlocks)) {
-               if (afs_WaitForCacheDrain == 0)
-                   afs_WaitForCacheDrainCount++;
-               afs_WaitForCacheDrain = 1;
-               afs_osi_Sleep(&afs_WaitForCacheDrain);
+               afs_MaybeWaitForCacheDrain();
            }
            afs_MaybeFreeDiscardedDCache();
            /* need to check if someone else got the chunk first. */
@@ -3784,13 +3796,7 @@ afs_ObtainDCacheForWriting(struct vcache *avc, afs_size_t filePos,
            while (afs_blocksUsed >
                   PERCENT(CM_WAITFORDRAINPCT, afs_cacheBlocks)) {
                ReleaseWriteLock(&avc->lock);
-               if (afs_blocksUsed - afs_blocksDiscarded >
-                   PERCENT(CM_WAITFORDRAINPCT, afs_cacheBlocks)) {
-                   if (afs_WaitForCacheDrain == 0)
-                       afs_WaitForCacheDrainCount++;
-                   afs_WaitForCacheDrain = 1;
-                   afs_osi_Sleep(&afs_WaitForCacheDrain);
-               }
+               afs_MaybeWaitForCacheDrain();
                afs_MaybeFreeDiscardedDCache();
                afs_MaybeWakeupTruncateDaemon();
                ObtainWriteLock(&avc->lock, 509);
index c0b00c6..a66976e 100644 (file)
@@ -265,6 +265,7 @@ extern struct dcache *afs_FindDCache(struct vcache *avc,
 extern void afs_StoreWarn(afs_int32 acode, afs_int32 avolume,
                          afs_int32 aflags);
 extern void afs_MaybeWakeupTruncateDaemon(void);
+extern void afs_MaybeWaitForCacheDrain(void);
 extern void afs_CacheTruncateDaemon(void);
 extern void afs_AdjustSize(struct dcache *adc,
                           afs_int32 newSize);