* [PATCH] xfs_mdrestore: fix restoration on filesystems with 4k sectors
@ 2026-01-06 18:48 Darrick J. Wong
2026-01-07 6:12 ` Christoph Hellwig
0 siblings, 1 reply; 3+ messages in thread
From: Darrick J. Wong @ 2026-01-06 18:48 UTC (permalink / raw)
To: Andrey Albershteyn; +Cc: xfs
From: Darrick J. Wong <djwong@kernel.org>
Running xfs/129 on a disk with 4k LBAs produces the following failure:
--- /run/fstests/bin/tests/xfs/129.out 2025-07-15 14:41:40.210489431 -0700
+++ /run/fstests/logs/xfs/129.out.bad 2026-01-05 21:43:08.814485633 -0800
@@ -2,3 +2,8 @@ QA output created by 129
Create the original file blocks
Reflink every other block
Create metadump file, restore it and check restored fs
+xfs_mdrestore: Invalid superblock disk address/length
+mount: /opt: can't read superblock on /dev/loop0.
+ dmesg(1) may have more information after failed mount system call.
+mount /dev/loop0 /opt failed
+(see /run/fstests/logs/xfs/129.full for details)
This is a failure to restore a v2 metadump to /dev/loop0. Looking at
the metadump itself, the first xfs_meta_extent contains:
{
.xme_addr = 0,
.xme_len = 8,
}
Hrm. This is the primary superblock on the data device, with a length
of 8x512B = 4K. The original filesystem has this geometry:
# xfs_info /dev/sda4
meta-data=/dev/sda4 isize=512 agcount=4, agsize=2183680 blks
= sectsz=4096 attr=2, projid32bit=1
In other words, a sector size of 4k because the device's LBA size is 4k.
Regrettably, the metadump validation in mdrestore assumes that the
primary superblock is only 512 bytes long, which is not correct for this
scenario.
Fix this by allowing an xme_len value of up to the maximum sector size
for xfs, which is 32k. Also remove a redundant and confusing mask check
for the xme_addr.
Note that this error was masked (at least on little-endian platforms
that most of us test on) until recent commit 98f05de13e7815 ("mdrestore:
fix restore_v2() superblock length check") which is why I didn't spot it
earlier.
Cc: <linux-xfs@vger.kernel.org> # v6.6.0
Fixes: fa9f484b79123c ("mdrestore: Define mdrestore ops for v2 format")
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
mdrestore/xfs_mdrestore.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/mdrestore/xfs_mdrestore.c b/mdrestore/xfs_mdrestore.c
index b6e8a6196a795a..525fa68e6d23a6 100644
--- a/mdrestore/xfs_mdrestore.c
+++ b/mdrestore/xfs_mdrestore.c
@@ -437,13 +437,21 @@ restore_v2(
if (fread(&xme, sizeof(xme), 1, md_fp) != 1)
fatal("error reading from metadump file\n");
- if (xme.xme_addr != 0 || be32_to_cpu(xme.xme_len) != 1 ||
- (be64_to_cpu(xme.xme_addr) & XME_ADDR_DEVICE_MASK) !=
- XME_ADDR_DATA_DEVICE)
- fatal("Invalid superblock disk address/length\n");
+ /*
+ * The first block must be the primary super, which is at the start of
+ * the data device, which is device 0.
+ */
+ if (xme.xme_addr != 0)
+ fatal("Invalid superblock disk address 0x%llx\n",
+ be64_to_cpu(xme.xme_addr));
len = BBTOB(be32_to_cpu(xme.xme_len));
+ /* The primary superblock is always a single filesystem sector. */
+ if (len < BBTOB(1) || len > 1U << XFS_MAX_SECTORSIZE_LOG)
+ fatal("Invalid superblock disk length 0x%x\n",
+ be32_to_cpu(xme.xme_len));
+
if (fread(block_buffer, len, 1, md_fp) != 1)
fatal("error reading from metadump file\n");
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] xfs_mdrestore: fix restoration on filesystems with 4k sectors
2026-01-06 18:48 [PATCH] xfs_mdrestore: fix restoration on filesystems with 4k sectors Darrick J. Wong
@ 2026-01-07 6:12 ` Christoph Hellwig
2026-01-07 17:22 ` Darrick J. Wong
0 siblings, 1 reply; 3+ messages in thread
From: Christoph Hellwig @ 2026-01-07 6:12 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: Andrey Albershteyn, xfs
On Tue, Jan 06, 2026 at 10:48:27AM -0800, Darrick J. Wong wrote:
> + /*
> + * The first block must be the primary super, which is at the start of
> + * the data device, which is device 0.
> + */
> + if (xme.xme_addr != 0)
> + fatal("Invalid superblock disk address 0x%llx\n",
> + be64_to_cpu(xme.xme_addr));
>
> len = BBTOB(be32_to_cpu(xme.xme_len));
>
> + /* The primary superblock is always a single filesystem sector. */
> + if (len < BBTOB(1) || len > 1U << XFS_MAX_SECTORSIZE_LOG)
I'd use XFS_MAX_SECTORSIZE here instead of open coding the shift.
Otherwise looks good.
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] xfs_mdrestore: fix restoration on filesystems with 4k sectors
2026-01-07 6:12 ` Christoph Hellwig
@ 2026-01-07 17:22 ` Darrick J. Wong
0 siblings, 0 replies; 3+ messages in thread
From: Darrick J. Wong @ 2026-01-07 17:22 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: Andrey Albershteyn, xfs
On Tue, Jan 06, 2026 at 10:12:09PM -0800, Christoph Hellwig wrote:
> On Tue, Jan 06, 2026 at 10:48:27AM -0800, Darrick J. Wong wrote:
> > + /*
> > + * The first block must be the primary super, which is at the start of
> > + * the data device, which is device 0.
> > + */
> > + if (xme.xme_addr != 0)
> > + fatal("Invalid superblock disk address 0x%llx\n",
> > + be64_to_cpu(xme.xme_addr));
> >
> > len = BBTOB(be32_to_cpu(xme.xme_len));
> >
> > + /* The primary superblock is always a single filesystem sector. */
> > + if (len < BBTOB(1) || len > 1U << XFS_MAX_SECTORSIZE_LOG)
>
> I'd use XFS_MAX_SECTORSIZE here instead of open coding the shift.
>
> Otherwise looks good.
Fixed, thanks for reading! :)
--D
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-01-07 17:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-06 18:48 [PATCH] xfs_mdrestore: fix restoration on filesystems with 4k sectors Darrick J. Wong
2026-01-07 6:12 ` Christoph Hellwig
2026-01-07 17:22 ` Darrick J. Wong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox