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>
- 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;
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, WRITE);
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);
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);
* \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;
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)
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);
+
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
- mutex_unlock(&cdt->cdt_llog_lock);
+ up_write(&cdt->cdt_llog_lock);
llog_ctxt_put(lctxt);
EXIT;
llog_ctxt_put(lctxt);
EXIT;
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",
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 */
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);
* 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
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);