linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: jeffm@suse.com
To: linux-btrfs@vger.kernel.org
Cc: Jeff Mahoney <jeffm@suse.com>
Subject: [PATCH 17/18] btrfs-progs: handle command groups directly for common case
Date: Wed, 16 May 2018 17:38:50 -0400	[thread overview]
Message-ID: <20180516213851.10196-18-jeffm@suse.com> (raw)
In-Reply-To: <20180516213851.10196-1-jeffm@suse.com>

From: Jeff Mahoney <jeffm@suse.com>

Most command groups just pass their own command group to
handle_command_group.  We can remove the explicit definitions
of command group callbacks by passing the cmd_struct to
handle_command_group and allowing it to resolve the group from it.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 btrfs.c           | 14 +++++++-------
 cmds-balance.c    |  6 +++---
 cmds-device.c     |  5 -----
 cmds-filesystem.c |  6 ------
 cmds-inspect.c    |  5 -----
 cmds-property.c   |  6 ------
 cmds-qgroup.c     |  5 -----
 cmds-quota.c      |  5 -----
 cmds-replace.c    |  5 -----
 cmds-rescue.c     |  5 -----
 cmds-scrub.c      |  6 ------
 cmds-subvolume.c  |  5 -----
 commands.h        |  7 ++++---
 13 files changed, 14 insertions(+), 66 deletions(-)

diff --git a/btrfs.c b/btrfs.c
index 32b8e090..427e14c8 100644
--- a/btrfs.c
+++ b/btrfs.c
@@ -140,26 +140,26 @@ static void handle_help_options_next_level(const struct cmd_struct *cmd,
 	}
 }
 
-int handle_command_group(const struct cmd_group *grp,
+int handle_command_group(const struct cmd_struct *cmd,
 			 const struct cmd_context *cmdcxt,
 			 int argc, char **argv)
 
 {
-	const struct cmd_struct *cmd;
+	const struct cmd_struct *subcmd;
 
 	argc--;
 	argv++;
 	if (argc < 1) {
-		usage_command_group(grp, false, false);
+		usage_command_group(cmd->next, false, false);
 		exit(1);
 	}
 
-	cmd = parse_command_token(argv[0], grp);
+	subcmd = parse_command_token(argv[0], cmd->next);
 
-	handle_help_options_next_level(cmd, cmdcxt, argc, argv);
+	handle_help_options_next_level(subcmd, cmdcxt, argc, argv);
 
-	fixup_argv0(argv, cmd->token);
-	return cmd_execute(cmd, cmdcxt, argc, argv);
+	fixup_argv0(argv, subcmd->token);
+	return cmd_execute(subcmd, cmdcxt, argc, argv);
 }
 
 static const struct cmd_group btrfs_cmd_group;
diff --git a/cmds-balance.c b/cmds-balance.c
index c17b9ee3..e414ca27 100644
--- a/cmds-balance.c
+++ b/cmds-balance.c
@@ -943,7 +943,7 @@ static const struct cmd_group balance_cmd_group = {
 	}
 };
 
-static int cmd_balance(const struct cmd_struct *unused,
+static int cmd_balance(const struct cmd_struct *cmd,
 		       const struct cmd_context *cmdcxt, int argc, char **argv)
 {
 	if (argc == 2 && strcmp("start", argv[1]) != 0) {
@@ -956,7 +956,7 @@ static int cmd_balance(const struct cmd_struct *unused,
 		return do_balance(argv[1], &args, 0);
 	}
 
-	return handle_command_group(&balance_cmd_group, cmdcxt, argc, argv);
+	return handle_command_group(cmd, cmdcxt, argc, argv);
 }
 
-DEFINE_GROUP_COMMAND(balance, "balance");
+DEFINE_COMMAND(balance, "balance", cmd_balance, NULL, &balance_cmd_group, 0, 0);
diff --git a/cmds-device.c b/cmds-device.c
index ac9e82b1..f8c0ff20 100644
--- a/cmds-device.c
+++ b/cmds-device.c
@@ -630,9 +630,4 @@ static const struct cmd_group device_cmd_group = {
 	}
 };
 
-static int cmd_device(const struct cmd_struct *unused,
-		      const struct cmd_context *cmdcxt, int argc, char **argv)
-{
-	return handle_command_group(&device_cmd_group, cmdcxt, argc, argv);
-}
 DEFINE_GROUP_COMMAND_TOKEN(device);
diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index 6701b16f..24852ec6 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -1235,10 +1235,4 @@ static const struct cmd_group filesystem_cmd_group = {
 	}
 };
 
-static int cmd_filesystem(const struct cmd_struct *unused,
-			  const struct cmd_context *cmdcxt,
-			  int argc, char **argv)
-{
-	return handle_command_group(&filesystem_cmd_group, cmdcxt, argc, argv);
-}
 DEFINE_GROUP_COMMAND_TOKEN(filesystem);
diff --git a/cmds-inspect.c b/cmds-inspect.c
index eecfd7f9..22c5a5d6 100644
--- a/cmds-inspect.c
+++ b/cmds-inspect.c
@@ -658,9 +658,4 @@ static const struct cmd_group inspect_cmd_group = {
 	}
 };
 
-static int cmd_inspect(const struct cmd_struct *unused,
-		       const struct cmd_context *cmdcxt, int argc, char **argv)
-{
-	return handle_command_group(&inspect_cmd_group, cmdcxt, argc, argv);
-}
 DEFINE_GROUP_COMMAND(inspect, "inspect-internal");
diff --git a/cmds-property.c b/cmds-property.c
index 498fa456..58f6c48a 100644
--- a/cmds-property.c
+++ b/cmds-property.c
@@ -422,10 +422,4 @@ static const struct cmd_group property_cmd_group = {
 	}
 };
 
-static int cmd_property(const struct cmd_struct *unused,
-			const struct cmd_context *cmdcxt,
-			int argc, char **argv)
-{
-	return handle_command_group(&property_cmd_group, cmdcxt, argc, argv);
-}
 DEFINE_GROUP_COMMAND_TOKEN(property);
diff --git a/cmds-qgroup.c b/cmds-qgroup.c
index 9325b568..ce9aa1c6 100644
--- a/cmds-qgroup.c
+++ b/cmds-qgroup.c
@@ -541,9 +541,4 @@ static const struct cmd_group qgroup_cmd_group = {
 	}
 };
 
-static int cmd_qgroup(const struct cmd_struct *unused,
-		      const struct cmd_context *cmdcxt, int argc, char **argv)
-{
-	return handle_command_group(&qgroup_cmd_group, cmdcxt, argc, argv);
-}
 DEFINE_GROUP_COMMAND_TOKEN(qgroup);
diff --git a/cmds-quota.c b/cmds-quota.c
index 2a88d4c4..7b524123 100644
--- a/cmds-quota.c
+++ b/cmds-quota.c
@@ -219,9 +219,4 @@ static const struct cmd_group quota_cmd_group = {
 	}
 };
 
-static int cmd_quota(const struct cmd_struct *unused,
-		     const struct cmd_context *cmdcxt, int argc, char **argv)
-{
-	return handle_command_group(&quota_cmd_group, cmdcxt, argc, argv);
-}
 DEFINE_GROUP_COMMAND_TOKEN(quota);
diff --git a/cmds-replace.c b/cmds-replace.c
index 64c93537..8b2091c9 100644
--- a/cmds-replace.c
+++ b/cmds-replace.c
@@ -560,9 +560,4 @@ static const struct cmd_group replace_cmd_group = {
 	}
 };
 
-static int cmd_replace(const struct cmd_struct *unused,
-		       const struct cmd_context *cmdcxt, int argc, char **argv)
-{
-	return handle_command_group(&replace_cmd_group, cmdcxt, argc, argv);
-}
 DEFINE_GROUP_COMMAND_TOKEN(replace);
diff --git a/cmds-rescue.c b/cmds-rescue.c
index ec1ea222..364d6dd9 100644
--- a/cmds-rescue.c
+++ b/cmds-rescue.c
@@ -273,9 +273,4 @@ static const struct cmd_group rescue_cmd_group = {
 	}
 };
 
-static int cmd_rescue(const struct cmd_struct *unused,
-		      const struct cmd_context *cmdcxt, int argc, char **argv)
-{
-	return handle_command_group(&rescue_cmd_group, cmdcxt, argc, argv);
-}
 DEFINE_GROUP_COMMAND_TOKEN(rescue);
diff --git a/cmds-scrub.c b/cmds-scrub.c
index 41f9226e..bafec7df 100644
--- a/cmds-scrub.c
+++ b/cmds-scrub.c
@@ -1805,10 +1805,4 @@ static const struct cmd_group scrub_cmd_group = {
 	}
 };
 
-static int cmd_scrub(const struct cmd_struct *unused,
-		     const struct cmd_context *cmdcxt, int argc, char **argv)
-{
-	return handle_command_group(&scrub_cmd_group, cmdcxt, argc, argv);
-}
-
 DEFINE_GROUP_COMMAND_TOKEN(scrub);
diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index be78d555..e5e5193b 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -1307,9 +1307,4 @@ static const struct cmd_group subvolume_cmd_group = {
 	}
 };
 
-int cmd_subvolume(const struct cmd_struct *unused,
-		  const struct cmd_context *cmdcxt, int argc, char **argv)
-{
-	return handle_command_group(&subvolume_cmd_group, cmdcxt, argc, argv);
-}
 DEFINE_GROUP_COMMAND_TOKEN(subvolume);
diff --git a/commands.h b/commands.h
index 83316c6d..5c15a16e 100644
--- a/commands.h
+++ b/commands.h
@@ -94,7 +94,8 @@ struct cmd_struct {
 /*
  * Define a command for the common case - just a name and string.
  * It's assumed that the callback is called cmd_<name> and the usage
- * array is named cmd_<name>_usage.
+ * array is named cmd_<name>_usage.  Text is the only supported output
+ * format.
  */
 #define DEFINE_SIMPLE_COMMAND(name, token)				\
 	DEFINE_COMMAND(name, token, cmd_ ##name,			\
@@ -106,7 +107,7 @@ struct cmd_struct {
  * struct cmd_group is called <name>_cmd_group.
  */
 #define DEFINE_GROUP_COMMAND(name, token)				\
-	DEFINE_COMMAND(name, token, cmd_ ##name,			\
+	DEFINE_COMMAND(name, token, handle_command_group,		\
 		       NULL, &(name ## _cmd_group), 0, 0)
 
 /*
@@ -130,7 +131,7 @@ static inline int cmd_execute(const struct cmd_struct *cmd,
 	return cmd->fn(cmd, cmdcxt, argc, argv);
 }
 
-int handle_command_group(const struct cmd_group *grp,
+int handle_command_group(const struct cmd_struct *cmd,
 			 const struct cmd_context *cmdcxt,
 			 int argc, char **argv);
 
-- 
2.15.1


  parent reply	other threads:[~2018-05-16 21:39 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-16 21:38 [PATCH v3 00/18] btrfs-progs: qgroups-usability jeffm
2018-05-16 21:38 ` [PATCH 01/18] btrfs-progs: quota: Add -W option to rescan to wait without starting rescan jeffm
2018-05-16 21:38 ` [PATCH 02/18] btrfs-progs: qgroups: fix misleading index check jeffm
2018-05-16 21:38 ` [PATCH 03/18] btrfs-progs: constify pathnames passed as arguments jeffm
2018-05-16 21:38 ` [PATCH 04/18] btrfs-progs: btrfs-list: add rb_entry helpers for root_info jeffm
2018-05-16 21:38 ` [PATCH 05/18] btrfs-progs: qgroups: add pathname to show output jeffm
2018-05-18  4:55   ` Misono Tomohiro
2018-05-16 21:38 ` [PATCH 06/18] btrfs-progs: qgroups: introduce and use info and limit structures jeffm
2018-05-16 21:38 ` [PATCH 07/18] btrfs-progs: qgroups: introduce btrfs_qgroup_query jeffm
2018-05-16 21:38 ` [PATCH 08/18] btrfs-progs: subvolume: add quota info to btrfs sub show jeffm
2018-05-16 21:38 ` [PATCH 09/18] btrfs-progs: help: convert ints used as bools to bool jeffm
2018-05-16 21:38 ` [PATCH 10/18] btrfs-progs: reorder placement of help declarations for send/receive jeffm
2018-05-16 21:38 ` [PATCH 11/18] btrfs-progs: filesystem balance: split out special handling jeffm
2018-05-16 21:38 ` [PATCH 12/18] btrfs-progs: use cmd_struct as command entry point jeffm
2018-05-16 21:38 ` [PATCH 13/18] btrfs-progs: pass cmd_struct to command callback function jeffm
2018-05-16 21:38 ` [PATCH 14/18] btrfs-progs: pass cmd_struct to clean_args_no_options{,_relaxed} jeffm
2018-05-16 21:38 ` [PATCH 15/18] btrfs-progs: pass cmd_struct to usage() jeffm
2018-05-16 21:38 ` [PATCH 16/18] btrfs-progs: add support for output formats jeffm
2018-05-16 21:38 ` jeffm [this message]
2018-05-16 21:38 ` [PATCH 18/18] btrfs-progs: qgroups: don't print dead qgroups jeffm

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=20180516213851.10196-18-jeffm@suse.com \
    --to=jeffm@suse.com \
    --cc=linux-btrfs@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;
as well as URLs for NNTP newsgroup(s).