Whamcloud - gitweb
LU-18813 osd-wbcfs: refactor osd_device_alloc 06/59306/3
authorTimothy Day <timday@amazon.com>
Tue, 20 May 2025 05:09:47 +0000 (01:09 -0400)
committerOleg Drokin <green@whamcloud.com>
Sat, 7 Jun 2025 23:04:24 +0000 (23:04 +0000)
osd_device_alloc() has improper error handling.
Refactor the function such that we properly
cleanup if __osd_device_init() fails.

Test-Parameters: trivial
Test-Parameters: testlist=sanity fstype=wbcfs mdscount=4 mdtcount=1 osscount=4 ostcount=1
Test-Parameters: testlist=sanity fstype=wbcfs combinedmdsmgs=false standalonemgs=true mdscount=1 mdtcount=1 osscount=4 ostcount=1
Signed-off-by: Timothy Day <timday@amazon.com>
Change-Id: Ia03eb805ef3fdc75c8490e09c66b99e6541d13fd
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/59306
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Qian Yingjin <qian@ddn.com>
Reviewed-by: Lijing Chen <lijinc@amazon.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/osd-wbcfs/osd_handler.c

index 999e188..0320d28 100644 (file)
@@ -499,18 +499,24 @@ static struct lu_device *osd_device_alloc(const struct lu_env *env,
        ENTRY;
 
        OBD_ALLOC_PTR(osd);
-       if (osd == NULL)
+       if (!osd)
                RETURN(ERR_PTR(-ENOMEM));
 
        rc = dt_device_init(&osd->od_dt_dev, t);
-       if (unlikely(rc)) {
-               OBD_FREE_PTR(osd);
-               GOTO(out, rc);
-       }
+       if (rc)
+               GOTO(out_free, rc);
 
        rc = __osd_device_init(env, osd, cfg);
-out:
-       RETURN(rc == 0 ? osd2lu_dev(osd) : ERR_PTR(rc));
+       if (rc)
+               GOTO(out_dev_fini, rc);
+
+       RETURN(osd2lu_dev(osd));
+
+out_dev_fini:
+       dt_device_fini(&osd->od_dt_dev);
+out_free:
+       OBD_FREE_PTR(osd);
+       RETURN(ERR_PTR(rc));
 }
 
 static struct lu_device *osd_device_free(const struct lu_env *env,