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 <andreas.dilger@intel.com>
Change-Id: I45b10156ac0081b2246b15c6790e42764b5cab07
Reviewed-on: https://review.whamcloud.com/26486
Reviewed-by: Jinshan Xiong <jinshan.xiong@intel.com>
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Bobi Jam <bobijam@hotmail.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
-.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.
.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
.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()
.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)
-.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.
-.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
-.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.
__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);
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;
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);
}
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++;
}
/* 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)
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;
}
/**
* 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
*
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;