diff mbox

[v2,7/9] btrfs-progs: convert: Introduce function to read out btrfs reserved range

Message ID 20170224055232.4140-8-quwenruo@cn.fujitsu.com (mailing list archive)
State Accepted
Headers show

Commit Message

Qu Wenruo Feb. 24, 2017, 5:52 a.m. UTC
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(+)
diff mbox

Patch

diff --git a/convert/main.c b/convert/main.c
index 08df0111..a58716b5 100644
--- a/convert/main.c
+++ b/convert/main.c
@@ -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;