Whamcloud - gitweb
LU-9312 hsm: convert cdt_llog_lock to a rw semaphore 03/26803/6
authorJohn L. Hammond <john.hammond@intel.com>
Wed, 17 Jun 2015 22:46:09 +0000 (15:46 -0700)
committerOleg Drokin <oleg.drokin@intel.com>
Mon, 29 May 2017 17:29:20 +0000 (17:29 +0000)
Convert struct coordinator:cdt_llog_lock from a mutex to a rw
semaphore. Add a flag to cdt_llog_process() to indicate whether a read
or write lock is needed.

Change-Id: Ie5c14d8eccda22731ad0ad9594bee7db99fe9cfd
Signed-off-by: John L. Hammond <john.hammond@intel.com>
Reviewed-on: https://review.whamcloud.com/26803
Tested-by: Jenkins
Reviewed-by: Ben Evans <bevans@cray.com>
Reviewed-by: Quentin Bouget <quentin.bouget@cea.fr>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/mdt/mdt_coordinator.c
lustre/mdt/mdt_hsm_cdt_actions.c
lustre/mdt/mdt_hsm_cdt_client.c
lustre/mdt/mdt_internal.h

index d250424..0475011 100644 (file)
@@ -573,8 +573,8 @@ static int mdt_coordinator(void *data)
 
                hsd.request_cnt = 0;
 
 
                hsd.request_cnt = 0;
 
-               rc = cdt_llog_process(mti->mti_env, mdt,
-                                     mdt_coordinator_cb, &hsd);
+               rc = cdt_llog_process(mti->mti_env, mdt, mdt_coordinator_cb,
+                                     &hsd, WRITE);
                if (rc < 0)
                        goto clean_cb_alloc;
 
                if (rc < 0)
                        goto clean_cb_alloc;
 
@@ -789,7 +789,7 @@ static int mdt_hsm_pending_restore(struct mdt_thread_info *mti)
        hrd.hrd_mti = mti;
 
        rc = cdt_llog_process(mti->mti_env, mti->mti_mdt,
        hrd.hrd_mti = mti;
 
        rc = cdt_llog_process(mti->mti_env, mti->mti_mdt,
-                             hsm_restore_cb, &hrd);
+                             hsm_restore_cb, &hrd, WRITE);
 
        RETURN(rc);
 }
 
        RETURN(rc);
 }
@@ -852,7 +852,7 @@ int mdt_hsm_cdt_init(struct mdt_device *mdt)
        ENTRY;
 
        init_waitqueue_head(&cdt->cdt_waitq);
        ENTRY;
 
        init_waitqueue_head(&cdt->cdt_waitq);
-       mutex_init(&cdt->cdt_llog_lock);
+       init_rwsem(&cdt->cdt_llog_lock);
        init_rwsem(&cdt->cdt_agent_lock);
        init_rwsem(&cdt->cdt_request_lock);
        mutex_init(&cdt->cdt_restore_lock);
        init_rwsem(&cdt->cdt_agent_lock);
        init_rwsem(&cdt->cdt_request_lock);
        mutex_init(&cdt->cdt_restore_lock);
@@ -1701,8 +1701,7 @@ static int hsm_cancel_all_actions(struct mdt_device *mdt)
        hcad.mdt = mdt;
 
        rc = cdt_llog_process(mti->mti_env, mti->mti_mdt,
        hcad.mdt = mdt;
 
        rc = cdt_llog_process(mti->mti_env, mti->mti_mdt,
-                             mdt_cancel_all_cb, &hcad);
-
+                             mdt_cancel_all_cb, &hcad, WRITE);
 out_cdt_state:
        /* Enable coordinator, unless the coordinator was stopping. */
        set_cdt_state(cdt, old_state, NULL);
 out_cdt_state:
        /* Enable coordinator, unless the coordinator was stopping. */
        set_cdt_state(cdt, old_state, NULL);
