From 3709019d713144a82b9914c7723cb841275962b7 Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Fri, 7 Apr 2017 16:34:04 -0600 Subject: [PATCH] LU-8998 misc: minor clean ups Use LCME_ID_INVAL instead of comparing component IDs to 0. Swab layout fields in lfsck_lmm2layout() to match existing usage. Handle the (potential) case where LCME_ID_MAX isn't ~LCME_ID_MASK. Fix man page dates. Test-Parameters: trivial testlist=sanity-pfl Signed-off-by: Andreas Dilger Change-Id: I45b10156ac0081b2246b15c6790e42764b5cab07 Reviewed-on: https://review.whamcloud.com/26486 Reviewed-by: Jinshan Xiong Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Bobi Jam Reviewed-by: Oleg Drokin --- lustre/doc/llapi_layout_comp_add.3 | 14 ++++++++------ lustre/doc/llapi_layout_comp_extent_get.3 | 2 +- lustre/doc/llapi_layout_comp_flags_get.3 | 2 +- lustre/doc/llapi_layout_file_comp_add.3 | 2 +- lustre/lfsck/lfsck_layout.c | 15 ++++++++------- lustre/lod/lod_internal.h | 18 ++++++++++++------ lustre/lod/lod_lov.c | 11 ++++++----- lustre/utils/liblustreapi_layout.c | 7 ++++--- 8 files changed, 41 insertions(+), 30 deletions(-) diff --git a/lustre/doc/llapi_layout_comp_add.3 b/lustre/doc/llapi_layout_comp_add.3 index 7df9851..1ea53b7 100644 --- a/lustre/doc/llapi_layout_comp_add.3 +++ b/lustre/doc/llapi_layout_comp_add.3 @@ -1,4 +1,4 @@ -.TH llapi_layout_comp_add 3 "2015 Nov 4" "Lustre User API" +.TH llapi_layout_comp_add 3 "2017 Apr 7" "Lustre User API" .SH NAME llapi_layout_comp_add, llapi_layout_comp_del \- add or delete a layout component into/from the layout. @@ -19,9 +19,9 @@ A composite layout is made of several layout components. .BR llapi_layout_comp_add (3) adds the layout component .I comp -into the -.IR layout . -The +into the in-memory +.IR layout +under construction. The .IR layout will be turned into composite if it was plain before adding. All layout attributes of @@ -34,8 +34,9 @@ functions. .BR llapi_layout_comp_del (3) deletes the layout component .I comp -from the -.IR layout . +from the in-memory +.IR layout , +but does not delete the component from an existing file layout on the MDT. .PP .SH RETURN VALUES .B llapi_layout_comp_add() @@ -52,5 +53,6 @@ An invalid argument was specified. .BR llapi_layout_free (3), .BR llapi_layout_file_open (3), .BR llapi_layout_file_comp_add (3), +.BR llapi_layout_file_comp_del (3), .BR llapi_layout (7), .BR lustreapi (7) diff --git a/lustre/doc/llapi_layout_comp_extent_get.3 b/lustre/doc/llapi_layout_comp_extent_get.3 index a13019a..c2b9dd7 100644 --- a/lustre/doc/llapi_layout_comp_extent_get.3 +++ b/lustre/doc/llapi_layout_comp_extent_get.3 @@ -1,4 +1,4 @@ -.TH llapi_layout_comp_extent_get 3 "2015 Nov 4" "Lustre User API" +.TH llapi_layout_comp_extent_get 3 "2017 Apr 7" "Lustre User API" .SH NAME llapi_layout_comp_extent_get, llapi_layout_comp_extent_set \- get or set the extent of a layout component. diff --git a/lustre/doc/llapi_layout_comp_flags_get.3 b/lustre/doc/llapi_layout_comp_flags_get.3 index a27844a..f20bffb 100644 --- a/lustre/doc/llapi_layout_comp_flags_get.3 +++ b/lustre/doc/llapi_layout_comp_flags_get.3 @@ -1,4 +1,4 @@ -.TH llapi_layout_comp_flags_get 3 "2015 Nov 4" "Lustre User API" +.TH llapi_layout_comp_flags_get 3 "2017 Apr 7" "Lustre User API" .SH NAME llapi_layout_comp_flags_get, llapi_layout_comp_flags_set, llapi_layout_comp_flags_clear \- get, set or clear the flags of a layout diff --git a/lustre/doc/llapi_layout_file_comp_add.3 b/lustre/doc/llapi_layout_file_comp_add.3 index 61e318f..0d90965 100644 --- a/lustre/doc/llapi_layout_file_comp_add.3 +++ b/lustre/doc/llapi_layout_file_comp_add.3 @@ -1,4 +1,4 @@ -.TH llapi_layout_file_comp_add 3 "2015 Nov 4" "Lustre User API" +.TH llapi_layout_file_comp_add 3 "2017 Apr 7" "Lustre User API" .SH NAME llapi_layout_file_comp_add \- add one or more components into an existing file. diff --git a/lustre/lfsck/lfsck_layout.c b/lustre/lfsck/lfsck_layout.c index 4773b81..1d8ab14 100644 --- a/lustre/lfsck/lfsck_layout.c +++ b/lustre/lfsck/lfsck_layout.c @@ -388,7 +388,8 @@ static int lfsck_layout_verify_header(struct dt_object *obj, __u64 end = le64_to_cpu(lcme->lcme_extent.e_end); __u32 comp_id = le32_to_cpu(lcme->lcme_id); - if (unlikely(comp_id == 0 || comp_id > LCME_ID_MAX)) { + if (unlikely(comp_id == LCME_ID_INVAL || + comp_id > LCME_ID_MAX)) { CDEBUG(D_LFSCK, "found invalid FPL ID %u " "for the file "DFID" at idx %d\n", comp_id, PFID(lfsck_dto2fid(obj)), i); @@ -3208,7 +3209,7 @@ static int lfsck_lmm2layout(struct lov_mds_md_v1 *lmm, struct ost_layout *ol, ol->ol_comp_id = 0; } else if (magic == LOV_MAGIC_COMP_V1) { struct lov_comp_md_v1 *lcm = (struct lov_comp_md_v1 *)lmm; - struct lov_comp_md_entry_v1 *lcme; + struct lov_comp_md_entry_v1 *lcme = NULL; __u16 count = le16_to_cpu(lcm->lcm_entry_count); int i; @@ -3227,11 +3228,11 @@ static int lfsck_lmm2layout(struct lov_mds_md_v1 *lmm, struct ost_layout *ol, GOTO(out, rc = 1); lmm = (void *)lmm + le32_to_cpu(lcme->lcme_offset); - ol->ol_stripe_size = lmm->lmm_stripe_size; - ol->ol_stripe_count = lmm->lmm_stripe_count; - ol->ol_comp_start = lcme->lcme_extent.e_start; - ol->ol_comp_end = lcme->lcme_extent.e_end; - ol->ol_comp_id = lcme->lcme_id; + ol->ol_stripe_size = le32_to_cpu(lmm->lmm_stripe_size); + ol->ol_stripe_count = le32_to_cpu(lmm->lmm_stripe_count); + ol->ol_comp_start = le64_to_cpu(lcme->lcme_extent.e_start); + ol->ol_comp_end = le64_to_cpu(lcme->lcme_extent.e_end); + ol->ol_comp_id = le32_to_cpu(lcme->lcme_id); } else { GOTO(out, rc = -EINVAL); } diff --git a/lustre/lod/lod_internal.h b/lustre/lod/lod_internal.h index 7bd32ff..f92bb0e 100644 --- a/lustre/lod/lod_internal.h +++ b/lustre/lod/lod_internal.h @@ -336,17 +336,23 @@ static inline int lod_obj_set_pool(struct lod_object *lo, int i, new_pool); } -/* - * Layout generation is used to generate unique component ID, to check ID - * collision, we preserve the highest bit of the layout generation when it - * wrapped. +/** + * Create new layout generation. + * + * The only requirement for layout generation is that it changes when + * the layout is modified, so a circular counter is sufficient for the + * low rate of layout modifications. + * + * Layout generation is also used to generate unique component ID. + * To detect generation overflow, we preserve the highest bit of the + * generation when it wrapped. */ static inline void lod_obj_inc_layout_gen(struct lod_object *lo) { - __u32 preserve = lo->ldo_layout_gen & LCME_ID_NONE; + __u32 preserve = lo->ldo_layout_gen & ~LCME_ID_MASK; lo->ldo_layout_gen++; lo->ldo_layout_gen |= preserve; - /* Zero is not a valid component ID */ + /* Zero is not a valid generation */ if (unlikely((lo->ldo_layout_gen & LCME_ID_MASK) == 0)) lo->ldo_layout_gen++; } diff --git a/lustre/lod/lod_lov.c b/lustre/lod/lod_lov.c index bc1b70d..50b3998 100644 --- a/lustre/lod/lod_lov.c +++ b/lustre/lod/lod_lov.c @@ -869,9 +869,9 @@ static __u32 lod_gen_component_id(struct lod_object *lo, int comp_idx) /* Layout generation wraps, need to check collisions. */ start = id & LCME_ID_MASK; - end = (__u32)LCME_ID_MAX + 1; + end = LCME_ID_MAX; again: - for (id = start; id < end; id++) { + for (id = start; id <= end; id++) { for (i = 0; i < lo->ldo_comp_cnt; i++) { lod_comp = &lo->ldo_comp_entries[i]; if (id == lod_comp->llc_id) @@ -881,9 +881,10 @@ again: if (i == lo->ldo_comp_cnt) return id; } - if (end == (__u32)LCME_ID_MAX + 1) { - start = 0; - end = lo->ldo_layout_gen & LCME_ID_MASK; + if (end > LCME_ID_MAX) { + start = 1; + end = min(lo->ldo_layout_gen & LCME_ID_MASK, + (__u32)(LCME_ID_MAX - 1)); goto again; } diff --git a/lustre/utils/liblustreapi_layout.c b/lustre/utils/liblustreapi_layout.c index 6136cff..7f364fd 100644 --- a/lustre/utils/liblustreapi_layout.c +++ b/lustre/utils/liblustreapi_layout.c @@ -1734,7 +1734,7 @@ int llapi_layout_comp_add(struct llapi_layout *layout) /** * Deletes current component from the composite layout. The component * to be deleted must be the tail of components list, and it can't be - * the last component in the layout. + * the only component in the layout. * * \param[in] layout composite layout * @@ -1754,12 +1754,13 @@ int llapi_layout_comp_del(struct llapi_layout *layout) return -1; } - /* It must be the tail of the list */ + /* It must be the tail of the list (for PFL, can be relaxed + * once we get mirrored components) */ if (comp->llc_list.next != &layout->llot_comp_list) { errno = EINVAL; return -1; } - /* It can't be the last one on the list */ + /* It can't be the only one on the list */ if (comp->llc_list.prev == &layout->llot_comp_list) { errno = EINVAL; return -1; -- 1.8.3.1