From d9a1691ab7191125711aaadde8d043b93879733c Mon Sep 17 00:00:00 2001 From: Oleg Drokin Date: Mon, 10 Feb 2025 12:34:44 -0500 Subject: [PATCH] LU-18689 osp: Unregister proc files before obd cleanup 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: [] down_read+0x28/0x50 RIP: 0010:[] [] down_read+0x28/0x50 Call Trace: [] active_show+0x28/0x90 [osp] [] lustre_attr_show+0x16/0x20 [obdclass] [] sysfs_kf_seq_show+0xcc/0x1e0 [] kernfs_seq_show+0x23/0x30 [] seq_read+0x135/0x470 [] kernfs_fop_read+0x11d/0x190 [] vfs_read+0xb9/0x1c0 [] SyS_read+0x7f/0xf0 BUG: unable to handle kernel NULL pointer dereference at 0000000000000158 IP: [] osp_statfs+0x2a1/0x4e0 [osp] Oops: 0000 [#1] SMP DEBUG_PAGEALLOC RIP: 0010:[] [] osp_statfs+0x2a1/0x4e0 [osp] Call Trace: [] filestotal_show+0x52/0x120 [obdclass] [] lustre_attr_show+0x16/0x20 [obdclass] [] sysfs_kf_seq_show+0xcc/0x1e0 [] kernfs_seq_show+0x23/0x30 [] seq_read+0x135/0x470 [] kernfs_fop_read+0x11d/0x190 [] vfs_read+0xb9/0x1c0 [] SyS_read+0x7f/0xf0 Signed-off-by: Oleg Drokin Change-Id: Ie0337fcecfa1afe0c6be901bd9dab9cf6847555a Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/57949 Tested-by: jenkins Tested-by: Maloo Reviewed-by: James Simmons Reviewed-by: Andreas Dilger --- lustre/osp/osp_dev.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/lustre/osp/osp_dev.c b/lustre/osp/osp_dev.c index 5681338..bf54999 100644 --- a/lustre/osp/osp_dev.c +++ b/lustre/osp/osp_dev.c @@ -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); } /** -- 1.8.3.1