From b56a794f8d77987df07d2efcb8af5f9d63f6e678 Mon Sep 17 00:00:00 2001 From: Simon Wilkinson Date: Wed, 23 Sep 2009 18:18:34 +0100 Subject: [PATCH] Refactor the cache bypass determination code The code which determines whether the cache can be bypassed occurs in multiple locations in this file. Make a single static inline function that can do this, and use it. Reviewed-on: http://gerrit.openafs.org/489 Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- src/afs/LINUX/osi_vnodeops.c | 46 +++++++++++++----------------------- 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/src/afs/LINUX/osi_vnodeops.c b/src/afs/LINUX/osi_vnodeops.c index c874772e87..a93162001c 100644 --- a/src/afs/LINUX/osi_vnodeops.c +++ b/src/afs/LINUX/osi_vnodeops.c @@ -1605,6 +1605,21 @@ afs_linux_follow_link(struct dentry *dp, struct dentry *basep, #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) +static inline int +afs_linux_can_bypass(struct inode *ip) { + switch(cache_bypass_strategy) { + case NEVER_BYPASS_CACHE: + return 0; + case ALWAYS_BYPASS_CACHE: + return 1; + case LARGE_FILES_BYPASS_CACHE: + if(i_size_read(ip) > cache_bypass_threshold) + return 1; + default: + } + return 0; +} + /* The kernel calls readpages before trying readpage, with a list of * pages. The readahead algorithm expands num_pages when it thinks * the application will benefit. Unlike readpage, the pages are not @@ -1634,21 +1649,7 @@ afs_linux_readpages(struct file *fp, struct address_space *mapping, afs_int32 isize; credp = crref(); - - switch(cache_bypass_strategy) { - case NEVER_BYPASS_CACHE: - break; - case ALWAYS_BYPASS_CACHE: - bypasscache = 1; - break; - case LARGE_FILES_BYPASS_CACHE: - if(i_size_read(ip) > cache_bypass_threshold) { - bypasscache = 1; - } - break; - default: - break; - } + bypasscache = afs_linux_can_bypass(ip); /* In the new incarnation of selective caching, a file's caching policy * can change, eg because file size exceeds threshold, etc. */ @@ -1810,20 +1811,7 @@ afs_linux_readpage(struct file *fp, struct page *pp) AFS_UIOSYS); #if defined(AFS_CACHE_BYPASS) - switch(cache_bypass_strategy) { - case NEVER_BYPASS_CACHE: - break; - case ALWAYS_BYPASS_CACHE: - bypasscache = 1; - break; - case LARGE_FILES_BYPASS_CACHE: - if(i_size_read(ip) > cache_bypass_threshold) { - bypasscache = 1; - } - break; - default: - break; - } + bypasscache = afs_linux_can_bypass(ip); /* In the new incarnation of selective caching, a file's caching policy * can change, eg because file size exceeds threshold, etc. */