]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blobdiff - scrub/phase2.c
libfrog: convert workqueue.c functions to negative error codes
[thirdparty/xfsprogs-dev.git] / scrub / phase2.c
index d92b7e29765373d8417a23120b1859b4869c47c0..c40d9d3b17fc3339d3988f9ff04bd09d0b9ee44d 100644 (file)
 
 /* Scrub each AG's metadata btrees. */
 static void
-xfs_scan_ag_metadata(
+scan_ag_metadata(
        struct workqueue                *wq,
        xfs_agnumber_t                  agno,
        void                            *arg)
 {
        struct scrub_ctx                *ctx = (struct scrub_ctx *)wq->wq_ctx;
-       bool                            *pmoveon = arg;
-       struct xfs_action_list          alist;
-       struct xfs_action_list          immediate_alist;
+       bool                            *aborted = arg;
+       struct action_list              alist;
+       struct action_list              immediate_alist;
        unsigned long long              broken_primaries;
        unsigned long long              broken_secondaries;
-       bool                            moveon;
        char                            descr[DESCR_BUFSZ];
+       int                             ret;
 
-       xfs_action_list_init(&alist);
-       xfs_action_list_init(&immediate_alist);
+       if (*aborted)
+               return;
+
+       action_list_init(&alist);
+       action_list_init(&immediate_alist);
        snprintf(descr, DESCR_BUFSZ, _("AG %u"), agno);
 
        /*
         * First we scrub and fix the AG headers, because we need
         * them to work well enough to check the AG btrees.
         */
-       moveon = xfs_scrub_ag_headers(ctx, agno, &alist);
-       if (!moveon)
+       ret = xfs_scrub_ag_headers(ctx, agno, &alist);
+       if (ret)
                goto err;
 
        /* Repair header damage. */
-       moveon = xfs_action_list_process_or_defer(ctx, agno, &alist);
-       if (!moveon)
+       ret = action_list_process_or_defer(ctx, agno, &alist);
+       if (ret)
                goto err;
 
        /* Now scrub the AG btrees. */
-       moveon = xfs_scrub_ag_metadata(ctx, agno, &alist);
-       if (!moveon)
+       ret = xfs_scrub_ag_metadata(ctx, agno, &alist);
+       if (ret)
                goto err;
 
        /*
@@ -64,7 +67,7 @@ xfs_scan_ag_metadata(
         */
        broken_secondaries = 0;
        broken_primaries = 0;
-       xfs_action_list_find_mustfix(&alist, &immediate_alist,
+       action_list_find_mustfix(&alist, &immediate_alist,
                        &broken_primaries, &broken_secondaries);
        if (broken_secondaries && !debug_tweak_on("XFS_SCRUB_FORCE_REPAIR")) {
                if (broken_primaries)
@@ -78,54 +81,58 @@ _("Filesystem might not be repairable."));
        }
 
        /* Repair (inode) btree damage. */
-       moveon = xfs_action_list_process_or_defer(ctx, agno, &immediate_alist);
-       if (!moveon)
+       ret = action_list_process_or_defer(ctx, agno, &immediate_alist);
+       if (ret)
                goto err;
 
        /* Everything else gets fixed during phase 4. */
-       xfs_action_list_defer(ctx, agno, &alist);
-
+       action_list_defer(ctx, agno, &alist);
        return;
 err:
-       *pmoveon = false;
+       *aborted = true;
 }
 
 /* Scrub whole-FS metadata btrees. */
 static void
-xfs_scan_fs_metadata(
+scan_fs_metadata(
        struct workqueue                *wq,
        xfs_agnumber_t                  agno,
        void                            *arg)
 {
        struct scrub_ctx                *ctx = (struct scrub_ctx *)wq->wq_ctx;
-       bool                            *pmoveon = arg;
-       struct xfs_action_list          alist;
-       bool                            moveon;
+       bool                            *aborted = arg;
+       struct action_list              alist;
+       int                             ret;
 
-       xfs_action_list_init(&alist);
-       moveon = xfs_scrub_fs_metadata(ctx, &alist);
-       if (!moveon)
-               *pmoveon = false;
+       if (*aborted)
+               return;
 
-       xfs_action_list_defer(ctx, agno, &alist);
+       action_list_init(&alist);
+       ret = xfs_scrub_fs_metadata(ctx, &alist);
+       if (ret) {
+               *aborted = true;
+               return;
+       }
+
+       action_list_defer(ctx, agno, &alist);
 }
 
 /* Scan all filesystem metadata. */
-bool
-xfs_scan_metadata(
+int
+phase2_func(
        struct scrub_ctx        *ctx)
 {
-       struct xfs_action_list  alist;
+       struct action_list      alist;
        struct workqueue        wq;
        xfs_agnumber_t          agno;
-       bool                    moveon = true;
-       int                     ret;
+       bool                    aborted = false;
+       int                     ret, ret2;
 
-       ret = workqueue_create(&wq, (struct xfs_mount *)ctx,
+       ret = -workqueue_create(&wq, (struct xfs_mount *)ctx,
                        scrub_nproc_workqueue(ctx));
        if (ret) {
                str_liberror(ctx, ret, _("creating scrub workqueue"));
-               return false;
+               return ret;
        }
 
        /*
@@ -133,53 +140,55 @@ xfs_scan_metadata(
         * upgrades (followed by a full scrub), do that before we launch
         * anything else.
         */
-       xfs_action_list_init(&alist);
-       moveon = xfs_scrub_primary_super(ctx, &alist);
-       if (!moveon)
+       action_list_init(&alist);
+       ret = xfs_scrub_primary_super(ctx, &alist);
+       if (ret)
                goto out;
-       moveon = xfs_action_list_process_or_defer(ctx, 0, &alist);
-       if (!moveon)
+       ret = action_list_process_or_defer(ctx, 0, &alist);
+       if (ret)
                goto out;
 
-       for (agno = 0; moveon && agno < ctx->mnt.fsgeom.agcount; agno++) {
-               ret = workqueue_add(&wq, xfs_scan_ag_metadata, agno, &moveon);
+       for (agno = 0; !aborted && agno < ctx->mnt.fsgeom.agcount; agno++) {
+               ret = -workqueue_add(&wq, scan_ag_metadata, agno, &aborted);
                if (ret) {
-                       moveon = false;
                        str_liberror(ctx, ret, _("queueing per-AG scrub work"));
                        goto out;
                }
        }
 
-       if (!moveon)
+       if (aborted)
                goto out;
 
-       ret = workqueue_add(&wq, xfs_scan_fs_metadata, 0, &moveon);
+       ret = -workqueue_add(&wq, scan_fs_metadata, 0, &aborted);
        if (ret) {
-               moveon = false;
                str_liberror(ctx, ret, _("queueing per-FS scrub work"));
                goto out;
        }
 
 out:
-       ret = workqueue_terminate(&wq);
-       if (ret) {
-               moveon = false;
-               str_liberror(ctx, ret, _("finishing scrub work"));
+       ret2 = -workqueue_terminate(&wq);
+       if (ret2) {
+               str_liberror(ctx, ret2, _("finishing scrub work"));
+               if (!ret && ret2)
+                       ret = ret2;
        }
        workqueue_destroy(&wq);
-       return moveon;
+
+       if (!ret && aborted)
+               ret = ECANCELED;
+       return ret;
 }
 
 /* Estimate how much work we're going to do. */
-bool
-xfs_estimate_metadata_work(
+int
+phase2_estimate(
        struct scrub_ctx        *ctx,
        uint64_t                *items,
        unsigned int            *nr_threads,
        int                     *rshift)
 {
-       *items = xfs_scrub_estimate_ag_work(ctx);
+       *items = scrub_estimate_ag_work(ctx);
        *nr_threads = scrub_nproc(ctx);
        *rshift = 0;
-       return true;
+       return 0;
 }