xref: /linux/fs/ceph/cache.h (revision 06d07429858317ded2db7986113a9e0129cd599b)
11f327613SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
299ccbd22SMilosz Tanski /*
399ccbd22SMilosz Tanski  * Ceph cache definitions.
499ccbd22SMilosz Tanski  *
599ccbd22SMilosz Tanski  *  Copyright (C) 2013 by Adfin Solutions, Inc. All Rights Reserved.
699ccbd22SMilosz Tanski  *  Written by Milosz Tanski (milosz@adfin.com)
799ccbd22SMilosz Tanski  */
899ccbd22SMilosz Tanski 
999ccbd22SMilosz Tanski #ifndef _CEPH_CACHE_H
1099ccbd22SMilosz Tanski #define _CEPH_CACHE_H
1199ccbd22SMilosz Tanski 
12f0702876SJeff Layton #include <linux/netfs.h>
13f0702876SJeff Layton 
1499ccbd22SMilosz Tanski #ifdef CONFIG_CEPH_FSCACHE
15400e1286SJeff Layton #include <linux/fscache.h>
1699ccbd22SMilosz Tanski 
1782995cc6SDavid Howells int ceph_fscache_register_fs(struct ceph_fs_client* fsc, struct fs_context *fc);
1899ccbd22SMilosz Tanski void ceph_fscache_unregister_fs(struct ceph_fs_client* fsc);
1999ccbd22SMilosz Tanski 
2046b59b2bSYan, Zheng void ceph_fscache_register_inode_cookie(struct inode *inode);
2199ccbd22SMilosz Tanski void ceph_fscache_unregister_inode_cookie(struct ceph_inode_info* ci);
22400e1286SJeff Layton 
23400e1286SJeff Layton void ceph_fscache_use_cookie(struct inode *inode, bool will_modify);
24400e1286SJeff Layton void ceph_fscache_unuse_cookie(struct inode *inode, bool update);
25400e1286SJeff Layton 
26400e1286SJeff Layton void ceph_fscache_update(struct inode *inode);
27400e1286SJeff Layton void ceph_fscache_invalidate(struct inode *inode, bool dio_write);
2899ccbd22SMilosz Tanski 
ceph_fscache_cookie(struct ceph_inode_info * ci)29f0702876SJeff Layton static inline struct fscache_cookie *ceph_fscache_cookie(struct ceph_inode_info *ci)
30f0702876SJeff Layton {
31e81fb419SLinus Torvalds 	return netfs_i_cookie(&ci->netfs);
32f0702876SJeff Layton }
33f0702876SJeff Layton 
ceph_fscache_resize(struct inode * inode,loff_t to)34400e1286SJeff Layton static inline void ceph_fscache_resize(struct inode *inode, loff_t to)
3599ccbd22SMilosz Tanski {
36400e1286SJeff Layton 	struct ceph_inode_info *ci = ceph_inode(inode);
37400e1286SJeff Layton 	struct fscache_cookie *cookie = ceph_fscache_cookie(ci);
38400e1286SJeff Layton 
39400e1286SJeff Layton 	if (cookie) {
40400e1286SJeff Layton 		ceph_fscache_use_cookie(inode, true);
41400e1286SJeff Layton 		fscache_resize_cookie(cookie, to);
42400e1286SJeff Layton 		ceph_fscache_unuse_cookie(inode, true);
43400e1286SJeff Layton 	}
4499ccbd22SMilosz Tanski }
4599ccbd22SMilosz Tanski 
ceph_fscache_unpin_writeback(struct inode * inode,struct writeback_control * wbc)46*c9c4ff12SDavid Howells static inline int ceph_fscache_unpin_writeback(struct inode *inode,
47400e1286SJeff Layton 						struct writeback_control *wbc)
48f0702876SJeff Layton {
49*c9c4ff12SDavid Howells 	return netfs_unpin_writeback(inode, wbc);
50400e1286SJeff Layton }
51f0702876SJeff Layton 
52*c9c4ff12SDavid Howells #define ceph_fscache_dirty_folio netfs_dirty_folio
53f0702876SJeff Layton 
ceph_is_cache_enabled(struct inode * inode)54400e1286SJeff Layton static inline bool ceph_is_cache_enabled(struct inode *inode)
5599ccbd22SMilosz Tanski {
56400e1286SJeff Layton 	return fscache_cookie_enabled(ceph_fscache_cookie(ceph_inode(inode)));
5799ccbd22SMilosz Tanski }
5899ccbd22SMilosz Tanski 
59400e1286SJeff Layton #else /* CONFIG_CEPH_FSCACHE */
ceph_fscache_register_fs(struct ceph_fs_client * fsc,struct fs_context * fc)6082995cc6SDavid Howells static inline int ceph_fscache_register_fs(struct ceph_fs_client* fsc,
6182995cc6SDavid Howells 					   struct fs_context *fc)
6299ccbd22SMilosz Tanski {
6399ccbd22SMilosz Tanski 	return 0;
6499ccbd22SMilosz Tanski }
6599ccbd22SMilosz Tanski 
ceph_fscache_unregister_fs(struct ceph_fs_client * fsc)6699ccbd22SMilosz Tanski static inline void ceph_fscache_unregister_fs(struct ceph_fs_client* fsc)
6799ccbd22SMilosz Tanski {
6899ccbd22SMilosz Tanski }
6999ccbd22SMilosz Tanski 
ceph_fscache_register_inode_cookie(struct inode * inode)7046b59b2bSYan, Zheng static inline void ceph_fscache_register_inode_cookie(struct inode *inode)
7146b59b2bSYan, Zheng {
7246b59b2bSYan, Zheng }
7346b59b2bSYan, Zheng 
ceph_fscache_unregister_inode_cookie(struct ceph_inode_info * ci)7446b59b2bSYan, Zheng static inline void ceph_fscache_unregister_inode_cookie(struct ceph_inode_info* ci)
7546b59b2bSYan, Zheng {
7646b59b2bSYan, Zheng }
7746b59b2bSYan, Zheng 
ceph_fscache_use_cookie(struct inode * inode,bool will_modify)78400e1286SJeff Layton static inline void ceph_fscache_use_cookie(struct inode *inode, bool will_modify)
7999ccbd22SMilosz Tanski {
8099ccbd22SMilosz Tanski }
8199ccbd22SMilosz Tanski 
ceph_fscache_unuse_cookie(struct inode * inode,bool update)82400e1286SJeff Layton static inline void ceph_fscache_unuse_cookie(struct inode *inode, bool update)
8399ccbd22SMilosz Tanski {
8499ccbd22SMilosz Tanski }
8599ccbd22SMilosz Tanski 
ceph_fscache_update(struct inode * inode)86400e1286SJeff Layton static inline void ceph_fscache_update(struct inode *inode)
87400e1286SJeff Layton {
88400e1286SJeff Layton }
89400e1286SJeff Layton 
ceph_fscache_invalidate(struct inode * inode,bool dio_write)90400e1286SJeff Layton static inline void ceph_fscache_invalidate(struct inode *inode, bool dio_write)
91400e1286SJeff Layton {
92400e1286SJeff Layton }
93400e1286SJeff Layton 
ceph_fscache_cookie(struct ceph_inode_info * ci)94400e1286SJeff Layton static inline struct fscache_cookie *ceph_fscache_cookie(struct ceph_inode_info *ci)
95400e1286SJeff Layton {
96400e1286SJeff Layton 	return NULL;
97400e1286SJeff Layton }
98400e1286SJeff Layton 
ceph_fscache_resize(struct inode * inode,loff_t to)99400e1286SJeff Layton static inline void ceph_fscache_resize(struct inode *inode, loff_t to)
100400e1286SJeff Layton {
101400e1286SJeff Layton }
102400e1286SJeff Layton 
ceph_fscache_unpin_writeback(struct inode * inode,struct writeback_control * wbc)103*c9c4ff12SDavid Howells static inline int ceph_fscache_unpin_writeback(struct inode *inode,
104400e1286SJeff Layton 					       struct writeback_control *wbc)
105400e1286SJeff Layton {
106*c9c4ff12SDavid Howells 	return 0;
107400e1286SJeff Layton }
108400e1286SJeff Layton 
109*c9c4ff12SDavid Howells #define ceph_fscache_dirty_folio filemap_dirty_folio
110400e1286SJeff Layton 
ceph_is_cache_enabled(struct inode * inode)111f0702876SJeff Layton static inline bool ceph_is_cache_enabled(struct inode *inode)
112f0702876SJeff Layton {
113f0702876SJeff Layton 	return false;
114f0702876SJeff Layton }
115400e1286SJeff Layton #endif /* CONFIG_CEPH_FSCACHE */
116400e1286SJeff Layton 
117400e1286SJeff Layton #endif
118