-struct resync_comp {
- uint64_t start;
- uint64_t end;
- uint32_t mirror_id;
- uint32_t id; /* component id */
- bool synced;
-};
-
-/* find all stale components */
-static size_t mirror_find_stale(struct llapi_layout *layout,
- struct resync_comp *comp, size_t max_count)
-{
- int idx = 0;
- int rc;
-
- rc = llapi_layout_comp_use(layout, LLAPI_LAYOUT_COMP_USE_FIRST);
- syserr(rc < 0, "llapi_layout_comp_move");
-
- while (rc == 0) {
- uint32_t id;
- uint32_t mirror_id;
- uint32_t flags;
- uint64_t start, end;
-
- rc = llapi_layout_mirror_id_get(layout, &mirror_id);
- syserr(rc < 0, "llapi_layout_comp_id_get");
-
- rc = llapi_layout_comp_id_get(layout, &id);
- syserr(rc < 0, "llapi_layout_comp_id_get");
-
- rc = llapi_layout_comp_flags_get(layout, &flags);
- syserr(rc < 0, "llapi_layout_comp_flags_get");
-
- rc = llapi_layout_comp_extent_get(layout, &start, &end);
- syserr(rc < 0, "llapi_layout_comp_flags_get");
-
- if (flags & LCME_FL_STALE) {
- comp[idx].id = id;
- comp[idx].mirror_id = mirror_id;
- comp[idx].start = start;
- comp[idx].end = end;
- idx++;
-
- syserr(idx >= max_count, "array too small");
- }
-
- rc = llapi_layout_comp_use(layout, LLAPI_LAYOUT_COMP_USE_NEXT);
- syserr(rc < 0, "llapi_layout_comp_move");
- }
-
- return idx;
-}
-
-/* locate @layout to a valid component covering file [file_start, file_end) */
-static uint32_t mirror_find(struct llapi_layout *layout,
- uint64_t file_start, uint64_t file_end, uint64_t *endp)
-{
- uint32_t mirror_id = 0;
- int rc;
-
- rc = llapi_layout_comp_use(layout, LLAPI_LAYOUT_COMP_USE_FIRST);
- syserr(rc < 0, "llapi_layout_comp_move");
-
- *endp = 0;
- while (rc == 0) {
- uint64_t start, end;
- uint32_t flags, id, rid;
-
- llapi_layout_mirror_id_get(layout, &rid);
- syserr(rc < 0, "llapi_layout_mirror_id_get");
-
- rc = llapi_layout_comp_id_get(layout, &id);
- syserr(rc < 0, "llapi_layout_comp_id_get");
-
- rc = llapi_layout_comp_flags_get(layout, &flags);
- syserr(rc < 0, "llapi_layout_comp_flags_get");
-
- rc = llapi_layout_comp_extent_get(layout, &start, &end);
- syserr(rc < 0, "llapi_layout_comp_extent_get");
-
- if (!(flags & LCME_FL_STALE)) {
- if (file_start >= start && file_start < end) {
- if (mirror_id == 0)
- mirror_id = rid;
- else if (mirror_id != rid || *endp != start)
- break;
-
- file_start = *endp = end;
- if (end >= file_end)
- break;
- }
- }
-
- rc = llapi_layout_comp_use(layout, LLAPI_LAYOUT_COMP_USE_NEXT);
- syserr(rc < 0, "llapi_layout_comp_move");
- }
-
- return mirror_id;
-}
-
-static char *endstr(uint64_t end)
-{
- static char buf[32];
-
- if (end == (uint64_t)-1)
- return "eof";
-
- snprintf(buf, sizeof(buf), "%lx", end);
- return buf;
-}
-
-static ssize_t mirror_resync_one(int fd, struct llapi_layout *layout,
- uint32_t dst, uint64_t start, uint64_t end)