]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - fs/nfsd/nfscache.c
nfsd: don't call nfsd_reply_cache_shutdown twice
[mirror_ubuntu-hirsute-kernel.git] / fs / nfsd / nfscache.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
1da177e4 2/*
1da177e4
LT
3 * Request reply cache. This is currently a global cache, but this may
4 * change in the future and be a per-client cache.
5 *
6 * This code is heavily inspired by the 44BSD implementation, although
7 * it does things a bit differently.
8 *
9 * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
10 */
11
5a0e3ad6 12#include <linux/slab.h>
8f97514b 13#include <linux/vmalloc.h>
5976687a 14#include <linux/sunrpc/addr.h>
0338dd15 15#include <linux/highmem.h>
0733c7ba
JL
16#include <linux/log2.h>
17#include <linux/hash.h>
01a7decf 18#include <net/checksum.h>
5a0e3ad6 19
9a74af21
BH
20#include "nfsd.h"
21#include "cache.h"
1da177e4 22
0338dd15
JL
23#define NFSDDBG_FACILITY NFSDDBG_REPCACHE
24
0733c7ba
JL
25/*
26 * We use this value to determine the number of hash buckets from the max
27 * cache size, the idea being that when the cache is at its maximum number
28 * of entries, then this should be the average number of entries per bucket.
29 */
30#define TARGET_BUCKET_SIZE 64
1da177e4 31
7142b98d 32struct nfsd_drc_bucket {
736c6625 33 struct rb_root rb_head;
bedd4b61 34 struct list_head lru_head;
89a26b3d 35 spinlock_t cache_lock;
7142b98d
TM
36};
37
38static struct nfsd_drc_bucket *drc_hashtbl;
8a8bc40d 39static struct kmem_cache *drc_slab;
9dc56143
JL
40
41/* max number of entries allowed in the cache */
0338dd15 42static unsigned int max_drc_entries;
1da177e4 43
0733c7ba
JL
44/* number of significant bits in the hash value */
45static unsigned int maskbits;
bedd4b61 46static unsigned int drc_hashsize;
0733c7ba 47
9dc56143
JL
48/*
49 * Stats and other tracking of on the duplicate reply cache. All of these and
50 * the "rc" fields in nfsdstats are protected by the cache_lock
51 */
52
53/* total number of entries */
31e60f52 54static atomic_t num_drc_entries;
9dc56143
JL
55
56/* cache misses due only to checksum comparison failures */
57static unsigned int payload_misses;
58
6c6910cd
JL
59/* amount of memory (in bytes) currently consumed by the DRC */
60static unsigned int drc_mem_usage;
61
98d821bd
JL
62/* longest hash chain seen */
63static unsigned int longest_chain;
64
65/* size of cache when we saw the longest hash chain */
66static unsigned int longest_chain_cachesize;
67
1da177e4 68static int nfsd_cache_append(struct svc_rqst *rqstp, struct kvec *vec);
1ab6c499
DC
69static unsigned long nfsd_reply_cache_count(struct shrinker *shrink,
70 struct shrink_control *sc);
71static unsigned long nfsd_reply_cache_scan(struct shrinker *shrink,
72 struct shrink_control *sc);
b4e7f2c9 73
c8c797f9 74static struct shrinker nfsd_reply_cache_shrinker = {
1ab6c499
DC
75 .scan_objects = nfsd_reply_cache_scan,
76 .count_objects = nfsd_reply_cache_count,
b4e7f2c9
JL
77 .seeks = 1,
78};
1da177e4 79
0338dd15
JL
80/*
81 * Put a cap on the size of the DRC based on the amount of available
82 * low memory in the machine.
83 *
84 * 64MB: 8192
85 * 128MB: 11585
86 * 256MB: 16384
87 * 512MB: 23170
88 * 1GB: 32768
89 * 2GB: 46340
90 * 4GB: 65536
91 * 8GB: 92681
92 * 16GB: 131072
93 *
94 * ...with a hard cap of 256k entries. In the worst case, each entry will be
95 * ~1k, so the above numbers should give a rough max of the amount of memory
96 * used in k.
97 */
98static unsigned int
99nfsd_cache_size_limit(void)
100{
101 unsigned int limit;
ca79b0c2 102 unsigned long low_pages = totalram_pages() - totalhigh_pages();
0338dd15
JL
103
104 limit = (16 * int_sqrt(low_pages)) << (PAGE_SHIFT-10);
105 return min_t(unsigned int, limit, 256*1024);
106}
107
0733c7ba
JL
108/*
109 * Compute the number of hash buckets we need. Divide the max cachesize by
110 * the "target" max bucket size, and round up to next power of two.
111 */
112static unsigned int
113nfsd_hashsize(unsigned int limit)
114{
115 return roundup_pow_of_two(limit / TARGET_BUCKET_SIZE);
116}
117
7142b98d
TM
118static u32
119nfsd_cache_hash(__be32 xid)
120{
121 return hash_32(be32_to_cpu(xid), maskbits);
122}
123
f09841fd 124static struct svc_cacherep *
76ecec21 125nfsd_reply_cache_alloc(struct svc_rqst *rqstp, __wsum csum)
1da177e4
LT
126{
127 struct svc_cacherep *rp;
1da177e4 128
f09841fd
JL
129 rp = kmem_cache_alloc(drc_slab, GFP_KERNEL);
130 if (rp) {
1da177e4
LT
131 rp->c_state = RC_UNUSED;
132 rp->c_type = RC_NOCACHE;
736c6625 133 RB_CLEAR_NODE(&rp->c_node);
f09841fd 134 INIT_LIST_HEAD(&rp->c_lru);
76ecec21 135
ed00c2f6
TM
136 memset(&rp->c_key, 0, sizeof(rp->c_key));
137 rp->c_key.k_xid = rqstp->rq_xid;
138 rp->c_key.k_proc = rqstp->rq_proc;
139 rpc_copy_addr((struct sockaddr *)&rp->c_key.k_addr, svc_addr(rqstp));
140 rpc_set_port((struct sockaddr *)&rp->c_key.k_addr, rpc_get_port(svc_addr(rqstp)));
141 rp->c_key.k_prot = rqstp->rq_prot;
142 rp->c_key.k_vers = rqstp->rq_vers;
143 rp->c_key.k_len = rqstp->rq_arg.len;
144 rp->c_key.k_csum = csum;
1da177e4 145 }
f09841fd
JL
146 return rp;
147}
1da177e4 148
f09841fd 149static void
736c6625 150nfsd_reply_cache_free_locked(struct nfsd_drc_bucket *b, struct svc_cacherep *rp)
f09841fd 151{
6c6910cd
JL
152 if (rp->c_type == RC_REPLBUFF && rp->c_replvec.iov_base) {
153 drc_mem_usage -= rp->c_replvec.iov_len;
f09841fd 154 kfree(rp->c_replvec.iov_base);
6c6910cd 155 }
76ecec21 156 if (rp->c_state != RC_UNUSED) {
736c6625 157 rb_erase(&rp->c_node, &b->rb_head);
76ecec21
TM
158 list_del(&rp->c_lru);
159 atomic_dec(&num_drc_entries);
160 drc_mem_usage -= sizeof(*rp);
161 }
f09841fd
JL
162 kmem_cache_free(drc_slab, rp);
163}
164
2c6b691c 165static void
89a26b3d 166nfsd_reply_cache_free(struct nfsd_drc_bucket *b, struct svc_cacherep *rp)
2c6b691c 167{
89a26b3d 168 spin_lock(&b->cache_lock);
736c6625 169 nfsd_reply_cache_free_locked(b, rp);
89a26b3d 170 spin_unlock(&b->cache_lock);
2c6b691c
JL
171}
172
f09841fd
JL
173int nfsd_reply_cache_init(void)
174{
0733c7ba 175 unsigned int hashsize;
bedd4b61 176 unsigned int i;
a68465c9 177 int status = 0;
0733c7ba 178
ac534ff2 179 max_drc_entries = nfsd_cache_size_limit();
31e60f52 180 atomic_set(&num_drc_entries, 0);
0733c7ba
JL
181 hashsize = nfsd_hashsize(max_drc_entries);
182 maskbits = ilog2(hashsize);
ac534ff2 183
a68465c9
KM
184 status = register_shrinker(&nfsd_reply_cache_shrinker);
185 if (status)
186 return status;
187
8a8bc40d
JL
188 drc_slab = kmem_cache_create("nfsd_drc", sizeof(struct svc_cacherep),
189 0, 0, NULL);
190 if (!drc_slab)
191 goto out_nomem;
192
7142b98d 193 drc_hashtbl = kcalloc(hashsize, sizeof(*drc_hashtbl), GFP_KERNEL);
8f97514b 194 if (!drc_hashtbl) {
fad953ce
KC
195 drc_hashtbl = vzalloc(array_size(hashsize,
196 sizeof(*drc_hashtbl)));
8f97514b
JL
197 if (!drc_hashtbl)
198 goto out_nomem;
199 }
200
89a26b3d 201 for (i = 0; i < hashsize; i++) {
bedd4b61 202 INIT_LIST_HEAD(&drc_hashtbl[i].lru_head);
89a26b3d
TM
203 spin_lock_init(&drc_hashtbl[i].cache_lock);
204 }
bedd4b61 205 drc_hashsize = hashsize;
1da177e4 206
d5c3428b
BF
207 return 0;
208out_nomem:
209 printk(KERN_ERR "nfsd: failed to allocate reply cache\n");
d5c3428b 210 return -ENOMEM;
1da177e4
LT
211}
212
d5c3428b 213void nfsd_reply_cache_shutdown(void)
1da177e4
LT
214{
215 struct svc_cacherep *rp;
bedd4b61 216 unsigned int i;
1da177e4 217
b4e7f2c9 218 unregister_shrinker(&nfsd_reply_cache_shrinker);
aca8a23d 219
bedd4b61
TM
220 for (i = 0; i < drc_hashsize; i++) {
221 struct list_head *head = &drc_hashtbl[i].lru_head;
222 while (!list_empty(head)) {
223 rp = list_first_entry(head, struct svc_cacherep, c_lru);
736c6625 224 nfsd_reply_cache_free_locked(&drc_hashtbl[i], rp);
bedd4b61 225 }
1da177e4
LT
226 }
227
8f97514b 228 kvfree(drc_hashtbl);
7142b98d 229 drc_hashtbl = NULL;
bedd4b61 230 drc_hashsize = 0;
8a8bc40d 231
e79017dd
JL
232 kmem_cache_destroy(drc_slab);
233 drc_slab = NULL;
1da177e4
LT
234}
235
236/*
aca8a23d
JL
237 * Move cache entry to end of LRU list, and queue the cleaner to run if it's
238 * not already scheduled.
1da177e4
LT
239 */
240static void
bedd4b61 241lru_put_end(struct nfsd_drc_bucket *b, struct svc_cacherep *rp)
1da177e4 242{
56c2548b 243 rp->c_timestamp = jiffies;
bedd4b61 244 list_move_tail(&rp->c_lru, &b->lru_head);
1da177e4
LT
245}
246
1ab6c499 247static long
bedd4b61 248prune_bucket(struct nfsd_drc_bucket *b)
aca8a23d
JL
249{
250 struct svc_cacherep *rp, *tmp;
1ab6c499 251 long freed = 0;
aca8a23d 252
bedd4b61 253 list_for_each_entry_safe(rp, tmp, &b->lru_head, c_lru) {
1b19453d
JL
254 /*
255 * Don't free entries attached to calls that are still
256 * in-progress, but do keep scanning the list.
257 */
258 if (rp->c_state == RC_INPROG)
259 continue;
31e60f52 260 if (atomic_read(&num_drc_entries) <= max_drc_entries &&
1b19453d 261 time_before(jiffies, rp->c_timestamp + RC_EXPIRE))
aca8a23d 262 break;
736c6625 263 nfsd_reply_cache_free_locked(b, rp);
1ab6c499 264 freed++;
aca8a23d 265 }
bedd4b61
TM
266 return freed;
267}
268
269/*
270 * Walk the LRU list and prune off entries that are older than RC_EXPIRE.
271 * Also prune the oldest ones when the total exceeds the max number of entries.
272 */
273static long
274prune_cache_entries(void)
275{
276 unsigned int i;
277 long freed = 0;
bedd4b61
TM
278
279 for (i = 0; i < drc_hashsize; i++) {
280 struct nfsd_drc_bucket *b = &drc_hashtbl[i];
281
89a26b3d
TM
282 if (list_empty(&b->lru_head))
283 continue;
284 spin_lock(&b->cache_lock);
bedd4b61 285 freed += prune_bucket(b);
89a26b3d 286 spin_unlock(&b->cache_lock);
bedd4b61 287 }
1ab6c499 288 return freed;
aca8a23d
JL
289}
290
1ab6c499
DC
291static unsigned long
292nfsd_reply_cache_count(struct shrinker *shrink, struct shrink_control *sc)
b4e7f2c9 293{
31e60f52 294 return atomic_read(&num_drc_entries);
b4e7f2c9
JL
295}
296
1ab6c499
DC
297static unsigned long
298nfsd_reply_cache_scan(struct shrinker *shrink, struct shrink_control *sc)
299{
89a26b3d 300 return prune_cache_entries();
1ab6c499 301}
01a7decf
JL
302/*
303 * Walk an xdr_buf and get a CRC for at most the first RC_CSUMLEN bytes
304 */
305static __wsum
306nfsd_cache_csum(struct svc_rqst *rqstp)
307{
308 int idx;
309 unsigned int base;
310 __wsum csum;
311 struct xdr_buf *buf = &rqstp->rq_arg;
312 const unsigned char *p = buf->head[0].iov_base;
313 size_t csum_len = min_t(size_t, buf->head[0].iov_len + buf->page_len,
314 RC_CSUMLEN);
315 size_t len = min(buf->head[0].iov_len, csum_len);
316
317 /* rq_arg.head first */
318 csum = csum_partial(p, len, 0);
319 csum_len -= len;
320
321 /* Continue into page array */
322 idx = buf->page_base / PAGE_SIZE;
323 base = buf->page_base & ~PAGE_MASK;
324 while (csum_len) {
325 p = page_address(buf->pages[idx]) + base;
56edc86b 326 len = min_t(size_t, PAGE_SIZE - base, csum_len);
01a7decf
JL
327 csum = csum_partial(p, len, csum);
328 csum_len -= len;
329 base = 0;
330 ++idx;
331 }
332 return csum;
333}
334
ed00c2f6
TM
335static int
336nfsd_cache_key_cmp(const struct svc_cacherep *key, const struct svc_cacherep *rp)
9dc56143 337{
ed00c2f6
TM
338 if (key->c_key.k_xid == rp->c_key.k_xid &&
339 key->c_key.k_csum != rp->c_key.k_csum)
9dc56143 340 ++payload_misses;
ef9b16dc 341
ed00c2f6 342 return memcmp(&key->c_key, &rp->c_key, sizeof(key->c_key));
9dc56143
JL
343}
344
a4a3ec32
JL
345/*
346 * Search the request hash for an entry that matches the given rqstp.
347 * Must be called with cache_lock held. Returns the found entry or
76ecec21 348 * inserts an empty key on failure.
a4a3ec32
JL
349 */
350static struct svc_cacherep *
76ecec21 351nfsd_cache_insert(struct nfsd_drc_bucket *b, struct svc_cacherep *key)
a4a3ec32 352{
76ecec21 353 struct svc_cacherep *rp, *ret = key;
736c6625
TM
354 struct rb_node **p = &b->rb_head.rb_node,
355 *parent = NULL;
98d821bd 356 unsigned int entries = 0;
736c6625 357 int cmp;
a4a3ec32 358
736c6625 359 while (*p != NULL) {
98d821bd 360 ++entries;
736c6625
TM
361 parent = *p;
362 rp = rb_entry(parent, struct svc_cacherep, c_node);
363
364 cmp = nfsd_cache_key_cmp(key, rp);
365 if (cmp < 0)
366 p = &parent->rb_left;
367 else if (cmp > 0)
368 p = &parent->rb_right;
369 else {
98d821bd 370 ret = rp;
736c6625 371 goto out;
98d821bd
JL
372 }
373 }
736c6625
TM
374 rb_link_node(&key->c_node, parent, p);
375 rb_insert_color(&key->c_node, &b->rb_head);
376out:
98d821bd
JL
377 /* tally hash chain length stats */
378 if (entries > longest_chain) {
379 longest_chain = entries;
31e60f52 380 longest_chain_cachesize = atomic_read(&num_drc_entries);
98d821bd
JL
381 } else if (entries == longest_chain) {
382 /* prefer to keep the smallest cachesize possible here */
31e60f52
TM
383 longest_chain_cachesize = min_t(unsigned int,
384 longest_chain_cachesize,
385 atomic_read(&num_drc_entries));
a4a3ec32 386 }
98d821bd 387
76ecec21 388 lru_put_end(b, ret);
98d821bd 389 return ret;
a4a3ec32
JL
390}
391
1da177e4
LT
392/*
393 * Try to find an entry matching the current call in the cache. When none
1ac83629
JL
394 * is found, we try to grab the oldest expired entry off the LRU list. If
395 * a suitable one isn't there, then drop the cache_lock and allocate a
396 * new one, then search again in case one got inserted while this thread
397 * didn't hold the lock.
1da177e4
LT
398 */
399int
1091006c 400nfsd_cache_lookup(struct svc_rqst *rqstp)
1da177e4 401{
0338dd15 402 struct svc_cacherep *rp, *found;
c7afef1f 403 __be32 xid = rqstp->rq_xid;
01a7decf 404 __wsum csum;
7142b98d
TM
405 u32 hash = nfsd_cache_hash(xid);
406 struct nfsd_drc_bucket *b = &drc_hashtbl[hash];
1091006c 407 int type = rqstp->rq_cachetype;
0b9ea37f 408 int rtn = RC_DOIT;
1da177e4
LT
409
410 rqstp->rq_cacherep = NULL;
13cc8a78 411 if (type == RC_NOCACHE) {
1da177e4 412 nfsdstats.rcnocache++;
0b9ea37f 413 return rtn;
1da177e4
LT
414 }
415
01a7decf
JL
416 csum = nfsd_cache_csum(rqstp);
417
0b9ea37f
JL
418 /*
419 * Since the common case is a cache miss followed by an insert,
a0ef5e19 420 * preallocate an entry.
0b9ea37f 421 */
76ecec21
TM
422 rp = nfsd_reply_cache_alloc(rqstp, csum);
423 if (!rp) {
424 dprintk("nfsd: unable to allocate DRC entry!\n");
425 return rtn;
6c6910cd 426 }
0338dd15 427
76ecec21
TM
428 spin_lock(&b->cache_lock);
429 found = nfsd_cache_insert(b, rp);
430 if (found != rp) {
736c6625 431 nfsd_reply_cache_free_locked(NULL, rp);
0338dd15
JL
432 rp = found;
433 goto found_entry;
1da177e4
LT
434 }
435
0338dd15 436 nfsdstats.rcmisses++;
1da177e4
LT
437 rqstp->rq_cacherep = rp;
438 rp->c_state = RC_INPROG;
76ecec21
TM
439
440 atomic_inc(&num_drc_entries);
441 drc_mem_usage += sizeof(*rp);
442
443 /* go ahead and prune the cache */
444 prune_bucket(b);
1da177e4 445 out:
89a26b3d 446 spin_unlock(&b->cache_lock);
1da177e4
LT
447 return rtn;
448
449found_entry:
450 /* We found a matching entry which is either in progress or done. */
76ecec21 451 nfsdstats.rchits++;
1da177e4 452 rtn = RC_DROPIT;
76ecec21 453
7e5d0e0d
TM
454 /* Request being processed */
455 if (rp->c_state == RC_INPROG)
1da177e4
LT
456 goto out;
457
458 /* From the hall of fame of impractical attacks:
459 * Is this a user who tries to snoop on the cache? */
460 rtn = RC_DOIT;
4d152e2c 461 if (!test_bit(RQ_SECURE, &rqstp->rq_flags) && rp->c_secure)
1da177e4
LT
462 goto out;
463
464 /* Compose RPC reply header */
465 switch (rp->c_type) {
466 case RC_NOCACHE:
467 break;
468 case RC_REPLSTAT:
469 svc_putu32(&rqstp->rq_res.head[0], rp->c_replstat);
470 rtn = RC_REPLY;
471 break;
472 case RC_REPLBUFF:
473 if (!nfsd_cache_append(rqstp, &rp->c_replvec))
474 goto out; /* should not happen */
475 rtn = RC_REPLY;
476 break;
477 default:
478 printk(KERN_WARNING "nfsd: bad repcache type %d\n", rp->c_type);
736c6625 479 nfsd_reply_cache_free_locked(b, rp);
1da177e4
LT
480 }
481
482 goto out;
483}
484
485/*
486 * Update a cache entry. This is called from nfsd_dispatch when
487 * the procedure has been executed and the complete reply is in
488 * rqstp->rq_res.
489 *
490 * We're copying around data here rather than swapping buffers because
491 * the toplevel loop requires max-sized buffers, which would be a waste
492 * of memory for a cache with a max reply size of 100 bytes (diropokres).
493 *
494 * If we should start to use different types of cache entries tailored
495 * specifically for attrstat and fh's, we may save even more space.
496 *
497 * Also note that a cachetype of RC_NOCACHE can legally be passed when
498 * nfsd failed to encode a reply that otherwise would have been cached.
499 * In this case, nfsd_cache_update is called with statp == NULL.
500 */
501void
c7afef1f 502nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
1da177e4 503{
13cc8a78 504 struct svc_cacherep *rp = rqstp->rq_cacherep;
1da177e4 505 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
bedd4b61
TM
506 u32 hash;
507 struct nfsd_drc_bucket *b;
1da177e4 508 int len;
6c6910cd 509 size_t bufsize = 0;
1da177e4 510
13cc8a78 511 if (!rp)
1da177e4
LT
512 return;
513
ed00c2f6 514 hash = nfsd_cache_hash(rp->c_key.k_xid);
bedd4b61
TM
515 b = &drc_hashtbl[hash];
516
1da177e4
LT
517 len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
518 len >>= 2;
fca4217c 519
1da177e4
LT
520 /* Don't cache excessive amounts of data and XDR failures */
521 if (!statp || len > (256 >> 2)) {
89a26b3d 522 nfsd_reply_cache_free(b, rp);
1da177e4
LT
523 return;
524 }
525
526 switch (cachetype) {
527 case RC_REPLSTAT:
528 if (len != 1)
529 printk("nfsd: RC_REPLSTAT/reply len %d!\n",len);
530 rp->c_replstat = *statp;
531 break;
532 case RC_REPLBUFF:
533 cachv = &rp->c_replvec;
6c6910cd
JL
534 bufsize = len << 2;
535 cachv->iov_base = kmalloc(bufsize, GFP_KERNEL);
1da177e4 536 if (!cachv->iov_base) {
89a26b3d 537 nfsd_reply_cache_free(b, rp);
1da177e4
LT
538 return;
539 }
6c6910cd
JL
540 cachv->iov_len = bufsize;
541 memcpy(cachv->iov_base, statp, bufsize);
1da177e4 542 break;
2c6b691c 543 case RC_NOCACHE:
89a26b3d 544 nfsd_reply_cache_free(b, rp);
2c6b691c 545 return;
1da177e4 546 }
89a26b3d 547 spin_lock(&b->cache_lock);
6c6910cd 548 drc_mem_usage += bufsize;
bedd4b61 549 lru_put_end(b, rp);
4d152e2c 550 rp->c_secure = test_bit(RQ_SECURE, &rqstp->rq_flags);
1da177e4
LT
551 rp->c_type = cachetype;
552 rp->c_state = RC_DONE;
89a26b3d 553 spin_unlock(&b->cache_lock);
1da177e4
LT
554 return;
555}
556
557/*
558 * Copy cached reply to current reply buffer. Should always fit.
559 * FIXME as reply is in a page, we should just attach the page, and
560 * keep a refcount....
561 */
562static int
563nfsd_cache_append(struct svc_rqst *rqstp, struct kvec *data)
564{
565 struct kvec *vec = &rqstp->rq_res.head[0];
566
567 if (vec->iov_len + data->iov_len > PAGE_SIZE) {
5b5e0928 568 printk(KERN_WARNING "nfsd: cached reply too large (%zd).\n",
1da177e4
LT
569 data->iov_len);
570 return 0;
571 }
572 memcpy((char*)vec->iov_base + vec->iov_len, data->iov_base, data->iov_len);
573 vec->iov_len += data->iov_len;
574 return 1;
575}
a2f999a3
JL
576
577/*
578 * Note that fields may be added, removed or reordered in the future. Programs
579 * scraping this file for info should test the labels to ensure they're
580 * getting the correct field.
581 */
582static int nfsd_reply_cache_stats_show(struct seq_file *m, void *v)
583{
a2f999a3 584 seq_printf(m, "max entries: %u\n", max_drc_entries);
31e60f52
TM
585 seq_printf(m, "num entries: %u\n",
586 atomic_read(&num_drc_entries));
0733c7ba 587 seq_printf(m, "hash buckets: %u\n", 1 << maskbits);
a2f999a3
JL
588 seq_printf(m, "mem usage: %u\n", drc_mem_usage);
589 seq_printf(m, "cache hits: %u\n", nfsdstats.rchits);
590 seq_printf(m, "cache misses: %u\n", nfsdstats.rcmisses);
591 seq_printf(m, "not cached: %u\n", nfsdstats.rcnocache);
592 seq_printf(m, "payload misses: %u\n", payload_misses);
98d821bd
JL
593 seq_printf(m, "longest chain len: %u\n", longest_chain);
594 seq_printf(m, "cachesize at longest: %u\n", longest_chain_cachesize);
a2f999a3
JL
595 return 0;
596}
597
598int nfsd_reply_cache_stats_open(struct inode *inode, struct file *file)
599{
600 return single_open(file, nfsd_reply_cache_stats_show, NULL);
601}