From 0682d7d6bc64bb75777f05ffb423779bbe781063 Mon Sep 17 00:00:00 2001 From: Alex Zhuravlev Date: Tue, 9 Nov 2021 11:03:32 +0300 Subject: [PATCH] LU-13494 osp: wait for import invalidation osp_update_fini() should wait till racing ptlrpc_import_invalidate() (running in a dedicated invalidation thread) is complete as the both threads access ou_update and osp_update_fini() release the structure. the change also fixes kernel's warning on scheduling while atomic: old osp_update_fini() took the spinlock to protect ou_list, but given new wait_event() we don't need to protect the list anymore. Signed-off-by: Alex Zhuravlev Change-Id: Iea40d3be8b1b3079b9fe8bdd015cc3392027b64d Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/45499 Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin Reviewed-by: Lai Siyao Tested-by: jenkins Tested-by: Maloo --- lustre/osp/osp_dev.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lustre/osp/osp_dev.c b/lustre/osp/osp_dev.c index 5497028..d1232e9 100644 --- a/lustre/osp/osp_dev.c +++ b/lustre/osp/osp_dev.c @@ -570,6 +570,7 @@ static int osp_update_init(struct osp_device *osp) */ static void osp_update_fini(const struct lu_env *env, struct osp_device *osp) { + struct obd_import *imp = osp->opd_obd->u.cli.cl_import; struct osp_update_request *our; struct osp_update_request *tmp; struct osp_updates *ou = osp->opd_update; @@ -580,17 +581,22 @@ static void osp_update_fini(const struct lu_env *env, struct osp_device *osp) kthread_stop(ou->ou_update_task); lu_env_fini(&ou->ou_env); + /* + * import invalidation can be running in a dedicated thread. + * we have to wait for the thread's completion as the thread + * invalidates this list as well. + */ + wait_event_idle(imp->imp_recovery_waitq, + (atomic_read(&imp->imp_inval_count) == 0)); + /* Remove the left osp thandle from the list */ - spin_lock(&ou->ou_lock); - list_for_each_entry_safe(our, tmp, &ou->ou_list, - our_list) { + list_for_each_entry_safe(our, tmp, &ou->ou_list, our_list) { list_del_init(&our->our_list); LASSERT(our->our_th != NULL); osp_trans_callback(env, our->our_th, -EIO); /* our will be destroyed in osp_thandle_put() */ osp_thandle_put(env, our->our_th); } - spin_unlock(&ou->ou_lock); OBD_FREE_PTR(ou); osp->opd_update = NULL; -- 1.8.3.1