diff mbox series

[v2] xfs: add check before calling xfs_mod_fdblocks

Message ID 20220621070224.1231039-1-zhangshida@kylinos.cn (mailing list archive)
State Superseded
Headers show
Series [v2] xfs: add check before calling xfs_mod_fdblocks | expand

Commit Message

zhangshida June 21, 2022, 7:02 a.m. UTC
Checks are missing when delta equals 0 in __xfs_ag_resv_free() and
__xfs_ag_resv_init().

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

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

Comments

zhangshida June 21, 2022, 7:12 a.m. UTC | #1
Shida Zhang <starzhangzsd@gmail.com> 于2022年6月21日周二 15:02写道:
>
> Checks are missing when delta equals 0 in __xfs_ag_resv_free() and
> __xfs_ag_resv_init().
>
> Signed-off-by: Shida Zhang <zhangshida@kylinos.cn>
> ---
>  Changes from v1:
>  -Add checks before calling xfs_mod_fdblocks instead.
>
>  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
>

And the code path that lead delta = 0 is shown below:

=> 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
Dave Chinner June 21, 2022, 7:39 a.m. UTC | #2
On Tue, Jun 21, 2022 at 03:02:24PM +0800, Shida Zhang wrote:
> Checks are missing when delta equals 0 in __xfs_ag_resv_free() and
> __xfs_ag_resv_init().

This describes what the patch does, not the problem being solved is. 

i.e. This doesn't tell the reader why the delta can be zero in these
places, nor does it tell them what the impact of it being zero is.
We can't use this information to identify a system that is having
problems due to this issue because they havent' been described.

Hence when I ask for more detail about how something occurs, what I'm
asking for is a description of the how the problem was found, what
the impact of the problem has on systems, how the problem is
reproduced, etc.

Something led you to finding this problem - tell us the story so we
also know what you know and so can understand why the change needs
to be made. A good commit description tells the reader everything
you know about the problem that needs to be fixed, the code change
itself will then describe how the problem was fixed...

Cheers,

Dave.
zhangshida June 21, 2022, 8:39 a.m. UTC | #3
Dave Chinner <david@fromorbit.com> 于2022年6月21日周二 15:39写道:
>
> On Tue, Jun 21, 2022 at 03:02:24PM +0800, Shida Zhang wrote:
> > Checks are missing when delta equals 0 in __xfs_ag_resv_free() and
> > __xfs_ag_resv_init().
>
> This describes what the patch does, not the problem being solved is.
>
> i.e. This doesn't tell the reader why the delta can be zero in these
> places, nor does it tell them what the impact of it being zero is.
> We can't use this information to identify a system that is having
> problems due to this issue because they havent' been described.
>
> Hence when I ask for more detail about how something occurs, what I'm
> asking for is a description of the how the problem was found, what
> the impact of the problem has on systems, how the problem is
> reproduced, etc.
>
> Something led you to finding this problem - tell us the story so we
> also know what you know and so can understand why the change needs
> to be made. A good commit description tells the reader everything
> you know about the problem that needs to be fixed, the code change
> itself will then describe how the problem was fixed...
>
> Cheers,
>
> Dave.
> --
> Dave Chinner
> david@fromorbit.com

Thanks for your suggestion. I will try to rephrase the description.

Cheers,

Stephen.
diff mbox series

Patch

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_);