Whamcloud - gitweb
LU-11025 lmv: simplify name to stripe mapping 11/37711/4
authorLai Siyao <lai.siyao@whamcloud.com>
Sat, 15 Feb 2020 02:48:59 +0000 (10:48 +0800)
committerOleg Drokin <green@whamcloud.com>
Tue, 31 Mar 2020 06:59:20 +0000 (06:59 +0000)
Handle layout change internally when mapping name to stripe:
* Move layout changing related code into lmv name to stripe mapping
  so callers doesn't need to take care of the internals.
* lmv_name_to_stripe_index() maps name in new layout, and
  lmv_name_to_stripe_index_old() in old layout.
* rename lmv_migrate_existence_check() to lmv_old_layout_lookup()
  to support directory restripe in the future.
* support layout changing directory in LFSCK.

Signed-off-by: Lai Siyao <lai.siyao@whamcloud.com>
Change-Id: Icf8bda5db884784f761a2d373a6f81d7e13f525f
Reviewed-on: https://review.whamcloud.com/37711
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Hongchao Zhang <hongchao@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
12 files changed:
lustre/include/lustre_lmv.h
lustre/include/obd.h
lustre/include/uapi/linux/lustre/lustre_idl.h
lustre/include/uapi/linux/lustre/lustre_user.h
lustre/lfsck/lfsck_striped_dir.c
lustre/lmv/lmv_intent.c
lustre/lmv/lmv_internal.h
lustre/lmv/lmv_obd.c
lustre/lod/lod_object.c
lustre/mdd/mdd_dir.c
lustre/mdt/mdt_reint.c
lustre/obdecho/echo_client.c

index 44c8f48..002f07f 100644 (file)
@@ -64,10 +64,10 @@ static inline bool lmv_dir_foreign(const struct lmv_stripe_md *lsm)
        return lsm && lsm->lsm_md_magic == LMV_MAGIC_FOREIGN;
 }
 
-static inline bool lmv_dir_migrating(const struct lmv_stripe_md *lsm)
+static inline bool lmv_dir_layout_changing(const struct lmv_stripe_md *lsm)
 {
        return lmv_dir_striped(lsm) &&
-              lsm->lsm_md_hash_type & LMV_HASH_FLAG_MIGRATION;
+              (lsm->lsm_md_hash_type & LMV_HASH_FLAG_LAYOUT_CHANGE);
 }
 
 static inline bool lmv_dir_bad_hash(const struct lmv_stripe_md *lsm)
@@ -75,10 +75,6 @@ static inline bool lmv_dir_bad_hash(const struct lmv_stripe_md *lsm)
        if (!lmv_dir_striped(lsm))
                return false;
 
-       if (lmv_dir_migrating(lsm) &&
-           lsm->lsm_md_stripe_count - lsm->lsm_md_migrate_offset <= 1)
-               return false;
-
        if (lsm->lsm_md_hash_type & LMV_HASH_FLAG_BAD_TYPE)
                return true;
 
@@ -279,36 +275,102 @@ lmv_hash_crush(unsigned int count, const char *name, int namelen)
        return idx;
 }
 
