Whamcloud - gitweb
LU-6142 osc: tidy up osc_init()
authorMr. NeilBrown <neilb@suse.de>
Fri, 8 Mar 2024 00:57:03 +0000 (16:57 -0800)
committerAndreas Dilger <adilger@whamcloud.com>
Sat, 9 Mar 2024 07:44:42 +0000 (07:44 +0000)
A module_init() function that registers the services
of the module should do that last, after all other
initialization has succeeded.
This patch moves the class_register_type() call to the
end and ensures everything else that might have been
set up, is cleaned up on error.

Linux-commit: e67f133d02e ("staging: lustre: osc: tidy up osc_init()")

Lustre-change: https://review.whamcloud.com/49458
Lustre-commit: f66b0c3b22bfcf0d7ac9383df5d87317f831a03d

Change-Id: I2a5ffb116c6d7c33a4530bab6e89a5ffe6117cea
Signed-off-by: Mr. NeilBrown <neilb@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/54322
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lustre/osc/osc_request.c

index d34a618..de32a89 100644 (file)
@@ -4088,14 +4088,9 @@ static int __init osc_init(void)
        if (rc)
                RETURN(rc);
 
-       rc = class_register_type(&osc_obd_ops, NULL, true,
-                                LUSTRE_OSC_NAME, &osc_device_type);
-       if (rc)
-               GOTO(out_kmem, rc);
-
        rc = register_shrinker(&osc_cache_shrinker);
        if (rc)
-               GOTO(out_type, rc);
+               GOTO(out_kmem, rc);
 
        /* This is obviously too much memory, only prevent overflow here */
        if (osc_reqpool_mem_max >= 1 << 12 || osc_reqpool_mem_max == 0)
@@ -4126,14 +4121,19 @@ static int __init osc_init(void)
        if (rc != 0)
                GOTO(out_req_pool, rc);
 
+       rc = class_register_type(&osc_obd_ops, NULL, true,
+                                LUSTRE_OSC_NAME, &osc_device_type);
+       if (rc < 0)
+               GOTO(out_stop_grant, rc);
+
        RETURN(rc);
 
+out_stop_grant:
+       osc_stop_grant_work();
 out_req_pool:
        ptlrpc_free_rq_pool(osc_rq_pool);
 out_shrinker:
        unregister_shrinker(&osc_cache_shrinker);
-out_type:
-       class_unregister_type(LUSTRE_OSC_NAME);
 out_kmem:
        lu_kmem_fini(osc_caches);
 
@@ -4142,11 +4142,11 @@ out_kmem:
 
 static void __exit osc_exit(void)
 {
+       class_unregister_type(LUSTRE_OSC_NAME);
+       ptlrpc_free_rq_pool(osc_rq_pool);
        osc_stop_grant_work();
        unregister_shrinker(&osc_cache_shrinker);
-       class_unregister_type(LUSTRE_OSC_NAME);
        lu_kmem_fini(osc_caches);
-       ptlrpc_free_rq_pool(osc_rq_pool);
 }
 
 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");