This source file includes following definitions.
- seconds_since_boot
- convert_to_wallclock
- cache_get
- cache_get_rcu
- cache_put
- cache_is_expired
- get_int
- get_uint
- get_time
- get_expiry
1
2
3
4
5
6
7
8
9
10
11 #ifndef _LINUX_SUNRPC_CACHE_H_
12 #define _LINUX_SUNRPC_CACHE_H_
13
14 #include <linux/kref.h>
15 #include <linux/slab.h>
16 #include <linux/atomic.h>
17 #include <linux/proc_fs.h>
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 struct cache_head {
47 struct hlist_node cache_list;
48 time_t expiry_time;
49 time_t last_refresh;
50
51
52
53
54 struct kref ref;
55 unsigned long flags;
56 };
57 #define CACHE_VALID 0
58 #define CACHE_NEGATIVE 1
59 #define CACHE_PENDING 2
60 #define CACHE_CLEANED 3
61
62 #define CACHE_NEW_EXPIRY 120
63
64 struct cache_detail {
65 struct module * owner;
66 int hash_size;
67 struct hlist_head * hash_table;
68 spinlock_t hash_lock;
69
70 char *name;
71 void (*cache_put)(struct kref *);
72
73 int (*cache_upcall)(struct cache_detail *,
74 struct cache_head *);
75
76 void (*cache_request)(struct cache_detail *cd,
77 struct cache_head *ch,
78 char **bpp, int *blen);
79
80 int (*cache_parse)(struct cache_detail *,
81 char *buf, int len);
82
83 int (*cache_show)(struct seq_file *m,
84 struct cache_detail *cd,
85 struct cache_head *h);
86 void (*warn_no_listener)(struct cache_detail *cd,
87 int has_died);
88
89 struct cache_head * (*alloc)(void);
90 void (*flush)(void);
91 int (*match)(struct cache_head *orig, struct cache_head *new);
92 void (*init)(struct cache_head *orig, struct cache_head *new);
93 void (*update)(struct cache_head *orig, struct cache_head *new);
94
95
96
97
98 time_t flush_time;
99
100
101
102
103
104 struct list_head others;
105 time_t nextcheck;
106 int entries;
107
108
109 struct list_head queue;
110
111 atomic_t writers;
112 time_t last_close;
113 time_t last_warn;
114
115 union {
116 struct proc_dir_entry *procfs;
117 struct dentry *pipefs;
118 };
119 struct net *net;
120 };
121
122
123
124
125
126
127 struct cache_req {
128 struct cache_deferred_req *(*defer)(struct cache_req *req);
129 int thread_wait;
130
131
132 };
133
134
135
136 struct cache_deferred_req {
137 struct hlist_node hash;
138 struct list_head recent;
139 struct cache_head *item;
140 void *owner;
141
142 void (*revisit)(struct cache_deferred_req *req,
143 int too_many);
144 };
145
146
147
148
149
150
151 static inline time_t seconds_since_boot(void)
152 {
153 struct timespec boot;
154 getboottime(&boot);
155 return get_seconds() - boot.tv_sec;
156 }
157
158 static inline time_t convert_to_wallclock(time_t sinceboot)
159 {
160 struct timespec boot;
161 getboottime(&boot);
162 return boot.tv_sec + sinceboot;
163 }
164
165 extern const struct file_operations cache_file_operations_pipefs;
166 extern const struct file_operations content_file_operations_pipefs;
167 extern const struct file_operations cache_flush_operations_pipefs;
168
169 extern struct cache_head *
170 sunrpc_cache_lookup_rcu(struct cache_detail *detail,
171 struct cache_head *key, int hash);
172 extern struct cache_head *
173 sunrpc_cache_update(struct cache_detail *detail,
174 struct cache_head *new, struct cache_head *old, int hash);
175
176 extern int
177 sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h);
178
179
180 extern void cache_clean_deferred(void *owner);
181
182 static inline struct cache_head *cache_get(struct cache_head *h)
183 {
184 kref_get(&h->ref);
185 return h;
186 }
187
188 static inline struct cache_head *cache_get_rcu(struct cache_head *h)
189 {
190 if (kref_get_unless_zero(&h->ref))
191 return h;
192 return NULL;
193 }
194
195 static inline void cache_put(struct cache_head *h, struct cache_detail *cd)
196 {
197 if (kref_read(&h->ref) <= 2 &&
198 h->expiry_time < cd->nextcheck)
199 cd->nextcheck = h->expiry_time;
200 kref_put(&h->ref, cd->cache_put);
201 }
202
203 static inline bool cache_is_expired(struct cache_detail *detail, struct cache_head *h)
204 {
205 if (!test_bit(CACHE_VALID, &h->flags))
206 return false;
207
208 return (h->expiry_time < seconds_since_boot()) ||
209 (detail->flush_time >= h->last_refresh);
210 }
211
212 extern int cache_check(struct cache_detail *detail,
213 struct cache_head *h, struct cache_req *rqstp);
214 extern void cache_flush(void);
215 extern void cache_purge(struct cache_detail *detail);
216 #define NEVER (0x7FFFFFFF)
217 extern void __init cache_initialize(void);
218 extern int cache_register_net(struct cache_detail *cd, struct net *net);
219 extern void cache_unregister_net(struct cache_detail *cd, struct net *net);
220
221 extern struct cache_detail *cache_create_net(const struct cache_detail *tmpl, struct net *net);
222 extern void cache_destroy_net(struct cache_detail *cd, struct net *net);
223
224 extern void sunrpc_init_cache_detail(struct cache_detail *cd);
225 extern void sunrpc_destroy_cache_detail(struct cache_detail *cd);
226 extern int sunrpc_cache_register_pipefs(struct dentry *parent, const char *,
227 umode_t, struct cache_detail *);
228 extern void sunrpc_cache_unregister_pipefs(struct cache_detail *);
229 extern void sunrpc_cache_unhash(struct cache_detail *, struct cache_head *);
230
231
232 extern void *cache_seq_start_rcu(struct seq_file *file, loff_t *pos);
233 extern void *cache_seq_next_rcu(struct seq_file *file, void *p, loff_t *pos);
234 extern void cache_seq_stop_rcu(struct seq_file *file, void *p);
235
236 extern void qword_add(char **bpp, int *lp, char *str);
237 extern void qword_addhex(char **bpp, int *lp, char *buf, int blen);
238 extern int qword_get(char **bpp, char *dest, int bufsize);
239
240 static inline int get_int(char **bpp, int *anint)
241 {
242 char buf[50];
243 char *ep;
244 int rv;
245 int len = qword_get(bpp, buf, sizeof(buf));
246
247 if (len < 0)
248 return -EINVAL;
249 if (len == 0)
250 return -ENOENT;
251
252 rv = simple_strtol(buf, &ep, 0);
253 if (*ep)
254 return -EINVAL;
255
256 *anint = rv;
257 return 0;
258 }
259
260 static inline int get_uint(char **bpp, unsigned int *anint)
261 {
262 char buf[50];
263 int len = qword_get(bpp, buf, sizeof(buf));
264
265 if (len < 0)
266 return -EINVAL;
267 if (len == 0)
268 return -ENOENT;
269
270 if (kstrtouint(buf, 0, anint))
271 return -EINVAL;
272
273 return 0;
274 }
275
276 static inline int get_time(char **bpp, time_t *time)
277 {
278 char buf[50];
279 long long ll;
280 int len = qword_get(bpp, buf, sizeof(buf));
281
282 if (len < 0)
283 return -EINVAL;
284 if (len == 0)
285 return -ENOENT;
286
287 if (kstrtoll(buf, 0, &ll))
288 return -EINVAL;
289
290 *time = (time_t)ll;
291 return 0;
292 }
293
294 static inline time_t get_expiry(char **bpp)
295 {
296 time_t rv;
297 struct timespec boot;
298
299 if (get_time(bpp, &rv))
300 return 0;
301 if (rv < 0)
302 return 0;
303 getboottime(&boot);
304 return rv - boot.tv_sec;
305 }
306
307 #endif