Skip to contentSkip to conversation

fs/xfs: add large extent counters incompat feature support

PATCH In review Anthony Iliopoulos via Grub-devel 6 participants 13 messages Oct 26, 2023 – Nov 7, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/xfs: add large extent counters incompat feature support

XFS introduced 64-bit extent counters for inodes via a series of upstream commits, and the feature was marked as stable in v6.5 via commit 61d7e8274cd8 ("xfs: drop EXPERIMENTAL tag for large extent counts").

Further, xfsprogs release v6.5.0 switched this feature on by default in mkfs.xfs via commit e5b18d7d1d96 ("mkfs: enable large extent counts by default").

Filesystems formatted with large extent count support (nrext64=1) are thus currently not recognizable by grub, since this is an incompat feature. Add the required support so that those filesystems and inodes with large extent counters can be read by grub.

---
 grub-core/fs/xfs.c | 30 +++++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)
grub-core/fs/xfs.c +25 -5
index b91cd32b49ab..ab0d2cdf55a2 100644
@@ -79,6 +79,8 @@ GRUB_MOD_LICENSE ("GPLv3+");
 /* Inode flags2 flags */
 #define XFS_DIFLAG2_BIGTIME_BIT	3
 #define XFS_DIFLAG2_BIGTIME		(1 << XFS_DIFLAG2_BIGTIME_BIT)
+#define XFS_DIFLAG2_NREXT64_BIT	4
+#define XFS_DIFLAG2_NREXT64		(1 << XFS_DIFLAG2_NREXT64_BIT)
 
 /* incompat feature flags */
 #define XFS_SB_FEAT_INCOMPAT_FTYPE      (1 << 0)        /* filetype in dirent */
@@ -86,6 +88,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
 #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 */
