Whamcloud - gitweb
LU-3331 llite: remove llite proc root on init failure 20/6420/6
authorJohn L. Hammond <john.hammond@intel.com>
Wed, 17 Sep 2014 22:00:21 +0000 (18:00 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Wed, 24 Sep 2014 01:29:54 +0000 (01:29 +0000)
In init_lustre_lite() ensure that /proc/fs/lustre/llite is removed in
case of failure. Generally rework the cleanup code in this function.

Signed-off-by: John L. Hammond <john.hammond@intel.com>
Change-Id: I95844622dd39d2529d227b99fffbc938fd17910a
Reviewed-on: http://review.whamcloud.com/6420
Tested-by: Jenkins
Reviewed-by: Bob Glossman <bob.glossman@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: James Simmons <uja.ornl@gmail.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/llite/super25.c
lustre/obdclass/lprocfs_status.c

index 08e9d0e..6267c54 100644 (file)
@@ -80,21 +80,6 @@ static void ll_destroy_inode(struct inode *inode)
 }
 #endif
 
-static int ll_init_inodecache(void)
-{
-       ll_inode_cachep = kmem_cache_create("lustre_inode_cache",
-                                           sizeof(struct ll_inode_info),
-                                           0, SLAB_HWCACHE_ALIGN, NULL);
-       if (ll_inode_cachep == NULL)
-               return -ENOMEM;
-       return 0;
-}
-
-static void ll_destroy_inodecache(void)
-{
-       kmem_cache_destroy(ll_inode_cachep);
-}
-
 /* exported operations */
 struct super_operations lustre_super_operations =
 {
@@ -118,9 +103,10 @@ void lustre_register_client_process_config(int (*cpc)(struct lustre_cfg *lcfg));
 
 static int __init init_lustre_lite(void)
 {
-       int i, rc, seed[2];
-       struct timeval tv;
+       struct proc_dir_entry *entry;
        lnet_process_id_t lnet_id;
+       struct timeval tv;
+       int i, rc, seed[2];
 
        CLASSERT(sizeof(LUSTRE_VOLATILE_HDR) == LUSTRE_VOLATILE_HDR_LEN + 1);
 
@@ -130,106 +116,119 @@ static int __init init_lustre_lite(void)
        CDEBUG(D_INFO, "Lustre client module (%p).\n",
               &lustre_super_operations);
 
-        rc = ll_init_inodecache();
-        if (rc)
-                return -ENOMEM;
+       ll_inode_cachep = kmem_cache_create("lustre_inode_cache",
+                                           sizeof(struct ll_inode_info),
+                                           0, SLAB_HWCACHE_ALIGN, NULL);
+       if (ll_inode_cachep == NULL)
+               GOTO(out_cache, rc = -ENOMEM);
+
        ll_file_data_slab = kmem_cache_create("ll_file_data",
                                                 sizeof(struct ll_file_data), 0,
                                                 SLAB_HWCACHE_ALIGN, NULL);
-       if (ll_file_data_slab == NULL) {
-               ll_destroy_inodecache();
-               return -ENOMEM;
-       }
+       if (ll_file_data_slab == NULL)
+               GOTO(out_cache, rc = -ENOMEM);
 
        ll_remote_perm_cachep = kmem_cache_create("ll_remote_perm_cache",
                                                  sizeof(struct ll_remote_perm),
                                                  0, 0, NULL);
-       if (ll_remote_perm_cachep == NULL) {
-               kmem_cache_destroy(ll_file_data_slab);
-               ll_file_data_slab = NULL;
-               ll_destroy_inodecache();
-               return -ENOMEM;
-       }
+       if (ll_remote_perm_cachep == NULL)
+               GOTO(out_cache, rc = -ENOMEM);
 
        ll_rmtperm_hash_cachep = kmem_cache_create("ll_rmtperm_hash_cache",
                                                   REMOTE_PERM_HASHSIZE *
                                                   sizeof(struct list_head),
                                                   0, 0, NULL);
-       if (ll_rmtperm_hash_cachep == NULL) {
-               kmem_cache_destroy(ll_remote_perm_cachep);
-               ll_remote_perm_cachep = NULL;
-               kmem_cache_destroy(ll_file_data_slab);
-               ll_file_data_slab = NULL;
-               ll_destroy_inodecache();
-               return -ENOMEM;
+       if (ll_rmtperm_hash_cachep == NULL)
+               GOTO(out_cache, rc = -ENOMEM);
+
+       entry = lprocfs_seq_register("llite", proc_lustre_root, NULL, NULL);
+       if (IS_ERR(entry)) {
+               rc = PTR_ERR(entry);
+               CERROR("cannot register '/proc/fs/lustre/llite': rc = %d\n",
+                      rc);
+               GOTO(out_cache, rc);
        }
 
-        proc_lustre_fs_root = proc_lustre_root ?
-                             lprocfs_seq_register("llite", proc_lustre_root,
-                                                  NULL, NULL) : NULL;
+       proc_lustre_fs_root = entry;
 
-        lustre_register_client_fill_super(ll_fill_super);
-        lustre_register_kill_super_cb(ll_kill_super);
+       cfs_get_random_bytes(seed, sizeof(seed));
 
-        lustre_register_client_process_config(ll_process_config);
+       /* Nodes with small feet have little entropy. The NID for this
+        * node gives the most entropy in the low bits. */
+       for (i = 0;; i++) {
+               if (LNetGetId(i, &lnet_id) == -ENOENT)
+                       break;
 
-        cfs_get_random_bytes(seed, sizeof(seed));
-
-        /* Nodes with small feet have little entropy
-         * the NID for this node gives the most entropy in the low bits */
-        for (i=0; ; i++) {
-                if (LNetGetId(i, &lnet_id) == -ENOENT) {
-                        break;
-                }
-                if (LNET_NETTYP(LNET_NIDNET(lnet_id.nid)) != LOLND) {
-                        seed[0] ^= LNET_NIDADDR(lnet_id.nid);
-                }
-        }
+               if (LNET_NETTYP(LNET_NIDNET(lnet_id.nid)) != LOLND)
+                       seed[0] ^= LNET_NIDADDR(lnet_id.nid);
+       }
 
        do_gettimeofday(&tv);
        cfs_srand(tv.tv_sec ^ seed[0], tv.tv_usec ^ seed[1]);
 
-        init_timer(&ll_capa_timer);
-        ll_capa_timer.function = ll_capa_timer_callback;
-        rc = ll_capa_thread_start();
-        /*
-         * XXX normal cleanup is needed here.
-         */
-        if (rc == 0)
-                rc = vvp_global_init();
+       init_timer(&ll_capa_timer);
+       ll_capa_timer.function = ll_capa_timer_callback;
+       rc = ll_capa_thread_start();
+       if (rc != 0)
+               GOTO(out_proc, rc);
+
+       rc = vvp_global_init();
+       if (rc != 0)
+               GOTO(out_capa, rc);
+
+       rc = ll_xattr_init();
+       if (rc != 0)
+               GOTO(out_vvp, rc);
+
+       lustre_register_client_fill_super(ll_fill_super);
+       lustre_register_kill_super_cb(ll_kill_super);
+       lustre_register_client_process_config(ll_process_config);
+
+       RETURN(0);
+
+out_vvp:
+       vvp_global_fini();
+out_capa:
+       del_timer(&ll_capa_timer);
+       ll_capa_thread_stop();
+out_proc:
+       lprocfs_remove(&proc_lustre_fs_root);
+out_cache:
+       if (ll_inode_cachep != NULL)
+               kmem_cache_destroy(ll_inode_cachep);
+
+       if (ll_file_data_slab != NULL)
+               kmem_cache_destroy(ll_file_data_slab);
+
+       if (ll_remote_perm_cachep != NULL)
+               kmem_cache_destroy(ll_remote_perm_cachep);
 
-       if (rc == 0)
-               rc = ll_xattr_init();
+       if (ll_rmtperm_hash_cachep != NULL)
+               kmem_cache_destroy(ll_rmtperm_hash_cachep);
 
-        return rc;
+       return rc;
 }
 
 static void __exit exit_lustre_lite(void)
 {
-       ll_xattr_fini();
-        vvp_global_fini();
-        del_timer(&ll_capa_timer);
-        ll_capa_thread_stop();
-        LASSERTF(capa_count[CAPA_SITE_CLIENT] == 0,
-                 "client remaining capa count %d\n",
-                 capa_count[CAPA_SITE_CLIENT]);
-
-        lustre_register_client_fill_super(NULL);
-        lustre_register_kill_super_cb(NULL);
+       lustre_register_client_fill_super(NULL);
+       lustre_register_kill_super_cb(NULL);
+       lustre_register_client_process_config(NULL);
 
-        lustre_register_client_process_config(NULL);
+       lprocfs_remove(&proc_lustre_fs_root);
 
-        ll_destroy_inodecache();
+       ll_xattr_fini();
+       vvp_global_fini();
+       del_timer(&ll_capa_timer);
+       ll_capa_thread_stop();
+       LASSERTF(capa_count[CAPA_SITE_CLIENT] == 0,
+                "client remaining capa count %d\n",
+                capa_count[CAPA_SITE_CLIENT]);
 
+       kmem_cache_destroy(ll_inode_cachep);
        kmem_cache_destroy(ll_rmtperm_hash_cachep);
-       ll_rmtperm_hash_cachep = NULL;
-
        kmem_cache_destroy(ll_remote_perm_cachep);
-       ll_remote_perm_cachep = NULL;
-
        kmem_cache_destroy(ll_file_data_slab);
-       if (proc_lustre_fs_root)
-               lprocfs_remove(&proc_lustre_fs_root);
 }
 
 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
index a4b8013..e38c39d 100644 (file)
@@ -498,7 +498,10 @@ lprocfs_seq_register(const char *name, struct proc_dir_entry *parent,
        struct proc_dir_entry *newchild;
 
        newchild = proc_mkdir(name, parent);
-       if (newchild != NULL && list != NULL) {
+       if (newchild == NULL)
+               return ERR_PTR(-ENOMEM);
+
+       if (list != NULL) {
                int rc = lprocfs_seq_add_vars(newchild, list, data);
                if (rc) {
                        lprocfs_remove(&newchild);