diff mbox series

[33/43] xfs: support xchk_xref_is_used_rt_space on zoned file systems

Message ID 20241211085636.1380516-34-hch@lst.de (mailing list archive)
State New
Headers show
Series [01/43] xfs: constify feature checks | expand

Commit Message

Christoph Hellwig Dec. 11, 2024, 8:54 a.m. UTC
Space usage is tracked by the rmap, which already is separately
cross-reference.  But on top of that we have the write pointer and can
do a basic sanity check here that the block is not beyond the write
pointer.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/xfs/scrub/rtbitmap.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Comments

Darrick J. Wong Dec. 13, 2024, 10:49 p.m. UTC | #1
On Wed, Dec 11, 2024 at 09:54:58AM +0100, Christoph Hellwig wrote:
> Space usage is tracked by the rmap, which already is separately
> cross-reference.  But on top of that we have the write pointer and can

  cross-referenced

> do a basic sanity check here that the block is not beyond the write
> pointer.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  fs/xfs/scrub/rtbitmap.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/xfs/scrub/rtbitmap.c b/fs/xfs/scrub/rtbitmap.c
> index e8c776a34c1d..d5ff8609dbfb 100644
> --- a/fs/xfs/scrub/rtbitmap.c
> +++ b/fs/xfs/scrub/rtbitmap.c
> @@ -21,6 +21,7 @@
>  #include "xfs_rmap.h"
>  #include "xfs_rtrmap_btree.h"
>  #include "xfs_exchmaps.h"
> +#include "xfs_zone_alloc.h"
>  #include "scrub/scrub.h"
>  #include "scrub/common.h"
>  #include "scrub/repair.h"
> @@ -272,7 +273,6 @@ xchk_xref_is_used_rt_space(
>  	xfs_extlen_t		len)
>  {
>  	struct xfs_rtgroup	*rtg = sc->sr.rtg;
> -	struct xfs_inode	*rbmip = rtg_bitmap(rtg);
>  	xfs_rtxnum_t		startext;
>  	xfs_rtxnum_t		endext;
>  	bool			is_free;
> @@ -281,6 +281,13 @@ xchk_xref_is_used_rt_space(
>  	if (xchk_skip_xref(sc->sm))
>  		return;
>  
> +	if (xfs_has_zoned(sc->mp)) {
> +		if (!xfs_zone_rgbno_is_valid(rtg,
> +				xfs_rtb_to_rgbno(sc->mp, rtbno) + len - 1))
> +			xchk_ino_xref_set_corrupt(sc, rtg_rmap(rtg)->i_ino);
> +		return;
> +	}
> +
>  	startext = xfs_rtb_to_rtx(sc->mp, rtbno);
>  	endext = xfs_rtb_to_rtx(sc->mp, rtbno + len - 1);
>  	error = xfs_rtalloc_extent_is_free(rtg, sc->tp, startext,
> @@ -288,5 +295,5 @@ xchk_xref_is_used_rt_space(
>  	if (!xchk_should_check_xref(sc, &error, NULL))
>  		return;
>  	if (is_free)
> -		xchk_ino_xref_set_corrupt(sc, rbmip->i_ino);
> +		xchk_ino_xref_set_corrupt(sc, rtg_bitmap(rtg)->i_ino);

rbmip is already the return value from rtg_bitmap()

--D

>  }
> -- 
> 2.45.2
> 
>
Christoph Hellwig Dec. 15, 2024, 6:13 a.m. UTC | #2
On Fri, Dec 13, 2024 at 02:49:12PM -0800, Darrick J. Wong wrote:
> > @@ -272,7 +273,6 @@ xchk_xref_is_used_rt_space(
> >  	xfs_extlen_t		len)
> >  {
> >  	struct xfs_rtgroup	*rtg = sc->sr.rtg;
> > -	struct xfs_inode	*rbmip = rtg_bitmap(rtg);


> >  	if (is_free)
> > -		xchk_ino_xref_set_corrupt(sc, rbmip->i_ino);
> > +		xchk_ino_xref_set_corrupt(sc, rtg_bitmap(rtg)->i_ino);
> 
> rbmip is already the return value from rtg_bitmap()

Yes, but it gets removed above.  Because it only has a single user,
and it keeps me from incorrectly referencing it in the zone branch,
which I did initially and which didn't end up well :)
Darrick J. Wong Dec. 17, 2024, 5:02 p.m. UTC | #3
On Sun, Dec 15, 2024 at 07:13:49AM +0100, Christoph Hellwig wrote:
> On Fri, Dec 13, 2024 at 02:49:12PM -0800, Darrick J. Wong wrote:
> > > @@ -272,7 +273,6 @@ xchk_xref_is_used_rt_space(
> > >  	xfs_extlen_t		len)
> > >  {
> > >  	struct xfs_rtgroup	*rtg = sc->sr.rtg;
> > > -	struct xfs_inode	*rbmip = rtg_bitmap(rtg);
> 
> 
> > >  	if (is_free)
> > > -		xchk_ino_xref_set_corrupt(sc, rbmip->i_ino);
> > > +		xchk_ino_xref_set_corrupt(sc, rtg_bitmap(rtg)->i_ino);
> > 
> > rbmip is already the return value from rtg_bitmap()
> 
> Yes, but it gets removed above.  Because it only has a single user,
> and it keeps me from incorrectly referencing it in the zone branch,
> which I did initially and which didn't end up well :)

Oh right, my bad.  With the typo in the commit message fixed,
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>

--D
diff mbox series

Patch

diff --git a/fs/xfs/scrub/rtbitmap.c b/fs/xfs/scrub/rtbitmap.c
index e8c776a34c1d..d5ff8609dbfb 100644
--- a/fs/xfs/scrub/rtbitmap.c
+++ b/fs/xfs/scrub/rtbitmap.c
@@ -21,6 +21,7 @@ 
 #include "xfs_rmap.h"
 #include "xfs_rtrmap_btree.h"
 #include "xfs_exchmaps.h"
+#include "xfs_zone_alloc.h"
 #include "scrub/scrub.h"
 #include "scrub/common.h"
 #include "scrub/repair.h"
@@ -272,7 +273,6 @@  xchk_xref_is_used_rt_space(
 	xfs_extlen_t		len)
 {
 	struct xfs_rtgroup	*rtg = sc->sr.rtg;
-	struct xfs_inode	*rbmip = rtg_bitmap(rtg);
 	xfs_rtxnum_t		startext;
 	xfs_rtxnum_t		endext;
 	bool			is_free;
@@ -281,6 +281,13 @@  xchk_xref_is_used_rt_space(
 	if (xchk_skip_xref(sc->sm))
 		return;
 
+	if (xfs_has_zoned(sc->mp)) {
+		if (!xfs_zone_rgbno_is_valid(rtg,
+				xfs_rtb_to_rgbno(sc->mp, rtbno) + len - 1))
+			xchk_ino_xref_set_corrupt(sc, rtg_rmap(rtg)->i_ino);
+		return;
+	}
+
 	startext = xfs_rtb_to_rtx(sc->mp, rtbno);
 	endext = xfs_rtb_to_rtx(sc->mp, rtbno + len - 1);
 	error = xfs_rtalloc_extent_is_free(rtg, sc->tp, startext,
@@ -288,5 +295,5 @@  xchk_xref_is_used_rt_space(
 	if (!xchk_should_check_xref(sc, &error, NULL))
 		return;
 	if (is_free)
-		xchk_ino_xref_set_corrupt(sc, rbmip->i_ino);
+		xchk_ino_xref_set_corrupt(sc, rtg_bitmap(rtg)->i_ino);
 }