X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fmdt%2Fmdt_reint.c;h=3b005b144e4e6b415eab9a79ab13c2fb80b434f5;hb=342caced07fdaca95d5ab4091e947116738ef69a;hp=51f87c266bfe50206c8a3dfe8b37f6d6bdd61813;hpb=6869932b552ac705f411de3362f01bd50c1f6f7d;p=fs%2Flustre-release.git diff --git a/lustre/mdt/mdt_reint.c b/lustre/mdt/mdt_reint.c index 51f87c2..3b005b1 100644 --- a/lustre/mdt/mdt_reint.c +++ b/lustre/mdt/mdt_reint.c @@ -80,7 +80,8 @@ static int mdt_create_pack_capa(struct mdt_thread_info *info, int rc, if (repbody->valid & OBD_MD_FLMDSCAPA) RETURN(rc); - if (rc == 0 && info->mti_mdt->mdt_opts.mo_mds_capa) { + if (rc == 0 && info->mti_mdt->mdt_opts.mo_mds_capa && + info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) { struct lustre_capa *capa; capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA1); @@ -95,6 +96,51 @@ static int mdt_create_pack_capa(struct mdt_thread_info *info, int rc, RETURN(rc); } +int mdt_version_get_check(struct mdt_thread_info *info, int index) +{ + /** version recovery */ + struct md_object *mo; + struct ptlrpc_request *req = mdt_info_req(info); + __u64 curr_version, *pre_versions; + ENTRY; + + if (!exp_connect_vbr(req->rq_export)) + RETURN(0); + + LASSERT(info->mti_mos[index]); + LASSERT(mdt_object_exists(info->mti_mos[index])); + mo = mdt_object_child(info->mti_mos[index]); + + curr_version = mo_version_get(info->mti_env, mo); + CDEBUG(D_INODE, "Version is "LPX64"\n", curr_version); + /** VBR: version is checked always because costs nothing */ + if (lustre_msg_get_transno(req->rq_reqmsg) != 0) { + pre_versions = lustre_msg_get_versions(req->rq_reqmsg); + LASSERT(index < PTLRPC_NUM_VERSIONS); + /** Sanity check for malformed buffers */ + if (pre_versions == NULL) { + CERROR("No versions in request buffer\n"); + spin_lock(&req->rq_export->exp_lock); + req->rq_export->exp_vbr_failed = 1; + spin_unlock(&req->rq_export->exp_lock); + RETURN(-EOVERFLOW); + } else if (pre_versions[index] != curr_version) { + CDEBUG(D_INODE, "Version mismatch "LPX64" != "LPX64"\n", + pre_versions[index], curr_version); + spin_lock(&req->rq_export->exp_lock); + req->rq_export->exp_vbr_failed = 1; + spin_unlock(&req->rq_export->exp_lock); + RETURN(-EOVERFLOW); + } + } + /** save pre-versions in reply */ + LASSERT(req->rq_repmsg != NULL); + pre_versions = lustre_msg_get_versions(req->rq_repmsg); + if (pre_versions) + pre_versions[index] = curr_version; + RETURN(0); +} + static int mdt_md_create(struct mdt_thread_info *info) { struct mdt_device *mdt = info->mti_mdt; @@ -135,6 +181,12 @@ static int mdt_md_create(struct mdt_thread_info *info) mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom, OBD_FAIL_MDS_REINT_CREATE_WRITE); + info->mti_mos[0] = parent; + info->mti_mos[1] = child; + rc = mdt_version_get_check(info, 0); + if (rc) + GOTO(out_put_child, rc); + /* Let lower layer know current lock mode. */ info->mti_spec.sp_cr_mode = mdt_dlm_mode2mdl_mode(lh->mlh_pdo_mode); @@ -144,6 +196,7 @@ static int mdt_md_create(struct mdt_thread_info *info) * or not. */ info->mti_spec.sp_cr_lookup = 1; + info->mti_spec.sp_feat = &dt_directory_features; lname = mdt_name(info->mti_env, (char *)rr->rr_name, rr->rr_namelen); @@ -156,6 +209,7 @@ static int mdt_md_create(struct mdt_thread_info *info) mdt_pack_attr2body(info, repbody, &ma->ma_attr, mdt_object_fid(child)); } +out_put_child: mdt_object_put(info->mti_env, child); } else rc = PTR_ERR(child); @@ -225,13 +279,14 @@ int mdt_attr_set(struct mdt_thread_info *info, struct mdt_object *mo, int flags) struct md_attr *ma = &info->mti_attr; struct mdt_lock_handle *lh; int som_update = 0; + int do_vbr = ma->ma_attr.la_valid & (LA_MODE|LA_UID|LA_GID); int rc; ENTRY; /* attr shouldn't be set on remote object */ LASSERT(mdt_object_exists(mo) >= 0); - if (info->mti_epoch) + if (exp_connect_som(info->mti_exp) && info->mti_epoch) som_update = (info->mti_epoch->flags & MF_SOM_CHANGE); /* Try to avoid object_lock if another epoch has been started @@ -269,6 +324,14 @@ int mdt_attr_set(struct mdt_thread_info *info, struct mdt_object *mo, int flags) if (unlikely(ma->ma_attr.la_valid == LA_CTIME)) ma->ma_attr_flags |= MDS_VTX_BYPASS; + /* VBR: update version if attr changed are important for recovery */ + if (do_vbr) { + info->mti_mos[0] = mo; + rc = mdt_version_get_check(info, 0); + if (rc) + GOTO(out_unlock, rc); + } + /* all attrs are packed into mti_attr in unpack_setattr */ rc = mo_attr_set(info->mti_env, mdt_object_child(mo), ma); if (rc != 0) @@ -291,7 +354,6 @@ out_unlock: static int mdt_reint_setattr(struct mdt_thread_info *info, struct mdt_lock_handle *lhc) { - struct mdt_device *mdt = info->mti_mdt; struct md_attr *ma = &info->mti_attr; struct mdt_reint_record *rr = &info->mti_rr; struct ptlrpc_request *req = mdt_info_req(info); @@ -308,12 +370,13 @@ static int mdt_reint_setattr(struct mdt_thread_info *info, if (info->mti_dlm_req) ldlm_request_cancel(req, info->mti_dlm_req, 0); - + repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY); mo = mdt_object_find(info->mti_env, info->mti_mdt, rr->rr_fid1); if (IS_ERR(mo)) GOTO(out, rc = PTR_ERR(mo)); + /* start a log jounal handle if needed */ if (!(mdt_conn_flags(info) & OBD_CONNECT_SOM)) { if ((ma->ma_attr.la_valid & LA_SIZE) || (rr->rr_flags & MRF_SETATTR_LOCKED)) { @@ -387,7 +450,8 @@ static int mdt_reint_setattr(struct mdt_thread_info *info, mdt_pack_attr2body(info, repbody, &ma->ma_attr, mdt_object_fid(mo)); - if (mdt->mdt_opts.mo_oss_capa && + if (info->mti_mdt->mdt_opts.mo_oss_capa && + info->mti_exp->exp_connect_flags & OBD_CONNECT_OSS_CAPA && S_ISREG(lu_object_attr(&mo->mot_obj.mo_lu)) && (ma->ma_attr.la_valid & LA_SIZE)) { struct lustre_capa *capa; @@ -470,21 +534,36 @@ static int mdt_reint_unlink(struct mdt_thread_info *info, if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNLINK)) RETURN(err_serious(-ENOENT)); - /* step 1: lock the parent */ + /* + * step 1: lock the parent. Note, this may be child in case of + * remote operation denoted by ->mti_cross_ref flag. + */ parent_lh = &info->mti_lh[MDT_LH_PARENT]; - mdt_lock_pdo_init(parent_lh, LCK_PW, rr->rr_name, - rr->rr_namelen); - + if (info->mti_cross_ref) { + /* + * Init reg lock for cross ref case when we need to do only + * ref del locally. + */ + mdt_lock_reg_init(parent_lh, LCK_PW); + } else { + mdt_lock_pdo_init(parent_lh, LCK_PW, rr->rr_name, + rr->rr_namelen); + } mp = mdt_object_find_lock(info, rr->rr_fid1, parent_lh, MDS_INODELOCK_UPDATE); if (IS_ERR(mp)) { rc = PTR_ERR(mp); - /* errors are possible here in cross-ref cases, see below */ + /* errors are possible here in cross-ref cases, see below */ if (info->mti_cross_ref) rc = 0; GOTO(out, rc); } + info->mti_mos[0] = mp; + rc = mdt_version_get_check(info, 0); + if (rc) + GOTO(out_unlock_parent, rc); + mdt_reint_init_ma(info, ma); if (!ma->ma_lmm || !ma->ma_cookie) GOTO(out_unlock_parent, rc = -EINVAL); @@ -500,7 +579,8 @@ static int mdt_reint_unlink(struct mdt_thread_info *info, mdt_set_capainfo(info, 0, rr->rr_fid1, BYPASS_CAPA); rc = mo_ref_del(info->mti_env, mdt_object_child(mp), ma); - mdt_handle_last_unlink(info, mp, ma); + if (rc == 0) + mdt_handle_last_unlink(info, mp, ma); } else rc = 0; GOTO(out_unlock_parent, rc); @@ -529,6 +609,11 @@ static int mdt_reint_unlink(struct mdt_thread_info *info, mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom, OBD_FAIL_MDS_REINT_UNLINK_WRITE); + info->mti_mos[1] = mc; + rc = mdt_version_get_check(info, 1); + if (rc) + GOTO(out_unlock_child, rc); + /* * Now we can only make sure we need MA_INODE, in mdd layer, will check * whether need MA_LOV and MA_COOKIE. @@ -542,6 +627,7 @@ static int mdt_reint_unlink(struct mdt_thread_info *info, mdt_handle_last_unlink(info, mc, ma); EXIT; +out_unlock_child: mdt_object_unlock_put(info, mc, child_lh, rc); out_unlock_parent: mdt_object_unlock_put(info, mp, parent_lh, rc); @@ -601,6 +687,11 @@ static int mdt_reint_link(struct mdt_thread_info *info, if (IS_ERR(mp)) RETURN(PTR_ERR(mp)); + info->mti_mos[0] = mp; + rc = mdt_version_get_check(info, 0); + if (rc) + GOTO(out_unlock_parent, rc); + /* step 2: find & lock the source */ lhs = &info->mti_lh[MDT_LH_CHILD]; mdt_lock_reg_init(lhs, LCK_EX); @@ -620,11 +711,17 @@ static int mdt_reint_link(struct mdt_thread_info *info, mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom, OBD_FAIL_MDS_REINT_LINK_WRITE); + info->mti_mos[1] = ms; + rc = mdt_version_get_check(info, 1); + if (rc) + GOTO(out_unlock_child, rc); + lname = mdt_name(info->mti_env, (char *)rr->rr_name, rr->rr_namelen); rc = mdo_link(info->mti_env, mdt_object_child(mp), mdt_object_child(ms), lname, ma); EXIT; +out_unlock_child: mdt_object_unlock_put(info, ms, lhs, rc); out_unlock_parent: mdt_object_unlock_put(info, mp, lhp, rc); @@ -712,25 +809,25 @@ static int mdt_rename_lock(struct mdt_thread_info *info, struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace; ldlm_policy_data_t *policy = &info->mti_policy; struct ldlm_res_id *res_id = &info->mti_res_id; - struct lu_site *ls; + struct md_site *ms; int rc; ENTRY; - /* - * Disable global rename BFL lock temporarily because - * when a mds do rename recoverying, which might enqueue - * BFL lock to the controller mds. and this req might be - * replay req for controller mds. but we did not have + /* + * Disable global rename BFL lock temporarily because + * when a mds do rename recoverying, which might enqueue + * BFL lock to the controller mds. and this req might be + * replay req for controller mds. but we did not have * such handling in controller mds. XXX */ RETURN(0); - ls = info->mti_mdt->mdt_md_dev.md_lu_dev.ld_site; + ms = mdt_md_site(info->mti_mdt); fid_build_reg_res_name(&LUSTRE_BFL_FID, res_id); memset(policy, 0, sizeof *policy); policy->l_inodebits.bits = MDS_INODELOCK_UPDATE; - if (ls->ls_control_exp == NULL) { + if (ms->ms_control_exp == NULL) { int flags = LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB; /* @@ -740,17 +837,20 @@ static int mdt_rename_lock(struct mdt_thread_info *info, rc = ldlm_cli_enqueue_local(ns, res_id, LDLM_IBITS, policy, LCK_EX, &flags, ldlm_blocking_ast, ldlm_completion_ast, NULL, NULL, 0, - NULL, lh); + NULL, + &info->mti_exp->exp_handle.h_cookie, + lh); } else { struct ldlm_enqueue_info einfo = { LDLM_IBITS, LCK_EX, - ldlm_blocking_ast, ldlm_completion_ast, NULL, NULL }; + ldlm_blocking_ast, ldlm_completion_ast, NULL, NULL, NULL }; int flags = 0; /* * This is the case mdt0 is remote node, issue DLM lock like * other clients. */ - rc = ldlm_cli_enqueue(ls->ls_control_exp, NULL, &einfo, res_id, + rc = ldlm_cli_enqueue(ms->ms_control_exp, + NULL, &einfo, res_id, policy, &flags, NULL, 0, NULL, lh, 0); } @@ -855,6 +955,11 @@ static int mdt_reint_rename(struct mdt_thread_info *info, if (IS_ERR(msrcdir)) GOTO(out_rename_lock, rc = PTR_ERR(msrcdir)); + info->mti_mos[0] = msrcdir; + rc = mdt_version_get_check(info, 0); + if (rc) + GOTO(out_unlock_source, rc); + /* step 2: find & lock the target dir. */ lh_tgtdirp = &info->mti_lh[MDT_LH_CHILD]; mdt_lock_pdo_init(lh_tgtdirp, LCK_PW, rr->rr_tgt, @@ -876,7 +981,14 @@ static int mdt_reint_rename(struct mdt_thread_info *info, rc = mdt_object_lock(info, mtgtdir, lh_tgtdirp, MDS_INODELOCK_UPDATE, MDT_LOCAL_LOCK); - if (rc != 0) + if (rc != 0) { + mdt_object_put(info->mti_env, mtgtdir); + GOTO(out_unlock_source, rc); + } + + info->mti_mos[1] = mtgtdir; + rc = mdt_version_get_check(info, 1); + if (rc) GOTO(out_unlock_target, rc); } } @@ -904,6 +1016,12 @@ static int mdt_reint_rename(struct mdt_thread_info *info, mdt_object_put(info->mti_env, mold); GOTO(out_unlock_target, rc); } + + info->mti_mos[2] = mold; + rc = mdt_version_get_check(info, 2); + if (rc) + GOTO(out_unlock_old, rc); + mdt_set_capainfo(info, 2, old_fid, BYPASS_CAPA); /* step 4: find & lock the new object. */ @@ -931,6 +1049,12 @@ static int mdt_reint_rename(struct mdt_thread_info *info, mdt_object_put(info->mti_env, mnew); GOTO(out_unlock_old, rc); } + + info->mti_mos[3] = mnew; + rc = mdt_version_get_check(info, 3); + if (rc) + GOTO(out_unlock_new, rc); + mdt_set_capainfo(info, 3, new_fid, BYPASS_CAPA); } else if (rc != -EREMOTE && rc != -ENOENT) GOTO(out_unlock_old, rc);