linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: Christoph Hellwig <hch@lst.de>
Cc: Carlos Maiolino <cem@kernel.org>, Jens Axboe <axboe@kernel.dk>,
	Christian Brauner <brauner@kernel.org>,
	linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH 17/21] xfs: verify data checksums during media verification
Date: Mon, 28 Sep 2026 18:19:36 -0700	[thread overview]
Message-ID: <20260929011936.GY2705364@frogsfrogsfrogs> (raw)
In-Reply-To: <20260924100032.2733101-18-hch@lst.de>

On Thu, Sep 24, 2026 at 11:59:49AM +0200, Christoph Hellwig wrote:
> Wire up reading and verifying data checksums during media verification.
> This is very similar to the file read path in that it kicks of an async
> read for the checksum buffer before reading the data, and then validating
> once both are read in.
> 
> To support this, split the per-read logic in xfs_verify_media into a
> separate helpers for the data checksums vs no checksum cases.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  fs/xfs/xfs_verify_media.c | 131 +++++++++++++++++++++++++++++++-------
>  1 file changed, 107 insertions(+), 24 deletions(-)
> 
> diff --git a/fs/xfs/xfs_verify_media.c b/fs/xfs/xfs_verify_media.c
> index 71f4d6c832a9..46a19405c9e5 100644
> --- a/fs/xfs/xfs_verify_media.c
> +++ b/fs/xfs/xfs_verify_media.c
> @@ -22,6 +22,7 @@
>  #include "xfs_rtrmap_btree.h"
>  #include "xfs_health.h"
>  #include "xfs_healthmon.h"
> +#include "xfs_rtcsum.h"
>  #include "xfs_trace.h"
>  #include "xfs_verify_media.h"
>  
> @@ -261,6 +262,95 @@ xfs_verify_media_error(
>  	}
>  }
>  
> +static int
> +xfs_submit_verify_bio(
> +	struct xfs_mount	*mp,
> +	struct xfs_verify_media	*me,
> +	struct xfs_buftarg	*btp,
> +	struct folio		*folio,
> +	xfs_daddr_t		*daddr,
> +	uint64_t		*bbcount)
> +{
> +	unsigned int		bio_bbcount;
> +	int			error;
> +
> +	bio_bbcount = min(*bbcount, folio_size(folio) >> SECTOR_SHIFT);
> +	error = bdev_rw_virt(btp->bt_bdev, *daddr, folio_address(folio),
> +			bio_bbcount << SECTOR_SHIFT,
> +			REQ_OP_READ);
> +	if (error) {
> +		xfs_verify_media_error(mp, me, btp, *daddr, bio_bbcount, error);
> +		return 1;
> +	}
> +
> +	*daddr += bio_bbcount;
> +	*bbcount -= bio_bbcount;
> +	return 0;
> +}
> +
> +static int
> +xfs_submit_verify_bio_csum(

What's the return value convention here?  1 for media error, 0 for
success, or negative errno if we failed to issue the read?

> +	struct xfs_mount	*mp,
> +	struct xfs_verify_media	*me,
> +	struct xfs_buftarg	*btp,
> +	struct folio		*folio,
> +	xfs_daddr_t		*daddr,
> +	uint64_t		*bbcount)
> +{
> +	struct xfs_buf		*csum_bp = NULL;
> +	unsigned int		bio_bbcount;
> +	struct bvec_iter	saved_iter;
> +	xfs_fsblock_t		bno, end;
> +	xfs_filblks_t		len;
> +	struct bio		bio;
> +	struct bio_vec		bv;
> +	int			error;
> +
> +	bno = xfs_daddr_to_rtb(mp, *daddr);
> +	end = xfs_daddr_to_rtb(mp, *daddr + *bbcount);

It occurs to me that xfs_daddr_to_rtb rounds its argument down.  So if
you pass in daddr==0 and bbcount==2, you'll get bno==end==0 and do no
verification.  I would hope that callers won't pass in parameters like
that, but who knows?

So I think this should be:

	end = xfs_daddr_to_rtb(mp,
			*daddr + *bbcount + XFS_FSB_TO_BB(mp, 1) - 1);

Which I admit is a bit gross.

--D

> +	len = min(end - bno, XFS_B_TO_FSBT(mp, folio_size(folio)));
> +	len = min(len, xfs_rtcsum_max_len(mp, bno));
> +
> +	error = xfs_rtcsum_read_async(mp, bno, &csum_bp);
> +	if (error)
> +		return error;
> +
> +	*daddr = xfs_rtb_to_daddr(mp, bno);
> +	bio_bbcount = XFS_FSB_TO_BB(mp, len);
> +
> +	bio_init(&bio, btp->bt_bdev, &bv, 1, REQ_OP_READ);
> +	bio.bi_iter.bi_sector = *daddr;
> +	bio_add_folio_nofail(&bio, folio,
> +			min(bio_bbcount << SECTOR_SHIFT, folio_size(folio)), 0);
> +	saved_iter = bio.bi_iter;
> +
> +	error = submit_bio_wait(&bio);
> +	if (error)
> +		goto out_media_error;
> +
> +	error = xfs_buf_read_async_wait(csum_bp);
> +	if (error)
> +		goto out_buf_rele;
> +
> +	error = xfs_csum_verify(mp, &bio, &saved_iter,
> +			csum_bp->b_addr + xfs_rtb_to_rtcsumoff(mp, bno), bno,
> +			false);
> +	if (error)
> +		goto out_media_error;
> +
> +	*daddr += bio_bbcount;
> +	*bbcount -= bio_bbcount;
> +
> +out_buf_rele:
> +	xfs_buf_rele(csum_bp);
> +	bio_uninit(&bio);
> +	return error;
> +out_media_error:
> +	xfs_verify_media_error(mp, me, btp, *daddr, bio_bbcount, error);
> +	error = 1;
> +	goto out_buf_rele;
> +}
> +
>  /* Verify the media of an xfs device by submitting read requests to the disk. */
>  static int
>  xfs_verify_media(
> @@ -310,18 +400,13 @@ xfs_verify_media(
>  		return 0;
>  
>  	/*
> -	 * There are three ranges involved here:
> -	 *
> -	 *  - [me->me_start_daddr, me->me_end_daddr) is the range that the
> -	 *    user wants to verify.  end_daddr can be beyond the end of the
> -	 *    disk; we'll constrain it to the end if necessary.
> +	 * [me->me_start_daddr, me->me_end_daddr) is the range that the user
> +	 * wants to verify.  end_daddr can be beyond the end of the disk; we'll
> +	 * constrain it to the end if necessary.
>  	 *
> -	 *  - [daddr, me->me_end_daddr) is the range that we have not yet
> -	 *    verified.  We update daddr after each successful read.
> -	 *    me->me_start_daddr is set to daddr before returning.
> -	 *
> -	 *  - [daddr, daddr + bio_bbcount) is the range that we're currently
> -	 *    verifying.
> +	 * [daddr, me->me_end_daddr) is the range that we have not yet verified.
> +	 * We update daddr after each successful read.  me->me_start_daddr is
> +	 * set to daddr before returning.
>  	 */
>  	daddr = me->me_start_daddr;
>  	bbcount = min_t(sector_t, me->me_end_daddr, btp->bt_nr_sectors) -
> @@ -334,22 +419,20 @@ xfs_verify_media(
>  	trace_xfs_verify_media(mp, me, btp->bt_dev, daddr, bbcount, folio);
>  
>  	for (;;) {
> -		unsigned int	bio_bbcount;
> -
> -		bio_bbcount = min(bbcount, folio_size(folio) >> SECTOR_SHIFT);
> -		error = bdev_rw_virt(btp->bt_bdev, daddr, folio_address(folio),
> -				bio_bbcount << SECTOR_SHIFT,
> -				REQ_OP_READ);
> +		if (IS_ENABLED(CONFIG_XFS_RT) &&
> +		    me->me_dev == XFS_DEV_RT &&
> +		    xfs_has_rtcsum(mp)) {
> +			error = xfs_submit_verify_bio_csum(mp, me, btp, folio,
> +					&daddr, &bbcount);
> +		} else {
> +			error = xfs_submit_verify_bio(mp, me, btp, folio,
> +					&daddr, &bbcount);
> +		}
>  		if (error) {
> -			xfs_verify_media_error(mp, me, btp, daddr, bio_bbcount,
> -					error);
> -			error = 0;
> +			if (error == 1)
> +				error = 0;
>  			break;
>  		}
> -
> -		daddr += bio_bbcount;
> -		bbcount -= bio_bbcount;
> -
>  		if (bbcount == 0)
>  			break;
>  
> -- 
> 2.53.0
> 
> 

  reply	other threads:[~2026-09-29  1:19 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-24  9:59 support for RT data checksums Christoph Hellwig
2026-09-24  9:59 ` [PATCH 01/21] block: export fs_bio_integrity_verify Christoph Hellwig
2026-09-24 20:29   ` Darrick J. Wong
2026-09-24  9:59 ` [PATCH 02/21] iomap: add support for data checksumming Christoph Hellwig
2026-09-24 21:39   ` Darrick J. Wong
2026-09-25  5:53     ` Christoph Hellwig
2026-09-24  9:59 ` [PATCH 03/21] xfs: add a xfs_buf_read_async buffer cache API Christoph Hellwig
2026-09-24 21:43   ` Darrick J. Wong
2026-09-25  5:54     ` Christoph Hellwig
2026-09-24  9:59 ` [PATCH 04/21] xfs: add xfs_daddr_to_rgno and xfs_daddr_to_rgbno helpers Christoph Hellwig
2026-09-24 21:44   ` Darrick J. Wong
2026-09-24  9:59 ` [PATCH 05/21] xfs: introduce XFS_BLI_PREALLOC Christoph Hellwig
2026-09-24 21:49   ` Darrick J. Wong
2026-09-25  5:57     ` Christoph Hellwig
2026-10-08 11:46   ` Anuj gupta
2026-09-24  9:59 ` [PATCH 06/21] xfs: prepare xfs_rtfile_initialize_blocks for larger than FSB blocks Christoph Hellwig
2026-09-24 22:03   ` Darrick J. Wong
2026-09-25  5:58     ` Christoph Hellwig
2026-09-24  9:59 ` [PATCH 07/21] xfs: relase zi_open_zones_lock over xfs_open_zone_put on unmount Christoph Hellwig
2026-09-24  9:59 ` [PATCH 08/21] xfs: define the RT data checksum on-disk format Christoph Hellwig
2026-09-24 22:13   ` Darrick J. Wong
2026-09-25  0:04     ` Eric Biggers
2026-09-25  6:01     ` Christoph Hellwig
2026-09-24  9:59 ` [PATCH 09/21] xfs: add support for per-RTG csum files Christoph Hellwig
2026-09-24 22:24   ` Darrick J. Wong
2026-09-25  6:10     ` Christoph Hellwig
2026-09-24  9:59 ` [PATCH 10/21] xfs: calculate the log reservation for logging data checksum buffers Christoph Hellwig
2026-09-24 22:30   ` Darrick J. Wong
2026-09-25  6:12     ` Christoph Hellwig
2026-09-24  9:59 ` [PATCH 11/21] xfs: core RT data checksum support Christoph Hellwig
2026-09-25 23:20   ` Darrick J. Wong
2026-09-26  6:13     ` Christoph Hellwig
2026-09-24  9:59 ` [PATCH 12/21] xfs: data checksums require stable writes Christoph Hellwig
2026-09-25 23:21   ` Darrick J. Wong
2026-09-24  9:59 ` [PATCH 13/21] xfs: require file system block size alignment when using data checksums Christoph Hellwig
2026-09-25 23:24   ` Darrick J. Wong
2026-09-26  6:15     ` Christoph Hellwig
2026-09-24  9:59 ` [PATCH 14/21] xfs: add support for reading with " Christoph Hellwig
2026-09-29  0:42   ` Darrick J. Wong
2026-10-05 12:59     ` Christoph Hellwig
2026-09-24  9:59 ` [PATCH 15/21] xfs: add support for writing " Christoph Hellwig
2026-09-29  1:01   ` Darrick J. Wong
2026-10-05 13:00     ` Christoph Hellwig
2026-09-24  9:59 ` [PATCH 16/21] xfs: add data checksum support to zoned garbage collection Christoph Hellwig
2026-09-29  1:06   ` Darrick J. Wong
2026-10-05 13:11     ` Christoph Hellwig
2026-09-24  9:59 ` [PATCH 17/21] xfs: verify data checksums during media verification Christoph Hellwig
2026-09-29  1:19   ` Darrick J. Wong [this message]
2026-10-05 13:13     ` Christoph Hellwig
2026-09-24  9:59 ` [PATCH 18/21] xfs: don't try to verify checksums on empty zones Christoph Hellwig
2026-09-29  1:25   ` Darrick J. Wong
2026-10-05 13:14     ` Christoph Hellwig
2026-10-08 11:43   ` Anuj gupta
2026-09-24  9:59 ` [PATCH 19/21] xfs: report RT data checksum information via XFS_FSOP_GEOM Christoph Hellwig
2026-09-29  1:26   ` Darrick J. Wong
2026-09-24  9:59 ` [PATCH 20/21] xfs: add an experimental feature warning for RT data checksums Christoph Hellwig
2026-09-29  1:27   ` Darrick J. Wong
2026-09-24  9:59 ` [PATCH 21/21] xfs: enable " Christoph Hellwig
2026-09-29  1:27   ` Darrick J. Wong
2026-10-05 13:16     ` Christoph Hellwig
2026-09-24 22:52 ` support for " Dave Chinner
2026-09-25  6:27   ` Christoph Hellwig
2026-09-27 22:59     ` Dave Chinner
2026-09-28  5:24       ` Christoph Hellwig
2026-09-29 14:11         ` Dave Chinner
2026-09-30  7:11           ` Dave Chinner
2026-10-05 13:53             ` Christoph Hellwig
2026-10-06  5:31               ` Dave Chinner
2026-10-07 13:46                 ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260929011936.GY2705364@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=brauner@kernel.org \
    --cc=cem@kernel.org \
    --cc=hch@lst.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).