xfs: Print a warning if the filesystem needs to be repaired
PATCH 1/1 xfs: Print a warning if the filesystem needs to be repaired
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.
One option is to make the GRUB behaviour consistent with the Linux kernel, and don't allow to mount a XFS filesystem that needs to be repaired. But that will prevent to even boot to a rescue environment for the OS in order to repair the filesystem.
To prevent this situation, let's GRUB attempt to mount the filesystem even when needs to be repaired. Since after all, it currently attempts to mount even if is in an inconsistent state without trying to replay the jornal.
For this reason, make it a best effort but print an error message when the filesystem is mounted if needs to be repaired. That way, if booting fails later due the inconsistencies when traversing the filesystem, the user can understand why that and take any needed action.
---
grub-core/fs/xfs.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
grub-core/fs/xfs.c +16 -0
@@ -79,6 +79,7 @@ GRUB_MOD_LICENSE ("GPLv3+");#define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0)/* filetype in dirent */ #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_NEEDSREPAIR (1 << 4)/* needs xfs_repair */ /* * Directory entries with ftype are explicitly handled by GRUB code.
@@ -300,6 +301,16 @@ static int grub_xfs_sb_valid(struct grub_xfs_data *data)return 0 ; } +static int +grub_xfs_sb_needsrepair (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
@@ -915,6 +926,11 @@ grub_xfs_mount (grub_disk_t disk)if (!grub_xfs_sb_valid (data)) goto fail; +if (grub_xfs_sb_needsrepair (data)) + { +grub_printf (N_ ("Filesystem needs repair. Please run a XFS repair tool" )); + } +if (grub_add (grub_xfs_inode_size (data),sizeof (struct grub_xfs_data ) -sizeof (struct grub_xfs_inode ) +1 , &sz)) goto fail;
Signature · 1 line
2.31.1
Quoted 37 lines
Suggested-by Eric Sandeen <[email protected]>Signed-off-by Javier Martinez Canillas <[email protected]>---
grub-core/fs/xfs.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)grub-core/fs/xfs.c +11
-0@@ -79,6 +79,7 @@ GRUB_MOD_LICENSE ("GPLv3+");#define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0)/* filetype in dirent */ #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_NEEDSREPAIR (1 << 4)/* needs xfs_repair */ /* * Directory entries with ftype are explicitly handled by GRUB code. @@ -300,6 +301,16 @@ static int grub_xfs_sb_valid(struct grub_xfs_data *data)return 0 ; } +static int +grub_xfs_sb_needsrepair (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
grub-core/fs/xfs.c grub_xfs_mount (grub_disk_t disk) · line 933
Quoted 8 lines
grub-core/fs/xfs.c +5
-0@@ -915,6 +926,11 @@ grub_xfs_mount (grub_disk_t disk)if (!grub_xfs_sb_valid (data)) goto fail; +if (grub_xfs_sb_needsrepair (data)) + { +grub_printf (N_ ("Filesystem needs repair. Please run a XFS repair tool" )); + } +
I'm not a grub developer, but from the XFS point of view, this looks fine.
Feel free to add my reviewed tag if it makes sense to you:
Signature · 1 line
Carlos
Quoted 9 lines · Javier Martinez Canillas
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_repairtool is able to clear that flag.One option is to make the GRUB behaviour consistent with the Linux kernel, and don't allow to mount a XFS filesystem that needs to be repaired. But that will prevent to even boot to a rescue environment for the OS in order to repair the filesystem.
Quoted 6 lines
To prevent this situation, let's GRUB attempt to mount the filesystem even when needs to be repaired. Since after all, it currently attempts to mount even if is in an inconsistent state without trying to replay the jornal.
For this reason, make it a best effort but print an error message when the filesystem is mounted if needs to be repaired. That way, if booting fails
s/filesystem is mounted if needs to be repaired/filesystem is mounted and should be repaired/
Quoted 2 lines
later due the inconsistencies when traversing the filesystem, the user can understand why that and take any needed action.
s/that/that happened/
Quoted 12 lines
Suggested-by Eric Sandeen <[email protected]>Signed-off-by Javier Martinez Canillas <[email protected]>---
grub-core/fs/xfs.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)grub-core/fs/xfs.c +0
-0
grub-core/fs/xfs.c GRUB_MOD_LICENSE ("GPLv3+"); · line 82
Quoted 4 lines
grub-core/fs/xfs.c +1
-0@@ -79,6 +79,7 @@ GRUB_MOD_LICENSE ("GPLv3+");#define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0)/* filetype in dirent */ #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_NEEDSREPAIR (1 << 4)/* needs xfs_repair */
s/XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR/XFS_SB_FEAT_INCOMPAT_NEEDS_REPAIR/
grub-core/fs/xfs.c static int grub_xfs_sb_valid(struct grub_xfs_data *data) · line 305
Quoted 8 lines
grub-core/fs/xfs.c +2
-0/* * Directory entries with ftype are explicitly handled by GRUB code. @@ -300,6 +301,16 @@ static int grub_xfs_sb_valid(struct grub_xfs_data *data)return 0 ; } +static int +grub_xfs_sb_needsrepair (struct grub_xfs_data *data)
s/grub_xfs_sb_needsrepair/xfs_sb_needs_repair/
grub-core/fs/xfs.c static int grub_xfs_sb_valid(struct grub_xfs_data *data) · line 308
Quoted 3 lines
grub-core/fs/xfs.c +3
-0+{ + return ((data->sblock.version & + grub_cpu_to_be16_compile_time(XFS_SB_VERSION_NUMBITS)) ==
Missing space before "(" and below...
grub-core/fs/xfs.c static int grub_xfs_sb_valid(struct grub_xfs_data *data) · line 309
Quoted 1 line
grub-core/fs/xfs.c +1
-0+ grub_cpu_to_be16_compile_time(XFS_SB_VERSION_5) &&
Hmmm... Is XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR flag available for XFS_SB_VERSION_5 only? Should not we use ">=" instead of "=="? Does not older XFS versions support this flag?
grub-core/fs/xfs.c static int grub_xfs_sb_valid(struct grub_xfs_data *data) · line 311
Quoted 2 lines
grub-core/fs/xfs.c +2
-0+ data->sblock.sb_features_incompat & + grub_cpu_to_be32_compile_time(XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR));
I would add more parenthesis here...
grub-core/fs/xfs.c grub_xfs_mount (grub_disk_t disk) · line 932
Quoted 13 lines
grub-core/fs/xfs.c +6
-0+} +/* Filetype information as used in inodes. */ #define FILETYPE_INO_MASK 0170000#define FILETYPE_INO_REG 0100000@@ -915,6 +926,11 @@ grub_xfs_mount (grub_disk_t disk)if (!grub_xfs_sb_valid (data)) goto fail; +if (grub_xfs_sb_needsrepair (data)) + { +grub_printf (N_ ("Filesystem needs repair. Please run a XFS repair tool" )); + }
Please drop these curly brackets here...
Daniel
Hi Daniel
Quoted 9 lines
grub-core/fs/xfs.c GRUB_MOD_LICENSE ("GPLv3+"); · line 82
Quoted 7 lines
grub-core/fs/xfs.c +1
-0@@ -79,6 +79,7 @@ GRUB_MOD_LICENSE ("GPLv3+");#define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0)/* filetype in dirent */ #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_NEEDSREPAIR (1 << 4)/* needs xfs_repair */ s/XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR/XFS_SB_FEAT_INCOMPAT_NEEDS_REPAIR/
I believe Javier got this from kernel, I wonder if it doesn't make sense to keep the flags names consistent with kernel?
Quoted 6 lines
grub-core/fs/xfs.c static int grub_xfs_sb_valid(struct grub_xfs_data *data) · line 309
Quoted 2 lines
grub-core/fs/xfs.c +1
-0+ grub_cpu_to_be16_compile_time(XFS_SB_VERSION_5) &&Hmmm... Is
XFS_SB_FEAT_INCOMPAT_NEEDSREPAIRflag available forXFS_SB_VERSION_5only? Should not we use ">=" instead of "=="? Does not older XFS versions support this flag?
No, only xfs V5 superblock supports needsrepair flag.
Hope it helps somehow.
Cheers.
Signature · 1 line
Carlos
Quoted 12 lines · Carlos Maiolino
Hi Daniel
Quoted 9 lines
grub-core/fs/xfs.c GRUB_MOD_LICENSE ("GPLv3+"); · line 82
Quoted 7 lines
grub-core/fs/xfs.c +1
-0@@ -79,6 +79,7 @@ GRUB_MOD_LICENSE ("GPLv3+");#define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0)/* filetype in dirent */ #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_NEEDSREPAIR (1 << 4)/* needs xfs_repair */ s/XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR/XFS_SB_FEAT_INCOMPAT_NEEDS_REPAIR/
Quoted 2 lines
I believe Javier got this from kernel, I wonder if it doesn't make sense to keep the flags names consistent with kernel?
That's correct, I copied the macro name from the kernel and agree with Carlos that's better to keep it the same. It makes much easier to grep the kernel source code when looking for something:
#define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0) /* filetype in dirent */
#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 */
https://elixir.bootlin.com/linux/latest/source/fs/xfs/libxfs/xfs_format.h#L471
Quoted 11 lines
Quoted 8 lines
grub-core/fs/xfs.c static int grub_xfs_sb_valid(struct grub_xfs_data *data) · line 309
Quoted 4 lines
grub-core/fs/xfs.c +1
-0+ grub_cpu_to_be16_compile_time(XFS_SB_VERSION_5) &&Hmmm... Is
XFS_SB_FEAT_INCOMPAT_NEEDSREPAIRflag available forXFS_SB_VERSION_5only? Should not we use ">=" instead of "=="? Does not older XFS versions support this flag?No, only xfs V5 superblock supports needsrepair flag.
Indeed, and there's no plan for a XFS v5+ in the near future as was explained to me by Carlos. I also copied the logic to check from the Linux kernel which uses '==' for all the flags supported only in v5.
Best regards,
Signature · 3 lines
Javier Martinez Canillas Software Engineer - Desktop Hardware Enablement Red Hat
Quoted 20 lines · Javier Martinez Canillas
Quoted 12 lines · Carlos Maiolino
Hi Daniel
Quoted 9 lines
grub-core/fs/xfs.c GRUB_MOD_LICENSE ("GPLv3+"); · line 82
Quoted 7 lines
grub-core/fs/xfs.c +1
-0@@ -79,6 +79,7 @@ GRUB_MOD_LICENSE ("GPLv3+");#define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0)/* filetype in dirent */ #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_NEEDSREPAIR (1 << 4)/* needs xfs_repair */ s/XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR/XFS_SB_FEAT_INCOMPAT_NEEDS_REPAIR/
Quoted 2 lines
I believe Javier got this from kernel, I wonder if it doesn't make sense to keep the flags names consistent with kernel?
That's correct, I copied the macro name from the kernel and agree with Carlos that's better to keep it the same. It makes much easier to grep the kernel source code when looking for something:
Quoted 7 lines
#define
XFS_SB_FEAT_INCOMPAT_FTYPE(1 << 0) /* filetype in dirent */
#defineXFS_SB_FEAT_INCOMPAT_SPINODES(1 << 1) /* sparse inode chunks */
#defineXFS_SB_FEAT_INCOMPAT_META_UUID(1 << 2) /* metadata UUID */
#defineXFS_SB_FEAT_INCOMPAT_BIGTIME(1 << 3) /* large timestamps */
#defineXFS_SB_FEAT_INCOMPAT_NEEDSREPAIR(1 << 4) /* needsxfs_repair*/https://elixir.bootlin.com/linux/latest/source/fs/xfs/libxfs/xfs_format.h#L471
If this comes from the kernel then I am OK with it.
Quoted 11 lines
Quoted 7 lines
Quoted 5 lines
grub-core/fs/xfs.c static int grub_xfs_sb_valid(struct grub_xfs_data *data) · line 309
Quoted 1 line
grub-core/fs/xfs.c +1
-0+ grub_cpu_to_be16_compile_time(XFS_SB_VERSION_5) &&Hmmm... Is
XFS_SB_FEAT_INCOMPAT_NEEDSREPAIRflag available forXFS_SB_VERSION_5only? Should not we use ">=" instead of "=="? Does not older XFS versions support this flag?No, only xfs V5 superblock supports needsrepair flag.
Indeed, and there's no plan for a XFS v5+ in the near future as was explained to me by Carlos. I also copied the logic to check from the Linux kernel which uses '==' for all the flags supported only in v5.
OK, then just repost the patch with minor fixes...
Daniel
Filesystems are not mounted in GRUB. This patch will result in GRUB outputting a warning on every access to any XFS that has this flag set, even if it is not related to further booting. It will create an excessive noise. FS drivers shouldn't print anything except dprintf's
Quoted 83 lines · Javier Martinez Canillas
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_repairtool is able to clear that flag.One option is to make the GRUB behaviour consistent with the Linux kernel, and don't allow to mount a XFS filesystem that needs to be repaired. But that will prevent to even boot to a rescue environment for the OS in order to repair the filesystem.
To prevent this situation, let's GRUB attempt to mount the filesystem even when needs to be repaired. Since after all, it currently attempts to mount even if is in an inconsistent state without trying to replay the jornal.
For this reason, make it a best effort but print an error message when the filesystem is mounted if needs to be repaired. That way, if booting fails later due the inconsistencies when traversing the filesystem, the user can understand why that and take any needed action.
Suggested-by Eric Sandeen <[email protected]>Signed-off-by Javier Martinez Canillas <[email protected]>---
grub-core/fs/xfs.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)grub-core/fs/xfs.c +0
-0@@ -79,6 +79,7 @@ GRUB_MOD_LICENSE ("GPLv3+");#define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0)/* filetype in dirent */
#defineXFS_SB_FEAT_INCOMPAT_SPINODES(1 << 1) /* sparse inode
chunks */
#defineXFS_SB_FEAT_INCOMPAT_META_UUID(1 << 2) /* metadata UUID
*/
+#defineXFS_SB_FEAT_INCOMPAT_NEEDSREPAIR(1 << 4) /* needsxfs_repair*//*
* Directory entries with ftype are explicitly handled by GRUB code.grub-core/fs/xfs.c +10
-0@@ -300,6 +301,16 @@ static int grub_xfs_sb_valid(struct grub_xfs_data *data)return 0 ; } +static int +grub_xfs_sb_needsrepair (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_MASK0170000
#defineFILETYPE_INO_REG0100000grub-core/fs/xfs.c +5
-0@@ -915,6 +926,11 @@ grub_xfs_mount (grub_disk_t disk)if (!grub_xfs_sb_valid (data)) goto fail; +if (grub_xfs_sb_needsrepair (data)) + { +grub_printf (N_ ("Filesystem needs repair. Please run a XFS repair tool")); + } + if (grub_add (grub_xfs_inode_size (data), sizeof (struct grub_xfs_data) - sizeof (struct grub_xfs_inode) + 1,&sz))
goto fail;--
2.31.1_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Hello Vladimir,
Quoted 5 lines · Vladimir 'phcoder' Serbinenko
Filesystems are not mounted in GRUB. This patch will result in GRUB outputting a warning on every access to any XFS that has this flag set, even if it is not related to further booting. It will create an excessive noise. FS drivers shouldn't print anything except dprintf's
I see, you are right. There's a grub_xfs_mount() function in grub-core/fs/xfs.c but it's misleading indeed since is just called from the .fs_* handlers to read the data.
Do you think we should just ignore the flag then and drop this patch or it is worth to have some debugging printouts with grub_dprintf("xfs", ... ) ?
Best regards,
Signature · 3 lines
Javier Martinez Canillas Software Engineer - Desktop Hardware Enablement Red Hat
Quoted 7 lines · Javier Martinez Canillas
Hello Vladimir,
Quoted 4 lines · Vladimir 'phcoder' Serbinenko
Filesystems are not mounted in GRUB. This patch will result in GRUB outputting a warning on every access to any XFS that has this flag set, even if it is not related to further booting. It will create an excessive noise. FS drivers shouldn't print anything except dprintf's
I see. Good to know, thanks for the information.
Quoted 2 lines
Do you think we should just ignore the flag then and drop this patch or it is worth to have some debugging printouts with grub_dprintf("xfs", ... ) ?
If I understand this correctly, grub can simply ignore the flag, which will make it attempt to read the filesystem anyway.
Although, if it fails to read the FS for 'some reason', maybe it can print out a debug message then saying such flag was set in the filesystem? This may give some extra information to the user?!
Cheers.
Signature · 1 line
Carlos
Quoted 14 lines · Carlos Maiolino
Quoted 7 lines · Javier Martinez Canillas
Hello Vladimir,
Quoted 4 lines · Vladimir 'phcoder' Serbinenko
Filesystems are not mounted in GRUB. This patch will result in GRUB outputting a warning on every access to any XFS that has this flag set, even if it is not related to further booting. It will create an excessive noise. FS drivers shouldn't print anything except dprintf's
I see. Good to know, thanks for the information.
Quoted 2 lines
Do you think we should just ignore the flag then and drop this patch or it is worth to have some debugging printouts with grub_dprintf("xfs", ... ) ?
Quoted 6 lines
If I understand this correctly, grub can simply ignore the flag, which will make it attempt to read the filesystem anyway.
Although, if it fails to read the FS for 'some reason', maybe it can print out a debug message then saying such flag was set in the filesystem? This may give some extra information to the user?!
I think it is good idea. Could you prepare a patch?
Daniel
Hello Daniel,
Quoted 15 lines · Daniel Kiper
Quoted 14 lines · Carlos Maiolino
Quoted 7 lines · Javier Martinez Canillas
Hello Vladimir,
Quoted 4 lines · Vladimir 'phcoder' Serbinenko
Filesystems are not mounted in GRUB. This patch will result in GRUB outputting a warning on every access to any XFS that has this flag set, even if it is not related to further booting. It will create an excessive noise. FS drivers shouldn't print anything except dprintf's
I see. Good to know, thanks for the information.
Quoted 2 lines
Do you think we should just ignore the flag then and drop this patch or it is worth to have some debugging printouts with grub_dprintf("xfs", ... ) ?
Quoted 9 lines
Quoted 6 lines
If I understand this correctly, grub can simply ignore the flag, which will make it attempt to read the filesystem anyway.
Although, if it fails to read the FS for 'some reason', maybe it can print out a debug message then saying such flag was set in the filesystem? This may give some extra information to the user?!
I think it is good idea. Could you prepare a patch?
Yes, I'll post a new version today. Also, it was pointed out to me that even if GRUB will mostly ignore this feature flag (besides printing a message if fails to read something), we should at least include XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR in the XFS_SB_FEAT_INCOMPAT_SUPPORTED list.
Otherwise GRUB will just fail to read anything if grub_xfs_sb_valid() finds that an unsupported incompatible feature is enabled in the super block.
Quoted 1 line
Daniel
Best regards,
Signature · 3 lines
Javier Martinez Canillas Software Engineer - Desktop Hardware Enablement Red Hat