Whamcloud - gitweb
LU-15847 tgt: move tti_ transaction params to tsi_ 91/47491/5
authorMikhail Pershin <mpershin@whamcloud.com>
Sat, 28 May 2022 18:16:11 +0000 (21:16 +0300)
committerOleg Drokin <green@whamcloud.com>
Tue, 25 Oct 2022 17:24:12 +0000 (17:24 +0000)
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 <mpershin@whamcloud.com>
Change-Id: I3f0c15e283b9e21c04a009f6cf346afa278e7095
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/47491
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: John Hammond <jhammond@whamcloud.com>
Reviewed-by: Lai Siyao <lai.siyao@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/include/lu_target.h
lustre/mdt/mdt_handler.c
lustre/mdt/mdt_internal.h
lustre/mdt/mdt_recovery.c
lustre/target/out_handler.c
lustre/target/tgt_handler.c
lustre/target/tgt_internal.h
lustre/target/tgt_lastrcvd.c
lustre/target/tgt_main.c

index 2a361ac..dd08892 100644 (file)
@@ -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)
index e939c6e..3973064 100644 (file)
@@ -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;
index 8715ec3..978f676 100644 (file)
@@ -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,
index 45d404e..d560f02 100644 (file)
@@ -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)
 {
index f81a77a..707cff2 100644 (file)
@@ -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)
index 67a6b73..357e2fb 100644 (file)
@@ -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,
index b5ab975..ed45f82 100644 (file)
@@ -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;
index 7f1abac..b21b1f4 100644 (file)
@@ -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;
index b40d466..7a293ba 100644 (file)
@@ -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);