Whamcloud - gitweb
LU-10308 misc: update Intel copyright messages for 2017
[fs/lustre-release.git] / lustre / mdt / mdt_hsm_cdt_client.c
index 3ccb802..9d0335c 100644 (file)
@@ -23,7 +23,7 @@
  * (C) Copyright 2012 Commissariat a l'energie atomique et aux energies
  *     alternatives
  *
- * Copyright (c) 2013, 2014, Intel Corporation.
+ * Copyright (c) 2013, 2017, Intel Corporation.
  */
 /*
  * lustre/mdt/mdt_hsm_cdt_client.c
@@ -154,7 +154,8 @@ static int hsm_find_compatible(const struct lu_env *env, struct mdt_device *mdt,
        hcdcb.cdt = &mdt->mdt_coordinator;
        hcdcb.hal = hal;
 
-       rc = cdt_llog_process(env, mdt, hsm_find_compatible_cb, &hcdcb, READ);
+       rc = cdt_llog_process(env, mdt, hsm_find_compatible_cb, &hcdcb, 0, 0,
+                             READ);
 
        RETURN(rc);
 }
@@ -280,48 +281,22 @@ hsm_action_permission(struct mdt_thread_info *mti,
        RETURN(*mask & (1UL << hsma) ? 0 : -EPERM);
 }
 
-/*
- * Coordinator external API
- */
-
-/**
- * register a list of requests
- * \param mti [IN]
- * \param hal [IN] list of requests
- * \retval 0 success
- * \retval -ve failure
- * in case of restore, caller must hold layout lock
- */
-int mdt_hsm_add_actions(struct mdt_thread_info *mti,
-                       struct hsm_action_list *hal)
+/* Process a single HAL. hsm_find_compatible has already been called
+ * on it. */
+static int mdt_hsm_register_hal(struct mdt_thread_info *mti,
+                               struct mdt_device *mdt,
+                               struct coordinator *cdt,
+                               struct hsm_action_list *hal)
 {
-       struct mdt_device       *mdt = mti->mti_mdt;
-       struct coordinator      *cdt = &mdt->mdt_coordinator;
        struct hsm_action_item  *hai;
        struct mdt_object       *obj = NULL;
-       int                      rc = 0, i;
+       int                      rc, i;
        struct md_hsm            mh;
        bool                     is_restore = false;
        __u64                    compound_id;
-       ENTRY;
-
-       /* no coordinator started, so we cannot serve requests */
-       if (cdt->cdt_state == CDT_STOPPED)
-               RETURN(-EAGAIN);
-
-       if (!hal_is_sane(hal))
-               RETURN(-EINVAL);
 
        compound_id = atomic_inc_return(&cdt->cdt_compound_id);
 
-       /* search for compatible request, if found hai_cookie is set
-        * to the request cookie
-        * it is also used to set the cookie for cancel request by FID
-        */
-       rc = hsm_find_compatible(mti->mti_env, mdt, hal);
-       if (rc)
-               GOTO(out, rc);
-
        hai = hai_first(hal);
        for (i = 0; i < hal->hal_count; i++, hai = hai_next(hai)) {
                int archive_id;
@@ -445,10 +420,25 @@ int mdt_hsm_add_actions(struct mdt_thread_info *mti,
                        mdt_object_put(mti->mti_env, obj);
 
                        mutex_lock(&cdt->cdt_restore_lock);
+                       if (unlikely((cdt->cdt_state == CDT_STOPPED) ||
+                                    (cdt->cdt_state == CDT_STOPPING))) {
+                               mutex_unlock(&cdt->cdt_restore_lock);
+                               mdt_object_unlock(mti, NULL, &crh->crh_lh, 1);
+                               OBD_SLAB_FREE_PTR(crh, mdt_hsm_cdt_kmem);
+                               GOTO(out, rc = -EAGAIN);
+                       }
                        list_add_tail(&crh->crh_list, &cdt->cdt_restore_hdl);
                        mutex_unlock(&cdt->cdt_restore_lock);
                }
 record:
+               /*
+                * Wait here to catch the 2nd RESTORE request to the same FID.
+                * Normally layout lock protects against adding such request.
+                * But when cdt is stopping it cancel all locks via
+                * ldlm_resource_clean and protections may not work.
+                * See LU-9266 and sanity-hsm_407 for details.
+                */
+               OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_HSM_CDT_DELAY, cfs_fail_val);
                /* record request */
                rc = mdt_agent_record_add(mti->mti_env, mdt, compound_id,
                                          archive_id, flags, hai);
@@ -462,10 +452,53 @@ record:
                rc = 0;
 
        GOTO(out, rc);
+
+out:
+       return rc;
+}
+
+/*
+ * Coordinator external API
+ */
+
+/**
+ * register a list of requests
+ * \param mti [IN]
+ * \param hal [IN] list of requests
+ * \retval 0 success
+ * \retval -ve failure
+ * in case of restore, caller must hold layout lock
+ */
+int mdt_hsm_add_actions(struct mdt_thread_info *mti,
+                       struct hsm_action_list *hal)
+{
+       struct mdt_device       *mdt = mti->mti_mdt;
+       struct coordinator      *cdt = &mdt->mdt_coordinator;
+       int                      rc;
+       ENTRY;
+
+       /* no coordinator started, so we cannot serve requests */
+       if (cdt->cdt_state == CDT_STOPPED)
+               RETURN(-EAGAIN);
+
+       if (!hal_is_sane(hal))
+               RETURN(-EINVAL);
+
+       /* search for compatible request, if found hai_cookie is set
+        * to the request cookie
+        * it is also used to set the cookie for cancel request by FID
+        */
+       rc = hsm_find_compatible(mti->mti_env, mdt, hal);
+       if (rc)
+               GOTO(out, rc);
+
+       rc = mdt_hsm_register_hal(mti, mdt, cdt, hal);
+
+       GOTO(out, rc);
 out:
-       /* if work has been added, wake up coordinator */
+       /* if work has been added, signal the coordinator */
        if (rc == 0 || rc == -ENODATA)
-               mdt_hsm_cdt_wakeup(mdt);
+               mdt_hsm_cdt_event(cdt);
 
        return rc;
 }