-static inline int lmv_name_to_stripe_index(__u32 hash_type,
-                                          unsigned int stripe_count,
-                                          const char *name, int namelen)
+static inline int
+__lmv_name_to_stripe_index(__u32 hash_type, __u32 stripe_count,
+                          __u32 migrate_hash, __u32 migrate_offset,
+                          const char *name, int namelen, bool new_layout)
 {
-       unsigned int idx;
+       __u32 saved_hash = hash_type;
+       __u32 saved_count = stripe_count;
+       int stripe_index = 0;
 
        LASSERT(namelen > 0);
        LASSERT(stripe_count > 0);
 
-       if (stripe_count == 1)
-               return 0;
+       if (hash_type & LMV_HASH_FLAG_MIGRATION) {
+               if (new_layout) {
+                       stripe_count = migrate_offset;
+               } else {
+                       hash_type = migrate_hash;
+                       stripe_count -= migrate_offset;
+               }
+       }
 
-       switch (hash_type & LMV_HASH_TYPE_MASK) {
-       case LMV_HASH_TYPE_ALL_CHARS:
-               idx = lmv_hash_all_chars(stripe_count, name, namelen);
-               break;
-       case LMV_HASH_TYPE_FNV_1A_64:
-               idx = lmv_hash_fnv1a(stripe_count, name, namelen);
-               break;
-       case LMV_HASH_TYPE_CRUSH:
-               idx = lmv_hash_crush(stripe_count, name, namelen);
-               break;
-       default:
-               return -EBADFD;
+       if (stripe_count > 1) {
+               switch (hash_type & LMV_HASH_TYPE_MASK) {
+               case LMV_HASH_TYPE_ALL_CHARS:
+                       stripe_index = lmv_hash_all_chars(stripe_count, name,
+                                                         namelen);
+                       break;
+               case LMV_HASH_TYPE_FNV_1A_64:
+                       stripe_index = lmv_hash_fnv1a(stripe_count, name,
+                                                     namelen);
+                       break;
+               case LMV_HASH_TYPE_CRUSH:
+                       stripe_index = lmv_hash_crush(stripe_count, name,
+                                                     namelen);
+                       break;
+               default:
+                       return -EBADFD;
+               }
        }
 
-       CDEBUG(D_INFO, "name %.*s hash_type %#x idx %d/%u\n", namelen, name,
-              hash_type, idx, stripe_count);
+       LASSERT(stripe_index < stripe_count);
 
-       return idx;
+       if ((saved_hash & LMV_HASH_FLAG_MIGRATION) && !new_layout)
+               stripe_index += migrate_offset;
+
+       LASSERT(stripe_index < saved_count);
+
+       CDEBUG(D_INFO, "name %.*s hash %#x/%#x idx %d/%u/%u under %s layout\n",
+              namelen, name, saved_hash, migrate_hash, stripe_index,
+              saved_count, migrate_offset, new_layout ? "new" : "old");
+
+       return stripe_index;
+}
+
+static inline int lmv_name_to_stripe_index(struct lmv_mds_md_v1 *lmv,
+                                          const char *name, int namelen)
+{
+       if (lmv->lmv_magic == LMV_MAGIC_V1)
+               return __lmv_name_to_stripe_index(lmv->lmv_hash_type,
+                                                 lmv->lmv_stripe_count,
+                                                 lmv->lmv_migrate_hash,
+                                                 lmv->lmv_migrate_offset,
+                                                 name, namelen, true);
+
+       if (lmv->lmv_magic == cpu_to_le32(LMV_MAGIC_V1))
+               return __lmv_name_to_stripe_index(
+                                       le32_to_cpu(lmv->lmv_hash_type),
+                                       le32_to_cpu(lmv->lmv_stripe_count),
+                                       le32_to_cpu(lmv->lmv_migrate_hash),
+                                       le32_to_cpu(lmv->lmv_migrate_offset),
+                                       name, namelen, true);
+
+       return -EINVAL;
+}
+
+static inline int lmv_name_to_stripe_index_old(struct lmv_mds_md_v1 *lmv,
+                                              const char *name, int namelen)
+{
+       if (lmv->lmv_magic == LMV_MAGIC_V1 ||
+           lmv->lmv_magic == LMV_MAGIC_STRIPE)
+               return __lmv_name_to_stripe_index(lmv->lmv_hash_type,
+                                                 lmv->lmv_stripe_count,
+                                                 lmv->lmv_migrate_hash,
+                                                 lmv->lmv_migrate_offset,
+                                                 name, namelen, false);
+
+       if (lmv->lmv_magic == cpu_to_le32(LMV_MAGIC_V1) ||
+           lmv->lmv_magic == cpu_to_le32(LMV_MAGIC_STRIPE))
+               return __lmv_name_to_stripe_index(
+                                       le32_to_cpu(lmv->lmv_hash_type),
+                                       le32_to_cpu(lmv->lmv_stripe_count),
+                                       le32_to_cpu(lmv->lmv_migrate_hash),
+                                       le32_to_cpu(lmv->lmv_migrate_offset),
+                                       name, namelen, false);
+
+       return -EINVAL;
 }
 
 static inline bool lmv_user_magic_supported(__u32 lum_magic)
@@ -321,15 +383,18 @@ static inline bool lmv_user_magic_supported(__u32 lum_magic)
 static inline bool lmv_is_sane(const struct lmv_mds_md_v1 *lmv)
 {
        if (le32_to_cpu(lmv->lmv_magic) != LMV_MAGIC_V1)
-               return false;
+               goto insane;
 
        if (le32_to_cpu(lmv->lmv_stripe_count) == 0)
-               return false;
+               goto insane;
 
        if (!lmv_is_known_hash_type(lmv->lmv_hash_type))
-               return false;
+               goto insane;
 
        return true;
+insane:
+       LMV_DEBUG(D_ERROR, lmv, "insane");
+       return false;
 }
 
 #endif
index 9cbc8f7..a0f8f39 100644 (file)
@@ -903,14 +903,14 @@ struct md_op_data {
        __u16                   op_mirror_id;
 
        /*
-        * used to access migrating dir: if it's set, assume migration is
-        * finished, use the new layout to access dir, otherwise use old layout.
+        * used to access dir that is changing layout: if it's set, access
+        * dir by new layout, otherwise old layout.
         * By default it's not set, because new files are created under new
         * layout, if we can't find file with name under both old and new
         * layout, we are sure file with name doesn't exist, but in reverse
         * order there may be a race with creation by others.
         */
-       bool                    op_post_migrate;
+       bool                    op_new_layout;
        /* used to access dir with bash hash */
        __u32                   op_stripe_index;
        /* Archive ID for PCC attach */
index 3ff800f..008132c 100644 (file)
@@ -2224,6 +2224,13 @@ struct lmv_mds_md_v1 {
        struct lu_fid lmv_stripe_fids[0];       /* FIDs for each stripe */
 };
 
+#define LMV_DEBUG(mask, lmv, msg)                                      \
+       CDEBUG(mask, "%s LMV: magic %#x count %u index %u hash %#x version %u migrate offset %u migrate hash %u.\n",    \
+              msg, (lmv)->lmv_magic, (lmv)->lmv_stripe_count,          \
+              (lmv)->lmv_master_mdt_index, (lmv)->lmv_hash_type,       \
+              (lmv)->lmv_layout_version, (lmv)->lmv_migrate_offset,    \
+              (lmv)->lmv_migrate_hash)
+
 /* foreign LMV EA */
 struct lmv_foreign_md {
        __u32 lfm_magic;        /* magic number = LMV_MAGIC_FOREIGN */
index 602f746..0875e8d 100644 (file)
@@ -1021,6 +1021,8 @@ static inline bool lmv_is_known_hash_type(__u32 type)
 #define LMV_HASH_FLAG_BAD_TYPE         0x20000000
 #define LMV_HASH_FLAG_MIGRATION                0x80000000
 
+#define LMV_HASH_FLAG_LAYOUT_CHANGE    LMV_HASH_FLAG_MIGRATION
+
 extern char *mdt_hash_name[LMV_HASH_TYPE_MAX];
 
 struct lustre_foreign_type {
index ed0d3d5..e451a38 100644 (file)
@@ -971,24 +971,30 @@ int lfsck_shard_name_to_index(const struct lu_env *env, const char *name,
        return idx;
 }
 
+static inline bool lfsck_name_hash_match(struct lmv_mds_md_v1 *lmv,
+                                        const char *name, int namelen)
+{
+       int idx;
+
+       idx = lmv_name_to_stripe_index_old(lmv, name, namelen);
+       if (idx == lmv->lmv_master_mdt_index)
+               return true;
+
+       if (!(lmv->lmv_hash_type & LMV_HASH_FLAG_LAYOUT_CHANGE))
+               return false;
+
+       idx = lmv_name_to_stripe_index(lmv, name, namelen);
+       return (idx == lmv->lmv_master_mdt_index);
+}
+
 bool lfsck_is_valid_slave_name_entry(const struct lu_env *env,
                                     struct lfsck_lmv *llmv,
                                     const char *name, int namelen)
 {
-       struct lmv_mds_md_v1    *lmv;
-       int                      idx;
-
        if (llmv == NULL || !llmv->ll_lmv_slave || !llmv->ll_lmv_verified)
                return true;
 
-       lmv = &llmv->ll_lmv;
-       idx = lmv_name_to_stripe_index(lmv->lmv_hash_type,
-                                      lmv->lmv_stripe_count,
-                                      name, namelen);
-       if (unlikely(idx != lmv->lmv_master_mdt_index))
-               return false;
-
-       return true;
+       return lfsck_name_hash_match(&llmv->ll_lmv, name, namelen);
 }
 
 /**
@@ -1015,9 +1021,8 @@ int lfsck_namespace_check_name(const struct lu_env *env,
                               struct dt_object *child,
                               const struct lu_name *cname)
 {
-       struct lmv_mds_md_v1    *lmv = &lfsck_env_info(env)->lti_lmv;
-       int                      idx;
-       int                      rc;
+       struct lmv_mds_md_v1 *lmv = &lfsck_env_info(env)->lti_lmv;
+       int rc;
 
        rc = lfsck_read_stripe_lmv(env, lfsck, parent, lmv);
        if (rc != 0)
@@ -1027,11 +1032,8 @@ int lfsck_namespace_check_name(const struct lu_env *env,
                if (!lfsck_is_valid_slave_lmv(lmv))
                        return 0;
 
-               idx = lmv_name_to_stripe_index(lmv->lmv_hash_type,
-                                              lmv->lmv_stripe_count,
-                                              cname->ln_name,
-                                              cname->ln_namelen);
-               if (unlikely(idx != lmv->lmv_master_mdt_index))
+               if (!lfsck_name_hash_match(lmv, cname->ln_name,
+                                          cname->ln_namelen))
                        return 1;
        } else if (lfsck_shard_name_to_index(env, cname->ln_name,
                        cname->ln_namelen, lfsck_object_type(child),
index 11a78b1..9e31b5f 100644 (file)
@@ -300,7 +300,7 @@ static int lmv_intent_open(struct obd_export *exp, struct md_op_data *op_data,
                if (lmv_dir_bad_hash(op_data->op_mea1))
                        RETURN(-EBADF);
 
-               if (lmv_dir_migrating(op_data->op_mea1)) {
+               if (lmv_dir_layout_changing(op_data->op_mea1)) {
                        if (flags & O_EXCL) {
                                /*
                                 * open(O_CREAT | O_EXCL) needs to check
@@ -308,11 +308,11 @@ static int lmv_intent_open(struct obd_export *exp, struct md_op_data *op_data,
                                 * old and new layout, check old layout on
                                 * client side.
                                 */
-                               rc = lmv_migrate_existence_check(lmv, op_data);
+                               rc = lmv_old_layout_lookup(lmv, op_data);
                                if (rc != -ENOENT)
                                        RETURN(rc);
 
-                               op_data->op_post_migrate = true;
+                               op_data->op_new_layout = true;
                        } else {
                                /*
                                 * open(O_CREAT) will be sent to MDT in old
index 84a6d98..340bd5a 100644 (file)
@@ -156,41 +156,20 @@ static inline int lmv_stripe_md_size(int stripe_count)
 /* for file under migrating directory, return the target stripe info */
 static inline const struct lmv_oinfo *
 lsm_name_to_stripe_info(const struct lmv_stripe_md *lsm, const char *name,
-                       int namelen, bool post_migrate)
+                       int namelen, bool new_layout)
 {
-       __u32 hash_type = lsm->lsm_md_hash_type;
-       __u32 stripe_count = lsm->lsm_md_stripe_count;
        int stripe_index;
 
        LASSERT(lmv_dir_striped(lsm));
 
-       if (hash_type & LMV_HASH_FLAG_MIGRATION) {
-               if (post_migrate) {
-                       hash_type &= ~LMV_HASH_FLAG_MIGRATION;
-                       stripe_count = lsm->lsm_md_migrate_offset;
-               } else {
-                       hash_type = lsm->lsm_md_migrate_hash;
-                       stripe_count -= lsm->lsm_md_migrate_offset;
-               }
-       }
-
-       stripe_index = lmv_name_to_stripe_index(hash_type, stripe_count,
-                                               name, namelen);
+       stripe_index = __lmv_name_to_stripe_index(lsm->lsm_md_hash_type,
+                                                 lsm->lsm_md_stripe_count,
+                                                 lsm->lsm_md_migrate_hash,
+                                                 lsm->lsm_md_migrate_offset,
+                                                 name, namelen, new_layout);
        if (stripe_index < 0)
                return ERR_PTR(stripe_index);
 
-       if ((lsm->lsm_md_hash_type & LMV_HASH_FLAG_MIGRATION) && !post_migrate)
-               stripe_index += lsm->lsm_md_migrate_offset;
-
-       if (stripe_index >= lsm->lsm_md_stripe_count) {
-               CERROR("stripe_index %d stripe_count %d hash_type %#x "
-                       "migrate_offset %d migrate_hash %#x name %.*s\n",
-                       stripe_index, lsm->lsm_md_stripe_count,
-                       lsm->lsm_md_hash_type, lsm->lsm_md_migrate_offset,
-                       lsm->lsm_md_migrate_hash, namelen, name);
-               return ERR_PTR(-EBADF);
-       }
-
        return &lsm->lsm_md_oinfo[stripe_index];
 }
 
@@ -201,8 +180,8 @@ static inline bool lmv_dir_retry_check_update(struct md_op_data *op_data)
        if (!lsm)
                return false;
 
-       if (lmv_dir_migrating(lsm) && !op_data->op_post_migrate) {
-               op_data->op_post_migrate = true;
+       if (lmv_dir_layout_changing(lsm) && !op_data->op_new_layout) {
+               op_data->op_new_layout = true;
                return true;
        }
 
@@ -217,8 +196,7 @@ static inline bool lmv_dir_retry_check_update(struct md_op_data *op_data)
 
 struct lmv_tgt_desc *lmv_locate_tgt(struct lmv_obd *lmv,
                                    struct md_op_data *op_data);
-int lmv_migrate_existence_check(struct lmv_obd *lmv,
-                               struct md_op_data *op_data);
+int lmv_old_layout_lookup(struct lmv_obd *lmv, struct md_op_data *op_data);
 
 /* lproc_lmv.c */
 int lmv_tunables_init(struct obd_device *obd);
index 1484f67..e28cd46 100644 (file)
@@ -1542,7 +1542,7 @@ static struct lu_tgt_desc *lmv_locate_tgt_rr(struct lmv_obd *lmv, __u32 *mdt)
 static struct lmv_tgt_desc *
 lmv_locate_tgt_by_name(struct lmv_obd *lmv, struct lmv_stripe_md *lsm,
                       const char *name, int namelen, struct lu_fid *fid,
-                      __u32 *mds, bool post_migrate)
+                      __u32 *mds, bool new_layout)
 {
        struct lmv_tgt_desc *tgt;
        const struct lmv_oinfo *oinfo;
@@ -1561,8 +1561,7 @@ lmv_locate_tgt_by_name(struct lmv_obd *lmv, struct lmv_stripe_md *lsm,
                        return ERR_PTR(-EBADF);
                oinfo = &lsm->lsm_md_oinfo[cfs_fail_val];
        } else {
-               oinfo = lsm_name_to_stripe_info(lsm, name, namelen,
-                                               post_migrate);
+               oinfo = lsm_name_to_stripe_info(lsm, name, namelen, new_layout);
                if (IS_ERR(oinfo))
                        return ERR_CAST(oinfo);
        }
@@ -1581,7 +1580,7 @@ lmv_locate_tgt_by_name(struct lmv_obd *lmv, struct lmv_stripe_md *lsm,
  *
  * For striped directory, it will locate the stripe by name hash, if hash_type
  * is unknown, it will return the stripe specified by 'op_data->op_stripe_index'
- * which is set outside, and if dir is migrating, 'op_data->op_post_migrate'
+ * which is set outside, and if dir is migrating, 'op_data->op_new_layout'
  * indicates whether old or new layout is used to locate.
  *
  * For plain direcotry, it just locate the MDT of op_data->op_fid1.
@@ -1640,7 +1639,7 @@ lmv_locate_tgt(struct lmv_obd *lmv, struct md_op_data *op_data)
                tgt = lmv_locate_tgt_by_name(lmv, op_data->op_mea1,
                                op_data->op_name, op_data->op_namelen,
                                &op_data->op_fid1, &op_data->op_mds,
-                               op_data->op_post_migrate);
+                               op_data->op_new_layout);
        }
 
        return tgt;
@@ -1654,7 +1653,7 @@ lmv_locate_tgt2(struct lmv_obd *lmv, struct md_op_data *op_data)
        int rc;
 
        LASSERT(op_data->op_name);
-       if (lmv_dir_migrating(op_data->op_mea2)) {
+       if (lmv_dir_layout_changing(op_data->op_mea2)) {
                struct lu_fid fid1 = op_data->op_fid1;
                struct lmv_stripe_md *lsm1 = op_data->op_mea1;
                struct ptlrpc_request *request = NULL;
@@ -1688,13 +1687,14 @@ lmv_locate_tgt2(struct lmv_obd *lmv, struct md_op_data *op_data)
                                &op_data->op_mds, true);
 }
 
-int lmv_migrate_existence_check(struct lmv_obd *lmv, struct md_op_data *op_data)
+int lmv_old_layout_lookup(struct lmv_obd *lmv, struct md_op_data *op_data)
 {
        struct lu_tgt_desc *tgt;
        struct ptlrpc_request *request;
        int rc;
 
-       LASSERT(lmv_dir_migrating(op_data->op_mea1));
+       LASSERT(lmv_dir_layout_changing(op_data->op_mea1));
+       LASSERT(!op_data->op_new_layout);
 
        tgt = lmv_locate_tgt(lmv, op_data);
        if (IS_ERR(tgt))
@@ -1778,16 +1778,16 @@ int lmv_create(struct obd_export *exp, struct md_op_data *op_data,
        if (lmv_dir_bad_hash(op_data->op_mea1))
                RETURN(-EBADF);
 
-       if (lmv_dir_migrating(op_data->op_mea1)) {
+       if (lmv_dir_layout_changing(op_data->op_mea1)) {
                /*
                 * if parent is migrating, create() needs to lookup existing
                 * name in both old and new layout, check old layout on client.
                 */
-               rc = lmv_migrate_existence_check(lmv, op_data);
+               rc = lmv_old_layout_lookup(lmv, op_data);
                if (rc != -ENOENT)
                        RETURN(rc);
 
-               op_data->op_post_migrate = true;
+               op_data->op_new_layout = true;
        }
 
        tgt = lmv_locate_tgt(lmv, op_data);
@@ -2015,7 +2015,7 @@ static int lmv_migrate(struct obd_export *exp, struct md_op_data *op_data,
        struct lmv_tgt_desc *tp_tgt = NULL;
        struct lmv_tgt_desc *child_tgt;
        struct lmv_tgt_desc *tgt;
-       struct lu_fid target_fid;
+       struct lu_fid target_fid = { 0 };
        int rc;
 
        ENTRY;
@@ -2034,29 +2034,15 @@ static int lmv_migrate(struct obd_export *exp, struct md_op_data *op_data,
                RETURN(PTR_ERR(parent_tgt));
 
        if (lmv_dir_striped(lsm)) {
-               __u32 hash_type = lsm->lsm_md_hash_type;
-               __u32 stripe_count = lsm->lsm_md_stripe_count;
+               const struct lmv_oinfo *oinfo;
 
-               /*
-                * old stripes are appended after new stripes for migrating
-                * directory.
-                */
-               if (lmv_dir_migrating(lsm)) {
-                       hash_type = lsm->lsm_md_migrate_hash;
-                       stripe_count -= lsm->lsm_md_migrate_offset;
-               }
-
-               rc = lmv_name_to_stripe_index(hash_type, stripe_count, name,
-                                             namelen);
-               if (rc < 0)
-                       RETURN(rc);
-
-               if (lmv_dir_migrating(lsm))
-                       rc += lsm->lsm_md_migrate_offset;
+               oinfo = lsm_name_to_stripe_info(lsm, name, namelen, false);
+               if (IS_ERR(oinfo))
+                       RETURN(PTR_ERR(oinfo));
 
-               /* save it in fid4 temporarily for early cancel */
-               op_data->op_fid4 = lsm->lsm_md_oinfo[rc].lmo_fid;
-               sp_tgt = lmv_tgt(lmv, lsm->lsm_md_oinfo[rc].lmo_mds);
+               /* save source stripe FID in fid4 temporarily for ELC */
+               op_data->op_fid4 = oinfo->lmo_fid;
+               sp_tgt = lmv_tgt(lmv, oinfo->lmo_mds);
                if (!sp_tgt)
                        RETURN(-ENODEV);
 
@@ -2064,18 +2050,14 @@ static int lmv_migrate(struct obd_export *exp, struct md_op_data *op_data,
                 * if parent is being migrated too, fill op_fid2 with target
                 * stripe fid, otherwise the target stripe is not created yet.
                 */
-               if (lmv_dir_migrating(lsm)) {
-                       hash_type = lsm->lsm_md_hash_type &
-                                   ~LMV_HASH_FLAG_MIGRATION;
-                       stripe_count = lsm->lsm_md_migrate_offset;
-
-                       rc = lmv_name_to_stripe_index(hash_type, stripe_count,
-                                                     name, namelen);
-                       if (rc < 0)
-                               RETURN(rc);
-
-                       op_data->op_fid2 = lsm->lsm_md_oinfo[rc].lmo_fid;
-                       tp_tgt = lmv_tgt(lmv, lsm->lsm_md_oinfo[rc].lmo_mds);
+               if (lmv_dir_layout_changing(lsm)) {
+                       oinfo = lsm_name_to_stripe_info(lsm, name, namelen,
+                                                       true);
+                       if (IS_ERR(oinfo))
+                               RETURN(PTR_ERR(oinfo));
+
+                       op_data->op_fid2 = oinfo->lmo_fid;
+                       tp_tgt = lmv_tgt(lmv, oinfo->lmo_mds);
                        if (!tp_tgt)
                                RETURN(-ENODEV);
                }
@@ -3104,9 +3086,10 @@ static int lmv_unpack_md_v1(struct obd_export *exp, struct lmv_stripe_md *lsm,
        if (cplen >= sizeof(lsm->lsm_md_pool_name))
                RETURN(-E2BIG);
 
-       CDEBUG(D_INFO, "unpack lsm count %d, master %d hash_type %#x "
+       CDEBUG(D_INFO, "unpack lsm count %d/%d, master %d hash_type %#x/%#x "
               "layout_version %d\n", lsm->lsm_md_stripe_count,
-              lsm->lsm_md_master_mdt_index, lsm->lsm_md_hash_type,
+              lsm->lsm_md_migrate_offset, lsm->lsm_md_master_mdt_index,
+              lsm->lsm_md_hash_type, lsm->lsm_md_migrate_hash,
               lsm->lsm_md_layout_version);
 
        stripe_count = le32_to_cpu(lmm1->lmv_stripe_count);
index 27313ce..c218c5e 100644 (file)
@@ -5127,8 +5127,8 @@ static void lod_ah_init(const struct lu_env *env,
                                lc->ldo_dir_stripe_count = 0;
                }
 
-               if (lc->ldo_dir_hash_type == LMV_HASH_TYPE_UNKNOWN)
-                       lc->ldo_dir_hash_type =
+               if (!(lc->ldo_dir_hash_type & LMV_HASH_TYPE_MASK))
+                       lc->ldo_dir_hash_type |=
                                d->lod_mdt_descs.ltd_lmv_desc.ld_pattern;
 
                CDEBUG(D_INFO, "final dir stripe [%hu %d %u]\n",
index 606e29c..c490331 100644 (file)
@@ -4087,22 +4087,14 @@ static int mdd_migrate(const struct lu_env *env, struct md_object *md_pobj,
        plmv = pbuf.lb_buf;
        if (plmv) {
                __u32 hash_type = le32_to_cpu(plmv->lmv_hash_type);
-               __u32 count = le32_to_cpu(plmv->lmv_stripe_count);
                int index;
 
-               /* locate target parent stripe */
-               if (hash_type & LMV_HASH_FLAG_MIGRATION) {
-                       /*
-                        * fail check here to make sure top dir migration
-                        * succeed.
-                        */
-                       if (OBD_FAIL_CHECK_RESET(OBD_FAIL_MIGRATE_ENTRIES, 0))
-                               GOTO(out, rc = -EIO);
-                       hash_type &= ~LMV_HASH_FLAG_MIGRATION;
-                       count = le32_to_cpu(plmv->lmv_migrate_offset);
-               }
-               index = lmv_name_to_stripe_index(hash_type, count,
-                                                lname->ln_name,
+               /* fail check here to make sure top dir migration succeed. */
+               if ((hash_type & LMV_HASH_FLAG_MIGRATION) &&
+                   OBD_FAIL_CHECK_RESET(OBD_FAIL_MIGRATE_ENTRIES, 0))
+                       GOTO(out, rc = -EIO);
+
+               index = lmv_name_to_stripe_index(plmv, lname->ln_name,
                                                 lname->ln_namelen);
                if (index < 0)
                        GOTO(out, rc = index);
@@ -4114,26 +4106,17 @@ static int mdd_migrate(const struct lu_env *env, struct md_object *md_pobj,
 
                /* locate source parent stripe */
                if (le32_to_cpu(plmv->lmv_hash_type) &
-                   LMV_HASH_FLAG_MIGRATION) {
-                       hash_type = le32_to_cpu(plmv->lmv_migrate_hash);
-                       count = le32_to_cpu(plmv->lmv_stripe_count) -
-                               le32_to_cpu(plmv->lmv_migrate_offset);
-
-                       index = lmv_name_to_stripe_index(hash_type, count,
-                                                        lname->ln_name,
-                                                        lname->ln_namelen);
-                       if (index < 0) {
-                               mdd_object_put(env, tpobj);
+                   LMV_HASH_FLAG_LAYOUT_CHANGE) {
+                       index = lmv_name_to_stripe_index_old(plmv,
+                                                            lname->ln_name,
+                                                            lname->ln_namelen);
+                       if (index < 0)
                                GOTO(out, rc = index);
-                       }
 
-                       index += le32_to_cpu(plmv->lmv_migrate_offset);
                        fid_le_to_cpu(fid, &plmv->lmv_stripe_fids[index]);
                        spobj = mdd_object_find(env, mdd, fid);
-                       if (IS_ERR(spobj)) {
-                               mdd_object_put(env, tpobj);
+                       if (IS_ERR(spobj))
                                GOTO(out, rc = PTR_ERR(spobj));
-                       }
                } else {
                        spobj = tpobj;
                        mdd_object_get(spobj);
index 84c4d18..c3b5401 100644 (file)
@@ -1825,25 +1825,12 @@ static int mdt_migrate_lookup(struct mdt_thread_info *info,
        if (ma->ma_valid & MA_LMV) {
                /* if parent is striped, lookup on corresponding stripe */
                struct lmv_mds_md_v1 *lmv = &ma->ma_lmv->lmv_md_v1;
-               __u32 hash_type = le32_to_cpu(lmv->lmv_hash_type);
-               __u32 stripe_count = le32_to_cpu(lmv->lmv_stripe_count);
-               bool is_migrating = le32_to_cpu(lmv->lmv_hash_type) &
-                                   LMV_HASH_FLAG_MIGRATION;
-
-               if (is_migrating) {
-                       hash_type = le32_to_cpu(lmv->lmv_migrate_hash);
-                       stripe_count -= le32_to_cpu(lmv->lmv_migrate_offset);
-               }
 
-               rc = lmv_name_to_stripe_index(hash_type, stripe_count,
-                                             lname->ln_name,
-                                             lname->ln_namelen);
+               rc = lmv_name_to_stripe_index_old(lmv, lname->ln_name,
+                                                 lname->ln_namelen);
                if (rc < 0)
                        return rc;
 
-               if (le32_to_cpu(lmv->lmv_hash_type) & LMV_HASH_FLAG_MIGRATION)
-                       rc += le32_to_cpu(lmv->lmv_migrate_offset);
-
                fid_le_to_cpu(fid, &lmv->lmv_stripe_fids[rc]);
 
                stripe = mdt_object_find(env, info->mti_mdt, fid);
@@ -1853,7 +1840,9 @@ static int mdt_migrate_lookup(struct mdt_thread_info *info,
                fid_zero(fid);
                rc = mdo_lookup(env, mdt_object_child(stripe), lname, fid,
                                &info->mti_spec);
-               if (rc == -ENOENT && is_migrating) {
+               if (rc == -ENOENT &&
+                   (cpu_to_le32(lmv->lmv_hash_type) &
+                    LMV_HASH_FLAG_LAYOUT_CHANGE)) {
                        /*
                         * if parent is migrating, and lookup child failed on
                         * source stripe, lookup again on target stripe, if it
@@ -1862,11 +1851,7 @@ static int mdt_migrate_lookup(struct mdt_thread_info *info,
                         */
                        mdt_object_put(env, stripe);
 
-                       hash_type = le32_to_cpu(lmv->lmv_hash_type);
-                       stripe_count = le32_to_cpu(lmv->lmv_migrate_offset);
-
-                       rc = lmv_name_to_stripe_index(hash_type, stripe_count,
-                                                     lname->ln_name,
+                       rc = lmv_name_to_stripe_index(lmv, lname->ln_name,
                                                      lname->ln_namelen);
                        if (rc < 0)
                                return rc;
index 4f6bcd8..e7eece1 100644 (file)
@@ -1700,9 +1700,8 @@ echo_md_dir_stripe_choose(const struct lu_env *env, struct echo_device *ed,
                echo_md_build_name(&tmp_ln_name, info->eti_name, id);
        }
 
-       idx = lmv_name_to_stripe_index(LMV_HASH_TYPE_FNV_1A_64,
-                               le32_to_cpu(lmv->lmv_stripe_count),
-                               tmp_ln_name.ln_name, tmp_ln_name.ln_namelen);
+       idx = lmv_name_to_stripe_index(lmv, tmp_ln_name.ln_name,
+                                      tmp_ln_name.ln_namelen);
 
        LASSERT(idx < le32_to_cpu(lmv->lmv_stripe_count));
        fid_le_to_cpu(&stripe_fid, &lmv->lmv_stripe_fids[idx]);