All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH v3 3/6] btrfs-progs: convert: Introduce function to record relocated ranges
Date: Mon, 19 Dec 2016 14:56:39 +0800	[thread overview]
Message-ID: <20161219065642.25078-4-quwenruo@cn.fujitsu.com> (raw)
In-Reply-To: <20161219065642.25078-1-quwenruo@cn.fujitsu.com>

Introduce a new function, record_reloc_data(), to read out any data that
is a subset of reserved btrfs ranges.

This function is mainly a compatible function for old convert behavior.
As old convert behavior only reloc super blocks (4K size), while the new
convert behavior will reloc 64K block.

So this function will truncate and map the file extents of the converted
image, and read out corresponding data for later rollback usage.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 convert/main.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/convert/main.c b/convert/main.c
index db6d371..87c52c1 100644
--- a/convert/main.c
+++ b/convert/main.c
@@ -2723,6 +2723,64 @@ static int is_range_intersection_of_reserved_ranges(u64 start, u64 len,
 	return 1;
 }
 
+/*
+ * Read out data in reserved_ranges and write them into @reloc_ranges
+ *
+ * This is mainly for old convert behavior.
+ * Which only relocs the super block (4K), while we now reloc 64K.
+ *
+ * So there is some range in reserved range but still mapped 1:1.
+ * We use this function to read them into @reloc_ranges
+ */
+static int record_reloc_data(struct btrfs_fs_info *fs_info,
+			     u64 old_offset, u64 disk_bytenr, u64 ram_len,
+			     char *reloc_ranges[3])
+{
+	/* Which reloc range we interests with, physical bytenr */
+	u64 reloc_start;
+	u64 reloc_len;
+
+	/*
+	 * File offset, which get truncated to above range,
+	 * Offset in image file
+	 */
+	u64 file_start;
+	u64 file_len;
+
+	/* Btrfs logical address, used for final reading*/
+	u64 logical_start;
+	u64 logical_len;
+	char *dest;
+	int nr;
+	int ret;
+
+	/* Check if the range intersects */
+	if (!is_range_intersection_of_reserved_ranges(old_offset, ram_len,
+						      &nr))
+		return 0;
+	reloc_start = reserved_range_starts[nr];
+	reloc_len = reserved_range_lens[nr];
+
+	/* Truncate the range to reserved ranges */
+	file_start = max(old_offset, reloc_start);
+	file_len = min(old_offset + ram_len, reloc_start + reloc_len) -
+			file_start;
+
+	/* Get btrfs logical address */
+	logical_start = file_start - old_offset + disk_bytenr;
+	logical_len = file_len;
+
+	dest = reloc_ranges[nr] + file_start - reloc_start;
+	ret = read_extent_data(fs_info->tree_root, dest, logical_start,
+				&logical_len, 0);
+	if (ret < 0)
+		return ret;
+	/* Short read, something went wrong */
+	if (logical_len != file_len)
+		return -EIO;
+	return 0;
+}
+
 static int do_rollback(const char *devname)
 {
 	int fd = -1;
-- 
2.10.2




  parent reply	other threads:[~2016-12-19  6:56 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-19  6:56 [PATCH v3 0/6] Convert rollback rework for v4.9 Qu Wenruo
2016-12-19  6:56 ` [PATCH v3 1/6] btrfs-progs: file-item: Fix wrong file extents inserted Qu Wenruo
2016-12-19  6:56 ` [PATCH v3 2/6] btrfs-progs: utils: Introduce basic set operations for range Qu Wenruo
2017-01-23 17:28   ` David Sterba
2017-01-24  0:40     ` Qu Wenruo
2017-01-23 17:40   ` David Sterba
2016-12-19  6:56 ` Qu Wenruo [this message]
2016-12-19  6:56 ` [PATCH v3 4/6] btrfs-progs: convert: Introduce new function to check if we can rollback Qu Wenruo
2016-12-19  6:56 ` [PATCH v3 5/6] btrfs-progs: convert: Switch to new rollback function Qu Wenruo
2016-12-20  5:36   ` Chandan Rajendra
2017-01-23 17:54   ` David Sterba
2017-01-24  0:44     ` Qu Wenruo
2017-01-24 16:37       ` David Sterba
2017-01-25  0:42         ` Qu Wenruo
2017-01-30 14:55           ` David Sterba
2016-12-19  6:56 ` [PATCH v3 6/6] btrfs-progs: convert-test: trigger chunk allocation after convert Qu Wenruo
2016-12-21 14:35 ` [PATCH v3 0/6] Convert rollback rework for v4.9 David Sterba
2016-12-22  1:53   ` Qu Wenruo

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=20161219065642.25078-4-quwenruo@cn.fujitsu.com \
    --to=quwenruo@cn.fujitsu.com \
    --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.