From b82b12265b976bdb044a752bfd27b2494edfffbd Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Thu, 23 Feb 2017 15:17:16 +0800 Subject: [PATCH] btrfs-progs: convert: Introduce function to read out btrfs reserved range Introduce a new function, read_reserved_ranges(), to allow later rollback to use these data to do rollback. Signed-off-by: Qu Wenruo --- convert/main.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/convert/main.c b/convert/main.c index 8fcfd36b..69279506 100644 --- a/convert/main.c +++ b/convert/main.c @@ -1513,6 +1513,36 @@ fail: return -1; } +/* + * Read out data of convert image which is in btrfs reserved ranges so we can + * use them to overwrite the ranges during rollback. + */ +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 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;