Add new helper to check if fscache enabled for cifs inode Signed-off-by: David Howells <dhowells@xxxxxxxxxx> Signed-off-by: Steve French <stfrench@xxxxxxxxxxxxx> --- fs/cifs/file.c | 7 +++++++ fs/cifs/fscache.h | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 4b8c1ac58f00..49e7cf701b3e 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -4287,6 +4287,13 @@ cifs_readpages_copy_into_pages(struct TCP_Server_Info *server, return readpages_fill_pages(server, rdata, iter, iter->count); } +static bool cifs_is_cache_enabled(struct inode *inode) +{ + struct fscache_cookie *cookie = cifs_inode_cookie(inode); + + return fscache_cookie_enabled(cookie) && !hlist_empty(&cookie->backing_objects); +} + static int readpages_get_pages(struct address_space *mapping, struct list_head *page_list, unsigned int rsize, struct list_head *tmplist, diff --git a/fs/cifs/fscache.h b/fs/cifs/fscache.h index e811f2dd7619..713c0da1bad0 100644 --- a/fs/cifs/fscache.h +++ b/fs/cifs/fscache.h @@ -70,6 +70,10 @@ extern void cifs_fscache_release_inode_cookie(struct inode *); extern void cifs_fscache_set_inode_cookie(struct inode *, struct file *); extern void cifs_fscache_reset_inode_cookie(struct inode *); +static inline struct fscache_cookie *cifs_inode_cookie(struct inode *inode) +{ + return CIFS_I(inode)->fscache; +} extern void __cifs_fscache_invalidate_page(struct page *, struct inode *); extern int cifs_fscache_release_page(struct page *page, gfp_t gfp); extern int __cifs_readpage_from_fscache(struct inode *, struct page *); @@ -138,6 +142,7 @@ static inline void cifs_fscache_release_inode_cookie(struct inode *inode) {} static inline void cifs_fscache_set_inode_cookie(struct inode *inode, struct file *filp) {} static inline void cifs_fscache_reset_inode_cookie(struct inode *inode) {} +static inline struct fscache_cookie *cifs_inode_cookie(struct inode *inode) { return NULL; } static inline int cifs_fscache_release_page(struct page *page, gfp_t gfp) { return 1; /* May release page */ -- Thanks, Steve
From 0f9488f68edbaf63db9f56e241d038685921630d Mon Sep 17 00:00:00 2001 From: David Howells <dhowells@xxxxxxxxxx> Date: Thu, 4 Feb 2021 01:23:04 -0600 Subject: [PATCH] cifs: add new helper function for fscache conversion Add new helper to check if fscache enabled for cifs inode Signed-off-by: David Howells <dhowells@xxxxxxxxxx> Signed-off-by: Steve French <stfrench@xxxxxxxxxxxxx> --- fs/cifs/file.c | 7 +++++++ fs/cifs/fscache.h | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 4b8c1ac58f00..49e7cf701b3e 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -4287,6 +4287,13 @@ cifs_readpages_copy_into_pages(struct TCP_Server_Info *server, return readpages_fill_pages(server, rdata, iter, iter->count); } +static bool cifs_is_cache_enabled(struct inode *inode) +{ + struct fscache_cookie *cookie = cifs_inode_cookie(inode); + + return fscache_cookie_enabled(cookie) && !hlist_empty(&cookie->backing_objects); +} + static int readpages_get_pages(struct address_space *mapping, struct list_head *page_list, unsigned int rsize, struct list_head *tmplist, diff --git a/fs/cifs/fscache.h b/fs/cifs/fscache.h index e811f2dd7619..713c0da1bad0 100644 --- a/fs/cifs/fscache.h +++ b/fs/cifs/fscache.h @@ -70,6 +70,10 @@ extern void cifs_fscache_release_inode_cookie(struct inode *); extern void cifs_fscache_set_inode_cookie(struct inode *, struct file *); extern void cifs_fscache_reset_inode_cookie(struct inode *); +static inline struct fscache_cookie *cifs_inode_cookie(struct inode *inode) +{ + return CIFS_I(inode)->fscache; +} extern void __cifs_fscache_invalidate_page(struct page *, struct inode *); extern int cifs_fscache_release_page(struct page *page, gfp_t gfp); extern int __cifs_readpage_from_fscache(struct inode *, struct page *); @@ -138,6 +142,7 @@ static inline void cifs_fscache_release_inode_cookie(struct inode *inode) {} static inline void cifs_fscache_set_inode_cookie(struct inode *inode, struct file *filp) {} static inline void cifs_fscache_reset_inode_cookie(struct inode *inode) {} +static inline struct fscache_cookie *cifs_inode_cookie(struct inode *inode) { return NULL; } static inline int cifs_fscache_release_page(struct page *page, gfp_t gfp) { return 1; /* May release page */ -- 2.27.0