hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
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_
....@@ -47,8 +45,9 @@
4745 */
4846 struct cache_head {
4947 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
48
+ time64_t expiry_time; /* After time expiry_time, don't use
49
+ * the data */
50
+ time64_t last_refresh; /* If CACHE_PENDING, this is when upcall was
5251 * sent, else this is when update was
5352 * received, though it is alway set to
5453 * be *after* ->flush_time.
....@@ -67,7 +66,7 @@
6766 struct module * owner;
6867 int hash_size;
6968 struct hlist_head * hash_table;
70
- rwlock_t hash_lock;
69
+ spinlock_t hash_lock;
7170
7271 char *name;
7372 void (*cache_put)(struct kref *);
....@@ -89,6 +88,7 @@
8988 int has_died);
9089
9190 struct cache_head * (*alloc)(void);
91
+ void (*flush)(void);
9292 int (*match)(struct cache_head *orig, struct cache_head *new);
9393 void (*init)(struct cache_head *orig, struct cache_head *new);
9494 void (*update)(struct cache_head *orig, struct cache_head *new);
....@@ -96,22 +96,22 @@
9696 /* fields below this comment are for internal use
9797 * and should not be touched by cache owners
9898 */
99
- time_t flush_time; /* flush all cache items with
99
+ time64_t flush_time; /* flush all cache items with
100100 * last_refresh at or earlier
101101 * than this. last_refresh
102102 * is never set at or earlier
103103 * than this.
104104 */
105105 struct list_head others;
106
- time_t nextcheck;
106
+ time64_t nextcheck;
107107 int entries;
108108
109109 /* fields for communication over channel */
110110 struct list_head queue;
111111
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 */
112
+ atomic_t writers; /* how many time is /channel open */
113
+ time64_t last_close; /* if no writers, when did last close */
114
+ time64_t last_warn; /* when we last warned about no writers */
115115
116116 union {
117117 struct proc_dir_entry *procfs;
....@@ -148,18 +148,22 @@
148148 * timestamps kept in the cache are expressed in seconds
149149 * since boot. This is the best for measuring differences in
150150 * real time.
151
+ * This reimplemnts ktime_get_boottime_seconds() in a slightly
152
+ * faster but less accurate way. When we end up converting
153
+ * back to wallclock (CLOCK_REALTIME), that error often
154
+ * cancels out during the reverse operation.
151155 */
152
-static inline time_t seconds_since_boot(void)
156
+static inline time64_t seconds_since_boot(void)
153157 {
154
- struct timespec boot;
155
- getboottime(&boot);
156
- return get_seconds() - boot.tv_sec;
158
+ struct timespec64 boot;
159
+ getboottime64(&boot);
160
+ return ktime_get_real_seconds() - boot.tv_sec;
157161 }
158162
159
-static inline time_t convert_to_wallclock(time_t sinceboot)
163
+static inline time64_t convert_to_wallclock(time64_t sinceboot)
160164 {
161
- struct timespec boot;
162
- getboottime(&boot);
165
+ struct timespec64 boot;
166
+ getboottime64(&boot);
163167 return boot.tv_sec + sinceboot;
164168 }
165169
....@@ -168,14 +172,17 @@
168172 extern const struct file_operations cache_flush_operations_pipefs;
169173
170174 extern struct cache_head *
171
-sunrpc_cache_lookup(struct cache_detail *detail,
172
- struct cache_head *key, int hash);
175
+sunrpc_cache_lookup_rcu(struct cache_detail *detail,
176
+ struct cache_head *key, int hash);
173177 extern struct cache_head *
174178 sunrpc_cache_update(struct cache_detail *detail,
175179 struct cache_head *new, struct cache_head *old, int hash);
176180
177181 extern int
178182 sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h);
183
+extern int
184
+sunrpc_cache_pipe_upcall_timeout(struct cache_detail *detail,
185
+ struct cache_head *h);
179186
180187
181188 extern void cache_clean_deferred(void *owner);
....@@ -186,6 +193,12 @@
186193 return h;
187194 }
188195
196
+static inline struct cache_head *cache_get_rcu(struct cache_head *h)
197
+{
198
+ if (kref_get_unless_zero(&h->ref))
199
+ return h;
200
+ return NULL;
201
+}
189202
190203 static inline void cache_put(struct cache_head *h, struct cache_detail *cd)
191204 {
....@@ -197,11 +210,11 @@
197210
198211 static inline bool cache_is_expired(struct cache_detail *detail, struct cache_head *h)
199212 {
213
+ if (h->expiry_time < seconds_since_boot())
214
+ return true;
200215 if (!test_bit(CACHE_VALID, &h->flags))
201216 return false;
202
-
203
- return (h->expiry_time < seconds_since_boot()) ||
204
- (detail->flush_time >= h->last_refresh);
217
+ return detail->flush_time >= h->last_refresh;
205218 }
206219
207220 extern int cache_check(struct cache_detail *detail,
....@@ -224,9 +237,9 @@
224237 extern void sunrpc_cache_unhash(struct cache_detail *, struct cache_head *);
225238
226239 /* 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);
240
+extern void *cache_seq_start_rcu(struct seq_file *file, loff_t *pos);
241
+extern void *cache_seq_next_rcu(struct seq_file *file, void *p, loff_t *pos);
242
+extern void cache_seq_stop_rcu(struct seq_file *file, void *p);
230243
231244 extern void qword_add(char **bpp, int *lp, char *str);
232245 extern void qword_addhex(char **bpp, int *lp, char *buf, int blen);
....@@ -268,7 +281,7 @@
268281 return 0;
269282 }
270283
271
-static inline int get_time(char **bpp, time_t *time)
284
+static inline int get_time(char **bpp, time64_t *time)
272285 {
273286 char buf[50];
274287 long long ll;
....@@ -282,20 +295,20 @@
282295 if (kstrtoll(buf, 0, &ll))
283296 return -EINVAL;
284297
285
- *time = (time_t)ll;
298
+ *time = ll;
286299 return 0;
287300 }
288301
289
-static inline time_t get_expiry(char **bpp)
302
+static inline time64_t get_expiry(char **bpp)
290303 {
291
- time_t rv;
292
- struct timespec boot;
304
+ time64_t rv;
305
+ struct timespec64 boot;
293306
294307 if (get_time(bpp, &rv))
295308 return 0;
296309 if (rv < 0)
297310 return 0;
298
- getboottime(&boot);
311
+ getboottime64(&boot);
299312 return rv - boot.tv_sec;
300313 }
301314