afs: consolidate duplicated wait-for-cache-drain code

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>
This commit is contained in:
Mark Vitale 2018-08-09 17:40:09 -04:00 committed by Benjamin Kaduk
parent 25792e2463
commit 23bd776b01
3 changed files with 19 additions and 18 deletions

View 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();
}

View File

@ -407,6 +407,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
*
@ -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);

View 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);