All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: "Darrick J. Wong" <darrick.wong@oracle.com>
Cc: Christoph Hellwig <hch@lst.de>, linux-xfs@vger.kernel.org
Subject: Re: [PATCH] xfs: clean up xchk_bmap_check_rmaps usage of XFS_IFORK_Q
Date: Sun, 17 May 2020 10:05:14 +0200	[thread overview]
Message-ID: <20200517080514.GC30453@lst.de> (raw)
In-Reply-To: <20200516200106.GA23621@lst.de>

On Sat, May 16, 2020 at 10:01:06PM +0200, Christoph Hellwig wrote:
> >  	for (agno = 0; agno < sc->mp->m_sb.sb_agcount; agno++) {
> > @@ -651,8 +647,9 @@ xchk_bmap(
> >  		}
> >  		break;
> >  	case XFS_ATTR_FORK:
> > +		/* No fork means no attr data at all. */
> >  		if (!ifp)
> > -			goto out_check_rmap;
> > +			goto out;
> 
> Maybe lift the !ifp to before the switch statement, or even to just after
> assigning the value to ifp?  For the data fork it obviously won't be
> true, but it still looks simple than duplicating it for the attr and
> cow fork.
> 
> Otherwise looks fine:
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>

This is what I ended up with for my tree:

---
From a98ef6f4bbfe186a83d3384cbd0a0727c0e1ddee Mon Sep 17 00:00:00 2001
From: "Darrick J. Wong" <darrick.wong@oracle.com>
Date: Sat, 16 May 2020 11:42:59 -0700
Subject: xfs: clean up xchk_bmap_check_rmaps usage of XFS_IFORK_Q

XFS_IFORK_Q is supposed to be a predicate, not a function returning a
value.  Its usage is in xchk_bmap_check_rmaps is incorrect, but that
function only cares about whether or not the "size" of the data is zero
or not.  Convert that logic to use a proper boolean, and teach the
caller to skip the call entirely if the end result would be that we'd do
nothing anyway.  This avoids a crash later in this series.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
[hch: generalized the NULL ifor check]
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/xfs/scrub/bmap.c | 34 +++++++++++++---------------------
 1 file changed, 13 insertions(+), 21 deletions(-)

diff --git a/fs/xfs/scrub/bmap.c b/fs/xfs/scrub/bmap.c
index add8598eacd5d..93d5b8a9d7f74 100644
--- a/fs/xfs/scrub/bmap.c
+++ b/fs/xfs/scrub/bmap.c
@@ -566,8 +566,8 @@ xchk_bmap_check_rmaps(
 	struct xfs_scrub	*sc,
 	int			whichfork)
 {
-	loff_t			size;
 	xfs_agnumber_t		agno;
+	bool			zero_size;
 	int			error;
 
 	if (!xfs_sb_version_hasrmapbt(&sc->mp->m_sb) ||
@@ -579,6 +579,8 @@ xchk_bmap_check_rmaps(
 	if (XFS_IS_REALTIME_INODE(sc->ip) && whichfork == XFS_DATA_FORK)
 		return 0;
 
+	ASSERT(XFS_IFORK_PTR(sc->ip, whichfork) != NULL);
+
 	/*
 	 * Only do this for complex maps that are in btree format, or for
 	 * situations where we would seem to have a size but zero extents.
@@ -586,19 +588,13 @@ xchk_bmap_check_rmaps(
 	 * to flag this bmap as corrupt if there are rmaps that need to be
 	 * reattached.
 	 */
-	switch (whichfork) {
-	case XFS_DATA_FORK:
-		size = i_size_read(VFS_I(sc->ip));
-		break;
-	case XFS_ATTR_FORK:
-		size = XFS_IFORK_Q(sc->ip);
-		break;
-	default:
-		size = 0;
-		break;
-	}
+	if (whichfork == XFS_DATA_FORK)
+		zero_size = i_size_read(VFS_I(sc->ip)) == 0;
+	else
+		zero_size = false;
+
 	if (XFS_IFORK_FORMAT(sc->ip, whichfork) != XFS_DINODE_FMT_BTREE &&
-	    (size == 0 || XFS_IFORK_NEXTENTS(sc->ip, whichfork) > 0))
+	    (zero_size || XFS_IFORK_NEXTENTS(sc->ip, whichfork) > 0))
 		return 0;
 
 	for (agno = 0; agno < sc->mp->m_sb.sb_agcount; agno++) {
@@ -627,12 +623,14 @@ xchk_bmap(
 	struct xchk_bmap_info	info = { NULL };
 	struct xfs_mount	*mp = sc->mp;
 	struct xfs_inode	*ip = sc->ip;
-	struct xfs_ifork	*ifp;
+	struct xfs_ifork	*ifp = XFS_IFORK_PTR(ip, whichfork);
 	xfs_fileoff_t		endoff;
 	struct xfs_iext_cursor	icur;
 	int			error = 0;
 
-	ifp = XFS_IFORK_PTR(ip, whichfork);
+	/* Non-existent forks can be ignored. */
+	if (!ifp)
+		goto out;
 
 	info.is_rt = whichfork == XFS_DATA_FORK && XFS_IS_REALTIME_INODE(ip);
 	info.whichfork = whichfork;
@@ -641,9 +639,6 @@ xchk_bmap(
 
 	switch (whichfork) {
 	case XFS_COW_FORK:
-		/* Non-existent CoW forks are ignorable. */
-		if (!ifp)
-			goto out;
 		/* No CoW forks on non-reflink inodes/filesystems. */
 		if (!xfs_is_reflink_inode(ip)) {
 			xchk_ino_set_corrupt(sc, sc->ip->i_ino);
@@ -651,8 +646,6 @@ xchk_bmap(
 		}
 		break;
 	case XFS_ATTR_FORK:
-		if (!ifp)
-			goto out_check_rmap;
 		if (!xfs_sb_version_hasattr(&mp->m_sb) &&
 		    !xfs_sb_version_hasattr2(&mp->m_sb))
 			xchk_ino_set_corrupt(sc, sc->ip->i_ino);
@@ -717,7 +710,6 @@ xchk_bmap(
 			goto out;
 	}
 
-out_check_rmap:
 	error = xchk_bmap_check_rmaps(sc, whichfork);
 	if (!xchk_fblock_xref_process_error(sc, whichfork, 0, &error))
 		goto out;
-- 
2.26.2


  reply	other threads:[~2020-05-17  8:05 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-10  7:23 move the extent count and format into struct xfs_ifork Christoph Hellwig
2020-05-10  7:23 ` [PATCH 1/6] xfs: use XFS_IFORK_BOFF xchk_bmap_check_rmaps Christoph Hellwig
2020-05-11 11:40   ` Chandan Babu R
2020-05-12 15:31     ` Brian Foster
2020-05-12 15:38       ` Darrick J. Wong
2020-05-12 16:14         ` Brian Foster
2020-05-12 19:16           ` Darrick J. Wong
2020-05-13 13:19             ` Brian Foster
2020-05-13 13:21               ` Christoph Hellwig
2020-05-16 18:42   ` [PATCH] xfs: clean up xchk_bmap_check_rmaps usage of XFS_IFORK_Q Darrick J. Wong
2020-05-16 20:01     ` Christoph Hellwig
2020-05-17  8:05       ` Christoph Hellwig [this message]
2020-05-10  7:24 ` [PATCH 2/6] xfs: remove the XFS_DFORK_Q macro Christoph Hellwig
2020-05-11 12:39   ` Chandan Babu R
2020-05-12 15:31   ` Brian Foster
2020-05-16 18:02   ` Darrick J. Wong
2020-05-10  7:24 ` [PATCH 3/6] xfs: remove xfs_ifree_local_data Christoph Hellwig
2020-05-11 16:32   ` Chandan Babu R
2020-05-12 15:31   ` Brian Foster
2020-05-16 18:07   ` Darrick J. Wong
2022-07-24 12:14     ` Alex Lyakas
2020-05-10  7:24 ` [PATCH 4/6] xfs: move the per-fork nextents fields into struct xfs_ifork Christoph Hellwig
2020-05-12  5:26   ` Chandan Babu R
2020-05-12 16:10   ` Brian Foster
2020-05-16 18:09     ` Darrick J. Wong
2020-05-17  8:12     ` Christoph Hellwig
2020-05-10  7:24 ` [PATCH 5/6] xfs: move the fork format " Christoph Hellwig
2020-05-12  9:37   ` Chandan Babu R
2020-05-12 18:53   ` Brian Foster
2020-05-14 21:25   ` Darrick J. Wong
2020-05-16 13:58     ` Christoph Hellwig
2020-05-16 17:01       ` Darrick J. Wong
2020-05-16 18:01         ` Darrick J. Wong
2020-05-16 18:16           ` Christoph Hellwig
2020-05-16 18:29             ` Darrick J. Wong
2020-05-10  7:24 ` [PATCH 6/6] xfs: cleanup xfs_idestroy_fork Christoph Hellwig
2020-05-12  9:48   ` Chandan Babu R
2020-05-12 18:54   ` Brian Foster
2020-05-16 18:10     ` 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=20200517080514.GC30453@lst.de \
    --to=hch@lst.de \
    --cc=darrick.wong@oracle.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.