aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarrick J. Wong <darrick.wong@oracle.com>2018-04-12 10:34:11 -0500
committerEric Sandeen <sandeen@redhat.com>2018-04-12 10:34:11 -0500
commit680eacaa3bcb6559d3381e6f1e6abf4603b55040 (patch)
treeef43dc2867ac064ef3b2c10b648c66285877049e
parent5fa5a86026ad3c0b38d254b467d739dbb31e7d73 (diff)
downloadxfsprogs-dev-680eacaa3bcb6559d3381e6f1e6abf4603b55040.tar.gz
xfs_scrub: refactor mountpoint finding code to use libfrog path code
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>
-rw-r--r--man/man8/xfs_scrub.82
-rw-r--r--scrub/common.c69
-rw-r--r--scrub/common.h1
-rw-r--r--scrub/phase1.c12
-rw-r--r--scrub/xfs_scrub.c19
-rw-r--r--scrub/xfs_scrub.h1
6 files changed, 10 insertions, 94 deletions
diff --git a/man/man8/xfs_scrub.8 b/man/man8/xfs_scrub.8
index 77fed92996..680ef72b44 100644
--- a/man/man8/xfs_scrub.8
+++ b/man/man8/xfs_scrub.8
@@ -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
diff --git a/scrub/common.c b/scrub/common.c
index 5248b27037..bbf97bf49f 100644
--- a/scrub/common.c
+++ b/scrub/common.c
@@ -264,75 +264,6 @@ scrub_nproc_workqueue(
}
/*
- * 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.
*/
diff --git a/scrub/common.h b/scrub/common.h
index 4f1f0cd627..bc83971ae1 100644
--- a/scrub/common.h
+++ b/scrub/common.h
@@ -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);
diff --git a/scrub/phase1.c b/scrub/phase1.c
index 992677097d..c2b9067aaa 100644
--- a/scrub/phase1.c
+++ b/scrub/phase1.c
@@ -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,
diff --git a/scrub/xfs_scrub.c b/scrub/xfs_scrub.c
index e3f4eac1c8..8f54f92a76 100644
--- a/scrub/xfs_scrub.c
+++ b/scrub/xfs_scrub.c
@@ -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
diff --git a/scrub/xfs_scrub.h b/scrub/xfs_scrub.h
index aa130a73f2..c9dbe8e033 100644
--- a/scrub/xfs_scrub.h
+++ b/scrub/xfs_scrub.h
@@ -48,7 +48,6 @@ struct scrub_ctx {
/* Strings we need for presentation */
char *mntpoint;
- char *blkdev;
/* Mountpoint info */
struct stat mnt_sb;