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);
}
}
*
* \param[in] lov_xattr LOV user metadata xattr to copy data from
* \param[in] lov_xattr_size size the lov_xattr_size passed in
- * \param[in] flags bitwise-or'd flags to control the behavior
+ * \param[in] flags flags to control how layout is retrieved
*
* \retval valid llapi_layout pointer on success
* \retval NULL if memory allocation fails
*/
struct llapi_layout *llapi_layout_get_by_xattr(void *lov_xattr,
- ssize_t lov_xattr_size,
- uint32_t flags)
+ ssize_t lov_xattr_size,
+ enum llapi_layout_get_flags flags)
{
struct lov_user_md *lum = lov_xattr;
struct lov_comp_md_v1 *comp_v1 = NULL;
}
#if __BYTE_ORDER == __BIG_ENDIAN
- if (flags & LLAPI_LXF_COPY) {
+ if (flags & LLAPI_LAYOUT_GET_COPY) {
lum = malloc(lov_xattr_size);
if (lum == NULL) {
errno = ENOMEM;
llapi_layout_swab_lov_user_md(lum, lov_xattr_size);
- if ((flags & LLAPI_LXF_CHECK) &&
+#if LUSTRE_VERSION_CODE > OBD_OCD_VERSION(2, 16, 53, 0)
+#define LLAPI_LXF_CHECK_OLD 0x0001
+ if (flags & LLAPI_LXF_CHECK_OLD)
+ flags = (flags & ~LLAPI_LXF_CHECK_OLD) | LLAPI_LAYOUT_GET_CHECK;
+#endif
+ if ((flags & LLAPI_LAYOUT_GET_CHECK) &&
!llapi_layout_lum_valid(lum, lov_xattr_size)) {
errno = EBADSLT;
goto out;
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)
* \retval valid llapi_layout pointer on success
* \retval NULL if an error occurs
*/
-struct llapi_layout *llapi_layout_get_by_fd(int fd, uint32_t flags)
+struct llapi_layout *llapi_layout_get_by_fd(int fd,
+ enum llapi_layout_get_flags flags)
{
size_t lum_len;
struct lov_user_md *lum;
goto out;
layout = llapi_layout_get_by_xattr(lum, bytes_read,
- S_ISDIR(st.st_mode) ? 0 : LLAPI_LXF_CHECK);
+ S_ISDIR(st.st_mode) ? 0 : LLAPI_LAYOUT_GET_CHECK);
out:
free(lum);
return layout;
/**
* Get the striping layout for the file at \a path.
*
- * If \a flags contains LAYOUT_GET_EXPECTED, substitute
+ * If \a flags contains LLAPI_LAYOUT_GET_EXPECTED, substitute
* expected inherited attribute values for unspecified attributes. See
* llapi_layout_expected().
*
* \retval valid llapi_layout pointer on success
* \retval NULL if an error occurs
*/
-struct llapi_layout *llapi_layout_get_by_path(const char *path, uint32_t flags)
+struct llapi_layout *llapi_layout_get_by_path(const char *path,
+ enum llapi_layout_get_flags flags)
{
struct llapi_layout *layout = NULL;
+ bool failed = false;
+ int open_flags;
int fd;
int tmp;
- if (flags & LAYOUT_GET_EXPECTED)
+ if (flags & LLAPI_LAYOUT_GET_EXPECTED)
return llapi_layout_expected(path);
- fd = open(path, O_RDONLY);
- if (fd < 0)
- return layout;
+ /* Always get layout in O_DIRECT */
+ /* Allow fetching layout even without the key on encrypted files */
+ open_flags = O_RDONLY | O_DIRECT | O_FILE_ENC;
+do_open:
+ fd = open(path, open_flags);
+ if (fd < 0) {
+ if (errno != EINVAL || failed)
+ return layout;
+ /* EINVAL is because a directory cannot be opened in O_DIRECT */
+ open_flags = O_RDONLY | O_FILE_ENC;
+ failed = true;
+ goto do_open;
+ }
layout = llapi_layout_get_by_fd(fd, flags);
tmp = errno;
*/
struct llapi_layout *llapi_layout_get_by_fid(const char *lustre_dir,
const struct lu_fid *fid,
- uint32_t flags)
+ enum llapi_layout_get_flags flags)
{
int fd;
int tmp;
* the old API uses 0 and -1.
*/
-static bool llapi_layout_stripe_count_is_valid(int64_t stripe_count)
+bool llapi_layout_stripe_count_is_valid(int64_t stripe_count)
{
return stripe_count == LLAPI_LAYOUT_DEFAULT ||
stripe_count == LLAPI_LAYOUT_WIDE ||
* \retval -1 if arguments are invalid or pool name is too long
*/
int llapi_layout_pool_name_set(struct llapi_layout *layout,
- const char *pool_name)
+ char *pool_name)
{
struct llapi_layout_comp *comp;
- char *ptr;
comp = __llapi_layout_cur_comp(layout);
if (comp == NULL)
return -1;
- if (pool_name == NULL) {
- errno = EINVAL;
- return -1;
- }
-
- /* Strip off any 'fsname.' portion. */
- ptr = strchr(pool_name, '.');
- if (ptr != NULL)
- pool_name = ptr + 1;
-
- if (strlen(pool_name) > LOV_MAXPOOLNAME) {
+ if (!llapi_pool_name_is_valid(&pool_name, NULL)) {
errno = EINVAL;
return -1;
}
strncpy(comp->llc_pool_name, pool_name, sizeof(comp->llc_pool_name));
-
return 0;
}
return -1;
}
- if (layout && llapi_layout_sanity((struct llapi_layout *)layout, false,
- !!(layout->llot_mirror_count > 1)))
- return -1;
+ if (layout) {
+ rc = llapi_layout_sanity((struct llapi_layout *)layout,
+ path, false,
+ !!(layout->llot_mirror_count > 1));
+ if (rc) {
+ llapi_layout_sanity_perror(rc);
+ return -1;
+ }
+ }
/* Object creation must be postponed until after layout attributes
* have been applied. */
return "0";
}
-const __u16 llapi_layout_string_flags(char *string)
+__u16 llapi_layout_string_flags(char *string)
{
if (strncmp(string, "ro", strlen(string)) == 0)
return LCM_FL_RDONLY;
goto out;
}
- if (llapi_layout_sanity(existing_layout, false, false)) {
+ rc = llapi_layout_sanity(existing_layout, path, false, false);
+ if (rc) {
tmp_errno = errno;
+ llapi_layout_sanity_perror(rc);
rc = -1;
goto out;
}
goto out;
}
- if (llapi_layout_sanity(existing_layout, false, false)) {
+ rc = llapi_layout_sanity(existing_layout, path, false, false);
+ if (rc) {
tmp_errno = errno;
+ llapi_layout_sanity_perror(rc);
rc = -1;
goto out;
}
goto out;
}
- if (llapi_layout_sanity(existing_layout, false, false)) {
+ rc = llapi_layout_sanity(existing_layout, path, false, false);
+ if (rc) {
tmp_errno = errno;
+ llapi_layout_sanity_perror(rc);
rc = -1;
goto out;
}
}
/**
+ * 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;
+
+ /* DoM component does not inherit stripe size */
+ if (m_comp->llc_pattern != LLAPI_LAYOUT_MDT)
+ 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.
}
/* locate @layout to a valid component covering file [file_start, file_end) */
-uint32_t llapi_mirror_find(struct llapi_layout *layout,
- uint64_t file_start, uint64_t file_end,
- uint64_t *endp)
+int llapi_mirror_find(struct llapi_layout *layout, uint64_t file_start,
+ uint64_t file_end, uint64_t *endp)
{
uint32_t mirror_id = 0;
int rc;
if (rc < 0)
return rc;
}
+ if (!mirror_id)
+ return -ENOENT;
return mirror_id;
}
struct llapi_resync_comp *comp_array,
int comp_size, uint64_t start, uint64_t end)
{
- uint64_t count;
size_t page_size = sysconf(_SC_PAGESIZE);
const size_t buflen = 4 << 20; /* 4M */
void *buf;
uint64_t pos = start;
+ uint64_t data_off = pos, data_end = pos;
+ uint32_t src = 0;
int i;
int rc;
+ int rc2 = 0;
rc = posix_memalign(&buf, page_size, buflen);
if (rc)
return -rc;
- if (end == OBD_OBJECT_EOF)
- count = OBD_OBJECT_EOF;
- else
- count = end - start;
-
- while (count > 0) {
- uint32_t src;
- uint64_t mirror_end = 0;
- uint64_t bytes_left;
+ while (pos < end) {
+ uint64_t mirror_end;
ssize_t bytes_read;
size_t to_read;
size_t to_write;
- src = llapi_mirror_find(layout, pos, end, &mirror_end);
- if (src == 0)
- return -ENOENT;
+ if (pos >= data_end) {
+ off_t tmp_off;
+ size_t data_size;
+
+ if (pos >= mirror_end || !src) {
+ rc = llapi_mirror_find(layout, pos, end,
+ &mirror_end);
+ if (rc < 0)
+ return rc;
+ src = rc;
+ /* restrict mirror end by resync end */
+ mirror_end = MIN(end, mirror_end);
+ }
- if (mirror_end == OBD_OBJECT_EOF) {
- bytes_left = count;
- } else {
- bytes_left = MIN(count, mirror_end - pos);
- bytes_left = ((bytes_left - 1) | (page_size - 1)) + 1;
+ tmp_off = llapi_mirror_data_seek(fd, src, pos,
+ &data_size);
+ if (tmp_off < 0) {
+ /* switch to full copy */
+ to_read = mirror_end - pos;
+ goto do_read;
+ }
+ data_off = tmp_off;
+ data_end = data_off + data_size;
+
+ data_off = MIN(data_off, mirror_end);
+ data_end = MIN(data_end, mirror_end);
+
+ /* align by page, if there is data block to copy */
+ if (data_size)
+ data_off &= ~(page_size - 1);
+ }
+
+ if (pos < data_off) {
+ for (i = 0; i < comp_size; i++) {
+ uint64_t cur_pos;
+ size_t to_punch;
+ uint32_t mid = comp_array[i].lrc_mirror_id;
+
+ /* skip non-overlapped component */
+ if (pos >= comp_array[i].lrc_end ||
+ data_off <= comp_array[i].lrc_start)
+ continue;
+
+ if (pos < comp_array[i].lrc_start)
+ cur_pos = comp_array[i].lrc_start;
+ else
+ cur_pos = pos;
+
+ if (data_off > comp_array[i].lrc_end)
+ to_punch = comp_array[i].lrc_end -
+ cur_pos;
+ else
+ to_punch = data_off - cur_pos;
+
+ if (comp_array[i].lrc_end == OBD_OBJECT_EOF) {
+ /* the last component can be truncated
+ * safely
+ */
+ rc = llapi_mirror_truncate(fd, mid,
+ cur_pos);
+ /* hole at the end of file, so just
+ * truncate up to set size.
+ */
+ if (!rc && data_off == data_end)
+ rc = llapi_mirror_truncate(fd,
+ mid, data_end);
+ } else {
+ rc = llapi_mirror_punch(fd,
+ comp_array[i].lrc_mirror_id,
+ cur_pos, to_punch);
+ }
+ /* if failed then read failed hole range */
+ if (rc < 0) {
+ rc = 0;
+ pos = cur_pos;
+ if (pos + to_punch == data_off)
+ to_read = data_end - pos;
+ else
+ to_read = to_punch;
+ goto do_read;
+ }
+ }
+ pos = data_off;
}
- to_read = MIN(buflen, bytes_left);
+ if (pos == mirror_end)
+ continue;
+ to_read = data_end - pos;
+do_read:
+ if (!to_read)
+ break;
+
+ assert(data_end <= mirror_end);
+ to_read = MIN(buflen, to_read);
+ to_read = ((to_read - 1) | (page_size - 1)) + 1;
bytes_read = llapi_mirror_read(fd, src, buf, to_read, pos);
if (bytes_read == 0) {
/* end of file */
* meanings.
*/
comp_array[i].lrc_synced = true;
+ llapi_error(LLAPI_MSG_ERROR, written,
+ "component %u not synced",
+ comp_array[i].lrc_id);
+ if (rc2 == 0)
+ rc2 = (int)written;
continue;
}
assert(written == to_write2);
}
-
pos += bytes_read;
- count -= bytes_read;
}
free(buf);
if (rc < 0) {
+ /* fatal error happens */
for (i = 0; i < comp_size; i++)
comp_array[i].lrc_synced = false;
return rc;
}
+ /**
+ * no fatal error happens, each lrc_synced tells whether the component
+ * has been resync successfully (note: we'd reverse the value to
+ * reflect its true meaning.
+ */
for (i = 0; i < comp_size; i++) {
comp_array[i].lrc_synced = !comp_array[i].lrc_synced;
if (comp_array[i].lrc_synced && pos & (page_size - 1)) {
rc = llapi_mirror_truncate(fd,
comp_array[i].lrc_mirror_id, pos);
- if (rc < 0)
+ /* Ignore truncate error on encrypted file without the
+ * key if tried on LUSTRE_ENCRYPTION_UNIT_SIZE boundary.
+ */
+ if (rc < 0 && (rc != -ENOKEY ||
+ pos & ~LUSTRE_ENCRYPTION_MASK))
comp_array[i].lrc_synced = false;
}
}
- /* partially successful is successful */
- return 0;
+ /**
+ * returns the first error code for partially successful resync if
+ * possible.
+ */
+ return rc2;
}
enum llapi_layout_comp_sanity_error {
LSE_FLAGS,
LSE_DOM_EXTENSION,
LSE_DOM_EXTENSION_FOLLOWING,
- LSE_DOM_FLR,
+ LSE_DOM_FIRST,
LSE_SET_COMP_START,
LSE_NOT_ZERO_LENGTH_EXTENDABLE,
LSE_END_NOT_GREATER,
LSE_START_GT_END,
LSE_ALIGN_END,
LSE_ALIGN_EXT,
+ LSE_UNKNOWN_OST,
+ LSE_LAST,
+};
+
+const char *const llapi_layout_strerror[] =
+{
+ [LSE_OK] = "",
+ [LSE_INCOMPLETE_MIRROR] =
+ "Incomplete mirror - must go to EOF",
+ [LSE_ADJACENT_EXTENSION] =
+ "No adjacent extension space components",
+ [LSE_INIT_EXTENSION] =
+ "Cannot apply extension flag to init components",
+ [LSE_FLAGS] =
+ "Wrong flags",
+ [LSE_DOM_EXTENSION] =
+ "DoM components can't be extension space",
+ [LSE_DOM_EXTENSION_FOLLOWING] =
+ "DoM components cannot be followed by extension space",
+ [LSE_DOM_FIRST] =
+ "DoM component should be the first one in a file/mirror",
+ [LSE_SET_COMP_START] =
+ "Must set previous component extent before adding next",
+ [LSE_NOT_ZERO_LENGTH_EXTENDABLE] =
+ "Extendable component must start out zero-length",
+ [LSE_END_NOT_GREATER] =
+ "Component end is before end of previous component",
+ [LSE_ZERO_LENGTH_NORMAL] =
+ "Zero length components must be followed by extension",
+ [LSE_NOT_ADJACENT_PREV] =
+ "Components not adjacent (end != next->start",
+ [LSE_START_GT_END] =
+ "Component start is > end",
+ [LSE_ALIGN_END] =
+ "The component end must be aligned by the stripe size",
+ [LSE_ALIGN_EXT] =
+ "The extension size must be aligned by the stripe size",
+ [LSE_UNKNOWN_OST] =
+ "An unknown OST idx is specified",
};
struct llapi_layout_sanity_args {
+ char lsa_fsname[MAX_OBD_NAME + 1];
bool lsa_incomplete;
bool lsa_flr;
bool lsa_ondisk;
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)
+
+/**
+ * When modified, adjust llapi_stripe_param_verify() if needed as well.
+ */
static int llapi_layout_sanity_cb(struct llapi_layout *layout,
void *arg)
{
if (comp->llc_flags & ~LCME_USER_COMP_FLAGS)
args->lsa_rc = LSE_FLAGS;
} else {
- if (comp->llc_flags & ~LCME_FL_EXTENSION)
+ if (comp->llc_flags &
+ ~(LCME_FL_EXTENSION | LCME_FL_PREF_RW))
args->lsa_rc = LSE_FLAGS;
}
}
goto out_err;
}
- /* DoM and FLR are not supported together */
- if (args->lsa_flr && first_comp) {
- args->lsa_rc = LSE_DOM_FLR;
- errno = ENOTSUP;
+ /* DoM should be the first component in a mirror */
+ if (!first_comp) {
+ args->lsa_rc = LSE_DOM_FIRST;
+ errno = EINVAL;
goto out_err;
}
}
/* Components not followed by ext space must have length > 0. */
if (comp->llc_extent.e_start == comp->llc_extent.e_end &&
- next && !(next->llc_flags & LCME_FL_EXTENSION)) {
+ (next == NULL || !(next->llc_flags & LCME_FL_EXTENSION))) {
args->lsa_rc = LSE_ZERO_LENGTH_NORMAL;
goto out_err;
}
} else if (!(comp->llc_flags & LCME_FL_EXTENSION) &&
(comp->llc_stripe_size != LLAPI_LAYOUT_DEFAULT)) {
if (comp->llc_extent.e_end != LUSTRE_EOF &&
+ comp->llc_extent.e_end !=
+ comp->llc_extent.e_start &&
comp->llc_extent.e_end % comp->llc_stripe_size) {
args->lsa_rc = LSE_ALIGN_END;
goto out_err;
goto out_err;
}
+ if (args->lsa_fsname[0] != '\0') {
+ int i, rc = 0;
+
+ if (comp->llc_pattern & LLAPI_LAYOUT_SPECIFIC) {
+ assert(comp->llc_stripe_count <=
+ comp->llc_objects_count);
+
+ for (i = 0; i < comp->llc_stripe_count && rc == 0; i++){
+ if (comp->llc_objects[i].l_ost_idx ==
+ LLAPI_LAYOUT_IDX_MAX) {
+ args->lsa_rc = -1;
+ goto out_err;
+ }
+ rc = llapi_layout_search_ost(
+ comp->llc_objects[i].l_ost_idx,
+ comp->llc_pool_name, args->lsa_fsname);
+ }
+ } else if (comp->llc_stripe_offset != LLAPI_LAYOUT_DEFAULT) {
+ rc = llapi_layout_search_ost(
+ comp->llc_stripe_offset,
+ comp->llc_pool_name, args->lsa_fsname);
+ }
+ if (rc) {
+ args->lsa_rc = LSE_UNKNOWN_OST;
+ goto out_err;
+ }
+ }
+
return LLAPI_LAYOUT_ITER_CONT;
out_err:
/* Print explanation of layout error */
void llapi_layout_sanity_perror(int error)
{
- char *msg = NULL;
-
- switch (error) {
- case LSE_OK:
- break;
- case LSE_INCOMPLETE_MIRROR:
- msg = "Incomplete mirror - must go to EOF";
- break;
- case LSE_ADJACENT_EXTENSION:
- msg = "No adjacent extension space components";
- break;
- case LSE_INIT_EXTENSION:
- msg = "Cannot apply extension flag to init components";
- break;
- case LSE_FLAGS:
- msg = "Wrong flags";
- break;
- case LSE_DOM_EXTENSION:
- msg = "DoM components can't be extension space";
- break;
- case LSE_DOM_EXTENSION_FOLLOWING:
- msg = "DoM components cannot be followed by extension space";
- break;
- case LSE_DOM_FLR:
- msg = "FLR and DoM are not supported together";
- break;
- case LSE_SET_COMP_START:
- msg = "Must set previous component extent before adding next";
- break;
- case LSE_NOT_ZERO_LENGTH_EXTENDABLE:
- msg = "Extendable component must start out zero-length";
- break;
- case LSE_END_NOT_GREATER:
- msg = "Component end is before end of previous component";
- break;
- case LSE_ZERO_LENGTH_NORMAL:
- msg = "Zero length components must be followed by extension";
- break;
- case LSE_NOT_ADJACENT_PREV:
- msg = "Components not adjacent (end != next->start";
- break;
- case LSE_START_GT_END:
- msg = "Component start is > end";
- case LSE_ALIGN_END:
- msg = "The component end must be aligned by the stripe size";
- break;
- case LSE_ALIGN_EXT:
- msg = "The extension size must be aligned by the stripe size";
- break;
- default:
+ if (error >= LSE_LAST || error < 0) {
fprintf(stdout, "Invalid layout, unrecognized error: %d\n",
error);
+ } else {
+ fprintf(stdout, "Invalid layout: %s\n",
+ llapi_layout_strerror[error]);
}
-
- if (msg)
- fprintf(stdout, "Invalid layout: %s\n", msg);
}
/* Walk a layout and enforce sanity checks that apply to > 1 component
* components"?
*
* \param[in] layout component layout list.
+ * \param[in] fname file the layout to be checked for
* \param[in] incomplete if layout is complete or not - some checks can
* only be done on complete layouts.
* \param[in] flr set when this is called from FLR mirror create
* \retval 0, success, positive: various errors, see
* llapi_layout_sanity_perror, -1, failure
*/
-int llapi_layout_sanity(struct llapi_layout *layout, bool incomplete, bool flr)
+int llapi_layout_sanity(struct llapi_layout *layout,
+ const char *fname,
+ bool incomplete,
+ bool flr)
{
- struct llapi_layout_sanity_args args;
+ struct llapi_layout_sanity_args args = { { 0 } };
struct llapi_layout_comp *curr;
int rc = 0;
if (!curr)
return 0;
+ /* Make sure we are on a Lustre file system */
+ if (fname) {
+ rc = llapi_search_fsname(fname, args.lsa_fsname);
+ if (rc) {
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "'%s' is not on a Lustre filesystem",
+ fname);
+ return rc;
+ }
+ }
+
/* Set up args */
args.lsa_rc = 0;
args.lsa_flr = flr;
return rc;
}
+
+int llapi_layout_dom_size(struct llapi_layout *layout, uint64_t *size)
+{
+ uint64_t pattern, start;
+ int rc;
+
+ if (!layout || !llapi_layout_is_composite(layout)) {
+ *size = 0;
+ return 0;
+ }
+
+ rc = llapi_layout_comp_use(layout, LLAPI_LAYOUT_COMP_USE_FIRST);
+ if (rc)
+ return -errno;
+
+ rc = llapi_layout_pattern_get(layout, &pattern);
+ if (rc)
+ return -errno;
+
+ if (pattern != LOV_PATTERN_MDT && pattern != LLAPI_LAYOUT_MDT) {
+ *size = 0;
+ return 0;
+ }
+
+ rc = llapi_layout_comp_extent_get(layout, &start, size);
+ if (rc)
+ return -errno;
+ if (start)
+ return -ERANGE;
+ 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;
+}