From patchwork Wed Dec 7 03:47:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Chinner X-Patchwork-Id: 9486753 X-Mozilla-Keys: nonjunk Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on sandeen.net X-Spam-Level: X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD autolearn=unavailable autolearn_force=no version=3.4.0 X-Spam-HP: BAYES_00=-1.9,HEADER_FROM_DIFFERENT_DOMAINS=0.001, RCVD_IN_DNSWL_HI=-5,RP_MATCHES_RCVD=-0.1 X-Original-To: sandeen@sandeen.net Delivered-To: sandeen@sandeen.net Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by sandeen.net (Postfix) with ESMTP id 4ECE647968B for ; Tue, 6 Dec 2016 21:46:38 -0600 (CST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752198AbcLGDrg (ORCPT ); Tue, 6 Dec 2016 22:47:36 -0500 Received: from ipmail06.adl6.internode.on.net ([150.101.137.145]:56141 "EHLO ipmail06.adl6.internode.on.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752017AbcLGDrf (ORCPT ); Tue, 6 Dec 2016 22:47:35 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2AQFwCUhUdYIGuWLHleHAEBBAEBCgEBgzkBAQEBAR+BYIZ0nDgBAQEBAQEGgR2QM4I8hBaGHgICAoIjVAECAQEBAQECBgEBAQEBATlFhGkGJy8jEAgYMTkDBxQZiG6qYz2LOwEBCCeFdIlUhXoFmmaRC4QHjEVJkUiBThMOg1wcgXEqNIZSgjwBAQE Received: from ppp121-44-150-107.lns20.syd7.internode.on.net (HELO dastard) ([121.44.150.107]) by ipmail06.adl6.internode.on.net with ESMTP; 07 Dec 2016 14:17:29 +1030 Received: from discord.disaster.area ([192.168.1.111]) by dastard with esmtp (Exim 4.80) (envelope-from ) id 1cETCZ-00069N-6J; Wed, 07 Dec 2016 14:47:27 +1100 Received: from dave by discord.disaster.area with local (Exim 4.88) (envelope-from ) id 1cETCZ-0000bE-5D; Wed, 07 Dec 2016 14:47:27 +1100 From: Dave Chinner To: linux-xfs@vger.kernel.org Cc: fstests@vger.kernel.org, amir73il@gmail.com Subject: [PATCH 2/6] libxcmd: rename args_command to command_iterator Date: Wed, 7 Dec 2016 14:47:20 +1100 Message-Id: <20161207034724.1613-3-david@fromorbit.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161207034724.1613-1-david@fromorbit.com> References: <20161207034724.1613-1-david@fromorbit.com> Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Dave Chinner 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 --- 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); /*