linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] xfs: add check before calling xfs_mod_fdblocks
@ 2022-06-21  8:42 Shida Zhang
  2022-06-22  4:41 ` Darrick J. Wong
  0 siblings, 1 reply; 4+ messages in thread
From: Shida Zhang @ 2022-06-21  8:42 UTC (permalink / raw)
  To: djwong, dchinner; +Cc: zhangshida, starzhangzsd, linux-kernel, linux-xfs

Checks are missing when delta equals 0 in __xfs_ag_resv_free() and
__xfs_ag_resv_init().

the case that the delta equals 0 is reachable with the command
sequence below:

 # mkfs.xfs -f /dev/sdb5
 # mount /dev/sdb5 /mnt/scratch/

where /dev/sdb5 is my disk for test. And if the patch below is
applied:

====
xfs_mod_freecounter(
        if (rsvd)
                ASSERT(has_resv_pool);

+       if (delta == 0)
+               dump_stack();
+
        if (delta > 0) {
                /*
                 * If the reserve pool is depleted, put blocks back into it
====

the following stack will be shown in the message:

=>  xfs_mod_freecounter+0x84/0x2b8
=>  __xfs_ag_resv_free+0xc4/0x188
=>  xfs_ag_resv_free+0x24/0x50
=>  xfs_fs_unreserve_ag_blocks+0x40/0x160
=>  xfs_mountfs+0x500/0x900
=>  xfs_fs_fill_super+0x3d8/0x810
=>  get_tree_bdev+0x164/0x258
=>  xfs_fs_get_tree+0x20/0x30
=>  vfs_get_tree+0x30/0xf8
=>  path_mount+0x3c4/0xa58
=>  do_mount+0x74/0x98

=>  xfs_mod_freecounter+0x84/0x2b8
=>  __xfs_ag_resv_init+0x64/0x1d0
=>  xfs_ag_resv_init+0x108/0x1c8
=>  xfs_fs_reserve_ag_blocks+0x4c/0x110
=>  xfs_mountfs+0x57c/0x900
=>  xfs_fs_fill_super+0x3d8/0x810
=>  get_tree_bdev+0x164/0x258
=>  xfs_fs_get_tree+0x20/0x30
=>  vfs_get_tree+0x30/0xf8
=>  path_mount+0x3c4/0xa58
=>  do_mount+0x74/0x98

After applying this patch, we can avoid to call xfs_mod_fdblocks when
delta equals 0.

Signed-off-by: Shida Zhang <zhangshida@kylinos.cn>
---
 Changes from v1:
 -Add checks before calling xfs_mod_fdblocks instead.
 Changes from v2:
 -Rephrase the commit description.

 fs/xfs/libxfs/xfs_ag_resv.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/fs/xfs/libxfs/xfs_ag_resv.c b/fs/xfs/libxfs/xfs_ag_resv.c
index fe94058d4e9e..c8fa032e4b00 100644
--- a/fs/xfs/libxfs/xfs_ag_resv.c
+++ b/fs/xfs/libxfs/xfs_ag_resv.c
@@ -149,7 +149,12 @@ __xfs_ag_resv_free(
 		oldresv = resv->ar_orig_reserved;
 	else
 		oldresv = resv->ar_reserved;
-	error = xfs_mod_fdblocks(pag->pag_mount, oldresv, true);
+
+	if (oldresv)
+		error = xfs_mod_fdblocks(pag->pag_mount, oldresv, true);
+	else
+		error = 0;
+
 	resv->ar_reserved = 0;
 	resv->ar_asked = 0;
 	resv->ar_orig_reserved = 0;
@@ -215,8 +220,13 @@ __xfs_ag_resv_init(
 
 	if (XFS_TEST_ERROR(false, mp, XFS_ERRTAG_AG_RESV_FAIL))
 		error = -ENOSPC;
-	else
-		error = xfs_mod_fdblocks(mp, -(int64_t)hidden_space, true);
+	else {
+		error = 0;
+		if (hidden_space)
+			error = xfs_mod_fdblocks(mp, -(int64_t)hidden_space,
+						true);
+	}
+
 	if (error) {
 		trace_xfs_ag_resv_init_error(pag->pag_mount, pag->pag_agno,
 				error, _RET_IP_);
-- 
2.25.1


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

end of thread, other threads:[~2022-06-23  1:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-21  8:42 [PATCH v3] xfs: add check before calling xfs_mod_fdblocks Shida Zhang
2022-06-22  4:41 ` Darrick J. Wong
2022-06-22  5:57   ` Stephen Zhang
2022-06-23  1:15     ` Darrick J. Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).