All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Cc: <dsterba@suse.cz>
Subject: [PATCH v3 5/7] btrfs-progs: convert: Introduce function to read out btrfs reserved range
Date: Tue, 14 Mar 2017 16:05:07 +0800	[thread overview]
Message-ID: <20170314080509.31163-6-quwenruo@cn.fujitsu.com> (raw)
In-Reply-To: <20170314080509.31163-1-quwenruo@cn.fujitsu.com>

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 --git a/convert/main.c b/convert/main.c
index e834c6f9..505b4a70 100644
--- a/convert/main.c
+++ b/convert/main.c
@@ -1506,6 +1506,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++) {
+		const 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;
-- 
2.12.0




  parent reply	other threads:[~2017-03-14  8:05 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-14  8:05 [PATCH v3 0/7] convert: rollback rework Qu Wenruo
2017-03-14  8:05 ` [PATCH v3 1/7] btrfs-progs: convert: Add comment for the overall convert workflow Qu Wenruo
2017-03-14  8:05 ` [PATCH v3 2/7] btrfs-progs: convert: Introduce simple range structure for convert reserved ranges Qu Wenruo
2017-03-14  8:05 ` [PATCH v3 3/7] btrfs-progs: convert: Use reserved ranges array to cleanup open code Qu Wenruo
2017-03-14  8:05 ` [PATCH v3 4/7] btrfs-progs: file: Introduce function to read out file content Qu Wenruo
2017-03-14  8:05 ` Qu Wenruo [this message]
2017-03-14  8:05 ` [PATCH v3 6/7] btrfs-progs: convert: Introduce function to check if convert image is able to be rolled back Qu Wenruo
2017-03-14  8:05 ` [PATCH v3 7/7] btrfs-progs: convert: Rework rollback Qu Wenruo
2017-03-14 11:55 ` [PATCH v3 0/7] convert: rollback rework David Sterba
2017-03-14 11:55   ` David Sterba
2017-03-15  0:35     ` Qu Wenruo
2017-03-27 17:55       ` David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170314080509.31163-6-quwenruo@cn.fujitsu.com \
    --to=quwenruo@cn.fujitsu.com \
    --cc=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.