From 546eff6991923f7b3fe959548fd9dbe266c72367 Mon Sep 17 00:00:00 2001 From: Andrew Perepechko Date: Thu, 25 Nov 2021 20:28:01 +0300 Subject: [PATCH] LU-13542 osd: brw stats are initialized too late Lustre crashes with the following stack trace: [] lprocfs_oh_tally+0x2c/0x40 [obdclass] [] record_start_io.part.14+0x2b/0x40 [osd_zfs] [] osd_read+0xa2/0x180 [osd_zfs] [] dt_record_read+0x1e/0x70 [obdclass] [] lustre_index_restore+0x527/0x1720 [obdclass] [] osd_initial_OI_scrub+0xa34/0xd50 [osd_zfs] [] osd_scrub_setup+0x9ed/0xb90 [osd_zfs] [] osd_mount+0xf4b/0x1380 [osd_zfs] osd_procfs_init()/osd_stats_init() are called *after* osd_initial_OI_scrub(), so osd stats are not yet initialized when osd_read() first tries to update them. This patch separates osd stats initialization from procfs initialization so that osd stats should become initialized by the time scrub starts its own initialization. Change-Id: I15ab03e77eaab76e3dea8067b849c891e89aa9a8 Signed-off-by: Andrew Perepechko HPE-bug-id: LUS-8173 Reviewed-on: https://review.whamcloud.com/38554 Tested-by: jenkins Reviewed-by: Andreas Dilger Reviewed-by: James Simmons Tested-by: Maloo Reviewed-by: Oleg Drokin --- lustre/include/lprocfs_status.h | 2 ++ lustre/obdclass/lprocfs_status_server.c | 10 +++++++++- lustre/osd-ldiskfs/osd_handler.c | 3 +++ lustre/osd-zfs/osd_handler.c | 2 ++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lustre/include/lprocfs_status.h b/lustre/include/lprocfs_status.h index 5c7ddb2..d622f8c 100644 --- a/lustre/include/lprocfs_status.h +++ b/lustre/include/lprocfs_status.h @@ -416,6 +416,8 @@ struct brw_stats { struct brw_stats_props bs_props[BRW_RW_STATS_NUM / 2]; }; +void lprocfs_init_brw_stats(struct brw_stats *brw_stats); + void ldebugfs_register_osd_stats(struct dentry *parent, struct brw_stats *brw_stats, struct lprocfs_stats *stats); diff --git a/lustre/obdclass/lprocfs_status_server.c b/lustre/obdclass/lprocfs_status_server.c index 7a78959..a912ba6 100644 --- a/lustre/obdclass/lprocfs_status_server.c +++ b/lustre/obdclass/lprocfs_status_server.c @@ -775,6 +775,15 @@ static ssize_t brw_stats_seq_write(struct file *file, LDEBUGFS_SEQ_FOPS(brw_stats); +void lprocfs_init_brw_stats(struct brw_stats *brw_stats) +{ + int i; + + for (i = 0; i < BRW_RW_STATS_NUM; i++) + spin_lock_init(&brw_stats->bs_hist[i].oh_lock); +} +EXPORT_SYMBOL(lprocfs_init_brw_stats); + void ldebugfs_register_osd_stats(struct dentry *parent, struct brw_stats *brw_stats, struct lprocfs_stats *stats) @@ -786,7 +795,6 @@ void ldebugfs_register_osd_stats(struct dentry *parent, for (i = 0; i < BRW_RW_STATS_NUM; i++) { struct brw_stats_props *props = brw_stats->bs_props; - spin_lock_init(&brw_stats->bs_hist[i].oh_lock); if (i % 2) { props[i / 2].bsp_name = brw_props[i / 2].bsp_name; props[i / 2].bsp_units = brw_props[i / 2].bsp_units; diff --git a/lustre/osd-ldiskfs/osd_handler.c b/lustre/osd-ldiskfs/osd_handler.c index 756a0fc..c95ceb3 100644 --- a/lustre/osd-ldiskfs/osd_handler.c +++ b/lustre/osd-ldiskfs/osd_handler.c @@ -8169,6 +8169,9 @@ static int osd_device_init0(const struct lu_env *env, restored = true; INIT_LIST_HEAD(&o->od_ios_list); + + lprocfs_init_brw_stats(&o->od_brw_stats); + /* setup scrub, including OI files initialization */ o->od_in_init = 1; rc = osd_scrub_setup(env, o, restored); diff --git a/lustre/osd-zfs/osd_handler.c b/lustre/osd-zfs/osd_handler.c index bd6d8df..9552fa9 100644 --- a/lustre/osd-zfs/osd_handler.c +++ b/lustre/osd-zfs/osd_handler.c @@ -1191,6 +1191,8 @@ static int osd_mount(const struct lu_env *env, if (opts && strstr(opts, "resetoi")) resetoi = true; + lprocfs_init_brw_stats(&o->od_brw_stats); + o->od_in_init = 1; rc = osd_scrub_setup(env, o, interval, resetoi); o->od_in_init = 0; -- 1.8.3.1