+#define XFS_SB_FEAT_INCOMPAT_NREXT64 (1 << 5)           /* large extent counters */
 
 /*
  * Directory entries with ftype are explicitly handled by GRUB code.
@@ -101,7 +104,8 @@ GRUB_MOD_LICENSE ("GPLv3+");
 	 XFS_SB_FEAT_INCOMPAT_SPINODES | \
 	 XFS_SB_FEAT_INCOMPAT_META_UUID | \
 	 XFS_SB_FEAT_INCOMPAT_BIGTIME | \
-	 XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR)
+	 XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR | \
+	 XFS_SB_FEAT_INCOMPAT_NREXT64)
 
 struct grub_xfs_sblock
 {
@@ -203,7 +207,8 @@ struct grub_xfs_inode
   grub_uint16_t mode;
   grub_uint8_t version;
   grub_uint8_t format;
-  grub_uint8_t unused2[26];
+  grub_uint8_t unused2[18];
+  grub_uint64_t nextents_big;
   grub_uint64_t atime;
   grub_uint64_t mtime;
   grub_uint64_t ctime;
@@ -539,11 +544,26 @@ get_fsb (const void *keys, int idx)
   return grub_be_to_cpu64 (grub_get_unaligned64 (p));
 }
 
+static int
+grub_xfs_inode_has_large_extent_counts (const struct grub_xfs_inode *inode)
+{
+  return inode->version >= 3 &&
+	 (inode->flags2 & grub_cpu_to_be64_compile_time (XFS_DIFLAG2_NREXT64));
+}
+
+static grub_uint64_t
+grub_xfs_get_inode_nextents (struct grub_xfs_inode *inode)
+{
+  return (grub_xfs_inode_has_large_extent_counts (inode)) ?
+	  grub_be_to_cpu64 (inode->nextents_big) :
+	  grub_be_to_cpu32 (inode->nextents);
+}
+
 static grub_disk_addr_t
 grub_xfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)
 {
   struct grub_xfs_btree_node *leaf = 0;
-  int ex, nrec;
+  grub_uint64_t ex, nrec;
   struct grub_xfs_extent *exts;
   grub_uint64_t ret = 0;
 
@@ -568,7 +588,7 @@ grub_xfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)
 				/ (2 * sizeof (grub_uint64_t));
       do
         {
-          int i;
+          grub_uint64_t i;
 
           for (i = 0; i < nrec; i++)
             {
@@ -615,7 +635,7 @@ grub_xfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)
       grub_addr_t exts_end = 0;
       grub_addr_t data_end = 0;
 
-      nrec = grub_be_to_cpu32 (node->inode.nextents);
+      nrec = grub_xfs_get_inode_nextents (&node->inode);
       exts = (struct grub_xfs_extent *) grub_xfs_inode_data(&node->inode);
 
       if (grub_mul (sizeof (struct grub_xfs_extent), nrec, &exts_end) ||
Signature · 7 lines
2.41.0


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Reviewed-by on v1 1/1
#2 lore raw

Hey,

Adding Marta and Sebastian...

Quoted 7 lines · Andrey Albershteyn

haha what a chance!

Just today I was working on the same thing, and have almost identical patch which I was about to send :)

The patch looks good to me.

Marta, Sebastian, may I ask you to test this patch as well?

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#3 lore raw

Hello,

I tested all new xfs patches together:
fs/xfs: add large extent counters incompat feature support fs/xfs: Fix XFS directory extent parsing
fs/xfs: Incorrect short form directory data boundary check

on ppc64le, aarch64, x86 BIOS and UEFI, and basic installation and booting tests passed.

-marta

Quoted 10 lines · Daniel Kiper

Hey,

Adding Marta and Sebastian...

Quoted 5 lines · Andrey Albershteyn

haha what a chance!

Just today I was working on the same thing, and have almost identical patch which I was about to send :)

Quoted 8 lines
Quoted 2 lines

The patch looks good to me.

Marta, Sebastian, may I ask you to test this patch as well?

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#4 lore raw
In reply to Daniel Kiper
Quoted 10 lines · Daniel Kiper

Hey,

Adding Marta and Sebastian...

Quoted 5 lines · Andrey Albershteyn

haha what a chance!

Just today I was working on the same thing, and have almost identical patch which I was about to send :)

Quoted 6 lines
Quoted 2 lines

The patch looks good to me.

Marta, Sebastian, may I ask you to test this patch as well?

Sebastian, did you have a chance to test this patch?

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#5 lore raw
Quoted 1 line · Daniel Kiper

Sebastian, did you have a chance to test this patch?

Just did so.

I had the previous two plus this one. Did the previous two get merged in the meaintime or are they still undere review?

Quoted 1 line

Daniel

Sebastian

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#6 lore raw
Quoted 6 lines · Sebastian Andrzej Siewior
Quoted 1 line · Daniel Kiper

Sebastian, did you have a chance to test this patch?

Just did so.

Cool! Thanks a lot!

Quoted 2 lines

I had the previous two plus this one. Did the previous two get merged in the meaintime or are they still undere review?

I merged them in the meantime.

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#8 lore raw
In reply to Daniel Kiper
Quoted 4 lines · Daniel Kiper
Quoted 2 lines

I had the previous two plus this one. Did the previous two get merged in the meaintime or are they still undere review?

I merged them in the meantime.

I don't know how this works but

	https://savannah.gnu.org/bugs/?64376

could be closed (unless a release is required or so).

Quoted 1 line

Daniel

Sebastian

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Tested-by on v1 1/1
#9 lore raw
In reply to Anthony Iliopoulos via Grub-devel
Quoted 98 lines · Anthony Iliopoulos via Grub-devel

XFS introduced 64-bit extent counters for inodes via a series of upstream commits, and the feature was marked as stable in v6.5 via commit 61d7e8274cd8 ("xfs: drop EXPERIMENTAL tag for large extent counts").

Further, xfsprogs release v6.5.0 switched this feature on by default in mkfs.xfs via commit e5b18d7d1d96 ("mkfs: enable large extent counts by default").

Filesystems formatted with large extent count support (nrext64=1) are thus currently not recognizable by grub, since this is an incompat feature. Add the required support so that those filesystems and inodes with large extent counters can be read by grub.

---
  grub-core/fs/xfs.c | 30 +++++++++++++++++++++++++-----
  1 file changed, 25 insertions(+), 5 deletions(-)
grub-core/fs/xfs.c +24 -4
index b91cd32b49ab..ab0d2cdf55a2 100644
@@ -79,6 +79,8 @@ GRUB_MOD_LICENSE ("GPLv3+");
  /* Inode flags2 flags */
  #define XFS_DIFLAG2_BIGTIME_BIT	3
  #define XFS_DIFLAG2_BIGTIME		(1 << XFS_DIFLAG2_BIGTIME_BIT)
