+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)
+{
+ return lum_magic == LMV_USER_MAGIC ||
+ lum_magic == LMV_USER_MAGIC_SPECIFIC ||
+ lum_magic == LMV_MAGIC_FOREIGN;
+}
+
+/* master LMV is sane */
+static inline bool lmv_is_sane(const struct lmv_mds_md_v1 *lmv)
+{
+ if (!lmv)
+ return false;
+
+ if (le32_to_cpu(lmv->lmv_magic) != LMV_MAGIC_V1)
+ goto insane;
+
+ if (le32_to_cpu(lmv->lmv_stripe_count) == 0)
+ goto insane;
+
+ if (!lmv_is_known_hash_type(le32_to_cpu(lmv->lmv_hash_type)))
+ goto insane;
+
+ return true;
+insane:
+ LMV_DEBUG(D_ERROR, lmv, "insane");
+ return false;
+}
+
+/* LMV can be either master or stripe LMV */
+static inline bool lmv_is_sane2(const struct lmv_mds_md_v1 *lmv)
+{
+ if (!lmv)
+ return false;
+
+ if (le32_to_cpu(lmv->lmv_magic) != LMV_MAGIC_V1 &&
+ le32_to_cpu(lmv->lmv_magic) != LMV_MAGIC_STRIPE)
+ goto insane;
+
+ if (le32_to_cpu(lmv->lmv_stripe_count) == 0)
+ goto insane;
+
+ if (!lmv_is_known_hash_type(le32_to_cpu(lmv->lmv_hash_type)))
+ goto insane;
+
+ return true;
+insane:
+ LMV_DEBUG(D_ERROR, lmv, "insane");
+ return false;
+}
+
+static inline bool lmv_is_splitting(const struct lmv_mds_md_v1 *lmv)
+{
+ if (!lmv_is_sane2(lmv))
+ return false;
+
+ return lmv_hash_is_splitting(cpu_to_le32(lmv->lmv_hash_type));
+}
+
+static inline bool lmv_is_merging(const struct lmv_mds_md_v1 *lmv)