Whamcloud - gitweb
LU-14459 mdt: support fixed directory layout
[fs/lustre-release.git] / lustre / mdt / mdt_reint.c
index a06ccef..6a90950 100644 (file)
@@ -27,7 +27,6 @@
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
  *
  * lustre/mdt/mdt_reint.c
  *
@@ -353,6 +352,7 @@ static int mdt_restripe(struct mdt_thread_info *info,
        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;
@@ -364,6 +364,9 @@ static int mdt_restripe(struct mdt_thread_info *info,
        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);
@@ -382,7 +385,7 @@ static int mdt_restripe(struct mdt_thread_info *info,
        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))
@@ -413,6 +416,18 @@ static int mdt_restripe(struct mdt_thread_info *info,
                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);
@@ -531,8 +546,12 @@ static int mdt_create(struct mdt_thread_info *info)
                    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;
        }
 
@@ -596,9 +615,6 @@ static int mdt_create(struct mdt_thread_info *info)
        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.
@@ -1292,7 +1308,8 @@ 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)) {
+       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));
        }
@@ -2264,6 +2281,15 @@ lock_parent:
 
                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 */
@@ -2604,11 +2630,22 @@ static int mdt_reint_rename(struct mdt_thread_info *info,
                    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));
                }
        }