From ccfe0195b3b47b2b0091ebd845efff3b22d89e14 Mon Sep 17 00:00:00 2001 From: Yang Sheng Date: Fri, 19 Jul 2024 22:17:00 +0800 Subject: [PATCH] LU-18051 ofd: Initialize the buffer for lvbo_update properly The lu_env maybe used in different target than it initialized. So we should refill it by tags to over come the issue while MDT & OST work in same node. Signed-off-by: Yang Sheng Change-Id: Ie7706dc9df2dd6fdbbac801fb266a87d9ed22026 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/55808 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Mikhail Pershin Reviewed-by: Alex Zhuravlev Reviewed-by: Oleg Drokin --- lustre/include/lu_object.h | 16 +++++++++++++--- lustre/mdt/mdt_internal.h | 2 +- lustre/mdt/mdt_lvb.c | 25 ++++++------------------- lustre/ofd/ofd_internal.h | 2 +- 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/lustre/include/lu_object.h b/lustre/include/lu_object.h index 30b2244..8e3040d 100644 --- a/lustre/include/lu_object.h +++ b/lustre/include/lu_object.h @@ -1154,20 +1154,30 @@ void lu_env_fini(struct lu_env *env); int lu_env_refill(struct lu_env *env); int lu_env_refill_by_tags(struct lu_env *env, __u32 ctags, __u32 stags); -static inline void *lu_env_info(const struct lu_env *env, - const struct lu_context_key *key) +static inline void *__lu_env_info(const struct lu_env *env, + const struct lu_context_key *key, int tags) { void *info; info = lu_context_key_get(&env->le_ctx, key); if (!info) { - if (!lu_env_refill((struct lu_env *)env)) + int rc; + + if (tags) + rc = lu_env_refill_by_tags((struct lu_env *)env, + key->lct_tags, 0); + else + rc = lu_env_refill((struct lu_env *)env); + if (!rc) info = lu_context_key_get(&env->le_ctx, key); } LASSERT(info); return info; } +#define lu_env_info(env, key) __lu_env_info(env, key, 0) +#define lu_env_info_get(env, key) __lu_env_info(env, key, 1) + struct lu_env *lu_env_find(void); int lu_env_add(struct lu_env *env); int lu_env_add_task(struct lu_env *env, struct task_struct *task); diff --git a/lustre/mdt/mdt_internal.h b/lustre/mdt/mdt_internal.h index 5730842..6de73df 100644 --- a/lustre/mdt/mdt_internal.h +++ b/lustre/mdt/mdt_internal.h @@ -616,7 +616,7 @@ extern struct lu_context_key mdt_thread_key; static inline struct mdt_thread_info *mdt_th_info(const struct lu_env *env) { - return lu_env_info(env, &mdt_thread_key); + return lu_env_info_get(env, &mdt_thread_key); } struct cdt_req_progress { diff --git a/lustre/mdt/mdt_lvb.c b/lustre/mdt/mdt_lvb.c index cf5e6a9..7748bdc 100644 --- a/lustre/mdt/mdt_lvb.c +++ b/lustre/mdt/mdt_lvb.c @@ -171,16 +171,9 @@ int mdt_dom_lvbo_update(struct ldlm_resource *res, struct ldlm_lock *lock, RETURN(-ENOENT); LASSERT(env); - info = lu_context_key_get(&env->le_ctx, &mdt_thread_key); - if (!info) { - rc = lu_env_refill_by_tags((struct lu_env *)env, - LCT_MD_THREAD, 0); - if (rc) - GOTO(out_env, rc); - info = lu_context_key_get(&env->le_ctx, &mdt_thread_key); - if (!info) - GOTO(out_env, rc = -ENOMEM); - } + info = mdt_th_info(env); + if (!info) + GOTO(out_env, rc = -ENOMEM); fid = &info->mti_tmp_fid2; fid_extract_from_res_name(fid, &res->lr_name); @@ -347,15 +340,9 @@ static int mdt_lvbo_fill(struct ldlm_lock *lock, GOTO(out, rc); } - info = lu_context_key_get(&env->le_ctx, &mdt_thread_key); - if (!info) { - rc = lu_env_refill_by_tags(env, LCT_MD_THREAD, 0); - if (rc) - GOTO(out, rc); - info = lu_context_key_get(&env->le_ctx, &mdt_thread_key); - if (!info) - GOTO(out, rc = -ENOMEM); - } + info = mdt_th_info(env); + if (!info) + GOTO(out, rc = -ENOMEM); /* DOM LVB is used by glimpse and IO completion when * DoM bits is always alone. diff --git a/lustre/ofd/ofd_internal.h b/lustre/ofd/ofd_internal.h index a604347..8670136 100644 --- a/lustre/ofd/ofd_internal.h +++ b/lustre/ofd/ofd_internal.h @@ -440,7 +440,7 @@ int ofd_intent_policy(const struct lu_env *env, struct ldlm_namespace *ns, static inline struct ofd_thread_info *ofd_info(const struct lu_env *env) { - return lu_env_info(env, &ofd_thread_key); + return lu_env_info_get(env, &ofd_thread_key); } static inline struct ofd_thread_info *ofd_info_init(const struct lu_env *env, -- 1.8.3.1