xfs
[Top] [All Lists]

[PATCH] xfs_mdrestore: initialize sb prior to xfs_sb_from_disk()

To: xfs-oss <xfs@xxxxxxxxxxx>
Subject: [PATCH] xfs_mdrestore: initialize sb prior to xfs_sb_from_disk()
From: Eric Sandeen <sandeen@xxxxxxxxxx>
Date: Thu, 05 Jun 2014 18:09:16 -0500
Delivered-to: xfs@xxxxxxxxxxx
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.5.0
If we xfs_mdrestore an image from a non-crc filesystem, lo
and behold the restored image has gained a CRC:

# db/xfs_metadump.sh -o /dev/sdc1 - | xfs_mdrestore - test.img
# xfs_db -c "sb 0" -c "p crc" /dev/sdc1
crc = 0 (correct)
# xfs_db -c "sb 0" -c "p crc" test.img
crc = 0xb6f8d6a0 (correct)

Obviously it can't really be correct :)

The problem is, xfs_sb_from_disk doesn't fill in the sb_crc
field.

An earlier commit:

  47de6e1 repair: ensure that unused superblock fields are zeroed

fixed this same sort of problem for xfs_repair.  Do the same
for mdrestore.

Signed-off-by: Eric Sandeen <sandeen@xxxxxxxxxx>
---

But ... should we maybe just do this once and for all in
xfs_sb_from_disk?  I'm not sure leaving it up to every
caller is a good idea, unless somebody ahs a reason to
pre-populate some fields - I can't imagine why that would
be, though...

diff --git a/mdrestore/xfs_mdrestore.c b/mdrestore/xfs_mdrestore.c
index e57bdb2..0453f17 100644
--- a/mdrestore/xfs_mdrestore.c
+++ b/mdrestore/xfs_mdrestore.c
@@ -104,6 +104,7 @@ perform_restore(
                        1, src_f) != 1)
                fatal("error reading from file: %s\n", strerror(errno));
 
+       memset(&sb, 0, sizeof(struct xfs_sb));
        libxfs_sb_from_disk(&sb, (xfs_dsb_t *)block_buffer);
 
        if (sb.sb_magicnum != XFS_SB_MAGIC)

<Prev in Thread] Current Thread [Next in Thread>