From: Chandan Rajendra <chandan@linux.vnet.ibm.com>
To: linux-btrfs@vger.kernel.org
Cc: Chandan Rajendra <chandan@linux.vnet.ibm.com>, dsterba@suse.com
Subject: [PATCH 2/2] btrfs-convert: Fix migrate_super_block() to work with 64k sectorsize
Date: Thu, 8 Dec 2016 19:26:20 +0530 [thread overview]
Message-ID: <1481205380-22978-2-git-send-email-chandan@linux.vnet.ibm.com> (raw)
In-Reply-To: <1481205380-22978-1-git-send-email-chandan@linux.vnet.ibm.com>
migrate_super_block() uses sectorsize to refer to the size of the
superblock. Hence on 64k sectorsize filesystems, it ends up computing
checksum beyond the super block length (i.e.
BTRFS_SUPER_INFO_SIZE). This commit fixes the bug by using
BTRFS_SUPER_INFO_SIZE instead of sectorsize of the underlying
filesystem.
Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>
---
convert/main.c | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/convert/main.c b/convert/main.c
index 1148a36..fd6f77b 100644
--- a/convert/main.c
+++ b/convert/main.c
@@ -1360,7 +1360,7 @@ err:
/*
* Migrate super block to its default position and zero 0 ~ 16k
*/
-static int migrate_super_block(int fd, u64 old_bytenr, u32 sectorsize)
+static int migrate_super_block(int fd, u64 old_bytenr)
{
int ret;
struct extent_buffer *buf;
@@ -1368,13 +1368,13 @@ static int migrate_super_block(int fd, u64 old_bytenr, u32 sectorsize)
u32 len;
u32 bytenr;
- buf = malloc(sizeof(*buf) + sectorsize);
+ buf = malloc(sizeof(*buf) + BTRFS_SUPER_INFO_SIZE);
if (!buf)
return -ENOMEM;
- buf->len = sectorsize;
- ret = pread(fd, buf->data, sectorsize, old_bytenr);
- if (ret != sectorsize)
+ buf->len = BTRFS_SUPER_INFO_SIZE;
+ ret = pread(fd, buf->data, BTRFS_SUPER_INFO_SIZE, old_bytenr);
+ if (ret != BTRFS_SUPER_INFO_SIZE)
goto fail;
super = (struct btrfs_super_block *)buf->data;
@@ -1382,19 +1382,20 @@ static int migrate_super_block(int fd, u64 old_bytenr, u32 sectorsize)
btrfs_set_super_bytenr(super, BTRFS_SUPER_INFO_OFFSET);
csum_tree_block_size(buf, BTRFS_CRC32_SIZE, 0);
- ret = pwrite(fd, buf->data, sectorsize, BTRFS_SUPER_INFO_OFFSET);
- if (ret != sectorsize)
+ ret = pwrite(fd, buf->data, BTRFS_SUPER_INFO_SIZE,
+ BTRFS_SUPER_INFO_OFFSET);
+ if (ret != BTRFS_SUPER_INFO_SIZE)
goto fail;
ret = fsync(fd);
if (ret)
goto fail;
- memset(buf->data, 0, sectorsize);
+ memset(buf->data, 0, BTRFS_SUPER_INFO_SIZE);
for (bytenr = 0; bytenr < BTRFS_SUPER_INFO_OFFSET; ) {
len = BTRFS_SUPER_INFO_OFFSET - bytenr;
- if (len > sectorsize)
- len = sectorsize;
+ if (len > BTRFS_SUPER_INFO_SIZE)
+ len = BTRFS_SUPER_INFO_SIZE;
ret = pwrite(fd, buf->data, len, bytenr);
if (ret != len) {
fprintf(stderr, "unable to zero fill device\n");
@@ -2519,7 +2520,7 @@ static int do_convert(const char *devname, int datacsum, int packing,
* If this step succeed, we get a mountable btrfs. Otherwise
* the source fs is left unchanged.
*/
- ret = migrate_super_block(fd, mkfs_cfg.super_bytenr, blocksize);
+ ret = migrate_super_block(fd, mkfs_cfg.super_bytenr);
if (ret) {
error("unable to migrate super block: %d", ret);
goto fail;
--
2.5.5
next prev parent reply other threads:[~2016-12-08 13:56 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-08 13:56 [PATCH 1/2] btrfs-progs: btrfs-convert: Prevent accounting blocks beyond end of device Chandan Rajendra
2016-12-08 13:56 ` Chandan Rajendra [this message]
2016-12-09 1:09 ` [PATCH 2/2] btrfs-convert: Fix migrate_super_block() to work with 64k sectorsize Qu Wenruo
2016-12-09 5:15 ` Chandan Rajendra
2016-12-14 12:38 ` David Sterba
2016-12-09 1:03 ` [PATCH 1/2] btrfs-progs: btrfs-convert: Prevent accounting blocks beyond end of device Qu Wenruo
2016-12-09 4:36 ` Chandan Rajendra
2016-12-14 12:38 ` David Sterba
2016-12-09 1:04 ` 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=1481205380-22978-2-git-send-email-chandan@linux.vnet.ibm.com \
--to=chandan@linux.vnet.ibm.com \
--cc=dsterba@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;
as well as URLs for NNTP newsgroup(s).