Whamcloud - gitweb
LU-18689 osp: Unregister proc files before obd cleanup 49/57949/6
authorOleg Drokin <green@whamcloud.com>
Mon, 10 Feb 2025 17:34:44 +0000 (12:34 -0500)
committerOleg Drokin <green@whamcloud.com>
Tue, 18 Feb 2025 05:04:30 +0000 (05:04 +0000)
Don't register the proc files before we are fully done initializing
either.

This fixes problems with proc/sysfs access highlighted by
recovery-small test 57 that take many forms, but
universally have osp in backtrace and either crashes in one of the
attributes or in osp_statfs

BUG: unable to handle kernel NULL pointer dereference at 0000000000000710
IP: [<ffffffff817dfdf8>] down_read+0x28/0x50
RIP: 0010:[<ffffffff817dfdf8>]  [<ffffffff817dfdf8>] down_read+0x28/0x50
Call Trace:
 [<ffffffffa1535378>] active_show+0x28/0x90 [osp]
 [<ffffffffa0397166>] lustre_attr_show+0x16/0x20 [obdclass]
 [<ffffffff812d728c>] sysfs_kf_seq_show+0xcc/0x1e0
 [<ffffffff812d58b3>] kernfs_seq_show+0x23/0x30
 [<ffffffff8126f0b5>] seq_read+0x135/0x470
 [<ffffffff812d643d>] kernfs_fop_read+0x11d/0x190
 [<ffffffff81245839>] vfs_read+0xb9/0x1c0
 [<ffffffff8124676f>] SyS_read+0x7f/0xf0

BUG: unable to handle kernel NULL pointer dereference at 0000000000000158
IP: [<ffffffffa14e85b1>] osp_statfs+0x2a1/0x4e0 [osp]
Oops: 0000 [#1] SMP DEBUG_PAGEALLOC
RIP: 0010:[<ffffffffa14e85b1>]  [<ffffffffa14e85b1>] osp_statfs+0x2a1/0x4e0 [osp]
Call Trace:
 [<ffffffffa03c53f2>] filestotal_show+0x52/0x120 [obdclass]
 [<ffffffffa0378166>] lustre_attr_show+0x16/0x20 [obdclass]
 [<ffffffff812d728c>] sysfs_kf_seq_show+0xcc/0x1e0
 [<ffffffff812d58b3>] kernfs_seq_show+0x23/0x30
 [<ffffffff8126f0b5>] seq_read+0x135/0x470
 [<ffffffff812d643d>] kernfs_fop_read+0x11d/0x190
 [<ffffffff81245839>] vfs_read+0xb9/0x1c0
 [<ffffffff8124676f>] SyS_read+0x7f/0xf0

Signed-off-by: Oleg Drokin <green@whamcloud.com>
Change-Id: Ie0337fcecfa1afe0c6be901bd9dab9cf6847555a
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/57949
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lustre/osp/osp_dev.c

index 5681338..bf54999 100644 (file)
@@ -1208,14 +1208,12 @@ static int osp_init0(const struct lu_env *env, struct osp_device *osp,
                GOTO(out_ref, rc);
        }
 
-       osp_tunables_init(osp);
-
        rc = client_fid_init(osp->opd_obd, NULL, osp->opd_connect_mdt ?
                             LUSTRE_SEQ_METADATA : LUSTRE_SEQ_DATA);
        if (rc) {
                CERROR("%s: fid init error: rc = %d\n",
                       osp->opd_obd->obd_name, rc);
-               GOTO(out_proc, rc);
+               GOTO(out_obd, rc);
        }
 
        if (!osp->opd_connect_mdt) {
@@ -1262,6 +1260,9 @@ static int osp_init0(const struct lu_env *env, struct osp_device *osp,
        rc = ptlrpc_init_import(imp);
        if (rc)
                GOTO(out, rc);
+
+       osp_tunables_init(osp);
+
        OBD_FREE(osdname, MAX_OBD_NAME);
        init_waitqueue_head(&osp->opd_out_waitq);
        RETURN(0);
@@ -1281,8 +1282,7 @@ out_last_used:
                osp_last_used_fini(env, osp);
 out_fid:
        client_fid_fini(osp->opd_obd);
-out_proc:
-       osp_tunables_fini(osp);
+out_obd:
        client_obd_cleanup(obd);
 out_ref:
        ptlrpcd_decref();
@@ -1388,17 +1388,14 @@ static struct lu_device *osp_device_fini(const struct lu_env *env,
 
        LASSERT(osp->opd_obd);
 
-       rc = client_obd_cleanup(osp->opd_obd);
-       if (rc != 0) {
-               ptlrpcd_decref();
-               RETURN(ERR_PTR(rc));
-       }
-
+       /* We must remove the tunables first so nobody accessed them when
+        * the obd devices are already gone.
+        */
        osp_tunables_fini(osp);
-
+       rc = client_obd_cleanup(osp->opd_obd);
        ptlrpcd_decref();
 
-       RETURN(NULL);
+       RETURN(rc != 0 ? ERR_PTR(rc) : NULL);
 }
 
 /**