* [PATCH v4 1/4] xfs: Fix xfs_last_rt_bmblock()
2026-02-20 6:53 [PATCH v4 0/4] xfs: Misc changes to XFS realtime Nirjhar Roy (IBM)
@ 2026-02-20 6:53 ` Nirjhar Roy (IBM)
2026-02-20 6:53 ` [PATCH v4 2/4] xfs: Add a comment in xfs_log_sb() Nirjhar Roy (IBM)
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Nirjhar Roy (IBM) @ 2026-02-20 6:53 UTC (permalink / raw)
To: djwong, hch, cem
Cc: linux-xfs, ritesh.list, ojaswin, nirjhar.roy.lists, nirjhar
From: "Nirjhar Roy (IBM)" <nirjhar.roy.lists@gmail.com>
Bug description:
If the size of the last rtgroup i.e, the rtg passed to
xfs_last_rt_bmblock() is such that the last rtextent falls in 0th word
offset of a bmblock of the bitmap file tracking this (last) rtgroup,
then in that case xfs_last_rt_bmblock() incorrectly returns the next
bmblock number instead of the current/last used bmblock number.
When xfs_last_rt_bmblock() incorrectly returns the next bmblock,
the loop to grow/modify the bmblocks in xfs_growfs_rtg() doesn't
execute and xfs_growfs basically does a nop in certain cases.
xfs_growfs will do a nop when the new size of the fs will have the same
number of rtgroups i.e, we are only growing the last rtgroup.
Reproduce:
$ mkfs.xfs -m metadir=0 -r rtdev=/dev/loop1 /dev/loop0 \
-r size=32769b -f
$ mount -o rtdev=/dev/loop1 /dev/loop0 /mnt/scratch
$ xfs_growfs -R $(( 32769 + 1 )) /mnt/scratch
$ xfs_info /mnt/scratch | grep rtextents
$ # We can see that rtextents hasn't changed
Fix:
Fix this by returning the current/last used bmblock when the last
rtgroup size is not a multiple xfs_rtbitmap_rtx_per_rbmblock()
and the next bmblock when the rtgroup size is a multiple of
xfs_rtbitmap_rtx_per_rbmblock() i.e, the existing blocks are
completely used up.
Also, I have renamed xfs_last_rt_bmblock() to
xfs_last_rt_bmblock_to_extend() to signify that this function
returns the bmblock number to extend and NOT always the last used
bmblock number.
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Signed-off-by: Nirjhar Roy (IBM) <nirjhar.roy.lists@gmail.com>
---
fs/xfs/xfs_rtalloc.c | 30 ++++++++++++++++++++++++------
1 file changed, 24 insertions(+), 6 deletions(-)
diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
index 90a94a5b6f7e..decbd07b94fd 100644
--- a/fs/xfs/xfs_rtalloc.c
+++ b/fs/xfs/xfs_rtalloc.c
@@ -1079,17 +1079,27 @@ xfs_last_rtgroup_extents(
}
/*
- * Calculate the last rbmblock currently used.
+ * This will return the bitmap block number (indexed at 0) that will be
+ * extended/modified. There are 2 cases here:
+ * 1. The size of the rtg is such that it is a multiple of
+ * xfs_rtbitmap_rtx_per_rbmblock() i.e, an integral number of bitmap blocks
+ * are completely filled up. In this case, we should return
+ * 1 + (the last used bitmap block number).
+ * 2. The size of the rtg is not an multiple of xfs_rtbitmap_rtx_per_rbmblock().
+ * Here we will return the block number of last used block number. In this
+ * case, we will modify the last used bitmap block to extend the size of the
+ * rtgroup.
*
* This also deals with the case where there were no rtextents before.
*/
static xfs_fileoff_t
-xfs_last_rt_bmblock(
+xfs_last_rt_bmblock_to_extend(
struct xfs_rtgroup *rtg)
{
struct xfs_mount *mp = rtg_mount(rtg);
xfs_rgnumber_t rgno = rtg_rgno(rtg);
xfs_fileoff_t bmbno = 0;
+ unsigned int mod = 0;
ASSERT(!mp->m_sb.sb_rgcount || rgno >= mp->m_sb.sb_rgcount - 1);
@@ -1097,9 +1107,16 @@ xfs_last_rt_bmblock(
xfs_rtxnum_t nrext = xfs_last_rtgroup_extents(mp);
/* Also fill up the previous block if not entirely full. */
- bmbno = xfs_rtbitmap_blockcount_len(mp, nrext);
- if (xfs_rtx_to_rbmword(mp, nrext) != 0)
- bmbno--;
+ /* We are doing a -1 to convert it to a 0 based index */
+ bmbno = xfs_rtbitmap_blockcount_len(mp, nrext) - 1;
+ div_u64_rem(nrext, xfs_rtbitmap_rtx_per_rbmblock(mp), &mod);
+ /*
+ * mod = 0 means that all the current blocks are full. So
+ * return the next block number to be used for the rtgroup
+ * growth.
+ */
+ if (mod == 0)
+ bmbno++;
}
return bmbno;
@@ -1204,7 +1221,8 @@ xfs_growfs_rtg(
goto out_rele;
}
- for (bmbno = xfs_last_rt_bmblock(rtg); bmbno < bmblocks; bmbno++) {
+ for (bmbno = xfs_last_rt_bmblock_to_extend(rtg); bmbno < bmblocks;
+ bmbno++) {
error = xfs_growfs_rt_bmblock(rtg, nrblocks, rextsize, bmbno);
if (error)
goto out_error;
--
2.43.5
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH v4 2/4] xfs: Add a comment in xfs_log_sb()
2026-02-20 6:53 [PATCH v4 0/4] xfs: Misc changes to XFS realtime Nirjhar Roy (IBM)
2026-02-20 6:53 ` [PATCH v4 1/4] xfs: Fix xfs_last_rt_bmblock() Nirjhar Roy (IBM)
@ 2026-02-20 6:53 ` Nirjhar Roy (IBM)
2026-02-20 6:54 ` [PATCH v4 3/4] xfs: Update lazy counters in xfs_growfs_rt_bmblock() Nirjhar Roy (IBM)
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Nirjhar Roy (IBM) @ 2026-02-20 6:53 UTC (permalink / raw)
To: djwong, hch, cem
Cc: linux-xfs, ritesh.list, ojaswin, nirjhar.roy.lists, nirjhar
From: "Nirjhar Roy (IBM)" <nirjhar.roy.lists@gmail.com>
Add a comment explaining why the sb_frextents are updated outside the
if (xfs_has_lazycount(mp) check even though it is a lazycounter.
RT groups are supported only in v5 filesystems which always have
lazycounter enabled - so putting it inside the if(xfs_has_lazycount(mp)
check is redundant.
Suggested-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Nirjhar Roy (IBM) <nirjhar.roy.lists@gmail.com>
---
fs/xfs/libxfs/xfs_sb.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c
index 38d16fe1f6d8..47322adb7690 100644
--- a/fs/xfs/libxfs/xfs_sb.c
+++ b/fs/xfs/libxfs/xfs_sb.c
@@ -1347,6 +1347,9 @@ xfs_log_sb(
* feature was introduced. This counter can go negative due to the way
* we handle nearly-lockless reservations, so we must use the _positive
* variant here to avoid writing out nonsense frextents.
+ *
+ * RT groups are only supported on v5 file systems, which always
+ * have lazy SB counters.
*/
if (xfs_has_rtgroups(mp) && !xfs_has_zoned(mp)) {
mp->m_sb.sb_frextents =
--
2.43.5
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH v4 3/4] xfs: Update lazy counters in xfs_growfs_rt_bmblock()
2026-02-20 6:53 [PATCH v4 0/4] xfs: Misc changes to XFS realtime Nirjhar Roy (IBM)
2026-02-20 6:53 ` [PATCH v4 1/4] xfs: Fix xfs_last_rt_bmblock() Nirjhar Roy (IBM)
2026-02-20 6:53 ` [PATCH v4 2/4] xfs: Add a comment in xfs_log_sb() Nirjhar Roy (IBM)
@ 2026-02-20 6:54 ` Nirjhar Roy (IBM)
2026-02-20 6:54 ` [PATCH v4 4/4] xfs: Add comments for usages of some macros Nirjhar Roy (IBM)
2026-02-25 9:38 ` [PATCH v4 0/4] xfs: Misc changes to XFS realtime Carlos Maiolino
4 siblings, 0 replies; 6+ messages in thread
From: Nirjhar Roy (IBM) @ 2026-02-20 6:54 UTC (permalink / raw)
To: djwong, hch, cem
Cc: linux-xfs, ritesh.list, ojaswin, nirjhar.roy.lists, nirjhar
From: "Nirjhar Roy (IBM)" <nirjhar.roy.lists@gmail.com>
Update lazy counters in xfs_growfs_rt_bmblock() similar to the way it
is done xfs_growfs_data_private(). This is because the lazy counters are
not always updated and synching the counters will avoid inconsistencies
between frexents and rtextents(total realtime extent count). This will
be more useful once realtime shrink is implemented as this will prevent
some transient state to occur where frexents might be greater than
total rtextents.
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Nirjhar Roy (IBM) <nirjhar.roy.lists@gmail.com>
---
fs/xfs/xfs_rtalloc.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
index decbd07b94fd..9d451474088c 100644
--- a/fs/xfs/xfs_rtalloc.c
+++ b/fs/xfs/xfs_rtalloc.c
@@ -1047,6 +1047,15 @@ xfs_growfs_rt_bmblock(
*/
xfs_trans_resv_calc(mp, &mp->m_resv);
+ /*
+ * Sync sb counters now to reflect the updated values. Lazy counters are
+ * not always updated and in order to avoid inconsistencies between
+ * frextents and rtextents, it is better to sync the counters.
+ */
+
+ if (xfs_has_lazysbcount(mp))
+ xfs_log_sb(args.tp);
+
error = xfs_trans_commit(args.tp);
if (error)
goto out_free;
--
2.43.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v4 4/4] xfs: Add comments for usages of some macros.
2026-02-20 6:53 [PATCH v4 0/4] xfs: Misc changes to XFS realtime Nirjhar Roy (IBM)
` (2 preceding siblings ...)
2026-02-20 6:54 ` [PATCH v4 3/4] xfs: Update lazy counters in xfs_growfs_rt_bmblock() Nirjhar Roy (IBM)
@ 2026-02-20 6:54 ` Nirjhar Roy (IBM)
2026-02-25 9:38 ` [PATCH v4 0/4] xfs: Misc changes to XFS realtime Carlos Maiolino
4 siblings, 0 replies; 6+ messages in thread
From: Nirjhar Roy (IBM) @ 2026-02-20 6:54 UTC (permalink / raw)
To: djwong, hch, cem
Cc: linux-xfs, ritesh.list, ojaswin, nirjhar.roy.lists, nirjhar
From: "Nirjhar Roy (IBM)" <nirjhar.roy.lists@gmail.com>
Add comments explaining when to use XFS_IS_CORRUPT() and ASSERT()
Suggested-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Nirjhar Roy (IBM) <nirjhar.roy.lists@gmail.com>
---
fs/xfs/xfs_platform.h | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/fs/xfs/xfs_platform.h b/fs/xfs/xfs_platform.h
index 1e59bf94d1f2..59a33c60e0ca 100644
--- a/fs/xfs/xfs_platform.h
+++ b/fs/xfs/xfs_platform.h
@@ -235,6 +235,10 @@ int xfs_rw_bdev(struct block_device *bdev, sector_t sector, unsigned int count,
#ifdef XFS_WARN
+/*
+ * Please note that this ASSERT doesn't kill the kernel. It will if the kernel
+ * has panic_on_warn set.
+ */
#define ASSERT(expr) \
(likely(expr) ? (void)0 : asswarn(NULL, #expr, __FILE__, __LINE__))
@@ -245,6 +249,11 @@ int xfs_rw_bdev(struct block_device *bdev, sector_t sector, unsigned int count,
#endif /* XFS_WARN */
#endif /* DEBUG */
+/*
+ * Use this to catch metadata corruptions that are not caught by block or
+ * structure verifiers. The reason is that the verifiers check corruptions only
+ * within the scope of the object being verified.
+ */
#define XFS_IS_CORRUPT(mp, expr) \
(unlikely(expr) ? xfs_corruption_error(#expr, XFS_ERRLEVEL_LOW, (mp), \
NULL, 0, __FILE__, __LINE__, \
--
2.43.5
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH v4 0/4] xfs: Misc changes to XFS realtime
2026-02-20 6:53 [PATCH v4 0/4] xfs: Misc changes to XFS realtime Nirjhar Roy (IBM)
` (3 preceding siblings ...)
2026-02-20 6:54 ` [PATCH v4 4/4] xfs: Add comments for usages of some macros Nirjhar Roy (IBM)
@ 2026-02-25 9:38 ` Carlos Maiolino
4 siblings, 0 replies; 6+ messages in thread
From: Carlos Maiolino @ 2026-02-25 9:38 UTC (permalink / raw)
To: djwong, hch, Nirjhar Roy (IBM)
Cc: linux-xfs, ritesh.list, ojaswin, nirjhar.roy.lists
On Fri, 20 Feb 2026 12:23:57 +0530, Nirjhar Roy (IBM) wrote:
> From: "Nirjhar Roy (IBM)" <nirjhar.roy.lists@gmail.com>
>
> This series has a bug fix and adds some missing operations to
> growfs code in the realtime code. Details are in the commit messages.
>
> [v3]- v4
> 1. Added RBs from Darrick patch 1,2,3.
> 2. Updated the comments in patch 4.
>
> [...]
Applied to for-next, thanks!
[1/4] xfs: Fix xfs_last_rt_bmblock()
commit: 5c230c08da92e8b4a4916b9de4bb87521adcba0e
[2/4] xfs: Add a comment in xfs_log_sb()
commit: d93c48bfe3d969d370512f5adbfa29bcb91e020b
[3/4] xfs: Update lazy counters in xfs_growfs_rt_bmblock()
commit: e37c36b26503edcfd8824ed16b256d83b58c2faf
[4/4] xfs: Add comments for usages of some macros.
commit: fddf473b28fb68aefc56959cd86faf3acb5a8621
Best regards,
--
Carlos Maiolino <cem@kernel.org>
^ permalink raw reply [flat|nested] 6+ messages in thread