From: John L. Hammond Date: Wed, 17 Jun 2015 22:46:09 +0000 (-0700) Subject: LU-9312 hsm: convert cdt_llog_lock to a rw semaphore X-Git-Tag: 2.9.59~77 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=2d5babe5a9920cab6153b14523da0f12e8bd2239 LU-9312 hsm: convert cdt_llog_lock to a rw semaphore 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 Reviewed-on: https://review.whamcloud.com/26803 Tested-by: Jenkins Reviewed-by: Ben Evans Reviewed-by: Quentin Bouget Tested-by: Maloo Reviewed-by: Oleg Drokin --- diff --git a/lustre/mdt/mdt_coordinator.c b/lustre/mdt/mdt_coordinator.c index d250424..0475011 100644 --- a/lustre/mdt/mdt_coordinator.c +++ b/lustre/mdt/mdt_coordinator.c @@ -573,8 +573,8 @@ static int mdt_coordinator(void *data) 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; @@ -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, - hsm_restore_cb, &hrd); + hsm_restore_cb, &hrd, WRITE); RETURN(rc); } @@ -852,7 +852,7 @@ int mdt_hsm_cdt_init(struct mdt_device *mdt) 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); @@ -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, - 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); diff --git a/lustre/mdt/mdt_hsm_cdt_actions.c b/lustre/mdt/mdt_hsm_cdt_actions.c index 711747c..94bc265 100644 --- a/lustre/mdt/mdt_hsm_cdt_actions.c +++ b/lustre/mdt/mdt_hsm_cdt_actions.c @@ -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 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, - 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; @@ -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); - 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) @@ -106,7 +110,12 @@ int cdt_llog_process(const struct lu_env *env, struct mdt_device *mdt, 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); } @@ -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); - 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 @@ -167,7 +176,7 @@ int mdt_agent_record_add(const struct lu_env *env, if (rc > 0) rc = 0; - mutex_unlock(&cdt->cdt_llog_lock); + up_write(&cdt->cdt_llog_lock); 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(); - 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", @@ -425,11 +435,11 @@ static int mdt_hsm_actions_proc_show(struct seq_file *s, void *v) 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); - 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 */ diff --git a/lustre/mdt/mdt_hsm_cdt_client.c b/lustre/mdt/mdt_hsm_cdt_client.c index b42093e..3ccb802 100644 --- a/lustre/mdt/mdt_hsm_cdt_client.c +++ b/lustre/mdt/mdt_hsm_cdt_client.c @@ -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; - 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); } diff --git a/lustre/mdt/mdt_internal.h b/lustre/mdt/mdt_internal.h index d0b9d8c..db40237 100644 --- a/lustre/mdt/mdt_internal.h +++ b/lustre/mdt/mdt_internal.h @@ -140,7 +140,7 @@ struct coordinator { * 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 @@ -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, - 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);