/* old per-command-name function */
typedef int (*command_fn) (struct cmd_context *cmd, int argc, char **argv);
-/* new per-command-line-id functions */
-typedef int (*command_id_fn) (struct cmd_context *cmd, int argc, char **argv);
-
struct command_function {
int command_enum;
- command_id_fn fn;
+ command_fn fn; /* new style */
};
struct command_name {
uint16_t command_enum; /* <command_id>_CMD */
uint16_t command_index; /* position in commands[] */
- const struct command_function *functions; /* new style */
- command_fn fn; /* old style */
-
- unsigned int cmd_flags; /* CMD_FLAG_ */
- uint16_t lvm_command_enum; /* position in commands[] */
+ uint16_t lvm_command_enum; /* position in command_names[] */
+ uint16_t cmd_flags; /* CMD_FLAG_ */
/* definitions of opt/pos args */
command_names_args[ci].num_args = num_args;
}
-static const struct command_function *_find_command_id_function(int command_enum)
+static command_fn _find_command_id_function(int command_enum)
{
int i;
for (i = 0; i < CMD_COUNT; i++) {
if (_command_functions[i].command_enum == command_enum)
- return &_command_functions[i];
+ return _command_functions[i].fn;
}
return NULL;
}
int lvm_register_commands(struct cmd_context *cmd, const char *run_name)
{
int i;
- const char *last_name = NULL;
- const struct command_name *cname = NULL;
/* already initialized */
if (_cmdline.commands)
for (i = 0; i < COMMAND_COUNT; i++) {
commands_idx[i] = &commands[i];
commands[i].command_index = i;
-
- /* new style */
- commands[i].functions = _find_command_id_function(commands[i].command_enum);
-
- /* old style */
- if (!commands[i].functions) {
- if (!last_name || strcmp(last_name, commands[i].name)) {
- last_name = commands[i].name;
- cname = find_command_name(last_name);
- }
- if (cname)
- commands[i].fn = cname->fn;
- }
}
/* Sort all commands by its name for quick binary search */
int skip_hyphens;
int refresh_done = 0;
int io;
+ command_fn fn;
/* Avoid excessive access to /etc/localtime and set TZ variable for glibc
* so it does not need to check /etc/localtime everytime that needs that info */
goto_out;
}
- if (cmd->command->functions)
- /* A command-line-specific function is used */
- ret = cmd->command->functions->fn(cmd, argc, argv);
- else
+ /* A command-line-specific function is used */
+ if (!(fn = _find_command_id_function(cmd->command->command_enum)))
/* The old style command-name function is used */
- ret = cmd->command->fn(cmd, argc, argv);
+ fn = command_names[cmd->command->lvm_command_enum].fn;
+
+ ret = fn(cmd, argc, argv);
lvmlockd_disconnect();
fin_locking(cmd);