+void lustre_swab_lov_comp_md_v1(struct lov_comp_md_v1 *lum)
+{
+ struct lov_comp_md_entry_v1 *ent;
+ struct lov_user_md_v1 *v1;
+ struct lov_user_md_v3 *v3;
+ int i;
+ bool cpu_endian;
+ __u32 off, size;
+ __u16 ent_count, stripe_count;
+ ENTRY;
+
+ cpu_endian = lum->lcm_magic == LOV_USER_MAGIC_COMP_V1;
+ ent_count = lum->lcm_entry_count;
+ if (!cpu_endian)
+ __swab16s(&ent_count);
+
+ CDEBUG(D_IOCTL, "swabbing lov_user_comp_md v1\n");
+ __swab32s(&lum->lcm_magic);
+ __swab32s(&lum->lcm_size);
+ __swab32s(&lum->lcm_layout_gen);
+ __swab16s(&lum->lcm_flags);
+ __swab16s(&lum->lcm_entry_count);
+ __swab16s(&lum->lcm_mirror_count);
+ BUILD_BUG_ON(offsetof(typeof(*lum), lcm_padding1) == 0);
+ BUILD_BUG_ON(offsetof(typeof(*lum), lcm_padding2) == 0);
+
+ for (i = 0; i < ent_count; i++) {
+ ent = &lum->lcm_entries[i];
+ off = ent->lcme_offset;
+ size = ent->lcme_size;
+
+ if (!cpu_endian) {
+ __swab32s(&off);
+ __swab32s(&size);
+ }
+ __swab32s(&ent->lcme_id);
+ __swab32s(&ent->lcme_flags);
+ __swab64s(&ent->lcme_timestamp);
+ __swab64s(&ent->lcme_extent.e_start);
+ __swab64s(&ent->lcme_extent.e_end);
+ __swab32s(&ent->lcme_offset);
+ __swab32s(&ent->lcme_size);
+ __swab32s(&ent->lcme_layout_gen);
+ BUILD_BUG_ON(offsetof(typeof(*ent), lcme_padding_1) == 0);
+
+ v1 = (struct lov_user_md_v1 *)((char *)lum + off);
+ stripe_count = v1->lmm_stripe_count;
+ if (!cpu_endian)
+ __swab16s(&stripe_count);
+
+ if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_V1) ||
+ v1->lmm_magic == LOV_USER_MAGIC_V1) {
+ lustre_swab_lov_user_md_v1(v1);
+ if (size > sizeof(*v1))
+ lustre_swab_lov_user_md_objects(v1->lmm_objects,
+ stripe_count);
+ } else if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_V3) ||
+ v1->lmm_magic == LOV_USER_MAGIC_V3 ||
+ v1->lmm_magic == __swab32(LOV_USER_MAGIC_SPECIFIC) ||
+ v1->lmm_magic == LOV_USER_MAGIC_SPECIFIC) {
+ v3 = (struct lov_user_md_v3 *)v1;
+ lustre_swab_lov_user_md_v3(v3);
+ if (size > sizeof(*v3))
+ lustre_swab_lov_user_md_objects(v3->lmm_objects,
+ stripe_count);
+ } else {
+ CERROR("Invalid magic %#x\n", v1->lmm_magic);
+ }
+ }
+}
+EXPORT_SYMBOL(lustre_swab_lov_comp_md_v1);
+
+void lustre_swab_lov_user_md_objects(struct lov_user_ost_data *lod,
+ int stripe_count)
+{
+ int i;
+
+ ENTRY;
+ for (i = 0; i < stripe_count; i++) {
+ lustre_swab_ost_id(&(lod[i].l_ost_oi));
+ __swab32s(&(lod[i].l_ost_gen));
+ __swab32s(&(lod[i].l_ost_idx));
+ }
+ EXIT;
+}
+EXPORT_SYMBOL(lustre_swab_lov_user_md_objects);
+
+void lustre_swab_lov_user_md(struct lov_user_md *lum, size_t size)
+{
+ struct lov_user_md_v1 *v1;
+ struct lov_user_md_v3 *v3;
+ struct lov_foreign_md *lfm;
+ __u16 stripe_count;
+ ENTRY;
+
+ CDEBUG(D_IOCTL, "swabbing lov_user_md\n");
+ switch (lum->lmm_magic) {
+ case __swab32(LOV_MAGIC_V1):
+ case LOV_USER_MAGIC_V1:
+ {
+ v1 = (struct lov_user_md_v1 *)lum;
+ stripe_count = v1->lmm_stripe_count;
+
+ if (lum->lmm_magic != LOV_USER_MAGIC_V1)
+ __swab16s(&stripe_count);
+
+ lustre_swab_lov_user_md_v1(v1);
+ if (size > sizeof(*v1))
+ lustre_swab_lov_user_md_objects(v1->lmm_objects,
+ stripe_count);
+
+ break;
+ }
+ case __swab32(LOV_MAGIC_V3):
+ case LOV_USER_MAGIC_V3:
+ {
+ v3 = (struct lov_user_md_v3 *)lum;
+ stripe_count = v3->lmm_stripe_count;
+
+ if (lum->lmm_magic != LOV_USER_MAGIC_V3)
+ __swab16s(&stripe_count);
+
+ lustre_swab_lov_user_md_v3(v3);
+ if (size > sizeof(*v3))
+ lustre_swab_lov_user_md_objects(v3->lmm_objects,
+ stripe_count);
+ break;
+ }
+ case __swab32(LOV_USER_MAGIC_SPECIFIC):
+ case LOV_USER_MAGIC_SPECIFIC:
+ {
+ v3 = (struct lov_user_md_v3 *)lum;
+ stripe_count = v3->lmm_stripe_count;
+
+ if (lum->lmm_magic != LOV_USER_MAGIC_SPECIFIC)
+ __swab16s(&stripe_count);
+
+ lustre_swab_lov_user_md_v3(v3);
+ lustre_swab_lov_user_md_objects(v3->lmm_objects, stripe_count);
+ break;
+ }
+ case __swab32(LOV_MAGIC_COMP_V1):
+ case LOV_USER_MAGIC_COMP_V1:
+ lustre_swab_lov_comp_md_v1((struct lov_comp_md_v1 *)lum);
+ break;
+ case __swab32(LOV_MAGIC_FOREIGN):
+ case LOV_USER_MAGIC_FOREIGN:
+ {
+ lfm = (struct lov_foreign_md *)lum;
+ __swab32s(&lfm->lfm_magic);
+ __swab32s(&lfm->lfm_length);
+ __swab32s(&lfm->lfm_type);
+ __swab32s(&lfm->lfm_flags);
+ break;
+ }
+ default:
+ CDEBUG(D_IOCTL, "Invalid LOV magic %08x\n", lum->lmm_magic);
+ }
+}
+EXPORT_SYMBOL(lustre_swab_lov_user_md);
+