index 711747c..94bc265 100644 (file)
@@ -80,11 +80,12 @@ void dump_llog_agent_req_rec(const char *prefix,
  * \param mdt [IN] MDT device
  * \param cb [IN] llog callback funtion
  * \param data [IN] llog callback  data
  * \param mdt [IN] MDT device
  * \param cb [IN] llog callback funtion
  * \param data [IN] llog callback  data
+ * \param rw [IN] cdt_llog_lock mode (READ or WRITE)
  * \retval 0 success
  * \retval -ve failure
  */
 int cdt_llog_process(const struct lu_env *env, struct mdt_device *mdt,
  * \retval 0 success
  * \retval -ve failure
  */
 int cdt_llog_process(const struct lu_env *env, struct mdt_device *mdt,
-                    llog_cb_t cb, void *data)
+                    llog_cb_t cb, void *data, int rw)
 {
        struct obd_device       *obd = mdt2obd_dev(mdt);
        struct llog_ctxt        *lctxt = NULL;
 {
        struct obd_device       *obd = mdt2obd_dev(mdt);
        struct llog_ctxt        *lctxt = NULL;
@@ -96,7 +97,10 @@ int cdt_llog_process(const struct lu_env *env, struct mdt_device *mdt,
        if (lctxt == NULL || lctxt->loc_handle == NULL)
                RETURN(-ENOENT);
 
        if (lctxt == NULL || lctxt->loc_handle == NULL)
                RETURN(-ENOENT);
 
-       mutex_lock(&cdt->cdt_llog_lock);
+       if (rw == READ)
+               down_read(&cdt->cdt_llog_lock);
+       else
+               down_write(&cdt->cdt_llog_lock);
 
        rc = llog_cat_process(env, lctxt->loc_handle, cb, data, 0, 0);
        if (rc < 0)
 
        rc = llog_cat_process(env, lctxt->loc_handle, cb, data, 0, 0);
        if (rc < 0)
@@ -106,7 +110,12 @@ int cdt_llog_process(const struct lu_env *env, struct mdt_device *mdt,
                rc = 0;
 
        llog_ctxt_put(lctxt);
                rc = 0;
 
        llog_ctxt_put(lctxt);
-       mutex_unlock(&cdt->cdt_llog_lock);
+
+       if (rw == READ)
+               up_read(&cdt->cdt_llog_lock);
+       else
+               up_write(&cdt->cdt_llog_lock);
+
        RETURN(rc);
 }
 
        RETURN(rc);
 }
 
@@ -151,7 +160,7 @@ int mdt_agent_record_add(const struct lu_env *env,
        if (lctxt == NULL || lctxt->loc_handle == NULL)
                GOTO(free, rc = -ENOENT);
 
        if (lctxt == NULL || lctxt->loc_handle == NULL)
                GOTO(free, rc = -ENOENT);
 
-       mutex_lock(&cdt->cdt_llog_lock);
+       down_write(&cdt->cdt_llog_lock);
 
        /* in case of cancel request, the cookie is already set to the
         * value of the request cookie to be cancelled
 
        /* in case of cancel request, the cookie is already set to the
         * value of the request cookie to be cancelled
@@ -167,7 +176,7 @@ int mdt_agent_record_add(const struct lu_env *env,
        if (rc > 0)
                rc = 0;
 
        if (rc > 0)
                rc = 0;
 
-       mutex_unlock(&cdt->cdt_llog_lock);
+       up_write(&cdt->cdt_llog_lock);
        llog_ctxt_put(lctxt);
 
        EXIT;
        llog_ctxt_put(lctxt);
 
        EXIT;
@@ -274,7 +283,8 @@ int mdt_agent_record_update(const struct lu_env *env, struct mdt_device *mdt,
        ducb.status = status;
        ducb.change_time = cfs_time_current_sec();
 
        ducb.status = status;
        ducb.change_time = cfs_time_current_sec();
 
-       rc = cdt_llog_process(env, mdt, mdt_agent_record_update_cb, &ducb);
+       rc = cdt_llog_process(env, mdt, mdt_agent_record_update_cb, &ducb,
+                             WRITE);
        if (rc < 0)
                CERROR("%s: cdt_llog_process() failed, rc=%d, cannot update "
                       "status to %s for %d cookies, done %d\n",
        if (rc < 0)
                CERROR("%s: cdt_llog_process() failed, rc=%d, cannot update "
                       "status to %s for %d cookies, done %d\n",
@@ -425,11 +435,11 @@ static int mdt_hsm_actions_proc_show(struct seq_file *s, void *v)
        if (aai->aai_eof)
                RETURN(0);
 
        if (aai->aai_eof)
                RETURN(0);
 
-       mutex_lock(&cdt->cdt_llog_lock);
+       down_read(&cdt->cdt_llog_lock);
        rc = llog_cat_process(&aai->aai_env, aai->aai_ctxt->loc_handle,
                              hsm_actions_show_cb, s,
                              aai->aai_cat_index, aai->aai_index);
        rc = llog_cat_process(&aai->aai_env, aai->aai_ctxt->loc_handle,
                              hsm_actions_show_cb, s,
                              aai->aai_cat_index, aai->aai_index);
-       mutex_unlock(&cdt->cdt_llog_lock);
+       up_read(&cdt->cdt_llog_lock);
        if (rc == 0) /* all llog parsed */
                aai->aai_eof = true;
        if (rc == LLOG_PROC_BREAK) /* buffer full */
        if (rc == 0) /* all llog parsed */
                aai->aai_eof = true;
        if (rc == LLOG_PROC_BREAK) /* buffer full */
index b42093e..3ccb802 100644 (file)
@@ -154,7 +154,7 @@ static int hsm_find_compatible(const struct lu_env *env, struct mdt_device *mdt,
        hcdcb.cdt = &mdt->mdt_coordinator;
        hcdcb.hal = hal;
 
        hcdcb.cdt = &mdt->mdt_coordinator;
        hcdcb.hal = hal;
 
-       rc = cdt_llog_process(env, mdt, hsm_find_compatible_cb, &hcdcb);
+       rc = cdt_llog_process(env, mdt, hsm_find_compatible_cb, &hcdcb, READ);
 
        RETURN(rc);
 }
 
        RETURN(rc);
 }
index d0b9d8c..db40237 100644 (file)
@@ -140,7 +140,7 @@ struct coordinator {
                                                       * counter */
        __u64                    cdt_last_cookie;     /**< last cookie
                                                       * allocated */
                                                       * counter */
        __u64                    cdt_last_cookie;     /**< last cookie
                                                       * allocated */
-       struct mutex             cdt_llog_lock;       /**< protect llog
+       struct rw_semaphore      cdt_llog_lock;       /**< protect llog
                                                       * access */
        struct rw_semaphore      cdt_agent_lock;      /**< protect agent list */
        struct rw_semaphore      cdt_request_lock;    /**< protect request
                                                       * access */
        struct rw_semaphore      cdt_agent_lock;      /**< protect agent list */
        struct rw_semaphore      cdt_request_lock;    /**< protect request
@@ -823,7 +823,7 @@ extern const struct file_operations mdt_hsm_actions_fops;
 void dump_llog_agent_req_rec(const char *prefix,
                             const struct llog_agent_req_rec *larr);
 int cdt_llog_process(const struct lu_env *env, struct mdt_device *mdt,
 void dump_llog_agent_req_rec(const char *prefix,
                             const struct llog_agent_req_rec *larr);
 int cdt_llog_process(const struct lu_env *env, struct mdt_device *mdt,
-                    llog_cb_t cb, void *data);
+                    llog_cb_t cb, void *data, int rw);
 int mdt_agent_record_add(const struct lu_env *env, struct mdt_device *mdt,
                         __u64 compound_id, __u32 archive_id,
                         __u64 flags, struct hsm_action_item *hai);
 int mdt_agent_record_add(const struct lu_env *env, struct mdt_device *mdt,
                         __u64 compound_id, __u32 archive_id,
                         __u64 flags, struct hsm_action_item *hai);