From: Darrick J. Wong <darrick.wong@xxxxxxxxxx> Replace the moveon returns in the fscounters functions with direct error returns. Drop the xfs_ prefixes while we're at it. Signed-off-by: Darrick J. Wong <darrick.wong@xxxxxxxxxx> --- scrub/fscounters.c | 129 ++++++++++++++++++++-------------------------------- scrub/fscounters.h | 4 +- scrub/phase6.c | 12 +++-- scrub/phase7.c | 15 ++++-- 4 files changed, 68 insertions(+), 92 deletions(-) diff --git a/scrub/fscounters.c b/scrub/fscounters.c index e064c865..2581947f 100644 --- a/scrub/fscounters.c +++ b/scrub/fscounters.c @@ -25,8 +25,8 @@ /* Count the number of inodes in the filesystem. */ /* INUMBERS wrapper routines. */ -struct xfs_count_inodes { - bool moveon; +struct count_inodes { + int error; uint64_t counters[0]; }; @@ -34,13 +34,14 @@ struct xfs_count_inodes { * Count the number of inodes. Use INUMBERS to figure out how many inodes * exist in the filesystem, assuming we've already scrubbed that. */ -static bool -xfs_count_inodes_ag( - struct scrub_ctx *ctx, - const char *descr, - uint32_t agno, - uint64_t *count) +static void +count_ag_inodes( + struct workqueue *wq, + xfs_agnumber_t agno, + void *arg) { + struct count_inodes *ci = arg; + struct scrub_ctx *ctx = (struct scrub_ctx *)wq->wq_ctx; struct xfs_inumbers_req *ireq; uint64_t nr = 0; unsigned int i; @@ -48,107 +49,78 @@ xfs_count_inodes_ag( ireq = xfrog_inumbers_alloc_req(64, 0); if (!ireq) { - str_liberror(ctx, ENOMEM, _("allocating inumbers request")); - return false; + ci->error = errno; + return; } xfrog_inumbers_set_ag(ireq, agno); - while (!(error = xfrog_inumbers(&ctx->mnt, ireq))) { + while (!ci->error && (error = xfrog_inumbers(&ctx->mnt, ireq)) == 0) { if (ireq->hdr.ocount == 0) break; for (i = 0; i < ireq->hdr.ocount; i++) nr += ireq->inumbers[i].xi_alloccount; } + if (error) + ci->error = error; free(ireq); - if (error) { - str_liberror(ctx, error, descr); - return false; - } - - *count = nr; - return true; -} - -/* Scan all the inodes in an AG. */ -static void -xfs_count_ag_inodes( - struct workqueue *wq, - xfs_agnumber_t agno, - void *arg) -{ - struct xfs_count_inodes *ci = arg; - struct scrub_ctx *ctx = (struct scrub_ctx *)wq->wq_ctx; - char descr[DESCR_BUFSZ]; - bool moveon; - - snprintf(descr, DESCR_BUFSZ, _("dev %d:%d AG %u inodes"), - major(ctx->fsinfo.fs_datadev), - minor(ctx->fsinfo.fs_datadev), - agno); - - moveon = xfs_count_inodes_ag(ctx, descr, agno, &ci->counters[agno]); - if (!moveon) - ci->moveon = false; + ci->counters[agno] = nr; } -/* Count all the inodes in a filesystem. */ -bool -xfs_count_all_inodes( +/* + * Count all the inodes in a filesystem. Returns 0 or a positive error number. + */ +int +scrub_count_all_inodes( struct scrub_ctx *ctx, uint64_t *count) { - struct xfs_count_inodes *ci; + struct count_inodes *ci; xfs_agnumber_t agno; struct workqueue wq; - bool moveon = true; - int ret; + int ret, ret2; - ci = calloc(1, sizeof(struct xfs_count_inodes) + + ci = calloc(1, sizeof(struct count_inodes) + (ctx->mnt.fsgeom.agcount * sizeof(uint64_t))); if (!ci) - return false; - ci->moveon = true; + return errno; ret = workqueue_create(&wq, (struct xfs_mount *)ctx, scrub_nproc_workqueue(ctx)); - if (ret) { - moveon = false; - str_liberror(ctx, ret, _("creating icount workqueue")); + if (ret) goto out_free; - } - for (agno = 0; agno < ctx->mnt.fsgeom.agcount; agno++) { - ret = workqueue_add(&wq, xfs_count_ag_inodes, agno, ci); - if (ret) { - moveon = false; - str_liberror(ctx, ret, _("queueing icount work")); + + for (agno = 0; agno < ctx->mnt.fsgeom.agcount && !ci->error; agno++) { + ret = workqueue_add(&wq, count_ag_inodes, agno, ci); + if (ret) break; - } } - ret = workqueue_terminate(&wq); - if (ret) { - moveon = false; - str_liberror(ctx, ret, _("finishing icount work")); - } + ret2 = workqueue_terminate(&wq); + if (!ret && ret2) + ret = ret2; workqueue_destroy(&wq); - if (!moveon) + if (ci->error) { + ret = ci->error; goto out_free; + } for (agno = 0; agno < ctx->mnt.fsgeom.agcount; agno++) *count += ci->counters[agno]; - moveon = ci->moveon; out_free: free(ci); - return moveon; + return ret; } -/* Estimate the number of blocks and inodes in the filesystem. */ -bool -xfs_scan_estimate_blocks( +/* + * Estimate the number of blocks and inodes in the filesystem. Returns 0 + * or a positive error number. + */ +int +scrub_scan_estimate_blocks( struct scrub_ctx *ctx, unsigned long long *d_blocks, unsigned long long *d_bfree, @@ -164,17 +136,13 @@ xfs_scan_estimate_blocks( /* Grab the fstatvfs counters, since it has to report accurately. */ error = fstatvfs(ctx->mnt.fd, &sfs); - if (error) { - str_errno(ctx, ctx->mntpoint); - return false; - } + if (error) + return errno; /* Fetch the filesystem counters. */ error = ioctl(ctx->mnt.fd, XFS_IOC_FSCOUNTS, &fc); - if (error) { - str_errno(ctx, ctx->mntpoint); - return false; - } + if (error) + return errno; /* * XFS reserves some blocks to prevent hard ENOSPC, so add those @@ -182,7 +150,8 @@ xfs_scan_estimate_blocks( */ error = ioctl(ctx->mnt.fd, XFS_IOC_GET_RESBLKS, &rb); if (error) - str_errno(ctx, ctx->mntpoint); + return errno; + sfs.f_bfree += rb.resblks_avail; *d_blocks = sfs.f_blocks; @@ -194,5 +163,5 @@ xfs_scan_estimate_blocks( *f_files = sfs.f_files; *f_free = sfs.f_ffree; - return true; + return 0; } diff --git a/scrub/fscounters.h b/scrub/fscounters.h index e3a79740..1fae58a6 100644 --- a/scrub/fscounters.h +++ b/scrub/fscounters.h @@ -6,10 +6,10 @@ #ifndef XFS_SCRUB_FSCOUNTERS_H_ #define XFS_SCRUB_FSCOUNTERS_H_ -bool xfs_scan_estimate_blocks(struct scrub_ctx *ctx, +int scrub_scan_estimate_blocks(struct scrub_ctx *ctx, unsigned long long *d_blocks, unsigned long long *d_bfree, unsigned long long *r_blocks, unsigned long long *r_bfree, unsigned long long *f_files, unsigned long long *f_free); -bool xfs_count_all_inodes(struct scrub_ctx *ctx, uint64_t *count); +int scrub_count_all_inodes(struct scrub_ctx *ctx, uint64_t *count); #endif /* XFS_SCRUB_FSCOUNTERS_H_ */ diff --git a/scrub/phase6.c b/scrub/phase6.c index 0f22af59..6a8dabe1 100644 --- a/scrub/phase6.c +++ b/scrub/phase6.c @@ -776,17 +776,19 @@ xfs_estimate_verify_work( unsigned long long r_bfree; unsigned long long f_files; unsigned long long f_free; - bool moveon; + int ret; - moveon = xfs_scan_estimate_blocks(ctx, &d_blocks, &d_bfree, + ret = scrub_scan_estimate_blocks(ctx, &d_blocks, &d_bfree, &r_blocks, &r_bfree, &f_files, &f_free); - if (!moveon) - return moveon; + if (ret) { + str_liberror(ctx, ret, _("estimating verify work")); + return false; + } *items = cvt_off_fsb_to_b(&ctx->mnt, d_blocks + r_blocks); if (scrub_data == 1) *items -= cvt_off_fsb_to_b(&ctx->mnt, d_bfree + r_bfree); *nr_threads = disk_heads(ctx->datadev); *rshift = 20; - return moveon; + return true; } diff --git a/scrub/phase7.c b/scrub/phase7.c index 2622bc45..64e52359 100644 --- a/scrub/phase7.c +++ b/scrub/phase7.c @@ -156,14 +156,19 @@ xfs_scan_summary( ptvar_free(ptvar); /* Scan the whole fs. */ - moveon = xfs_count_all_inodes(ctx, &counted_inodes); - if (!moveon) + error = scrub_count_all_inodes(ctx, &counted_inodes); + if (error) { + str_liberror(ctx, error, _("counting inodes")); + moveon = false; goto out; + } - moveon = xfs_scan_estimate_blocks(ctx, &d_blocks, &d_bfree, &r_blocks, + error = scrub_scan_estimate_blocks(ctx, &d_blocks, &d_bfree, &r_blocks, &r_bfree, &f_files, &f_free); - if (!moveon) - return moveon; + if (error) { + str_liberror(ctx, error, _("estimating verify work")); + return false; + } /* * If we counted blocks with fsmap, then dblocks includes