public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xfs: make sure sb_fdblocks is non-negative
@ 2024-05-11  0:34 Wengang Wang
  2024-05-11  1:17 ` Dave Chinner
  2024-05-31 15:52 ` Darrick J. Wong
  0 siblings, 2 replies; 10+ messages in thread
From: Wengang Wang @ 2024-05-11  0:34 UTC (permalink / raw)
  To: linux-xfs; +Cc: wen.gang.wang

when writting super block to disk (in xfs_log_sb), sb_fdblocks is fetched from
m_fdblocks without any lock. As m_fdblocks can experience a positive -> negativ
 -> positive changing when the FS reaches fullness (see xfs_mod_fdblocks)
So there is a chance that sb_fdblocks is negative, and because sb_fdblocks is
type of unsigned long long, it reads super big. And sb_fdblocks being bigger
than sb_dblocks is a problem during log recovery, xfs_validate_sb_write()
complains.

Fix:
As sb_fdblocks will be re-calculated during mount when lazysbcount is enabled,
We just need to make xfs_validate_sb_write() happy -- make sure sb_fdblocks is
not genative.

Signed-off-by: Wengang Wang <wen.gang.wang@oracle.com>
---
 fs/xfs/libxfs/xfs_sb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c
index 73a4b895de67..199756970383 100644
--- a/fs/xfs/libxfs/xfs_sb.c
+++ b/fs/xfs/libxfs/xfs_sb.c
@@ -1037,7 +1037,7 @@ xfs_log_sb(
 		mp->m_sb.sb_ifree = min_t(uint64_t,
 				percpu_counter_sum(&mp->m_ifree),
 				mp->m_sb.sb_icount);
-		mp->m_sb.sb_fdblocks = percpu_counter_sum(&mp->m_fdblocks);
+		mp->m_sb.sb_fdblocks = percpu_counter_sum_positive(&mp->m_fdblocks);
 	}
 
 	xfs_sb_to_disk(bp->b_addr, &mp->m_sb);
-- 
2.39.3 (Apple Git-146)


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-06-04  4:06 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-11  0:34 [PATCH] xfs: make sure sb_fdblocks is non-negative Wengang Wang
2024-05-11  1:17 ` Dave Chinner
2024-05-13 17:06   ` Wengang Wang
2024-05-31 15:44     ` Wengang Wang
2024-06-02 23:37       ` Dave Chinner
2024-06-03 17:23         ` Wengang Wang
2024-06-03 18:43           ` Darrick J. Wong
2024-06-04  4:06             ` Dave Chinner
2024-05-31 15:52 ` Darrick J. Wong
2024-05-31 18:03   ` Wengang Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox