]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_scrub: remove moveon from scrub ioctl wrappers
authorDarrick J. Wong <darrick.wong@oracle.com>
Wed, 6 Nov 2019 22:29:22 +0000 (17:29 -0500)
committerEric Sandeen <sandeen@sandeen.net>
Wed, 6 Nov 2019 22:29:22 +0000 (17:29 -0500)
Replace the moveon returns in the scrub ioctl wrapper functions
with a direct integer error return.

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/phase2.c
scrub/phase3.c
scrub/phase4.c
scrub/phase5.c
scrub/phase7.c
scrub/scrub.c
scrub/scrub.h
scrub/xfs_scrub.h

index d92b7e29765373d8417a23120b1859b4869c47c0..016d8ec5f36bb99d3d84d92567e660b99ce973b2 100644 (file)
@@ -32,6 +32,7 @@ xfs_scan_ag_metadata(
        unsigned long long              broken_secondaries;
        bool                            moveon;
        char                            descr[DESCR_BUFSZ];
+       int                             ret;
 
        xfs_action_list_init(&alist);
        xfs_action_list_init(&immediate_alist);
@@ -41,8 +42,8 @@ xfs_scan_ag_metadata(
         * 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. */
@@ -51,8 +52,8 @@ xfs_scan_ag_metadata(
                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;
 
        /*
@@ -100,11 +101,11 @@ xfs_scan_fs_metadata(
        struct scrub_ctx                *ctx = (struct scrub_ctx *)wq->wq_ctx;
        bool                            *pmoveon = arg;
        struct xfs_action_list          alist;
-       bool                            moveon;
+       int                             ret;
 
        xfs_action_list_init(&alist);
-       moveon = xfs_scrub_fs_metadata(ctx, &alist);
-       if (!moveon)
+       ret = xfs_scrub_fs_metadata(ctx, &alist);
+       if (ret)
                *pmoveon = false;
 
        xfs_action_list_defer(ctx, agno, &alist);
@@ -134,9 +135,11 @@ xfs_scan_metadata(
         * anything else.
         */
        xfs_action_list_init(&alist);
-       moveon = xfs_scrub_primary_super(ctx, &alist);
-       if (!moveon)
+       ret = xfs_scrub_primary_super(ctx, &alist);
+       if (ret) {
+               moveon = false;
                goto out;
+       }
        moveon = xfs_action_list_process_or_defer(ctx, 0, &alist);
        if (!moveon)
                goto out;
@@ -178,7 +181,7 @@ xfs_estimate_metadata_work(
        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;
index 171be3fd883b936e93785ffc976f2d9f7f711e7a..4248e85f62659b007f46d83f14ec8df61cb16ef4 100644 (file)
  * ensure that the inode we're checking matches what the inode scan
  * told us to look at.
  */
-static bool
-xfs_scrub_fd(
+static int
+scrub_fd(
        struct scrub_ctx        *ctx,
-       bool                    (*fn)(struct scrub_ctx *ctx, uint64_t ino,
+       int                     (*fn)(struct scrub_ctx *ctx, uint64_t ino,
                                      uint32_t gen, struct xfs_action_list *a),
        struct xfs_bulkstat     *bs,
        struct xfs_action_list  *alist)
@@ -85,8 +85,8 @@ xfs_scrub_inode(
        }
 
        /* Scrub the inode. */
-       moveon = xfs_scrub_fd(ctx, xfs_scrub_inode_fields, bstat, &alist);
-       if (!moveon)
+       error = scrub_fd(ctx, xfs_scrub_inode_fields, bstat, &alist);
+       if (error)
                goto out;
 
        moveon = xfs_action_list_process_or_defer(ctx, agno, &alist);
@@ -94,14 +94,14 @@ xfs_scrub_inode(
                goto out;
 
        /* Scrub all block mappings. */
-       moveon = xfs_scrub_fd(ctx, xfs_scrub_data_fork, bstat, &alist);
-       if (!moveon)
+       error = scrub_fd(ctx, xfs_scrub_data_fork, bstat, &alist);
+       if (error)
                goto out;
-       moveon = xfs_scrub_fd(ctx, xfs_scrub_attr_fork, bstat, &alist);
-       if (!moveon)
+       error = scrub_fd(ctx, xfs_scrub_attr_fork, bstat, &alist);
+       if (error)
                goto out;
-       moveon = xfs_scrub_fd(ctx, xfs_scrub_cow_fork, bstat, &alist);
-       if (!moveon)
+       error = scrub_fd(ctx, xfs_scrub_cow_fork, bstat, &alist);
+       if (error)
                goto out;
 
        moveon = xfs_action_list_process_or_defer(ctx, agno, &alist);
@@ -110,23 +110,23 @@ xfs_scrub_inode(
 
        if (S_ISLNK(bstat->bs_mode)) {
                /* Check symlink contents. */
-               moveon = xfs_scrub_symlink(ctx, bstat->bs_ino, bstat->bs_gen,
+               error = xfs_scrub_symlink(ctx, bstat->bs_ino, bstat->bs_gen,
                                &alist);
        } else if (S_ISDIR(bstat->bs_mode)) {
                /* Check the directory entries. */
-               moveon = xfs_scrub_fd(ctx, xfs_scrub_dir, bstat, &alist);
+               error = scrub_fd(ctx, xfs_scrub_dir, bstat, &alist);
        }
-       if (!moveon)
+       if (error)
                goto out;
 
        /* Check all the extended attributes. */
-       moveon = xfs_scrub_fd(ctx, xfs_scrub_attr, bstat, &alist);
-       if (!moveon)
+       error = scrub_fd(ctx, xfs_scrub_attr, bstat, &alist);
+       if (error)
                goto out;
 
        /* Check parent pointers. */
-       moveon = xfs_scrub_fd(ctx, xfs_scrub_parent, bstat, &alist);
-       if (!moveon)
+       error = scrub_fd(ctx, xfs_scrub_parent, bstat, &alist);
+       if (error)
                goto out;
 
        /* Try to repair the file while it's open. */
@@ -135,6 +135,8 @@ xfs_scrub_inode(
                goto out;
 
 out:
+       if (error)
+               moveon = false;
        error = ptcounter_add(icount, 1);
        if (error) {
                str_liberror(ctx, error,
index a276bc329e433f924ac2d105d54adeb42287e944..a121df02ec4c6449d503b2ab22b9dbe93b0fe89f 100644 (file)
@@ -114,9 +114,9 @@ xfs_process_action_items(
 /* Fix everything that needs fixing. */
 bool
 xfs_repair_fs(
-       struct scrub_ctx                *ctx)
+       struct scrub_ctx        *ctx)
 {
-       bool                            moveon;
+       int                     ret;
 
        /*
         * Check the summary counters early.  Normally we do this during phase
@@ -124,8 +124,8 @@ xfs_repair_fs(
         * counters, so counter repairs have to be put on the list now so that
         * they get fixed before we stop retrying unfixed metadata repairs.
         */
-       moveon = xfs_scrub_fs_summary(ctx, &ctx->action_lists[0]);
-       if (!moveon)
+       ret = xfs_scrub_fs_summary(ctx, &ctx->action_lists[0]);
+       if (ret)
                return false;
 
        return xfs_process_action_items(ctx);
index e752a0c49a2b5e314150252223630a293a752977..c2cccd76817fad1baa887251c0f1671f4ee16e9f 100644 (file)
@@ -390,8 +390,8 @@ _("Filesystem has errors, skipping connectivity checks."));
                return true;
        }
 
-       moveon = xfs_scrub_fs_label(ctx);
-       if (!moveon)
+       ret = xfs_scrub_fs_label(ctx);
+       if (ret)
                return false;
 
        ret = scrub_scan_all_inodes(ctx, xfs_scrub_connections, &moveon);
index 28689eac6eef1279cb97d96401daf23f1b590733..57794d0f609f7beec001911f1f7f37be0eeb3427 100644 (file)
@@ -120,8 +120,8 @@ xfs_scan_summary(
 
        /* Check and fix the fs summary counters. */
        xfs_action_list_init(&alist);
-       moveon = xfs_scrub_fs_summary(ctx, &alist);
-       if (!moveon)
+       error = xfs_scrub_fs_summary(ctx, &alist);
+       if (error)
                return false;
        moveon = xfs_action_list_process(ctx, ctx->mnt.fd, &alist,
                        ALP_COMPLAIN_IF_UNFIXED | ALP_NOPROGRESS);
index d9df1e5b7d6ab42b8ff574807595542520147d61..2bda5054734f56e8a1e7fad77f856e9ba055b796 100644 (file)
@@ -249,7 +249,7 @@ _("Optimizations of %s are possible."), _(xfrog_scrubbers[i].descr));
 }
 
 /* Save a scrub context for later repairs. */
-static bool
+static int
 xfs_scrub_save_repair(
        struct scrub_ctx                *ctx,
        struct xfs_action_list          *alist,
@@ -260,9 +260,10 @@ xfs_scrub_save_repair(
        /* Schedule this item for later repairs. */
        aitem = malloc(sizeof(struct action_item));
        if (!aitem) {
-               str_errno(ctx, _("repair list"));
-               return false;
+               str_errno(ctx, _("adding item to repair list"));
+               return errno;
        }
+
        memset(aitem, 0, sizeof(*aitem));
        aitem->type = meta->sm_type;
        aitem->flags = meta->sm_flags;
@@ -280,10 +281,15 @@ xfs_scrub_save_repair(
        }
 
        xfs_action_list_add(alist, aitem);
-       return true;
+       return 0;
 }
 
-/* Scrub a single XFS_SCRUB_TYPE_*, saving corruption reports for later. */
+/*
+ * Scrub a single XFS_SCRUB_TYPE_*, saving corruption reports for later.
+ *
+ * Returns 0 for success.  If errors occur, this function will log them and
+ * return a positive error code.
+ */
 static int
 xfs_scrub_meta_type(
        struct scrub_ctx                *ctx,
@@ -296,6 +302,7 @@ xfs_scrub_meta_type(
                .sm_agno                = agno,
        };
        enum check_outcome              fix;
+       int                             ret;
 
        background_sleep();
 
@@ -307,8 +314,9 @@ xfs_scrub_meta_type(
        case CHECK_ABORT:
                return ECANCELED;
        case CHECK_REPAIR:
-               if (!xfs_scrub_save_repair(ctx, alist, &meta))
-                       return ENOMEM;
+               ret = xfs_scrub_save_repair(ctx, alist, &meta);
+               if (ret)
+                       return ret;
                /* fall through */
        case CHECK_DONE:
                return 0;
@@ -344,30 +352,28 @@ xfs_scrub_all_types(
 
                ret = xfs_scrub_meta_type(ctx, type, agno, alist);
                if (ret)
-                       return false;
+                       return ret;
        }
 
-       return true;
+       return 0;
 }
 
 /*
  * Scrub primary superblock.  This will be useful if we ever need to hook
  * a filesystem-wide pre-scrub activity off of the sb 0 scrubber (which
- * currently does nothing).
+ * currently does nothing).  If errors occur, this function will log them and
+ * return nonzero.
  */
-bool
+int
 xfs_scrub_primary_super(
        struct scrub_ctx                *ctx,
        struct xfs_action_list          *alist)
 {
-       int                             ret;
-
-       ret = xfs_scrub_meta_type(ctx, XFS_SCRUB_TYPE_SB, 0, alist);
-       return ret == 0;
+       return xfs_scrub_meta_type(ctx, XFS_SCRUB_TYPE_SB, 0, alist);
 }
 
 /* Scrub each AG's header blocks. */
-bool
+int
 xfs_scrub_ag_headers(
        struct scrub_ctx                *ctx,
        xfs_agnumber_t                  agno,
@@ -377,7 +383,7 @@ xfs_scrub_ag_headers(
 }
 
 /* Scrub each AG's metadata btrees. */
-bool
+int
 xfs_scrub_ag_metadata(
        struct scrub_ctx                *ctx,
        xfs_agnumber_t                  agno,
@@ -387,7 +393,7 @@ xfs_scrub_ag_metadata(
 }
 
 /* Scrub whole-FS metadata btrees. */
-bool
+int
 xfs_scrub_fs_metadata(
        struct scrub_ctx                *ctx,
        struct xfs_action_list          *alist)
@@ -396,20 +402,17 @@ xfs_scrub_fs_metadata(
 }
 
 /* Scrub FS summary metadata. */
-bool
+int
 xfs_scrub_fs_summary(
        struct scrub_ctx                *ctx,
        struct xfs_action_list          *alist)
 {
-       int                             ret;
-
-       ret = xfs_scrub_meta_type(ctx, XFS_SCRUB_TYPE_FSCOUNTERS, 0, alist);
-       return ret == 0;
+       return xfs_scrub_meta_type(ctx, XFS_SCRUB_TYPE_FSCOUNTERS, 0, alist);
 }
 
 /* How many items do we have to check? */
 unsigned int
-xfs_scrub_estimate_ag_work(
+scrub_estimate_ag_work(
        struct scrub_ctx                *ctx)
 {
        const struct xfrog_scrub_descr  *sc;
@@ -433,8 +436,11 @@ xfs_scrub_estimate_ag_work(
        return estimate;
 }
 
-/* Scrub inode metadata. */
-static bool
+/*
+ * Scrub inode metadata.  If errors occur, this function will log them and
+ * return nonzero.
+ */
+static int
 __xfs_scrub_file(
        struct scrub_ctx                *ctx,
        uint64_t                        ino,
@@ -455,14 +461,14 @@ __xfs_scrub_file(
        /* Scrub the piece of metadata. */
        fix = xfs_check_metadata(ctx, &meta, true);
        if (fix == CHECK_ABORT)
-               return false;
+               return ECANCELED;
        if (fix == CHECK_DONE)
-               return true;
+               return 0;
 
        return xfs_scrub_save_repair(ctx, alist, &meta);
 }
 
-bool
+int
 xfs_scrub_inode_fields(
        struct scrub_ctx        *ctx,
        uint64_t                ino,
@@ -472,7 +478,7 @@ xfs_scrub_inode_fields(
        return __xfs_scrub_file(ctx, ino, gen, XFS_SCRUB_TYPE_INODE, alist);
 }
 
-bool
+int
 xfs_scrub_data_fork(
        struct scrub_ctx        *ctx,
        uint64_t                ino,
@@ -482,7 +488,7 @@ xfs_scrub_data_fork(
        return __xfs_scrub_file(ctx, ino, gen, XFS_SCRUB_TYPE_BMBTD, alist);
 }
 
-bool
+int
 xfs_scrub_attr_fork(
        struct scrub_ctx        *ctx,
        uint64_t                ino,
@@ -492,7 +498,7 @@ xfs_scrub_attr_fork(
        return __xfs_scrub_file(ctx, ino, gen, XFS_SCRUB_TYPE_BMBTA, alist);
 }
 
-bool
+int
 xfs_scrub_cow_fork(
        struct scrub_ctx        *ctx,
        uint64_t                ino,
@@ -502,7 +508,7 @@ xfs_scrub_cow_fork(
        return __xfs_scrub_file(ctx, ino, gen, XFS_SCRUB_TYPE_BMBTC, alist);
 }
 
-bool
+int
 xfs_scrub_dir(
        struct scrub_ctx        *ctx,
        uint64_t                ino,
@@ -512,7 +518,7 @@ xfs_scrub_dir(
        return __xfs_scrub_file(ctx, ino, gen, XFS_SCRUB_TYPE_DIR, alist);
 }
 
-bool
+int
 xfs_scrub_attr(
        struct scrub_ctx        *ctx,
        uint64_t                ino,
@@ -522,7 +528,7 @@ xfs_scrub_attr(
        return __xfs_scrub_file(ctx, ino, gen, XFS_SCRUB_TYPE_XATTR, alist);
 }
 
-bool
+int
 xfs_scrub_symlink(
        struct scrub_ctx        *ctx,
        uint64_t                ino,
@@ -532,7 +538,7 @@ xfs_scrub_symlink(
        return __xfs_scrub_file(ctx, ino, gen, XFS_SCRUB_TYPE_SYMLINK, alist);
 }
 
-bool
+int
 xfs_scrub_parent(
        struct scrub_ctx        *ctx,
        uint64_t                ino,
@@ -542,7 +548,11 @@ xfs_scrub_parent(
        return __xfs_scrub_file(ctx, ino, gen, XFS_SCRUB_TYPE_PARENT, alist);
 }
 
-/* Test the availability of a kernel scrub command. */
+/*
+ * Test the availability of a kernel scrub command.  If errors occur (or the
+ * scrub ioctl is rejected) the errors will be logged and this function will
+ * return false.
+ */
 static bool
 __xfs_scrub_test(
        struct scrub_ctx                *ctx,
index d407abb0b147dc298e1e5b53c16fb074da9b59d4..bfb3f8e3344aa43410486917c9599b4a74cacd98 100644 (file)
@@ -17,15 +17,15 @@ enum check_outcome {
 struct action_item;
 
 void xfs_scrub_report_preen_triggers(struct scrub_ctx *ctx);
-bool xfs_scrub_primary_super(struct scrub_ctx *ctx,
+int xfs_scrub_primary_super(struct scrub_ctx *ctx,
                struct xfs_action_list *alist);
-bool xfs_scrub_ag_headers(struct scrub_ctx *ctx, xfs_agnumber_t agno,
+int xfs_scrub_ag_headers(struct scrub_ctx *ctx, xfs_agnumber_t agno,
                struct xfs_action_list *alist);
-bool xfs_scrub_ag_metadata(struct scrub_ctx *ctx, xfs_agnumber_t agno,
+int xfs_scrub_ag_metadata(struct scrub_ctx *ctx, xfs_agnumber_t agno,
                struct xfs_action_list *alist);
-bool xfs_scrub_fs_metadata(struct scrub_ctx *ctx,
+int xfs_scrub_fs_metadata(struct scrub_ctx *ctx,
                struct xfs_action_list *alist);
-bool xfs_scrub_fs_summary(struct scrub_ctx *ctx,
+int xfs_scrub_fs_summary(struct scrub_ctx *ctx,
                struct xfs_action_list *alist);
 
 bool xfs_can_scrub_fs_metadata(struct scrub_ctx *ctx);
@@ -37,21 +37,21 @@ bool xfs_can_scrub_symlink(struct scrub_ctx *ctx);
 bool xfs_can_scrub_parent(struct scrub_ctx *ctx);
 bool xfs_can_repair(struct scrub_ctx *ctx);
 
-bool xfs_scrub_inode_fields(struct scrub_ctx *ctx, uint64_t ino, uint32_t gen,
+int xfs_scrub_inode_fields(struct scrub_ctx *ctx, uint64_t ino, uint32_t gen,
                struct xfs_action_list *alist);
-bool xfs_scrub_data_fork(struct scrub_ctx *ctx, uint64_t ino, uint32_t gen,
+int xfs_scrub_data_fork(struct scrub_ctx *ctx, uint64_t ino, uint32_t gen,
                struct xfs_action_list *alist);
-bool xfs_scrub_attr_fork(struct scrub_ctx *ctx, uint64_t ino, uint32_t gen,
+int xfs_scrub_attr_fork(struct scrub_ctx *ctx, uint64_t ino, uint32_t gen,
                struct xfs_action_list *alist);
-bool xfs_scrub_cow_fork(struct scrub_ctx *ctx, uint64_t ino, uint32_t gen,
+int xfs_scrub_cow_fork(struct scrub_ctx *ctx, uint64_t ino, uint32_t gen,
                struct xfs_action_list *alist);
-bool xfs_scrub_dir(struct scrub_ctx *ctx, uint64_t ino, uint32_t gen,
+int xfs_scrub_dir(struct scrub_ctx *ctx, uint64_t ino, uint32_t gen,
                struct xfs_action_list *alist);
-bool xfs_scrub_attr(struct scrub_ctx *ctx, uint64_t ino, uint32_t gen,
+int xfs_scrub_attr(struct scrub_ctx *ctx, uint64_t ino, uint32_t gen,
                struct xfs_action_list *alist);
-bool xfs_scrub_symlink(struct scrub_ctx *ctx, uint64_t ino, uint32_t gen,
+int xfs_scrub_symlink(struct scrub_ctx *ctx, uint64_t ino, uint32_t gen,
                struct xfs_action_list *alist);
-bool xfs_scrub_parent(struct scrub_ctx *ctx, uint64_t ino, uint32_t gen,
+int xfs_scrub_parent(struct scrub_ctx *ctx, uint64_t ino, uint32_t gen,
                struct xfs_action_list *alist);
 
 /* Repair parameters are the scrub inputs and retry count. */
index 61831c92fad0825906f6c6be4d735b6b3b355d6f..9207974823f05fef41412355f1c7b8a7c53226f8 100644 (file)
@@ -98,7 +98,7 @@ bool xfs_repair_fs(struct scrub_ctx *ctx);
 
 /* Progress estimator functions */
 uint64_t xfs_estimate_inodes(struct scrub_ctx *ctx);
-unsigned int xfs_scrub_estimate_ag_work(struct scrub_ctx *ctx);
+unsigned int scrub_estimate_ag_work(struct scrub_ctx *ctx);
 bool xfs_estimate_metadata_work(struct scrub_ctx *ctx, uint64_t *items,
                                unsigned int *nr_threads, int *rshift);
 bool xfs_estimate_inodes_work(struct scrub_ctx *ctx, uint64_t *items,