From: "Darrick J. Wong" <djwong@kernel.org>
To: djwong@kernel.org, cem@kernel.org
Cc: linux-xfs@vger.kernel.org
Subject: [PATCH 2/4] xfs_io: collapse trivial helpers
Date: Wed, 20 Dec 2023 09:14:48 -0800 [thread overview]
Message-ID: <170309219107.1608142.4643674100831010643.stgit@frogsfrogsfrogs> (raw)
In-Reply-To: <170309219080.1608142.737701463093437769.stgit@frogsfrogsfrogs>
From: Darrick J. Wong <djwong@kernel.org>
Simply the call chain by having parse_args set the scrub ioctl
parameters in the caller's object. The parse_args callers can then
invoke the ioctl directly, eliminating one function and one indirect
call.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
io/scrub.c | 124 +++++++++++++++++++-----------------------------------------
1 file changed, 40 insertions(+), 84 deletions(-)
diff --git a/io/scrub.c b/io/scrub.c
index 8b3bdd77..238d9240 100644
--- a/io/scrub.c
+++ b/io/scrub.c
@@ -41,57 +41,12 @@ scrub_help(void)
printf("\n");
}
-static void
-scrub_ioctl(
- int fd,
- int type,
- uint64_t control,
- uint32_t control2)
-{
- struct xfs_scrub_metadata meta;
- const struct xfrog_scrub_descr *sc;
- int error;
-
- sc = &xfrog_scrubbers[type];
- memset(&meta, 0, sizeof(meta));
- meta.sm_type = type;
- switch (sc->type) {
- case XFROG_SCRUB_TYPE_AGHEADER:
- case XFROG_SCRUB_TYPE_PERAG:
- meta.sm_agno = control;
- break;
- case XFROG_SCRUB_TYPE_INODE:
- meta.sm_ino = control;
- meta.sm_gen = control2;
- break;
- case XFROG_SCRUB_TYPE_NONE:
- case XFROG_SCRUB_TYPE_FS:
- /* no control parameters */
- break;
- }
- meta.sm_flags = 0;
-
- error = ioctl(fd, XFS_IOC_SCRUB_METADATA, &meta);
- if (error)
- perror("scrub");
- if (meta.sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
- printf(_("Corruption detected.\n"));
- if (meta.sm_flags & XFS_SCRUB_OFLAG_PREEN)
- printf(_("Optimization possible.\n"));
- if (meta.sm_flags & XFS_SCRUB_OFLAG_XFAIL)
- printf(_("Cross-referencing failed.\n"));
- if (meta.sm_flags & XFS_SCRUB_OFLAG_XCORRUPT)
- printf(_("Corruption detected during cross-referencing.\n"));
- if (meta.sm_flags & XFS_SCRUB_OFLAG_INCOMPLETE)
- printf(_("Scan was not complete.\n"));
-}
-
static int
parse_args(
int argc,
char **argv,
- struct cmdinfo *cmdinfo,
- void (*fn)(int, int, uint64_t, uint32_t))
+ const struct cmdinfo *cmdinfo,
+ struct xfs_scrub_metadata *meta)
{
char *p;
int type = -1;
@@ -100,6 +55,7 @@ parse_args(
uint32_t control2 = 0;
const struct xfrog_scrub_descr *d = NULL;
+ memset(meta, 0, sizeof(struct xfs_scrub_metadata));
while ((c = getopt(argc, argv, "")) != EOF) {
switch (c) {
default:
@@ -125,6 +81,8 @@ parse_args(
}
optind++;
+ meta->sm_type = type;
+
switch (d->type) {
case XFROG_SCRUB_TYPE_INODE:
if (optind == argc) {
@@ -153,6 +111,8 @@ parse_args(
exitcode = 1;
return command_usage(cmdinfo);
}
+ meta->sm_ino = control;
+ meta->sm_gen = control2;
break;
case XFROG_SCRUB_TYPE_AGHEADER:
case XFROG_SCRUB_TYPE_PERAG:
@@ -169,6 +129,7 @@ parse_args(
exitcode = 1;
return command_usage(cmdinfo);
}
+ meta->sm_agno = control;
break;
case XFROG_SCRUB_TYPE_FS:
case XFROG_SCRUB_TYPE_NONE:
@@ -178,13 +139,12 @@ parse_args(
exitcode = 1;
return command_usage(cmdinfo);
}
+ /* no control parameters */
break;
default:
ASSERT(0);
break;
}
- fn(file->fd, type, control, control2);
-
return 0;
}
@@ -193,7 +153,27 @@ scrub_f(
int argc,
char **argv)
{
- return parse_args(argc, argv, &scrub_cmd, scrub_ioctl);
+ struct xfs_scrub_metadata meta;
+ int error;
+
+ error = parse_args(argc, argv, &scrub_cmd, &meta);
+ if (error)
+ return error;
+
+ error = ioctl(file->fd, XFS_IOC_SCRUB_METADATA, &meta);
+ if (error)
+ perror("scrub");
+ if (meta.sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
+ printf(_("Corruption detected.\n"));
+ if (meta.sm_flags & XFS_SCRUB_OFLAG_PREEN)
+ printf(_("Optimization possible.\n"));
+ if (meta.sm_flags & XFS_SCRUB_OFLAG_XFAIL)
+ printf(_("Cross-referencing failed.\n"));
+ if (meta.sm_flags & XFS_SCRUB_OFLAG_XCORRUPT)
+ printf(_("Corruption detected during cross-referencing.\n"));
+ if (meta.sm_flags & XFS_SCRUB_OFLAG_INCOMPLETE)
+ printf(_("Scan was not complete.\n"));
+ return 0;
}
void
@@ -236,37 +216,20 @@ repair_help(void)
printf("\n");
}
-static void
-repair_ioctl(
- int fd,
- int type,
- uint64_t control,
- uint32_t control2)
+static int
+repair_f(
+ int argc,
+ char **argv)
{
struct xfs_scrub_metadata meta;
- const struct xfrog_scrub_descr *sc;
int error;
- sc = &xfrog_scrubbers[type];
- memset(&meta, 0, sizeof(meta));
- meta.sm_type = type;
- switch (sc->type) {
- case XFROG_SCRUB_TYPE_AGHEADER:
- case XFROG_SCRUB_TYPE_PERAG:
- meta.sm_agno = control;
- break;
- case XFROG_SCRUB_TYPE_INODE:
- meta.sm_ino = control;
- meta.sm_gen = control2;
- break;
- case XFROG_SCRUB_TYPE_NONE:
- case XFROG_SCRUB_TYPE_FS:
- /* no control parameters */
- break;
- }
- meta.sm_flags = XFS_SCRUB_IFLAG_REPAIR;
+ error = parse_args(argc, argv, &repair_cmd, &meta);
+ if (error)
+ return error;
+ meta.sm_flags |= XFS_SCRUB_IFLAG_REPAIR;
- error = ioctl(fd, XFS_IOC_SCRUB_METADATA, &meta);
+ error = ioctl(file->fd, XFS_IOC_SCRUB_METADATA, &meta);
if (error)
perror("repair");
if (meta.sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
@@ -281,14 +244,7 @@ repair_ioctl(
printf(_("Repair was not complete.\n"));
if (meta.sm_flags & XFS_SCRUB_OFLAG_NO_REPAIR_NEEDED)
printf(_("Metadata did not need repair or optimization.\n"));
-}
-
-static int
-repair_f(
- int argc,
- char **argv)
-{
- return parse_args(argc, argv, &repair_cmd, repair_ioctl);
+ return 0;
}
void
next prev parent reply other threads:[~2023-12-20 17:14 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-20 17:06 [PATCHBOMB] xfsprogs: pending changes for 6.6 Darrick J. Wong
2023-12-20 17:10 ` [PATCHSET 1/4] xfsprogs: various bug fixes " Darrick J. Wong
2023-12-20 17:11 ` [PATCH 1/5] libfrog: move 64-bit division wrappers to libfrog Darrick J. Wong
2023-12-20 17:11 ` [PATCH 2/5] libxfs: don't UAF a requeued EFI Darrick J. Wong
2023-12-20 17:12 ` [PATCH 3/5] xfs_copy: distinguish short writes to EOD from runtime errors Darrick J. Wong
2023-12-21 5:29 ` Christoph Hellwig
2023-12-20 17:12 ` [PATCH 4/5] xfs_copy: actually do directio writes to block devices Darrick J. Wong
2023-12-21 5:30 ` Christoph Hellwig
2023-12-20 17:12 ` [PATCH 5/5] xfs_db: report the device associated with each io cursor Darrick J. Wong
2023-12-21 5:30 ` Christoph Hellwig
2023-12-20 17:10 ` [PATCHSET 2/4] xfs_metadump: various bug fixes Darrick J. Wong
2023-12-20 17:12 ` [PATCH 1/6] xfs_metadump.8: update for external log device options Darrick J. Wong
2023-12-20 17:13 ` [PATCH 2/6] xfs_mdrestore: fix uninitialized variables in mdrestore main Darrick J. Wong
2023-12-20 17:13 ` [PATCH 3/6] xfs_mdrestore: emit newlines for fatal errors Darrick J. Wong
2023-12-20 17:13 ` [PATCH 4/6] xfs_mdrestore: EXTERNALLOG is a compat value, not incompat Darrick J. Wong
2023-12-20 17:14 ` [PATCH 5/6] xfs_mdrestore: fix missed progress reporting Darrick J. Wong
2023-12-20 17:14 ` [PATCH 6/6] xfs_mdrestore: refactor progress printing and sb fixup code Darrick J. Wong
2023-12-21 5:32 ` Christoph Hellwig
2023-12-20 17:11 ` [PATCHSET v28.3 3/4] xfs_io: clean up scrub subcommand code Darrick J. Wong
2023-12-20 17:14 ` [PATCH 1/4] xfs_io: set exitcode = 1 on parsing errors in scrub/repair command Darrick J. Wong
2023-12-21 5:32 ` Christoph Hellwig
2023-12-20 17:14 ` Darrick J. Wong [this message]
2023-12-21 5:48 ` [PATCH 2/4] xfs_io: collapse trivial helpers Christoph Hellwig
2023-12-20 17:15 ` [PATCH 3/4] xfs_io: extract contorl number parsing routines Darrick J. Wong
2023-12-21 5:49 ` Christoph Hellwig
2023-12-21 5:50 ` Christoph Hellwig
2023-12-20 17:15 ` [PATCH 4/4] xfs_io: support passing the FORCE_REBUILD flag to online repair Darrick J. Wong
2023-12-20 17:11 ` [PATCHSET v28.3 4/4] xfsprogs: force rebuilding of metadata Darrick J. Wong
2023-12-20 17:15 ` [PATCH 1/3] xfs_scrub: handle spurious wakeups in scan_fs_tree Darrick J. Wong
2023-12-20 17:15 ` [PATCH 2/3] xfs_scrub: don't retry unsupported optimizations Darrick J. Wong
2023-12-20 17:16 ` [PATCH 3/3] xfs_scrub: try to use XFS_SCRUB_IFLAG_FORCE_REBUILD Darrick J. Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=170309219107.1608142.4643674100831010643.stgit@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=cem@kernel.org \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox