From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH v5 4/4] btrfs-progs: image: fix restored image size misalignment
Date: Mon, 28 Dec 2020 08:31:59 +0800 [thread overview]
Message-ID: <20201228003159.115343-5-wqu@suse.com> (raw)
In-Reply-To: <20201228003159.115343-1-wqu@suse.com>
[BUG]
There is a small device size misalignment between the super block device
size and the device extent size:
total_bytes 10737418240 <<<
bytes_used 15097856
dev_item.total_bytes 10737418240
dev_item.bytes_used 1094713344
item 0 key (DEV_ITEMS DEV_ITEM 1) itemoff 16185 itemsize 98
devid 1 total_bytes 1095761920 bytes_used 1094713344
^^^^^^^^^^
[CAUSE]
In fixup_device_size(), we only reset superblock device item size, which
will be overwritten in write_dev_supers() using
btrfs_device::total_bytes.
And it doesn't touch btrfs_superblock::total_bytes either.
[FIX]
So fix the small mismatch by also resetting btrfs_device::total_bytes,
btrfs_device::bytes_used and btrfs_superblock::total_bytes.
Thankfully since commit 73dd4e3c87c9 ("btrfs-progs: image: Don't modify
the chunk and device tree if the source dump is single device") single
device dump won't have such problem, but it's still worthy for
multi-device dump.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
image/main.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/image/main.c b/image/main.c
index 5fa6fa5aba17..42564b1d2f44 100644
--- a/image/main.c
+++ b/image/main.c
@@ -2374,6 +2374,7 @@ static int fixup_device_size(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info = trans->fs_info;
struct btrfs_dev_item *dev_item;
struct btrfs_dev_extent *dev_ext;
+ struct btrfs_device *dev;
struct btrfs_path path;
struct extent_buffer *leaf;
struct btrfs_root *root = fs_info->chunk_root;
@@ -2392,6 +2393,8 @@ static int fixup_device_size(struct btrfs_trans_handle *trans,
key.type = BTRFS_DEV_EXTENT_KEY;
key.offset = (u64)-1;
+ dev = list_first_entry(&fs_info->fs_devices->devices,
+ struct btrfs_device, dev_list);
ret = btrfs_search_slot(NULL, fs_info->dev_root, &key, &path, 0, 0);
if (ret < 0) {
errno = -ret;
@@ -2425,6 +2428,9 @@ static int fixup_device_size(struct btrfs_trans_handle *trans,
btrfs_set_stack_device_total_bytes(dev_item, dev_size);
btrfs_set_stack_device_bytes_used(dev_item, mdres->alloced_chunks);
+ dev->total_bytes = dev_size;
+ dev->bytes_used = mdres->alloced_chunks;
+ btrfs_set_super_total_bytes(fs_info->super_copy, dev_size);
ret = fstat(out_fd, &buf);
if (ret < 0) {
error("failed to stat result image: %m");
--
2.29.2
prev parent reply other threads:[~2020-12-28 0:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-28 0:31 [PATCH v5 0/4] btrfs-progs: image: new data dump feature Qu Wenruo
2020-12-28 0:31 ` [PATCH v5 1/4] btrfs-progs: image: introduce framework for more dump versions Qu Wenruo
2020-12-28 0:31 ` [PATCH v5 2/4] btrfs-progs: image: introduce -d option to dump data Qu Wenruo
2020-12-28 0:31 ` [PATCH v5 3/4] btrfs-progs: image: reduce memory requirement for decompression Qu Wenruo
2020-12-28 0:31 ` Qu Wenruo [this message]
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=20201228003159.115343-5-wqu@suse.com \
--to=wqu@suse.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox