]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blobdiff - scrub/phase1.c
xfs_scrub: use datadev parallelization estimates for thread count
[thirdparty/xfsprogs-dev.git] / scrub / phase1.c
index 547767b811ea1cfca9a972ec1494e01e5f78ca22..6b472147f866386f17acb039ff4f25d6bae0d9eb 100644 (file)
@@ -1,52 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (C) 2018 Oracle.  All Rights Reserved.
- *
  * Author: Darrick J. Wong <darrick.wong@oracle.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software Foundation,
- * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
  */
-#include <stdio.h>
-#include <mntent.h>
+#include "xfs.h"
 #include <unistd.h>
 #include <sys/types.h>
-#include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/resource.h>
 #include <sys/statvfs.h>
-#include <sys/vfs.h>
 #include <fcntl.h>
 #include <dirent.h>
 #include <stdint.h>
-#include <stdbool.h>
 #include <pthread.h>
-#include <errno.h>
-#include <linux/fs.h>
 #include "libfrog.h"
 #include "workqueue.h"
 #include "input.h"
 #include "path.h"
 #include "handle.h"
 #include "bitops.h"
-#include "xfs_arch.h"
-#include "xfs_format.h"
 #include "avl64.h"
 #include "list.h"
 #include "xfs_scrub.h"
 #include "common.h"
 #include "disk.h"
 #include "scrub.h"
+#include "repair.h"
 
 /* Phase 1: Find filesystem geometry (and clean up after) */
 
@@ -68,6 +47,9 @@ bool
 xfs_cleanup_fs(
        struct scrub_ctx        *ctx)
 {
+       int                     error;
+
+       xfs_action_lists_free(&ctx->action_lists);
        if (ctx->fshandle)
                free_handle(ctx->fshandle, ctx->fshandle_len);
        if (ctx->rtdev)
@@ -77,7 +59,9 @@ xfs_cleanup_fs(
        if (ctx->datadev)
                disk_close(ctx->datadev);
        fshandle_destroy();
-       close(ctx->mnt_fd);
+       error = close(ctx->mnt_fd);
+       if (error)
+               str_errno(ctx, _("closing mountpoint fd"));
        fs_table_destroy();
 
        return true;
@@ -91,7 +75,6 @@ bool
 xfs_setup_fs(
        struct scrub_ctx                *ctx)
 {
-       struct fs_path                  *fsp;
        int                             error;
 
        /*
@@ -126,15 +109,8 @@ _("Must be root to run scrub."));
                return false;
        }
 
-       ctx->nr_io_threads = nproc;
-       if (verbose) {
-               fprintf(stdout, _("%s: using %d threads to scrub.\n"),
-                               ctx->mntpoint, scrub_nproc(ctx));
-               fflush(stdout);
-       }
-
        if (!platform_test_xfs_fd(ctx->mnt_fd)) {
-               str_error(ctx, ctx->mntpoint,
+               str_info(ctx, ctx->mntpoint,
 _("Does not appear to be an XFS filesystem!"));
                return false;
        }
@@ -157,6 +133,11 @@ _("Does not appear to be an XFS filesystem!"));
                return false;
        }
 
+       if (!xfs_action_lists_alloc(ctx->geo.agcount, &ctx->action_lists)) {
+               str_error(ctx, ctx->mntpoint, _("Not enough memory."));
+               return false;
+       }
+
        ctx->agblklog = log2_roundup(ctx->geo.agblocks);
        ctx->blocklog = highbit32(ctx->geo.blocksize);
        ctx->inodelog = highbit32(ctx->geo.inodesize);
@@ -174,41 +155,26 @@ _("Does not appear to be an XFS filesystem!"));
            !xfs_can_scrub_bmap(ctx) || !xfs_can_scrub_dir(ctx) ||
            !xfs_can_scrub_attr(ctx) || !xfs_can_scrub_symlink(ctx) ||
            !xfs_can_scrub_parent(ctx)) {
-               str_error(ctx, ctx->mntpoint,
-_("Kernel metadata scrubbing facility is required."));
+               str_info(ctx, ctx->mntpoint,
+_("Kernel metadata scrubbing facility is not available."));
                return false;
        }
 
        /* Do we need kernel-assisted metadata repair? */
        if (ctx->mode != SCRUB_MODE_DRY_RUN && !xfs_can_repair(ctx)) {
-               if (ctx->mode == SCRUB_MODE_PREEN)
-                       str_error(ctx, ctx->mntpoint,
-_("Kernel metadata optimization facility is required."));
-               else
-                       str_error(ctx, ctx->mntpoint,
-_("Kernel metadata repair facility is required."));
+               str_info(ctx, ctx->mntpoint,
+_("Kernel metadata repair facility is not available.  Use -n to scrub."));
                return false;
        }
 
-       /* Go find the XFS devices if we have a usable fsmap. */
-       fs_table_initialise(0, NULL, 0, NULL);
-       errno = 0;
-       fsp = fs_table_lookup(ctx->mntpoint, FS_MOUNT_POINT);
-       if (!fsp) {
-               str_error(ctx, ctx->mntpoint,
-_("Unable to find XFS information."));
-               return false;
-       }
-       memcpy(&ctx->fsinfo, fsp, sizeof(struct fs_path));
-
        /* Did we find the log and rt devices, if they're present? */
        if (ctx->geo.logstart == 0 && ctx->fsinfo.fs_log == NULL) {
-               str_error(ctx, ctx->mntpoint,
+               str_info(ctx, ctx->mntpoint,
 _("Unable to find log device path."));
                return false;
        }
        if (ctx->geo.rtblocks && ctx->fsinfo.fs_rt == NULL) {
-               str_error(ctx, ctx->mntpoint,
+               str_info(ctx, ctx->mntpoint,
 _("Unable to find realtime device path."));
                return false;
        }
@@ -220,6 +186,13 @@ _("Unable to find realtime device path."));
                return false;
        }
 
+       ctx->nr_io_threads = disk_heads(ctx->datadev);
+       if (verbose) {
+               fprintf(stdout, _("%s: using %d threads to scrub.\n"),
+                               ctx->mntpoint, scrub_nproc(ctx));
+               fflush(stdout);
+       }
+
        if (ctx->fsinfo.fs_log) {
                ctx->logdev = disk_open(ctx->fsinfo.fs_log);
                if (error) {
@@ -240,6 +213,7 @@ _("Unable to find realtime device path."));
         * this point are most probably corruption errors (as opposed to
         * purely setup errors).
         */
-       ctx->need_repair = true;
+       log_info(ctx, _("Invoking online scrub."), ctx);
+       ctx->scrub_setup_succeeded = true;
        return true;
 }