X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fmdt%2Fmdt_hsm_cdt_actions.c;h=eda547efaaa6217ba8d1ec0f1f20702efc376c02;hb=afacbae9e3e8ce7ba4ff0ad9bd57899095ad7a46;hp=37a4da18a4b6762f62296642d8405ad6645a00cb;hpb=612f27788166e2f1153cb5f2c4b4bffba9a42235;p=fs%2Flustre-release.git diff --git a/lustre/mdt/mdt_hsm_cdt_actions.c b/lustre/mdt/mdt_hsm_cdt_actions.c index 37a4da1..eda547e 100644 --- a/lustre/mdt/mdt_hsm_cdt_actions.c +++ b/lustre/mdt/mdt_hsm_cdt_actions.c @@ -25,7 +25,7 @@ * */ /* - * lustre/mdt/mdt_agent_actions.c + * lustre/mdt/mdt_hsm_cdt_actions.c * * Lustre HSM * @@ -43,7 +43,8 @@ #include #include "mdt_internal.h" -void dump_llog_agent_req_rec(char *prefix, struct llog_agent_req_rec *larr) +void dump_llog_agent_req_rec(const char *prefix, + const struct llog_agent_req_rec *larr) { char buf[12]; int sz; @@ -92,10 +93,10 @@ int cdt_llog_process(const struct lu_env *env, struct mdt_device *mdt, ENTRY; lctxt = llog_get_context(obd, LLOG_AGENT_ORIG_CTXT); - if ((lctxt == NULL) || (lctxt->loc_handle == NULL)) + if (lctxt == NULL || lctxt->loc_handle == NULL) RETURN(-ENOENT); - down(&cdt->cdt_llog_lock); + mutex_lock(&cdt->cdt_llog_lock); rc = llog_cat_process(env, lctxt->loc_handle, cb, data, 0, 0); if (rc < 0) @@ -105,7 +106,7 @@ int cdt_llog_process(const struct lu_env *env, struct mdt_device *mdt, rc = 0; llog_ctxt_put(lctxt); - up(&cdt->cdt_llog_lock); + mutex_unlock(&cdt->cdt_llog_lock); RETURN(rc); } @@ -147,10 +148,10 @@ int mdt_agent_record_add(const struct lu_env *env, memcpy(&larr->arr_hai, hai, hai->hai_len); lctxt = llog_get_context(obd, LLOG_AGENT_ORIG_CTXT); - if ((lctxt == NULL) || (lctxt->loc_handle == NULL)) + if (lctxt == NULL || lctxt->loc_handle == NULL) GOTO(free, rc = -ENOENT); - down(&cdt->cdt_llog_lock); + mutex_lock(&cdt->cdt_llog_lock); /* in case of cancel request, the cookie is already set to the * value of the request cookie to be cancelled @@ -164,7 +165,7 @@ int mdt_agent_record_add(const struct lu_env *env, if (rc > 0) rc = 0; - up(&cdt->cdt_llog_lock); + mutex_unlock(&cdt->cdt_llog_lock); llog_ctxt_put(lctxt); EXIT; @@ -222,8 +223,8 @@ static int mdt_agent_record_update_cb(const struct lu_env *env, * the 1st has to be set to ARS_CANCELED and the 2nd to ARS_SUCCEED */ if (agent_req_in_final_state(larr->arr_status) || - ((larr->arr_hai.hai_action == HSMA_CANCEL) && - (ducb->status == ARS_CANCELED))) + (larr->arr_hai.hai_action == HSMA_CANCEL && + ducb->status == ARS_CANCELED)) RETURN(0); rc = 0; @@ -324,8 +325,7 @@ int mdt_agent_llog_update_rec(const struct lu_env *env, * multiple record in seq_file buffer in one show call. * op->start() sets the iterator up and returns the first element of sequence * op->stop() shuts it down. - * op->next() returns the next element of sequence. - * op->show() prints element into the buffer. + * op->show() iterate llog and print element into the buffer. * In case of error ->start() and ->next() return ERR_PTR(error) * In the end of sequence they return %NULL * op->show() returns 0 in case of success and negative number in case of error. @@ -337,92 +337,58 @@ int mdt_agent_llog_update_rec(const struct lu_env *env, #define AGENT_ACTIONS_IT_MAGIC 0x19660426 struct agent_action_iterator { int aai_magic; /**< magic number */ + bool aai_eof; /**< all done */ struct lu_env aai_env; /**< lustre env for llog */ struct obd_device *aai_obd; /**< metadata device */ struct llog_ctxt *aai_ctxt; /**< llog context */ - struct llog_handle *aai_llh; /**< llog handle */ - int aai_index_done; /**< idx already shown */ - int aai_index_cb; /**< current idx in loop cb */ - int aai_eof; /**< all done */ + int aai_cat_index; /**< cata idx already shown */ + int aai_index; /**< idx in cata shown */ }; /** * seq_file method called to start access to /proc file * get llog context + llog handle */ -static void *mdt_agent_actions_proc_start(struct seq_file *s, loff_t *pos) +static void *mdt_hsm_actions_proc_start(struct seq_file *s, loff_t *pos) { struct agent_action_iterator *aai = s->private; - int rc; ENTRY; LASSERTF(aai->aai_magic == AGENT_ACTIONS_IT_MAGIC, "%08X", aai->aai_magic); aai->aai_ctxt = llog_get_context(aai->aai_obd, LLOG_AGENT_ORIG_CTXT); - if (aai->aai_ctxt == NULL) { + if (aai->aai_ctxt == NULL || aai->aai_ctxt->loc_handle == NULL) { CERROR("llog_get_context() failed\n"); RETURN(ERR_PTR(-ENOENT)); } - rc = llog_open(&aai->aai_env, aai->aai_ctxt, &aai->aai_llh, NULL, - HSM_ACTIONS, LLOG_OPEN_EXISTS); - if (rc) - GOTO(err, rc); - - rc = llog_init_handle(&aai->aai_env, aai->aai_llh, LLOG_F_IS_CAT, NULL); - if (rc) - GOTO(err, rc); CDEBUG(D_HSM, "llog succesfully initialized, start from "LPD64"\n", *pos); /* first call = rewind */ if (*pos == 0) { - aai->aai_index_done = 0; - aai->aai_eof = 0; + aai->aai_cat_index = 0; + aai->aai_index = 0; + aai->aai_eof = false; *pos = 1; } - RETURN(aai); -err: - if (aai->aai_llh) { - llog_cat_close(&aai->aai_env, aai->aai_llh); - aai->aai_llh = NULL; - } - - if (aai->aai_ctxt) - llog_ctxt_put(aai->aai_ctxt); + if (aai->aai_eof) + RETURN(NULL); - RETURN(ERR_PTR(rc)); + RETURN(aai); } -/** - * seq_file method called to get next item - * just returns NULL at eof - * (seq_file buffer filling is done in llog_cat_process() callback) - */ -static void *mdt_agent_actions_proc_next(struct seq_file *s, void *v, +static void *mdt_hsm_actions_proc_next(struct seq_file *s, void *v, loff_t *pos) { - struct agent_action_iterator *aai = s->private; - ENTRY; - - LASSERTF(aai->aai_magic == AGENT_ACTIONS_IT_MAGIC, "%08X", - aai->aai_magic); - - CDEBUG(D_HSM, "set current="LPD64" to done=%d, eof=%d\n", - *pos, aai->aai_index_done, aai->aai_eof); - (*pos) = aai->aai_index_done; - - if (aai->aai_eof) - RETURN(NULL); - - RETURN(aai); + RETURN(NULL); } /** * llog_cat_process() callback, used to fill a seq_file buffer */ -static int agent_actions_show_cb(const struct lu_env *env, +static int hsm_actions_show_cb(const struct lu_env *env, struct llog_handle *llh, struct llog_rec_hdr *hdr, void *data) @@ -431,6 +397,7 @@ static int agent_actions_show_cb(const struct lu_env *env, struct seq_file *s = data; struct agent_action_iterator *aai; int rc, sz; + size_t count; char buf[12]; ENTRY; @@ -438,21 +405,25 @@ static int agent_actions_show_cb(const struct lu_env *env, LASSERTF(aai->aai_magic == AGENT_ACTIONS_IT_MAGIC, "%08X", aai->aai_magic); - aai->aai_index_cb++; /* if rec already printed => skip */ - if (aai->aai_index_cb <= aai->aai_index_done) + if (unlikely(llh->lgh_hdr->llh_cat_idx < aai->aai_cat_index)) RETURN(0); + if (unlikely(llh->lgh_hdr->llh_cat_idx == aai->aai_cat_index && + hdr->lrh_index <= aai->aai_index)) + RETURN(0); + + count = s->count; sz = larr->arr_hai.hai_len - sizeof(larr->arr_hai); - rc = seq_printf(s, "lrh=[type=%X len=%d idx=%d] fid="DFID + rc = seq_printf(s, "lrh=[type=%X len=%d idx=%d/%d] fid="DFID " dfid="DFID " compound/cookie="LPX64"/"LPX64 " action=%s archive#=%d flags="LPX64 " extent="LPX64"-"LPX64 " gid="LPX64" datalen=%d status=%s" " data=[%s]\n", - larr->arr_hdr.lrh_type, - larr->arr_hdr.lrh_len, larr->arr_hdr.lrh_index, + hdr->lrh_type, hdr->lrh_len, + llh->lgh_hdr->llh_cat_idx, hdr->lrh_index, PFID(&larr->arr_hai.hai_fid), PFID(&larr->arr_hai.hai_dfid), larr->arr_compound_id, larr->arr_hai.hai_cookie, @@ -464,20 +435,23 @@ static int agent_actions_show_cb(const struct lu_env *env, larr->arr_hai.hai_gid, sz, agent_req_status2name(larr->arr_status), hai_dump_data_field(&larr->arr_hai, buf, sizeof(buf))); - if (rc >= 0) { - aai->aai_index_done++; - RETURN(0); + if (rc == 0) { + aai->aai_cat_index = llh->lgh_hdr->llh_cat_idx; + aai->aai_index = hdr->lrh_index; + } else { + if (s->count == s->size && count > 0) /* rewind the buffer */ + s->count = count; + rc = LLOG_PROC_BREAK; } - /* buffer is full, stop filling */ - RETURN(LLOG_PROC_BREAK); + RETURN(rc); } /** - * mdt_agent_actions_proc_show() is called at for each seq record + * mdt_hsm_actions_proc_show() is called at for each seq record * process the llog, with a cb which fill the file_seq buffer * to be faster, one show will fill multiple records */ -static int mdt_agent_actions_proc_show(struct seq_file *s, void *v) +static int mdt_hsm_actions_proc_show(struct seq_file *s, void *v) { struct agent_action_iterator *aai = s->private; int rc; @@ -486,21 +460,18 @@ static int mdt_agent_actions_proc_show(struct seq_file *s, void *v) LASSERTF(aai->aai_magic == AGENT_ACTIONS_IT_MAGIC, "%08X", aai->aai_magic); - CDEBUG(D_HSM, "show from done=%d, eof=%d\n", - aai->aai_index_done, aai->aai_eof); + CDEBUG(D_HSM, "show from cat %d index %d eof=%d\n", + aai->aai_cat_index, aai->aai_index, aai->aai_eof); if (aai->aai_eof) RETURN(0); - aai->aai_index_cb = 0; - rc = llog_cat_process(&aai->aai_env, aai->aai_llh, - agent_actions_show_cb, s, 0, 0); - /* was all llog parsed? */ - if (rc == 0) - aai->aai_eof = 1; - /* not enough room in buffer? */ - if (rc == LLOG_PROC_BREAK) - RETURN(0); - /* error */ + rc = llog_cat_process(&aai->aai_env, aai->aai_ctxt->loc_handle, + hsm_actions_show_cb, s, + aai->aai_cat_index, aai->aai_index + 1); + if (rc == 0) /* all llog parsed */ + aai->aai_eof = true; + if (rc == LLOG_PROC_BREAK) /* buffer full */ + rc = 0; RETURN(rc); } @@ -508,7 +479,7 @@ static int mdt_agent_actions_proc_show(struct seq_file *s, void *v) * seq_file method called to stop access to /proc file * clean + put llog context */ -static void mdt_agent_actions_proc_stop(struct seq_file *s, void *v) +static void mdt_hsm_actions_proc_stop(struct seq_file *s, void *v) { struct agent_action_iterator *aai = s->private; ENTRY; @@ -516,24 +487,21 @@ static void mdt_agent_actions_proc_stop(struct seq_file *s, void *v) LASSERTF(aai->aai_magic == AGENT_ACTIONS_IT_MAGIC, "%08X", aai->aai_magic); - if (aai->aai_llh) { - llog_cat_close(&aai->aai_env, aai->aai_llh); - aai->aai_llh = NULL; - } if (aai->aai_ctxt) llog_ctxt_put(aai->aai_ctxt); + EXIT; return; } -static const struct seq_operations mdt_agent_actions_proc_ops = { - .start = mdt_agent_actions_proc_start, - .next = mdt_agent_actions_proc_next, - .show = mdt_agent_actions_proc_show, - .stop = mdt_agent_actions_proc_stop, +static const struct seq_operations mdt_hsm_actions_proc_ops = { + .start = mdt_hsm_actions_proc_start, + .next = mdt_hsm_actions_proc_next, + .show = mdt_hsm_actions_proc_show, + .stop = mdt_hsm_actions_proc_stop, }; -static int lprocfs_open_agent_actions(struct inode *inode, struct file *file) +static int lprocfs_open_hsm_actions(struct inode *inode, struct file *file) { struct agent_action_iterator *aai; struct seq_file *s; @@ -541,14 +509,12 @@ static int lprocfs_open_agent_actions(struct inode *inode, struct file *file) struct mdt_device *mdt; ENTRY; - if (LPROCFS_ENTRY_AND_CHECK(PDE(inode))) + if (LPROCFS_ENTRY_CHECK(PDE(inode))) RETURN(-ENOENT); - rc = seq_open(file, &mdt_agent_actions_proc_ops); - if (rc) { - LPROCFS_EXIT(); + rc = seq_open(file, &mdt_hsm_actions_proc_ops); + if (rc) RETURN(rc); - } OBD_ALLOC_PTR(aai); if (aai == NULL) @@ -559,7 +525,6 @@ static int lprocfs_open_agent_actions(struct inode *inode, struct file *file) if (rc) GOTO(err, rc); - aai->aai_llh = NULL; /* mdt is saved in proc_dir_entry->data by * mdt_coordinator_procfs_init() calling lprocfs_register() */ @@ -581,10 +546,10 @@ out: } /** - * lprocfs_release_agent_actions() is called at end of /proc access - * free alloacted ressources and call cleanup lprocfs methods + * lprocfs_release_hsm_actions() is called at end of /proc access. + * It frees allocated ressources and calls cleanup lprocfs methods. */ -static int lprocfs_release_agent_actions(struct inode *inode, struct file *file) +static int lprocfs_release_hsm_actions(struct inode *inode, struct file *file) { struct seq_file *seq = file->private_data; struct agent_action_iterator *aai = seq->private; @@ -597,12 +562,12 @@ static int lprocfs_release_agent_actions(struct inode *inode, struct file *file) return lprocfs_seq_release(inode, file); } -/* methods to access agent actions llog through /proc */ -const struct file_operations mdt_agent_actions_fops = { +/* Methods to access HSM action list LLOG through /proc */ +const struct file_operations mdt_hsm_actions_fops = { .owner = THIS_MODULE, - .open = lprocfs_open_agent_actions, + .open = lprocfs_open_hsm_actions, .read = seq_read, .llseek = seq_lseek, - .release = lprocfs_release_agent_actions, + .release = lprocfs_release_hsm_actions, };