xref: /openbmc/linux/fs/ceph/cache.h (revision e81fb419)
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 {
31*e81fb419SLinus 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)46400e1286SJeff Layton static inline void ceph_fscache_unpin_writeback(struct inode *inode,
47400e1286SJeff Layton 						struct writeback_control *wbc)
48f0702876SJeff Layton {
49400e1286SJeff Layton 	fscache_unpin_writeback(wbc, ceph_fscache_cookie(ceph_inode(inode)));
50400e1286SJeff Layton }
51f0702876SJeff Layton 
ceph_fscache_dirty_folio(struct address_space * mapping,struct folio * folio)528fb72b4aSMatthew Wilcox (Oracle) static inline int ceph_fscache_dirty_folio(struct address_space *mapping,
538fb72b4aSMatthew Wilcox (Oracle) 		struct folio *folio)
54400e1286SJeff Layton {
558fb72b4aSMatthew Wilcox (Oracle) 	struct ceph_inode_info *ci = ceph_inode(mapping->host);
56400e1286SJeff Layton 
578fb72b4aSMatthew Wilcox (Oracle) 	return fscache_dirty_folio(mapping, folio, ceph_fscache_cookie(ci));
58f0702876SJeff Layton }
59f0702876SJeff Layton 
ceph_begin_cache_operation(struct netfs_io_request * rreq)606a19114bSDavid Howells static inline int ceph_begin_cache_operation(struct netfs_io_request *rreq)
61f0702876SJeff Layton {
62f0702876SJeff Layton 	struct fscache_cookie *cookie = ceph_fscache_cookie(ceph_inode(rreq->inode));
63f0702876SJeff Layton 
64400e1286SJeff Layton 	return fscache_begin_read_operation(&rreq->cache_resources, cookie);
65f0702876SJeff Layton }
6699ccbd22SMilosz Tanski 
ceph_is_cache_enabled(struct inode * inode)67400e1286SJeff Layton static inline bool ceph_is_cache_enabled(struct inode *inode)
6899ccbd22SMilosz Tanski {
69400e1286SJeff Layton 	return fscache_cookie_enabled(ceph_fscache_cookie(ceph_inode(inode)));
7099ccbd22SMilosz Tanski }
7199ccbd22SMilosz Tanski 
ceph_fscache_note_page_release(struct inode * inode)72400e1286SJeff Layton static inline void ceph_fscache_note_page_release(struct inode *inode)
7399ccbd22SMilosz Tanski {
74400e1286SJeff Layton 	struct ceph_inode_info *ci = ceph_inode(inode);
7599ccbd22SMilosz Tanski 
76400e1286SJeff Layton 	fscache_note_page_release(ceph_fscache_cookie(ci));
77400e1286SJeff Layton }
78400e1286SJeff Layton #else /* CONFIG_CEPH_FSCACHE */
ceph_fscache_register_fs(struct ceph_fs_client * fsc,struct fs_context * fc)7982995cc6SDavid Howells static inline int ceph_fscache_register_fs(struct ceph_fs_client* fsc,
8082995cc6SDavid Howells 					   struct fs_context *fc)
8199ccbd22SMilosz Tanski {
8299ccbd22SMilosz Tanski 	return 0;
8399ccbd22SMilosz Tanski }
8499ccbd22SMilosz Tanski 
ceph_fscache_unregister_fs(struct ceph_fs_client * fsc)8599ccbd22SMilosz Tanski static inline void ceph_fscache_unregister_fs(struct ceph_fs_client* fsc)
8699ccbd22SMilosz Tanski {
8799ccbd22SMilosz Tanski }
8899ccbd22SMilosz Tanski 
ceph_fscache_register_inode_cookie(struct inode * inode)8946b59b2bSYan, Zheng static inline void ceph_fscache_register_inode_cookie(struct inode *inode)
9046b59b2bSYan, Zheng {
9146b59b2bSYan, Zheng }
9246b59b2bSYan, Zheng 
ceph_fscache_unregister_inode_cookie(struct ceph_inode_info * ci)9346b59b2bSYan, Zheng static inline void ceph_fscache_unregister_inode_cookie(struct ceph_inode_info* ci)
9446b59b2bSYan, Zheng {
9546b59b2bSYan, Zheng }
9646b59b2bSYan, Zheng 
ceph_fscache_use_cookie(struct inode * inode,bool will_modify)97400e1286SJeff Layton static inline void ceph_fscache_use_cookie(struct inode *inode, bool will_modify)
9899ccbd22SMilosz Tanski {
9999ccbd22SMilosz Tanski }
10099ccbd22SMilosz Tanski 
ceph_fscache_unuse_cookie(struct inode * inode,bool update)101400e1286SJeff Layton static inline void ceph_fscache_unuse_cookie(struct inode *inode, bool update)
10299ccbd22SMilosz Tanski {
10399ccbd22SMilosz Tanski }
10499ccbd22SMilosz Tanski 
ceph_fscache_update(struct inode * inode)105400e1286SJeff Layton static inline void ceph_fscache_update(struct inode *inode)
106400e1286SJeff Layton {
107400e1286SJeff Layton }
108400e1286SJeff Layton 
ceph_fscache_invalidate(struct inode * inode,bool dio_write)109400e1286SJeff Layton static inline void ceph_fscache_invalidate(struct inode *inode, bool dio_write)
110400e1286SJeff Layton {
111400e1286SJeff Layton }
112400e1286SJeff Layton 
ceph_fscache_cookie(struct ceph_inode_info * ci)113400e1286SJeff Layton static inline struct fscache_cookie *ceph_fscache_cookie(struct ceph_inode_info *ci)
114400e1286SJeff Layton {
115400e1286SJeff Layton 	return NULL;
116400e1286SJeff Layton }
117400e1286SJeff Layton 
ceph_fscache_resize(struct inode * inode,loff_t to)118400e1286SJeff Layton static inline void ceph_fscache_resize(struct inode *inode, loff_t to)
119400e1286SJeff Layton {
120400e1286SJeff Layton }
121400e1286SJeff Layton 
ceph_fscache_unpin_writeback(struct inode * inode,struct writeback_control * wbc)122400e1286SJeff Layton static inline void ceph_fscache_unpin_writeback(struct inode *inode,
123400e1286SJeff Layton 						struct writeback_control *wbc)
124400e1286SJeff Layton {
125400e1286SJeff Layton }
126400e1286SJeff Layton 
ceph_fscache_dirty_folio(struct address_space * mapping,struct folio * folio)1278fb72b4aSMatthew Wilcox (Oracle) static inline int ceph_fscache_dirty_folio(struct address_space *mapping,
1288fb72b4aSMatthew Wilcox (Oracle) 		struct folio *folio)
129400e1286SJeff Layton {
1308fb72b4aSMatthew Wilcox (Oracle) 	return filemap_dirty_folio(mapping, folio);
131400e1286SJeff Layton }
132400e1286SJeff Layton 
ceph_is_cache_enabled(struct inode * inode)133f0702876SJeff Layton static inline bool ceph_is_cache_enabled(struct inode *inode)
134f0702876SJeff Layton {
135f0702876SJeff Layton 	return false;
136f0702876SJeff Layton }
137f0702876SJeff Layton 
ceph_begin_cache_operation(struct netfs_io_request * rreq)1386a19114bSDavid Howells static inline int ceph_begin_cache_operation(struct netfs_io_request *rreq)
139f0702876SJeff Layton {
140f0702876SJeff Layton 	return -ENOBUFS;
141f0702876SJeff Layton }
14299ccbd22SMilosz Tanski 
ceph_fscache_note_page_release(struct inode * inode)143400e1286SJeff Layton static inline void ceph_fscache_note_page_release(struct inode *inode)
144400e1286SJeff Layton {
145400e1286SJeff Layton }
146400e1286SJeff Layton #endif /* CONFIG_CEPH_FSCACHE */
147400e1286SJeff Layton 
148400e1286SJeff Layton #endif
149