.. | .. |
---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
---|
1 | 2 | /* |
---|
2 | 3 | * include/linux/sunrpc/cache.h |
---|
3 | 4 | * |
---|
.. | .. |
---|
5 | 6 | * used by sunrpc clients and servers. |
---|
6 | 7 | * |
---|
7 | 8 | * Copyright (C) 2002 Neil Brown <neilb@cse.unsw.edu.au> |
---|
8 | | - * |
---|
9 | | - * Released under terms in GPL version 2. See COPYING. |
---|
10 | | - * |
---|
11 | 9 | */ |
---|
12 | 10 | |
---|
13 | 11 | #ifndef _LINUX_SUNRPC_CACHE_H_ |
---|
.. | .. |
---|
16 | 14 | #include <linux/kref.h> |
---|
17 | 15 | #include <linux/slab.h> |
---|
18 | 16 | #include <linux/atomic.h> |
---|
| 17 | +#include <linux/kstrtox.h> |
---|
19 | 18 | #include <linux/proc_fs.h> |
---|
20 | 19 | |
---|
21 | 20 | /* |
---|
.. | .. |
---|
47 | 46 | */ |
---|
48 | 47 | struct cache_head { |
---|
49 | 48 | struct hlist_node cache_list; |
---|
50 | | - time_t expiry_time; /* After time time, don't use the data */ |
---|
51 | | - time_t last_refresh; /* If CACHE_PENDING, this is when upcall was |
---|
| 49 | + time64_t expiry_time; /* After time expiry_time, don't use |
---|
| 50 | + * the data */ |
---|
| 51 | + time64_t last_refresh; /* If CACHE_PENDING, this is when upcall was |
---|
52 | 52 | * sent, else this is when update was |
---|
53 | 53 | * received, though it is alway set to |
---|
54 | 54 | * be *after* ->flush_time. |
---|
.. | .. |
---|
67 | 67 | struct module * owner; |
---|
68 | 68 | int hash_size; |
---|
69 | 69 | struct hlist_head * hash_table; |
---|
70 | | - rwlock_t hash_lock; |
---|
| 70 | + spinlock_t hash_lock; |
---|
71 | 71 | |
---|
72 | 72 | char *name; |
---|
73 | 73 | void (*cache_put)(struct kref *); |
---|
.. | .. |
---|
89 | 89 | int has_died); |
---|
90 | 90 | |
---|
91 | 91 | struct cache_head * (*alloc)(void); |
---|
| 92 | + void (*flush)(void); |
---|
92 | 93 | int (*match)(struct cache_head *orig, struct cache_head *new); |
---|
93 | 94 | void (*init)(struct cache_head *orig, struct cache_head *new); |
---|
94 | 95 | void (*update)(struct cache_head *orig, struct cache_head *new); |
---|
.. | .. |
---|
96 | 97 | /* fields below this comment are for internal use |
---|
97 | 98 | * and should not be touched by cache owners |
---|
98 | 99 | */ |
---|
99 | | - time_t flush_time; /* flush all cache items with |
---|
| 100 | + time64_t flush_time; /* flush all cache items with |
---|
100 | 101 | * last_refresh at or earlier |
---|
101 | 102 | * than this. last_refresh |
---|
102 | 103 | * is never set at or earlier |
---|
103 | 104 | * than this. |
---|
104 | 105 | */ |
---|
105 | 106 | struct list_head others; |
---|
106 | | - time_t nextcheck; |
---|
| 107 | + time64_t nextcheck; |
---|
107 | 108 | int entries; |
---|
108 | 109 | |
---|
109 | 110 | /* fields for communication over channel */ |
---|
110 | 111 | struct list_head queue; |
---|
111 | 112 | |
---|
112 | | - atomic_t readers; /* how many time is /chennel open */ |
---|
113 | | - time_t last_close; /* if no readers, when did last close */ |
---|
114 | | - time_t last_warn; /* when we last warned about no readers */ |
---|
| 113 | + atomic_t writers; /* how many time is /channel open */ |
---|
| 114 | + time64_t last_close; /* if no writers, when did last close */ |
---|
| 115 | + time64_t last_warn; /* when we last warned about no writers */ |
---|
115 | 116 | |
---|
116 | 117 | union { |
---|
117 | 118 | struct proc_dir_entry *procfs; |
---|
.. | .. |
---|
148 | 149 | * timestamps kept in the cache are expressed in seconds |
---|
149 | 150 | * since boot. This is the best for measuring differences in |
---|
150 | 151 | * real time. |
---|
| 152 | + * This reimplemnts ktime_get_boottime_seconds() in a slightly |
---|
| 153 | + * faster but less accurate way. When we end up converting |
---|
| 154 | + * back to wallclock (CLOCK_REALTIME), that error often |
---|
| 155 | + * cancels out during the reverse operation. |
---|
151 | 156 | */ |
---|
152 | | -static inline time_t seconds_since_boot(void) |
---|
| 157 | +static inline time64_t seconds_since_boot(void) |
---|
153 | 158 | { |
---|
154 | | - struct timespec boot; |
---|
155 | | - getboottime(&boot); |
---|
156 | | - return get_seconds() - boot.tv_sec; |
---|
| 159 | + struct timespec64 boot; |
---|
| 160 | + getboottime64(&boot); |
---|
| 161 | + return ktime_get_real_seconds() - boot.tv_sec; |
---|
157 | 162 | } |
---|
158 | 163 | |
---|
159 | | -static inline time_t convert_to_wallclock(time_t sinceboot) |
---|
| 164 | +static inline time64_t convert_to_wallclock(time64_t sinceboot) |
---|
160 | 165 | { |
---|
161 | | - struct timespec boot; |
---|
162 | | - getboottime(&boot); |
---|
| 166 | + struct timespec64 boot; |
---|
| 167 | + getboottime64(&boot); |
---|
163 | 168 | return boot.tv_sec + sinceboot; |
---|
164 | 169 | } |
---|
165 | 170 | |
---|
.. | .. |
---|
168 | 173 | extern const struct file_operations cache_flush_operations_pipefs; |
---|
169 | 174 | |
---|
170 | 175 | extern struct cache_head * |
---|
171 | | -sunrpc_cache_lookup(struct cache_detail *detail, |
---|
172 | | - struct cache_head *key, int hash); |
---|
| 176 | +sunrpc_cache_lookup_rcu(struct cache_detail *detail, |
---|
| 177 | + struct cache_head *key, int hash); |
---|
173 | 178 | extern struct cache_head * |
---|
174 | 179 | sunrpc_cache_update(struct cache_detail *detail, |
---|
175 | 180 | struct cache_head *new, struct cache_head *old, int hash); |
---|
176 | 181 | |
---|
177 | 182 | extern int |
---|
178 | 183 | sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h); |
---|
| 184 | +extern int |
---|
| 185 | +sunrpc_cache_pipe_upcall_timeout(struct cache_detail *detail, |
---|
| 186 | + struct cache_head *h); |
---|
179 | 187 | |
---|
180 | 188 | |
---|
181 | 189 | extern void cache_clean_deferred(void *owner); |
---|
.. | .. |
---|
186 | 194 | return h; |
---|
187 | 195 | } |
---|
188 | 196 | |
---|
| 197 | +static inline struct cache_head *cache_get_rcu(struct cache_head *h) |
---|
| 198 | +{ |
---|
| 199 | + if (kref_get_unless_zero(&h->ref)) |
---|
| 200 | + return h; |
---|
| 201 | + return NULL; |
---|
| 202 | +} |
---|
189 | 203 | |
---|
190 | 204 | static inline void cache_put(struct cache_head *h, struct cache_detail *cd) |
---|
191 | 205 | { |
---|
.. | .. |
---|
197 | 211 | |
---|
198 | 212 | static inline bool cache_is_expired(struct cache_detail *detail, struct cache_head *h) |
---|
199 | 213 | { |
---|
| 214 | + if (h->expiry_time < seconds_since_boot()) |
---|
| 215 | + return true; |
---|
200 | 216 | if (!test_bit(CACHE_VALID, &h->flags)) |
---|
201 | 217 | return false; |
---|
202 | | - |
---|
203 | | - return (h->expiry_time < seconds_since_boot()) || |
---|
204 | | - (detail->flush_time >= h->last_refresh); |
---|
| 218 | + return detail->flush_time >= h->last_refresh; |
---|
205 | 219 | } |
---|
206 | 220 | |
---|
207 | 221 | extern int cache_check(struct cache_detail *detail, |
---|
.. | .. |
---|
224 | 238 | extern void sunrpc_cache_unhash(struct cache_detail *, struct cache_head *); |
---|
225 | 239 | |
---|
226 | 240 | /* Must store cache_detail in seq_file->private if using next three functions */ |
---|
227 | | -extern void *cache_seq_start(struct seq_file *file, loff_t *pos); |
---|
228 | | -extern void *cache_seq_next(struct seq_file *file, void *p, loff_t *pos); |
---|
229 | | -extern void cache_seq_stop(struct seq_file *file, void *p); |
---|
| 241 | +extern void *cache_seq_start_rcu(struct seq_file *file, loff_t *pos); |
---|
| 242 | +extern void *cache_seq_next_rcu(struct seq_file *file, void *p, loff_t *pos); |
---|
| 243 | +extern void cache_seq_stop_rcu(struct seq_file *file, void *p); |
---|
230 | 244 | |
---|
231 | 245 | extern void qword_add(char **bpp, int *lp, char *str); |
---|
232 | 246 | extern void qword_addhex(char **bpp, int *lp, char *buf, int blen); |
---|
.. | .. |
---|
268 | 282 | return 0; |
---|
269 | 283 | } |
---|
270 | 284 | |
---|
271 | | -static inline int get_time(char **bpp, time_t *time) |
---|
| 285 | +static inline int get_time(char **bpp, time64_t *time) |
---|
272 | 286 | { |
---|
273 | 287 | char buf[50]; |
---|
274 | 288 | long long ll; |
---|
.. | .. |
---|
282 | 296 | if (kstrtoll(buf, 0, &ll)) |
---|
283 | 297 | return -EINVAL; |
---|
284 | 298 | |
---|
285 | | - *time = (time_t)ll; |
---|
| 299 | + *time = ll; |
---|
286 | 300 | return 0; |
---|
287 | 301 | } |
---|
288 | 302 | |
---|
289 | | -static inline time_t get_expiry(char **bpp) |
---|
| 303 | +static inline time64_t get_expiry(char **bpp) |
---|
290 | 304 | { |
---|
291 | | - time_t rv; |
---|
292 | | - struct timespec boot; |
---|
| 305 | + time64_t rv; |
---|
| 306 | + struct timespec64 boot; |
---|
293 | 307 | |
---|
294 | 308 | if (get_time(bpp, &rv)) |
---|
295 | 309 | return 0; |
---|
296 | 310 | if (rv < 0) |
---|
297 | 311 | return 0; |
---|
298 | | - getboottime(&boot); |
---|
| 312 | + getboottime64(&boot); |
---|
299 | 313 | return rv - boot.tv_sec; |
---|
300 | 314 | } |
---|
301 | 315 | |
---|