public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: Brian Foster <bfoster@redhat.com>
Cc: xfs@oss.sgi.com
Subject: Re: [PATCH 3/6] xfs: bulkstat chunk-formatter has issues
Date: Wed, 5 Nov 2014 08:18:38 +1100	[thread overview]
Message-ID: <20141104211838.GB28565@dastard> (raw)
In-Reply-To: <20141104185849.GE55611@bfoster.bfoster>

On Tue, Nov 04, 2014 at 01:58:49PM -0500, Brian Foster wrote:
> On Tue, Nov 04, 2014 at 11:53:18PM +1100, Dave Chinner wrote:
> > From: Dave Chinner <dchinner@redhat.com>
> > 
> > The loop construct has issues:
> > 	- clustidx is completely unused, so remove it.
> > 	- the loop tries to be smart by terminating when the
> > 	  "freecount" tells it that all inodes are free. Just drop
> > 	  it as in most cases we have to scan all inodes in the
> > 	  chunk anyway.
> > 	- move the "user buffer left" condition check to the only
> > 	  point where we consume space int eh user buffer.
> > 	- move the initialisation of agino out of the loop, leaving
> > 	  just a simple loop control logic using the clusteridx.
> > 
> > Also, double handling of the user buffer variables leads to problems
> > tracking the current state - use the cursor variables directly
> > rather than keeping local copies and then having to update the
> > cursor before returning.
> > 
> > cc: <stable@vger.kernel.org>
> > Signed-off-by: Dave Chinner <dchinner@redhat.com>
> > ---
> >  fs/xfs/xfs_itable.c | 55 ++++++++++++++++++++---------------------------------
> >  1 file changed, 21 insertions(+), 34 deletions(-)
> > 
> > diff --git a/fs/xfs/xfs_itable.c b/fs/xfs/xfs_itable.c
> > index 50a3e59..ff31965 100644
> > --- a/fs/xfs/xfs_itable.c
> > +++ b/fs/xfs/xfs_itable.c
> > @@ -283,59 +283,46 @@ xfs_bulkstat_ag_ichunk(
> >  	xfs_ino_t			*lastino)
> >  {
> >  	char				__user **ubufp = acp->ac_ubuffer;
> > -	int				ubleft = acp->ac_ubleft;
> > -	int				ubelem = acp->ac_ubelem;
> > -	int				chunkidx, clustidx;
> > +	int				chunkidx;
> >  	int				error = 0;
> >  	xfs_agino_t			agino;
> >  
> > -	for (agino = irbp->ir_startino, chunkidx = clustidx = 0;
> > -	     XFS_BULKSTAT_UBLEFT(ubleft) &&
> > -	     irbp->ir_freecount < XFS_INODES_PER_CHUNK;
> > -	     chunkidx++, clustidx++, agino++) {
> > -		int		fmterror;	/* bulkstat formatter result */
> > +	agino = irbp->ir_startino;
> > +	for (chunkidx = 0; chunkidx < XFS_INODES_PER_CHUNK;
> > +	     chunkidx++, agino++) {
> > +		int		fmterror;
> >  		int		ubused;
> >  		xfs_ino_t	ino = XFS_AGINO_TO_INO(mp, agno, agino);
> >  
> > -		ASSERT(chunkidx < XFS_INODES_PER_CHUNK);
> > -
> >  		/* Skip if this inode is free */
> >  		if (XFS_INOBT_MASK(chunkidx) & irbp->ir_free) {
> >  			*lastino = ino;
> >  			continue;
> >  		}
> >  
> > -		/*
> > -		 * Count used inodes as free so we can tell when the
> > -		 * chunk is used up.
> > -		 */
> > -		irbp->ir_freecount++;
> > -
> >  		/* Get the inode and fill in a single buffer */
> >  		ubused = statstruct_size;
> > -		error = formatter(mp, ino, *ubufp, ubleft, &ubused, &fmterror);
> > -		if (fmterror == BULKSTAT_RV_NOTHING) {
> > -			if (error && error != -ENOENT && error != -EINVAL) {
> > -				ubleft = 0;
> > -				break;
> > -			}
> > -			*lastino = ino;
> > -			continue;
> > -		}
> > -		if (fmterror == BULKSTAT_RV_GIVEUP) {
> > -			ubleft = 0;
> > +		error = formatter(mp, ino, *ubufp, acp->ac_ubleft,
> > +				  &ubused, &fmterror);
> > +		if (fmterror == BULKSTAT_RV_GIVEUP ||
> > +		    (error && error != -ENOENT && error != -EINVAL)) {
> > +			acp->ac_ubleft = 0;
> >  			ASSERT(error);
> >  			break;
> >  		}
> > -		if (*ubufp)
> > -			*ubufp += ubused;
> > -		ubleft -= ubused;
> > -		ubelem++;
> > +		if (fmterror == BULKSTAT_RV_NOTHING || error) {
> > +			*lastino = ino;
> > +			continue;
> > +		}
> 
> Not introduced by this patch, but this looks like inconsistent error
> handling. The structure of the code suggests we intend to carry on in
> the event of ENOENT or EINVAL, but said errors can leak out of this
> function if we never get back to the formatter call (e.g., we're at the
> last inode or all subsequent inodes are free).

Good catch - I'll fix it. I'll just zero the error in that branch.

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

  reply	other threads:[~2014-11-04 21:18 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-04 12:53 [PATCH 0/6] xfs: fix the bulkstat mess Dave Chinner
2014-11-04 12:53 ` [PATCH 1/6] xfs: bulkstat btree walk doesn't terminate Dave Chinner
2014-11-04 18:58   ` Brian Foster
2014-11-04 12:53 ` [PATCH 2/6] xfs: bulkstat chunk formatting cursor is broken Dave Chinner
2014-11-04 18:58   ` Brian Foster
2014-11-04 21:11     ` Dave Chinner
2014-11-04 12:53 ` [PATCH 3/6] xfs: bulkstat chunk-formatter has issues Dave Chinner
2014-11-04 18:58   ` Brian Foster
2014-11-04 21:18     ` Dave Chinner [this message]
2014-11-04 12:53 ` [PATCH 4/6] xfs: bulkstat main loop logic is a mess Dave Chinner
2014-11-04 18:59   ` Brian Foster
2014-11-04 21:20     ` Dave Chinner
2014-11-04 12:53 ` [PATCH 5/6] xfs: bulkstat error handling is broken Dave Chinner
2014-11-04 18:59   ` Brian Foster
2014-11-04 12:53 ` [PATCH 6/6] xfs: track bulkstat progress by agino Dave Chinner
2014-11-04 19:00   ` Brian Foster
2014-11-04 21:39     ` Dave Chinner
  -- strict thread matches above, loose matches on Subject: below --
2014-11-05  0:05 [PATCH 0/6 v2] xfs: fix the bulkstat mess Dave Chinner
2014-11-05  0:05 ` [PATCH 3/6] xfs: bulkstat chunk-formatter has issues Dave Chinner
2014-11-05 14:59   ` Brian Foster
2014-11-06 13:14 [PATCH 0/6 v3] xfs: fix the bulkstat mess Dave Chinner
2014-11-06 13:14 ` [PATCH 3/6] xfs: bulkstat chunk-formatter has issues Dave Chinner
2014-11-06 16:31   ` Brian Foster

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=20141104211838.GB28565@dastard \
    --to=david@fromorbit.com \
    --cc=bfoster@redhat.com \
    --cc=xfs@oss.sgi.com \
    /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