public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: Christoph Hellwig <hch@infradead.org>
Cc: cem@kernel.org, stable@vger.kernel.org,
	linux-xfs@vger.kernel.org, hch@lst.de
Subject: Re: [PATCH 4/6] xfs: fix zero byte checking in the superblock scrubber
Date: Wed, 4 Dec 2024 21:54:51 -0800	[thread overview]
Message-ID: <20241205055451.GB7837@frogsfrogsfrogs> (raw)
In-Reply-To: <Z1ASehwdTewFiwZE@infradead.org>

On Wed, Dec 04, 2024 at 12:27:38AM -0800, Christoph Hellwig wrote:
> On Tue, Dec 03, 2024 at 07:03:16PM -0800, Darrick J. Wong wrote:
> > +/* Calculate the ondisk superblock size in bytes */
> > +STATIC size_t
> > +xchk_superblock_ondisk_size(
> > +	struct xfs_mount	*mp)
> > +{
> > +	if (xfs_has_metadir(mp))
> > +		return offsetofend(struct xfs_dsb, sb_pad);
> > +	if (xfs_has_metauuid(mp))
> > +		return offsetofend(struct xfs_dsb, sb_meta_uuid);
> > +	if (xfs_has_crc(mp))
> > +		return offsetofend(struct xfs_dsb, sb_lsn);
> > +	if (xfs_sb_version_hasmorebits(&mp->m_sb))
> > +		return offsetofend(struct xfs_dsb, sb_bad_features2);
> > +	if (xfs_has_logv2(mp))
> > +		return offsetofend(struct xfs_dsb, sb_logsunit);
> > +	if (xfs_has_sector(mp))
> > +		return offsetofend(struct xfs_dsb, sb_logsectsize);
> > +	/* only support dirv2 or more recent */
> > +	return offsetofend(struct xfs_dsb, sb_dirblklog);
> 
> This really should be libxfs so tht it can be shared with
> secondary_sb_whack in xfsrepair.  The comment at the end of
> the xfs_dsb definition should also be changed to point to this
> libxfs version.

The xfs_repair version of this is subtlely different -- given a
secondary ondisk superblock, it figures out the size of the ondisk
superblock given the features set *in that alleged superblock*.  From
there it validates the secondary superblock.  The featureset in the
alleged superblock doesn't even have to match the primary super, but
it'll go zero things all the same before copying the incore super back
to disk:

	if (xfs_sb_version_hasmetadir(sb))
		size = offsetofend(struct xfs_dsb, sb_pad);
	else if (xfs_sb_version_hasmetauuid(sb))
		size = offsetofend(struct xfs_dsb, sb_meta_uuid);

This version in online computes the size of the secondary ondisk
superblock object given the features set in the *primary* superblock
that we used to mount the filesystem.

Also if I did that we'd have to recopy the xfs_sb_version_hasXXXX
functions back into libxfs after ripping most of them out.  Or we'd have
to encode the logic manually.  But even then, the xfs_repair and
xfs_scrub functions are /not quite/ switching on the same thing.

> > +}
> >  	/* Everything else must be zero. */
> > -	if (memchr_inv(sb + 1, 0,
> > -			BBTOB(bp->b_length) - sizeof(struct xfs_dsb)))
> > +	sblen = xchk_superblock_ondisk_size(mp);
> > +	if (memchr_inv((char *)sb + sblen, 0, BBTOB(bp->b_length) - sblen))
> 
> This could be simplified to
> 
> 	if (memchr_inv(bp->b_addr + sblen, 0, BBTOB(bp->b_length) - sblen))

<nod>

> Otherwise looks good:
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>

Thanks!

--D

  reply	other threads:[~2024-12-05  5:54 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-04  3:02 [PATCHSET v2] xfs: proposed bug fixes for 6.13 Darrick J. Wong
2024-12-04  3:02 ` [PATCH 1/6] xfs: don't move nondir/nonreg temporary repair files to the metadir namespace Darrick J. Wong
2024-12-04  8:24   ` Christoph Hellwig
2024-12-05  6:14     ` Darrick J. Wong
2024-12-05  6:46       ` Christoph Hellwig
2024-12-05  7:16         ` Darrick J. Wong
2024-12-04  3:02 ` [PATCH 2/6] xfs: don't crash on corrupt /quotas dirent Darrick J. Wong
2024-12-04  8:24   ` Christoph Hellwig
2024-12-04  3:03 ` [PATCH 3/6] xfs: check pre-metadir fields correctly Darrick J. Wong
2024-12-04  8:25   ` Christoph Hellwig
2024-12-04  3:03 ` [PATCH 4/6] xfs: fix zero byte checking in the superblock scrubber Darrick J. Wong
2024-12-04  8:27   ` Christoph Hellwig
2024-12-05  5:54     ` Darrick J. Wong [this message]
2024-12-05  6:48       ` Christoph Hellwig
2024-12-05  7:17         ` Darrick J. Wong
2024-12-04  3:03 ` [PATCH 5/6] xfs: return from xfs_symlink_verify early on V4 filesystems Darrick J. Wong
2024-12-04  8:27   ` Christoph Hellwig
2024-12-04  3:03 ` [PATCH 6/6] xfs: port xfs_ioc_start_commit to multigrain timestamps Darrick J. Wong
2024-12-04  4:01   ` Jeff Layton
2024-12-04  8:28   ` Christoph Hellwig
2024-12-05  1:26 ` [PATCHSET v2] xfs: proposed bug fixes for 6.13 Bill O'Donnell
2024-12-05  6:42   ` Darrick J. Wong
2024-12-05  6:52     ` Bill O'Donnell
2024-12-05  6:58       ` Christoph Hellwig
2024-12-05  7:04         ` Bill O'Donnell
2024-12-05  7:30           ` Bill O'Donnell
2024-12-05  7:39             ` Darrick J. Wong
2024-12-05  7:33           ` Darrick J. Wong
2024-12-05  7:40             ` Bill O'Donnell
2024-12-05  7:46             ` Bill O'Donnell
2024-12-05  8:02               ` Bill O'Donnell
2024-12-05  8:39                 ` Greg KH
2024-12-05  8:47                   ` Bill O'Donnell
2024-12-05  7:57         ` Darrick J. Wong
2024-12-05 16:11     ` Bill O'Donnell
  -- strict thread matches above, loose matches on Subject: below --
2024-12-07  0:30 [PATCHSET v3] " Darrick J. Wong
2024-12-07  0:31 ` [PATCH 4/6] xfs: fix zero byte checking in the superblock scrubber Darrick J. Wong
2024-12-11 20:07 [PATCHSET v4] xfs: bug fixes for 6.13 Darrick J. Wong
2024-12-11 20:08 ` [PATCH 4/6] xfs: fix zero byte checking in the superblock scrubber Darrick J. Wong

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=20241205055451.GB7837@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=cem@kernel.org \
    --cc=hch@infradead.org \
    --cc=hch@lst.de \
    --cc=linux-xfs@vger.kernel.org \
    --cc=stable@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