From: Dave Chinner <david@fromorbit.com>
To: linux-xfs@vger.kernel.org
Subject: [PATCH 2/6] libxcmd: rename args_command to command_iterator
Date: Fri, 16 Dec 2016 15:41:11 +1100 [thread overview]
Message-ID: <20161216044115.21287-3-david@fromorbit.com> (raw)
In-Reply-To: <20161216044115.21287-1-david@fromorbit.com>
From: Dave Chinner <dchinner@redhat.com>
It is not particularly easy to understand the function of the
args_command abstraction. it's actually a command iterator interface
that allows callers to specify the target of the command and iterate
the command multiple times over different targets. Rename and
document the abstraction to make this functionality clear.
Signed-Off-By: Dave Chinner <dchinner@redhat.com>
---
include/command.h | 4 ++--
io/init.c | 9 +++++++--
libxcmd/command.c | 16 ++++++++--------
quota/init.c | 9 +++++++--
4 files changed, 24 insertions(+), 14 deletions(-)
diff --git a/include/command.h b/include/command.h
index 58bfcaac44a0..637ee06e6e9a 100644
--- a/include/command.h
+++ b/include/command.h
@@ -50,12 +50,12 @@ extern int ncmds;
extern void help_init(void);
extern void quit_init(void);
-typedef int (*argsfunc_t)(int index);
+typedef int (*iterfunc_t)(int index);
typedef int (*checkfunc_t)(const cmdinfo_t *ci);
extern void add_command(const cmdinfo_t *ci);
extern void add_user_command(char *optarg);
-extern void add_args_command(argsfunc_t af);
+extern void add_command_iterator(iterfunc_t func);
extern void add_check_command(checkfunc_t cf);
extern const cmdinfo_t *find_command(const char *cmd);
diff --git a/io/init.c b/io/init.c
index ab40f3745390..34009b024833 100644
--- a/io/init.c
+++ b/io/init.c
@@ -90,8 +90,13 @@ init_commands(void)
cowextsize_init();
}
+/*
+ * This allows xfs_io commands specified on the command line to be run on every
+ * open file in the file table. Commands that should not be iterated across all
+ * open files need to specify CMD_FLAG_ONESHOT in their command flags.
+ */
static int
-init_args_command(
+filetable_iterator(
int index)
{
if (index >= filecount)
@@ -214,7 +219,7 @@ init(
}
init_commands();
- add_args_command(init_args_command);
+ add_command_iterator(filetable_iterator);
add_check_command(init_check_command);
}
diff --git a/libxcmd/command.c b/libxcmd/command.c
index dce8361ce3ea..789aeb5c5e5a 100644
--- a/libxcmd/command.c
+++ b/libxcmd/command.c
@@ -23,7 +23,7 @@
cmdinfo_t *cmdtab;
int ncmds;
-static argsfunc_t args_func;
+static iterfunc_t iter_func;
static checkfunc_t check_func;
static int ncmdline;
static char **cmdline;
@@ -130,7 +130,7 @@ add_user_command(char *optarg)
* so we abort straight away.
*/
static int
-args_command(
+iterate_command(
const cmdinfo_t *ct,
int index)
{
@@ -138,16 +138,16 @@ args_command(
return 0;
if (ct->flags & CMD_FLAG_ONESHOT)
return -1;
- if (args_func)
- return args_func(index);
+ if (iter_func)
+ return iter_func(index);
return 0;
}
void
-add_args_command(
- argsfunc_t af)
+add_command_iterator(
+ iterfunc_t func)
{
- args_func = af;
+ iter_func = func;
}
void
@@ -171,7 +171,7 @@ command_loop(void)
ct = find_command(v[0]);
if (ct) {
j = 0;
- while (!done && (j = args_command(ct, j)))
+ while (!done && (j = iterate_command(ct, j)))
done = command(ct, c, v);
} else
fprintf(stderr, _("command \"%s\" not found\n"),
diff --git a/quota/init.c b/quota/init.c
index 3bebbb8735f3..193f6421fd59 100644
--- a/quota/init.c
+++ b/quota/init.c
@@ -75,8 +75,13 @@ init_commands(void)
state_init();
}
+/*
+ * This function allows xfs_quota commands to iterate across all discovered
+ * quota enabled filesystems. Commands that should not iterate all filesystems
+ * should specify CMD_FLAG_ONESHOT in their command flags.
+ */
static int
-init_args_command(
+filesystem_iterator(
int index)
{
if (index >= fs_count)
@@ -189,7 +194,7 @@ init(
free(projopts);
init_commands();
- add_args_command(init_args_command);
+ add_command_iterator(filesystem_iterator);
add_check_command(init_check_command);
/*
--
2.10.2
next prev parent reply other threads:[~2016-12-16 4:45 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-16 4:41 [PATCH v2 0/6] xfs_io: fix up command iteration Dave Chinner
2016-12-16 4:41 ` [PATCH 1/6] libxcmd: check CMD_FLAG_GLOBAL inside args_command() Dave Chinner
2016-12-20 8:26 ` Christoph Hellwig
2016-12-16 4:41 ` Dave Chinner [this message]
2016-12-20 8:27 ` [PATCH 2/6] libxcmd: rename args_command to command_iterator Christoph Hellwig
2016-12-16 4:41 ` [PATCH 3/6] libxcmd: merge command() and iterate_command() Dave Chinner
2016-12-20 8:31 ` Christoph Hellwig
2016-12-20 20:11 ` Eric Sandeen
2016-12-21 9:38 ` Christoph Hellwig
2016-12-16 4:41 ` [PATCH 4/6] libxcmd: don't check generic library commands Dave Chinner
2016-12-20 8:34 ` Christoph Hellwig
2016-12-16 4:41 ` [PATCH 5/6] xfs_io: make various commands one-shot only Dave Chinner
2016-12-20 8:44 ` Christoph Hellwig
2016-12-16 4:41 ` [PATCH 6/6] libxcmd: add non-iterating user commands Dave Chinner
2016-12-16 6:39 ` Amir Goldstein
-- strict thread matches above, loose matches on Subject: below --
2016-12-07 3:47 [PATCH 0/6] xfs_io: fix up command iteration Dave Chinner
2016-12-07 3:47 ` [PATCH 2/6] libxcmd: rename args_command to command_iterator Dave Chinner
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=20161216044115.21287-3-david@fromorbit.com \
--to=david@fromorbit.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.