From: John L. Hammond Date: Tue, 1 Apr 2014 16:34:55 +0000 (-0500) Subject: LU-2675 mdt: refactor mdt_getattr_name_lock() X-Git-Tag: 2.5.58~2 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=1a937b36bb212eb720d504f124d9b135975892d6 LU-2675 mdt: refactor mdt_getattr_name_lock() In mdt_getattr_name_lock(), concentrate the cross reference handling code into one block. Remove assertions about the remoteness of parent. Remove some set but unused local variables in mdt_handler.c. Declare functions static where possible. Remove the unused structures mdt_handler and mdt_opc_slice. Signed-off-by: John L. Hammond Change-Id: I3468e200130259cf7c760bb080c1bdff9e03fd8e Reviewed-on: http://review.whamcloud.com/9861 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Fan Yong Reviewed-by: Mike Pershin Reviewed-by: Oleg Drokin --- diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index fa70517..329c5fc 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -262,7 +262,7 @@ static void mdt_lock_pdo_mode(struct mdt_thread_info *info, struct mdt_object *o EXIT; } -int mdt_getstatus(struct tgt_session_info *tsi) +static int mdt_getstatus(struct tgt_session_info *tsi) { struct mdt_thread_info *info = tsi2mdt_info(tsi); struct mdt_device *mdt = info->mti_mdt; @@ -306,7 +306,7 @@ out: return rc; } -int mdt_statfs(struct tgt_session_info *tsi) +static int mdt_statfs(struct tgt_session_info *tsi) { struct ptlrpc_request *req = tgt_ses_req(tsi); struct mdt_thread_info *info = tsi2mdt_info(tsi); @@ -617,8 +617,8 @@ int mdt_stripe_get(struct mdt_thread_info *info, struct mdt_object *o, return rc; } -int mdt_attr_get_pfid(struct mdt_thread_info *info, - struct mdt_object *o, struct lu_fid *pfid) +static int mdt_attr_get_pfid(struct mdt_thread_info *info, + struct mdt_object *o, struct lu_fid *pfid) { struct lu_buf *buf = &info->mti_buf; struct link_ea_header *leh; @@ -1054,14 +1054,13 @@ static int mdt_renew_capa(struct mdt_thread_info *info) RETURN(rc); } -int mdt_getattr(struct tgt_session_info *tsi) +static int mdt_getattr(struct tgt_session_info *tsi) { struct mdt_thread_info *info = tsi2mdt_info(tsi); struct mdt_object *obj = info->mti_object; struct req_capsule *pill = info->mti_pill; struct mdt_body *reqbody; struct mdt_body *repbody; - mode_t mode; int rc, rc2; ENTRY; @@ -1079,8 +1078,6 @@ int mdt_getattr(struct tgt_session_info *tsi) LASSERT(obj != NULL); LASSERT(lu_object_assert_exists(&obj->mot_obj)); - mode = lu_object_attr(&obj->mot_obj); - /* Readlink */ if (reqbody->valid & OBD_MD_LINKNAME) { /* No easy way to know how long is the symlink, but it cannot @@ -1147,7 +1144,7 @@ out: return rc; } -int mdt_is_subdir(struct tgt_session_info *tsi) +static int mdt_is_subdir(struct tgt_session_info *tsi) { struct mdt_thread_info *info = tsi2mdt_info(tsi); struct mdt_object *o = info->mti_object; @@ -1176,7 +1173,7 @@ int mdt_is_subdir(struct tgt_session_info *tsi) RETURN(rc); } -int mdt_swap_layouts(struct tgt_session_info *tsi) +static int mdt_swap_layouts(struct tgt_session_info *tsi) { struct mdt_thread_info *info; struct ptlrpc_request *req = tgt_ses_req(tsi); @@ -1333,88 +1330,36 @@ static int mdt_getattr_name_lock(struct mdt_thread_info *info, struct lu_name *lname = NULL; struct mdt_lock_handle *lhp = NULL; struct ldlm_lock *lock; - struct ldlm_res_id *res_id; - int is_resent; - int ma_need = 0; - int rc; - - ENTRY; - - is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh); - LASSERT(ergo(is_resent, - lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT)); + bool is_resent; + bool try_layout; + int ma_need = 0; + int rc; + ENTRY; - LASSERT(parent != NULL); + is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh); + LASSERT(ergo(is_resent, + lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT)); - lname = &info->mti_name; - mdt_name_unpack(info->mti_pill, &RMF_NAME, lname, MNF_FIX_ANON); + LASSERT(parent != NULL); - if (!info->mti_cross_ref) { - /* - * XXX: Check for anonymous name is for getattr by fid - * (OBD_CONNECT_ATTRFID), otherwise do not allow empty name, - * that is the name must contain at least one character and - * the terminating '\0'. - */ - if (!lu_name_is_valid(lname)) { - reqbody = req_capsule_client_get(info->mti_pill, - &RMF_MDT_BODY); - if (unlikely(reqbody == NULL)) - RETURN(err_serious(-EFAULT)); - - if (unlikely(!fid_is_sane(&reqbody->fid2))) - RETURN(err_serious(-EINVAL)); - - CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", " - "ldlm_rep = %p\n", - PFID(mdt_object_fid(parent)), - PFID(&reqbody->fid2), ldlm_rep); + if (info->mti_cross_ref) { + /* Only getattr on the child. Parent is on another node. */ + mdt_set_disposition(info, ldlm_rep, + DISP_LOOKUP_EXECD | DISP_LOOKUP_POS); + child = parent; + CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", " + "ldlm_rep = %p\n", + PFID(mdt_object_fid(child)), ldlm_rep); + + if (is_resent) { + /* Do not take lock for resent case. */ + lock = ldlm_handle2lock(&lhc->mlh_reg_lh); + LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n", + lhc->mlh_reg_lh.cookie); + LASSERT(fid_res_name_eq(mdt_object_fid(child), + &lock->l_resource->lr_name)); + LDLM_LOCK_PUT(lock); } else { - CDEBUG(D_INODE, "getattr with lock for "DFID"/"DNAME", " - "ldlm_rep = %p\n", PFID(mdt_object_fid(parent)), - PNAME(lname), ldlm_rep); - } - } - - mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD); - - if (unlikely(!mdt_object_exists(parent)) && lu_name_is_valid(lname)) { - LU_OBJECT_DEBUG(D_INODE, info->mti_env, - &parent->mot_obj, - "Parent doesn't exist!\n"); - RETURN(-ESTALE); - } else if (!info->mti_cross_ref) { - LASSERTF(!mdt_object_remote(parent), - "Parent "DFID" is on remote server\n", - PFID(mdt_object_fid(parent))); - } - - if (lu_name_is_valid(lname)) { - rc = mdt_raw_lookup(info, parent, lname, ldlm_rep); - if (rc != 0) { - if (rc > 0) - rc = 0; - RETURN(rc); - } - } - - if (info->mti_cross_ref) { - /* Only getattr on the child. Parent is on another node. */ - mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS); - child = parent; - CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", " - "ldlm_rep=%p\n", PFID(mdt_object_fid(child)), ldlm_rep); - - if (is_resent) { - /* Do not take lock for resent case. */ - lock = ldlm_handle2lock(&lhc->mlh_reg_lh); - LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n", - lhc->mlh_reg_lh.cookie); - LASSERT(fid_res_name_eq(mdt_object_fid(child), - &lock->l_resource->lr_name)); - LDLM_LOCK_PUT(lock); - rc = 0; - } else { mdt_lock_handle_init(lhc); mdt_lock_reg_init(lhc, LCK_PR); @@ -1428,27 +1373,74 @@ static int mdt_getattr_name_lock(struct mdt_thread_info *info, rc = mdt_object_lock(info, child, lhc, child_bits, MDT_LOCAL_LOCK); + if (rc < 0) + RETURN(rc); } - if (rc == 0) { - /* Finally, we can get attr for child. */ - if (!mdt_object_exists(child)) { - LU_OBJECT_DEBUG(D_INFO, info->mti_env, - &child->mot_obj, - "remote object doesn't exist.\n"); - mdt_object_unlock(info, child, lhc, 1); - RETURN(-ENOENT); - } - mdt_set_capainfo(info, 0, mdt_object_fid(child), - BYPASS_CAPA); - rc = mdt_getattr_internal(info, child, 0); - if (unlikely(rc != 0)) - mdt_object_unlock(info, child, lhc, 1); - } + /* Finally, we can get attr for child. */ + if (!mdt_object_exists(child)) { + LU_OBJECT_DEBUG(D_INFO, info->mti_env, + &child->mot_obj, + "remote object doesn't exist.\n"); + mdt_object_unlock(info, child, lhc, 1); + RETURN(-ENOENT); + } + + mdt_set_capainfo(info, 0, mdt_object_fid(child), BYPASS_CAPA); + rc = mdt_getattr_internal(info, child, 0); + if (unlikely(rc != 0)) + mdt_object_unlock(info, child, lhc, 1); + RETURN(rc); } + lname = &info->mti_name; + mdt_name_unpack(info->mti_pill, &RMF_NAME, lname, MNF_FIX_ANON); + + if (lu_name_is_valid(lname)) { + CDEBUG(D_INODE, "getattr with lock for "DFID"/"DNAME", " + "ldlm_rep = %p\n", PFID(mdt_object_fid(parent)), + PNAME(lname), ldlm_rep); + } else { + reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY); + if (unlikely(reqbody == NULL)) + RETURN(err_serious(-EPROTO)); + + *child_fid = reqbody->fid2; + + if (unlikely(!fid_is_sane(child_fid))) + RETURN(err_serious(-EINVAL)); + + CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", " + "ldlm_rep = %p\n", + PFID(mdt_object_fid(parent)), + PFID(&reqbody->fid2), ldlm_rep); + } + + mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD); + + if (unlikely(!mdt_object_exists(parent)) && lu_name_is_valid(lname)) { + LU_OBJECT_DEBUG(D_INODE, info->mti_env, + &parent->mot_obj, + "Parent doesn't exist!\n"); + RETURN(-ESTALE); + } + + if (mdt_object_remote(parent)) { + CERROR("%s: parent "DFID" is on remote target\n", + mdt_obd_name(info->mti_mdt), + PFID(mdt_object_fid(parent))); + RETURN(-EIO); + } + if (lu_name_is_valid(lname)) { + rc = mdt_raw_lookup(info, parent, lname, ldlm_rep); + if (rc != 0) { + if (rc > 0) + rc = 0; + RETURN(rc); + } + /* step 1: lock parent only if parent is a directory */ if (S_ISDIR(lu_object_attr(&parent->mot_obj))) { lhp = &info->mti_lh[MDT_LH_PARENT]; @@ -1464,18 +1456,14 @@ static int mdt_getattr_name_lock(struct mdt_thread_info *info, fid_zero(child_fid); rc = mdo_lookup(info->mti_env, next, lname, child_fid, &info->mti_spec); + if (rc == -ENOENT) + mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG); - if (rc != 0) { - if (rc == -ENOENT) - mdt_set_disposition(info, ldlm_rep, - DISP_LOOKUP_NEG); - GOTO(out_parent, rc); - } else - mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS); - } else { - *child_fid = reqbody->fid2; - mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS); - } + if (rc != 0) + GOTO(out_parent, rc); + } + + mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS); /* *step 3: find the child object by fid & lock it. @@ -1502,7 +1490,6 @@ static int mdt_getattr_name_lock(struct mdt_thread_info *info, LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n", lhc->mlh_reg_lh.cookie); - res_id = &lock->l_resource->lr_name; if (!fid_res_name_eq(mdt_object_fid(child), &lock->l_resource->lr_name)) { LASSERTF(fid_res_name_eq(mdt_object_fid(parent), @@ -1519,14 +1506,12 @@ static int mdt_getattr_name_lock(struct mdt_thread_info *info, GOTO(relock, 0); } LDLM_LOCK_PUT(lock); - rc = 0; } else { - bool try_layout = false; - relock: OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RESEND, obd_timeout*2); mdt_lock_handle_init(lhc); mdt_lock_reg_init(lhc, LCK_PR); + try_layout = false; if (!mdt_object_exists(child)) { LU_OBJECT_DEBUG(D_INODE, info->mti_env, @@ -1608,7 +1593,6 @@ relock: mdt_object_unlock(info, child, lhc, 1); } else if (lock) { /* Debugging code. */ - res_id = &lock->l_resource->lr_name; LDLM_DEBUG(lock, "Returning lock to client"); LASSERTF(fid_res_name_eq(mdt_object_fid(child), &lock->l_resource->lr_name), @@ -1631,7 +1615,7 @@ out_parent: } /* normal handler: should release the child lock */ -int mdt_getattr_name(struct tgt_session_info *tsi) +static int mdt_getattr_name(struct tgt_session_info *tsi) { struct mdt_thread_info *info = tsi2mdt_info(tsi); struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_CHILD]; @@ -1672,7 +1656,7 @@ out_shrink: static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len, void *karg, void *uarg); -int mdt_set_info(struct tgt_session_info *tsi) +static int mdt_set_info(struct tgt_session_info *tsi) { struct ptlrpc_request *req = tgt_ses_req(tsi); char *key; @@ -1730,7 +1714,7 @@ int mdt_set_info(struct tgt_session_info *tsi) RETURN(rc); } -int mdt_readpage(struct tgt_session_info *tsi) +static int mdt_readpage(struct tgt_session_info *tsi) { struct mdt_thread_info *info = mdt_th_info(tsi->tsi_env); struct mdt_object *object = mdt_obj(tsi->tsi_corpus); @@ -1896,7 +1880,7 @@ static long mdt_reint_opcode(struct ptlrpc_request *req, return opc; } -int mdt_reint(struct tgt_session_info *tsi) +static int mdt_reint(struct tgt_session_info *tsi) { long opc; int rc; @@ -1960,7 +1944,7 @@ static int mdt_object_sync(struct mdt_thread_info *info) RETURN(rc); } -int mdt_sync(struct tgt_session_info *tsi) +static int mdt_sync(struct tgt_session_info *tsi) { struct ptlrpc_request *req = tgt_ses_req(tsi); struct req_capsule *pill = tsi->tsi_pill; @@ -2006,7 +1990,7 @@ int mdt_sync(struct tgt_session_info *tsi) * Handle quota control requests to consult current usage/limit, but also * to configure quota enforcement */ -int mdt_quotactl(struct tgt_session_info *tsi) +static int mdt_quotactl(struct tgt_session_info *tsi) { struct obd_export *exp = tsi->tsi_exp; struct req_capsule *pill = tsi->tsi_pill; @@ -2158,7 +2142,7 @@ static int mdt_llog_ctxt_unclone(const struct lu_env *env, /* * sec context handlers */ -int mdt_sec_ctx_handle(struct tgt_session_info *tsi) +static int mdt_sec_ctx_handle(struct tgt_session_info *tsi) { int rc; @@ -2180,7 +2164,7 @@ int mdt_sec_ctx_handle(struct tgt_session_info *tsi) /* * quota request handlers */ -int mdt_quota_dqacq(struct tgt_session_info *tsi) +static int mdt_quota_dqacq(struct tgt_session_info *tsi) { struct mdt_device *mdt = mdt_exp2dev(tsi->tsi_exp); struct lu_device *qmt = mdt->mdt_qmt_dev; @@ -2481,9 +2465,10 @@ static int mdt_object_local_lock(struct mdt_thread_info *info, RETURN(rc); } -int mdt_object_lock_internal(struct mdt_thread_info *info, struct mdt_object *o, - struct mdt_lock_handle *lh, __u64 ibits, - bool nonblock, int locality) +static int +mdt_object_lock_internal(struct mdt_thread_info *info, struct mdt_object *o, + struct mdt_lock_handle *lh, __u64 ibits, + bool nonblock, int locality) { int rc; ENTRY; @@ -2883,7 +2868,7 @@ struct mdt_thread_info *tsi2mdt_info(struct tgt_session_info *tsi) return mti; } -int mdt_tgt_connect(struct tgt_session_info *tsi) +static int mdt_tgt_connect(struct tgt_session_info *tsi) { struct ptlrpc_request *req = tgt_ses_req(tsi); int rc; @@ -3010,11 +2995,10 @@ static struct mdt_it_flavor { } }; -int mdt_intent_lock_replace(struct mdt_thread_info *info, - struct ldlm_lock **lockp, - struct ldlm_lock *new_lock, - struct mdt_lock_handle *lh, - __u64 flags) +static int +mdt_intent_lock_replace(struct mdt_thread_info *info, struct ldlm_lock **lockp, + struct ldlm_lock *new_lock, struct mdt_lock_handle *lh, + __u64 flags) { struct ptlrpc_request *req = mdt_info_req(info); struct ldlm_lock *lock = *lockp; @@ -3208,7 +3192,6 @@ static int mdt_intent_getattr(enum mdt_it_code opcode, struct ldlm_lock *new_lock = NULL; __u64 child_bits; struct ldlm_reply *ldlm_rep; - struct ptlrpc_request *req; struct mdt_body *reqbody; struct mdt_body *repbody; int rc, rc2; @@ -3241,7 +3224,6 @@ static int mdt_intent_getattr(enum mdt_it_code opcode, if (rc) GOTO(out_shrink, rc); - req = info->mti_pill->rc_req; ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP); mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD); @@ -3817,7 +3799,6 @@ static int mdt_fld_init(const struct lu_env *env, static void mdt_stack_pre_fini(const struct lu_env *env, struct mdt_device *m, struct lu_device *top) { - struct obd_device *obd; struct lustre_cfg_bufs *bufs; struct lustre_cfg *lcfg; struct mdt_thread_info *info; @@ -3832,7 +3813,6 @@ static void mdt_stack_pre_fini(const struct lu_env *env, LASSERT(m->mdt_child_exp); LASSERT(m->mdt_child_exp->exp_obd); - obd = m->mdt_child_exp->exp_obd; /* process cleanup, pass mdt obd name to get obd umount flags */ /* XXX: this is needed because all layers are referenced by @@ -4413,7 +4393,7 @@ static void mdt_fini(const struct lu_env *env, struct mdt_device *m) EXIT; } -int mdt_postrecov(const struct lu_env *, struct mdt_device *); +static int mdt_postrecov(const struct lu_env *, struct mdt_device *); static int mdt_init0(const struct lu_env *env, struct mdt_device *m, struct lu_device_type *ldt, struct lustre_cfg *cfg) @@ -5773,7 +5753,7 @@ static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len, RETURN(rc); } -int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt) +static int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt) { struct lu_device *ld = md2lu_dev(mdt->mdt_child); int rc; @@ -5783,7 +5763,7 @@ int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt) RETURN(rc); } -int mdt_obd_postrecov(struct obd_device *obd) +static int mdt_obd_postrecov(struct obd_device *obd) { struct lu_env env; int rc; diff --git a/lustre/mdt/mdt_internal.h b/lustre/mdt/mdt_internal.h index 6a19f9f..5b8cea1 100644 --- a/lustre/mdt/mdt_internal.h +++ b/lustre/mdt/mdt_internal.h @@ -474,31 +474,6 @@ static inline struct mdt_thread_info *mdt_th_info(const struct lu_env *env) return mti; } -/* ptlrpc request handler for MDT. All handlers are - * grouped into several slices - struct mdt_opc_slice, - * and stored in an array - mdt_handlers[]. - */ -struct mdt_handler { - /* The name of this handler. */ - const char *mh_name; - /* Fail id for this handler, checked at the beginning of this handler*/ - int mh_fail_id; - /* Operation code for this handler */ - __u32 mh_opc; - /* flags are listed in enum mdt_handler_flags below. */ - __u32 mh_flags; - /* The actual handler function to execute. */ - int (*mh_act)(struct mdt_thread_info *info); - /* Request format for this request. */ - const struct req_format *mh_fmt; -}; - -struct mdt_opc_slice { - __u32 mos_opc_start; - int mos_opc_end; - struct mdt_handler *mos_hs; -}; - struct cdt_req_progress { struct mutex crp_lock; /**< protect tree */ struct interval_node *crp_root; /**< tree to track extent diff --git a/lustre/target/out_handler.c b/lustre/target/out_handler.c index b7dfd58..40e5ce3 100644 --- a/lustre/target/out_handler.c +++ b/lustre/target/out_handler.c @@ -1254,7 +1254,6 @@ static int out_write(struct tgt_session_info *tsi) .th_version = 0, \ } -#define out_handler mdt_handler static struct tgt_handler out_update_ops[] = { DEF_OUT_HNDL(OUT_CREATE, "out_create", MUTABOR | HABEO_REFERO, out_create),