Commit 2b831ac6bc87d3cbcbb1a8816827b6923403e461

Authored by Dave Chinner
Committed by Dave Chinner
1 parent bf4a5af20d

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: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>

Showing 1 changed file with 24 additions and 34 deletions Side-by-side Diff

... ... @@ -283,59 +283,49 @@
283 283 xfs_ino_t *lastino)
284 284 {
285 285 char __user **ubufp = acp->ac_ubuffer;
286   - int ubleft = acp->ac_ubleft;
287   - int ubelem = acp->ac_ubelem;
288   - int chunkidx, clustidx;
  286 + int chunkidx;
289 287 int error = 0;
290 288 xfs_agino_t agino;
291 289  
292   - for (agino = irbp->ir_startino, chunkidx = clustidx = 0;
293   - XFS_BULKSTAT_UBLEFT(ubleft) &&
294   - irbp->ir_freecount < XFS_INODES_PER_CHUNK;
295   - chunkidx++, clustidx++, agino++) {
296   - int fmterror; /* bulkstat formatter result */
  290 + agino = irbp->ir_startino;
  291 + for (chunkidx = 0; chunkidx < XFS_INODES_PER_CHUNK;
  292 + chunkidx++, agino++) {
  293 + int fmterror;
297 294 int ubused;
298 295 xfs_ino_t ino = XFS_AGINO_TO_INO(mp, agno, agino);
299 296  
300   - ASSERT(chunkidx < XFS_INODES_PER_CHUNK);
301   -
302 297 /* Skip if this inode is free */
303 298 if (XFS_INOBT_MASK(chunkidx) & irbp->ir_free) {
304 299 *lastino = ino;
305 300 continue;
306 301 }
307 302  
308   - /*
309   - * Count used inodes as free so we can tell when the
310   - * chunk is used up.
311   - */
312   - irbp->ir_freecount++;
313   -
314 303 /* Get the inode and fill in a single buffer */
315 304 ubused = statstruct_size;
316   - error = formatter(mp, ino, *ubufp, ubleft, &ubused, &fmterror);
317   - if (fmterror == BULKSTAT_RV_NOTHING) {
318   - if (error && error != -ENOENT && error != -EINVAL) {
319   - ubleft = 0;
320   - break;
321   - }
322   - *lastino = ino;
323   - continue;
324   - }
325   - if (fmterror == BULKSTAT_RV_GIVEUP) {
326   - ubleft = 0;
  305 + error = formatter(mp, ino, *ubufp, acp->ac_ubleft,
  306 + &ubused, &fmterror);
  307 + if (fmterror == BULKSTAT_RV_GIVEUP ||
  308 + (error && error != -ENOENT && error != -EINVAL)) {
  309 + acp->ac_ubleft = 0;
327 310 ASSERT(error);
328 311 break;
329 312 }
330   - if (*ubufp)
331   - *ubufp += ubused;
332   - ubleft -= ubused;
333   - ubelem++;
  313 +
  314 + /* be careful not to leak error if at end of chunk */
  315 + if (fmterror == BULKSTAT_RV_NOTHING || error) {
  316 + *lastino = ino;
  317 + error = 0;
  318 + continue;
  319 + }
  320 +
  321 + *ubufp += ubused;
  322 + acp->ac_ubleft -= ubused;
  323 + acp->ac_ubelem++;
334 324 *lastino = ino;
335   - }
336 325  
337   - acp->ac_ubleft = ubleft;
338   - acp->ac_ubelem = ubelem;
  326 + if (acp->ac_ubleft < statstruct_size)
  327 + break;
  328 + }
339 329  
340 330 return error;
341 331 }