From: Jeffrey Altman Date: Mon, 9 Sep 2013 16:17:36 +0000 (-0400) Subject: afs: Introduce afs_WakeCacheWaitersIfDrained X-Git-Tag: openafs-stable-1_8_0pre1~950 X-Git-Url: https://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=765d964f13e49fe94a9a75839571fbffa04a0b65 afs: Introduce afs_WakeCacheWaitersIfDrained Consolidate common code into afs_WakeCacheWaitersIfDrained(). Change-Id: I10e35afbc1f1469038e111a7bbd209c8897c8972 Reviewed-on: http://gerrit.openafs.org/10233 Tested-by: BuildBot Reviewed-by: Marc Dionne Reviewed-by: Derrick Brashear --- diff --git a/src/afs/afs_dcache.c b/src/afs/afs_dcache.c index f7476a0..402de4f 100644 --- a/src/afs/afs_dcache.c +++ b/src/afs/afs_dcache.c @@ -396,6 +396,26 @@ static struct CTD_stats { u_int afs_min_cache = 0; /*! + * If there are waiters for the cache to drain, wake them if + * the number of free cache blocks reaches the CM_CACHESIZEDDRAINEDPCT. + * + * \note Environment: + * This routine must be called with the afs_xdcache lock held + * (in write mode). + */ +static void +afs_WakeCacheWaitersIfDrained(void) +{ + if (afs_WaitForCacheDrain) { + if ((afs_blocksUsed - afs_blocksDiscarded) <= + PERCENT(CM_CACHESIZEDRAINEDPCT, afs_cacheBlocks)) { + afs_WaitForCacheDrain = 0; + afs_osi_Wakeup(&afs_WaitForCacheDrain); + } + } +} + +/*! * Keeps the cache clean and free by truncating uneeded files, when used. * \param * \return @@ -988,13 +1008,7 @@ afs_FlushDCache(struct dcache *adc) afs_FreeDCache(adc); } - if (afs_WaitForCacheDrain) { - if ((afs_blocksUsed - afs_blocksDiscarded) <= - PERCENT(CM_CACHESIZEDRAINEDPCT, afs_cacheBlocks)) { - afs_WaitForCacheDrain = 0; - afs_osi_Wakeup(&afs_WaitForCacheDrain); - } - } + afs_WakeCacheWaitersIfDrained(); } /*afs_FlushDCache */ @@ -1019,13 +1033,7 @@ afs_FreeDCache(struct dcache *adc) afs_indexFlags[adc->index] |= IFFree; adc->dflags |= DFEntryMod; - if (afs_WaitForCacheDrain) { - if ((afs_blocksUsed - afs_blocksDiscarded) <= - PERCENT(CM_CACHESIZEDRAINEDPCT, afs_cacheBlocks)) { - afs_WaitForCacheDrain = 0; - afs_osi_Wakeup(&afs_WaitForCacheDrain); - } - } + afs_WakeCacheWaitersIfDrained(); } /* afs_FreeDCache */ /*! @@ -1065,14 +1073,7 @@ afs_DiscardDCache(struct dcache *adc) adc->dflags |= DFEntryMod; afs_indexFlags[adc->index] |= IFDiscarded; - if (afs_WaitForCacheDrain) { - if ((afs_blocksUsed - afs_blocksDiscarded) <= - PERCENT(CM_CACHESIZEDRAINEDPCT, afs_cacheBlocks)) { - afs_WaitForCacheDrain = 0; - afs_osi_Wakeup(&afs_WaitForCacheDrain); - } - } - + afs_WakeCacheWaitersIfDrained(); } /*afs_DiscardDCache */ /**