Commit 2b831ac6 authored by Dave Chinner's avatar Dave Chinner Committed by Dave Chinner

xfs: bulkstat chunk-formatter has issues

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> # 3.17
Signed-off-by: default avatarDave Chinner <dchinner@redhat.com>
Reviewed-by: default avatarBrian Foster <bfoster@redhat.com>
Signed-off-by: default avatarDave Chinner <david@fromorbit.com>
parent bf4a5af2
...@@ -283,59 +283,49 @@ xfs_bulkstat_ag_ichunk( ...@@ -283,59 +283,49 @@ xfs_bulkstat_ag_ichunk(
xfs_ino_t *lastino) xfs_ino_t *lastino)
{ {
char __user **ubufp = acp->ac_ubuffer; char __user **ubufp = acp->ac_ubuffer;
int ubleft = acp->ac_ubleft; int chunkidx;
int ubelem = acp->ac_ubelem;
int chunkidx, clustidx;
int error = 0; int error = 0;
xfs_agino_t agino; xfs_agino_t agino;
for (agino = irbp->ir_startino, chunkidx = clustidx = 0; agino = irbp->ir_startino;
XFS_BULKSTAT_UBLEFT(ubleft) && for (chunkidx = 0; chunkidx < XFS_INODES_PER_CHUNK;
irbp->ir_freecount < XFS_INODES_PER_CHUNK; chunkidx++, agino++) {
chunkidx++, clustidx++, agino++) { int fmterror;
int fmterror; /* bulkstat formatter result */
int ubused; int ubused;
xfs_ino_t ino = XFS_AGINO_TO_INO(mp, agno, agino); xfs_ino_t ino = XFS_AGINO_TO_INO(mp, agno, agino);
ASSERT(chunkidx < XFS_INODES_PER_CHUNK);
/* Skip if this inode is free */ /* Skip if this inode is free */
if (XFS_INOBT_MASK(chunkidx) & irbp->ir_free) { if (XFS_INOBT_MASK(chunkidx) & irbp->ir_free) {
*lastino = ino; *lastino = ino;
continue; 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 */ /* Get the inode and fill in a single buffer */
ubused = statstruct_size; ubused = statstruct_size;
error = formatter(mp, ino, *ubufp, ubleft, &ubused, &fmterror); error = formatter(mp, ino, *ubufp, acp->ac_ubleft,
if (fmterror == BULKSTAT_RV_NOTHING) { &ubused, &fmterror);
if (error && error != -ENOENT && error != -EINVAL) { if (fmterror == BULKSTAT_RV_GIVEUP ||
ubleft = 0; (error && error != -ENOENT && error != -EINVAL)) {
break; acp->ac_ubleft = 0;
}
*lastino = ino;
continue;
}
if (fmterror == BULKSTAT_RV_GIVEUP) {
ubleft = 0;
ASSERT(error); ASSERT(error);
break; break;
} }
if (*ubufp)
*ubufp += ubused; /* be careful not to leak error if at end of chunk */
ubleft -= ubused; if (fmterror == BULKSTAT_RV_NOTHING || error) {
ubelem++; *lastino = ino;
error = 0;
continue;
}
*ubufp += ubused;
acp->ac_ubleft -= ubused;
acp->ac_ubelem++;
*lastino = ino; *lastino = ino;
}
acp->ac_ubleft = ubleft; if (acp->ac_ubleft < statstruct_size)
acp->ac_ubelem = ubelem; break;
}
return error; return error;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment