X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fmdt%2Fmdt_reint.c;h=81c148fe573a2bbea9a126b3cc7893a0138b58ee;hb=c1d0a355a6a6;hp=cb77f698975c1906dda68e355f4905f0b7e77b9e;hpb=0a83d948f37bec7fca6e9aa30f59f26354273b23;p=fs%2Flustre-release.git diff --git a/lustre/mdt/mdt_reint.c b/lustre/mdt/mdt_reint.c index cb77f69..81c148f 100644 --- a/lustre/mdt/mdt_reint.c +++ b/lustre/mdt/mdt_reint.c @@ -217,78 +217,6 @@ static int mdt_lookup_version_check(struct mdt_thread_info *info, } -static inline int mdt_remote_permission_check(struct mdt_thread_info *info) -{ - struct lu_ucred *uc = mdt_ucred(info); - struct mdt_device *mdt = info->mti_mdt; - - if (!md_capable(uc, CFS_CAP_SYS_ADMIN)) { - if (uc->uc_gid != mdt->mdt_enable_remote_dir_gid && - mdt->mdt_enable_remote_dir_gid != -1) - return -EPERM; - } - - return 0; -} - -/** - * mdt_remote_permission: Check whether the remote operation is permitted, - * - * Only sysadmin can create remote directory / striped directory, - * migrate directory and set default stripedEA on directory, unless - * - * lctl set_param mdt.*.enable_remote_dir_gid=allow_gid. - * - * param[in] info: mdt_thread_info. - * - * retval = 0 remote operation is allowed. - * < 0 remote operation is denied. - */ -int mdt_remote_permission(struct mdt_thread_info *info) -{ - struct md_op_spec *spec = &info->mti_spec; - struct lu_attr *attr = &info->mti_attr.ma_attr; - struct obd_export *exp = mdt_info_req(info)->rq_export; - int rc; - - if (info->mti_rr.rr_opcode == REINT_MIGRATE) { - rc = mdt_remote_permission_check(info); - if (rc != 0) - return rc; - } - - if (info->mti_rr.rr_opcode == REINT_CREATE && - (S_ISDIR(attr->la_mode) && spec->u.sp_ea.eadata != NULL && - spec->u.sp_ea.eadatalen != 0)) { - const struct lmv_user_md *lum = spec->u.sp_ea.eadata; - - /* Only new clients can create remote dir( >= 2.4) and - * striped dir(>= 2.6), old client will return -ENOTSUPP */ - if (!mdt_is_dne_client(exp)) - return -ENOTSUPP; - - if (le32_to_cpu(lum->lum_stripe_count) > 1 && - !mdt_is_striped_client(exp)) - return -ENOTSUPP; - - rc = mdt_remote_permission_check(info); - if (rc != 0) - return rc; - } - - if (info->mti_rr.rr_opcode == REINT_SETATTR) { - struct md_attr *ma = &info->mti_attr; - - if ((ma->ma_valid & MA_LMV)) { - rc = mdt_remote_permission_check(info); - if (rc != 0) - return rc; - } - } - - return 0; -} - static int mdt_unlock_slaves(struct mdt_thread_info *mti, struct mdt_object *obj, struct ldlm_enqueue_info *einfo, @@ -322,17 +250,25 @@ static int mdt_unlock_slaves(struct mdt_thread_info *mti, static inline int mdt_object_striped(struct mdt_thread_info *mti, struct mdt_object *obj) { + struct lu_device *bottom_dev; + struct lu_object *bottom_obj; int rc; if (!S_ISDIR(obj->mot_header.loh_attr)) return 0; - rc = mo_xattr_get(mti->mti_env, mdt_object_child(obj), &LU_BUF_NULL, + /* getxattr from bottom obj to avoid reading in shard FIDs */ + bottom_dev = dt2lu_dev(mti->mti_mdt->mdt_bottom); + bottom_obj = lu_object_find_slice(mti->mti_env, bottom_dev, + mdt_object_fid(obj), NULL); + if (IS_ERR(bottom_obj)) + return PTR_ERR(bottom_obj); + + rc = dt_xattr_get(mti->mti_env, lu2dt(bottom_obj), &LU_BUF_NULL, XATTR_NAME_LMV); - if (rc <= 0) - return rc == -ENODATA ? 0 : rc; + lu_object_put(mti->mti_env, bottom_obj); - return 1; + return (rc > 0) ? 1 : (rc == -ENODATA) ? 0 : rc; } /** @@ -423,16 +359,44 @@ static int mdt_create(struct mdt_thread_info *info) struct mdt_body *repbody; struct md_attr *ma = &info->mti_attr; struct mdt_reint_record *rr = &info->mti_rr; + struct md_op_spec *spec = &info->mti_spec; int rc; ENTRY; - DEBUG_REQ(D_INODE, mdt_info_req(info), "Create ("DNAME"->"DFID") " - "in "DFID, + DEBUG_REQ(D_INODE, mdt_info_req(info), + "Create ("DNAME"->"DFID") in "DFID, PNAME(&rr->rr_name), PFID(rr->rr_fid2), PFID(rr->rr_fid1)); if (!fid_is_md_operative(rr->rr_fid1)) RETURN(-EPERM); + if (S_ISDIR(ma->ma_attr.la_mode) && + spec->u.sp_ea.eadata != NULL && spec->u.sp_ea.eadatalen != 0) { + const struct lmv_user_md *lum = spec->u.sp_ea.eadata; + struct lu_ucred *uc = mdt_ucred(info); + struct obd_export *exp = mdt_info_req(info)->rq_export; + + /* Only new clients can create remote dir( >= 2.4) and + * striped dir(>= 2.6), old client will return -ENOTSUPP */ + if (!mdt_is_dne_client(exp)) + RETURN(-ENOTSUPP); + + if (le32_to_cpu(lum->lum_stripe_count) > 1) { + if (!mdt_is_striped_client(exp)) + RETURN(-ENOTSUPP); + + if (!mdt->mdt_enable_striped_dir) + RETURN(-EPERM); + } else if (!mdt->mdt_enable_remote_dir) { + RETURN(-EPERM); + } + + if (!md_capable(uc, CFS_CAP_SYS_ADMIN) && + uc->uc_gid != mdt->mdt_enable_remote_dir_gid && + mdt->mdt_enable_remote_dir_gid != -1) + RETURN(-EPERM); + } + repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY); parent = mdt_object_find(info->mti_env, info->mti_mdt, rr->rr_fid1); @@ -474,10 +438,6 @@ static int mdt_create(struct mdt_thread_info *info) if (unlikely(IS_ERR(child))) GOTO(unlock_parent, rc = PTR_ERR(child)); - rc = mdt_remote_permission(info); - if (rc != 0) - GOTO(put_child, rc); - ma->ma_need = MA_INODE; ma->ma_valid = 0; @@ -638,6 +598,8 @@ out_unlock: int mdt_add_dirty_flag(struct mdt_thread_info *info, struct mdt_object *mo, struct md_attr *ma) { + struct lu_ucred *uc = mdt_ucred(info); + cfs_cap_t cap_saved; int rc; ENTRY; @@ -655,7 +617,12 @@ int mdt_add_dirty_flag(struct mdt_thread_info *info, struct mdt_object *mo, && !(ma->ma_hsm.mh_flags & (HS_DIRTY|HS_RELEASED))) { ma->ma_hsm.mh_flags |= HS_DIRTY; + /* Bump cap so that closes from non-owner writers can + * set the HSM state to dirty. */ + cap_saved = uc->uc_cap; + uc->uc_cap |= MD_CAP_TO_MASK(CFS_CAP_FOWNER); rc = mdt_hsm_attr_set(info, mo, &ma->ma_hsm); + uc->uc_cap = cap_saved; if (rc) CERROR("file attribute change error for "DFID": %d\n", PFID(mdt_object_fid(mo)), rc); @@ -665,26 +632,29 @@ int mdt_add_dirty_flag(struct mdt_thread_info *info, struct mdt_object *mo, } static int mdt_reint_setattr(struct mdt_thread_info *info, - struct mdt_lock_handle *lhc) + struct mdt_lock_handle *lhc) { - struct md_attr *ma = &info->mti_attr; - struct mdt_reint_record *rr = &info->mti_rr; - struct ptlrpc_request *req = mdt_info_req(info); - struct mdt_object *mo; - struct mdt_body *repbody; - int rc, rc2; - ENTRY; + 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); + struct mdt_object *mo; + struct mdt_body *repbody; + int rc, rc2; + ENTRY; - DEBUG_REQ(D_INODE, req, "setattr "DFID" %x", PFID(rr->rr_fid1), - (unsigned int)ma->ma_attr.la_valid); + DEBUG_REQ(D_INODE, req, "setattr "DFID" %x", PFID(rr->rr_fid1), + (unsigned int)ma->ma_attr.la_valid); if (info->mti_dlm_req) ldlm_request_cancel(req, info->mti_dlm_req, 0, LATF_SKIP); + OBD_RACE(OBD_FAIL_PTLRPC_RESEND_RACE); + 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)); + mo = mdt_object_find(info->mti_env, mdt, rr->rr_fid1); + if (IS_ERR(mo)) + GOTO(out, rc = PTR_ERR(mo)); if (!mdt_object_exists(mo)) GOTO(out_put, rc = -ENOENT); @@ -721,13 +691,23 @@ static int mdt_reint_setattr(struct mdt_thread_info *info, /* LU-10286: compatibility check for FLR. * Please check the comment in mdt_finish_open() for details */ - if (!exp_connect_flr(info->mti_exp)) { + if (!exp_connect_flr(info->mti_exp) || + !exp_connect_overstriping(info->mti_exp)) { rc = mdt_big_xattr_get(info, mo, XATTR_NAME_LOV); if (rc < 0 && rc != -ENODATA) GOTO(out_put, rc); - if (rc > 0 && mdt_lmm_is_flr(info->mti_big_lmm)) - GOTO(out_put, rc = -EOPNOTSUPP); + if (!exp_connect_flr(info->mti_exp)) { + if (rc > 0 && + mdt_lmm_is_flr(info->mti_big_lmm)) + GOTO(out_put, rc = -EOPNOTSUPP); + } + + if (!exp_connect_overstriping(info->mti_exp)) { + if (rc > 0 && + mdt_lmm_is_overstriping(info->mti_big_lmm)) + GOTO(out_put, rc = -EOPNOTSUPP); + } } /* For truncate, the file size sent from client @@ -744,39 +724,64 @@ static int mdt_reint_setattr(struct mdt_thread_info *info, if (ma->ma_valid & MA_LOV) GOTO(out_put, rc = -EPROTO); + /* MDT supports FMD for regular files due to Data-on-MDT */ + if (S_ISREG(lu_object_attr(&mo->mot_obj)) && + ma->ma_attr.la_valid & (LA_ATIME | LA_MTIME | LA_CTIME)) + tgt_fmd_update(info->mti_exp, mdt_object_fid(mo), + req->rq_xid); + rc = mdt_attr_set(info, mo, ma); if (rc) GOTO(out_put, rc); } else if ((ma->ma_valid & (MA_LOV | MA_LMV)) && (ma->ma_valid & MA_INODE)) { - struct lu_buf *buf = &info->mti_buf; - struct mdt_lock_handle *lh; + struct lu_buf *buf = &info->mti_buf; + struct lu_ucred *uc = mdt_ucred(info); + struct mdt_lock_handle *lh; + const char *name; + __u64 lockpart = MDS_INODELOCK_XATTR; - rc = mdt_remote_permission(info); - if (rc < 0) - GOTO(out_put, rc); + /* reject if either remote or striped dir is disabled */ + if (ma->ma_valid & MA_LMV) { + if (!mdt->mdt_enable_remote_dir || + !mdt->mdt_enable_striped_dir) + GOTO(out_put, rc = -EPERM); + + if (!md_capable(uc, CFS_CAP_SYS_ADMIN) && + uc->uc_gid != mdt->mdt_enable_remote_dir_gid && + mdt->mdt_enable_remote_dir_gid != -1) + GOTO(out_put, rc = -EPERM); + } + + if (!S_ISDIR(lu_object_attr(&mo->mot_obj))) + GOTO(out_put, rc = -ENOTDIR); if (ma->ma_attr.la_valid != 0) GOTO(out_put, rc = -EPROTO); - lh = &info->mti_lh[MDT_LH_PARENT]; - mdt_lock_reg_init(lh, LCK_PW); - - rc = mdt_object_lock(info, mo, lh, MDS_INODELOCK_XATTR); - if (rc != 0) - GOTO(out_put, rc); - if (ma->ma_valid & MA_LOV) { buf->lb_buf = ma->ma_lmm; buf->lb_len = ma->ma_lmm_size; + name = XATTR_NAME_LOV; } else { - buf->lb_buf = ma->ma_lmv; + struct lmv_user_md *lmu = &ma->ma_lmv->lmv_user_md; + + buf->lb_buf = lmu; buf->lb_len = ma->ma_lmv_size; + name = XATTR_NAME_DEFAULT_LMV; + /* force client to update dir default layout */ + lockpart |= MDS_INODELOCK_LOOKUP; } + + lh = &info->mti_lh[MDT_LH_PARENT]; + mdt_lock_reg_init(lh, LCK_PW); + + rc = mdt_object_lock(info, mo, lh, lockpart); + if (rc != 0) + GOTO(out_put, rc); + rc = mo_xattr_set(info->mti_env, mdt_object_child(mo), buf, - (ma->ma_valid & MA_LOV) ? - XATTR_NAME_LOV : XATTR_NAME_DEFAULT_LMV, - 0); + name, 0); mdt_object_unlock(info, mo, lh, rc); if (rc) @@ -869,7 +874,7 @@ static int mdt_reint_unlink(struct mdt_thread_info *info, struct mdt_lock_handle *child_lh; struct ldlm_enqueue_info *einfo = &info->mti_einfo[0]; __u64 lock_ibits; - bool cos_incompat = false, discard = false; + bool cos_incompat = false; int no_name = 0; int rc; @@ -946,7 +951,7 @@ relock: if (!cos_incompat) { rc = mdt_object_striped(info, mc); if (rc < 0) - GOTO(unlock_parent, rc = PTR_ERR(mc)); + GOTO(put_child, rc); cos_incompat = rc; if (cos_incompat) { @@ -1050,8 +1055,8 @@ relock: rc = mdt_attr_get_complex(info, mc, ma); if (rc) GOTO(out_stat, rc); - } else { - discard = mdt_dom_check_for_discard(info, mc); + } else if (mdt_dom_check_for_discard(info, mc)) { + mdt_dom_discard_data(info, mc); } mdt_handle_last_unlink(info, mc, ma); @@ -1085,13 +1090,7 @@ unlock_parent: mdt_object_unlock(info, mp, parent_lh, rc); put_parent: mdt_object_put(info->mti_env, mp); - - /* discard is just a PW DOM lock to drop the data on a client - * no need to keep objects being get and locked, do that after all. - */ - if (discard) - mdt_dom_discard_data(info, child_fid); - + CFS_RACE_WAKEUP(OBD_FAIL_OBD_ZERO_NLINK_RACE); return rc; } @@ -1119,6 +1118,11 @@ static int mdt_reint_link(struct mdt_thread_info *info, if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_LINK)) RETURN(err_serious(-ENOENT)); + if (OBD_FAIL_PRECHECK(OBD_FAIL_PTLRPC_RESEND_RACE)) { + req->rq_no_reply = 1; + RETURN(err_serious(-ENOENT)); + } + if (info->mti_dlm_req) ldlm_request_cancel(req, info->mti_dlm_req, 0, LATF_SKIP); @@ -1243,8 +1247,9 @@ static int mdt_pdir_hash_lock(struct mdt_thread_info *info, * going to be sent to client. If it is - mdt_intent_policy() path will * fix it up and turn FL_LOCAL flag off. */ - rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy, - res, dlmflags, &info->mti_exp->exp_handle.h_cookie); + rc = mdt_fid_lock(info->mti_env, ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, + policy, res, dlmflags, + &info->mti_exp->exp_handle.h_cookie); return rc; } @@ -1284,12 +1289,13 @@ static int mdt_rename_lock(struct mdt_thread_info *info, memset(policy, 0, sizeof *policy); policy->l_inodebits.bits = MDS_INODELOCK_UPDATE; flags = LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB; - rc = ldlm_cli_enqueue_local(ns, res_id, LDLM_IBITS, policy, - LCK_EX, &flags, ldlm_blocking_ast, - ldlm_completion_ast, NULL, NULL, 0, - LVB_T_NONE, - &info->mti_exp->exp_handle.h_cookie, - lh); + rc = ldlm_cli_enqueue_local(info->mti_env, ns, res_id, + LDLM_IBITS, policy, LCK_EX, &flags, + ldlm_blocking_ast, + ldlm_completion_ast, NULL, NULL, 0, + LVB_T_NONE, + &info->mti_exp->exp_handle.h_cookie, + lh); RETURN(rc); } RETURN(rc); @@ -1304,7 +1310,7 @@ static void mdt_rename_unlock(struct lustre_handle *lh) EXIT; } -static struct mdt_object *mdt_object_find_check(struct mdt_thread_info *info, +static struct mdt_object *mdt_parent_find_check(struct mdt_thread_info *info, const struct lu_fid *fid, int idx) { @@ -1322,6 +1328,12 @@ static struct mdt_object *mdt_object_find_check(struct mdt_thread_info *info, if (rc) GOTO(out_put, rc); + if (!mdt_object_exists(dir)) + GOTO(out_put, rc = -ENOENT); + + if (!S_ISDIR(lu_object_attr(&dir->mot_obj))) + GOTO(out_put, rc = -ENOTDIR); + RETURN(dir); out_put: mdt_object_put(info->mti_env, dir); @@ -1332,9 +1344,9 @@ out_put: * in case obj is remote obj on its parent, revoke LOOKUP lock, * herein we don't really check it, just do revoke. */ -static int mdt_revoke_remote_lookup_lock(struct mdt_thread_info *info, - struct mdt_object *pobj, - struct mdt_object *obj) +int mdt_revoke_remote_lookup_lock(struct mdt_thread_info *info, + struct mdt_object *pobj, + struct mdt_object *obj) { struct mdt_lock_handle *lh = &info->mti_lh[MDT_LH_LOCAL]; int rc; @@ -1343,10 +1355,11 @@ static int mdt_revoke_remote_lookup_lock(struct mdt_thread_info *info, mdt_lock_reg_init(lh, LCK_EX); if (mdt_object_remote(pobj)) { + /* don't bother to check if pobj and obj are on the same MDT. */ rc = mdt_remote_object_lock(info, pobj, mdt_object_fid(obj), &lh->mlh_rreg_lh, LCK_EX, MDS_INODELOCK_LOOKUP, false); - } else { + } else if (mdt_object_remote(obj)) { struct ldlm_res_id *res = &info->mti_res_id; union ldlm_policy_data *policy = &info->mti_policy; __u64 dlmflags = LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB | @@ -1355,8 +1368,12 @@ static int mdt_revoke_remote_lookup_lock(struct mdt_thread_info *info, fid_build_reg_res_name(mdt_object_fid(obj), res); memset(policy, 0, sizeof(*policy)); policy->l_inodebits.bits = MDS_INODELOCK_LOOKUP; - rc = mdt_fid_lock(info->mti_mdt->mdt_namespace, &lh->mlh_reg_lh, - LCK_EX, policy, res, dlmflags, NULL); + rc = mdt_fid_lock(info->mti_env, info->mti_mdt->mdt_namespace, + &lh->mlh_reg_lh, LCK_EX, policy, res, + dlmflags, NULL); + } else { + /* do nothing if both are local */ + return 0; } if (rc != ELDLM_OK) @@ -1394,6 +1411,21 @@ static void mdt_unlock_list(struct mdt_thread_info *info, } } +static inline void mdt_migrate_object_unlock(struct mdt_thread_info *info, + struct mdt_object *obj, + struct mdt_lock_handle *lh, + struct ldlm_enqueue_info *einfo, + struct list_head *slave_locks, + int decref) +{ + if (mdt_object_remote(obj)) { + mdt_unlock_list(info, slave_locks, decref); + mdt_object_unlock(info, obj, lh, decref); + } else { + mdt_reint_striped_unlock(info, obj, lh, einfo, decref); + } +} + /* * lock parents of links, and also check whether total locks don't exceed * RS_MAX_LOCKS. @@ -1402,18 +1434,20 @@ static void mdt_unlock_list(struct mdt_thread_info *info, * \retval 1 on success, but total lock count may exceed RS_MAX_LOCKS * \retval -ev negative errno upon error */ -static int mdt_lock_links(struct mdt_thread_info *info, - struct mdt_object *pobj, - const struct md_attr *ma, - struct mdt_object *obj, - struct list_head *link_locks) +static int mdt_link_parents_lock(struct mdt_thread_info *info, + struct mdt_object *pobj, + const struct md_attr *ma, + struct mdt_object *obj, + struct mdt_lock_handle *lhp, + struct ldlm_enqueue_info *peinfo, + struct list_head *parent_slave_locks, + struct list_head *link_locks) { struct mdt_device *mdt = info->mti_mdt; struct lu_buf *buf = &info->mti_big_buf; struct lu_name *lname = &info->mti_name; struct linkea_data ldata = { NULL }; bool blocked = false; - int retries = 5; int local_lnkp_cnt = 0; int rc; @@ -1434,7 +1468,6 @@ static int mdt_lock_links(struct mdt_thread_info *info, RETURN(rc); } -repeat: for (linkea_first_entry(&ldata); ldata.ld_lee && !rc; linkea_next_entry(&ldata)) { struct mdt_object *lnkp; @@ -1537,12 +1570,19 @@ repeat: rc = mdt_object_lock_try(info, lnkp, &msl->msl_lh, &ibits, MDS_INODELOCK_UPDATE, true); if (!(ibits & MDS_INODELOCK_UPDATE)) { - blocked = true; - CDEBUG(D_INFO, "busy lock on "DFID" "DNAME" retry %d\n", - PFID(&fid), PNAME(lname), retries); + CDEBUG(D_INFO, "busy lock on "DFID" "DNAME"\n", + PFID(&fid), PNAME(lname)); mdt_unlock_list(info, link_locks, 1); + /* also unlock parent locks to avoid deadlock */ + if (!blocked) + mdt_migrate_object_unlock(info, pobj, lhp, + peinfo, + parent_slave_locks, + 1); + + blocked = true; mdt_lock_pdo_init(&msl->msl_lh, LCK_PW, lname); rc = mdt_object_lock(info, lnkp, &msl->msl_lh, @@ -1583,15 +1623,8 @@ repeat: rc = mdt_revoke_remote_lookup_lock(info, lnkp, obj); } - if (blocked) { - rc = -EBUSY; - if (--retries > 0) { - mdt_unlock_list(info, link_locks, rc); - blocked = false; - local_lnkp_cnt = 0; - goto repeat; - } - } + if (blocked) + GOTO(out, rc = -EBUSY); EXIT; out: @@ -1635,6 +1668,9 @@ static int mdt_lock_remote_slaves(struct mdt_thread_info *info, for (i = 0; i < le32_to_cpu(lmv->lmv_stripe_count); i++) { fid_le_to_cpu(fid, &lmv->lmv_stripe_fids[i]); + if (!fid_is_sane(fid)) + continue; + slave = mdt_object_find(info->mti_env, mdt, fid); if (IS_ERR(slave)) GOTO(out, rc = PTR_ERR(slave)); @@ -1657,7 +1693,6 @@ static int mdt_lock_remote_slaves(struct mdt_thread_info *info, INIT_LIST_HEAD(&msl->msl_linkage); msl->msl_obj = slave; list_add_tail(&msl->msl_linkage, slave_locks); - } EXIT; @@ -1667,21 +1702,6 @@ out: return rc; } -static inline void mdt_migrate_object_unlock(struct mdt_thread_info *info, - struct mdt_object *obj, - struct mdt_lock_handle *lh, - struct ldlm_enqueue_info *einfo, - struct list_head *slave_locks, - int decref) -{ - if (mdt_object_remote(obj)) { - mdt_unlock_list(info, slave_locks, decref); - mdt_object_unlock(info, obj, lh, decref); - } else { - mdt_reint_striped_unlock(info, obj, lh, einfo, decref); - } -} - /* lock parent and its stripes */ static int mdt_migrate_parent_lock(struct mdt_thread_info *info, struct mdt_object *obj, @@ -1731,7 +1751,6 @@ static int mdt_migrate_object_lock(struct mdt_thread_info *info, int rc; if (mdt_object_remote(obj)) { - /* don't bother to check if pobj and obj are on the same MDT. */ rc = mdt_revoke_remote_lookup_lock(info, pobj, obj); if (rc) return rc; @@ -1928,7 +1947,7 @@ static int mdd_migrate_close(struct mdt_thread_info *info, * cancelled, it's okay to cancel it now as we've held mot_open_sem. */ ldlm_lock_cancel(lease); - ldlm_reprocess_all(lease->l_resource); + ldlm_reprocess_all(lease->l_resource, lease); LDLM_LOCK_PUT(lease); close: @@ -1952,11 +1971,14 @@ close: * 9. unlock above locks * 10. sync device if source has links */ -static int mdt_reint_migrate_internal(struct mdt_thread_info *info) +static int mdt_reint_migrate(struct mdt_thread_info *info, + struct mdt_lock_handle *unused) { const struct lu_env *env = info->mti_env; struct mdt_device *mdt = info->mti_mdt; + struct ptlrpc_request *req = mdt_info_req(info); struct mdt_reint_record *rr = &info->mti_rr; + struct lu_ucred *uc = mdt_ucred(info); struct md_attr *ma = &info->mti_attr; struct ldlm_enqueue_info *peinfo = &info->mti_einfo[0]; struct ldlm_enqueue_info *seinfo = &info->mti_einfo[1]; @@ -1964,12 +1986,14 @@ static int mdt_reint_migrate_internal(struct mdt_thread_info *info) struct mdt_object *spobj = NULL; struct mdt_object *sobj = NULL; struct mdt_object *tobj; + struct lustre_handle rename_lh = { 0 }; struct mdt_lock_handle *lhp; struct mdt_lock_handle *lhs; struct mdt_lock_handle *lht; LIST_HEAD(parent_slave_locks); LIST_HEAD(child_slave_locks); LIST_HEAD(link_locks); + int lock_retries = 5; bool open_sem_locked = false; bool do_sync = false; int rc; @@ -1978,18 +2002,44 @@ static int mdt_reint_migrate_internal(struct mdt_thread_info *info) CDEBUG(D_INODE, "migrate "DFID"/"DNAME" to "DFID"\n", PFID(rr->rr_fid1), PNAME(&rr->rr_name), PFID(rr->rr_fid2)); + if (info->mti_dlm_req) + ldlm_request_cancel(req, info->mti_dlm_req, 0, LATF_SKIP); + + if (!fid_is_md_operative(rr->rr_fid1) || + !fid_is_md_operative(rr->rr_fid2)) + RETURN(-EPERM); + /* don't allow migrate . or .. */ if (lu_name_is_dot_or_dotdot(&rr->rr_name)) RETURN(-EBUSY); - rc = mdt_remote_permission(info); - if (rc) - RETURN(rc); + if (!mdt->mdt_enable_remote_dir || !mdt->mdt_enable_dir_migration) + RETURN(-EPERM); + + if (!md_capable(uc, CFS_CAP_SYS_ADMIN) && + uc->uc_gid != mdt->mdt_enable_remote_dir_gid && + mdt->mdt_enable_remote_dir_gid != -1) + RETURN(-EPERM); + + /* + * Note: do not enqueue rename lock for replay request, because + * if other MDT holds rename lock, but being blocked to wait for + * this MDT to finish its recovery, and the failover MDT can not + * get rename lock, which will cause deadlock. + */ + if (!req_is_replay(req)) { + rc = mdt_rename_lock(info, &rename_lh); + if (rc != 0) { + CERROR("%s: can't lock FS for rename: rc = %d\n", + mdt_obd_name(info->mti_mdt), rc); + RETURN(rc); + } + } /* pobj is master object of parent */ - pobj = mdt_object_find_check(info, rr->rr_fid1, 0); + pobj = mdt_parent_find_check(info, rr->rr_fid1, 0); if (IS_ERR(pobj)) - RETURN(PTR_ERR(pobj)); + GOTO(unlock_rename, rc = PTR_ERR(pobj)); if (unlikely(!info->mti_big_lmm)) { info->mti_big_lmmsize = lmv_mds_md_size(64, LMV_MAGIC); @@ -2005,6 +2055,7 @@ static int mdt_reint_migrate_internal(struct mdt_thread_info *info) if (rc) GOTO(put_parent, rc); +lock_parent: /* lock parent object */ lhp = &info->mti_lh[MDT_LH_PARENT]; mdt_lock_reg_init(lhp, LCK_PW); @@ -2023,7 +2074,14 @@ static int mdt_reint_migrate_internal(struct mdt_thread_info *info) GOTO(unlock_parent, rc); /* lock parents of source links, and revoke LOOKUP lock of links */ - rc = mdt_lock_links(info, pobj, ma, sobj, &link_locks); + rc = mdt_link_parents_lock(info, pobj, ma, sobj, lhp, peinfo, + &parent_slave_locks, &link_locks); + if (rc == -EBUSY && lock_retries-- > 0) { + mdt_object_put(env, sobj); + mdt_object_put(env, spobj); + goto lock_parent; + } + if (rc < 0) GOTO(put_source, rc); @@ -2034,6 +2092,20 @@ static int mdt_reint_migrate_internal(struct mdt_thread_info *info) */ do_sync = rc; + /* TODO: DoM migration is not supported yet */ + if (S_ISREG(lu_object_attr(&sobj->mot_obj))) { + ma->ma_lmm = info->mti_big_lmm; + ma->ma_lmm_size = info->mti_big_lmmsize; + ma->ma_valid = 0; + rc = mdt_stripe_get(info, sobj, ma, XATTR_NAME_LOV); + if (rc) + GOTO(put_source, rc); + + if (ma->ma_valid & MA_LOV && + mdt_lmm_dom_entry(ma->ma_lmm) != LMM_NO_DOM) + GOTO(put_source, rc = -EOPNOTSUPP); + } + /* if migration HSM is allowed */ if (!mdt->mdt_opts.mo_migrate_hsm_allowed) { ma->ma_need = MA_HSM; @@ -2099,7 +2171,11 @@ unlock_open_sem: if (open_sem_locked) up_write(&sobj->mot_open_sem); unlock_links: - mdt_unlock_list(info, &link_locks, rc); + /* if we've got too many locks to save into RPC, + * then just commit before the locks are released */ + if (!rc && do_sync) + mdt_device_sync(env, mdt); + mdt_unlock_list(info, &link_locks, do_sync ? 1 : rc); put_source: mdt_object_put(env, sobj); mdt_object_put(env, spobj); @@ -2108,9 +2184,9 @@ unlock_parent: &parent_slave_locks, rc); put_parent: mdt_object_put(env, pobj); - - if (!rc && do_sync) - mdt_device_sync(env, mdt); +unlock_rename: + if (lustre_handle_is_used(&rename_lh)) + mdt_rename_unlock(&rename_lh); return rc; } @@ -2230,20 +2306,10 @@ static int mdt_rename_determine_lock_order(struct mdt_thread_info *info, * 2 - srcdir child; 3 - tgtdir child. * Update on disk version of srcdir child. */ -/** - * For DNE phase I, only these renames are allowed - * mv src_p/src_c tgt_p/tgt_c - * 1. src_p/src_c/tgt_p/tgt_c are in the same MDT. - * 2. src_p and tgt_p are same directory, and tgt_c does not - * exists. In this case, all of modification will happen - * in the MDT where ithesource parent is, only one remote - * update is needed, i.e. set c_time/m_time on the child. - * And tgt_c will be still in the same MDT as the original - * src_c. - */ -static int mdt_reint_rename_internal(struct mdt_thread_info *info, - struct mdt_lock_handle *lhc) +static int mdt_reint_rename(struct mdt_thread_info *info, + struct mdt_lock_handle *unused) { + struct mdt_device *mdt = info->mti_mdt; struct mdt_reint_record *rr = &info->mti_rr; struct md_attr *ma = &info->mti_attr; struct ptlrpc_request *req = mdt_info_req(info); @@ -2251,6 +2317,7 @@ static int mdt_reint_rename_internal(struct mdt_thread_info *info, struct mdt_object *mtgtdir = NULL; struct mdt_object *mold; struct mdt_object *mnew = NULL; + struct lustre_handle rename_lh = { 0 }; struct mdt_lock_handle *lh_srcdirp; struct mdt_lock_handle *lh_tgtdirp; struct mdt_lock_handle *lh_oldp = NULL; @@ -2258,8 +2325,8 @@ static int mdt_reint_rename_internal(struct mdt_thread_info *info, struct lu_fid *old_fid = &info->mti_tmp_fid1; struct lu_fid *new_fid = &info->mti_tmp_fid2; __u64 lock_ibits; - bool reverse = false; - bool cos_incompat, discard = false; + bool reverse = false, discard = false; + bool cos_incompat; int rc; ENTRY; @@ -2267,8 +2334,15 @@ static int mdt_reint_rename_internal(struct mdt_thread_info *info, PFID(rr->rr_fid1), PNAME(&rr->rr_name), PFID(rr->rr_fid2), PNAME(&rr->rr_tgt_name)); + if (info->mti_dlm_req) + ldlm_request_cancel(req, info->mti_dlm_req, 0, LATF_SKIP); + + if (!fid_is_md_operative(rr->rr_fid1) || + !fid_is_md_operative(rr->rr_fid2)) + RETURN(-EPERM); + /* find both parents. */ - msrcdir = mdt_object_find_check(info, rr->rr_fid1, 0); + msrcdir = mdt_parent_find_check(info, rr->rr_fid1, 0); if (IS_ERR(msrcdir)) RETURN(PTR_ERR(msrcdir)); @@ -2278,14 +2352,41 @@ static int mdt_reint_rename_internal(struct mdt_thread_info *info, mtgtdir = msrcdir; mdt_object_get(info->mti_env, mtgtdir); } else { - mtgtdir = mdt_object_find_check(info, rr->rr_fid2, 1); + mtgtdir = mdt_parent_find_check(info, rr->rr_fid2, 1); if (IS_ERR(mtgtdir)) GOTO(out_put_srcdir, rc = PTR_ERR(mtgtdir)); } + /* + * Note: do not enqueue rename lock for replay request, because + * if other MDT holds rename lock, but being blocked to wait for + * this MDT to finish its recovery, and the failover MDT can not + * get rename lock, which will cause deadlock. + */ + if (!req_is_replay(req)) { + /* + * Normally rename RPC is handled on the MDT with the target + * directory (if target exists, it's on the MDT with the + * target), if the source directory is remote, it's a hint that + * source is remote too (this may not be true, but it won't + * cause any issue), return -EXDEV early to avoid taking + * rename_lock. + */ + if (!mdt->mdt_enable_remote_rename && + mdt_object_remote(msrcdir)) + GOTO(out_put_tgtdir, rc = -EXDEV); + + rc = mdt_rename_lock(info, &rename_lh); + if (rc != 0) { + CERROR("%s: can't lock FS for rename: rc = %d\n", + mdt_obd_name(mdt), rc); + GOTO(out_put_tgtdir, rc); + } + } + rc = mdt_rename_determine_lock_order(info, msrcdir, mtgtdir); if (rc < 0) - GOTO(out_put_tgtdir, rc); + GOTO(out_unlock_rename, rc); reverse = rc; @@ -2310,7 +2411,7 @@ relock: rc = mdt_object_lock_save(info, mtgtdir, lh_tgtdirp, 1, cos_incompat); if (rc) - GOTO(out_put_tgtdir, rc); + GOTO(out_unlock_rename, rc); OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RENAME, 5); @@ -2318,20 +2419,21 @@ relock: cos_incompat); if (rc != 0) { mdt_object_unlock(info, mtgtdir, lh_tgtdirp, rc); - GOTO(out_put_tgtdir, rc); + GOTO(out_unlock_rename, rc); } } else { rc = mdt_object_lock_save(info, msrcdir, lh_srcdirp, 0, cos_incompat); if (rc) - GOTO(out_put_tgtdir, rc); + GOTO(out_unlock_rename, rc); OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RENAME, 5); if (mtgtdir != msrcdir) { rc = mdt_object_lock_save(info, mtgtdir, lh_tgtdirp, 1, cos_incompat); - } else if (lh_srcdirp->mlh_pdo_hash != + } else if (!mdt_object_remote(mtgtdir) && + lh_srcdirp->mlh_pdo_hash != lh_tgtdirp->mlh_pdo_hash) { rc = mdt_pdir_hash_lock(info, lh_tgtdirp, mtgtdir, MDS_INODELOCK_UPDATE, @@ -2340,7 +2442,7 @@ relock: } if (rc != 0) { mdt_object_unlock(info, msrcdir, lh_srcdirp, rc); - GOTO(out_put_tgtdir, rc); + GOTO(out_unlock_rename, rc); } } @@ -2370,6 +2472,9 @@ relock: GOTO(out_put_old, rc = -ENOENT); } + if (mdt_object_remote(mold) && !mdt->mdt_enable_remote_rename) + GOTO(out_put_old, rc = -EXDEV); + /* Check if @mtgtdir is subdir of @mold, before locking child * to avoid reverse locking. */ if (mtgtdir != msrcdir) { @@ -2544,7 +2649,6 @@ relock: mdt_handle_last_unlink(info, mnew, ma); discard = mdt_dom_check_for_discard(info, mnew); } - mdt_rename_counter_tally(info, info->mti_mdt, req, msrcdir, mtgtdir); } @@ -2555,95 +2659,49 @@ relock: out_unlock_old: mdt_object_unlock(info, mold, lh_oldp, rc); out_put_new: - if (mnew != NULL) + if (mnew && !discard) mdt_object_put(info->mti_env, mnew); out_put_old: mdt_object_put(info->mti_env, mold); out_unlock_parents: mdt_object_unlock(info, mtgtdir, lh_tgtdirp, rc); mdt_object_unlock(info, msrcdir, lh_srcdirp, rc); +out_unlock_rename: + if (lustre_handle_is_used(&rename_lh)) + mdt_rename_unlock(&rename_lh); out_put_tgtdir: mdt_object_put(info->mti_env, mtgtdir); out_put_srcdir: mdt_object_put(info->mti_env, msrcdir); - /* If 'discard' is set then new_fid must exits. - * DOM data discard need neither object nor lock, - * so do this at the end. + /* The DoM discard can be done right in the place above where it is + * assigned, meanwhile it is done here after rename unlock due to + * compatibility with old clients, for them the discard blocks + * the main thread until completion. Check LU-11359 for details. */ - if (discard) - mdt_dom_discard_data(info, new_fid); - - return rc; -} - -static int mdt_reint_rename_or_migrate(struct mdt_thread_info *info, - struct mdt_lock_handle *lhc, bool rename) -{ - struct mdt_reint_record *rr = &info->mti_rr; - struct ptlrpc_request *req = mdt_info_req(info); - struct lustre_handle rename_lh = { 0 }; - int rc; - ENTRY; - - if (info->mti_dlm_req) - ldlm_request_cancel(req, info->mti_dlm_req, 0, LATF_SKIP); - - if (!fid_is_md_operative(rr->rr_fid1) || - !fid_is_md_operative(rr->rr_fid2)) - RETURN(-EPERM); - - /* Note: do not enqueue rename lock for replay request, because - * if other MDT holds rename lock, but being blocked to wait for - * this MDT to finish its recovery, and the failover MDT can not - * get rename lock, which will cause deadlock. */ - if (!req_is_replay(req)) { - rc = mdt_rename_lock(info, &rename_lh); - if (rc != 0) { - CERROR("%s: can't lock FS for rename: rc = %d\n", - mdt_obd_name(info->mti_mdt), rc); - RETURN(rc); - } + if (discard) { + mdt_dom_discard_data(info, mnew); + mdt_object_put(info->mti_env, mnew); } - - if (rename) - rc = mdt_reint_rename_internal(info, lhc); - else - rc = mdt_reint_migrate_internal(info); - - if (lustre_handle_is_used(&rename_lh)) - mdt_rename_unlock(&rename_lh); - - RETURN(rc); -} - -static int mdt_reint_rename(struct mdt_thread_info *info, - struct mdt_lock_handle *lhc) -{ - return mdt_reint_rename_or_migrate(info, lhc, true); -} - -static int mdt_reint_migrate(struct mdt_thread_info *info, - struct mdt_lock_handle *lhc) -{ - return mdt_reint_rename_or_migrate(info, lhc, false); + return rc; } static int mdt_reint_resync(struct mdt_thread_info *info, struct mdt_lock_handle *lhc) { struct mdt_reint_record *rr = &info->mti_rr; - struct ptlrpc_request *req = mdt_info_req(info); - struct md_attr *ma = &info->mti_attr; - struct mdt_object *mo; - struct ldlm_lock *lease; - struct mdt_body *repbody; - struct md_layout_change layout = { 0 }; - bool lease_broken; - int rc, rc2; + struct ptlrpc_request *req = mdt_info_req(info); + struct md_attr *ma = &info->mti_attr; + struct mdt_object *mo; + struct ldlm_lock *lease; + struct mdt_body *repbody; + struct md_layout_change layout = { .mlc_mirror_id = rr->rr_mirror_id }; + bool lease_broken; + int rc, rc2; + ENTRY; - DEBUG_REQ(D_INODE, req, DFID": FLR file resync\n", PFID(rr->rr_fid1)); + DEBUG_REQ(D_INODE, req, DFID", FLR file resync", PFID(rr->rr_fid1)); if (info->mti_dlm_req) ldlm_request_cancel(req, info->mti_dlm_req, 0, LATF_SKIP); @@ -2661,7 +2719,7 @@ static int mdt_reint_resync(struct mdt_thread_info *info, if (mdt_object_remote(mo)) GOTO(out_obj, rc = -EREMOTE); - lease = ldlm_handle2lock(rr->rr_handle); + lease = ldlm_handle2lock(rr->rr_lease_handle); if (lease == NULL) GOTO(out_obj, rc = -ESTALE); @@ -2680,10 +2738,13 @@ static int mdt_reint_resync(struct mdt_thread_info *info, /* the file has yet opened by anyone else after we took the lease. */ layout.mlc_opc = MD_LAYOUT_RESYNC; - rc = mdt_layout_change(info, mo, &layout); + lhc = &info->mti_lh[MDT_LH_LOCAL]; + rc = mdt_layout_change(info, mo, lhc, &layout); if (rc) GOTO(out_unlock, rc); + mdt_object_unlock(info, mo, lhc, 0); + ma->ma_need = MA_INODE; ma->ma_valid = 0; rc = mdt_attr_get_complex(info, mo, ma);