1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef _LINUX_SUNRPC_CACHE_H_
14#define _LINUX_SUNRPC_CACHE_H_
15
16#include <linux/slab.h>
17#include <asm/atomic.h>
18#include <linux/proc_fs.h>
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
47struct cache_head {
48 struct cache_head * next;
49 time_t expiry_time;
50 time_t last_refresh;
51
52
53 struct kref ref;
54 unsigned long flags;
55};
56#define CACHE_VALID 0
57#define CACHE_NEGATIVE 1
58#define CACHE_PENDING 2
59
60#define CACHE_NEW_EXPIRY 120
61
62struct cache_detail_procfs {
63 struct proc_dir_entry *proc_ent;
64 struct proc_dir_entry *flush_ent, *channel_ent, *content_ent;
65};
66
67struct cache_detail_pipefs {
68 struct dentry *dir;
69};
70
71struct cache_detail {
72 struct module * owner;
73 int hash_size;
74 struct cache_head ** hash_table;
75 rwlock_t hash_lock;
76
77 atomic_t inuse;
78
79 char *name;
80 void (*cache_put)(struct kref *);
81
82 int (*cache_upcall)(struct cache_detail *,
83 struct cache_head *);
84
85 int (*cache_parse)(struct cache_detail *,
86 char *buf, int len);
87
88 int (*cache_show)(struct seq_file *m,
89 struct cache_detail *cd,
90 struct cache_head *h);
91 void (*warn_no_listener)(struct cache_detail *cd,
92 int has_died);
93
94 struct cache_head * (*alloc)(void);
95 int (*match)(struct cache_head *orig, struct cache_head *new);
96 void (*init)(struct cache_head *orig, struct cache_head *new);
97 void (*update)(struct cache_head *orig, struct cache_head *new);
98
99
100
101
102 time_t flush_time;
103
104 struct list_head others;
105 time_t nextcheck;
106 int entries;
107
108
109 struct list_head queue;
110
111 atomic_t readers;
112 time_t last_close;
113 time_t last_warn;
114
115 union {
116 struct cache_detail_procfs procfs;
117 struct cache_detail_pipefs pipefs;
118 } u;
119};
120
121
122
123
124
125
126struct cache_req {
127 struct cache_deferred_req *(*defer)(struct cache_req *req);
128};
129
130
131
132struct cache_deferred_req {
133 struct list_head hash;
134 struct list_head recent;
135 struct cache_head *item;
136 void *owner;
137
138 void (*revisit)(struct cache_deferred_req *req,
139 int too_many);
140};
141
142
143extern const struct file_operations cache_file_operations_pipefs;
144extern const struct file_operations content_file_operations_pipefs;
145extern const struct file_operations cache_flush_operations_pipefs;
146
147extern struct cache_head *
148sunrpc_cache_lookup(struct cache_detail *detail,
149 struct cache_head *key, int hash);
150extern struct cache_head *
151sunrpc_cache_update(struct cache_detail *detail,
152 struct cache_head *new, struct cache_head *old, int hash);
153
154extern int
155sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h,
156 void (*cache_request)(struct cache_detail *,
157 struct cache_head *,
158 char **,
159 int *));
160
161
162extern void cache_clean_deferred(void *owner);
163
164static inline struct cache_head *cache_get(struct cache_head *h)
165{
166 kref_get(&h->ref);
167 return h;
168}
169
170
171static inline void cache_put(struct cache_head *h, struct cache_detail *cd)
172{
173 if (atomic_read(&h->ref.refcount) <= 2 &&
174 h->expiry_time < cd->nextcheck)
175 cd->nextcheck = h->expiry_time;
176 kref_put(&h->ref, cd->cache_put);
177}
178
179static inline int cache_valid(struct cache_head *h)
180{
181
182
183
184
185
186
187 return (h->expiry_time != 0 && test_bit(CACHE_VALID, &h->flags));
188}
189
190extern int cache_check(struct cache_detail *detail,
191 struct cache_head *h, struct cache_req *rqstp);
192extern void cache_flush(void);
193extern void cache_purge(struct cache_detail *detail);
194#define NEVER (0x7FFFFFFF)
195extern int cache_register(struct cache_detail *cd);
196extern void cache_unregister(struct cache_detail *cd);
197
198extern int sunrpc_cache_register_pipefs(struct dentry *parent, const char *,
199 mode_t, struct cache_detail *);
200extern void sunrpc_cache_unregister_pipefs(struct cache_detail *);
201
202extern void qword_add(char **bpp, int *lp, char *str);
203extern void qword_addhex(char **bpp, int *lp, char *buf, int blen);
204extern int qword_get(char **bpp, char *dest, int bufsize);
205
206static inline int get_int(char **bpp, int *anint)
207{
208 char buf[50];
209 char *ep;
210 int rv;
211 int len = qword_get(bpp, buf, 50);
212 if (len < 0) return -EINVAL;
213 if (len ==0) return -ENOENT;
214 rv = simple_strtol(buf, &ep, 0);
215 if (*ep) return -EINVAL;
216 *anint = rv;
217 return 0;
218}
219
220static inline time_t get_expiry(char **bpp)
221{
222 int rv;
223 if (get_int(bpp, &rv))
224 return 0;
225 if (rv < 0)
226 return 0;
227 return rv;
228}
229
230#endif
231