From 0a317b171ebedcba8fc58e548991a884186c350c Mon Sep 17 00:00:00 2001 From: Mikhail Pershin Date: Sat, 28 May 2022 21:16:11 +0300 Subject: [PATCH] LU-15847 tgt: move tti_ transaction params to tsi_ Move tti_mult_trans and tti_has_trans to tgt_session_info to be available in all targets. This allows to cleanup old MDT duplicating code and can be used for complex transaction handling in MDT/OFD if needed. Signed-off-by: Mikhail Pershin Change-Id: I3f0c15e283b9e21c04a009f6cf346afa278e7095 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/47491 Tested-by: jenkins Tested-by: Maloo Reviewed-by: John Hammond Reviewed-by: Lai Siyao Reviewed-by: Oleg Drokin --- lustre/include/lu_target.h | 4 ++++ lustre/mdt/mdt_handler.c | 45 +++++++++++++++++++-------------------- lustre/mdt/mdt_internal.h | 6 +----- lustre/mdt/mdt_recovery.c | 50 -------------------------------------------- lustre/target/out_handler.c | 2 +- lustre/target/tgt_handler.c | 3 +-- lustre/target/tgt_internal.h | 2 -- lustre/target/tgt_lastrcvd.c | 11 +++++----- lustre/target/tgt_main.c | 23 +++++++++++--------- 9 files changed, 47 insertions(+), 99 deletions(-) diff --git a/lustre/include/lu_target.h b/lustre/include/lu_target.h index 2a361ac..dd08892 100644 --- a/lustre/include/lu_target.h +++ b/lustre/include/lu_target.h @@ -294,6 +294,10 @@ struct tgt_session_info { __u64 tsi_xid; __u32 tsi_result; __u32 tsi_client_gen; + + /* RPC transaction handling */ + bool tsi_mult_trans; + int tsi_has_trans; }; static inline struct tgt_session_info *tgt_ses_info(const struct lu_env *env) diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index e939c6e..3973064 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -3971,11 +3971,15 @@ int mdt_object_lock_try(struct mdt_thread_info *info, struct mdt_object *o, void mdt_save_lock(struct mdt_thread_info *info, struct lustre_handle *h, enum ldlm_mode mode, int decref) { + struct tgt_session_info *tsi = info->mti_env->le_ses ? + tgt_ses_info(info->mti_env) : NULL; + ENTRY; if (lustre_handle_is_used(h)) { - if (decref || !info->mti_has_trans || - !(mode & (LCK_PW | LCK_EX))) { + bool has_trans = tsi && tsi->tsi_has_trans; + + if (decref || !has_trans || !(mode & (LCK_PW | LCK_EX))) { mdt_fid_unlock(h, mode); } else { struct mdt_device *mdt = info->mti_mdt; @@ -4005,18 +4009,17 @@ void mdt_save_lock(struct mdt_thread_info *info, struct lustre_handle *h, } else { mdt_fid_unlock(h, mode); } - if (mdt_is_lock_sync(lock)) { - CDEBUG(D_HA, "found sync-lock," - " async commit started\n"); - mdt_device_commit_async(info->mti_env, - mdt); - } - LDLM_LOCK_PUT(lock); - } - h->cookie = 0ull; - } - EXIT; + if (mdt_is_lock_sync(lock)) { + CDEBUG(D_HA, "sync_lock, do async commit\n"); + mdt_device_commit_async(info->mti_env, mdt); + } + LDLM_LOCK_PUT(lock); + } + h->cookie = 0ull; + } + + EXIT; } /** @@ -4045,8 +4048,8 @@ static void mdt_save_remote_lock(struct mdt_thread_info *info, (MDS_INODELOCK_XATTR | MDS_INODELOCK_UPDATE))) mo_invalidate(info->mti_env, mdt_object_child(o)); - if (decref || !info->mti_has_trans || !req || - !(mode & (LCK_PW | LCK_EX))) { + if (decref || !req || !(mode & (LCK_PW | LCK_EX)) || + !tgt_ses_info(info->mti_env)->tsi_has_trans) { ldlm_lock_decref_and_cancel(h, mode); LDLM_LOCK_PUT(lock); } else { @@ -4255,7 +4258,6 @@ void mdt_thread_info_init(struct ptlrpc_request *req, info->mti_body = NULL; info->mti_object = NULL; info->mti_dlm_req = NULL; - info->mti_has_trans = 0; info->mti_cross_ref = 0; info->mti_opdata = 0; info->mti_big_lmm_used = 0; @@ -5883,8 +5885,6 @@ static void mdt_fini(const struct lu_env *env, struct mdt_device *m) upcall_cache_cleanup(m->mdt_identity_cache); m->mdt_identity_cache = NULL; - mdt_fs_cleanup(env, m); - tgt_fini(env, &m->mdt_lut); mdt_hsm_cdt_fini(m); @@ -6093,16 +6093,15 @@ static int mdt_init0(const struct lu_env *env, struct mdt_device *m, else m->mdt_brw_size = ONE_MB_BRW_SIZE; - rc = mdt_fs_setup(env, m, obd, lsi); - if (rc) - GOTO(err_tgt, rc); + if (OBD_FAIL_CHECK(OBD_FAIL_MDS_FS_SETUP)) + GOTO(err_tgt, rc = -ENOENT); fid.f_seq = FID_SEQ_LOCAL_NAME; fid.f_oid = 1; fid.f_ver = 0; rc = local_oid_storage_init(env, m->mdt_bottom, &fid, &m->mdt_los); if (rc != 0) - GOTO(err_fs_cleanup, rc); + GOTO(err_tgt, rc); rc = mdt_hsm_cdt_init(m); if (rc != 0) { @@ -6193,8 +6192,6 @@ err_free_hsm: err_los_fini: local_oid_storage_fini(env, m->mdt_los); m->mdt_los = NULL; -err_fs_cleanup: - mdt_fs_cleanup(env, m); err_tgt: /* keep recoverable clients */ obd->obd_fail = 1; diff --git a/lustre/mdt/mdt_internal.h b/lustre/mdt/mdt_internal.h index 8715ec3..978f676 100644 --- a/lustre/mdt/mdt_internal.h +++ b/lustre/mdt/mdt_internal.h @@ -498,8 +498,7 @@ struct mdt_thread_info { */ const struct ldlm_request *mti_dlm_req; - __u32 mti_has_trans:1, /* has txn already? */ - mti_cross_ref:1, + __u32 mti_cross_ref:1, /* big_lmm buffer was used and must be used in reply */ mti_big_lmm_used:1, mti_big_acl_used:1, @@ -890,9 +889,6 @@ void mdt_reconstruct_generic(struct mdt_thread_info *mti, extern void target_recovery_fini(struct obd_device *obd); extern void target_recovery_init(struct lu_target *lut, svc_handler_t handler); -int mdt_fs_setup(const struct lu_env *, struct mdt_device *, - struct obd_device *, struct lustre_sb_info *lsi); -void mdt_fs_cleanup(const struct lu_env *, struct mdt_device *); int mdt_export_stats_init(struct obd_device *obd, struct obd_export *exp, diff --git a/lustre/mdt/mdt_recovery.c b/lustre/mdt/mdt_recovery.c index 45d404e..d560f02 100644 --- a/lustre/mdt/mdt_recovery.c +++ b/lustre/mdt/mdt_recovery.c @@ -66,56 +66,6 @@ const struct lu_buf *mdt_buf_const(const struct lu_env *env, return buf; } -/* This callback notifies MDT that transaction was done. This is needed by - * mdt_save_lock() only. It is similar to new target code and will be removed - * as mdt_save_lock() will be converted to use target structures - */ -static int mdt_txn_stop_cb(const struct lu_env *env, - struct thandle *txn, void *cookie) -{ - struct mdt_thread_info *mti; - - mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key); - LASSERT(mti); - - if (mti->mti_has_trans) - CDEBUG(D_INFO, "More than one transaction\n"); - else - mti->mti_has_trans = 1; - return 0; -} - -int mdt_fs_setup(const struct lu_env *env, struct mdt_device *mdt, - struct obd_device *obd, struct lustre_sb_info *lsi) -{ - int rc = 0; - - ENTRY; - - if (OBD_FAIL_CHECK(OBD_FAIL_MDS_FS_SETUP)) - RETURN(-ENOENT); - - /* prepare transactions callbacks */ - mdt->mdt_txn_cb.dtc_txn_start = NULL; - mdt->mdt_txn_cb.dtc_txn_stop = mdt_txn_stop_cb; - mdt->mdt_txn_cb.dtc_cookie = NULL; - mdt->mdt_txn_cb.dtc_tag = LCT_MD_THREAD; - INIT_LIST_HEAD(&mdt->mdt_txn_cb.dtc_linkage); - - dt_txn_callback_add(mdt->mdt_bottom, &mdt->mdt_txn_cb); - - RETURN(rc); -} - -void mdt_fs_cleanup(const struct lu_env *env, struct mdt_device *mdt) -{ - ENTRY; - - /* Remove transaction callback */ - dt_txn_callback_del(mdt->mdt_bottom, &mdt->mdt_txn_cb); - EXIT; -} - /* reconstruction code */ static void mdt_steal_ack_locks(struct ptlrpc_request *req) { diff --git a/lustre/target/out_handler.c b/lustre/target/out_handler.c index f81a77a..707cff2 100644 --- a/lustre/target/out_handler.c +++ b/lustre/target/out_handler.c @@ -1109,7 +1109,7 @@ int out_handle(struct tgt_session_info *tsi) reply->ourp_magic = UPDATE_REPLY_MAGIC; reply->ourp_count = updates; tti->tti_u.update.tti_update_reply = reply; - tti->tti_mult_trans = !req_is_replay(tgt_ses_req(tsi)); + tsi->tsi_mult_trans = !req_is_replay(tgt_ses_req(tsi)); OBD_ALLOC_PTR(trd); if (!trd) diff --git a/lustre/target/tgt_handler.c b/lustre/target/tgt_handler.c index 67a6b73..357e2fb 100644 --- a/lustre/target/tgt_handler.c +++ b/lustre/target/tgt_handler.c @@ -2638,7 +2638,6 @@ static void tgt_warn_on_cksum(struct ptlrpc_request *req, int tgt_brw_write(struct tgt_session_info *tsi) { - struct tgt_thread_info *tti = tgt_th_info(tsi->tsi_env); struct ptlrpc_request *req = tgt_ses_req(tsi); struct ptlrpc_bulk_desc *desc = NULL; struct obd_export *exp = req->rq_export; @@ -2882,7 +2881,7 @@ out_commitrw: } /* multiple transactions can be assigned during write commit */ - tti->tti_mult_trans = 1; + tsi->tsi_mult_trans = 1; /* Must commit after prep above in all cases */ rc = obd_commitrw(tsi->tsi_env, OBD_BRW_WRITE, exp, &repbody->oa, diff --git a/lustre/target/tgt_internal.h b/lustre/target/tgt_internal.h index b5ab975..ed45f82 100644 --- a/lustre/target/tgt_internal.h +++ b/lustre/target/tgt_internal.h @@ -63,8 +63,6 @@ struct tgt_thread_info { /* transno storage during last_rcvd update */ __u64 tti_transno; - __u32 tti_has_trans:1, - tti_mult_trans:1; /* Updates data for OUT target */ struct thandle_exec_args tti_tea; diff --git a/lustre/target/tgt_lastrcvd.c b/lustre/target/tgt_lastrcvd.c index 7f1abac..b21b1f4 100644 --- a/lustre/target/tgt_lastrcvd.c +++ b/lustre/target/tgt_lastrcvd.c @@ -1981,8 +1981,8 @@ int tgt_txn_stop_cb(const struct lu_env *env, struct thandle *th, echo_client = (tgt_ses_req(tsi) == NULL && tsi->tsi_xid == 0); - if (tti->tti_has_trans && !echo_client) { - if (tti->tti_mult_trans == 0) { + if (tsi->tsi_has_trans && !echo_client) { + if (!tsi->tsi_mult_trans) { CDEBUG(D_HA, "More than one transaction %llu\n", tti->tti_transno); /** @@ -1997,12 +1997,13 @@ int tgt_txn_stop_cb(const struct lu_env *env, struct thandle *th, * data loss. */ } - /* we need another transno to be assigned */ + /* we need new transno to be assigned */ tti->tti_transno = 0; - } else if (th->th_result == 0) { - tti->tti_has_trans = 1; } + if (!th->th_result) + tsi->tsi_has_trans++; + if (tsi->tsi_vbr_obj != NULL && !lu_object_remote(&tsi->tsi_vbr_obj->do_lu)) { obj = tsi->tsi_vbr_obj; diff --git a/lustre/target/tgt_main.c b/lustre/target/tgt_main.c index b40d466..7a293ba 100644 --- a/lustre/target/tgt_main.c +++ b/lustre/target/tgt_main.c @@ -757,21 +757,11 @@ static void tgt_key_fini(const struct lu_context *ctx, OBD_SLAB_FREE_PTR(info, tgt_thread_kmem); } -static void tgt_key_exit(const struct lu_context *ctx, - struct lu_context_key *key, void *data) -{ - struct tgt_thread_info *tti = data; - - tti->tti_has_trans = 0; - tti->tti_mult_trans = 0; -} - /* context key: tg_thread_key */ struct lu_context_key tgt_thread_key = { .lct_tags = LCT_MD_THREAD | LCT_DT_THREAD, .lct_init = tgt_key_init, .lct_fini = tgt_key_fini, - .lct_exit = tgt_key_exit, }; LU_KEY_INIT_GENERIC(tgt); @@ -796,11 +786,24 @@ static void tgt_ses_key_fini(const struct lu_context *ctx, OBD_SLAB_FREE_PTR(session, tgt_session_kmem); } +static void tgt_ses_key_exit(const struct lu_context *ctx, + struct lu_context_key *key, void *data) +{ + struct tgt_session_info *tsi = data; + + if (tsi->tsi_has_trans > 1) + CDEBUG(D_WARNING, "total %i transactions per RPC\n", + tsi->tsi_has_trans); + tsi->tsi_has_trans = 0; + tsi->tsi_mult_trans = false; +} + /* context key: tgt_session_key */ struct lu_context_key tgt_session_key = { .lct_tags = LCT_SERVER_SESSION, .lct_init = tgt_ses_key_init, .lct_fini = tgt_ses_key_fini, + .lct_exit = tgt_ses_key_exit, }; EXPORT_SYMBOL(tgt_session_key); -- 1.8.3.1