-.TH llapi_layout_comp_id_get 3 "2015 Nov 4" "Lustre User API"
+.TH llapi_layout_comp_id_get 3 "2017 Apr 7" "Lustre User API"
.SH NAME
llapi_layout_comp_id_get \- get the ID of a layout component.
.SH SYNOPSIS
.B #include <lustre/lustreapi.h>
.PP
.BI "int llapi_layout_comp_id_get(const struct llapi_layout *" layout ",
-.BI " uint32_t *" id );
+.BI " uint32_t *" comp_id );
.fi
.SH DESCRIPTION
.PP
-Return the unique numeric
-.I id
-of the current component of
+Return the unique numeric ID
+.I comp_id
+of the currently active component of
.IR layout .
+The ID of a component is a unique numeric identifier for the component
+within the layout of each file, and no age, ordering, relative position,
+or other sematics are implied by the component ID. If a file's layout
+is modified a large number of times, the component ID may be re-used
+but will always be unique within a single file's layout.
.PP
.SH RETURN VALUES
-Return 0 on success, or -1 if an error occurred (in which case, errno is
-set appropriately).
+Return 0 on success. Return -1 if an error occurred and set errno
+appropriately.
.SH ERRORS
.TP 15
.SM EINVAL
.SH "SEE ALSO"
.BR llapi_layout_alloc (3),
.BR llapi_layout_file_open (3),
+.BR llapi_layout_comp_use_id (3),
.BR llapi_layout (7),
.BR lustreapi (7)
.BR LLAPI_LAYOUT_COMP_USE_FIRST :
The first component of the layout.
.PP
+.BR LLAPI_LAYOUT_COMP_USE_LAST :
+The last component of the layout.
+.PP
.BR LLAPI_LAYOUT_COMP_USE_NEXT :
The next component after the current one.
.PP
-.BR LLAPI_LAYOUT_COMP_USE_LAST :
-The last component of the layout.
+.BR LLAPI_LAYOUT_COMP_USE_PREV :
+The previous component before the current one.
.SH RETURN VALUES
-Return 0 on success, and 1 when there is no next component. Otherwise,
-if an error occurred -1 is returned and
+Return 0 on success, and 1 when there is no next or previous component.
+Otherwise, if an error occurred -1 is returned and
.I errno
is set appropriately.
.SH ERRORS
LLAPI_LAYOUT_COMP_USE_FIRST = 1,
LLAPI_LAYOUT_COMP_USE_LAST = 2,
LLAPI_LAYOUT_COMP_USE_NEXT = 3,
+ LLAPI_LAYOUT_COMP_USE_PREV = 4,
};
/**
i++;
} while (rc == 0);
+ /* Verify reverse iteration gives the same IDs as forward iteration */
+ rc = llapi_layout_comp_use(layout, LLAPI_LAYOUT_COMP_USE_LAST);
+ ASSERTF(rc == 0, "rc %d, errno %d", rc, errno);
+ do {
+ __u32 comp_id;
+
+ --i;
+ rc = llapi_layout_comp_id_get(layout, &comp_id);
+ ASSERTF(rc == 0 && comp_id == id[i],
+ "i %d, errno %d, id[] %u/%u", i, errno, id[i], comp_id);
+
+ rc = llapi_layout_comp_use(layout, LLAPI_LAYOUT_COMP_USE_PREV);
+ ASSERTF(rc == 0 || i == 0, "i=%d rc=%d errno=%d", i, rc, errno);
+ } while (rc == 0);
+
llapi_layout_free(layout);
/* delete non-tail component will fail */
* \param[in] pos the position to be moved, it can be:
* LLAPI_LAYOUT_COMP_USE_FIRST: use first component
* LLAPI_LAYOUT_COMP_USE_LAST: use last component
- * LLAPI_LAYOUT_COMP_USE_NEXT: use next component
+ * LLAPI_LAYOUT_COMP_USE_NEXT: use component after current
+ * LLAPI_LAYOUT_COMP_USE_PREV: use component before current
*
* \retval =0 : moved successfully
- * \retval =1 : at last component with NEXT
+ * \retval =1 : at last component with NEXT, at first component with PREV
* \retval <0 if error occurs
*/
-int llapi_layout_comp_use(struct llapi_layout *layout, uint32_t pos)
+int llapi_layout_comp_use(struct llapi_layout *layout,
+ enum llapi_layout_comp_use pos)
{
struct llapi_layout_comp *comp, *head, *tail;
return -1;
}
- head = list_entry(layout->llot_comp_list.next, typeof(*head),
- llc_list);
- tail = list_entry(layout->llot_comp_list.prev, typeof(*tail),
- llc_list);
-
- if (pos == LLAPI_LAYOUT_COMP_USE_NEXT) {
- if (comp == tail)
+ head = list_entry(layout->llot_comp_list.next, typeof(*head), llc_list);
+ tail = list_entry(layout->llot_comp_list.prev, typeof(*tail), llc_list);
+ switch (pos) {
+ case LLAPI_LAYOUT_COMP_USE_FIRST:
+ layout->llot_cur_comp = head;
+ break;
+ case LLAPI_LAYOUT_COMP_USE_NEXT:
+ if (comp == tail) {
+ errno = ENOENT;
return 1;
+ }
layout->llot_cur_comp = list_entry(comp->llc_list.next,
typeof(*comp), llc_list);
- } else if (pos == LLAPI_LAYOUT_COMP_USE_FIRST) {
- layout->llot_cur_comp = head;
- } else if (pos == LLAPI_LAYOUT_COMP_USE_LAST) {
+ break;
+ case LLAPI_LAYOUT_COMP_USE_LAST:
layout->llot_cur_comp = tail;
- } else {
+ break;
+ case LLAPI_LAYOUT_COMP_USE_PREV:
+ if (comp == head) {
+ errno = ENOENT;
+ return 1;
+ }
+ layout->llot_cur_comp = list_entry(comp->llc_list.prev,
+ typeof(*comp), llc_list);
+ break;
+ default:
errno = EINVAL;
return -1;
}