- int rc;
-
- if (lsm_op_find(le32_to_cpu(*(__u32 *)lmm)) == NULL) {
- char *buffer;
- int sz;
-
- CERROR("bad disk LOV MAGIC: 0x%08X; dumping LMM (size=%d):\n",
- le32_to_cpu(*(__u32 *)lmm), lmm_bytes);
- sz = lmm_bytes * 2 + 1;
- OBD_ALLOC_LARGE(buffer, sz);
- if (buffer != NULL) {
- int i;
-
- for (i = 0; i < lmm_bytes; i++)
- sprintf(buffer+2*i, "%.2X", ((char *)lmm)[i]);
- buffer[sz - 1] = '\0';
- CERROR("%s\n", buffer);
- OBD_FREE_LARGE(buffer, sz);
- }
- return -EINVAL;
- }
- rc = lsm_op_find(le32_to_cpu(*(__u32 *)lmm))->lsm_lmm_verify(lmm,
- lmm_bytes, stripe_count);
- return rc;
+ struct lov_comp_md_v1 *lcmv1 = buf;
+ struct lov_comp_md_entry_v1 *lcme;
+ struct lov_ost_data_v1 *lmm_objects;
+ size_t lmm_size;
+ unsigned int entry;
+ unsigned int offset;
+ unsigned int size;
+ unsigned int i;
+
+ ENTRY;
+
+ if (lsm->lsm_magic == LOV_MAGIC_V1 || lsm->lsm_magic == LOV_MAGIC_V3)
+ return lov_lsm_pack_v1v3(lsm, buf, buf_size);
+
+ if (lsm->lsm_magic == LOV_MAGIC_FOREIGN)
+ return lov_lsm_pack_foreign(lsm, buf, buf_size);
+
+ lmm_size = lov_comp_md_size(lsm);
+ if (buf_size == 0)
+ RETURN(lmm_size);
+
+ if (buf_size < lmm_size)
+ RETURN(-ERANGE);
+
+ lcmv1->lcm_magic = cpu_to_le32(lsm->lsm_magic);
+ lcmv1->lcm_size = cpu_to_le32(lmm_size);
+ lcmv1->lcm_layout_gen = cpu_to_le32(lsm->lsm_layout_gen);
+ lcmv1->lcm_flags = cpu_to_le16(lsm->lsm_flags);
+ lcmv1->lcm_mirror_count = cpu_to_le16(lsm->lsm_mirror_count);
+ lcmv1->lcm_entry_count = cpu_to_le16(lsm->lsm_entry_count);
+
+ offset = sizeof(*lcmv1) + sizeof(*lcme) * lsm->lsm_entry_count;
+
+ for (entry = 0; entry < lsm->lsm_entry_count; entry++) {
+ struct lov_stripe_md_entry *lsme;
+ struct lov_mds_md *lmm;
+ __u16 stripe_count;
+
+ lsme = lsm->lsm_entries[entry];
+ lcme = &lcmv1->lcm_entries[entry];
+
+ lcme->lcme_id = cpu_to_le32(lsme->lsme_id);
+ lcme->lcme_flags = cpu_to_le32(lsme->lsme_flags);
+ if (lsme->lsme_flags & LCME_FL_NOSYNC)
+ lcme->lcme_timestamp =
+ cpu_to_le64(lsme->lsme_timestamp);
+ lcme->lcme_extent.e_start =
+ cpu_to_le64(lsme->lsme_extent.e_start);
+ lcme->lcme_extent.e_end =
+ cpu_to_le64(lsme->lsme_extent.e_end);
+ lcme->lcme_offset = cpu_to_le32(offset);
+
+ lmm = (struct lov_mds_md *)((char *)lcmv1 + offset);
+ lmm->lmm_magic = cpu_to_le32(lsme->lsme_magic);
+ /* lmm->lmm_oi not set */
+ lmm->lmm_pattern = cpu_to_le32(lsme->lsme_pattern);
+ lmm->lmm_stripe_size = cpu_to_le32(lsme->lsme_stripe_size);
+ lmm->lmm_stripe_count = cpu_to_le16(lsme->lsme_stripe_count);
+ lmm->lmm_layout_gen = cpu_to_le16(lsme->lsme_layout_gen);
+
+ if (lsme->lsme_magic == LOV_MAGIC_V3) {
+ struct lov_mds_md_v3 *lmmv3 =
+ (struct lov_mds_md_v3 *)lmm;
+
+ strlcpy(lmmv3->lmm_pool_name, lsme->lsme_pool_name,
+ sizeof(lmmv3->lmm_pool_name));
+ lmm_objects = lmmv3->lmm_objects;
+ } else {
+ lmm_objects =
+ ((struct lov_mds_md_v1 *)lmm)->lmm_objects;
+ }
+
+ if (lsme_inited(lsme) &&
+ !(lsme->lsme_pattern & LOV_PATTERN_F_RELEASED))
+ stripe_count = lsme->lsme_stripe_count;
+ else
+ stripe_count = 0;
+
+ for (i = 0; i < stripe_count; i++) {
+ struct lov_oinfo *loi = lsme->lsme_oinfo[i];
+
+ ostid_cpu_to_le(&loi->loi_oi, &lmm_objects[i].l_ost_oi);
+ lmm_objects[i].l_ost_gen =
+ cpu_to_le32(loi->loi_ost_gen);
+ lmm_objects[i].l_ost_idx =
+ cpu_to_le32(loi->loi_ost_idx);
+ }
+
+ size = lov_mds_md_size(stripe_count, lsme->lsme_magic);
+ lcme->lcme_size = cpu_to_le32(size);
+ offset += size;
+ } /* for each layout component */
+
+ RETURN(lmm_size);