xfsprogs: last few fixes for 6.14
Hi everyone,
This is a collection of fixes for bugs that I stumbled over during the 6.14 QA cycle; and a libxfs sync for a cleanup that went in after -rc6.
--D
PATCH 1/2 xfsprogs: new libxfs code from kernel 6.14
Hi all,
Port kernel libxfs code to userspace.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
--D
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=libxfs-sync-6.14
---
Commits in this patchset:
* xfs: Use abs_diff instead of XFS_ABSDIFF
--- include/platform_defs.h | 19 +++++++++++++++++++ libxfs/xfs_alloc.c | 8 +++----- 2 files changed, 22 insertions(+), 5 deletions(-)
PATCH 1/1 xfs: Use abs_diff instead of XFS_ABSDIFF
From: Matthew Wilcox (Oracle) <[email protected]>
Source kernel commit: ca3ac4bf4dc307cea5781dccccf41c1d14c2f82f
We have a central definition for this function since 2023, used by a number of different parts of the kernel.
--- include/platform_defs.h | 19 +++++++++++++++++++ libxfs/xfs_alloc.c | 8 +++----- 2 files changed, 22 insertions(+), 5 deletions(-)
include/platform_defs.h +19 -0
@@ -261,4 +261,23 @@ static inline bool __must_check __must_check_overflow(bool overflow)__builtin_add_overflow (__a, __b, __d); \ })) +/** +* abs_diff - return absolute value of the difference between the arguments +* @a: the first argument +* @b: the second argument +* +* @a and @b have to be of the same type. With this restriction we compare +* signed to signed and unsigned to unsigned. The result is the subtraction +* the smaller of the two from the bigger, hence result is always a positive +* value. +* +* Return: an absolute value of the difference between the @a and @b. +*/ +#define abs_diff (a, b) ({ \ + typeof(a) __a = (a); \ + typeof(b) __b = (b); \ + (void)(&__a == &__b); \ + __a > __b ? (__a - __b) : (__b - __a); \ +}) +#endif /* __XFS_PLATFORM_DEFS_H__ */
libxfs/xfs_alloc.c +3 -5
@@ -29,8 +29,6 @@ struct kmem_cache *xfs_extfree_item_cache;struct workqueue_struct *xfs_alloc_wq; -#define XFS_ABSDIFF (a,b) (((a) <= (b)) ? ((b) - (a)) : ((a) - (b))) -#define XFSA_FIXUP_BNO_OK 1#define XFSA_FIXUP_CNT_OK 2
@@ -406,8 +404,8 @@ xfs_alloc_compute_diff(if (newbno1 !=NULLAGBLOCK && newbno2 !=NULLAGBLOCK ) {if (newlen1 < newlen2 || (newlen1 == newlen2 && -XFS_ABSDIFF (newbno1, wantbno) > -XFS_ABSDIFF (newbno2, wantbno))) +abs_diff (newbno1, wantbno) > +abs_diff (newbno2, wantbno))) newbno1 = newbno2; }else if (newbno2 !=NULLAGBLOCK ) newbno1 = newbno2;
@@ -423,7 +421,7 @@ xfs_alloc_compute_diff( }else newbno1 = freeend - wantlen; *newbnop = newbno1; -return newbno1 ==NULLAGBLOCK ?0 :XFS_ABSDIFF (newbno1, wantbno); +return newbno1 ==NULLAGBLOCK ?0 :abs_diff (newbno1, wantbno); }/*
PATCH 2/2 xfsprogs: random bug fixes
In reply to Darrick J. WongHi all,
Here's a pile of assorted bug fixes from around the codebase.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
With a bit of luck, this should all go splendidly. Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=random-fixes
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=random-fixes
fstests git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfstests-dev.git/log/?h=random-fixes
---
Commits in this patchset:
* xfs_repair: don't recreate /quota metadir if there are no quota inodes
* xfs_repair: fix crash in reset_rt_metadir_inodes
* xfs_repair: fix infinite loop in longform_dir2_entry_check*
* xfs_repair: fix stupid argument error in verify_inode_chunk
--- libxfs/libxfs_api_defs.h | 1 + repair/dino_chunks.c | 2 +- repair/phase6.c | 41 +++++++++++++++++++++++++++++++++++++---- 3 files changed, 39 insertions(+), 5 deletions(-)
PATCH 1/4 xfs_repair: don't recreate /quota metadir if there are no quota inodes
From: Darrick J. Wong <[email protected]>
If repair does not discover even a single quota file, then don't have it try to create a /quota metadir to hold them. This avoids pointless repair failures on quota-less filesystems that are nearly full.
Found via generic/558 on a zoned=1 filesystem.
--- repair/phase6.c | 5 +++++ 1 file changed, 5 insertions(+)
repair/phase6.c +5 -0
@@ -3538,6 +3538,11 @@ reset_quota_metadir_inodes(struct xfs_inode *dp =NULL ;int error; +if (!has_quota_inode (XFS_DQTYPE_USER ) && + !has_quota_inode (XFS_DQTYPE_GROUP ) && + !has_quota_inode (XFS_DQTYPE_PROJ )) +return ; + error = -libxfs_dqinode_mkdir_parent (mp, &dp);if (error) do_error(_("failed to create quota metadir (%d)\n"),
Re: [PATCH 1/4] xfs_repair: don't recreate /quota metadir if there are no quota inodes
Quoted 23 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
If repair does not discover even a single quota file, then don't have it try to create a /quota metadir to hold them. This avoids pointless repair failures on quota-less filesystems that are nearly full.
Found via generic/558 on a zoned=1 filesystem.
Cc <[email protected]> # v6.13.0Fixes b790ab2a303d58 ("xfs_repair: support quota inodes in the metadata directory")Signed-off-by "Darrick J. Wong" <[email protected]>--- repair/phase6.c | 5 +++++ 1 file changed, 5 insertions(+)repair/phase6.c +0
-0@@ -3538,6 +3538,11 @@ reset_quota_metadir_inodes(struct xfs_inode *dp =NULL ;
repair/phase6.c reset_quota_metadir_inodes( · line 3548
Quoted 10 lines
repair/phase6.c +5
-0int error; +if (!has_quota_inode (XFS_DQTYPE_USER ) && + !has_quota_inode (XFS_DQTYPE_GROUP ) && + !has_quota_inode (XFS_DQTYPE_PROJ )) +return ; + error = -libxfs_dqinode_mkdir_parent (mp, &dp);if (error) do_error(_("failed to create quota metadir (%d)\n"),
LGTM
Signature · 1 line
- Andrey
Re: [PATCH 1/4] xfs_repair: don't recreate /quota metadir if there are no quota inodes
In reply to Darrick J. WongQuoted 7 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
If repair does not discover even a single quota file, then don't have it try to create a /quota metadir to hold them. This avoids pointless repair failures on quota-less filesystems that are nearly full.
Found via generic/558 on a zoned=1 filesystem.
Interesting, I never saw that fail. Any interesting options you had to inject for that?
The patch itself looks fine, though:
Re: [PATCH 1/4] xfs_repair: don't recreate /quota metadir if there are no quota inodes
Quoted 11 lines · Christoph Hellwig
Quoted 7 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
If repair does not discover even a single quota file, then don't have it try to create a /quota metadir to hold them. This avoids pointless repair failures on quota-less filesystems that are nearly full.
Found via generic/558 on a zoned=1 filesystem.
Interesting, I never saw that fail. Any interesting options you had to inject for that?
No, just use a pathetically small device to try to pound on ENOSPC harder. ;)
--D
Quoted 5 lines
The patch itself looks fine, though:
Reviewed-by Christoph Hellwig <[email protected]>
PATCH 2/4 xfs_repair: fix crash in reset_rt_metadir_inodes
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
I observed that xfs_repair -n segfaults during xfs/812 after corrupting the /rtgroups metadir inode because mp->m_rtdirip isn't loaded. Fix the crash and print a warning about the missing inode.
--- repair/phase6.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
repair/phase6.c +10 -4
@@ -3397,15 +3397,21 @@ reset_rt_metadir_inodes(unload_rtgroup_inodes (mp);if (mp->m_sb.sb_rgcount >0 ) { -if (!no_modify) { +if (no_modify) { +if (!mp->m_rtdirip) +do_warn (_ ("would recreate realtime metadir\n" )); + }else { error = -libxfs_rtginode_mkdir_parent (mp);if (error)do_error (_ ("failed to create realtime metadir (%d)\n" ), error); } -mark_ino_inuse (mp, mp->m_rtdirip->i_ino,S_IFDIR , - mp->m_metadirip->i_ino); -mark_ino_metadata (mp, mp->m_rtdirip->i_ino); + +if (mp->m_rtdirip) { +mark_ino_inuse (mp, mp->m_rtdirip->i_ino,S_IFDIR , + mp->m_metadirip->i_ino); +mark_ino_metadata (mp, mp->m_rtdirip->i_ino); + } }/*
Re: [PATCH 2/4] xfs_repair: fix crash in reset_rt_metadir_inodes
Quoted 5 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
I observed that
xfs_repair-n segfaults during xfs/812 after corrupting the /rtgroups metadir inode becausemp->m_rtdiripisn't loaded. Fix the crash and print a warning about the missing inode.
Looks good:
PATCH 3/4 xfs_repair: fix infinite loop in longform_dir2_entry_check*
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
If someone corrupts the data fork of a directory to have a bmap record whose br_startoff only has bits set in the upper 32 bits, the code will suffer an integer overflow when assigning the 64-bit next_da_bno to the 32-bit da_bno. This leads to an infinite loop.
Found by fuzzing xfs/812 with u3.bmx[0].startoff = firstbit.
--- libxfs/libxfs_api_defs.h | 1 + repair/phase6.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+)
libxfs/libxfs_api_defs.h +1 -0
@@ -399,6 +399,7 @@#define xfs_verify_agbext libxfs_verify_agbext#define xfs_verify_agino libxfs_verify_agino#define xfs_verify_cksum libxfs_verify_cksum +#define xfs_verify_dablk libxfs_verify_dablk#define xfs_verify_dir_ino libxfs_verify_dir_ino#define xfs_verify_fsbext libxfs_verify_fsbext#define xfs_verify_fsbno libxfs_verify_fsbno
repair/phase6.c +22 -0
@@ -2169,6 +2169,13 @@ longform_dir2_check_node(if (bmap_next_offset (ip, &next_da_bno))break ; +if (next_da_bno !=NULLFILEOFF && + !libxfs_verify_dablk (mp, next_da_bno)) { +do_warn (_ ("invalid dir leaf block 0x%llx\n" ), + (unsigned long long )next_da_bno); +return 1 ; + } +/* * we need to use the da3 node verifier here as it handles the * fact that reading the leaf hash tree blocks can return either
@@ -2244,6 +2251,13 @@ longform_dir2_check_node(if (bmap_next_offset (ip, &next_da_bno))break ; +if (next_da_bno !=NULLFILEOFF && + !libxfs_verify_dablk (mp, next_da_bno)) { +do_warn (_ ("invalid dir free block 0x%llx\n" ), + (unsigned long long )next_da_bno); +return 1 ; + } + error =dir_read_buf (ip, da_bno, &bp, &xfs_dir3_free_buf_ops, &fixit);if (error) {
@@ -2379,6 +2393,14 @@ longform_dir2_entry_check(break ; } +if (next_da_bno !=NULLFILEOFF && + !libxfs_verify_dablk (mp, next_da_bno)) { +do_warn (_ ("invalid dir data block 0x%llx\n" ), + (unsigned long long )next_da_bno); + fixit++; + goto out_fix; + } +if (fmt ==XFS_DIR2_FMT_BLOCK ) ops = &xfs_dir3_block_buf_ops;else
Re: [PATCH 3/4] xfs_repair: fix infinite loop in longform_dir2_entry_check*
Looks good:
PATCH 4/4 xfs_repair: fix stupid argument error in verify_inode_chunk
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
An arm64 VM running fstests with 64k fsblock size blew up the test filesystem when the OOM killer whacked xfs_repair as it was rebuilding a sample filesystem. A subsequent attempt by fstests to repair the filesystem printed stuff like this:
inode rec for ino 39144576 (1/5590144) overlaps existing rec (start 1/5590144) inode rec for ino 39144640 (1/5590208) overlaps existing rec (start 1/5590208)
followed by a lot of errors such as:
cannot read agbno (1/5590208), disk block 734257664xfs_repair: error - read only 0 of 65536 bytes
Here we're feeding per-AG inode numbers into a block reading function as if it were a per-AG block number. This is wrong by a factor of 128x so we read past the end of the filesystem. Worse yet, the buffer cache fills up memory and thus the second repair process is also OOM killed. The filesystem is not fixed.
--- repair/dino_chunks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
repair/dino_chunks.c +1 -1
@@ -132,7 +132,7 @@ verify_inode_chunk(xfs_mount_t *mp,if (igeo->ialloc_blks ==1 ) {if (agbno > max_agbno)return 0 ; -if (check_aginode_block (mp, agno, agino) ==0 ) +if (check_aginode_block (mp, agno, agbno) ==0 )return 0 ;lock_ag (agno);
Re: [PATCH 4/4] xfs_repair: fix stupid argument error in verify_inode_chunk
Looks good: