From ef346a25dc992d4e35ce2aec23479c066626b77c Mon Sep 17 00:00:00 2001 From: Dave Chinner Date: Thu, 12 Jan 2017 14:12:41 -0600 Subject: [PATCH] libxcmd: rename args_command to command_iterator 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 Reviewed-by: Christoph Hellwig Reviewed-by: Eric Sandeen Signed-off-by: Eric Sandeen --- 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 58bfcaac4..637ee06e6 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 10ae223af..a382d9bae 100644 --- a/io/init.c +++ b/io/init.c @@ -91,8 +91,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) @@ -215,7 +220,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 dce8361ce..789aeb5c5 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 3bebbb873..193f6421f 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.47.2