comp_v1 = (struct lov_comp_md_v1 *)lum;
if (comp_v1 != NULL) {
- __swab32s(&comp_v1->lcm_magic);
- __swab32s(&comp_v1->lcm_size);
- __swab32s(&comp_v1->lcm_layout_gen);
- __swab16s(&comp_v1->lcm_flags);
- __swab16s(&comp_v1->lcm_entry_count);
+ comp_v1->lcm_magic = __swab32(comp_v1->lcm_magic);
+ comp_v1->lcm_size = __swab32(comp_v1->lcm_size);
+ comp_v1->lcm_layout_gen = __swab32(comp_v1->lcm_layout_gen);
+ comp_v1->lcm_flags = __swab16(comp_v1->lcm_flags);
+ comp_v1->lcm_entry_count = __swab16(comp_v1->lcm_entry_count);
ent_count = comp_v1->lcm_entry_count;
} else {
ent_count = 1;
for (i = 0; i < ent_count; i++) {
if (comp_v1 != NULL) {
ent = &comp_v1->lcm_entries[i];
- __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);
+ ent->lcme_id = __swab32(ent->lcme_id);
+ ent->lcme_flags = __swab32(ent->lcme_flags);
+ ent->lcme_timestamp = __swab64(ent->lcme_timestamp);
+ ent->lcme_extent.e_start = __swab64(ent->lcme_extent.e_start);
+ ent->lcme_extent.e_end = __swab64(ent->lcme_extent.e_end);
+ ent->lcme_offset = __swab32(ent->lcme_offset);
+ ent->lcme_size = __swab32(ent->lcme_size);
lum = (struct lov_user_md *)((char *)comp_v1 +
ent->lcme_offset);
}
obj_count = llapi_layout_objects_in_lum(lum, lum_size);
- __swab32s(&lum->lmm_magic);
- __swab32s(&lum->lmm_pattern);
- __swab32s(&lum->lmm_stripe_size);
- __swab16s(&lum->lmm_stripe_count);
- __swab16s(&lum->lmm_stripe_offset);
+ lum->lmm_magic = __swab32(lum->lmm_magic);
+ lum->lmm_pattern = __swab32(lum->lmm_pattern);
+ lum->lmm_stripe_size = __swab32(lum->lmm_stripe_size);
+ lum->lmm_stripe_count = __swab16(lum->lmm_stripe_count);
+ lum->lmm_stripe_offset = __swab16(lum->lmm_stripe_offset);
if (lum->lmm_magic != LOV_MAGIC_V1) {
struct lov_user_md_v3 *v3;
}
for (j = 0; j < obj_count; j++)
- __swab32s(&lod[j].l_ost_idx);
+ lod[j].l_ost_idx = __swab32(lod[j].l_ost_idx);
}
}
else if (v1->lmm_pattern == (LOV_PATTERN_RAID0 |
LOV_PATTERN_OVERSTRIPING))
comp->llc_pattern = LLAPI_LAYOUT_OVERSTRIPING;
+ else if (v1->lmm_pattern == LOV_PATTERN_MDT)
+ comp->llc_pattern = LLAPI_LAYOUT_MDT;
else
- /* Lustre only supports RAID0 for now. */
+ /* Lustre only supports RAID0, overstripping
+ * and DoM for now.
+ */
comp->llc_pattern = v1->lmm_pattern;
if (v1->lmm_stripe_size == 0)
}
/**
+ * Get the last initialized component
+ *
+ * \param[in] layout component layout list.
+ *
+ * \retval 0 found
+ * \retval -EINVAL not found
+ * \retval -EISDIR directory layout
+ */
+int llapi_layout_get_last_init_comp(struct llapi_layout *layout)
+{
+ struct llapi_layout_comp *comp = NULL, *head = NULL;
+
+ if (!layout->llot_is_composite)
+ return 0;
+
+ head = list_entry(layout->llot_comp_list.next, typeof(*comp), llc_list);
+ if (head == NULL)
+ return -EINVAL;
+ if (head->llc_id == 0 && !(head->llc_flags & LCME_FL_INIT))
+ /* a directory */
+ return -EISDIR;
+
+ /* traverse the components from the tail to find the last init one */
+ comp = list_entry(layout->llot_comp_list.prev, typeof(*comp), llc_list);
+ while (comp != head) {
+ if (comp->llc_flags & LCME_FL_INIT)
+ break;
+ comp = list_entry(comp->llc_list.prev, typeof(*comp), llc_list);
+ }
+
+ layout->llot_cur_comp = comp;
+
+ return comp->llc_flags & LCME_FL_INIT ? 0 : -EINVAL;
+}
+
+/**
+ * Interit stripe info from the file's component to the mirror
+ *
+ * \param[in] layout file component layout list.
+ * \param[in] layout mirro component layout list.
+ *
+ * \retval 0 on success
+ * \retval -EINVAL on error
+ */
+int llapi_layout_mirror_inherit(struct llapi_layout *f_layout,
+ struct llapi_layout *m_layout)
+{
+ struct llapi_layout_comp *m_comp = NULL;
+ struct llapi_layout_comp *f_comp = NULL;
+ int rc = 0;
+
+ f_comp = __llapi_layout_cur_comp(f_layout);
+ if (f_comp == NULL)
+ return -EINVAL;
+ m_comp = __llapi_layout_cur_comp(m_layout);
+ if (m_comp == NULL)
+ return -EINVAL;
+
+ m_comp->llc_stripe_size = f_comp->llc_stripe_size;
+ m_comp->llc_stripe_count = f_comp->llc_stripe_count;
+
+ return rc;
+}
+
+/**
* Find all stale components.
*
* \param[in] layout component layout list.
*/
comp_array[i].lrc_synced = true;
llapi_error(LLAPI_MSG_ERROR, written,
- "component %u not synced\n",
+ "component %u not synced",
comp_array[i].lrc_id);
if (rc2 == 0)
rc2 = (int)written;
int lsa_rc;
};
+/* The component flags can be set by users at creation/modification time. */
+#define LCME_USER_COMP_FLAGS (LCME_FL_PREF_RW | LCME_FL_NOSYNC | \
+ LCME_FL_EXTENSION)
+
static int llapi_layout_sanity_cb(struct llapi_layout *layout,
void *arg)
{
return 0;
}
+int lov_comp_md_size(struct lov_comp_md_v1 *lcm)
+{
+ if (lcm->lcm_magic == LOV_MAGIC_V1 || lcm->lcm_magic == LOV_MAGIC_V3) {
+ struct lov_user_md *lum = (void *)lcm;
+
+ return lov_user_md_size(lum->lmm_stripe_count, lum->lmm_magic);
+ }
+
+ if (lcm->lcm_magic == LOV_MAGIC_FOREIGN) {
+ struct lov_foreign_md *lfm = (void *)lcm;
+
+ return lfm->lfm_length;
+ }
+
+ if (lcm->lcm_magic != LOV_MAGIC_COMP_V1)
+ return -EOPNOTSUPP;
+
+ return lcm->lcm_size;
+}
+
+int llapi_get_lum_file_fd(int dir_fd, const char *fname, __u64 *valid,
+ lstatx_t *statx, struct lov_user_md *lum,
+ size_t lumsize)
+{
+ struct lov_user_mds_data *lmd;
+ char buf[65536 + offsetof(typeof(*lmd), lmd_lmm)];
+ int parent_fd = -1;
+ int rc;
+
+ if (lum && lumsize < sizeof(*lum))
+ return -EINVAL;
+
+ /* If a file name is provided, it is relative to the parent directory */
+ if (fname) {
+ parent_fd = dir_fd;
+ dir_fd = -1;
+ }
+
+ lmd = (struct lov_user_mds_data *)buf;
+ rc = get_lmd_info_fd(fname, parent_fd, dir_fd, buf, sizeof(buf),
+ GET_LMD_INFO);
+ if (rc)
+ return rc;
+
+ if (valid)
+ *valid = lmd->lmd_flags;
+
+ if (statx)
+ memcpy(statx, &lmd->lmd_stx, sizeof(*statx));
+
+ if (lum) {
+ if (lmd->lmd_lmmsize > lumsize)
+ return -EOVERFLOW;
+ memcpy(lum, &lmd->lmd_lmm, lmd->lmd_lmmsize);
+ }
+
+ return 0;
+}
+
+int llapi_get_lum_dir_fd(int dir_fd, __u64 *valid, lstatx_t *statx,
+ struct lov_user_md *lum, size_t lumsize)
+{
+ return llapi_get_lum_file_fd(dir_fd, NULL, valid, statx, lum, lumsize);
+}
+
+int llapi_get_lum_file(const char *path, __u64 *valid, lstatx_t *statx,
+ struct lov_user_md *lum, size_t lumsize)
+{
+ char parent[PATH_MAX];
+ const char *fname;
+ char *tmp;
+ int offset;
+ int dir_fd;
+ int rc;
+
+ tmp = strrchr(path, '/');
+ if (!tmp) {
+ strncpy(parent, ".", sizeof(parent) - 1);
+ offset = -1;
+ } else {
+ strncpy(parent, path, tmp - path);
+ offset = tmp - path - 1;
+ parent[tmp - path] = 0;
+ }
+
+ fname = path;
+ if (offset >= 0)
+ fname += offset + 2;
+
+ dir_fd = open(parent, O_RDONLY);
+ if (dir_fd < 0) {
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc, "cannot open '%s'", path);
+ return rc;
+ }
+
+ rc = llapi_get_lum_file_fd(dir_fd, fname, valid, statx, lum, lumsize);
+ close(dir_fd);
+ return rc;
+}
+
+int llapi_get_lum_dir(const char *path, __u64 *valid, lstatx_t *statx,
+ struct lov_user_md *lum, size_t lumsize)
+{
+ int dir_fd;
+ int rc;
+
+ dir_fd = open(path, O_RDONLY);
+ if (dir_fd < 0) {
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc, "cannot open '%s'", path);
+ return rc;
+ }
+
+ rc = llapi_get_lum_dir_fd(dir_fd, valid, statx, lum, lumsize);
+ close(dir_fd);
+ return rc;
+}