Whamcloud - gitweb
LU-7931 tests: setup/cleanup after every test script
[fs/lustre-release.git] / lustre / target / update_trans.c
index 00bc034..7928bae 100644 (file)
@@ -20,7 +20,7 @@
  * GPL HEADER END
  */
 /*
- * Copyright (c) 2014, Intel Corporation.
+ * Copyright (c) 2014, 2015, Intel Corporation.
  */
 /*
  * lustre/target/update_trans.c
@@ -72,7 +72,7 @@ static void top_multiple_thandle_dump(struct top_multiple_thandle *tmt,
        struct sub_thandle      *st;
 
        LASSERT(tmt->tmt_magic == TOP_THANDLE_MAGIC);
-       CDEBUG(mask, "%s tmt %p refcount %d committed %d result %d"
+       CDEBUG(mask, "%s tmt %p refcount %d committed %d result %d "
               "batchid "LPU64"\n",
               tmt->tmt_master_sub_dt ?
               tmt->tmt_master_sub_dt->dd_lu_dev.ld_obd->obd_name :
@@ -83,9 +83,9 @@ static void top_multiple_thandle_dump(struct top_multiple_thandle *tmt,
        list_for_each_entry(st, &tmt->tmt_sub_thandle_list, st_sub_list) {
                struct sub_thandle_cookie *stc;
 
-               CDEBUG(mask, "st %p obd %s committed %d sub_th %p\n",
+               CDEBUG(mask, "st %p obd %s committed %d stopped %d sub_th %p\n",
                       st, st->st_dt->dd_lu_dev.ld_obd->obd_name,
-                      st->st_committed, st->st_sub_th);
+                      st->st_committed, st->st_stopped, st->st_sub_th);
 
                list_for_each_entry(stc, &st->st_cookie_list, stc_list) {
                        CDEBUG(mask, " cookie "DOSTID": %u\n",
@@ -450,25 +450,11 @@ struct sub_thandle *create_sub_thandle(struct top_multiple_thandle *tmt,
        return st;
 }
 
-/**
- * sub thandle commit callback
- *
- * Mark the sub thandle to be committed and if all sub thandle are committed
- * notify the top thandle.
- *
- * \param[in] env      execution environment
- * \param[in] sub_th   sub thandle being committed
- * \param[in] cb       commit callback
- * \param[in] err      trans result
- */
-static void sub_trans_commit_cb(struct lu_env *env,
-                               struct thandle *sub_th,
-                               struct dt_txn_commit_cb *cb, int err)
+static void sub_trans_commit_cb_internal(struct top_multiple_thandle *tmt,
+                                        struct thandle *sub_th, int err)
 {
        struct sub_thandle      *st;
-       struct top_multiple_thandle *tmt = cb->dcb_data;
        bool                    all_committed = true;
-       ENTRY;
 
        /* Check if all sub thandles are committed */
        spin_lock(&tmt->tmt_sub_lock);
@@ -493,6 +479,26 @@ static void sub_trans_commit_cb(struct lu_env *env,
        RETURN_EXIT;
 }
 
+/**
+ * sub thandle commit callback
+ *
+ * Mark the sub thandle to be committed and if all sub thandle are committed
+ * notify the top thandle.
+ *
+ * \param[in] env      execution environment
+ * \param[in] sub_th   sub thandle being committed
+ * \param[in] cb       commit callback
+ * \param[in] err      trans result
+ */
+static void sub_trans_commit_cb(struct lu_env *env,
+                               struct thandle *sub_th,
+                               struct dt_txn_commit_cb *cb, int err)
+{
+       struct top_multiple_thandle *tmt = cb->dcb_data;
+
+       sub_trans_commit_cb_internal(tmt, sub_th, err);
+}
+
 static void sub_thandle_register_commit_cb(struct sub_thandle *st,
                                    struct top_multiple_thandle *tmt)
 {
@@ -572,6 +578,7 @@ int sub_thandle_trans_create(const struct lu_env *env,
        st->st_sub_th = sub_th;
 
        sub_th->th_wait_submit = 1;
+       sub_thandle_register_stop_cb(st, top_th->tt_multiple_thandle);
        return 0;
 }
 
@@ -661,6 +668,7 @@ static void distribute_txn_assign_batchid(struct top_multiple_thandle *new)
 {
        struct target_distribute_txn_data *tdtd;
        struct dt_device *dt = new->tmt_master_sub_dt;
+       struct sub_thandle *st;
 
        LASSERT(dt != NULL);
        tdtd = dt2lu_dev(dt)->ld_site->ls_tgt->lut_tdtd;
@@ -668,6 +676,10 @@ static void distribute_txn_assign_batchid(struct top_multiple_thandle *new)
        new->tmt_batchid = tdtd->tdtd_batchid++;
        list_add_tail(&new->tmt_commit_list, &tdtd->tdtd_list);
        spin_unlock(&tdtd->tdtd_batchid_lock);
+       list_for_each_entry(st, &new->tmt_sub_thandle_list, st_sub_list) {
+               if (st->st_sub_th != NULL)
+                       sub_thandle_register_commit_cb(st, new);
+       }
        top_multiple_thandle_get(new);
        top_multiple_thandle_dump(new, D_INFO);
 }
@@ -684,6 +696,7 @@ void distribute_txn_insert_by_batchid(struct top_multiple_thandle *new)
        struct dt_device *dt = new->tmt_master_sub_dt;
        struct top_multiple_thandle *tmt;
        struct target_distribute_txn_data *tdtd;
+       struct sub_thandle *st;
        bool    at_head = false;
 
        LASSERT(dt != NULL);
@@ -701,6 +714,12 @@ void distribute_txn_insert_by_batchid(struct top_multiple_thandle *new)
                list_add(&new->tmt_commit_list, &tdtd->tdtd_list);
        }
        spin_unlock(&tdtd->tdtd_batchid_lock);
+
+       list_for_each_entry(st, &new->tmt_sub_thandle_list, st_sub_list) {
+               if (st->st_sub_th != NULL)
+                       sub_thandle_register_commit_cb(st, new);
+       }
+
        top_multiple_thandle_get(new);
        top_multiple_thandle_dump(new, D_INFO);
        if (new->tmt_committed && at_head)
@@ -773,6 +792,11 @@ int top_trans_start(const struct lu_env *env, struct dt_device *master_dev,
        ENTRY;
 
        if (tmt == NULL) {
+               if (th->th_sync)
+                       top_th->tt_master_sub_thandle->th_sync = th->th_sync;
+               if (th->th_local)
+                       top_th->tt_master_sub_thandle->th_local = th->th_local;
+               top_th->tt_master_sub_thandle->th_tags = th->th_tags;
                rc = dt_trans_start(env, top_th->tt_master_sub_thandle->th_dev,
                                    top_th->tt_master_sub_thandle);
                RETURN(rc);
@@ -788,15 +812,16 @@ int top_trans_start(const struct lu_env *env, struct dt_device *master_dev,
                        continue;
                if (th->th_sync)
                        st->st_sub_th->th_sync = th->th_sync;
-               st->st_sub_th->th_local = th->th_local;
+               if (th->th_local)
+                       st->st_sub_th->th_local = th->th_local;
                st->st_sub_th->th_tags = th->th_tags;
                rc = dt_trans_start(env, st->st_sub_th->th_dev,
                                    st->st_sub_th);
                if (rc != 0)
                        GOTO(out, rc);
 
-               sub_thandle_register_stop_cb(st, tmt);
-               sub_thandle_register_commit_cb(st, tmt);
+               LASSERT(st->st_started == 0);
+               st->st_started = 1;
        }
 out:
        th->th_result = rc;
@@ -922,6 +947,12 @@ int top_trans_stop(const struct lu_env *env, struct dt_device *master_dev,
 
        if (likely(top_th->tt_multiple_thandle == NULL)) {
                LASSERT(master_dev != NULL);
+
+               if (th->th_sync)
+                       top_th->tt_master_sub_thandle->th_sync = th->th_sync;
+               if (th->th_local)
+                       top_th->tt_master_sub_thandle->th_local = th->th_local;
+               top_th->tt_master_sub_thandle->th_tags = th->th_tags;
                rc = dt_trans_stop(env, master_dev,
                                   top_th->tt_master_sub_thandle);
                OBD_FREE_PTR(top_th);
@@ -949,6 +980,7 @@ int top_trans_stop(const struct lu_env *env, struct dt_device *master_dev,
                        CERROR("%s: cannot prepare updates: rc = %d\n",
                               master_dev->dd_lu_dev.ld_obd->obd_name, rc);
                        th->th_result = rc;
+                       write_updates = false;
                        GOTO(stop_master_trans, rc);
                }
 
@@ -967,6 +999,7 @@ int top_trans_stop(const struct lu_env *env, struct dt_device *master_dev,
                        CERROR("%s: write updates failed: rc = %d\n",
                               master_dev->dd_lu_dev.ld_obd->obd_name, rc);
                        th->th_result = rc;
+                       write_updates = false;
                        GOTO(stop_master_trans, rc);
                }
        }
@@ -975,12 +1008,20 @@ stop_master_trans:
        /* Step 2: Stop the transaction on the master MDT, and fill the
         * master transno in the update logs to other MDT. */
        if (master_st != NULL && master_st->st_sub_th != NULL) {
-               master_st->st_sub_th->th_local = th->th_local;
+               if (th->th_local)
+                       master_st->st_sub_th->th_local = th->th_local;
                if (th->th_sync)
                        master_st->st_sub_th->th_sync = th->th_sync;
                master_st->st_sub_th->th_tags = th->th_tags;
                master_st->st_sub_th->th_result = th->th_result;
                rc = dt_trans_stop(env, master_st->st_dt, master_st->st_sub_th);
+               /* If it does not write_updates, then we call submit callback
+                * here, otherwise callback is done through
+                * osd(osp)_trans_commit_cb() */
+               if (!master_st->st_started &&
+                   !list_empty(&tmt->tmt_commit_list))
+                       sub_trans_commit_cb_internal(tmt,
+                                               master_st->st_sub_th, rc);
                if (rc < 0) {
                        th->th_result = rc;
                        GOTO(stop_other_trans, rc);
@@ -1033,7 +1074,8 @@ stop_other_trans:
 
                if (th->th_sync)
                        st->st_sub_th->th_sync = th->th_sync;
-               st->st_sub_th->th_local = th->th_local;
+               if (th->th_local)
+                       st->st_sub_th->th_local = th->th_local;
                st->st_sub_th->th_tags = th->th_tags;
                st->st_sub_th->th_result = th->th_result;
                rc = dt_trans_stop(env, st->st_sub_th->th_dev,
@@ -1103,6 +1145,7 @@ create_sub_thandle_with_thandle(struct top_thandle *top_th,
        st->st_sub_th = sub_th;
 
        sub_th->th_top = &top_th->tt_super;
+       sub_thandle_register_stop_cb(st, top_th->tt_multiple_thandle);
        return st;
 }
 
@@ -1645,14 +1688,21 @@ int distribute_txn_init(const struct lu_env *env,
        int                     rc;
        ENTRY;
 
-       spin_lock_init(&tdtd->tdtd_batchid_lock);
        INIT_LIST_HEAD(&tdtd->tdtd_list);
+       INIT_LIST_HEAD(&tdtd->tdtd_replay_finish_list);
+       INIT_LIST_HEAD(&tdtd->tdtd_replay_list);
+       spin_lock_init(&tdtd->tdtd_batchid_lock);
+       spin_lock_init(&tdtd->tdtd_replay_list_lock);
+       tdtd->tdtd_replay_handler = distribute_txn_replay_handle;
+       tdtd->tdtd_replay_ready = 0;
 
        tdtd->tdtd_batchid = lut->lut_last_transno + 1;
 
        init_waitqueue_head(&lut->lut_tdtd_commit_thread.t_ctl_waitq);
        init_waitqueue_head(&tdtd->tdtd_commit_thread_waitq);
+       init_waitqueue_head(&tdtd->tdtd_recovery_threads_waitq);
        atomic_set(&tdtd->tdtd_refcount, 0);
+       atomic_set(&tdtd->tdtd_recovery_threads_count, 0);
 
        tdtd->tdtd_lut = lut;
        rc = distribute_txn_commit_batchid_init(env, tdtd);