From 4b02a71242504c1aa51fa5bca87721031bf670ae Mon Sep 17 00:00:00 2001 From: jcl Date: Tue, 6 Aug 2013 23:05:11 +0200 Subject: [PATCH] LU-3709 mdt: CDT cleanup follow-on patch This patch implements the comments made during the review after maloo passed test or after the landing. rename in hai_zero() hai_first() Use a better name for hai helper replace use of cfs_helpers by native one in CDT replace cfs_atomic_t and helpers replace cfs_list and helpers change list_for_each + list_entry by list_entry_for_each replace cfs_task_t clean err msg in HSM agent interface remove duplicate rc print parenthesis code cleaning remove useless () in conditionnal tests Signed-off-by: JC Lafoucriere Change-Id: Ib57f5b4ed7023c18d71bdb620ed53f9b9fa41a3e Reviewed-on: http://review.whamcloud.com/7254 Tested-by: Hudson Reviewed-by: Jinshan Xiong Reviewed-by: John L. Hammond Tested-by: Maloo Reviewed-by: Oleg Drokin --- lustre/include/lustre/lustre_user.h | 4 +-- lustre/mdc/mdc_request.c | 2 +- lustre/mdt/mdt_coordinator.c | 65 +++++++++++++++++++------------------ lustre/mdt/mdt_handler.c | 12 +++---- lustre/mdt/mdt_hsm.c | 12 +++---- lustre/mdt/mdt_hsm_cdt_actions.c | 10 +++--- lustre/mdt/mdt_hsm_cdt_agent.c | 56 +++++++++++++++----------------- lustre/mdt/mdt_hsm_cdt_client.c | 52 ++++++++++++++--------------- lustre/mdt/mdt_hsm_cdt_requests.c | 43 ++++++++++++------------ lustre/mdt/mdt_internal.h | 14 ++++---- lustre/utils/lhsmtool_posix.c | 2 +- 11 files changed, 132 insertions(+), 140 deletions(-) diff --git a/lustre/include/lustre/lustre_user.h b/lustre/include/lustre/lustre_user.h index 045ff2b..f058f6d 100644 --- a/lustre/include/lustre/lustre_user.h +++ b/lustre/include/lustre/lustre_user.h @@ -1117,7 +1117,7 @@ static inline int cfs_size_round (int val) #endif /* Return pointer to first hai in action list */ -static inline struct hsm_action_item * hai_zero(struct hsm_action_list *hal) +static inline struct hsm_action_item *hai_first(struct hsm_action_list *hal) { return (struct hsm_action_item *)(hal->hal_fsname + cfs_size_round(strlen(hal-> \ @@ -1137,7 +1137,7 @@ static inline int hal_size(struct hsm_action_list *hal) struct hsm_action_item *hai; sz = sizeof(*hal) + cfs_size_round(strlen(hal->hal_fsname)); - hai = hai_zero(hal); + hai = hai_first(hal); for (i = 0 ; i < hal->hal_count ; i++, hai = hai_next(hai)) sz += cfs_size_round(hai->hai_len); diff --git a/lustre/mdc/mdc_request.c b/lustre/mdc/mdc_request.c index 498a2fd..18187af 100644 --- a/lustre/mdc/mdc_request.c +++ b/lustre/mdc/mdc_request.c @@ -2030,7 +2030,7 @@ static void lustre_swab_hal(struct hsm_action_list *h) __swab32s(&h->hal_count); __swab32s(&h->hal_archive_id); __swab64s(&h->hal_flags); - hai = hai_zero(h); + hai = hai_first(h); for (i = 0; i < h->hal_count; i++, hai = hai_next(hai)) lustre_swab_hai(hai); } diff --git a/lustre/mdt/mdt_coordinator.c b/lustre/mdt/mdt_coordinator.c index a48bc36..66df716 100644 --- a/lustre/mdt/mdt_coordinator.c +++ b/lustre/mdt/mdt_coordinator.c @@ -53,7 +53,7 @@ static struct lprocfs_vars lprocfs_mdt_hsm_vars[]; * \param mti [IN] context * \param fid [IN] object fid * \param hsm [OUT] HSM meta data - * \retval obj + * \retval obj or error (-ENOENT if not found) */ struct mdt_object *mdt_hsm_get_md_hsm(struct mdt_thread_info *mti, const struct lu_fid *fid, @@ -105,7 +105,7 @@ void mdt_hsm_dump_hal(int level, const char *prefix, prefix, hal->hal_version, hal->hal_count, hal->hal_compound_id, hal->hal_archive_id, hal->hal_flags); - hai = hai_zero(hal); + hai = hai_first(hal); for (i = 0; i < hal->hal_count; i++) { sz = hai->hai_len - sizeof(*hai); CDEBUG(level, "%s %d: fid="DFID" dfid="DFID @@ -201,7 +201,7 @@ static int mdt_coordinator_cb(const struct lu_env *env, continue; } } - if ((found == -1) && (empty_slot == -1)) + if (found == -1 && empty_slot == -1) /* unknown request and no more room for new request, * continue scan for to find other entries for * already found request @@ -239,7 +239,7 @@ static int mdt_coordinator_cb(const struct lu_env *env, hsd->request[empty_slot].hal = hal; hsd->request_cnt++; found = empty_slot; - hai = hai_zero(hal); + hai = hai_first(hal); } else { /* request is known */ /* we check if record archive num is the same as the @@ -276,7 +276,7 @@ static int mdt_coordinator_cb(const struct lu_env *env, hsd->request[found].hal = hal_buffer; hsd->request[found].hal_sz = sz; } - hai = hai_zero(hsd->request[found].hal); + hai = hai_first(hsd->request[found].hal); for (i = 0; i < hsd->request[found].hal->hal_count; i++) hai = hai_next(hai); @@ -461,8 +461,8 @@ static int mdt_coordinator(void *data) CDEBUG(D_HSM, "coordinator resumes\n"); - if ((cdt->cdt_thread.t_flags & SVC_STOPPING) || - (cdt->cdt_state == CDT_STOPPING)) { + if (cdt->cdt_thread.t_flags & SVC_STOPPING || + cdt->cdt_state == CDT_STOPPING) { cdt->cdt_thread.t_flags &= ~SVC_STOPPING; rc = 0; break; @@ -589,7 +589,7 @@ static int mdt_coordinator(void *data) kuc_free(hal, hsd.request[i].hal_used_sz); continue; } - hai = hai_zero(hal); + hai = hai_first(hal); for (j = 0; j < hsd.request[i].hal->hal_count; j++) { cookies[j] = hai->hai_cookie; hai = hai_next(hai); @@ -725,8 +725,8 @@ static int hsm_restore_cb(const struct lu_env *env, larr = (struct llog_agent_req_rec *)hdr; hai = &larr->arr_hai; - if ((hai->hai_action != HSMA_RESTORE) || - agent_req_in_final_state(larr->arr_status)) + if (hai->hai_action != HSMA_RESTORE || + agent_req_in_final_state(larr->arr_status)) RETURN(0); /* restore request not in a final state */ @@ -904,7 +904,7 @@ int mdt_hsm_cdt_start(struct mdt_device *mdt) int rc; void *ptr; struct mdt_thread_info *cdt_mti; - cfs_task_t *task; + struct task_struct *task; ENTRY; /* functions defined but not yet used @@ -921,7 +921,7 @@ int mdt_hsm_cdt_start(struct mdt_device *mdt) cdt->cdt_policy = CDT_DEFAULT_POLICY; cdt->cdt_state = CDT_INIT; - cfs_atomic_set(&cdt->cdt_compound_id, cfs_time_current_sec()); + atomic_set(&cdt->cdt_compound_id, cfs_time_current_sec()); /* just need to be larger than previous one */ /* cdt_last_cookie is protected by cdt_llog_lock */ cdt->cdt_last_cookie = cfs_time_current_sec(); @@ -1051,7 +1051,7 @@ int mdt_hsm_add_hal(struct mdt_thread_info *mti, ENTRY; /* register request in memory list */ - hai = hai_zero(hal); + hai = hai_first(hal); for (i = 0; i < hal->hal_count; i++, hai = hai_next(hai)) { struct cdt_agent_req *car; @@ -1229,9 +1229,8 @@ static int hsm_cdt_request_completed(struct mdt_thread_info *mti, *status = ARS_SUCCEED; break; default: - *status = (((cdt->cdt_policy & - CDT_NORETRY_ACTION) || - !(pgs->hpk_flags & HP_FLAG_RETRY)) ? + *status = (cdt->cdt_policy & CDT_NORETRY_ACTION || + !(pgs->hpk_flags & HP_FLAG_RETRY) ? ARS_FAILED : ARS_WAITING); break; } @@ -1329,8 +1328,8 @@ static int hsm_cdt_request_completed(struct mdt_thread_info *mti, * a crasy CT no need to manage DIRTY */ if (rc == 0) - hsm_set_cl_flags(&cl_flags, ((mh.mh_flags & HS_DIRTY) ? - CLF_HSM_DIRTY : 0)); + hsm_set_cl_flags(&cl_flags, + mh.mh_flags & HS_DIRTY ? CLF_HSM_DIRTY : 0); /* unlock is done later, after layout lock management */ if (is_mh_changed) @@ -1340,9 +1339,9 @@ unlock: /* we give back layout lock only if restore was successful or * if restore was canceled or if policy is to not retry * in other cases we just unlock the object */ - if ((car->car_hai->hai_action == HSMA_RESTORE) && - ((pgs->hpk_errval == 0) || (pgs->hpk_errval == ECANCELED) || - (cdt->cdt_policy & CDT_NORETRY_ACTION))) { + if (car->car_hai->hai_action == HSMA_RESTORE && + (pgs->hpk_errval == 0 || pgs->hpk_errval == ECANCELED || + cdt->cdt_policy & CDT_NORETRY_ACTION)) { struct cdt_restore_handle *crh; /* restore in data FID done, we swap the layouts @@ -1378,7 +1377,7 @@ unlock: GOTO(out, rc); out: - if ((obj != NULL) && !IS_ERR(obj)) { + if (obj != NULL && !IS_ERR(obj)) { mo_changelog(env, CL_HSM, cl_flags, mdt_object_child(obj)); mdt_object_put(mti->mti_env, obj); @@ -1416,6 +1415,8 @@ int mdt_hsm_update_request_state(struct mdt_thread_info *mti, " on fid="DFID"\n", mdt_obd_name(mdt), pgs->hpk_cookie, PFID(&pgs->hpk_fid)); + if (car == NULL) + RETURN(-ENOENT); RETURN(PTR_ERR(car)); } @@ -1430,12 +1431,12 @@ int mdt_hsm_update_request_state(struct mdt_thread_info *mti, /* progress is done on FID or data FID depending of the action and * of the copy progress */ /* for restore progress is used to send back the data FID to cdt */ - if ((car->car_hai->hai_action == HSMA_RESTORE) && - (lu_fid_eq(&car->car_hai->hai_fid, &car->car_hai->hai_dfid))) + if (car->car_hai->hai_action == HSMA_RESTORE && + lu_fid_eq(&car->car_hai->hai_fid, &car->car_hai->hai_dfid)) car->car_hai->hai_dfid = pgs->hpk_fid; - if (((car->car_hai->hai_action == HSMA_RESTORE) || - (car->car_hai->hai_action == HSMA_ARCHIVE)) && + if ((car->car_hai->hai_action == HSMA_RESTORE || + car->car_hai->hai_action == HSMA_ARCHIVE) && (!lu_fid_eq(&pgs->hpk_fid, &car->car_hai->hai_dfid) && !lu_fid_eq(&pgs->hpk_fid, &car->car_hai->hai_fid))) { CERROR("%s: Progress on "DFID" for cookie "LPX64 @@ -1542,8 +1543,8 @@ static int mdt_cancel_all_cb(const struct lu_env *env, larr = (struct llog_agent_req_rec *)hdr; hcad = data; - if ((larr->arr_status == ARS_WAITING) || - (larr->arr_status == ARS_STARTED)) { + if (larr->arr_status == ARS_WAITING || + larr->arr_status == ARS_STARTED) { larr->arr_status = ARS_CANCELED; larr->arr_req_change = cfs_time_current_sec(); rc = mdt_agent_llog_update_rec(env, hcad->mdt, llh, larr); @@ -1593,7 +1594,7 @@ static int hsm_cancel_all_actions(struct mdt_device *mdt) hal_len = sizeof(*hal) + cfs_size_round(MTI_NAME_MAXLEN + 1) + cfs_size_round(car->car_hai->hai_len); - if ((hal_len > hal_sz) && (hal_sz > 0)) { + if (hal_len > hal_sz && hal_sz > 0) { /* not enough room, free old buffer */ OBD_FREE(hal, hal_sz); hal = NULL; @@ -1619,7 +1620,7 @@ static int hsm_cancel_all_actions(struct mdt_device *mdt) hal->hal_flags = car->car_flags; hal->hal_count = 0; - hai = hai_zero(hal); + hai = hai_first(hal); memcpy(hai, car->car_hai, car->car_hai->hai_len); hai->hai_action = HSMA_CANCEL; hal->hal_count = 1; @@ -1673,12 +1674,12 @@ bool mdt_hsm_is_action_compat(const struct hsm_action_item *hai, switch (hai->hai_action) { case HSMA_ARCHIVE: if (!(hsm_flags & HS_NOARCHIVE) && - ((hsm_flags & HS_DIRTY) || !(hsm_flags & HS_ARCHIVED))) + (hsm_flags & HS_DIRTY || !(hsm_flags & HS_ARCHIVED))) is_compat = true; break; case HSMA_RESTORE: if (!(hsm_flags & HS_DIRTY) && (hsm_flags & HS_RELEASED) && - (hsm_flags & HS_ARCHIVED) && !(hsm_flags & HS_LOST)) + hsm_flags & HS_ARCHIVED && !(hsm_flags & HS_LOST)) is_compat = true; break; case HSMA_REMOVE: diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index f5ca000..15f6c4b 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -411,8 +411,8 @@ void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b, b->blocks = 0; /* if no object is allocated on osts, the size on mds is valid. b=22272 */ b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS; - } else if ((ma->ma_valid & MA_LOV) && ma->ma_lmm && - (ma->ma_lmm->lmm_pattern & LOV_PATTERN_F_RELEASED)) { + } else if ((ma->ma_valid & MA_LOV) && ma->ma_lmm != NULL && + ma->ma_lmm->lmm_pattern & LOV_PATTERN_F_RELEASED) { /* A released file stores its size on MDS. */ b->blocks = 0; b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS; @@ -766,7 +766,7 @@ static int mdt_getattr_internal(struct mdt_thread_info *info, /* the Lustre protocol supposes to return default striping * on the user-visible root if explicitly requested */ if ((ma->ma_valid & MA_LOV) == 0 && S_ISDIR(la->la_mode) && - (ma->ma_need & MA_LOV_DEF && is_root) && (ma->ma_need & MA_LOV)) { + (ma->ma_need & MA_LOV_DEF && is_root) && ma->ma_need & MA_LOV) { struct lu_fid rootfid; struct mdt_object *root; struct mdt_device *mdt = info->mti_mdt; @@ -2561,7 +2561,7 @@ int mdt_remote_object_lock(struct mdt_thread_info *mti, LASSERT(mdt_object_remote(o)); - LASSERT((ibits & MDS_INODELOCK_UPDATE)); + LASSERT(ibits & MDS_INODELOCK_UPDATE); memset(einfo, 0, sizeof(*einfo)); einfo->ei_type = LDLM_IBITS; @@ -5857,8 +5857,8 @@ static int mdt_path_current(struct mdt_thread_info *info, linkea_entry_unpack(lee, &reclen, tmpname, tmpfid); /* If set, use link #linkno for path lookup, otherwise use link #0. Only do this for the final path element. */ - if ((pli->pli_fidcount == 0) && - (pli->pli_linkno < leh->leh_reccount)) { + if (pli->pli_fidcount == 0 && + pli->pli_linkno < leh->leh_reccount) { int count; for (count = 0; count < pli->pli_linkno; count++) { lee = (struct link_ea_entry *) diff --git a/lustre/mdt/mdt_hsm.c b/lustre/mdt/mdt_hsm.c index 46511fe..510c737 100644 --- a/lustre/mdt/mdt_hsm.c +++ b/lustre/mdt/mdt_hsm.c @@ -284,10 +284,10 @@ int mdt_hsm_state_set(struct mdt_thread_info *info) * LOST without ARCHIVED: cannot lost a non-archived file. */ flags = ma->ma_hsm.mh_flags; - if (((flags & HS_DIRTY) && !(flags & HS_EXISTS)) || - ((flags & HS_RELEASED) && (flags & HS_DIRTY)) || - ((flags & HS_RELEASED) && !(flags & HS_ARCHIVED)) || - ((flags & HS_LOST) && !(flags & HS_ARCHIVED))) { + if ((flags & HS_DIRTY && !(flags & HS_EXISTS)) || + (flags & HS_RELEASED && flags & HS_DIRTY) || + (flags & HS_RELEASED && !(flags & HS_ARCHIVED)) || + (flags & HS_LOST && !(flags & HS_ARCHIVED))) { CDEBUG(D_HSM, "Incompatible flag change on "DFID "flags="LPX64"\n", PFID(&info->mti_body->fid1), flags); @@ -353,7 +353,7 @@ int mdt_hsm_action(struct mdt_thread_info *info) obd_uuid2fsname(hal->hal_fsname, mdt_obd_name(info->mti_mdt), MTI_NAME_MAXLEN); hal->hal_count = 1; - hai = hai_zero(hal); + hai = hai_first(hal); hai->hai_action = HSMA_NONE; hai->hai_cookie = 0; hai->hai_gid = 0; @@ -493,7 +493,7 @@ int mdt_hsm_request(struct mdt_thread_info *info) MTI_NAME_MAXLEN); hal->hal_count = hr->hr_itemcount; - hai = hai_zero(hal); + hai = hai_first(hal); for (i = 0; i < hr->hr_itemcount; i++, hai = hai_next(hai)) { hai->hai_action = action; hai->hai_cookie = 0; diff --git a/lustre/mdt/mdt_hsm_cdt_actions.c b/lustre/mdt/mdt_hsm_cdt_actions.c index 8a08005..af89b56 100644 --- a/lustre/mdt/mdt_hsm_cdt_actions.c +++ b/lustre/mdt/mdt_hsm_cdt_actions.c @@ -93,7 +93,7 @@ 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); mutex_lock(&cdt->cdt_llog_lock); @@ -148,7 +148,7 @@ 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); mutex_lock(&cdt->cdt_llog_lock); @@ -223,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; @@ -359,7 +359,7 @@ static void *mdt_agent_actions_proc_start(struct seq_file *s, loff_t *pos) aai->aai_magic); aai->aai_ctxt = llog_get_context(aai->aai_obd, LLOG_AGENT_ORIG_CTXT); - if ((aai->aai_ctxt == NULL) || (aai->aai_ctxt->loc_handle == NULL)) { + if (aai->aai_ctxt == NULL || aai->aai_ctxt->loc_handle == NULL) { CERROR("llog_get_context() failed\n"); RETURN(ERR_PTR(-ENOENT)); } diff --git a/lustre/mdt/mdt_hsm_cdt_agent.c b/lustre/mdt/mdt_hsm_cdt_agent.c index b7c4c93..92e0730 100644 --- a/lustre/mdt/mdt_hsm_cdt_agent.c +++ b/lustre/mdt/mdt_hsm_cdt_agent.c @@ -57,10 +57,8 @@ static struct hsm_agent *mdt_hsm_agent_lookup(struct coordinator *cdt, const struct obd_uuid *uuid) { struct hsm_agent *ha; - cfs_list_t *pos; - cfs_list_for_each(pos, &cdt->cdt_agents) { - ha = cfs_list_entry(pos, struct hsm_agent, ha_list); + list_for_each_entry(ha, &cdt->cdt_agents, ha_list) { if (obd_uuid_equals(&ha->ha_uuid, uuid)) return ha; } @@ -120,7 +118,7 @@ int mdt_hsm_agent_register(struct mdt_thread_info *mti, GOTO(out_free, rc = -EEXIST); } - cfs_list_add_tail(&ha->ha_list, &cdt->cdt_agents); + list_add_tail(&ha->ha_list, &cdt->cdt_agents); if (ha->ha_archive_cnt == 0) CDEBUG(D_HSM, "agent %s registered for all archives\n", @@ -134,7 +132,7 @@ int mdt_hsm_agent_register(struct mdt_thread_info *mti, out_free: - if ((ha != NULL) && (ha->ha_archive_id != NULL)) + if (ha != NULL && ha->ha_archive_id != NULL) OBD_FREE(ha->ha_archive_id, ha->ha_archive_cnt * sizeof(*ha->ha_archive_id)); if (ha != NULL) @@ -205,7 +203,7 @@ int mdt_hsm_agent_unregister(struct mdt_thread_info *mti, ha = mdt_hsm_agent_lookup(cdt, uuid); if (ha != NULL) - cfs_list_del_init(&ha->ha_list); + list_del_init(&ha->ha_list); up_write(&cdt->cdt_agent_lock); @@ -239,14 +237,14 @@ int mdt_hsm_agent_update_statistics(struct coordinator *cdt, int succ_rq, int fail_rq, int new_rq, const struct obd_uuid *uuid) { - struct hsm_agent *ha, *tmp; + struct hsm_agent *ha; int rc; ENTRY; down_read(&cdt->cdt_agent_lock); - cfs_list_for_each_entry_safe(ha, tmp, &cdt->cdt_agents, ha_list) { + list_for_each_entry(ha, &cdt->cdt_agents, ha_list) { if (obd_uuid_equals(&ha->ha_uuid, uuid)) { - if ((succ_rq == 0) && (fail_rq == 0) && (new_rq == 0)) { + if (succ_rq == 0 && fail_rq == 0 && new_rq == 0) { atomic_set(&ha->ha_success, 0); atomic_set(&ha->ha_failure, 0); atomic_set(&ha->ha_requests, 0); @@ -279,23 +277,22 @@ int mdt_hsm_find_best_agent(struct coordinator *cdt, __u32 archive, struct obd_uuid *uuid) { int rc = -EAGAIN, i, load = -1; - struct hsm_agent *ha, *tmp; + struct hsm_agent *ha; ENTRY; /* Choose an export to send a copytool req to */ down_read(&cdt->cdt_agent_lock); - cfs_list_for_each_entry_safe(ha, tmp, &cdt->cdt_agents, ha_list) { + list_for_each_entry(ha, &cdt->cdt_agents, ha_list) { for (i = 0; (i < ha->ha_archive_cnt) && (ha->ha_archive_id[i] != archive); i++) { /* nothing to do, just skip unmatching records */ } /* archive count == 0 means copy tool serves any backend */ - if ((ha->ha_archive_cnt != 0) && (i == ha->ha_archive_cnt)) + if (ha->ha_archive_cnt != 0 && i == ha->ha_archive_cnt) continue; - if ((load == -1) || - (load > atomic_read(&ha->ha_requests))) { + if (load == -1 || load > atomic_read(&ha->ha_requests)) { load = atomic_read(&ha->ha_requests); *uuid = ha->ha_uuid; rc = 0; @@ -361,20 +358,20 @@ int mdt_hsm_agent_send(struct mdt_thread_info *mti, /* Check if request is still valid (cf file hsm flags) */ fail_request = false; - hai = hai_zero(hal); + hai = hai_first(hal); for (i = 0; i < hal->hal_count; i++, hai = hai_next(hai)) { if (hai->hai_action != HSMA_CANCEL) { struct mdt_object *obj; struct md_hsm hsm; obj = mdt_hsm_get_md_hsm(mti, &hai->hai_fid, &hsm); - if (!IS_ERR(obj)) { + if (!IS_ERR(obj) && obj != NULL) { mdt_object_put(mti->mti_env, obj); } else { if (hai->hai_action == HSMA_REMOVE) continue; - if (PTR_ERR(obj) == -ENOENT) { + if (obj == NULL) { fail_request = true; rc = mdt_agent_record_update( mti->mti_env, mdt, @@ -383,10 +380,10 @@ int mdt_hsm_agent_send(struct mdt_thread_info *mti, if (rc) { CERROR( "%s: mdt_agent_record_update() " - "failed, rc=%d, cannot update " + "failed, cannot update " "status to %s for cookie " LPX64": rc = %d\n", - mdt_obd_name(mdt), rc, + mdt_obd_name(mdt), agent_req_status2name(ARS_FAILED), hai->hai_cookie, rc); GOTO(out_buf, rc); @@ -396,7 +393,6 @@ int mdt_hsm_agent_send(struct mdt_thread_info *mti, GOTO(out_buf, rc = PTR_ERR(obj)); } - if (!mdt_hsm_is_action_compat(hai, hal->hal_archive_id, hal->hal_flags, &hsm)) { /* incompatible request, we abort the request */ @@ -409,10 +405,10 @@ int mdt_hsm_agent_send(struct mdt_thread_info *mti, 1, ARS_FAILED); if (rc) { CERROR("%s: mdt_agent_record_update() " - "failed, rc=%d, cannot update " + "failed, cannot update " "status to %s for cookie " LPX64": rc = %d\n", - mdt_obd_name(mdt), rc, + mdt_obd_name(mdt), agent_req_status2name(ARS_FAILED), hai->hai_cookie, rc); GOTO(out_buf, rc); @@ -449,7 +445,7 @@ int mdt_hsm_agent_send(struct mdt_thread_info *mti, * from a server (MDT) to a client (MDC), backwards of normal comms. */ exp = cfs_hash_lookup(mdt2obd_dev(mdt)->obd_uuid_hash, &uuid); - if ((exp == NULL) || (exp->exp_disconnected)) { + if (exp == NULL || exp->exp_disconnected) { /* This should clean up agents on evicted exports */ rc = -ENOENT; CERROR("%s: agent uuid (%s) not found, unregistering:" @@ -481,7 +477,7 @@ int mdt_hsm_agent_send(struct mdt_thread_info *mti, out: if (rc != 0 && is_registered) { /* in case of error, we have to unregister requests */ - hai = hai_zero(hal); + hai = hai_first(hal); for (i = 0; i < hal->hal_count; i++, hai = hai_next(hai)) { if (hai->hai_action == HSMA_CANCEL) continue; @@ -522,20 +518,20 @@ static void *mdt_hsm_agent_proc_start(struct seq_file *s, loff_t *off) { struct mdt_device *mdt = s->private; struct coordinator *cdt = &mdt->mdt_coordinator; - cfs_list_t *pos; + struct list_head *pos; loff_t i; ENTRY; down_read(&cdt->cdt_agent_lock); - if (cfs_list_empty(&cdt->cdt_agents)) + if (list_empty(&cdt->cdt_agents)) RETURN(NULL); if (*off == 0) RETURN(SEQ_START_TOKEN); i = 0; - cfs_list_for_each(pos, &cdt->cdt_agents) { + list_for_each(pos, &cdt->cdt_agents) { i++; if (i >= *off) RETURN(pos); @@ -552,7 +548,7 @@ static void *mdt_hsm_agent_proc_next(struct seq_file *s, void *v, loff_t *p) { struct mdt_device *mdt = s->private; struct coordinator *cdt = &mdt->mdt_coordinator; - cfs_list_t *pos = v; + struct list_head *pos = v; ENTRY; if (pos == SEQ_START_TOKEN) @@ -571,7 +567,7 @@ static void *mdt_hsm_agent_proc_next(struct seq_file *s, void *v, loff_t *p) */ static int mdt_hsm_agent_proc_show(struct seq_file *s, void *v) { - cfs_list_t *pos = v; + struct list_head *pos = v; struct hsm_agent *ha; int i; ENTRY; @@ -579,7 +575,7 @@ static int mdt_hsm_agent_proc_show(struct seq_file *s, void *v) if (pos == SEQ_START_TOKEN) RETURN(0); - ha = cfs_list_entry(pos, struct hsm_agent, ha_list); + ha = list_entry(pos, struct hsm_agent, ha_list); seq_printf(s, "uuid=%s archive#=%d (", ha->ha_uuid.uuid, ha->ha_archive_cnt); if (ha->ha_archive_cnt == 0) diff --git a/lustre/mdt/mdt_hsm_cdt_client.c b/lustre/mdt/mdt_hsm_cdt_client.c index b47acea..8264070 100644 --- a/lustre/mdt/mdt_hsm_cdt_client.c +++ b/lustre/mdt/mdt_hsm_cdt_client.c @@ -77,12 +77,12 @@ static int hsm_find_compatible_cb(const struct lu_env *env, hcdcb = data; /* a compatible request must be WAITING or STARTED * and not a cancel */ - if (((larr->arr_status != ARS_WAITING) && - (larr->arr_status != ARS_STARTED)) || - (larr->arr_hai.hai_action == HSMA_CANCEL)) + if ((larr->arr_status != ARS_WAITING && + larr->arr_status != ARS_STARTED) || + larr->arr_hai.hai_action == HSMA_CANCEL) RETURN(0); - hai = hai_zero(hcdcb->hal); + hai = hai_first(hcdcb->hal); for (i = 0; i < hcdcb->hal->hal_count; i++, hai = hai_next(hai)) { /* if request is a CANCEL: * if cookie set in the request, there is no need to find a @@ -92,7 +92,7 @@ static int hsm_find_compatible_cb(const struct lu_env *env, * if the caller sets the cookie, we assume he also sets the * arr_archive_id */ - if ((hai->hai_action == HSMA_CANCEL) && (hai->hai_cookie != 0)) + if (hai->hai_action == HSMA_CANCEL && hai->hai_cookie != 0) continue; if (!lu_fid_eq(&hai->hai_fid, &larr->arr_hai.hai_fid)) @@ -110,8 +110,8 @@ static int hsm_find_compatible_cb(const struct lu_env *env, */ hai->hai_cookie = larr->arr_hai.hai_cookie; /* we read the archive number from the request we cancel */ - if ((hai->hai_action == HSMA_CANCEL) && - (hcdcb->hal->hal_archive_id == 0)) + if (hai->hai_action == HSMA_CANCEL && + hcdcb->hal->hal_archive_id == 0) hcdcb->hal->hal_archive_id = larr->arr_archive_id; } RETURN(0); @@ -136,13 +136,13 @@ static int hsm_find_compatible(const struct lu_env *env, struct mdt_device *mdt, ENTRY; ok_cnt = 0; - hai = hai_zero(hal); + hai = hai_first(hal); for (i = 0; i < hal->hal_count; i++, hai = hai_next(hai)) { /* in a cancel request hai_cookie may be set by caller to * show the request to be canceled * if not we need to search by FID */ - if ((hai->hai_action == HSMA_CANCEL) && (hai->hai_cookie != 0)) + if (hai->hai_action == HSMA_CANCEL && hai->hai_cookie != 0) ok_cnt++; else hai->hai_cookie = 0; @@ -181,7 +181,7 @@ static bool hsm_action_is_needed(struct hsm_action_item *hai, int hal_an, hsm_flags = hsm->mh_flags; switch (hai->hai_action) { case HSMA_ARCHIVE: - if ((hsm_flags & HS_DIRTY) || !(hsm_flags & HS_ARCHIVED)) + if (hsm_flags & HS_DIRTY || !(hsm_flags & HS_ARCHIVED)) is_needed = true; break; case HSMA_RESTORE: @@ -227,7 +227,7 @@ static bool hal_is_sane(struct hsm_action_list *hal) if (hal->hal_count == 0) RETURN(false); - hai = hai_zero(hal); + hai = hai_first(hal); for (i = 0; i < hal->hal_count; i++, hai = hai_next(hai)) { if (!fid_is_sane(&hai->hai_fid)) RETURN(false); @@ -277,7 +277,7 @@ int mdt_hsm_add_actions(struct mdt_thread_info *mti, if (!hal_is_sane(hal)) RETURN(-EINVAL); - *compound_id = cfs_atomic_inc_return(&cdt->cdt_compound_id); + *compound_id = atomic_inc_return(&cdt->cdt_compound_id); /* search for compatible request, if found hai_cookie is set * to the request cookie @@ -287,7 +287,7 @@ int mdt_hsm_add_actions(struct mdt_thread_info *mti, if (rc) GOTO(out, rc); - hai = hai_zero(hal); + hai = hai_first(hal); for (i = 0; i < hal->hal_count; i++, hai = hai_next(hai)) { int archive_id; __u64 flags; @@ -310,10 +310,10 @@ int mdt_hsm_add_actions(struct mdt_thread_info *mti, * do not record */ /* redundant case */ - if ((hai->hai_action != HSMA_CANCEL) && (hai->hai_cookie != 0)) + if (hai->hai_action != HSMA_CANCEL && hai->hai_cookie != 0) continue; /* cancel nothing case */ - if ((hai->hai_action == HSMA_CANCEL) && (hai->hai_cookie == 0)) + if (hai->hai_action == HSMA_CANCEL && hai->hai_cookie == 0) continue; /* new request or cancel request @@ -327,11 +327,13 @@ int mdt_hsm_add_actions(struct mdt_thread_info *mti, /* get HSM attributes */ obj = mdt_hsm_get_md_hsm(mti, &hai->hai_fid, &mh); - if (IS_ERR(obj)) { + if (IS_ERR(obj) || obj == NULL) { /* in case of archive remove, Lustre file * is not mandatory */ if (hai->hai_action == HSMA_REMOVE) goto record; + if (obj == NULL) + GOTO(out, rc = -ENOENT); GOTO(out, rc = PTR_ERR(obj)); } mdt_object_put(mti->mti_env, obj); @@ -356,8 +358,7 @@ int mdt_hsm_add_actions(struct mdt_thread_info *mti, * warranty an agent can serve any combinaison of archive * backend */ - if ((hai->hai_action != HSMA_CANCEL) && - (archive_id == 0)) + if (hai->hai_action != HSMA_CANCEL && archive_id == 0) archive_id = mh.mh_arch_id; /* if restore, take an exclusive lock on layout */ @@ -396,8 +397,7 @@ int mdt_hsm_add_actions(struct mdt_thread_info *mti, mdt_object_put(mti->mti_env, child); mutex_lock(&cdt->cdt_restore_lock); - cfs_list_add_tail(&crh->crh_list, - &cdt->cdt_restore_hdl); + list_add_tail(&crh->crh_list, &cdt->cdt_restore_hdl); mutex_unlock(&cdt->cdt_restore_lock); } record: @@ -416,7 +416,7 @@ record: GOTO(out, rc); out: /* if work has been added, wake up coordinator */ - if ((rc == 0) || (rc == -ENODATA)) + if (rc == 0 || rc == -ENODATA) mdt_hsm_cdt_wakeup(mdt); return rc; @@ -438,7 +438,7 @@ int mdt_hsm_get_running(struct mdt_thread_info *mti, int i; ENTRY; - hai = hai_zero(hal); + hai = hai_first(hal); for (i = 0; i < hal->hal_count; i++, hai = hai_next(hai)) { struct cdt_agent_req *car; @@ -471,7 +471,6 @@ bool mdt_hsm_restore_is_running(struct mdt_thread_info *mti, { struct mdt_device *mdt = mti->mti_mdt; struct coordinator *cdt = &mdt->mdt_coordinator; - cfs_list_t *pos, *tmp; struct cdt_restore_handle *crh; bool rc = false; ENTRY; @@ -480,8 +479,7 @@ bool mdt_hsm_restore_is_running(struct mdt_thread_info *mti, RETURN(rc); mutex_lock(&cdt->cdt_restore_lock); - cfs_list_for_each_safe(pos, tmp, &cdt->cdt_restore_hdl) { - crh = cfs_list_entry(pos, struct cdt_restore_handle, crh_list); + list_for_each_entry(crh, &cdt->cdt_restore_hdl, crh_list) { if (lu_fid_eq(&crh->crh_fid, fid)) { rc = true; break; @@ -507,7 +505,7 @@ int mdt_hsm_get_actions(struct mdt_thread_info *mti, int i, rc; ENTRY; - hai = hai_zero(hal); + hai = hai_first(hal); for (i = 0; i < hal->hal_count; i++, hai = hai_next(hai)) { hai->hai_action = HSMA_NONE; if (!fid_is_sane(&hai->hai_fid)) @@ -530,7 +528,7 @@ int mdt_hsm_get_actions(struct mdt_thread_info *mti, * we may want do give back dynamic informations on the * running request */ - hai = hai_zero(hal); + hai = hai_first(hal); for (i = 0; i < hal->hal_count; i++, hai = hai_next(hai)) { struct cdt_agent_req *car; diff --git a/lustre/mdt/mdt_hsm_cdt_requests.c b/lustre/mdt/mdt_hsm_cdt_requests.c index 7029827..f36e500 100644 --- a/lustre/mdt/mdt_hsm_cdt_requests.c +++ b/lustre/mdt/mdt_hsm_cdt_requests.c @@ -46,13 +46,10 @@ */ void dump_requests(char *prefix, struct coordinator *cdt) { - cfs_list_t *pos; struct cdt_agent_req *car; down_read(&cdt->cdt_request_lock); - cfs_list_for_each(pos, &cdt->cdt_requests) { - car = cfs_list_entry(pos, struct cdt_agent_req, - car_request_list); + list_for_each_entry(car, &cdt->cdt_requests, car_request_list) { CDEBUG(D_HSM, "%s fid="DFID" dfid="DFID " compound/cookie="LPX64"/"LPX64 " action=%s archive#=%d flags="LPX64 @@ -66,7 +63,7 @@ void dump_requests(char *prefix, struct coordinator *cdt) car->car_hai->hai_extent.offset, car->car_hai->hai_extent.length, car->car_hai->hai_gid, - cfs_atomic_read(&car->car_refcount), + atomic_read(&car->car_refcount), car->car_canceled); } up_read(&cdt->cdt_request_lock); @@ -243,7 +240,7 @@ struct cdt_agent_req *mdt_cdt_alloc_request(__u64 compound_id, __u32 archive_id, if (car == NULL) RETURN(ERR_PTR(-ENOMEM)); - cfs_atomic_set(&car->car_refcount, 1); + atomic_set(&car->car_refcount, 1); car->car_compound_id = compound_id; car->car_archive_id = archive_id; car->car_flags = flags; @@ -280,7 +277,7 @@ void mdt_cdt_free_request(struct cdt_agent_req *car) */ void mdt_cdt_get_request(struct cdt_agent_req *car) { - cfs_atomic_inc(&car->car_refcount); + atomic_inc(&car->car_refcount); } /** @@ -290,8 +287,8 @@ void mdt_cdt_get_request(struct cdt_agent_req *car) */ void mdt_cdt_put_request(struct cdt_agent_req *car) { - LASSERT(cfs_atomic_read(&car->car_refcount) > 0); - if (cfs_atomic_dec_and_test(&car->car_refcount)) + LASSERT(atomic_read(&car->car_refcount) > 0); + if (atomic_dec_and_test(&car->car_refcount)) mdt_cdt_free_request(car); } @@ -301,7 +298,7 @@ void mdt_cdt_put_request(struct cdt_agent_req *car) * \param cdt [IN] coordinator * \param cookie [IN] request cookie * \param fid [IN] fid - * \retval request pointer + * \retval request pointer or NULL if not found */ static struct cdt_agent_req *cdt_find_request_nolock(struct coordinator *cdt, __u64 cookie, @@ -311,9 +308,9 @@ static struct cdt_agent_req *cdt_find_request_nolock(struct coordinator *cdt, struct cdt_agent_req *found = NULL; ENTRY; - cfs_list_for_each_entry(car, &cdt->cdt_requests, car_request_list) { - if ((car->car_hai->hai_cookie == cookie) || - ((fid != NULL) && lu_fid_eq(fid, &car->car_hai->hai_fid))) { + list_for_each_entry(car, &cdt->cdt_requests, car_request_list) { + if (car->car_hai->hai_cookie == cookie || + (fid != NULL && lu_fid_eq(fid, &car->car_hai->hai_fid))) { mdt_cdt_get_request(car); found = car; break; @@ -346,7 +343,7 @@ int mdt_cdt_add_request(struct coordinator *cdt, struct cdt_agent_req *new_car) RETURN(-EEXIST); } - cfs_list_add_tail(&new_car->car_request_list, &cdt->cdt_requests); + list_add_tail(&new_car->car_request_list, &cdt->cdt_requests); up_write(&cdt->cdt_request_lock); mdt_hsm_agent_update_statistics(cdt, 0, 0, 1, &new_car->car_uuid); @@ -361,7 +358,7 @@ int mdt_cdt_add_request(struct coordinator *cdt, struct cdt_agent_req *new_car) * \param cdt [IN] coordinator * \param cookie [IN] request cookie * \param fid [IN] fid - * \retval request pointer + * \retval request pointer or NULL if not found */ struct cdt_agent_req *mdt_cdt_find_request(struct coordinator *cdt, const __u64 cookie, @@ -391,7 +388,7 @@ int mdt_cdt_remove_request(struct coordinator *cdt, __u64 cookie) down_write(&cdt->cdt_request_lock); car = cdt_find_request_nolock(cdt, cookie, NULL); if (car != NULL) { - cfs_list_del(&car->car_request_list); + list_del(&car->car_request_list); up_write(&cdt->cdt_request_lock); /* reference from cdt_requests list */ @@ -400,7 +397,7 @@ int mdt_cdt_remove_request(struct coordinator *cdt, __u64 cookie) /* reference from cdt_find_request_nolock() */ mdt_cdt_put_request(car); - LASSERT(atomic_read(&cdt->cdt_request_count) > 0); + LASSERT(atomic_read(&cdt->cdt_request_count) >= 1); atomic_dec(&cdt->cdt_request_count); RETURN(0); @@ -458,20 +455,20 @@ static void *mdt_hsm_request_proc_start(struct seq_file *s, loff_t *p) { struct mdt_device *mdt = s->private; struct coordinator *cdt = &mdt->mdt_coordinator; - cfs_list_t *pos; + struct list_head *pos; loff_t i; ENTRY; down_read(&cdt->cdt_request_lock); - if (cfs_list_empty(&cdt->cdt_requests)) + if (list_empty(&cdt->cdt_requests)) RETURN(NULL); if (*p == 0) RETURN(SEQ_START_TOKEN); i = 0; - cfs_list_for_each(pos, &cdt->cdt_requests) { + list_for_each(pos, &cdt->cdt_requests) { i++; if (i >= *p) RETURN(pos); @@ -487,7 +484,7 @@ static void *mdt_hsm_request_proc_next(struct seq_file *s, void *v, loff_t *p) { struct mdt_device *mdt = s->private; struct coordinator *cdt = &mdt->mdt_coordinator; - cfs_list_t *pos = v; + struct list_head *pos = v; ENTRY; if (pos == SEQ_START_TOKEN) @@ -507,7 +504,7 @@ static void *mdt_hsm_request_proc_next(struct seq_file *s, void *v, loff_t *p) */ static int mdt_hsm_request_proc_show(struct seq_file *s, void *v) { - cfs_list_t *pos = v; + struct list_head *pos = v; struct cdt_agent_req *car; char buf[12]; __u64 data_moved; @@ -516,7 +513,7 @@ static int mdt_hsm_request_proc_show(struct seq_file *s, void *v) if (pos == SEQ_START_TOKEN) RETURN(0); - car = cfs_list_entry(pos, struct cdt_agent_req, car_request_list); + car = list_entry(pos, struct cdt_agent_req, car_request_list); mdt_cdt_get_work_done(car, &data_moved); seq_printf(s, "fid="DFID" dfid="DFID diff --git a/lustre/mdt/mdt_internal.h b/lustre/mdt/mdt_internal.h index 3eb82ae..86805bc 100644 --- a/lustre/mdt/mdt_internal.h +++ b/lustre/mdt/mdt_internal.h @@ -129,11 +129,11 @@ struct coordinator { * requests */ atomic_t cdt_request_count; /**< current count of * started requests */ - cfs_list_t cdt_requests; /**< list of started + struct list_head cdt_requests; /**< list of started * requests */ - cfs_list_t cdt_agents; /**< list of register + struct list_head cdt_agents; /**< list of register * agents */ - cfs_list_t cdt_restore_hdl; /**< list of restore lock + struct list_head cdt_restore_hdl; /**< list of restore lock * handles */ }; @@ -577,7 +577,7 @@ struct cdt_req_progress { struct cdt_agent_req { cfs_list_t car_request_list; /**< to chain all the req. */ - cfs_atomic_t car_refcount; /**< reference counter */ + atomic_t car_refcount; /**< reference counter */ __u64 car_compound_id; /**< compound id */ __u64 car_flags; /**< request original flags */ struct obd_uuid car_uuid; /**< agent doing the req. */ @@ -597,10 +597,10 @@ struct hsm_agent { __u32 *ha_archive_id; /**< archive id */ int ha_archive_cnt; /**< number of archive entries * 0 means any archive */ - cfs_atomic_t ha_requests; /**< current request count */ - cfs_atomic_t ha_success; /**< number of successful + atomic_t ha_requests; /**< current request count */ + atomic_t ha_success; /**< number of successful * actions */ - cfs_atomic_t ha_failure; /**< number of failed actions */ + atomic_t ha_failure; /**< number of failed actions */ }; struct cdt_restore_handle { diff --git a/lustre/utils/lhsmtool_posix.c b/lustre/utils/lhsmtool_posix.c index 8b7c426..269a077 100644 --- a/lustre/utils/lhsmtool_posix.c +++ b/lustre/utils/lhsmtool_posix.c @@ -1737,7 +1737,7 @@ static int ct_daemon(void) continue; } - hai = hai_zero(hal); + hai = hai_first(hal); while (++i <= hal->hal_count) { if ((char *)hai - (char *)hal > msgsize) { CT_ERROR("'%s' item %d past end of message!\n", -- 1.8.3.1