public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: Christoph Hellwig <hch@lst.de>
Cc: Andrey Albershteyn <aalbersh@kernel.org>,
	Hans Holmberg <hans.holmberg@wdc.com>,
	linux-xfs@vger.kernel.org
Subject: Re: [PATCH 29/43] xfs_repair: validate rt groups vs reported hardware zones
Date: Mon, 14 Apr 2025 17:39:33 -0700	[thread overview]
Message-ID: <20250415003933.GL25675@frogsfrogsfrogs> (raw)
In-Reply-To: <20250414053629.360672-30-hch@lst.de>

On Mon, Apr 14, 2025 at 07:36:12AM +0200, Christoph Hellwig wrote:
> Run a report zones ioctl, and verify the rt group state vs the
> reported hardware zone state.  Note that there is no way to actually
> fix up any discrepancies here, as that would be rather scary without
> having transactions.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  repair/Makefile |   1 +
>  repair/phase5.c |  11 +---
>  repair/zoned.c  | 139 ++++++++++++++++++++++++++++++++++++++++++++++++
>  repair/zoned.h  |  10 ++++
>  4 files changed, 152 insertions(+), 9 deletions(-)
>  create mode 100644 repair/zoned.c
>  create mode 100644 repair/zoned.h
> 
> diff --git a/repair/Makefile b/repair/Makefile
> index ff5b1f5abeda..fb0b2f96cc91 100644
> --- a/repair/Makefile
> +++ b/repair/Makefile
> @@ -81,6 +81,7 @@ CFILES = \
>  	strblobs.c \
>  	threads.c \
>  	versions.c \
> +	zoned.c \
>  	xfs_repair.c
>  
>  LLDLIBS = $(LIBXFS) $(LIBXLOG) $(LIBXCMD) $(LIBFROG) $(LIBUUID) $(LIBRT) \
> diff --git a/repair/phase5.c b/repair/phase5.c
> index e350b411c243..e44c26885717 100644
> --- a/repair/phase5.c
> +++ b/repair/phase5.c
> @@ -21,6 +21,7 @@
>  #include "rmap.h"
>  #include "bulkload.h"
>  #include "agbtree.h"
> +#include "zoned.h"
>  
>  static uint64_t	*sb_icount_ag;		/* allocated inodes per ag */
>  static uint64_t	*sb_ifree_ag;		/* free inodes per ag */
> @@ -631,15 +632,7 @@ check_rtmetadata(
>  	struct xfs_mount	*mp)
>  {
>  	if (xfs_has_zoned(mp)) {
> -		/*
> -		 * Here we could/should verify the zone state a bit when we are
> -		 * on actual zoned devices:
> -		 *	- compare hw write pointer to last written
> -		 *	- compare zone state to last written
> -		 *
> -		 * Note much we can do when running in zoned mode on a
> -		 * conventional device.
> -		 */
> +		check_zones(mp);
>  		return;
>  	}
>  
> diff --git a/repair/zoned.c b/repair/zoned.c
> new file mode 100644
> index 000000000000..456076b9817d
> --- /dev/null
> +++ b/repair/zoned.c
> @@ -0,0 +1,139 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (c) 2024 Christoph Hellwig.
> + */
> +#include <ctype.h>
> +#include <linux/blkzoned.h>
> +#include "libxfs_priv.h"
> +#include "libxfs.h"
> +#include "xfs_zones.h"
> +#include "err_protos.h"
> +#include "zoned.h"
> +
> +/* random size that allows efficient processing */
> +#define ZONES_PER_IOCTL			16384
> +
> +static void
> +report_zones_cb(
> +	struct xfs_mount	*mp,
> +	struct blk_zone		*zone)
> +{
> +	xfs_rtblock_t		zsbno = xfs_daddr_to_rtb(mp, zone->start);
> +	xfs_rgblock_t		write_pointer;
> +	xfs_rgnumber_t		rgno;
> +	struct xfs_rtgroup	*rtg;
> +
> +	if (xfs_rtb_to_rgbno(mp, zsbno) != 0) {
> +		do_error(_("mismatched zone start 0x%llx."),
> +				(unsigned long long)zsbno);
> +		return;
> +	}
> +
> +	rgno = xfs_rtb_to_rgno(mp, zsbno);
> +	rtg = xfs_rtgroup_grab(mp, rgno);
> +	if (!rtg) {
> +		do_error(_("realtime group not found for zone %u."), rgno);
> +		return;
> +	}
> +
> +	if (!rtg_rmap(rtg))
> +		do_warn(_("no rmap inode for zone %u."), rgno);
> +	else
> +		xfs_zone_validate(zone, rtg, &write_pointer);
> +	xfs_rtgroup_rele(rtg);
> +}
> +
> +void
> +check_zones(
> +	struct xfs_mount	*mp)
> +{
> +	int			fd = mp->m_rtdev_targp->bt_bdev_fd;
> +	uint64_t		sector = XFS_FSB_TO_BB(mp, mp->m_sb.sb_rtstart);
> +	unsigned int		zone_size, zone_capacity;
> +	uint64_t		device_size;
> +	size_t			rep_size;
> +	struct blk_zone_report	*rep;
> +	unsigned int		i, n = 0;
> +
> +	if (ioctl(fd, BLKGETSIZE64, &device_size))
> +		return; /* not a block device */
> +	if (ioctl(fd, BLKGETZONESZ, &zone_size) || !zone_size)
> +		return;	/* not zoned */
> +
> +	/* BLKGETSIZE64 reports a byte value */
> +	device_size = BTOBB(device_size);

Much better now, thanks for cleaning up the type conversions
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>

--D

> +	if (device_size / zone_size < mp->m_sb.sb_rgcount) {
> +		do_error(_("rt device too small\n"));
> +		return;
> +	}
> +
> +	rep_size = sizeof(struct blk_zone_report) +
> +		   sizeof(struct blk_zone) * ZONES_PER_IOCTL;
> +	rep = malloc(rep_size);
> +	if (!rep) {
> +		do_warn(_("malloc failed for zone report\n"));
> +		return;
> +	}
> +
> +	while (n < mp->m_sb.sb_rgcount) {
> +		struct blk_zone *zones = (struct blk_zone *)(rep + 1);
> +		int ret;
> +
> +		memset(rep, 0, rep_size);
> +		rep->sector = sector;
> +		rep->nr_zones = ZONES_PER_IOCTL;
> +
> +		ret = ioctl(fd, BLKREPORTZONE, rep);
> +		if (ret) {
> +			do_error(_("ioctl(BLKREPORTZONE) failed: %d!\n"), ret);
> +			goto out_free;
> +		}
> +		if (!rep->nr_zones)
> +			break;
> +
> +		for (i = 0; i < rep->nr_zones; i++) {
> +			if (n >= mp->m_sb.sb_rgcount)
> +				break;
> +
> +			if (zones[i].len != zone_size) {
> +				do_error(_("Inconsistent zone size!\n"));
> +				goto out_free;
> +			}
> +
> +			switch (zones[i].type) {
> +			case BLK_ZONE_TYPE_CONVENTIONAL:
> +			case BLK_ZONE_TYPE_SEQWRITE_REQ:
> +				break;
> +			case BLK_ZONE_TYPE_SEQWRITE_PREF:
> +				do_error(
> +_("Found sequential write preferred zone\n"));
> +				goto out_free;
> +			default:
> +				do_error(
> +_("Found unknown zone type (0x%x)\n"), zones[i].type);
> +				goto out_free;
> +			}
> +
> +			if (!n) {
> +				zone_capacity = zones[i].capacity;
> +				if (zone_capacity > zone_size) {
> +					do_error(
> +_("Zone capacity larger than zone size!\n"));
> +					goto out_free;
> +				}
> +			} else if (zones[i].capacity != zone_capacity) {
> +				do_error(
> +_("Inconsistent zone capacity!\n"));
> +				goto out_free;
> +			}
> +
> +			report_zones_cb(mp, &zones[i]);
> +			n++;
> +		}
> +		sector = zones[rep->nr_zones - 1].start +
> +			 zones[rep->nr_zones - 1].len;
> +	}
> +
> +out_free:
> +	free(rep);
> +}
> diff --git a/repair/zoned.h b/repair/zoned.h
> new file mode 100644
> index 000000000000..ab76bf15b3ca
> --- /dev/null
> +++ b/repair/zoned.h
> @@ -0,0 +1,10 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Copyright (c) 2024 Christoph Hellwig.
> + */
> +#ifndef _XFS_REPAIR_ZONED_H_
> +#define _XFS_REPAIR_ZONED_H_
> +
> +void check_zones(struct xfs_mount *mp);
> +
> +#endif /* _XFS_REPAIR_ZONED_H_ */
> -- 
> 2.47.2
> 
> 

  reply	other threads:[~2025-04-15  0:39 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-14  5:35 xfsprogs support for zoned devices v2 Christoph Hellwig
2025-04-14  5:35 ` [PATCH 01/43] xfs: generalize the freespace and reserved blocks handling Christoph Hellwig
2025-04-14  5:35 ` [PATCH 02/43] FIXUP: " Christoph Hellwig
2025-04-14  5:35 ` [PATCH 03/43] xfs: make metabtree reservations global Christoph Hellwig
2025-04-14  5:35 ` [PATCH 04/43] FIXUP: " Christoph Hellwig
2025-04-14  5:35 ` [PATCH 05/43] xfs: reduce metafile reservations Christoph Hellwig
2025-04-14  5:35 ` [PATCH 06/43] xfs: add a rtg_blocks helper Christoph Hellwig
2025-04-14  5:35 ` [PATCH 07/43] xfs: move xfs_bmapi_reserve_delalloc to xfs_iomap.c Christoph Hellwig
2025-04-14  5:35 ` [PATCH 08/43] xfs: support XFS_BMAPI_REMAP in xfs_bmap_del_extent_delay Christoph Hellwig
2025-04-14  5:35 ` [PATCH 09/43] xfs: add a xfs_rtrmap_highest_rgbno helper Christoph Hellwig
2025-04-14  5:35 ` [PATCH 10/43] xfs: define the zoned on-disk format Christoph Hellwig
2025-04-14  5:35 ` [PATCH 11/43] FIXUP: " Christoph Hellwig
2025-04-14  5:35 ` [PATCH 12/43] xfs: allow internal RT devices for zoned mode Christoph Hellwig
2025-04-14  5:35 ` [PATCH 13/43] FIXUP: " Christoph Hellwig
2025-04-14 20:16   ` Darrick J. Wong
2025-04-14  5:35 ` [PATCH 14/43] xfs: export zoned geometry via XFS_FSOP_GEOM Christoph Hellwig
2025-04-14  5:35 ` [PATCH 15/43] xfs: disable sb_frextents for zoned file systems Christoph Hellwig
2025-04-14  5:35 ` [PATCH 16/43] xfs: parse and validate hardware zone information Christoph Hellwig
2025-04-14  5:36 ` [PATCH 17/43] FIXUP: " Christoph Hellwig
2025-04-14  5:36 ` [PATCH 18/43] xfs: add the zoned space allocator Christoph Hellwig
2025-04-14  5:36 ` [PATCH 19/43] xfs: add support for zoned space reservations Christoph Hellwig
2025-04-14  5:36 ` [PATCH 20/43] FIXUP: " Christoph Hellwig
2025-04-14  5:36 ` [PATCH 21/43] xfs: implement zoned garbage collection Christoph Hellwig
2025-04-14  5:36 ` [PATCH 22/43] xfs: enable fsmap reporting for internal RT devices Christoph Hellwig
2025-04-14  5:36 ` [PATCH 23/43] xfs: enable the zoned RT device feature Christoph Hellwig
2025-04-14  5:36 ` [PATCH 24/43] xfs: support zone gaps Christoph Hellwig
2025-04-14  5:36 ` [PATCH 25/43] FIXUP: " Christoph Hellwig
2025-04-14  5:36 ` [PATCH 26/43] libfrog: report the zoned geometry Christoph Hellwig
2025-04-14 22:16   ` Darrick J. Wong
2025-04-14  5:36 ` [PATCH 27/43] xfs_repair: support repairing zoned file systems Christoph Hellwig
2025-04-15  0:38   ` Darrick J. Wong
2025-04-14  5:36 ` [PATCH 28/43] xfs_repair: fix the RT device check in process_dinode_int Christoph Hellwig
2025-04-15  0:34   ` Darrick J. Wong
2025-04-14  5:36 ` [PATCH 29/43] xfs_repair: validate rt groups vs reported hardware zones Christoph Hellwig
2025-04-15  0:39   ` Darrick J. Wong [this message]
2025-04-14  5:36 ` [PATCH 30/43] xfs_mkfs: factor out a validate_rtgroup_geometry helper Christoph Hellwig
2025-04-15  0:40   ` Darrick J. Wong
2025-04-14  5:36 ` [PATCH 31/43] xfs_mkfs: support creating file system with zoned RT devices Christoph Hellwig
2025-04-15  0:41   ` Darrick J. Wong
2025-04-14  5:36 ` [PATCH 32/43] xfs_mkfs: calculate zone overprovisioning when specifying size Christoph Hellwig
2025-04-14  5:36 ` [PATCH 33/43] xfs_mkfs: default to rtinherit=1 for zoned file systems Christoph Hellwig
2025-04-15  0:37   ` Darrick J. Wong
2025-04-15  8:09     ` Christoph Hellwig
2025-04-14  5:36 ` [PATCH 34/43] xfs_mkfs: reflink conflicts with zoned file systems for now Christoph Hellwig
2025-04-14  5:36 ` [PATCH 35/43] xfs_mkfs: document the new zoned options in the man page Christoph Hellwig
2025-04-14  5:36 ` [PATCH 36/43] man: document XFS_FSOP_GEOM_FLAGS_ZONED Christoph Hellwig
2025-04-15  0:36   ` Darrick J. Wong
2025-04-14  5:36 ` [PATCH 37/43] xfs_io: correctly report RGs with internal rt dev in bmap output Christoph Hellwig
2025-04-14  5:36 ` [PATCH 38/43] xfs_io: don't re-query fs_path information in fsmap_f Christoph Hellwig
2025-04-14  5:36 ` [PATCH 39/43] xfs_io: handle internal RT devices in fsmap output Christoph Hellwig
2025-04-14  5:36 ` [PATCH 40/43] xfs_spaceman: handle internal RT devices Christoph Hellwig
2025-04-14  5:36 ` [PATCH 41/43] xfs_scrub: support internal RT device Christoph Hellwig
2025-04-15  0:35   ` Darrick J. Wong
2025-04-14  5:36 ` [PATCH 42/43] xfs_mdrestore: support internal RT devices Christoph Hellwig
2025-04-14  5:36 ` [PATCH 43/43] xfs_growfs: " Christoph Hellwig
2025-04-25 15:48 ` [PATCH 44/43] xfs_repair: fix libxfs abstraction mess Darrick J. Wong
2025-04-28 13:17   ` Christoph Hellwig
2025-04-28 16:28     ` Andrey Albershteyn
2025-04-29 12:24       ` Christoph Hellwig
2025-04-28 16:31   ` Andrey Albershteyn

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=20250415003933.GL25675@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=aalbersh@kernel.org \
    --cc=hans.holmberg@wdc.com \
    --cc=hch@lst.de \
    --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