#include <lprocfs_status.h>
#include "mdt_internal.h"
#include <lustre_lmv.h>
+#include <lustre_crypto.h>
static inline void mdt_reint_init_ma(struct mdt_thread_info *info,
struct md_attr *ma)
einfo->ei_enq_slave = 1;
einfo->ei_namespace = mti->mti_mdt->mdt_namespace;
einfo->ei_inodebits = ibits;
+ einfo->ei_req_slot = 1;
memset(policy, 0, sizeof(*policy));
policy->l_inodebits.bits = ibits;
}
if ((!(exp_connect_flags2(exp) & OBD_CONNECT2_CRUSH)) &&
- (le32_to_cpu(lum->lum_hash_type) & LMV_HASH_TYPE_MASK) ==
+ (le32_to_cpu(lum->lum_hash_type) & LMV_HASH_TYPE_MASK) >=
LMV_HASH_TYPE_CRUSH)
RETURN(-EPROTO);
if (!mdt_object_exists(parent))
GOTO(put_parent, rc = -ENOENT);
+ rc = mdt_check_enc(info, parent);
+ if (rc)
+ GOTO(put_parent, rc);
+
/*
* LU-10235: check if name exists locklessly first to avoid massive
* lock recalls on existing directories.
* not exist.
*/
info->mti_spec.sp_cr_lookup = 0;
+ if (mdt_object_remote(parent))
+ info->mti_spec.sp_cr_lookup = 1;
info->mti_spec.sp_feat = &dt_directory_features;
rc = mdo_create(info->mti_env, mdt_object_child(parent), &rr->rr_name,
*/
if (ma->ma_attr.la_valid & (LA_MODE|LA_UID|LA_GID))
lockpart |= MDS_INODELOCK_LOOKUP | MDS_INODELOCK_PERM;
+ /* Clear xattr cache on clients, so the virtual project ID xattr
+ * can get the new project ID
+ */
+ if (ma->ma_attr.la_valid & LA_PROJID)
+ lockpart |= MDS_INODELOCK_XATTR;
rc = mdt_reint_striped_lock(info, mo, lh, lockpart, einfo,
cos_incompat);
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);
+
if (ma->ma_valid & MA_LOV) {
buf->lb_buf = ma->ma_lmm;
buf->lb_len = ma->ma_lmm_size;
name = XATTR_NAME_LOV;
} else {
struct lmv_user_md *lmu = &ma->ma_lmv->lmv_user_md;
+ struct lu_fid *pfid = &info->mti_tmp_fid1;
+ struct lu_name *pname = &info->mti_name;
+ const char dotdot[] = "..";
+ struct mdt_object *pobj;
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);
+ if (fid_is_root(rr->rr_fid1)) {
+ lockpart |= MDS_INODELOCK_LOOKUP;
+ } else {
+ /* force client to update dir default layout */
+ fid_zero(pfid);
+ pname->ln_name = dotdot;
+ pname->ln_namelen = sizeof(dotdot);
+ rc = mdo_lookup(info->mti_env,
+ mdt_object_child(mo), pname,
+ pfid, NULL);
+ if (rc)
+ GOTO(out_put, rc);
+
+ pobj = mdt_object_find(info->mti_env, mdt,
+ pfid);
+ if (IS_ERR(pobj))
+ GOTO(out_put, rc = PTR_ERR(pobj));
+
+ if (mdt_object_remote(pobj))
+ rc = mdt_remote_object_lock(info, pobj,
+ mdt_object_fid(mo),
+ &lh->mlh_rreg_lh, LCK_EX,
+ MDS_INODELOCK_LOOKUP, false);
+ else
+ lockpart |= MDS_INODELOCK_LOOKUP;
+
+ mdt_object_put(info->mti_env, pobj);
+
+ if (rc)
+ GOTO(out_put, rc);
+ }
+ }
rc = mdt_object_lock(info, mo, lh, lockpart);
if (rc != 0)
if (rc != 0)
GOTO(put_parent, rc);
- /* lookup child object along with version checking */
- fid_zero(child_fid);
- rc = mdt_lookup_version_check(info, mp, &rr->rr_name, child_fid, 1);
- if (rc != 0) {
- /* Name might not be able to find during resend of
- * remote unlink, considering following case.
- * dir_A is a remote directory, the name entry of
- * dir_A is on MDT0, the directory is on MDT1,
- *
- * 1. client sends unlink req to MDT1.
- * 2. MDT1 sends name delete update to MDT0.
- * 3. name entry is being deleted in MDT0 synchronously.
- * 4. MDT1 is restarted.
- * 5. client resends unlink req to MDT1. So it can not
- * find the name entry on MDT0 anymore.
- * In this case, MDT1 only needs to destory the local
- * directory.
- */
- if (mdt_object_remote(mp) && rc == -ENOENT &&
- !fid_is_zero(rr->rr_fid2) &&
- lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT) {
- no_name = 1;
- *child_fid = *rr->rr_fid2;
- } else {
- GOTO(unlock_parent, rc);
+ if (info->mti_spec.sp_cr_flags & MDS_OP_WITH_FID) {
+ *child_fid = *rr->rr_fid2;
+ } else {
+ /* lookup child object along with version checking */
+ fid_zero(child_fid);
+ rc = mdt_lookup_version_check(info, mp, &rr->rr_name, child_fid,
+ 1);
+ if (rc != 0) {
+ /* Name might not be able to find during resend of
+ * remote unlink, considering following case.
+ * dir_A is a remote directory, the name entry of
+ * dir_A is on MDT0, the directory is on MDT1,
+ *
+ * 1. client sends unlink req to MDT1.
+ * 2. MDT1 sends name delete update to MDT0.
+ * 3. name entry is being deleted in MDT0 synchronously.
+ * 4. MDT1 is restarted.
+ * 5. client resends unlink req to MDT1. So it can not
+ * find the name entry on MDT0 anymore.
+ * In this case, MDT1 only needs to destory the local
+ * directory.
+ */
+ if (mdt_object_remote(mp) && rc == -ENOENT &&
+ !fid_is_zero(rr->rr_fid2) &&
+ lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT) {
+ no_name = 1;
+ *child_fid = *rr->rr_fid2;
+ } else {
+ GOTO(unlock_parent, rc);
+ }
}
}
if (IS_ERR(mc))
GOTO(unlock_parent, rc = PTR_ERR(mc));
+ if (info->mti_spec.sp_cr_flags & MDS_OP_WITH_FID) {
+ /* In this case, child fid is embedded in the request, and we do
+ * not have a proper name as rr_name contains an encoded
+ * hash. So find name that matches provided hash.
+ */
+ if (!find_name_matching_hash(info, &rr->rr_name,
+ NULL, mc))
+ GOTO(put_child, rc = -ENOENT);
+ }
+
if (!cos_incompat) {
rc = mdt_object_striped(info, mc);
if (rc < 0)
unlock_child:
mdt_reint_striped_unlock(info, mc, child_lh, einfo, rc);
put_child:
+ if (info->mti_spec.sp_cr_flags & MDS_OP_WITH_FID &&
+ info->mti_big_buf.lb_buf)
+ lu_buf_free(&info->mti_big_buf);
mdt_object_put(info->mti_env, mc);
unlock_parent:
mdt_object_unlock(info, mp, parent_lh, rc);
if (rc)
GOTO(put_parent, rc);
+ rc = mdt_check_enc(info, mp);
+ if (rc)
+ GOTO(put_parent, rc);
+
/* step 2: find source */
ms = mdt_object_find(info->mti_env, info->mti_mdt, rr->rr_fid1);
if (IS_ERR(ms))
cos_incompat = (mdt_object_remote(mp) || mdt_object_remote(ms));
+ OBD_RACE(OBD_FAIL_MDS_LINK_RENAME_RACE);
+
lhp = &info->mti_lh[MDT_LH_PARENT];
mdt_lock_pdo_init(lhp, LCK_PW, &rr->rr_name);
rc = mdt_reint_object_lock(info, mp, lhp, MDS_INODELOCK_UPDATE,
* 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, lease);
+ ldlm_reprocess_all(lease->l_resource,
+ lease->l_policy_data.l_inodebits.bits);
LDLM_LOCK_PUT(lease);
close:
if (!S_ISDIR(lu_object_attr(&pobj->mot_obj)))
GOTO(put_parent, rc = -ENOTDIR);
+ rc = mdt_check_enc(info, pobj);
+ if (rc)
+ GOTO(put_parent, rc);
+
rc = mdt_stripe_get(info, pobj, ma, XATTR_NAME_LMV);
if (rc)
GOTO(put_parent, rc);
return rc;
}
+/* Helper function for mdt_reint_rename so we don't need to opencode
+ * two different order lockings
+ */
+static int mdt_lock_two_dirs(struct mdt_thread_info *info,
+ struct mdt_object *mfirstdir,
+ struct mdt_lock_handle *lh_firstdirp,
+ struct mdt_object *mseconddir,
+ struct mdt_lock_handle *lh_seconddirp,
+ bool cos_incompat)
+{
+ int rc;
+
+ rc = mdt_object_lock_save(info, mfirstdir, lh_firstdirp, 0,
+ cos_incompat);
+ if (rc)
+ return rc;
+
+ OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RENAME, 5);
+
+ if (mfirstdir != mseconddir) {
+ rc = mdt_object_lock_save(info, mseconddir, lh_seconddirp, 1,
+ cos_incompat);
+ } else if (!mdt_object_remote(mseconddir) &&
+ lh_firstdirp->mlh_pdo_hash !=
+ lh_seconddirp->mlh_pdo_hash) {
+ rc = mdt_pdir_hash_lock(info, lh_seconddirp, mseconddir,
+ MDS_INODELOCK_UPDATE,
+ cos_incompat);
+ OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_PDO_LOCK2, 10);
+ }
+
+ if (rc != 0)
+ mdt_object_unlock(info, mfirstdir, lh_firstdirp, rc);
+
+ return rc;
+}
+
/*
* VBR: rename versions in reply: 0 - srcdir parent; 1 - tgtdir parent;
* 2 - srcdir child; 3 - tgtdir child.
bool reverse = false, discard = false;
bool cos_incompat;
ktime_t kstart = ktime_get();
+ enum mdt_stat_idx msi = 0;
int rc;
ENTRY;
if (IS_ERR(msrcdir))
RETURN(PTR_ERR(msrcdir));
+ rc = mdt_check_enc(info, msrcdir);
+ if (rc)
+ GOTO(out_put_srcdir, rc);
+
OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RENAME3, 5);
if (lu_fid_eq(rr->rr_fid1, rr->rr_fid2)) {
GOTO(out_put_srcdir, rc = PTR_ERR(mtgtdir));
}
+ rc = mdt_check_enc(info, mtgtdir);
+ if (rc)
+ GOTO(out_put_tgtdir, rc);
+
/*
* Note: do not enqueue rename lock for replay request, because
* if other MDT holds rename lock, but being blocked to wait for
* get rename lock, which will cause deadlock.
*/
if (!req_is_replay(req)) {
+ bool remote = mdt_object_remote(msrcdir);
+
/*
* Normally rename RPC is handled on the MDT with the target
* directory (if target exists, it's on the MDT with the
* cause any issue), return -EXDEV early to avoid taking
* rename_lock.
*/
- if (!mdt->mdt_enable_remote_rename &&
- mdt_object_remote(msrcdir))
+ if (!mdt->mdt_enable_remote_rename && remote)
GOTO(out_put_tgtdir, rc = -EXDEV);
/* This might be further relaxed in the future for regular file
* renames in different source and target parents. Start with
* only same-directory renames for simplicity and because this
* is by far the most the common use case.
+ *
+ * Striped directories should be considered "remote".
*/
- if (msrcdir != mtgtdir) {
+ if (msrcdir != mtgtdir || remote ||
+ (S_ISDIR(ma->ma_attr.la_mode) &&
+ !mdt->mdt_enable_parallel_rename_dir) ||
+ (!S_ISDIR(ma->ma_attr.la_mode) &&
+ !mdt->mdt_enable_parallel_rename_file)) {
rc = mdt_rename_lock(info, &rename_lh);
if (rc != 0) {
CERROR("%s: cannot lock for rename: rc = %d\n",
GOTO(out_put_tgtdir, rc);
}
} else {
- CDEBUG(D_INFO, "%s: samedir rename "DFID"/"DNAME"\n",
+ if (S_ISDIR(ma->ma_attr.la_mode))
+ msi = LPROC_MDT_RENAME_PAR_DIR;
+ else
+ msi = LPROC_MDT_RENAME_PAR_FILE;
+
+ CDEBUG(D_INFO,
+ "%s: samedir parallel rename "DFID"/"DNAME"\n",
mdt_obd_name(mdt), PFID(rr->rr_fid1),
PNAME(&rr->rr_name));
}
rc = mdt_rename_determine_lock_order(info, msrcdir, mtgtdir);
if (rc < 0)
GOTO(out_unlock_rename, rc);
-
reverse = rc;
/* source needs to be looked up after locking source parent, otherwise
mdt_lock_pdo_init(lh_srcdirp, LCK_PW, &rr->rr_name);
mdt_lock_pdo_init(lh_tgtdirp, LCK_PW, &rr->rr_tgt_name);
- if (reverse) {
- rc = mdt_object_lock_save(info, mtgtdir, lh_tgtdirp, 1,
- cos_incompat);
- if (rc)
- GOTO(out_unlock_rename, rc);
-
- OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RENAME, 5);
-
- rc = mdt_object_lock_save(info, msrcdir, lh_srcdirp, 0,
- cos_incompat);
- if (rc != 0) {
- mdt_object_unlock(info, mtgtdir, lh_tgtdirp, rc);
- GOTO(out_unlock_rename, rc);
- }
- } else {
- rc = mdt_object_lock_save(info, msrcdir, lh_srcdirp, 0,
- cos_incompat);
- if (rc)
- GOTO(out_unlock_rename, rc);
-
- OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RENAME, 5);
+ /* In case of same dir local rename we must sort by the hash,
+ * otherwise a lock deadlock is possible when renaming
+ * a to b and b to a at the same time LU-15285
+ */
+ if (!mdt_object_remote(mtgtdir) && mtgtdir == msrcdir)
+ reverse = lh_srcdirp->mlh_pdo_hash > lh_tgtdirp->mlh_pdo_hash;
+ if (unlikely(OBD_FAIL_PRECHECK(OBD_FAIL_MDS_PDO_LOCK)))
+ reverse = 0;
+
+ if (reverse)
+ rc = mdt_lock_two_dirs(info, mtgtdir, lh_tgtdirp, msrcdir,
+ lh_srcdirp, cos_incompat);
+ else
+ rc = mdt_lock_two_dirs(info, msrcdir, lh_srcdirp, mtgtdir,
+ lh_tgtdirp, cos_incompat);
- if (mtgtdir != msrcdir) {
- rc = mdt_object_lock_save(info, mtgtdir, lh_tgtdirp, 1,
- cos_incompat);
- } 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,
- cos_incompat);
- OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_PDO_LOCK2, 10);
- }
- if (rc != 0) {
- mdt_object_unlock(info, msrcdir, lh_srcdirp, rc);
- GOTO(out_unlock_rename, rc);
- }
- }
+ if (rc != 0)
+ GOTO(out_unlock_rename, rc);
OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RENAME4, 5);
OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RENAME2, 5);
/* handle last link of tgt object */
if (rc == 0) {
- mdt_counter_incr(req, LPROC_MDT_RENAME,
- ktime_us_delta(ktime_get(), kstart));
if (mnew) {
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,
+ msrcdir, mtgtdir, msi,
ktime_us_delta(ktime_get(), kstart));
}
mdt_dom_discard_data(info, mnew);
mdt_object_put(info->mti_env, mnew);
}
+ OBD_RACE(OBD_FAIL_MDS_LINK_RENAME_RACE);
return rc;
}