mirror of
https://github.com/kdave/btrfs-progs
synced 2025-02-16 09:46:55 +00:00
btrfs-progs: handle command groups directly for common case
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> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
61a7ffc84b
commit
1b42c7b50b
15
btrfs.c
15
btrfs.c
@ -117,25 +117,24 @@ static void handle_help_options_next_level(const struct cmd_struct *cmd,
|
||||
}
|
||||
}
|
||||
|
||||
int handle_command_group(const struct cmd_group *grp, int argc,
|
||||
int handle_command_group(const struct cmd_struct *cmd, 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, argc, argv);
|
||||
handle_help_options_next_level(subcmd, argc, argv);
|
||||
|
||||
fixup_argv0(argv, cmd->token);
|
||||
return cmd_execute(cmd, argc, argv);
|
||||
fixup_argv0(argv, subcmd->token);
|
||||
return cmd_execute(subcmd, argc, argv);
|
||||
}
|
||||
|
||||
static const struct cmd_group btrfs_cmd_group;
|
||||
|
@ -939,7 +939,7 @@ static const struct cmd_group balance_cmd_group = {
|
||||
}
|
||||
};
|
||||
|
||||
static int cmd_balance(const struct cmd_struct *unused, int argc, char **argv)
|
||||
static int cmd_balance(const struct cmd_struct *cmd, int argc, char **argv)
|
||||
{
|
||||
if (argc == 2 && strcmp("start", argv[1]) != 0) {
|
||||
/* old 'btrfs filesystem balance <path>' syntax */
|
||||
@ -951,7 +951,7 @@ static int cmd_balance(const struct cmd_struct *unused, int argc, char **argv)
|
||||
return do_balance(argv[1], &args, 0);
|
||||
}
|
||||
|
||||
return handle_command_group(&balance_cmd_group, argc, argv);
|
||||
return handle_command_group(cmd, argc, argv);
|
||||
}
|
||||
|
||||
DEFINE_GROUP_COMMAND(balance, "balance");
|
||||
DEFINE_COMMAND(balance, "balance", cmd_balance, NULL, &balance_cmd_group, 0);
|
||||
|
@ -681,8 +681,4 @@ static const struct cmd_group device_cmd_group = {
|
||||
}
|
||||
};
|
||||
|
||||
static int cmd_device(const struct cmd_struct *unused, int argc, char **argv)
|
||||
{
|
||||
return handle_command_group(&device_cmd_group, argc, argv);
|
||||
}
|
||||
DEFINE_GROUP_COMMAND_TOKEN(device);
|
||||
|
@ -1254,9 +1254,4 @@ static const struct cmd_group filesystem_cmd_group = {
|
||||
}
|
||||
};
|
||||
|
||||
static int cmd_filesystem(const struct cmd_struct *unused,
|
||||
int argc, char **argv)
|
||||
{
|
||||
return handle_command_group(&filesystem_cmd_group, argc, argv);
|
||||
}
|
||||
DEFINE_GROUP_COMMAND_TOKEN(filesystem);
|
||||
|
@ -660,8 +660,4 @@ static const struct cmd_group inspect_cmd_group = {
|
||||
}
|
||||
};
|
||||
|
||||
static int cmd_inspect(const struct cmd_struct *unused, int argc, char **argv)
|
||||
{
|
||||
return handle_command_group(&inspect_cmd_group, argc, argv);
|
||||
}
|
||||
DEFINE_GROUP_COMMAND(inspect, "inspect-internal");
|
||||
|
@ -421,9 +421,4 @@ static const struct cmd_group property_cmd_group = {
|
||||
}
|
||||
};
|
||||
|
||||
static int cmd_property(const struct cmd_struct *unused,
|
||||
int argc, char **argv)
|
||||
{
|
||||
return handle_command_group(&property_cmd_group, argc, argv);
|
||||
}
|
||||
DEFINE_GROUP_COMMAND_TOKEN(property);
|
||||
|
@ -518,8 +518,4 @@ static const struct cmd_group qgroup_cmd_group = {
|
||||
}
|
||||
};
|
||||
|
||||
static int cmd_qgroup(const struct cmd_struct *unused, int argc, char **argv)
|
||||
{
|
||||
return handle_command_group(&qgroup_cmd_group, argc, argv);
|
||||
}
|
||||
DEFINE_GROUP_COMMAND_TOKEN(qgroup);
|
||||
|
@ -207,8 +207,4 @@ static const struct cmd_group quota_cmd_group = {
|
||||
}
|
||||
};
|
||||
|
||||
static int cmd_quota(const struct cmd_struct *unused, int argc, char **argv)
|
||||
{
|
||||
return handle_command_group("a_cmd_group, argc, argv);
|
||||
}
|
||||
DEFINE_GROUP_COMMAND_TOKEN(quota);
|
||||
|
@ -563,8 +563,4 @@ static const struct cmd_group replace_cmd_group = {
|
||||
}
|
||||
};
|
||||
|
||||
static int cmd_replace(const struct cmd_struct *unused, int argc, char **argv)
|
||||
{
|
||||
return handle_command_group(&replace_cmd_group, argc, argv);
|
||||
}
|
||||
DEFINE_GROUP_COMMAND_TOKEN(replace);
|
||||
|
@ -272,8 +272,4 @@ static const struct cmd_group rescue_cmd_group = {
|
||||
}
|
||||
};
|
||||
|
||||
static int cmd_rescue(const struct cmd_struct *unused, int argc, char **argv)
|
||||
{
|
||||
return handle_command_group(&rescue_cmd_group, argc, argv);
|
||||
}
|
||||
DEFINE_GROUP_COMMAND_TOKEN(rescue);
|
||||
|
@ -1808,9 +1808,4 @@ static const struct cmd_group scrub_cmd_group = {
|
||||
}
|
||||
};
|
||||
|
||||
static int cmd_scrub(const struct cmd_struct *unused, int argc, char **argv)
|
||||
{
|
||||
return handle_command_group(&scrub_cmd_group, argc, argv);
|
||||
}
|
||||
|
||||
DEFINE_GROUP_COMMAND_TOKEN(scrub);
|
||||
|
@ -1305,9 +1305,4 @@ static const struct cmd_group subvolume_cmd_group = {
|
||||
}
|
||||
};
|
||||
|
||||
static int cmd_subvolume(const struct cmd_struct *unused,
|
||||
int argc, char **argv)
|
||||
{
|
||||
return handle_command_group(&subvolume_cmd_group, argc, argv);
|
||||
}
|
||||
DEFINE_GROUP_COMMAND_TOKEN(subvolume);
|
||||
|
@ -90,7 +90,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)
|
||||
|
||||
/*
|
||||
@ -113,8 +113,7 @@ static inline int cmd_execute(const struct cmd_struct *cmd,
|
||||
return cmd->fn(cmd, argc, argv);
|
||||
}
|
||||
|
||||
int handle_command_group(const struct cmd_group *grp, int argc,
|
||||
char **argv);
|
||||
int handle_command_group(const struct cmd_struct *cmd, int argc, char **argv);
|
||||
|
||||
extern const char * const generic_cmd_help_usage[];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user