Skip to content

Commit d5c3428

Browse files
author
J. Bruce Fields
committed
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 <[email protected]> Signed-off-by: J. Bruce Fields <[email protected]>
1 parent 26808d3 commit d5c3428

File tree

3 files changed

+21
-22
lines changed

3 files changed

+21
-22
lines changed

fs/nfsd/nfscache.c

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,41 +44,37 @@ static int nfsd_cache_append(struct svc_rqst *rqstp, struct kvec *vec);
4444
*/
4545
static DEFINE_SPINLOCK(cache_lock);
4646

47-
void
48-
nfsd_cache_init(void)
47+
int nfsd_reply_cache_init(void)
4948
{
5049
struct svc_cacherep *rp;
5150
int i;
5251

5352
INIT_LIST_HEAD(&lru_head);
5453
i = CACHESIZE;
55-
while(i) {
54+
while (i) {
5655
rp = kmalloc(sizeof(*rp), GFP_KERNEL);
57-
if (!rp) break;
56+
if (!rp)
57+
goto out_nomem;
5858
list_add(&rp->c_lru, &lru_head);
5959
rp->c_state = RC_UNUSED;
6060
rp->c_type = RC_NOCACHE;
6161
INIT_HLIST_NODE(&rp->c_hash);
6262
i--;
6363
}
6464

65-
if (i)
66-
printk (KERN_ERR "nfsd: cannot allocate all %d cache entries, only got %d\n",
67-
CACHESIZE, CACHESIZE-i);
68-
6965
hash_list = kcalloc (HASHSIZE, sizeof(struct hlist_head), GFP_KERNEL);
70-
if (!hash_list) {
71-
nfsd_cache_shutdown();
72-
printk (KERN_ERR "nfsd: cannot allocate %Zd bytes for hash list\n",
73-
HASHSIZE * sizeof(struct hlist_head));
74-
return;
75-
}
66+
if (!hash_list)
67+
goto out_nomem;
7668

7769
cache_disabled = 0;
70+
return 0;
71+
out_nomem:
72+
printk(KERN_ERR "nfsd: failed to allocate reply cache\n");
73+
nfsd_reply_cache_shutdown();
74+
return -ENOMEM;
7875
}
7976

80-
void
81-
nfsd_cache_shutdown(void)
77+
void nfsd_reply_cache_shutdown(void)
8278
{
8379
struct svc_cacherep *rp;
8480

fs/nfsd/nfsctl.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,9 @@ static int __init init_nfsd(void)
683683
if (retval)
684684
return retval;
685685
nfsd_stat_init(); /* Statistics */
686-
nfsd_cache_init(); /* RPC reply cache */
686+
retval = nfsd_reply_cache_init();
687+
if (retval)
688+
goto out_free_stat;
687689
nfsd_export_init(); /* Exports table */
688690
nfsd_lockd_init(); /* lockd->nfsd callbacks */
689691
nfsd_idmap_init(); /* Name to ID mapping */
@@ -700,19 +702,20 @@ static int __init init_nfsd(void)
700702
out_free_all:
701703
nfsd_idmap_shutdown();
702704
nfsd_export_shutdown();
703-
nfsd_cache_shutdown();
705+
nfsd_reply_cache_shutdown();
704706
remove_proc_entry("fs/nfs/exports", NULL);
705707
remove_proc_entry("fs/nfs", NULL);
706-
nfsd_stat_shutdown();
707708
nfsd_lockd_shutdown();
709+
out_free_stat:
710+
nfsd_stat_shutdown();
708711
nfsd4_free_slabs();
709712
return retval;
710713
}
711714

712715
static void __exit exit_nfsd(void)
713716
{
714717
nfsd_export_shutdown();
715-
nfsd_cache_shutdown();
718+
nfsd_reply_cache_shutdown();
716719
remove_proc_entry("fs/nfs/exports", NULL);
717720
remove_proc_entry("fs/nfs", NULL);
718721
nfsd_stat_shutdown();

include/linux/nfsd/cache.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ enum {
7272
*/
7373
#define RC_DELAY (HZ/5)
7474

75-
void nfsd_cache_init(void);
76-
void nfsd_cache_shutdown(void);
75+
int nfsd_reply_cache_init(void);
76+
void nfsd_reply_cache_shutdown(void);
7777
int nfsd_cache_lookup(struct svc_rqst *, int);
7878
void nfsd_cache_update(struct svc_rqst *, int, __be32 *);
7979

0 commit comments

Comments
 (0)