*/
/*
* This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
*
* lustre/mdt/mdt_reint.c
*
#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)
struct mdt_device *mdt = info->mti_mdt;
struct lu_fid *fid = &info->mti_tmp_fid2;
struct ldlm_enqueue_info *einfo = &info->mti_einfo[0];
+ struct lmv_user_md *lum = spec->u.sp_ea.eadata;
struct lmv_mds_md_v1 *lmv;
struct mdt_object *child;
struct mdt_lock_handle *lhp;
if (!mdt->mdt_enable_dir_restripe)
RETURN(-EPERM);
+ LASSERT(lum);
+ lum->lum_hash_type |= cpu_to_le32(LMV_HASH_FLAG_FIXED);
+
rc = mdt_version_get_check_save(info, parent, 0);
if (rc)
RETURN(rc);
if (ma->ma_valid & MA_LMV) {
/* don't allow restripe if parent dir layout is changing */
lmv = &ma->ma_lmv->lmv_md_v1;
- if (!lmv_is_sane(lmv))
+ if (!lmv_is_sane2(lmv))
GOTO(unlock_parent, rc = -EBADF);
if (lmv_is_layout_changing(lmv))
GOTO(out_child, rc = -EREMOTE);
}
+ if (!S_ISDIR(lu_object_attr(&child->mot_obj)))
+ GOTO(out_child, rc = -ENOTDIR);
+
+ rc = mdt_stripe_get(info, child, ma, XATTR_NAME_LMV);
+ if (rc)
+ GOTO(out_child, rc);
+
+ /* race with migrate? */
+ if ((ma->ma_valid & MA_LMV) &&
+ lmv_is_migrating(&ma->ma_lmv->lmv_md_v1))
+ GOTO(out_child, rc = -EBUSY);
+
/* lock object */
lhc = &info->mti_lh[MDT_LH_CHILD];
mdt_lock_reg_init(lhc, LCK_EX);
LMV_HASH_TYPE_CRUSH)
RETURN(-EPROTO);
- if (!md_capable(uc, CAP_SYS_ADMIN) &&
+ if (!cap_raised(uc->uc_cap, CAP_SYS_ADMIN) &&
uc->uc_gid != mdt->mdt_enable_remote_dir_gid &&
mdt->mdt_enable_remote_dir_gid != -1)
RETURN(-EPERM);
- /* restripe if later found dir exists */
- if (le32_to_cpu(lum->lum_stripe_offset) == LMV_OFFSET_DEFAULT)
+ /* restripe if later found dir exists, MDS_OPEN_CREAT means
+ * this is create only, don't try restripe.
+ */
+ if (mdt->mdt_enable_dir_restripe &&
+ le32_to_cpu(lum->lum_stripe_offset) == LMV_OFFSET_DEFAULT &&
+ !(spec->sp_cr_flags & MDS_OPEN_CREAT))
restripe = true;
}
if (rc)
GOTO(put_child, rc);
- /* Let lower layer know current lock mode. */
- info->mti_spec.sp_cr_mode = mdt_dlm_mode2mdl_mode(lh->mlh_pdo_mode);
-
/*
* Do not perform lookup sanity check. We know that name does
* not exist.
if (rc != 0)
GOTO(out_unlock, rc);
- mdt_dom_obj_lvb_update(info->mti_env, mo, false);
+ mdt_dom_obj_lvb_update(info->mti_env, mo, NULL, false);
EXIT;
out_unlock:
mdt_reint_striped_unlock(info, mo, lh, einfo, rc);
struct md_attr *ma)
{
struct lu_ucred *uc = mdt_ucred(info);
- cfs_cap_t cap_saved;
+ kernel_cap_t cap_saved;
int rc;
ENTRY;
* set the HSM state to dirty.
*/
cap_saved = uc->uc_cap;
- uc->uc_cap |= MD_CAP_TO_MASK(CAP_FOWNER);
+ cap_raise(uc->uc_cap, CAP_FOWNER);
rc = mdt_hsm_attr_set(info, mo, &ma->ma_hsm);
uc->uc_cap = cap_saved;
if (rc)
!mdt->mdt_enable_striped_dir)
GOTO(out_put, rc = -EPERM);
- if (!md_capable(uc, CAP_SYS_ADMIN) &&
+ if (!cap_raised(uc->uc_cap, 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 (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, false))
+ GOTO(put_child, rc = -ENOENT);
+ }
+
if (!cos_incompat) {
rc = mdt_object_striped(info, mc);
if (rc < 0)
/* Return -ENOTSUPP for old client */
GOTO(put_child, rc = -ENOTSUPP);
- if (!md_capable(uc, CAP_SYS_ADMIN))
+ if (!cap_raised(uc->uc_cap, CAP_SYS_ADMIN))
GOTO(put_child, rc = -EPERM);
ma->ma_need = MA_INODE;
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 (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_LINK))
RETURN(err_serious(-ENOENT));
- if (OBD_FAIL_PRECHECK(OBD_FAIL_PTLRPC_RESEND_RACE)) {
+ if (OBD_FAIL_PRECHECK(OBD_FAIL_PTLRPC_RESEND_RACE) ||
+ OBD_FAIL_PRECHECK(OBD_FAIL_PTLRPC_ENQ_RESEND)) {
req->rq_no_reply = 1;
RETURN(err_serious(-ENOENT));
}
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 (!mdt->mdt_enable_remote_dir || !mdt->mdt_enable_dir_migration)
RETURN(-EPERM);
- if (uc && !md_capable(uc, CAP_SYS_ADMIN) &&
+ if (uc && !cap_raised(uc->uc_cap, CAP_SYS_ADMIN) &&
uc->uc_gid != mdt->mdt_enable_remote_dir_gid &&
mdt->mdt_enable_remote_dir_gid != -1)
RETURN(-EPERM);
if (ma->ma_valid & MA_LOV && mdt_lmm_dom_stripesize(ma->ma_lmm))
info->mti_spec.sp_migrate_nsonly = 1;
+ } else if (S_ISDIR(lu_object_attr(&sobj->mot_obj))) {
+ rc = mdt_stripe_get(info, sobj, ma, XATTR_NAME_LMV);
+ if (rc)
+ GOTO(unlock_links, rc);
+
+ /* race with restripe/auto-split? */
+ if ((ma->ma_valid & MA_LMV) &&
+ lmv_is_restriping(&ma->ma_lmv->lmv_md_v1))
+ GOTO(unlock_links, rc = -EBUSY);
}
/* if migration HSM is allowed */
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);
+ /* 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.
+ */
+ if (msrcdir != mtgtdir) {
+ rc = mdt_rename_lock(info, &rename_lh);
+ if (rc != 0) {
+ CERROR("%s: cannot lock for rename: rc = %d\n",
+ mdt_obd_name(mdt), rc);
+ GOTO(out_put_tgtdir, rc);
+ }
+ } else {
+ CDEBUG(D_INFO, "%s: samedir rename "DFID"/"DNAME"\n",
+ mdt_obd_name(mdt), PFID(rr->rr_fid1),
+ PNAME(&rr->rr_name));
}
}
mdt_dom_discard_data(info, mnew);
mdt_object_put(info->mti_env, mnew);
}
+ OBD_RACE(OBD_FAIL_MDS_LINK_RENAME_RACE);
return rc;
}