hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/include/linux/sunrpc/cache.h
....@@ -1,3 +1,4 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /*
23 * include/linux/sunrpc/cache.h
34 *
....@@ -5,9 +6,6 @@
56 * used by sunrpc clients and servers.
67 *
78 * Copyright (C) 2002 Neil Brown <neilb@cse.unsw.edu.au>
8
- *
9
- * Released under terms in GPL version 2. See COPYING.
10
- *
119 */
1210
1311 #ifndef _LINUX_SUNRPC_CACHE_H_
....@@ -16,6 +14,7 @@
1614 #include <linux/kref.h>
1715 #include <linux/slab.h>
1816 #include <linux/atomic.h>
17
+#include <linux/kstrtox.h>
1918 #include <linux/proc_fs.h>
2019
2120 /*
....@@ -47,8 +46,9 @@
4746 */
4847 struct cache_head {
4948 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
5252 * sent, else this is when update was
5353 * received, though it is alway set to
5454 * be *after* ->flush_time.
....@@ -67,7 +67,7 @@
6767 struct module * owner;
6868 int hash_size;
6969 struct hlist_head * hash_table;
70
- rwlock_t hash_lock;
70
+ spinlock_t hash_lock;
7171
7272 char *name;
7373 void (*cache_put)(struct kref *);
....@@ -89,6 +89,7 @@
8989 int has_died);
9090
9191 struct cache_head * (*alloc)(void);
92
+ void (*flush)(void);
9293 int (*match)(struct cache_head *orig, struct cache_head *new);
9394 void (*init)(struct cache_head *orig, struct cache_head *new);
9495 void (*update)(struct cache_head *orig, struct cache_head *new);
....@@ -96,22 +97,22 @@
9697 /* fields below this comment are for internal use
9798 * and should not be touched by cache owners
9899 */
99
- time_t flush_time; /* flush all cache items with
100
+ time64_t flush_time; /* flush all cache items with
100101 * last_refresh at or earlier
101102 * than this. last_refresh
102103 * is never set at or earlier
103104 * than this.
104105 */
105106 struct list_head others;
106
- time_t nextcheck;
107
+ time64_t nextcheck;
107108 int entries;
108109
109110 /* fields for communication over channel */
110111 struct list_head queue;
111112
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 */
115116
116117 union {
117118 struct proc_dir_entry *procfs;
....@@ -148,18 +149,22 @@
148149 * timestamps kept in the cache are expressed in seconds
149150 * since boot. This is the best for measuring differences in
150151 * 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.
151156 */
152
-static inline time_t seconds_since_boot(void)
157
+static inline time64_t seconds_since_boot(void)
153158 {
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;
157162 }
158163
159
-static inline time_t convert_to_wallclock(time_t sinceboot)
164
+static inline time64_t convert_to_wallclock(time64_t sinceboot)
160165 {
161
- struct timespec boot;
162
- getboottime(&boot);
166
+ struct timespec64 boot;
167
+ getboottime64(&boot);
163168 return boot.tv_sec + sinceboot;
164169 }
165170
....@@ -168,14 +173,17 @@
168173 extern const struct file_operations cache_flush_operations_pipefs;
169174
170175 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);
173178 extern struct cache_head *
174179 sunrpc_cache_update(struct cache_detail *detail,
175180 struct cache_head *new, struct cache_head *old, int hash);
176181
177182 extern int
178183 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);
179187
180188
181189 extern void cache_clean_deferred(void *owner);
....@@ -186,6 +194,12 @@
186194 return h;
187195 }
188196
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
+}
189203
190204 static inline void cache_put(struct cache_head *h, struct cache_detail *cd)
191205 {
....@@ -197,11 +211,11 @@
197211
198212 static inline bool cache_is_expired(struct cache_detail *detail, struct cache_head *h)
199213 {
214
+ if (h->expiry_time < seconds_since_boot())
215
+ return true;
200216 if (!test_bit(CACHE_VALID, &h->flags))
201217 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;
205219 }
206220
207221 extern int cache_check(struct cache_detail *detail,
....@@ -224,9 +238,9 @@
224238 extern void sunrpc_cache_unhash(struct cache_detail *, struct cache_head *);
225239
226240 /* 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);
230244
231245 extern void qword_add(char **bpp, int *lp, char *str);
232246 extern void qword_addhex(char **bpp, int *lp, char *buf, int blen);
....@@ -268,7 +282,7 @@
268282 return 0;
269283 }
270284
271
-static inline int get_time(char **bpp, time_t *time)
285
+static inline int get_time(char **bpp, time64_t *time)
272286 {
273287 char buf[50];
274288 long long ll;
....@@ -282,20 +296,20 @@
282296 if (kstrtoll(buf, 0, &ll))
283297 return -EINVAL;
284298
285
- *time = (time_t)ll;
299
+ *time = ll;
286300 return 0;
287301 }
288302
289
-static inline time_t get_expiry(char **bpp)
303
+static inline time64_t get_expiry(char **bpp)
290304 {
291
- time_t rv;
292
- struct timespec boot;
305
+ time64_t rv;
306
+ struct timespec64 boot;
293307
294308 if (get_time(bpp, &rv))
295309 return 0;
296310 if (rv < 0)
297311 return 0;
298
- getboottime(&boot);
312
+ getboottime64(&boot);
299313 return rv - boot.tv_sec;
300314 }
301315