mirror of
git://sourceware.org/git/lvm2.git
synced 2025-03-10 16:58:47 +03:00
lvmcmdline: runtime function resolving
Instead of resolving and storing 'command_fn' withing 'struct command' use just funtion enum and resolve function pointer just in place, where it is really needed - first try to resolve 'new style' and fallback to 'old style' named.
This commit is contained in:
parent
bebbb1e66a
commit
1a219c69ee
@ -22,12 +22,9 @@ struct logical_volume;
|
|||||||
/* old per-command-name function */
|
/* old per-command-name function */
|
||||||
typedef int (*command_fn) (struct cmd_context *cmd, int argc, char **argv);
|
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 {
|
struct command_function {
|
||||||
int command_enum;
|
int command_enum;
|
||||||
command_id_fn fn;
|
command_fn fn; /* new style */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct command_name {
|
struct command_name {
|
||||||
@ -188,11 +185,8 @@ struct command {
|
|||||||
uint16_t command_enum; /* <command_id>_CMD */
|
uint16_t command_enum; /* <command_id>_CMD */
|
||||||
uint16_t command_index; /* position in commands[] */
|
uint16_t command_index; /* position in commands[] */
|
||||||
|
|
||||||
const struct command_function *functions; /* new style */
|
uint16_t lvm_command_enum; /* position in command_names[] */
|
||||||
command_fn fn; /* old style */
|
uint16_t cmd_flags; /* CMD_FLAG_ */
|
||||||
|
|
||||||
unsigned int cmd_flags; /* CMD_FLAG_ */
|
|
||||||
uint16_t lvm_command_enum; /* position in commands[] */
|
|
||||||
|
|
||||||
/* definitions of opt/pos args */
|
/* definitions of opt/pos args */
|
||||||
|
|
||||||
|
@ -1301,7 +1301,7 @@ static void _set_valid_args_for_command_name(int ci)
|
|||||||
command_names_args[ci].num_args = num_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;
|
int i;
|
||||||
|
|
||||||
@ -1310,7 +1310,7 @@ static const struct command_function *_find_command_id_function(int command_enum
|
|||||||
|
|
||||||
for (i = 0; i < CMD_COUNT; i++) {
|
for (i = 0; i < CMD_COUNT; i++) {
|
||||||
if (_command_functions[i].command_enum == command_enum)
|
if (_command_functions[i].command_enum == command_enum)
|
||||||
return &_command_functions[i];
|
return _command_functions[i].fn;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -1335,8 +1335,6 @@ static int _command_name_compare(const void *on1, const void *on2)
|
|||||||
int lvm_register_commands(struct cmd_context *cmd, const char *run_name)
|
int lvm_register_commands(struct cmd_context *cmd, const char *run_name)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
const char *last_name = NULL;
|
|
||||||
const struct command_name *cname = NULL;
|
|
||||||
|
|
||||||
/* already initialized */
|
/* already initialized */
|
||||||
if (_cmdline.commands)
|
if (_cmdline.commands)
|
||||||
@ -1357,19 +1355,6 @@ int lvm_register_commands(struct cmd_context *cmd, const char *run_name)
|
|||||||
for (i = 0; i < COMMAND_COUNT; i++) {
|
for (i = 0; i < COMMAND_COUNT; i++) {
|
||||||
commands_idx[i] = &commands[i];
|
commands_idx[i] = &commands[i];
|
||||||
commands[i].command_index = 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 */
|
/* Sort all commands by its name for quick binary search */
|
||||||
@ -3053,6 +3038,7 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
|
|||||||
int skip_hyphens;
|
int skip_hyphens;
|
||||||
int refresh_done = 0;
|
int refresh_done = 0;
|
||||||
int io;
|
int io;
|
||||||
|
command_fn fn;
|
||||||
|
|
||||||
/* Avoid excessive access to /etc/localtime and set TZ variable for glibc
|
/* 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 */
|
* so it does not need to check /etc/localtime everytime that needs that info */
|
||||||
@ -3281,12 +3267,12 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
|
|||||||
goto_out;
|
goto_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd->command->functions)
|
/* A command-line-specific function is used */
|
||||||
/* A command-line-specific function is used */
|
if (!(fn = _find_command_id_function(cmd->command->command_enum)))
|
||||||
ret = cmd->command->functions->fn(cmd, argc, argv);
|
|
||||||
else
|
|
||||||
/* The old style command-name function is used */
|
/* 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();
|
lvmlockd_disconnect();
|
||||||
fin_locking(cmd);
|
fin_locking(cmd);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user