From 765d964f13e49fe94a9a75839571fbffa04a0b65 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Mon, 9 Sep 2013 12:17:36 -0400 Subject: [PATCH] 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 --- src/afs/afs_dcache.c | 45 ++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/src/afs/afs_dcache.c b/src/afs/afs_dcache.c index f7476a064..402de4f83 100644 --- a/src/afs/afs_dcache.c +++ b/src/afs/afs_dcache.c @@ -395,6 +395,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 @@ -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 */ /** -- 2.39.5