]> err.no Git - linux-2.6/commitdiff
nfsd: fail module init on reply cache init failure
authorJ. Bruce Fields <bfields@citi.umich.edu>
Fri, 9 Nov 2007 19:10:56 +0000 (14:10 -0500)
committerJ. Bruce Fields <bfields@citi.umich.edu>
Fri, 1 Feb 2008 21:42:04 +0000 (16:42 -0500)
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>
fs/nfsd/nfscache.c
fs/nfsd/nfsctl.c
include/linux/nfsd/cache.h

index 578f2c9d56bec09899d4dc1c0ca135320e7c6bf9..5bfc2ac60d543a07a8d70d71057cf880d1bb995e 100644 (file)
@@ -44,17 +44,17 @@ static int  nfsd_cache_append(struct svc_rqst *rqstp, struct kvec *vec);
  */
 static DEFINE_SPINLOCK(cache_lock);
 
-void
-nfsd_cache_init(void)
+int nfsd_reply_cache_init(void)
 {
        struct svc_cacherep     *rp;
        int                     i;
 
        INIT_LIST_HEAD(&lru_head);
        i = CACHESIZE;
-       while(i) {
+       while (i) {
                rp = kmalloc(sizeof(*rp), GFP_KERNEL);
-               if (!rp) break;
+               if (!rp)
+                       goto out_nomem;
                list_add(&rp->c_lru, &lru_head);
                rp->c_state = RC_UNUSED;
                rp->c_type = RC_NOCACHE;
@@ -62,23 +62,19 @@ nfsd_cache_init(void)
                i--;
        }
 
-       if (i)
-               printk (KERN_ERR "nfsd: cannot allocate all %d cache entries, only got %d\n",
-                       CACHESIZE, CACHESIZE-i);
-
        hash_list = kcalloc (HASHSIZE, sizeof(struct hlist_head), GFP_KERNEL);
-       if (!hash_list) {
-               nfsd_cache_shutdown();
-               printk (KERN_ERR "nfsd: cannot allocate %Zd bytes for hash list\n",
-                       HASHSIZE * sizeof(struct hlist_head));
-               return;
-       }
+       if (!hash_list)
+               goto out_nomem;
 
        cache_disabled = 0;
+       return 0;
+out_nomem:
+       printk(KERN_ERR "nfsd: failed to allocate reply cache\n");
+       nfsd_reply_cache_shutdown();
+       return -ENOMEM;
 }
 
-void
-nfsd_cache_shutdown(void)
+void nfsd_reply_cache_shutdown(void)
 {
        struct svc_cacherep     *rp;
 
index ecf37794428659ff808c05de45206c79c620176d..2bfda9b8f504bbaba866165aa6061531f7e7ef26 100644 (file)
@@ -683,7 +683,9 @@ static int __init init_nfsd(void)
        if (retval)
                return retval;
        nfsd_stat_init();       /* Statistics */
-       nfsd_cache_init();      /* RPC reply cache */
+       retval = nfsd_reply_cache_init();
+       if (retval)
+               goto out_free_stat;
        nfsd_export_init();     /* Exports table */
        nfsd_lockd_init();      /* lockd->nfsd callbacks */
        nfsd_idmap_init();      /* Name to ID mapping */
@@ -700,11 +702,12 @@ static int __init init_nfsd(void)
 out_free_all:
        nfsd_idmap_shutdown();
        nfsd_export_shutdown();
-       nfsd_cache_shutdown();
+       nfsd_reply_cache_shutdown();
        remove_proc_entry("fs/nfs/exports", NULL);
        remove_proc_entry("fs/nfs", NULL);
-       nfsd_stat_shutdown();
        nfsd_lockd_shutdown();
+out_free_stat:
+       nfsd_stat_shutdown();
        nfsd4_free_slabs();
        return retval;
 }
@@ -712,7 +715,7 @@ out_free_all:
 static void __exit exit_nfsd(void)
 {
        nfsd_export_shutdown();
-       nfsd_cache_shutdown();
+       nfsd_reply_cache_shutdown();
        remove_proc_entry("fs/nfs/exports", NULL);
        remove_proc_entry("fs/nfs", NULL);
        nfsd_stat_shutdown();
index 007480cd6a601fbec62c5d5ac41ed50e2a2d882d..7b5d784cc8587cd80c8bd31125f56a793ebae253 100644 (file)
@@ -72,8 +72,8 @@ enum {
  */
 #define RC_DELAY               (HZ/5)
 
-void   nfsd_cache_init(void);
-void   nfsd_cache_shutdown(void);
+int    nfsd_reply_cache_init(void);
+void   nfsd_reply_cache_shutdown(void);
 int    nfsd_cache_lookup(struct svc_rqst *, int);
 void   nfsd_cache_update(struct svc_rqst *, int, __be32 *);