28f7f8
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
28f7f8
From: Eric Sandeen <sandeen@sandeen.net>
28f7f8
Date: Tue, 15 May 2018 14:55:55 -0500
28f7f8
Subject: [PATCH] xfs: accept filesystem with sparse inodes
28f7f8
28f7f8
The sparse inode metadata format became a mkfs.xfs default in
28f7f8
xfsprogs-4.16.0, and such filesystems are now rejected by grub as
28f7f8
containing an incompatible feature.
28f7f8
28f7f8
In essence, this feature allows xfs to allocate inodes into fragmented
28f7f8
freespace.  (Without this feature, if xfs could not allocate contiguous
28f7f8
space for 64 new inodes, inode creation would fail.)
28f7f8
28f7f8
In practice, the disk format change is restricted to the inode btree,
28f7f8
which as far as I can tell is not used by grub.  If all you're doing
28f7f8
today is parsing a directory, reading an inode number, and converting
28f7f8
that inode number to a disk location, then ignoring this feature
28f7f8
should be fine, so I've added it to XFS_SB_FEAT_INCOMPAT_SUPPORTED
28f7f8
28f7f8
I did some brief testing of this patch by hacking up the regression
28f7f8
tests to completely fragment freespace on the test xfs filesystem, and
28f7f8
then write a large-ish number of inodes to consume any existing
28f7f8
contiguous 64-inode chunk.  This way any files the grub tests add and
28f7f8
traverse would be in such a fragmented inode allocation.  Tests passed,
28f7f8
but I'm not sure how to cleanly integrate that into the test harness.
28f7f8
28f7f8
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
28f7f8
---
28f7f8
 grub-core/fs/xfs.c | 16 +++++++++++++++-
28f7f8
 1 file changed, 15 insertions(+), 1 deletion(-)
28f7f8
28f7f8
diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c
28f7f8
index 72492915533..852155b1bf3 100644
28f7f8
--- a/grub-core/fs/xfs.c
28f7f8
+++ b/grub-core/fs/xfs.c
28f7f8
@@ -76,8 +76,22 @@ GRUB_MOD_LICENSE ("GPLv3+");
28f7f8
 
28f7f8
 /* incompat feature flags */
28f7f8
 #define XFS_SB_FEAT_INCOMPAT_FTYPE      (1 << 0)        /* filetype in dirent */
28f7f8
+#define XFS_SB_FEAT_INCOMPAT_SPINODES   (1 << 1)        /* sparse inode chunks */
28f7f8
+#define XFS_SB_FEAT_INCOMPAT_META_UUID  (1 << 2)        /* metadata UUID */
28f7f8
+
28f7f8
+/*
28f7f8
+ * Directory entries with ftype are explicitly handled by grub code.
28f7f8
+ *
28f7f8
+ * We do not currently verify metadata UUID, so it is safe to read filesystems
28f7f8
+ * with the XFS_SB_FEAT_INCOMPAT_META_UUID feature.
28f7f8
+ *
28f7f8
+ * We do not currently read the inode btrees, so it is safe to read filesystems
28f7f8
+ * with the XFS_SB_FEAT_INCOMPAT_SPINODES feature.
28f7f8
+ */
28f7f8
 #define XFS_SB_FEAT_INCOMPAT_SUPPORTED \
28f7f8
-	(XFS_SB_FEAT_INCOMPAT_FTYPE)
28f7f8
+	(XFS_SB_FEAT_INCOMPAT_FTYPE | \
28f7f8
+	 XFS_SB_FEAT_INCOMPAT_SPINODES | \
28f7f8
+	 XFS_SB_FEAT_INCOMPAT_META_UUID)
28f7f8
 
28f7f8
 struct grub_xfs_sblock
28f7f8
 {