hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/net/sunrpc/cache.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * net/sunrpc/cache.c
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 #include <linux/types.h>
....@@ -34,6 +32,7 @@
3432 #include <linux/sunrpc/cache.h>
3533 #include <linux/sunrpc/stats.h>
3634 #include <linux/sunrpc/rpc_pipe_fs.h>
35
+#include <trace/events/sunrpc.h>
3736 #include "netns.h"
3837
3938 #define RPCDBG_FACILITY RPCDBG_CACHE
....@@ -43,7 +42,7 @@
4342
4443 static void cache_init(struct cache_head *h, struct cache_detail *detail)
4544 {
46
- time_t now = seconds_since_boot();
45
+ time64_t now = seconds_since_boot();
4746 INIT_HLIST_NODE(&h->cache_list);
4847 h->flags = 0;
4948 kref_init(&h->ref);
....@@ -57,28 +56,50 @@
5756 static void cache_fresh_unlocked(struct cache_head *head,
5857 struct cache_detail *detail);
5958
60
-struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail,
61
- struct cache_head *key, int hash)
59
+static struct cache_head *sunrpc_cache_find_rcu(struct cache_detail *detail,
60
+ struct cache_head *key,
61
+ int hash)
6262 {
63
- struct cache_head *new = NULL, *freeme = NULL, *tmp = NULL;
64
- struct hlist_head *head;
63
+ struct hlist_head *head = &detail->hash_table[hash];
64
+ struct cache_head *tmp;
6565
66
- head = &detail->hash_table[hash];
67
-
68
- read_lock(&detail->hash_lock);
69
-
70
- hlist_for_each_entry(tmp, head, cache_list) {
71
- if (detail->match(tmp, key)) {
72
- if (cache_is_expired(detail, tmp))
73
- /* This entry is expired, we will discard it. */
74
- break;
75
- cache_get(tmp);
76
- read_unlock(&detail->hash_lock);
77
- return tmp;
78
- }
66
+ rcu_read_lock();
67
+ hlist_for_each_entry_rcu(tmp, head, cache_list) {
68
+ if (!detail->match(tmp, key))
69
+ continue;
70
+ if (test_bit(CACHE_VALID, &tmp->flags) &&
71
+ cache_is_expired(detail, tmp))
72
+ continue;
73
+ tmp = cache_get_rcu(tmp);
74
+ rcu_read_unlock();
75
+ return tmp;
7976 }
80
- read_unlock(&detail->hash_lock);
81
- /* Didn't find anything, insert an empty entry */
77
+ rcu_read_unlock();
78
+ return NULL;
79
+}
80
+
81
+static void sunrpc_begin_cache_remove_entry(struct cache_head *ch,
82
+ struct cache_detail *cd)
83
+{
84
+ /* Must be called under cd->hash_lock */
85
+ hlist_del_init_rcu(&ch->cache_list);
86
+ set_bit(CACHE_CLEANED, &ch->flags);
87
+ cd->entries --;
88
+}
89
+
90
+static void sunrpc_end_cache_remove_entry(struct cache_head *ch,
91
+ struct cache_detail *cd)
92
+{
93
+ cache_fresh_unlocked(ch, cd);
94
+ cache_put(ch, cd);
95
+}
96
+
97
+static struct cache_head *sunrpc_cache_add_entry(struct cache_detail *detail,
98
+ struct cache_head *key,
99
+ int hash)
100
+{
101
+ struct cache_head *new, *tmp, *freeme = NULL;
102
+ struct hlist_head *head = &detail->hash_table[hash];
82103
83104 new = detail->alloc();
84105 if (!new)
....@@ -90,44 +111,55 @@
90111 cache_init(new, detail);
91112 detail->init(new, key);
92113
93
- write_lock(&detail->hash_lock);
114
+ spin_lock(&detail->hash_lock);
94115
95116 /* check if entry appeared while we slept */
96
- hlist_for_each_entry(tmp, head, cache_list) {
97
- if (detail->match(tmp, key)) {
98
- if (cache_is_expired(detail, tmp)) {
99
- hlist_del_init(&tmp->cache_list);
100
- detail->entries --;
101
- freeme = tmp;
102
- break;
103
- }
104
- cache_get(tmp);
105
- write_unlock(&detail->hash_lock);
106
- cache_put(new, detail);
107
- return tmp;
117
+ hlist_for_each_entry_rcu(tmp, head, cache_list,
118
+ lockdep_is_held(&detail->hash_lock)) {
119
+ if (!detail->match(tmp, key))
120
+ continue;
121
+ if (test_bit(CACHE_VALID, &tmp->flags) &&
122
+ cache_is_expired(detail, tmp)) {
123
+ sunrpc_begin_cache_remove_entry(tmp, detail);
124
+ trace_cache_entry_expired(detail, tmp);
125
+ freeme = tmp;
126
+ break;
108127 }
128
+ cache_get(tmp);
129
+ spin_unlock(&detail->hash_lock);
130
+ cache_put(new, detail);
131
+ return tmp;
109132 }
110133
111
- hlist_add_head(&new->cache_list, head);
134
+ hlist_add_head_rcu(&new->cache_list, head);
112135 detail->entries++;
113136 cache_get(new);
114
- write_unlock(&detail->hash_lock);
137
+ spin_unlock(&detail->hash_lock);
115138
116
- if (freeme) {
117
- cache_fresh_unlocked(freeme, detail);
118
- cache_put(freeme, detail);
119
- }
139
+ if (freeme)
140
+ sunrpc_end_cache_remove_entry(freeme, detail);
120141 return new;
121142 }
122
-EXPORT_SYMBOL_GPL(sunrpc_cache_lookup);
123143
144
+struct cache_head *sunrpc_cache_lookup_rcu(struct cache_detail *detail,
145
+ struct cache_head *key, int hash)
146
+{
147
+ struct cache_head *ret;
148
+
149
+ ret = sunrpc_cache_find_rcu(detail, key, hash);
150
+ if (ret)
151
+ return ret;
152
+ /* Didn't find anything, insert an empty entry */
153
+ return sunrpc_cache_add_entry(detail, key, hash);
154
+}
155
+EXPORT_SYMBOL_GPL(sunrpc_cache_lookup_rcu);
124156
125157 static void cache_dequeue(struct cache_detail *detail, struct cache_head *ch);
126158
127
-static void cache_fresh_locked(struct cache_head *head, time_t expiry,
159
+static void cache_fresh_locked(struct cache_head *head, time64_t expiry,
128160 struct cache_detail *detail)
129161 {
130
- time_t now = seconds_since_boot();
162
+ time64_t now = seconds_since_boot();
131163 if (now <= detail->flush_time)
132164 /* ensure it isn't immediately treated as expired */
133165 now = detail->flush_time + 1;
....@@ -146,6 +178,25 @@
146178 }
147179 }
148180
181
+static void cache_make_negative(struct cache_detail *detail,
182
+ struct cache_head *h)
183
+{
184
+ set_bit(CACHE_NEGATIVE, &h->flags);
185
+ trace_cache_entry_make_negative(detail, h);
186
+}
187
+
188
+static void cache_entry_update(struct cache_detail *detail,
189
+ struct cache_head *h,
190
+ struct cache_head *new)
191
+{
192
+ if (!test_bit(CACHE_NEGATIVE, &new->flags)) {
193
+ detail->update(h, new);
194
+ trace_cache_entry_update(detail, h);
195
+ } else {
196
+ cache_make_negative(detail, h);
197
+ }
198
+}
199
+
149200 struct cache_head *sunrpc_cache_update(struct cache_detail *detail,
150201 struct cache_head *new, struct cache_head *old, int hash)
151202 {
....@@ -156,18 +207,15 @@
156207 struct cache_head *tmp;
157208
158209 if (!test_bit(CACHE_VALID, &old->flags)) {
159
- write_lock(&detail->hash_lock);
210
+ spin_lock(&detail->hash_lock);
160211 if (!test_bit(CACHE_VALID, &old->flags)) {
161
- if (test_bit(CACHE_NEGATIVE, &new->flags))
162
- set_bit(CACHE_NEGATIVE, &old->flags);
163
- else
164
- detail->update(old, new);
212
+ cache_entry_update(detail, old, new);
165213 cache_fresh_locked(old, new->expiry_time, detail);
166
- write_unlock(&detail->hash_lock);
214
+ spin_unlock(&detail->hash_lock);
167215 cache_fresh_unlocked(old, detail);
168216 return old;
169217 }
170
- write_unlock(&detail->hash_lock);
218
+ spin_unlock(&detail->hash_lock);
171219 }
172220 /* We need to insert a new entry */
173221 tmp = detail->alloc();
....@@ -178,30 +226,20 @@
178226 cache_init(tmp, detail);
179227 detail->init(tmp, old);
180228
181
- write_lock(&detail->hash_lock);
182
- if (test_bit(CACHE_NEGATIVE, &new->flags))
183
- set_bit(CACHE_NEGATIVE, &tmp->flags);
184
- else
185
- detail->update(tmp, new);
229
+ spin_lock(&detail->hash_lock);
230
+ cache_entry_update(detail, tmp, new);
186231 hlist_add_head(&tmp->cache_list, &detail->hash_table[hash]);
187232 detail->entries++;
188233 cache_get(tmp);
189234 cache_fresh_locked(tmp, new->expiry_time, detail);
190235 cache_fresh_locked(old, 0, detail);
191
- write_unlock(&detail->hash_lock);
236
+ spin_unlock(&detail->hash_lock);
192237 cache_fresh_unlocked(tmp, detail);
193238 cache_fresh_unlocked(old, detail);
194239 cache_put(old, detail);
195240 return tmp;
196241 }
197242 EXPORT_SYMBOL_GPL(sunrpc_cache_update);
198
-
199
-static int cache_make_upcall(struct cache_detail *cd, struct cache_head *h)
200
-{
201
- if (cd->cache_upcall)
202
- return cd->cache_upcall(cd, h);
203
- return sunrpc_cache_pipe_upcall(cd, h);
204
-}
205243
206244 static inline int cache_is_valid(struct cache_head *h)
207245 {
....@@ -228,15 +266,15 @@
228266 {
229267 int rv;
230268
231
- write_lock(&detail->hash_lock);
269
+ spin_lock(&detail->hash_lock);
232270 rv = cache_is_valid(h);
233271 if (rv == -EAGAIN) {
234
- set_bit(CACHE_NEGATIVE, &h->flags);
272
+ cache_make_negative(detail, h);
235273 cache_fresh_locked(h, seconds_since_boot()+CACHE_NEW_EXPIRY,
236274 detail);
237275 rv = -ENOENT;
238276 }
239
- write_unlock(&detail->hash_lock);
277
+ spin_unlock(&detail->hash_lock);
240278 cache_fresh_unlocked(h, detail);
241279 return rv;
242280 }
....@@ -259,7 +297,7 @@
259297 struct cache_head *h, struct cache_req *rqstp)
260298 {
261299 int rv;
262
- long refresh_age, age;
300
+ time64_t refresh_age, age;
263301
264302 /* First decide return status as best we can */
265303 rv = cache_is_valid(h);
....@@ -273,17 +311,15 @@
273311 rv = -ENOENT;
274312 } else if (rv == -EAGAIN ||
275313 (h->expiry_time != 0 && age > refresh_age/2)) {
276
- dprintk("RPC: Want update, refage=%ld, age=%ld\n",
314
+ dprintk("RPC: Want update, refage=%lld, age=%lld\n",
277315 refresh_age, age);
278
- if (!test_and_set_bit(CACHE_PENDING, &h->flags)) {
279
- switch (cache_make_upcall(detail, h)) {
280
- case -EINVAL:
281
- rv = try_to_negate_entry(detail, h);
282
- break;
283
- case -EAGAIN:
284
- cache_fresh_unlocked(h, detail);
285
- break;
286
- }
316
+ switch (detail->cache_upcall(detail, h)) {
317
+ case -EINVAL:
318
+ rv = try_to_negate_entry(detail, h);
319
+ break;
320
+ case -EAGAIN:
321
+ cache_fresh_unlocked(h, detail);
322
+ break;
287323 }
288324 }
289325
....@@ -346,12 +382,12 @@
346382
347383 void sunrpc_init_cache_detail(struct cache_detail *cd)
348384 {
349
- rwlock_init(&cd->hash_lock);
385
+ spin_lock_init(&cd->hash_lock);
350386 INIT_LIST_HEAD(&cd->queue);
351387 spin_lock(&cache_list_lock);
352388 cd->nextcheck = 0;
353389 cd->entries = 0;
354
- atomic_set(&cd->readers, 0);
390
+ atomic_set(&cd->writers, 0);
355391 cd->last_close = 0;
356392 cd->last_warn = -1;
357393 list_add(&cd->others, &cache_list);
....@@ -366,11 +402,11 @@
366402 {
367403 cache_purge(cd);
368404 spin_lock(&cache_list_lock);
369
- write_lock(&cd->hash_lock);
405
+ spin_lock(&cd->hash_lock);
370406 if (current_detail == cd)
371407 current_detail = NULL;
372408 list_del_init(&cd->others);
373
- write_unlock(&cd->hash_lock);
409
+ spin_unlock(&cd->hash_lock);
374410 spin_unlock(&cache_list_lock);
375411 if (list_empty(&cache_list)) {
376412 /* module must be being unloaded so its safe to kill the worker */
....@@ -427,7 +463,7 @@
427463 struct hlist_head *head;
428464 struct hlist_node *tmp;
429465
430
- write_lock(&current_detail->hash_lock);
466
+ spin_lock(&current_detail->hash_lock);
431467
432468 /* Ok, now to clean this strand */
433469
....@@ -438,22 +474,19 @@
438474 if (!cache_is_expired(current_detail, ch))
439475 continue;
440476
441
- hlist_del_init(&ch->cache_list);
442
- current_detail->entries--;
477
+ sunrpc_begin_cache_remove_entry(ch, current_detail);
478
+ trace_cache_entry_expired(current_detail, ch);
443479 rv = 1;
444480 break;
445481 }
446482
447
- write_unlock(&current_detail->hash_lock);
483
+ spin_unlock(&current_detail->hash_lock);
448484 d = current_detail;
449485 if (!ch)
450486 current_index ++;
451487 spin_unlock(&cache_list_lock);
452
- if (ch) {
453
- set_bit(CACHE_CLEANED, &ch->flags);
454
- cache_fresh_unlocked(ch, d);
455
- cache_put(ch, d);
456
- }
488
+ if (ch)
489
+ sunrpc_end_cache_remove_entry(ch, d);
457490 } else
458491 spin_unlock(&cache_list_lock);
459492
....@@ -465,16 +498,17 @@
465498 */
466499 static void do_cache_clean(struct work_struct *work)
467500 {
468
- int delay = 5;
469
- if (cache_clean() == -1)
470
- delay = round_jiffies_relative(30*HZ);
501
+ int delay;
471502
472503 if (list_empty(&cache_list))
473
- delay = 0;
504
+ return;
474505
475
- if (delay)
476
- queue_delayed_work(system_power_efficient_wq,
477
- &cache_cleaner, delay);
506
+ if (cache_clean() == -1)
507
+ delay = round_jiffies_relative(30*HZ);
508
+ else
509
+ delay = 5;
510
+
511
+ queue_delayed_work(system_power_efficient_wq, &cache_cleaner, delay);
478512 }
479513
480514
....@@ -496,30 +530,27 @@
496530 {
497531 struct cache_head *ch = NULL;
498532 struct hlist_head *head = NULL;
499
- struct hlist_node *tmp = NULL;
500533 int i = 0;
501534
502
- write_lock(&detail->hash_lock);
535
+ spin_lock(&detail->hash_lock);
503536 if (!detail->entries) {
504
- write_unlock(&detail->hash_lock);
537
+ spin_unlock(&detail->hash_lock);
505538 return;
506539 }
507540
508541 dprintk("RPC: %d entries in %s cache\n", detail->entries, detail->name);
509542 for (i = 0; i < detail->hash_size; i++) {
510543 head = &detail->hash_table[i];
511
- hlist_for_each_entry_safe(ch, tmp, head, cache_list) {
512
- hlist_del_init(&ch->cache_list);
513
- detail->entries--;
514
-
515
- set_bit(CACHE_CLEANED, &ch->flags);
516
- write_unlock(&detail->hash_lock);
517
- cache_fresh_unlocked(ch, detail);
518
- cache_put(ch, detail);
519
- write_lock(&detail->hash_lock);
544
+ while (!hlist_empty(head)) {
545
+ ch = hlist_entry(head->first, struct cache_head,
546
+ cache_list);
547
+ sunrpc_begin_cache_remove_entry(ch, detail);
548
+ spin_unlock(&detail->hash_lock);
549
+ sunrpc_end_cache_remove_entry(ch, detail);
550
+ spin_lock(&detail->hash_lock);
520551 }
521552 }
522
- write_unlock(&detail->hash_lock);
553
+ spin_unlock(&detail->hash_lock);
523554 }
524555 EXPORT_SYMBOL_GPL(cache_purge);
525556
....@@ -878,7 +909,7 @@
878909 static ssize_t cache_slow_downcall(const char __user *buf,
879910 size_t count, struct cache_detail *cd)
880911 {
881
- static char write_buf[8192]; /* protected by queue_io_mutex */
912
+ static char write_buf[32768]; /* protected by queue_io_mutex */
882913 ssize_t ret = -EINVAL;
883914
884915 if (count >= sizeof(write_buf))
....@@ -1007,11 +1038,13 @@
10071038 }
10081039 rp->offset = 0;
10091040 rp->q.reader = 1;
1010
- atomic_inc(&cd->readers);
1041
+
10111042 spin_lock(&queue_lock);
10121043 list_add(&rp->q.list, &cd->queue);
10131044 spin_unlock(&queue_lock);
10141045 }
1046
+ if (filp->f_mode & FMODE_WRITE)
1047
+ atomic_inc(&cd->writers);
10151048 filp->private_data = rp;
10161049 return 0;
10171050 }
....@@ -1040,8 +1073,10 @@
10401073 filp->private_data = NULL;
10411074 kfree(rp);
10421075
1076
+ }
1077
+ if (filp->f_mode & FMODE_WRITE) {
1078
+ atomic_dec(&cd->writers);
10431079 cd->last_close = seconds_since_boot();
1044
- atomic_dec(&cd->readers);
10451080 }
10461081 module_put(cd->owner);
10471082 return 0;
....@@ -1149,7 +1184,7 @@
11491184
11501185 static bool cache_listeners_exist(struct cache_detail *detail)
11511186 {
1152
- if (atomic_read(&detail->readers))
1187
+ if (atomic_read(&detail->writers))
11531188 return true;
11541189 if (detail->last_close == 0)
11551190 /* This cache was never opened */
....@@ -1170,20 +1205,12 @@
11701205 *
11711206 * Each request is at most one page long.
11721207 */
1173
-int sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h)
1208
+static int cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h)
11741209 {
1175
-
11761210 char *buf;
11771211 struct cache_request *crq;
11781212 int ret = 0;
11791213
1180
- if (!detail->cache_request)
1181
- return -EINVAL;
1182
-
1183
- if (!cache_listeners_exist(detail)) {
1184
- warn_no_listener(detail);
1185
- return -EINVAL;
1186
- }
11871214 if (test_bit(CACHE_CLEANED, &h->flags))
11881215 /* Too late to make an upcall */
11891216 return -EAGAIN;
....@@ -1206,6 +1233,7 @@
12061233 if (test_bit(CACHE_PENDING, &h->flags)) {
12071234 crq->item = cache_get(h);
12081235 list_add_tail(&crq->q.list, &detail->queue);
1236
+ trace_cache_entry_upcall(detail, h);
12091237 } else
12101238 /* Lost a race, no longer PENDING, so don't enqueue */
12111239 ret = -EAGAIN;
....@@ -1217,7 +1245,26 @@
12171245 }
12181246 return ret;
12191247 }
1248
+
1249
+int sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h)
1250
+{
1251
+ if (test_and_set_bit(CACHE_PENDING, &h->flags))
1252
+ return 0;
1253
+ return cache_pipe_upcall(detail, h);
1254
+}
12201255 EXPORT_SYMBOL_GPL(sunrpc_cache_pipe_upcall);
1256
+
1257
+int sunrpc_cache_pipe_upcall_timeout(struct cache_detail *detail,
1258
+ struct cache_head *h)
1259
+{
1260
+ if (!cache_listeners_exist(detail)) {
1261
+ warn_no_listener(detail);
1262
+ trace_cache_entry_no_listener(detail, h);
1263
+ return -EINVAL;
1264
+ }
1265
+ return sunrpc_cache_pipe_upcall(detail, h);
1266
+}
1267
+EXPORT_SYMBOL_GPL(sunrpc_cache_pipe_upcall_timeout);
12211268
12221269 /*
12231270 * parse a message from user-space and pass it
....@@ -1294,21 +1341,19 @@
12941341 * get a header, then pass each real item in the cache
12951342 */
12961343
1297
-void *cache_seq_start(struct seq_file *m, loff_t *pos)
1298
- __acquires(cd->hash_lock)
1344
+static void *__cache_seq_start(struct seq_file *m, loff_t *pos)
12991345 {
13001346 loff_t n = *pos;
13011347 unsigned int hash, entry;
13021348 struct cache_head *ch;
13031349 struct cache_detail *cd = m->private;
13041350
1305
- read_lock(&cd->hash_lock);
13061351 if (!n--)
13071352 return SEQ_START_TOKEN;
13081353 hash = n >> 32;
13091354 entry = n & ((1LL<<32) - 1);
13101355
1311
- hlist_for_each_entry(ch, &cd->hash_table[hash], cache_list)
1356
+ hlist_for_each_entry_rcu(ch, &cd->hash_table[hash], cache_list)
13121357 if (!entry--)
13131358 return ch;
13141359 n &= ~((1LL<<32) - 1);
....@@ -1320,12 +1365,12 @@
13201365 if (hash >= cd->hash_size)
13211366 return NULL;
13221367 *pos = n+1;
1323
- return hlist_entry_safe(cd->hash_table[hash].first,
1368
+ return hlist_entry_safe(rcu_dereference_raw(
1369
+ hlist_first_rcu(&cd->hash_table[hash])),
13241370 struct cache_head, cache_list);
13251371 }
1326
-EXPORT_SYMBOL_GPL(cache_seq_start);
13271372
1328
-void *cache_seq_next(struct seq_file *m, void *p, loff_t *pos)
1373
+static void *cache_seq_next(struct seq_file *m, void *p, loff_t *pos)
13291374 {
13301375 struct cache_head *ch = p;
13311376 int hash = (*pos >> 32);
....@@ -1338,7 +1383,8 @@
13381383 *pos += 1LL<<32;
13391384 } else {
13401385 ++*pos;
1341
- return hlist_entry_safe(ch->cache_list.next,
1386
+ return hlist_entry_safe(rcu_dereference_raw(
1387
+ hlist_next_rcu(&ch->cache_list)),
13421388 struct cache_head, cache_list);
13431389 }
13441390 *pos &= ~((1LL<<32) - 1);
....@@ -1350,18 +1396,31 @@
13501396 if (hash >= cd->hash_size)
13511397 return NULL;
13521398 ++*pos;
1353
- return hlist_entry_safe(cd->hash_table[hash].first,
1399
+ return hlist_entry_safe(rcu_dereference_raw(
1400
+ hlist_first_rcu(&cd->hash_table[hash])),
13541401 struct cache_head, cache_list);
13551402 }
1356
-EXPORT_SYMBOL_GPL(cache_seq_next);
13571403
1358
-void cache_seq_stop(struct seq_file *m, void *p)
1359
- __releases(cd->hash_lock)
1404
+void *cache_seq_start_rcu(struct seq_file *m, loff_t *pos)
1405
+ __acquires(RCU)
13601406 {
1361
- struct cache_detail *cd = m->private;
1362
- read_unlock(&cd->hash_lock);
1407
+ rcu_read_lock();
1408
+ return __cache_seq_start(m, pos);
13631409 }
1364
-EXPORT_SYMBOL_GPL(cache_seq_stop);
1410
+EXPORT_SYMBOL_GPL(cache_seq_start_rcu);
1411
+
1412
+void *cache_seq_next_rcu(struct seq_file *file, void *p, loff_t *pos)
1413
+{
1414
+ return cache_seq_next(file, p, pos);
1415
+}
1416
+EXPORT_SYMBOL_GPL(cache_seq_next_rcu);
1417
+
1418
+void cache_seq_stop_rcu(struct seq_file *m, void *p)
1419
+ __releases(RCU)
1420
+{
1421
+ rcu_read_unlock();
1422
+}
1423
+EXPORT_SYMBOL_GPL(cache_seq_stop_rcu);
13651424
13661425 static int c_show(struct seq_file *m, void *p)
13671426 {
....@@ -1372,16 +1431,16 @@
13721431 return cd->cache_show(m, cd, NULL);
13731432
13741433 ifdebug(CACHE)
1375
- seq_printf(m, "# expiry=%ld refcnt=%d flags=%lx\n",
1434
+ seq_printf(m, "# expiry=%lld refcnt=%d flags=%lx\n",
13761435 convert_to_wallclock(cp->expiry_time),
13771436 kref_read(&cp->ref), cp->flags);
13781437 cache_get(cp);
13791438 if (cache_check(cd, cp, NULL))
13801439 /* cache_check does a cache_put on failure */
1381
- seq_printf(m, "# ");
1440
+ seq_puts(m, "# ");
13821441 else {
13831442 if (cache_is_expired(cd, cp))
1384
- seq_printf(m, "# ");
1443
+ seq_puts(m, "# ");
13851444 cache_put(cp, cd);
13861445 }
13871446
....@@ -1389,9 +1448,9 @@
13891448 }
13901449
13911450 static const struct seq_operations cache_content_op = {
1392
- .start = cache_seq_start,
1393
- .next = cache_seq_next,
1394
- .stop = cache_seq_stop,
1451
+ .start = cache_seq_start_rcu,
1452
+ .next = cache_seq_next_rcu,
1453
+ .stop = cache_seq_stop_rcu,
13951454 .show = c_show,
13961455 };
13971456
....@@ -1445,7 +1504,7 @@
14451504 char tbuf[22];
14461505 size_t len;
14471506
1448
- len = snprintf(tbuf, sizeof(tbuf), "%lu\n",
1507
+ len = snprintf(tbuf, sizeof(tbuf), "%llu\n",
14491508 convert_to_wallclock(cd->flush_time));
14501509 return simple_read_from_buffer(buf, count, ppos, tbuf, len);
14511510 }
....@@ -1456,7 +1515,7 @@
14561515 {
14571516 char tbuf[20];
14581517 char *ep;
1459
- time_t now;
1518
+ time64_t now;
14601519
14611520 if (*ppos || count > sizeof(tbuf)-1)
14621521 return -EINVAL;
....@@ -1485,6 +1544,9 @@
14851544 cd->flush_time = now;
14861545 cd->nextcheck = now;
14871546 cache_flush();
1547
+
1548
+ if (cd->flush)
1549
+ cd->flush();
14881550
14891551 *ppos += count;
14901552 return count;
....@@ -1536,15 +1598,14 @@
15361598 return cache_release(inode, filp, cd);
15371599 }
15381600
1539
-static const struct file_operations cache_file_operations_procfs = {
1540
- .owner = THIS_MODULE,
1541
- .llseek = no_llseek,
1542
- .read = cache_read_procfs,
1543
- .write = cache_write_procfs,
1544
- .poll = cache_poll_procfs,
1545
- .unlocked_ioctl = cache_ioctl_procfs, /* for FIONREAD */
1546
- .open = cache_open_procfs,
1547
- .release = cache_release_procfs,
1601
+static const struct proc_ops cache_channel_proc_ops = {
1602
+ .proc_lseek = no_llseek,
1603
+ .proc_read = cache_read_procfs,
1604
+ .proc_write = cache_write_procfs,
1605
+ .proc_poll = cache_poll_procfs,
1606
+ .proc_ioctl = cache_ioctl_procfs, /* for FIONREAD */
1607
+ .proc_open = cache_open_procfs,
1608
+ .proc_release = cache_release_procfs,
15481609 };
15491610
15501611 static int content_open_procfs(struct inode *inode, struct file *filp)
....@@ -1561,11 +1622,11 @@
15611622 return content_release(inode, filp, cd);
15621623 }
15631624
1564
-static const struct file_operations content_file_operations_procfs = {
1565
- .open = content_open_procfs,
1566
- .read = seq_read,
1567
- .llseek = seq_lseek,
1568
- .release = content_release_procfs,
1625
+static const struct proc_ops content_proc_ops = {
1626
+ .proc_open = content_open_procfs,
1627
+ .proc_read = seq_read,
1628
+ .proc_lseek = seq_lseek,
1629
+ .proc_release = content_release_procfs,
15691630 };
15701631
15711632 static int open_flush_procfs(struct inode *inode, struct file *filp)
....@@ -1599,12 +1660,12 @@
15991660 return write_flush(filp, buf, count, ppos, cd);
16001661 }
16011662
1602
-static const struct file_operations cache_flush_operations_procfs = {
1603
- .open = open_flush_procfs,
1604
- .read = read_flush_procfs,
1605
- .write = write_flush_procfs,
1606
- .release = release_flush_procfs,
1607
- .llseek = no_llseek,
1663
+static const struct proc_ops cache_flush_proc_ops = {
1664
+ .proc_open = open_flush_procfs,
1665
+ .proc_read = read_flush_procfs,
1666
+ .proc_write = write_flush_procfs,
1667
+ .proc_release = release_flush_procfs,
1668
+ .proc_lseek = no_llseek,
16081669 };
16091670
16101671 static void remove_cache_proc_entries(struct cache_detail *cd)
....@@ -1627,19 +1688,19 @@
16271688 goto out_nomem;
16281689
16291690 p = proc_create_data("flush", S_IFREG | 0600,
1630
- cd->procfs, &cache_flush_operations_procfs, cd);
1691
+ cd->procfs, &cache_flush_proc_ops, cd);
16311692 if (p == NULL)
16321693 goto out_nomem;
16331694
16341695 if (cd->cache_request || cd->cache_parse) {
16351696 p = proc_create_data("channel", S_IFREG | 0600, cd->procfs,
1636
- &cache_file_operations_procfs, cd);
1697
+ &cache_channel_proc_ops, cd);
16371698 if (p == NULL)
16381699 goto out_nomem;
16391700 }
16401701 if (cd->cache_show) {
16411702 p = proc_create_data("content", S_IFREG | 0400, cd->procfs,
1642
- &content_file_operations_procfs, cd);
1703
+ &content_proc_ops, cd);
16431704 if (p == NULL)
16441705 goto out_nomem;
16451706 }
....@@ -1849,13 +1910,12 @@
18491910
18501911 void sunrpc_cache_unhash(struct cache_detail *cd, struct cache_head *h)
18511912 {
1852
- write_lock(&cd->hash_lock);
1913
+ spin_lock(&cd->hash_lock);
18531914 if (!hlist_unhashed(&h->cache_list)){
1854
- hlist_del_init(&h->cache_list);
1855
- cd->entries--;
1856
- write_unlock(&cd->hash_lock);
1857
- cache_put(h, cd);
1915
+ sunrpc_begin_cache_remove_entry(h, cd);
1916
+ spin_unlock(&cd->hash_lock);
1917
+ sunrpc_end_cache_remove_entry(h, cd);
18581918 } else
1859
- write_unlock(&cd->hash_lock);
1919
+ spin_unlock(&cd->hash_lock);
18601920 }
18611921 EXPORT_SYMBOL_GPL(sunrpc_cache_unhash);