grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v3] xfs: Include needsrepair in the supported incompat features l


From: Javier Martinez Canillas
Subject: [PATCH v3] xfs: Include needsrepair in the supported incompat features list
Date: Mon, 3 May 2021 17:10:40 +0200

XFS now has an incompat feature flag to indicate that the filesystem needs
to be repaired. The Linux kernel refuses to mount a filesystem that has it
set and only the xfs_repair tool is able to clear that flag.

The GRUB doesn't have the concept of mounting filesystems and just attempt
to read the files. But it does some sanity checking, before attempting to
read from a filesystem.

Among the things that are tested, is if the super block only has set the
incompatible features flags that are supported by GRUB. If it contains any
flags that are not listed as supported, reading the XFS filesystem fails.

Since GRUB doesn't attempt to detect if the filesystem is inconsistent nor
replays the journal, just ignore if a filesystem needs to be repaired too.

But print a message if grub_xfs_mount() fails, to give more information to
the user about why that could had been the case.

Suggested-by: Eric Sandeen <esandeen@redhat.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
---

Hello,

This is a v3 of the XFS needsrepair patch addressing the issue pointed out
by Vladimir. As mentioned this patch isn't really optional if the feature
flag XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR is set, since it will prevent GRUB
to access the filesystem at all due detecting an unsupported feature flag.

The patch is on top of Carlos' "[PATCH V2 0/2] Enable bigtime feature for
xfs driver" series. There's no dependency really but it would make easier
to pick the patches and avoid merge conflicts.

[0]: https://www.mail-archive.com/grub-devel@gnu.org/msg32079.html

Best regards,
Javier

Changes in v3:
- Only print that the filesystem needs to be repaired if reading fails
  (phcoder).

Changes in v2:
- Add Carlos Reviewed-by tag
- Improve commit message (dkiper)
- Rename the grub_xfs_sb_needsrepair() function (dkiper)
- Add more parenthesis to the need repair check (dkiper)
- Drop curly brackets for single statement (dkiper)

 grub-core/fs/xfs.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c
index 2ce76ec70f9..c4c1bca39a8 100644
--- a/grub-core/fs/xfs.c
+++ b/grub-core/fs/xfs.c
@@ -84,6 +84,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
 #define XFS_SB_FEAT_INCOMPAT_SPINODES  (1 << 1)        /* sparse inode chunks 
*/
 #define XFS_SB_FEAT_INCOMPAT_META_UUID (1 << 2)        /* metadata UUID */
 #define XFS_SB_FEAT_INCOMPAT_BIGTIME   (1 << 3)        /* large timestamps */
+#define XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR (1 << 4)      /* needs xfs_repair */
 
 /*
  * Directory entries with ftype are explicitly handled by GRUB code.
@@ -98,7 +99,8 @@ GRUB_MOD_LICENSE ("GPLv3+");
        (XFS_SB_FEAT_INCOMPAT_FTYPE | \
         XFS_SB_FEAT_INCOMPAT_SPINODES | \
         XFS_SB_FEAT_INCOMPAT_META_UUID | \
-        XFS_SB_FEAT_INCOMPAT_BIGTIME)
+        XFS_SB_FEAT_INCOMPAT_BIGTIME | \
+        XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR)
 
 struct grub_xfs_sblock
 {
@@ -307,6 +309,16 @@ static int grub_xfs_sb_valid(struct grub_xfs_data *data)
   return 0;
 }
 
+static int
+grub_xfs_sb_needs_repair(struct grub_xfs_data *data)
+{
+  return ((data->sblock.version &
+           grub_cpu_to_be16_compile_time (XFS_SB_VERSION_NUMBITS)) ==
+          grub_cpu_to_be16_compile_time (XFS_SB_VERSION_5) &&
+          (data->sblock.sb_features_incompat &
+           grub_cpu_to_be32_compile_time (XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR)));
+}
+
 /* Filetype information as used in inodes.  */
 #define FILETYPE_INO_MASK      0170000
 #define FILETYPE_INO_REG       0100000
@@ -949,6 +961,9 @@ grub_xfs_mount (grub_disk_t disk)
   return data;
  fail:
 
+  if (grub_xfs_sb_needs_repair(data))
+    grub_dprintf("xfs", "Filesystem needs repair\n");
+
   if (grub_errno == GRUB_ERR_OUT_OF_RANGE)
     grub_error (GRUB_ERR_BAD_FS, "not an XFS filesystem");
 
-- 
2.31.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]