Whamcloud - gitweb
LU-7659 mdc: expose changelog through char devices
[fs/lustre-release.git] / lustre / mdt / mdt_coordinator.c
index 851e1f3..da11033 100644 (file)
@@ -882,6 +882,9 @@ static int mdt_hsm_cdt_start(struct mdt_device *mdt)
                       " for registered restore: %d\n",
                       mdt_obd_name(mdt), rc);
 
+       if (mdt->mdt_bottom->dd_rdonly)
+               RETURN(0);
+
        task = kthread_run(mdt_coordinator, cdt_mti, "hsm_cdtr");
        if (IS_ERR(task)) {
                rc = PTR_ERR(task);
@@ -916,6 +919,9 @@ int mdt_hsm_cdt_stop(struct mdt_device *mdt)
        struct mdt_thread_info          *cdt_mti;
        ENTRY;
 
+       if (mdt->mdt_opts.mo_coordinator == 0)
+               RETURN(0);
+
        if (cdt->cdt_state == CDT_STOPPED) {
                CERROR("%s: Coordinator already stopped\n",
                       mdt_obd_name(mdt));
@@ -1135,12 +1141,13 @@ static int hsm_cdt_request_completed(struct mdt_thread_info *mti,
        int                      cl_flags = 0, rc = 0;
        struct md_hsm            mh;
        bool                     is_mh_changed;
+       bool                     need_changelog = true;
        ENTRY;
 
        /* default is to retry */
        *status = ARS_WAITING;
 
-       /* find object by FID
+       /* find object by FID, mdt_hsm_get_md_hsm() returns obj or err
         * if error/removed continue anyway to get correct reporting done */
        obj = mdt_hsm_get_md_hsm(mti, &car->car_hai->hai_fid, &mh);
        /* we will update MD HSM only if needed */
@@ -1299,6 +1306,13 @@ static int hsm_cdt_request_completed(struct mdt_thread_info *mti,
                if (*status == ARS_WAITING)
                        GOTO(out, rc);
 
+               /* restore special case, need to create ChangeLog record
+                * before to give back layout lock to avoid concurrent
+                * file updater to post out of order ChangeLog */
+               mo_changelog(env, CL_HSM, cl_flags, mdt->mdt_child,
+                            &car->car_hai->hai_fid);
+               need_changelog = false;
+
                /* give back layout lock */
                mutex_lock(&cdt->cdt_restore_lock);
                crh = mdt_hsm_restore_hdl_find(cdt, &car->car_hai->hai_fid);
@@ -1320,8 +1334,9 @@ static int hsm_cdt_request_completed(struct mdt_thread_info *mti,
 
 out:
        /* always add a ChangeLog record */
-       mo_changelog(env, CL_HSM, cl_flags, mdt->mdt_child,
-                    &car->car_hai->hai_fid);
+       if (need_changelog)
+               mo_changelog(env, CL_HSM, cl_flags, mdt->mdt_child,
+                            &car->car_hai->hai_fid);
 
        if (!IS_ERR(obj))
                mdt_object_put(mti->mti_env, obj);