xref: /openbmc/linux/fs/ceph/cache.h (revision 53a2a90d)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Ceph cache definitions.
4  *
5  *  Copyright (C) 2013 by Adfin Solutions, Inc. All Rights Reserved.
6  *  Written by Milosz Tanski (milosz@adfin.com)
7  */
8 
9 #ifndef _CEPH_CACHE_H
10 #define _CEPH_CACHE_H
11 
12 #include <linux/netfs.h>
13 
14 #ifdef CONFIG_CEPH_FSCACHE
15 #include <linux/fscache.h>
16 
17 int ceph_fscache_register_fs(struct ceph_fs_client* fsc, struct fs_context *fc);
18 void ceph_fscache_unregister_fs(struct ceph_fs_client* fsc);
19 
20 void ceph_fscache_register_inode_cookie(struct inode *inode);
21 void ceph_fscache_unregister_inode_cookie(struct ceph_inode_info* ci);
22 
23 void ceph_fscache_use_cookie(struct inode *inode, bool will_modify);
24 void ceph_fscache_unuse_cookie(struct inode *inode, bool update);
25 
26 void ceph_fscache_update(struct inode *inode);
27 void ceph_fscache_invalidate(struct inode *inode, bool dio_write);
28 
29 static inline struct fscache_cookie *ceph_fscache_cookie(struct ceph_inode_info *ci)
30 {
31 	return netfs_i_cookie(&ci->netfs);
32 }
33 
34 static inline void ceph_fscache_resize(struct inode *inode, loff_t to)
35 {
36 	struct ceph_inode_info *ci = ceph_inode(inode);
37 	struct fscache_cookie *cookie = ceph_fscache_cookie(ci);
38 
39 	if (cookie) {
40 		ceph_fscache_use_cookie(inode, true);
41 		fscache_resize_cookie(cookie, to);
42 		ceph_fscache_unuse_cookie(inode, true);
43 	}
44 }
45 
46 static inline void ceph_fscache_unpin_writeback(struct inode *inode,
47 						struct writeback_control *wbc)
48 {
49 	fscache_unpin_writeback(wbc, ceph_fscache_cookie(ceph_inode(inode)));
50 }
51 
52 static inline int ceph_fscache_dirty_folio(struct address_space *mapping,
53 		struct folio *folio)
54 {
55 	struct ceph_inode_info *ci = ceph_inode(mapping->host);
56 
57 	return fscache_dirty_folio(mapping, folio, ceph_fscache_cookie(ci));
58 }
59 
60 static inline int ceph_begin_cache_operation(struct netfs_io_request *rreq)
61 {
62 	struct fscache_cookie *cookie = ceph_fscache_cookie(ceph_inode(rreq->inode));
63 
64 	return fscache_begin_read_operation(&rreq->cache_resources, cookie);
65 }
66 
67 static inline bool ceph_is_cache_enabled(struct inode *inode)
68 {
69 	return fscache_cookie_enabled(ceph_fscache_cookie(ceph_inode(inode)));
70 }
71 
72 static inline void ceph_fscache_note_page_release(struct inode *inode)
73 {
74 	struct ceph_inode_info *ci = ceph_inode(inode);
75 
76 	fscache_note_page_release(ceph_fscache_cookie(ci));
77 }
78 #else /* CONFIG_CEPH_FSCACHE */
79 static inline int ceph_fscache_register_fs(struct ceph_fs_client* fsc,
80 					   struct fs_context *fc)
81 {
82 	return 0;
83 }
84 
85 static inline void ceph_fscache_unregister_fs(struct ceph_fs_client* fsc)
86 {
87 }
88 
89 static inline void ceph_fscache_register_inode_cookie(struct inode *inode)
90 {
91 }
92 
93 static inline void ceph_fscache_unregister_inode_cookie(struct ceph_inode_info* ci)
94 {
95 }
96 
97 static inline void ceph_fscache_use_cookie(struct inode *inode, bool will_modify)
98 {
99 }
100 
101 static inline void ceph_fscache_unuse_cookie(struct inode *inode, bool update)
102 {
103 }
104 
105 static inline void ceph_fscache_update(struct inode *inode)
106 {
107 }
108 
109 static inline void ceph_fscache_invalidate(struct inode *inode, bool dio_write)
110 {
111 }
112 
113 static inline struct fscache_cookie *ceph_fscache_cookie(struct ceph_inode_info *ci)
114 {
115 	return NULL;
116 }
117 
118 static inline void ceph_fscache_resize(struct inode *inode, loff_t to)
119 {
120 }
121 
122 static inline void ceph_fscache_unpin_writeback(struct inode *inode,
123 						struct writeback_control *wbc)
124 {
125 }
126 
127 static inline int ceph_fscache_dirty_folio(struct address_space *mapping,
128 		struct folio *folio)
129 {
130 	return filemap_dirty_folio(mapping, folio);
131 }
132 
133 static inline bool ceph_is_cache_enabled(struct inode *inode)
134 {
135 	return false;
136 }
137 
138 static inline int ceph_begin_cache_operation(struct netfs_io_request *rreq)
139 {
140 	return -ENOBUFS;
141 }
142 
143 static inline void ceph_fscache_note_page_release(struct inode *inode)
144 {
145 }
146 #endif /* CONFIG_CEPH_FSCACHE */
147 
148 #endif
149