]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_scrub: refactor mountpoint finding code to use libfrog path code
authorDarrick J. Wong <darrick.wong@oracle.com>
Thu, 12 Apr 2018 15:34:11 +0000 (10:34 -0500)
committerEric Sandeen <sandeen@redhat.com>
Thu, 12 Apr 2018 15:34:11 +0000 (10:34 -0500)
Use the libfrog path finding code to determine if the argument being
passed in is a mountpoint, remove all mention of taking a block device
(we have never supported that) from the documentation, and fix some
potential memory leaks.

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>
man/man8/xfs_scrub.8
scrub/common.c
scrub/common.h
scrub/phase1.c
scrub/xfs_scrub.c
scrub/xfs_scrub.h

index 77fed92996ff6be99e7aa6eae9b919614846af17..680ef72b4442067616817afa61e2d555152270ed 100644 (file)
@@ -6,7 +6,7 @@ xfs_scrub \- check the contents of a mounted XFS filesystem
 [
 .B \-abCemnTvx
 ]
-.RI "[" mount-point " | " block-device "]"
+.I mount-point
 .br
 .B xfs_scrub \-V
 .SH DESCRIPTION
index 5248b270378410dfe6c802afa13134fc80f43b86..bbf97bf49f9df50afc93a5b4e17f9c8405ce6561 100644 (file)
@@ -263,75 +263,6 @@ scrub_nproc_workqueue(
        return x;
 }
 
-/*
- * Check if the argument is either the device name or mountpoint of a mounted
- * filesystem.
- */
-#define MNTTYPE_XFS    "xfs"
-static bool
-find_mountpoint_check(
-       struct stat             *sb,
-       struct mntent           *t)
-{
-       struct stat             ms;
-
-       if (S_ISDIR(sb->st_mode)) {             /* mount point */
-               if (stat(t->mnt_dir, &ms) < 0)
-                       return false;
-               if (sb->st_ino != ms.st_ino)
-                       return false;
-               if (sb->st_dev != ms.st_dev)
-                       return false;
-               if (strcmp(t->mnt_type, MNTTYPE_XFS) != 0)
-                       return NULL;
-       } else {                                /* device */
-               if (stat(t->mnt_fsname, &ms) < 0)
-                       return false;
-               if (sb->st_rdev != ms.st_rdev)
-                       return false;
-               if (strcmp(t->mnt_type, MNTTYPE_XFS) != 0)
-                       return NULL;
-               /*
-                * Make sure the mountpoint given by mtab is accessible
-                * before using it.
-                */
-               if (stat(t->mnt_dir, &ms) < 0)
-                       return false;
-       }
-
-       return true;
-}
-
-/* Check that our alleged mountpoint is in mtab */
-bool
-find_mountpoint(
-       char                    *mtab,
-       struct scrub_ctx        *ctx)
-{
-       struct mntent_cursor    cursor;
-       struct mntent           *t = NULL;
-       bool                    found = false;
-
-       if (platform_mntent_open(&cursor, mtab) != 0) {
-               fprintf(stderr, "Error: can't get mntent entries.\n");
-               exit(1);
-       }
-
-       while ((t = platform_mntent_next(&cursor)) != NULL) {
-               /*
-                * Keep jotting down matching mount details; newer mounts are
-                * towards the end of the file (hopefully).
-                */
-               if (find_mountpoint_check(&ctx->mnt_sb, t)) {
-                       ctx->mntpoint = strdup(t->mnt_dir);
-                       ctx->blkdev = strdup(t->mnt_fsname);
-                       found = true;
-               }
-       }
-       platform_mntent_close(&cursor);
-       return found;
-}
-
 /*
  * Sleep for 100ms * however many -b we got past the initial one.
  * This is an (albeit clumsy) way to throttle scrub activity.
index 4f1f0cd627a1e7f77b4c4379e82a784c4d8139fd..bc83971ae1693ebf912ceba71795d4b9f9e06782 100644 (file)
@@ -88,7 +88,6 @@ static inline int syncfs(int fd)
 }
 #endif
 
-bool find_mountpoint(char *mtab, struct scrub_ctx *ctx);
 void background_sleep(void);
 char *string_escape(const char *in);
 
index 992677097d52f216d8379d403073f72807a7814d..c2b9067aaa8475d24700b7574cd428b9eaaa17bd 100644 (file)
@@ -83,7 +83,6 @@ bool
 xfs_setup_fs(
        struct scrub_ctx                *ctx)
 {
-       struct fs_path                  *fsp;
        int                             error;
 
        /*
@@ -178,17 +177,6 @@ _("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_info(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_info(ctx, ctx->mntpoint,
index e3f4eac1c829f60c6c6302e0d2efd91a9fcc3321..8f54f92a764a86b6bccad9ad3605eed4d3603b66 100644 (file)
@@ -171,7 +171,7 @@ bool                                is_service;
 static void __attribute__((noreturn))
 usage(void)
 {
-       fprintf(stderr, _("Usage: %s [OPTIONS] mountpoint | device\n"), progname);
+       fprintf(stderr, _("Usage: %s [OPTIONS] mountpoint\n"), progname);
        fprintf(stderr, "\n");
        fprintf(stderr, _("Options:\n"));
        fprintf(stderr, _("  -a count     Stop after this many errors are found.\n"));
@@ -539,8 +539,8 @@ main(
        struct phase_rusage     all_pi;
        char                    *mtab = NULL;
        FILE                    *progress_fp = NULL;
+       struct fs_path          *fsp;
        bool                    moveon = true;
-       bool                    ismnt;
        int                     c;
        int                     fd;
        int                     ret = SCRUB_RET_SUCCESS;
@@ -641,7 +641,7 @@ main(
        if (optind != argc - 1)
                usage();
 
-       ctx.mntpoint = strdup(argv[optind]);
+       ctx.mntpoint = argv[optind];
 
        stdout_isatty = isatty(STDOUT_FILENO);
        stderr_isatty = isatty(STDERR_FILENO);
@@ -681,14 +681,15 @@ main(
                        mtab = _PATH_MOUNTED;
        }
 
-       ismnt = find_mountpoint(mtab, &ctx);
-       if (!ismnt) {
-               fprintf(stderr,
-_("%s: Not a XFS mount point or block device.\n"),
-                       ctx.mntpoint);
+       fs_table_initialise(0, NULL, 0, NULL);
+       fsp = fs_table_lookup_mount(ctx.mntpoint);
+       if (!fsp) {
+               fprintf(stderr, _("%s: Not a XFS mount point.\n"),
+                               ctx.mntpoint);
                ret |= SCRUB_RET_SYNTAX;
                goto out;
        }
+       memcpy(&ctx.fsinfo, fsp, sizeof(struct fs_path));
 
        /* How many CPUs? */
        nproc = sysconf(_SC_NPROCESSORS_ONLN);
@@ -741,8 +742,6 @@ out:
        phase_end(&all_pi, 0);
        if (progress_fp)
                fclose(progress_fp);
-       free(ctx.blkdev);
-       free(ctx.mntpoint);
 
        /*
         * If we're being run as a service, the return code must fit the LSB
index aa130a73f2dcd91c3c0b9048dd0c836ca9e9caf6..c9dbe8e033d711f63157862ae7c5d85a183bc97b 100644 (file)
@@ -48,7 +48,6 @@ struct scrub_ctx {
 
        /* Strings we need for presentation */
        char                    *mntpoint;
-       char                    *blkdev;
 
        /* Mountpoint info */
        struct stat             mnt_sb;