]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_scrub: fix per-thread counter error communication problems
authorDarrick J. Wong <darrick.wong@oracle.com>
Thu, 17 Oct 2019 02:35:25 +0000 (22:35 -0400)
committerEric Sandeen <sandeen@sandeen.net>
Thu, 17 Oct 2019 02:35:25 +0000 (22:35 -0400)
Fix all the places in the per-thread counter functions either we fail to
check for runtime errors or fail to communicate them properly to
callers.  Then fix all the callers to report the error messages instead
of hiding them.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
scrub/counter.c
scrub/counter.h
scrub/phase3.c
scrub/progress.c
scrub/read_verify.c

index 49ffbfea290210b95e0a276ee0f0a253ae680b0b..1bb726dcdf0d1f9c8f45e557b4b8e562669931c6 100644 (file)
@@ -26,23 +26,25 @@ struct ptcounter {
        struct ptvar    *var;
 };
 
-/* Initialize per-thread counter. */
-struct ptcounter *
-ptcounter_init(
-       size_t                  nr)
+/* Allocate per-thread counter. */
+int
+ptcounter_alloc(
+       size_t                  nr,
+       struct ptcounter        **pp)
 {
        struct ptcounter        *p;
        int                     ret;
 
        p = malloc(sizeof(struct ptcounter));
        if (!p)
-               return NULL;
+               return errno;
        ret = ptvar_alloc(nr, sizeof(uint64_t), &p->var);
        if (ret) {
                free(p);
-               return NULL;
+               return ret;
        }
-       return p;
+       *pp = p;
+       return 0;
 }
 
 /* Free per-thread counter. */
@@ -55,7 +57,7 @@ ptcounter_free(
 }
 
 /* Add a quantity to the counter. */
-void
+int
 ptcounter_add(
        struct ptcounter        *ptc,
        int64_t                 nr)
@@ -64,8 +66,10 @@ ptcounter_add(
        int                     ret;
 
        p = ptvar_get(ptc->var, &ret);
-       assert(ret == 0);
+       if (ret)
+               return ret;
        *p += nr;
+       return 0;
 }
 
 static int
@@ -82,12 +86,11 @@ ptcounter_val_helper(
 }
 
 /* Return the approximate value of this counter. */
-uint64_t
+int
 ptcounter_value(
-       struct ptcounter        *ptc)
+       struct ptcounter        *ptc,
+       uint64_t                *sum)
 {
-       uint64_t                sum = 0;
-
-       ptvar_foreach(ptc->var, ptcounter_val_helper, &sum);
-       return sum;
+       *sum = 0;
+       return ptvar_foreach(ptc->var, ptcounter_val_helper, sum);
 }
index 6c501b8570f36fbfd8c4a35dbaee1a0cfb41f7a8..01b65056a2ecba94712b26659aa68b34d7b77d20 100644 (file)
@@ -7,9 +7,9 @@
 #define XFS_SCRUB_COUNTER_H_
 
 struct ptcounter;
-struct ptcounter *ptcounter_init(size_t nr);
+int ptcounter_alloc(size_t nr, struct ptcounter **pp);
 void ptcounter_free(struct ptcounter *ptc);
-void ptcounter_add(struct ptcounter *ptc, int64_t nr);
-uint64_t ptcounter_value(struct ptcounter *ptc);
+int ptcounter_add(struct ptcounter *ptc, int64_t nr);
+int ptcounter_value(struct ptcounter *ptc, uint64_t *sum);
 
 #endif /* XFS_SCRUB_COUNTER_H_ */
