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 4/6] xfs: bulkstat main loop logic is a mess
Date: Wed, 5 Nov 2014 08:20:42 +1100	[thread overview]
Message-ID: <20141104212042.GC28565@dastard> (raw)
In-Reply-To: <20141104185908.GF55611@bfoster.bfoster>

On Tue, Nov 04, 2014 at 01:59:08PM -0500, Brian Foster wrote:
> On Tue, Nov 04, 2014 at 11:53:19PM +1100, Dave Chinner wrote:
> > From: Dave Chinner <dchinner@redhat.com>
> > 
> > There are a bunch of variables tha tare more wildy scoped than they
> > need to be, obfuscated user buffer checks and tortured "next inode"
> > tracking. This all needs cleaning up to expose the real issues that
> > need fixing.
> > 
> > cc: <stable@vger.kernel.org>
> > Signed-off-by: Dave Chinner <dchinner@redhat.com>
> > ---
> >  fs/xfs/xfs_itable.c | 55 ++++++++++++++++++++++-------------------------------
> >  1 file changed, 23 insertions(+), 32 deletions(-)
> > 
> > diff --git a/fs/xfs/xfs_itable.c b/fs/xfs/xfs_itable.c
> > index ff31965..fc4cf5d 100644
> > --- a/fs/xfs/xfs_itable.c
> > +++ b/fs/xfs/xfs_itable.c
> > @@ -345,30 +345,23 @@ xfs_bulkstat(
> >  	xfs_agino_t		agino;	/* inode # in allocation group */
> >  	xfs_agnumber_t		agno;	/* allocation group number */
> >  	xfs_btree_cur_t		*cur;	/* btree cursor for ialloc btree */
> > -	int			end_of_ag; /* set if we've seen the ag end */
> > -	int			error;	/* error code */
> > -	int			icount;	/* count of inodes good in irbuf */
> >  	size_t			irbsize; /* size of irec buffer in bytes */
> > -	xfs_ino_t		ino;	/* inode number (filesystem) */
> > -	xfs_inobt_rec_incore_t	*irbp;	/* current irec buffer pointer */
> >  	xfs_inobt_rec_incore_t	*irbuf;	/* start of irec buffer */
> > -	xfs_inobt_rec_incore_t	*irbufend; /* end of good irec buffer entries */
> >  	xfs_ino_t		lastino; /* last inode number returned */
> >  	int			nirbuf;	/* size of irbuf */
> >  	int			rval;	/* return value error code */
> >  	int			ubcount; /* size of user's buffer */
> > -	int			stat;
> >  	struct xfs_bulkstat_agichunk ac;
> > +	int			error = 0;
> >  
> >  	/*
> >  	 * Get the last inode value, see if there's nothing to do.
> >  	 */
> > -	ino = (xfs_ino_t)*lastinop;
> > -	lastino = ino;
> > -	agno = XFS_INO_TO_AGNO(mp, ino);
> > -	agino = XFS_INO_TO_AGINO(mp, ino);
> > +	lastino = *lastinop;
> > +	agno = XFS_INO_TO_AGNO(mp, lastino);
> > +	agino = XFS_INO_TO_AGINO(mp, lastino);
> >  	if (agno >= mp->m_sb.sb_agcount ||
> > -	    ino != XFS_AGINO_TO_INO(mp, agno, agino)) {
> > +	    lastino != XFS_AGINO_TO_INO(mp, agno, agino)) {
> >  		*done = 1;
> >  		*ubcountp = 0;
> >  		return 0;
> > @@ -393,8 +386,13 @@ xfs_bulkstat(
> >  	 * inode returned; 0 means start of the allocation group.
> >  	 */
> >  	rval = 0;
> > -	while (XFS_BULKSTAT_UBLEFT(ac.ac_ubleft) && agno < mp->m_sb.sb_agcount) {
> > -		cond_resched();
> > +	while (ac.ac_ubleft >= statstruct_size && agno < mp->m_sb.sb_agcount) {
> > +		struct xfs_inobt_rec_incore	*irbp = irbuf;
> > +		struct xfs_inobt_rec_incore	*irbufend = irbuf + nirbuf;
> > +		bool				end_of_ag = false;
> > +		int				icount = 0;
> > +		int				stat;
> > +
> >  		error = xfs_ialloc_read_agi(mp, NULL, agno, &agbp);
> >  		if (error)
> >  			break;
> > @@ -404,10 +402,6 @@ xfs_bulkstat(
> >  		 */
> >  		cur = xfs_inobt_init_cursor(mp, NULL, agbp, agno,
> >  					    XFS_BTNUM_INO);
> > -		irbp = irbuf;
> > -		irbufend = irbuf + nirbuf;
> > -		end_of_ag = 0;
> > -		icount = 0;
> >  		if (agino > 0) {
> >  			/*
> >  			 * In the middle of an allocation group, we need to get
> > @@ -432,7 +426,7 @@ xfs_bulkstat(
> >  			error = xfs_inobt_lookup(cur, 0, XFS_LOOKUP_GE, &stat);
> >  		}
> >  		if (error || stat == 0) {
> > -			end_of_ag = 1;
> > +			end_of_ag = true;
> >  			goto del_cursor;
> >  		}
> >  
> > @@ -445,7 +439,7 @@ xfs_bulkstat(
> >  
> >  			error = xfs_inobt_get_rec(cur, &r, &stat);
> >  			if (error || stat == 0) {
> > -				end_of_ag = 1;
> > +				end_of_ag = true;
> >  				goto del_cursor;
> >  			}
> >  
> > @@ -467,7 +461,7 @@ xfs_bulkstat(
> >  			agino = r.ir_startino + XFS_INODES_PER_CHUNK;
> >  			error = xfs_btree_increment(cur, 0, &stat);
> >  			if (error || stat == 0) {
> > -				end_of_ag = 1;
> > +				end_of_ag = true;
> >  				goto del_cursor;
> >  			}
> >  			cond_resched();
> > @@ -488,7 +482,7 @@ del_cursor:
> >  		 */
> >  		irbufend = irbp;
> >  		for (irbp = irbuf;
> > -		     irbp < irbufend && XFS_BULKSTAT_UBLEFT(ac.ac_ubleft);
> > +		     irbp < irbufend && ac.ac_ubleft >= statstruct_size;
> >  		     irbp++) {
> >  			error = xfs_bulkstat_ag_ichunk(mp, agno, irbp,
> >  					formatter, statstruct_size, &ac,
> > @@ -499,17 +493,14 @@ del_cursor:
> >  			cond_resched();
> >  		}
> >  
> > -		/*
> > -		 * Set up for the next loop iteration.
> > -		 */
> > -		if (XFS_BULKSTAT_UBLEFT(ac.ac_ubleft)) {
> > -			if (end_of_ag) {
> > -				agno++;
> > -				agino = 0;
> > -			} else
> > -				agino = XFS_INO_TO_AGINO(mp, lastino);
> > -		} else
> > +		if (error)
> >  			break;
> 
> This stood out to me as potentially broken as it introduces a
> non-deterministic error path. The preceding loop can overwrite error
> since it iterates until either all records are handled or the buffer is
> consumed.

That's true. Again an issue from splitting the larger patch up and
putting a chunk in the wrong patch. I'll move it to the next patch.

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:21 UTC|newest]

Thread overview: 20+ 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
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 [this message]
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 4/6] xfs: bulkstat main loop logic is a mess Dave Chinner
2014-11-06 13:14 [PATCH 0/6 v3] xfs: fix the bulkstat mess Dave Chinner
2014-11-06 13:14 ` [PATCH 4/6] xfs: bulkstat main loop logic is a mess Dave Chinner
2014-11-06 16:32   ` 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=20141104212042.GC28565@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