+#define XFS_DIFLAG2_NREXT64_BIT	4
+#define XFS_DIFLAG2_NREXT64		(1 << XFS_DIFLAG2_NREXT64_BIT)
 
  /* incompat feature flags */
  #define XFS_SB_FEAT_INCOMPAT_FTYPE      (1 << 0)        /* filetype in dirent */
@@ -86,6 +88,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
  #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 */
+#define XFS_SB_FEAT_INCOMPAT_NREXT64 (1 << 5)           /* large extent counters */
 
  /*
   * Directory entries with ftype are explicitly handled by GRUB code.
@@ -101,7 +104,8 @@ GRUB_MOD_LICENSE ("GPLv3+");
  	 XFS_SB_FEAT_INCOMPAT_SPINODES | \
  	 XFS_SB_FEAT_INCOMPAT_META_UUID | \
  	 XFS_SB_FEAT_INCOMPAT_BIGTIME | \
-	 XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR)
+	 XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR | \
+	 XFS_SB_FEAT_INCOMPAT_NREXT64)
 
  struct grub_xfs_sblock
  {
@@ -203,7 +207,8 @@ struct grub_xfs_inode
    grub_uint16_t mode;
    grub_uint8_t version;
    grub_uint8_t format;
-  grub_uint8_t unused2[26];
+  grub_uint8_t unused2[18];
+  grub_uint64_t nextents_big;
    grub_uint64_t atime;
    grub_uint64_t mtime;
    grub_uint64_t ctime;
@@ -539,11 +544,26 @@ get_fsb (const void *keys, int idx)
    return grub_be_to_cpu64 (grub_get_unaligned64 (p));
  }
 
+static int
+grub_xfs_inode_has_large_extent_counts (const struct grub_xfs_inode *inode)
+{
+  return inode->version >= 3 &&
+	 (inode->flags2 & grub_cpu_to_be64_compile_time (XFS_DIFLAG2_NREXT64));
+}
+
+static grub_uint64_t
+grub_xfs_get_inode_nextents (struct grub_xfs_inode *inode)
+{
+  return (grub_xfs_inode_has_large_extent_counts (inode)) ?
+	  grub_be_to_cpu64 (inode->nextents_big) :
+	  grub_be_to_cpu32 (inode->nextents);
+}
+
  static grub_disk_addr_t
  grub_xfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)
  {
    struct grub_xfs_btree_node *leaf = 0;
-  int ex, nrec;
+  grub_uint64_t ex, nrec;
    struct grub_xfs_extent *exts;
    grub_uint64_t ret = 0;
 
@@ -568,7 +588,7 @@ grub_xfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)
  				/ (2 * sizeof (grub_uint64_t));
        do
          {
-          int i;
+          grub_uint64_t i;
 
            for (i = 0; i < nrec; i++)
              {

grub-core/fs/xfs.c grub_xfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) · line 641

Quoted 8 lines
grub-core/fs/xfs.c +1 -1
@@ -615,7 +635,7 @@ grub_xfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)
        grub_addr_t exts_end = 0;
        grub_addr_t data_end = 0;
 
-      nrec = grub_be_to_cpu32 (node->inode.nextents);
+      nrec = grub_xfs_get_inode_nextents (&node->inode);
        exts = (struct grub_xfs_extent *) grub_xfs_inode_data(&node->inode);
 
        if (grub_mul (sizeof (struct grub_xfs_extent), nrec, &exts_end) ||

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#10 lore raw

PATCH 1/1 fs/xfs: add large extent counters incompat feature support

In reply to Anthony Iliopoulos via Grub-devel

Having applied the patches from:

[email protected]
[email protected]

and then used the result to build Debian-Installer, as seen here:

https://salsa.debian.org/philh/grub2/-/pipelines/596346

D-I's ability to install a system using an XFS file system is restored, as is the ability of the installed grub to subsequently boot, as seen here:

https://openqa.debian.net/tests/200503

Cheers, Phil.
--
Philip Hands -- https://hands.com/~phil

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#11 lore raw
Quoted 7 lines · Philip Hands

Having applied the patches from:

[email protected]
[email protected]

and then used the result to build Debian-Installer, as seen here:

Quoted 7 lines

https://salsa.debian.org/philh/grub2/-/pipelines/596346

D-I's ability to install a system using an XFS file system is restored, as is the ability of the installed grub to subsequently boot, as seen here:

https://openqa.debian.net/tests/200503

Great! Thanks a lot for the report!

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel