@@ -2749,6 +2749,37 @@ fail:
return -1;
}
+/*
+ * Read out data of convert image which is in btrfs reserved range.
+ *
+ * So rollback can just use these data to overwrite these ranges of btrfs
+ */
+static int read_reserved_ranges(struct btrfs_root *root, u64 ino,
+ u64 total_bytes, char *reserved_ranges[])
+{
+ int i;
+ int ret = 0;
+
+ for (i = 0; i < ARRAY_SIZE(btrfs_reserved_ranges); i++) {
+ struct simple_range *range = &btrfs_reserved_ranges[i];
+
+ if (range->start + range->len >= total_bytes)
+ break;
+ ret = btrfs_read_file(root, ino, range->start, range->len,
+ reserved_ranges[i]);
+ if (ret < range->len) {
+ error(
+ "failed to read out data of convert image, offset=%llu len=%llu ret=%d",
+ range->start, range->len, ret);
+ if (ret >= 0)
+ ret = -EIO;
+ break;
+ }
+ ret = 0;
+ }
+ return ret;
+}
+
static int do_rollback(const char *devname)
{
int fd = -1;
Introduce a new function, read_reserved_ranges(), to allow later rollback to use these data to do rollback. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> --- convert/main.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)