From 5bc1dd825b700677b002a43463a463c3ccb665ec Mon Sep 17 00:00:00 2001 From: Alexander Zarochentsev Date: Tue, 21 Nov 2023 09:46:44 -0500 Subject: [PATCH] LU-9839 clio: lov active ios accounting fix ASSERT(atomic_read(&lov->lo_active_ios)==0) is triggered due to a bug in active_ios accounting. For some cl_io_init(,CIT_MISC,,) calls increment the lov_active_ios counter is not protected by the layout lock. So the checks for active_ios != 0 are racy and not preventing another thread from starting new cl_io and incrementing the active_ios counter after any check but before the assertion. The lov_active_ios counter increment should be done under the same condition as taking the layout type lock. The ci_type=CIT_MISC and ci_ignore_layout=1 should not be used in ll_dom_finish_open() as the I/O doesn't come "from the osc layer" and may race with a layout change. HPE-bug-id: LUS-11628 Signed-off-by: Alexander Zarochentsev Change-Id: I35fda85b968b847a87e73dd36bbb1648c744d62c Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/51638 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Mikhail Pershin Reviewed-by: James Simmons Reviewed-by: Patrick Farrell Reviewed-by: Vitaly Fertman Reviewed-by: Oleg Drokin --- lustre/llite/file.c | 1 - lustre/lov/lov_io.c | 23 ++++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lustre/llite/file.c b/lustre/llite/file.c index ab776c4..a52f4ed 100644 --- a/lustre/llite/file.c +++ b/lustre/llite/file.c @@ -562,7 +562,6 @@ void ll_dom_finish_open(struct inode *inode, struct ptlrpc_request *req) RETURN_EXIT; io = vvp_env_thread_io(env); io->ci_obj = obj; - io->ci_ignore_layout = 1; rc = cl_io_init(env, io, CIT_MISC, obj); if (rc) GOTO(out_io, rc); diff --git a/lustre/lov/lov_io.c b/lustre/lov/lov_io.c index dbe5054..3b5d58e 100644 --- a/lustre/lov/lov_io.c +++ b/lustre/lov/lov_io.c @@ -664,6 +664,7 @@ static void lov_io_fini(const struct lu_env *env, const struct cl_io_slice *ios) struct lov_io *lio = cl2lov_io(env, ios); struct lov_object *lov = cl2lov(ios->cis_obj); struct lov_io_sub *sub; + struct cl_io *io = lio->lis_cl.cis_io; ENTRY; LASSERT(list_empty(&lio->lis_active)); @@ -679,9 +680,11 @@ static void lov_io_fini(const struct lu_env *env, const struct cl_io_slice *ios) } LASSERT(lio->lis_nr_subios == 0); - LASSERT(atomic_read(&lov->lo_active_ios) > 0); - if (atomic_dec_and_test(&lov->lo_active_ios)) - wake_up(&lov->lo_waitq); + if (!(io->ci_ignore_layout && io->ci_type == CIT_MISC)) { + LASSERT(atomic_read(&lov->lo_active_ios) > 0); + if (atomic_dec_and_test(&lov->lo_active_ios)) + wake_up(&lov->lo_waitq); + } EXIT; } @@ -1771,9 +1774,12 @@ static void lov_empty_io_fini(const struct lu_env *env, const struct cl_io_slice *ios) { struct lov_object *lov = cl2lov(ios->cis_obj); + struct lov_io *lio = cl2lov_io(env, ios); + struct cl_io *io = lio->lis_cl.cis_io; ENTRY; - if (atomic_dec_and_test(&lov->lo_active_ios)) + if (!(io->ci_type == CIT_MISC && io->ci_ignore_layout) && + atomic_dec_and_test(&lov->lo_active_ios)) wake_up(&lov->lo_waitq); EXIT; } @@ -1862,7 +1868,8 @@ int lov_io_init_composite(const struct lu_env *env, struct cl_object *obj, result = lov_io_subio_init(env, lio, io); if (!result) { cl_io_slice_add(io, &lio->lis_cl, obj, &lov_io_ops); - atomic_inc(&lov->lo_active_ios); + if (!(io->ci_ignore_layout && io->ci_type == CIT_MISC)) + atomic_inc(&lov->lo_active_ios); } EXIT; out: @@ -1905,7 +1912,8 @@ int lov_io_init_empty(const struct lu_env *env, struct cl_object *obj, } if (result == 0) { cl_io_slice_add(io, &lio->lis_cl, obj, &lov_empty_io_ops); - atomic_inc(&lov->lo_active_ios); + if (!(io->ci_ignore_layout && io->ci_type == CIT_MISC)) + atomic_inc(&lov->lo_active_ios); } io->ci_result = result < 0 ? result : 0; @@ -1962,7 +1970,8 @@ int lov_io_init_released(const struct lu_env *env, struct cl_object *obj, if (result == 0) { cl_io_slice_add(io, &lio->lis_cl, obj, &lov_empty_io_ops); - atomic_inc(&lov->lo_active_ios); + if (!(io->ci_ignore_layout && io->ci_type == CIT_MISC)) + atomic_inc(&lov->lo_active_ios); } io->ci_result = result < 0 ? result : 0; -- 1.8.3.1