xfs: Clear a couple of W=1 warnings
cover xfs: Clear a couple of W=1 warnings
For configs XFS_DEBUG and XFS_WARN disabled, there are a couple of W=1 warnings for unused variables. I have attempted to clear these here by simply marking the unused variables as __maybe_unused.
I suppose that another solution would be to change the ASSERT() statement relevant to this config from:
#define ASSERT(expr) ((void)0)
to:
#define ASSERT(expr) ((void)(expr))
Then the problem is that some local variables need to lose the #ifdef XFS_DEBUG guards, as those variables are now referenced in ASSERT(). This means that the objcode grows ever so slightly. I assume that this has all been considered previously...
Based on v6.9-rc5
John Garry (2):
xfs: Clear W=1 warning in xfs_iwalk_run_callbacks():
xfs: Clear W=1 warning in xfs_trans_unreserve_and_mod_sb():
fs/xfs/xfs_iwalk.c | 2 +- fs/xfs/xfs_trans.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.31.1
PATCH 1/2 xfs: Clear W=1 warning in xfs_iwalk_run_callbacks():
For CONFIG_XFS_DEBUG unset, xfs_iwalk_run_callbacks() generates the following warning for when building with W=1:
fs/xfs/xfs_iwalk.c: In function ‘xfs_iwalk_run_callbacks’:fs/xfs/xfs_iwalk.c:354:42: error: variable ‘irec’ set but not used [-Werror=unused-but-set-variable]
354 | struct xfs_inobt_rec_incore *irec;
| ^~~~
cc1: all warnings being treated as errors
Mark irec as __maybe_unused to clear the warning.
--- fs/xfs/xfs_iwalk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_iwalk.c +1 -1
@@ -351,7 +351,7 @@ xfs_iwalk_run_callbacks( int *has_more) {struct xfs_mount *mp = iwag->mp; -struct xfs_inobt_rec_incore *irec; +struct xfs_inobt_rec_incore __maybe_unused *irec;xfs_agino_t next_agino;int error;
Signature · 1 line
2.31.1
Re: [PATCH 1/2] xfs: Clear W=1 warning in xfs_iwalk_run_callbacks():
Review
Quoted 1 line · John Garry
(quoted diff) +1
-0+ struct xfs_inobt_rec_incore __maybe_unused *irec;
I've never seen code where __maybe_unused is the right answer, and this is no exception.
Just remove this instance of irec, which also removes the variable shadowing by the one inside the loop below.
fs/xfs/xfs_iwalk.c +2 -3
@@ -351,7 +351,6 @@ xfs_iwalk_run_callbacks( int *has_more) {struct xfs_mount *mp = iwag->mp; -struct xfs_inobt_rec_incore *irec;xfs_agino_t next_agino;int error;
@@ -361,8 +360,8 @@ xfs_iwalk_run_callbacks(/* Delete cursor but remember the last record we cached... */ xfs_iwalk_del_inobt (iwag->tp, curpp, agi_bpp,0 ); - irec = &iwag->recs[iwag->nr_recs -1 ]; -ASSERT (next_agino >= irec->ir_startino +XFS_INODES_PER_CHUNK ); +ASSERT (next_agino >= iwag->recs[iwag->nr_recs -1 ].ir_startino + +XFS_INODES_PER_CHUNK );if (iwag->drop_trans) {xfs_trans_cancel (iwag->tp);
Re: [PATCH 1/2] xfs: Clear W=1 warning in xfs_iwalk_run_callbacks():
Quoted 5 lines · Christoph Hellwig
Review
Quoted 1 line · John Garry
(quoted diff) +1
-0+ struct xfs_inobt_rec_incore __maybe_unused *irec;I've never seen code where
__maybe_unusedis the right answer, and this is no exception.
Then what about 9798f615ad2be?
Quoted 17 lines
Just remove this instance of irec, which also removes the variable shadowing by the one inside the loop below.
fs/xfs/xfs_iwalk.c +0
-1@@ -351,7 +351,6 @@ xfs_iwalk_run_callbacks( int *has_more) {struct xfs_mount *mp = iwag->mp; -struct xfs_inobt_rec_incore *irec;xfs_agino_t next_agino;int error;
fs/xfs/xfs_iwalk.c xfs_iwalk_run_callbacks( · line 365
Quoted 8 lines
fs/xfs/xfs_iwalk.c +2
-2@@ -361,8 +360,8 @@ xfs_iwalk_run_callbacks(/* Delete cursor but remember the last record we cached... */ xfs_iwalk_del_inobt (iwag->tp, curpp, agi_bpp,0 ); - irec = &iwag->recs[iwag->nr_recs -1 ]; -ASSERT (next_agino >= irec->ir_startino +XFS_INODES_PER_CHUNK ); +ASSERT (next_agino >= iwag->recs[iwag->nr_recs -1 ].ir_startino + +XFS_INODES_PER_CHUNK );
ok, that seems better.
Quoted 2 lines
fs/xfs/xfs_iwalk.c +0
-0if (iwag->drop_trans) {xfs_trans_cancel (iwag->tp);
Re: [PATCH 1/2] xfs: Clear W=1 warning in xfs_iwalk_run_callbacks():
Quoted 8 lines · John Garry
Quoted 5 lines · Christoph Hellwig
Review
Quoted 1 line · John Garry
(quoted diff) +1
-0+ struct xfs_inobt_rec_incore __maybe_unused *irec;I've never seen code where
__maybe_unusedis the right answer, and this is no exception.Then what about
9798f615ad2be?
Also not great and should be fixed.
(it also wasn't in the original patch and only got added working around some debug warnings)
Re: [PATCH 1/2] xfs: Clear W=1 warning in xfs_iwalk_run_callbacks():
Quoted 7 lines · Christoph Hellwig
Quoted 3 lines
Quoted 2 lines
I've never seen code where
__maybe_unusedis the right answer, and this is no exception.Then what about
9798f615ad2be?Also not great and should be fixed.
(it also wasn't in the original patch and only got added working around some debug warnings)
Fine, I'll look to remove those ones as well, which I think is possible with the same method you suggest.
However, there seems to be many more in -next now, but not for local variables..
Re: [PATCH 1/2] xfs: Clear W=1 warning in xfs_iwalk_run_callbacks():
Quoted 5 lines · John Garry
Quoted 3 lines
(it also wasn't in the original patch and only got added working around some debug warnings)
Fine, I'll look to remove those ones as well, which I think is possible with the same method you suggest.
It's a bit messy, as xfs_buf.b_addr is a void *:
From 1181afdac3d61b79813381d308b9ab2ebe30abca Mon Sep 17 00:00:00 2001
From: John Garry <[email protected]>
Date: Thu, 25 Apr 2024 16:23:49 +0100
Subject: [PATCH] xfs: Stop using __maybe_unused in xfs_alloc.c
fs/xfs/libxfs/xfs_alloc.c +7 -8
@@ -1008,13 +1008,13 @@ xfs_alloc_cur_finish(struct xfs_alloc_arg *args, struct xfs_alloc_cur *acur) { - struct xfs_agf __maybe_unused *agf = args->agbp->b_addr; int error;ASSERT (acur->cnt && acur->bnolt);ASSERT (acur->bno >= acur->rec_bno);ASSERT (acur->bno + acur->len <= acur->rec_bno + acur->rec_len); -ASSERT (acur->rec_bno + acur->rec_len <=be32_to_cpu (agf->agf_length)); +ASSERT (acur->rec_bno + acur->rec_len <= +be32_to_cpu (((struct xfs_agf *)args->agbp->b_addr)->agf_length)); error =xfs_alloc_fixup_trees (acur->cnt, acur->bnolt, acur->rec_bno, acur->rec_len, acur->bno, acur->len,0 );
@@ -1217,7 +1217,7 @@ STATIC int /* error */xfs_alloc_ag_vextent_exact ( xfs_alloc_arg_t *args) /* allocation argument structure */ { -struct xfs_agf __maybe_unused *agf = args->agbp->b_addr; +struct xfs_buf *agbp = args->agbp;struct xfs_btree_cur *bno_cur;/* by block-number btree cursor */ struct xfs_btree_cur *cnt_cur;/* by count btree cursor */ int error;
@@ -1234,8 +1234,7 @@ xfs_alloc_ag_vextent_exact(/* * Allocate/initialize a cursor for the by-number freespace btree. */ - bno_cur =xfs_bnobt_init_cursor (args->mp, args->tp, args->agbp, - args->pag); + bno_cur =xfs_bnobt_init_cursor (args->mp, args->tp, agbp, args->pag);/* * Lookup bno and minlen in the btree (minlen is irrelevant, really).
@@ -1295,9 +1294,9 @@ xfs_alloc_ag_vextent_exact(* We are allocating agbno for args->len * Allocate/initialize a cursor for the by-size btree. */ - cnt_cur =xfs_cntbt_init_cursor (args->mp, args->tp, args->agbp, - args->pag); -ASSERT (args->agbno + args->len <=be32_to_cpu (agf->agf_length)); + cnt_cur =xfs_cntbt_init_cursor (args->mp, args->tp, agbp, args->pag); +ASSERT (args->agbno + args->len <= +be32_to_cpu (((struct xfs_agf *)agbp->b_addr)->agf_length)); error =xfs_alloc_fixup_trees (cnt_cur, bno_cur, fbno, flen, args->agbno, args->len,XFSA_FIXUP_BNO_OK );if (error) {
Signature · 6 lines
2.35.3 --- There's a few ways to improve this, like make xfs_buf.b_addr a union, but I am not sure if it is worth it.
Re: [PATCH 1/2] xfs: Clear W=1 warning in xfs_iwalk_run_callbacks():
Quoted 21 lines · John Garry
Quoted 6 lines · John Garry
Quoted 3 lines
(it also wasn't in the original patch and only got added working around some debug warnings)
Fine, I'll look to remove those ones as well, which I think is possible with the same method you suggest.
It's a bit messy, as xfs_buf.b_addr is a void *:
From
1181afdac3d61b79813381d308b9ab2ebe30abcaMon Sep 17 00:00:00 2001
From: John Garry <[email protected]>
Date: Thu, 25 Apr 2024 16:23:49 +0100
Subject: [PATCH] xfs: Stop using__maybe_unusedinxfs_alloc.cfs/xfs/libxfs/xfs_alloc.c +0
-0
fs/xfs/libxfs/xfs_alloc.c xfs_alloc_cur_finish( · line 1011
Quoted 4 lines
fs/xfs/libxfs/xfs_alloc.c +0
-1@@ -1008,13 +1008,13 @@ xfs_alloc_cur_finish(struct xfs_alloc_arg *args, struct xfs_alloc_cur *acur) { - struct xfs_agf __maybe_unused *agf = args->agbp->b_addr;
If you surround this declaration with #ifdef DEBUG, will the warning go away...
fs/xfs/libxfs/xfs_alloc.c xfs_alloc_cur_finish( · line 1017
Quoted 8 lines
fs/xfs/libxfs/xfs_alloc.c +2
-1int error;ASSERT (acur->cnt && acur->bnolt);ASSERT (acur->bno >= acur->rec_bno);ASSERT (acur->bno + acur->len <= acur->rec_bno + acur->rec_len); -ASSERT (acur->rec_bno + acur->rec_len <=be32_to_cpu (agf->agf_length)); +ASSERT (acur->rec_bno + acur->rec_len <= +be32_to_cpu (((struct xfs_agf *)args->agbp->b_addr)->agf_length));
...without the need for this?
--D
Quoted 45 lines
fs/xfs/libxfs/xfs_alloc.c +5
-6error =xfs_alloc_fixup_trees (acur->cnt, acur->bnolt, acur->rec_bno, acur->rec_len, acur->bno, acur->len,0 );@@ -1217,7 +1217,7 @@ STATIC int /* error */xfs_alloc_ag_vextent_exact ( xfs_alloc_arg_t *args) /* allocation argument structure */ { -struct xfs_agf __maybe_unused *agf = args->agbp->b_addr; +struct xfs_buf *agbp = args->agbp;struct xfs_btree_cur *bno_cur;/* by block-number btree cursor */ struct xfs_btree_cur *cnt_cur;/* by count btree cursor */ int error;@@ -1234,8 +1234,7 @@ xfs_alloc_ag_vextent_exact(/* * Allocate/initialize a cursor for the by-number freespace btree. */ - bno_cur =xfs_bnobt_init_cursor (args->mp, args->tp, args->agbp, - args->pag); + bno_cur =xfs_bnobt_init_cursor (args->mp, args->tp, agbp, args->pag);/* * Lookup bno and minlen in the btree (minlen is irrelevant, really). @@ -1295,9 +1294,9 @@ xfs_alloc_ag_vextent_exact(* We are allocating agbno for args->len * Allocate/initialize a cursor for the by-size btree. */ - cnt_cur =xfs_cntbt_init_cursor (args->mp, args->tp, args->agbp, - args->pag); -ASSERT (args->agbno + args->len <=be32_to_cpu (agf->agf_length)); + cnt_cur =xfs_cntbt_init_cursor (args->mp, args->tp, agbp, args->pag); +ASSERT (args->agbno + args->len <= +be32_to_cpu (((struct xfs_agf *)agbp->b_addr)->agf_length)); error =xfs_alloc_fixup_trees (cnt_cur, bno_cur, fbno, flen, args->agbno, args->len,XFSA_FIXUP_BNO_OK );if (error) {Signature · 7 lines
2.35.3 --- There's a few ways to improve this, like make xfs_buf.b_addr a union, but I am not sure if it is worth it.
Re: [PATCH 1/2] xfs: Clear W=1 warning in xfs_iwalk_run_callbacks():
In reply to John GarryQuoted 23 lines · John Garry
Quoted 6 lines · John Garry
Quoted 3 lines
(it also wasn't in the original patch and only got added working around some debug warnings)
Fine, I'll look to remove those ones as well, which I think is possible with the same method you suggest.
It's a bit messy, as xfs_buf.b_addr is a void *:
From
1181afdac3d61b79813381d308b9ab2ebe30abcaMon Sep 17 00:00:00 2001
From: John Garry <[email protected]>
Date: Thu, 25 Apr 2024 16:23:49 +0100
Subject: [PATCH] xfs: Stop using__maybe_unusedinxfs_alloc.cfs/xfs/libxfs/xfs_alloc.c +0
-0@@ -1008,13 +1008,13 @@ xfs_alloc_cur_finish(struct xfs_alloc_arg *args, struct xfs_alloc_cur *acur)
fs/xfs/libxfs/xfs_alloc.c xfs_alloc_cur_finish( · line 1017
Quoted 10 lines
fs/xfs/libxfs/xfs_alloc.c +2
-2{ -struct xfs_agf __maybe_unused *agf = args->agbp->b_addr;int error;ASSERT (acur->cnt && acur->bnolt);ASSERT (acur->bno >= acur->rec_bno);ASSERT (acur->bno + acur->len <= acur->rec_bno + acur->rec_len); -ASSERT (acur->rec_bno + acur->rec_len <=be32_to_cpu (agf->agf_length)); +ASSERT (acur->rec_bno + acur->rec_len <= +be32_to_cpu (((struct xfs_agf *)args->agbp->b_addr)->agf_length));
Please think about what the code is actually doing and our data structures a little more deeply - this is can be fixed in a much better way than doing a mechanical code change.
agf->agf_length is what, exactly?
It's an on-disk constant for the AG size held in the AGF.
What is this ASSERT check doing?
It is verifying the agbno of the end of the extent is within valid bounds.
Do we have a pre-computed in memory constant for this on disk value?
Yes, we do: pag->block_count
Do we have a function to verify an agbno is within valid bounds of the AG using these in-memory constants?
Yes, we do: xfs_verify_agbno().
Do we have a function to verify an extent is within the valid bounds of the AG using these in-memory constants?
Yes, we do: xfs_verify_agbext()
Can this be written differently that has no need to access the on-disk AGF at all?
Yes, it can: ASSERT(xfs_verify_agbno(args->pag, acur->rec_bno + acur->rec_len)); or: ASSERT(xfs_verify_agbext(args->pag, acur->rec_bno, acur->rec_len));
The latter is better, as it verifies both the start and the end of the extent are within the bounds of the AG and catches overflows...
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 1/2] xfs: Clear W=1 warning in xfs_iwalk_run_callbacks():
Quoted 8 lines · Dave Chinner
ASSERT(xfs_verify_agbno(args->pag, acur->rec_bno + acur->rec_len)); or: ASSERT(xfs_verify_agbext(args->pag, acur->rec_bno, acur->rec_len));The latter is better, as it verifies both the start and the end of the extent are within the bounds of the AG and catches overflows...
Yupp. That's what I mean with my original comment - once you start thinking a little bigger there is usually a much better option than these __maybe_unused hacks.
Using perag fields and helpers instead of raw buffer access would also benefit a few other places in the allocator as well.
Re: [PATCH 1/2] xfs: Clear W=1 warning in xfs_iwalk_run_callbacks():
In reply to Dave ChinnerQuoted 11 lines · Dave Chinner
Can this be written differently that has no need to access the on-disk AGF at all?
Yes, it can: ASSERT(xfs_verify_agbno(args->pag, acur->rec_bno + acur->rec_len)); or: ASSERT(xfs_verify_agbext(args->pag, acur->rec_bno, acur->rec_len));
Quoted 2 lines
The latter is better, as it verifies both the start and the end of the extent are within the bounds of the AG and catches overflows...
Fine.
I'll send a single patch to convert both instances in xfs_alloc.c and tag you as "Originally-by" in the patch. Let me know if not ok.
Thanks,
John
PATCH 2/2 xfs: Clear W=1 warning in xfs_trans_unreserve_and_mod_sb():
In reply to John GarryFor CONFIG_XFS_DEBUG unset, xfs_trans_unreserve_and_mod_sb() generates the following warning for when building with W=1:
CC fs/xfs/xfs_trans.ofs/xfs/xfs_trans.c: In function ‘xfs_trans_unreserve_and_mod_sb’:fs/xfs/xfs_trans.c:601:17: error: variable ‘error’ set but not used [-Werror=unused-but-set-variable]
601 | int error;
| ^~~~~cc1: all warnings being treated as errors
Mark ret as __maybe_unused to clear the warning.
--- fs/xfs/xfs_trans.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_trans.c +1 -1
@@ -598,7 +598,7 @@ xfs_trans_unreserve_and_mod_sb(int64_t rtxdelta =0 ;int64_t idelta =0 ;int64_t ifreedelta =0 ; -int error; +int __maybe_unused error;/* calculate deltas */ if (tp->t_blk_res >0 )
Signature · 1 line
2.31.1
Re: [PATCH 2/2] xfs: Clear W=1 warning in xfs_trans_unreserve_and_mod_sb():
fs/xfs/xfs_trans.c xfs_trans_unreserve_and_mod_sb( · line 601
Quoted 1 line
fs/xfs/xfs_trans.c +1
-0+int __maybe_unused error;
error is gone in for-next.
Re: [PATCH 2/2] xfs: Clear W=1 warning in xfs_trans_unreserve_and_mod_sb():
Quoted 4 lines · Christoph Hellwig
fs/xfs/xfs_trans.c xfs_trans_unreserve_and_mod_sb( · line 601
Quoted 1 line
fs/xfs/xfs_trans.c +1
-0+int __maybe_unused error;error is gone in for-next.
ok, as long as this warning is acceptable for 6.9 - I assume what you reference is for 6.10