index a32d1cedebeddbdb7e7a3235c9ed1f982699c6d8..1e908c2cf121dfece27cb9cd65b71d19c1e9253b 100644 (file)
@@ -139,7 +139,12 @@ xfs_scrub_inode(
                goto out;
 
 out:
-       ptcounter_add(icount, 1);
+       error = ptcounter_add(icount, 1);
+       if (error) {
+               str_liberror(ctx, error,
+                               _("incrementing scanned inode counter"));
+               return false;
+       }
        progress_add(1);
        xfs_action_list_defer(ctx, agno, &alist);
        if (fd >= 0) {
@@ -158,12 +163,14 @@ xfs_scan_inodes(
        struct scrub_ctx        *ctx)
 {
        struct scrub_inode_ctx  ictx;
+       uint64_t                val;
+       int                     err;
        bool                    ret;
 
        ictx.moveon = true;
-       ictx.icount = ptcounter_init(scrub_nproc(ctx));
-       if (!ictx.icount) {
-               str_info(ctx, ctx->mntpoint, _("Could not create counter."));
+       err = ptcounter_alloc(scrub_nproc(ctx), &ictx.icount);
+       if (err) {
+               str_liberror(ctx, err, _("creating scanned inode counter"));
                return false;
        }
 
@@ -173,8 +180,12 @@ xfs_scan_inodes(
        if (!ictx.moveon)
                goto free;
        xfs_scrub_report_preen_triggers(ctx);
-       ctx->inodes_checked = ptcounter_value(ictx.icount);
-
+       err = ptcounter_value(ictx.icount, &val);
+       if (err) {
+               str_liberror(ctx, err, _("summing scanned inode counter"));
+               return false;
+       }
+       ctx->inodes_checked = val;
 free:
        ptcounter_free(ictx.icount);
        return ictx.moveon;
index c9a9d28638f33324c011aaf19838b1a30b5fec1a..08c7233eef5094d4b4134bf090d6aa471ef1c4ee 100644 (file)
@@ -119,6 +119,8 @@ progress_report_thread(void *arg)
 
        pthread_mutex_lock(&pt.lock);
        while (1) {
+               uint64_t        progress_val;
+
                /* Every half second. */
                ret = clock_gettime(CLOCK_REALTIME, &abstime);
                if (ret)
@@ -131,7 +133,9 @@ progress_report_thread(void *arg)
                pthread_cond_timedwait(&pt.wakeup, &pt.lock, &abstime);
                if (pt.terminate)
                        break;
-               progress_report(ptcounter_value(pt.ptc));
+               ret = ptcounter_value(pt.ptc, &progress_val);
+               if (!ret)
+                       progress_report(progress_val);
        }
        pthread_mutex_unlock(&pt.lock);
        return NULL;
@@ -187,9 +191,11 @@ progress_init_phase(
        pt.twiddle = 0;
        pt.terminate = false;
 
-       pt.ptc = ptcounter_init(nr_threads);
-       if (!pt.ptc)
+       ret = ptcounter_alloc(nr_threads, &pt.ptc);
+       if (ret) {
+               str_liberror(ctx, ret, _("allocating progress counter"));
                goto out_max;
+       }
 
        ret = pthread_create(&pt.thread, NULL, progress_report_thread, NULL);
        if (ret)
index 95987a9bab3f45be4ceda3d41eb590df58ece792..b890c92f2f0016cd4f56386913f501d4fc3c13f7 100644 (file)
@@ -84,8 +84,8 @@ read_verify_pool_init(
                        RVP_IO_MAX_SIZE);
        if (error || !rvp->readbuf)
                goto out_free;
-       rvp->verified_bytes = ptcounter_init(nproc);
-       if (!rvp->verified_bytes)
+       error = ptcounter_alloc(nproc, &rvp->verified_bytes);
+       if (error)
                goto out_buf;
        rvp->miniosz = miniosz;
        rvp->ctx = ctx;
@@ -282,5 +282,8 @@ uint64_t
 read_verify_bytes(
        struct read_verify_pool         *rvp)
 {
-       return ptcounter_value(rvp->verified_bytes);
+       uint64_t                        ret;
+
+       ptcounter_value(rvp->verified_bytes, &ret);
+       return ret;
 }