aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfsd
diff options
context:
space:
mode:
authorJeff Layton <jlayton@redhat.com>2013-01-28 14:41:11 -0500
committerJ. Bruce Fields <bfields@redhat.com>2013-02-04 09:16:22 -0500
commitf09841fdfad8dd95593725dfa70388f55b170947 (patch)
tree13154119afdf6df40317ea265512e3c1a8fcc984 /fs/nfsd
parent8a8bc40d9ba0890f88dbf7a7c8fa81ddc77c08e3 (diff)
nfsd: add alloc and free functions for DRC entries
Signed-off-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: J. Bruce Fields <bfields@redhat.com>
Diffstat (limited to 'fs/nfsd')
-rw-r--r--fs/nfsd/nfscache.c36
1 files changed, 27 insertions, 9 deletions
diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
index 4aad9e4a6161..363bc6188155 100644
--- a/fs/nfsd/nfscache.c
+++ b/fs/nfsd/nfscache.c
@@ -47,10 +47,34 @@ static int nfsd_cache_append(struct svc_rqst *rqstp, struct kvec *vec);
47 */ 47 */
48static DEFINE_SPINLOCK(cache_lock); 48static DEFINE_SPINLOCK(cache_lock);
49 49
50int nfsd_reply_cache_init(void) 50static struct svc_cacherep *
51nfsd_reply_cache_alloc(void)
51{ 52{
52 struct svc_cacherep *rp; 53 struct svc_cacherep *rp;
54
55 rp = kmem_cache_alloc(drc_slab, GFP_KERNEL);
56 if (rp) {
57 rp->c_state = RC_UNUSED;
58 rp->c_type = RC_NOCACHE;
59 INIT_LIST_HEAD(&rp->c_lru);
60 INIT_HLIST_NODE(&rp->c_hash);
61 }
62 return rp;
63}
64
65static void
66nfsd_reply_cache_free_locked(struct svc_cacherep *rp)
67{
68 if (rp->c_state == RC_DONE && rp->c_type == RC_REPLBUFF)
69 kfree(rp->c_replvec.iov_base);
70 list_del(&rp->c_lru);
71 kmem_cache_free(drc_slab, rp);
72}
73
74int nfsd_reply_cache_init(void)
75{
53 int i; 76 int i;
77 struct svc_cacherep *rp;
54 78
55 drc_slab = kmem_cache_create("nfsd_drc", sizeof(struct svc_cacherep), 79 drc_slab = kmem_cache_create("nfsd_drc", sizeof(struct svc_cacherep),
56 0, 0, NULL); 80 0, 0, NULL);
@@ -60,13 +84,10 @@ int nfsd_reply_cache_init(void)
60 INIT_LIST_HEAD(&lru_head); 84 INIT_LIST_HEAD(&lru_head);
61 i = CACHESIZE; 85 i = CACHESIZE;
62 while (i) { 86 while (i) {
63 rp = kmem_cache_alloc(drc_slab, GFP_KERNEL); 87 rp = nfsd_reply_cache_alloc();
64 if (!rp) 88 if (!rp)
65 goto out_nomem; 89 goto out_nomem;
66 list_add(&rp->c_lru, &lru_head); 90 list_add(&rp->c_lru, &lru_head);
67 rp->c_state = RC_UNUSED;
68 rp->c_type = RC_NOCACHE;
69 INIT_HLIST_NODE(&rp->c_hash);
70 i--; 91 i--;
71 } 92 }
72 93
@@ -88,10 +109,7 @@ void nfsd_reply_cache_shutdown(void)
88 109
89 while (!list_empty(&lru_head)) { 110 while (!list_empty(&lru_head)) {
90 rp = list_entry(lru_head.next, struct svc_cacherep, c_lru); 111 rp = list_entry(lru_head.next, struct svc_cacherep, c_lru);
91 if (rp->c_state == RC_DONE && rp->c_type == RC_REPLBUFF) 112 nfsd_reply_cache_free_locked(rp);
92 kfree(rp->c_replvec.iov_base);
93 list_del(&rp->c_lru);
94 kmem_cache_free(drc_slab, rp);
95 } 113 }
96 114
97 cache_disabled = 1; 115 cache_disabled = 1;