aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfsd/nfscache.c
diff options
context:
space:
mode:
authorJ. Bruce Fields <bfields@citi.umich.edu>2007-11-09 14:10:56 -0500
committerJ. Bruce Fields <bfields@citi.umich.edu>2008-02-01 16:42:04 -0500
commitd5c3428b2cb26d605fddc4878f4fcc03c23df89f (patch)
treeb476ca0b6709b65044f222912f2fdd2efbdcf297 /fs/nfsd/nfscache.c
parent26808d3f10b1213bbb6e27d441be40e20ab84611 (diff)
nfsd: fail module init on reply cache init failure
If the reply cache initialization fails due to a kmalloc failure, currently we try to soldier on with a reduced (or nonexistant) reply cache. Better to just fail immediately: the failure is then much easier to understand and debug, and it could save us complexity in some later code. (But actually, it doesn't help currently because the cache is also turned off in some odd failure cases; we should probably find a better way to handle those failure cases some day.) Fix some minor style problems while we're at it, and rename nfsd_cache_init() to remove the need for a comment describing it. Acked-by: NeilBrown <neilb@suse.de> Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
Diffstat (limited to 'fs/nfsd/nfscache.c')
-rw-r--r--fs/nfsd/nfscache.c28
1 files changed, 12 insertions, 16 deletions
diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
index 578f2c9d56be..5bfc2ac60d54 100644
--- a/fs/nfsd/nfscache.c
+++ b/fs/nfsd/nfscache.c
@@ -44,17 +44,17 @@ static int nfsd_cache_append(struct svc_rqst *rqstp, struct kvec *vec);
44 */ 44 */
45static DEFINE_SPINLOCK(cache_lock); 45static DEFINE_SPINLOCK(cache_lock);
46 46
47void 47int nfsd_reply_cache_init(void)
48nfsd_cache_init(void)
49{ 48{
50 struct svc_cacherep *rp; 49 struct svc_cacherep *rp;
51 int i; 50 int i;
52 51
53 INIT_LIST_HEAD(&lru_head); 52 INIT_LIST_HEAD(&lru_head);
54 i = CACHESIZE; 53 i = CACHESIZE;
55 while(i) { 54 while (i) {
56 rp = kmalloc(sizeof(*rp), GFP_KERNEL); 55 rp = kmalloc(sizeof(*rp), GFP_KERNEL);
57 if (!rp) break; 56 if (!rp)
57 goto out_nomem;
58 list_add(&rp->c_lru, &lru_head); 58 list_add(&rp->c_lru, &lru_head);
59 rp->c_state = RC_UNUSED; 59 rp->c_state = RC_UNUSED;
60 rp->c_type = RC_NOCACHE; 60 rp->c_type = RC_NOCACHE;
@@ -62,23 +62,19 @@ nfsd_cache_init(void)
62 i--; 62 i--;
63 } 63 }
64 64
65 if (i)
66 printk (KERN_ERR "nfsd: cannot allocate all %d cache entries, only got %d\n",
67 CACHESIZE, CACHESIZE-i);
68
69 hash_list = kcalloc (HASHSIZE, sizeof(struct hlist_head), GFP_KERNEL); 65 hash_list = kcalloc (HASHSIZE, sizeof(struct hlist_head), GFP_KERNEL);
70 if (!hash_list) { 66 if (!hash_list)
71 nfsd_cache_shutdown(); 67 goto out_nomem;
72 printk (KERN_ERR "nfsd: cannot allocate %Zd bytes for hash list\n",
73 HASHSIZE * sizeof(struct hlist_head));
74 return;
75 }
76 68
77 cache_disabled = 0; 69 cache_disabled = 0;
70 return 0;
71out_nomem:
72 printk(KERN_ERR "nfsd: failed to allocate reply cache\n");
73 nfsd_reply_cache_shutdown();
74 return -ENOMEM;
78} 75}
79 76
80void 77void nfsd_reply_cache_shutdown(void)
81nfsd_cache_shutdown(void)
82{ 78{
83 struct svc_cacherep *rp; 79 struct svc_cacherep *rp;
84 80