X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Futils%2Fliblustreapi_layout.c;h=123a491785d3598c2012e0b55c6ddf1812c26e3e;hb=0ab950762cdec28636b6033c50a2e563c28ba954;hp=aefde5df268c06a2991374f9dbb01b437c97ab80;hpb=3e23353201a753104d1fcdab28353646e40644dc;p=fs%2Flustre-release.git diff --git a/lustre/utils/liblustreapi_layout.c b/lustre/utils/liblustreapi_layout.c index aefde5d..123a491 100644 --- a/lustre/utils/liblustreapi_layout.c +++ b/lustre/utils/liblustreapi_layout.c @@ -2702,6 +2702,71 @@ error: } /** + * 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. @@ -3003,7 +3068,7 @@ enum llapi_layout_comp_sanity_error { LSE_LAST, }; -const char *llapi_layout_strerror[] = +const char *const llapi_layout_strerror[] = { [LSE_OK] = "", [LSE_INCOMPLETE_MIRROR] = @@ -3045,6 +3110,10 @@ struct llapi_layout_sanity_args { 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) { @@ -3110,7 +3179,8 @@ static int llapi_layout_sanity_cb(struct llapi_layout *layout, 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; } } @@ -3361,7 +3431,9 @@ int llapi_get_lum_file_fd(int dir_fd, const char *fname, __u64 *valid, if (rc) return rc; - *valid = lmd->lmd_flags; + if (valid) + *valid = lmd->lmd_flags; + if (statx) memcpy(statx, &lmd->lmd_stx, sizeof(*statx));