mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
command struct: remove command name refs
Change run time access to the command_name struct cmd->cname instead of indirectly through cmd->command->cname. This removes the two run time fields from struct command.
This commit is contained in:
parent
d9d5b8414b
commit
013c080756
@ -89,6 +89,7 @@ struct cmd_context {
|
|||||||
*/
|
*/
|
||||||
const char *cmd_line;
|
const char *cmd_line;
|
||||||
const char *name; /* needed before cmd->command is set */
|
const char *name; /* needed before cmd->command is set */
|
||||||
|
struct command_name *cname;
|
||||||
struct command *command;
|
struct command *command;
|
||||||
char **argv;
|
char **argv;
|
||||||
struct arg_values *opt_arg_values;
|
struct arg_values *opt_arg_values;
|
||||||
|
@ -164,13 +164,9 @@ struct command {
|
|||||||
const char *command_line_id;
|
const char *command_line_id;
|
||||||
int command_line_enum; /* <command_line_id>_CMD */
|
int command_line_enum; /* <command_line_id>_CMD */
|
||||||
|
|
||||||
struct command_name *cname;
|
|
||||||
|
|
||||||
command_fn fn; /* old style */
|
command_fn fn; /* old style */
|
||||||
struct command_function *functions; /* new style */
|
struct command_function *functions; /* new style */
|
||||||
|
|
||||||
unsigned int flags; /* copied from command_name.flags from commands.h */
|
|
||||||
|
|
||||||
unsigned int cmd_flags; /* CMD_FLAG_ */
|
unsigned int cmd_flags; /* CMD_FLAG_ */
|
||||||
|
|
||||||
/* definitions of opt/pos args */
|
/* definitions of opt/pos args */
|
||||||
|
@ -4512,7 +4512,7 @@ static int _lvconvert_merge_mirror_images_single(struct cmd_context *cmd,
|
|||||||
int lvconvert_merge_mirror_images_cmd(struct cmd_context *cmd, int argc, char **argv)
|
int lvconvert_merge_mirror_images_cmd(struct cmd_context *cmd, int argc, char **argv)
|
||||||
{
|
{
|
||||||
/* arg can be a VG name, which is the standard option usage */
|
/* arg can be a VG name, which is the standard option usage */
|
||||||
cmd->command->flags &= ~GET_VGNAME_FROM_OPTIONS;
|
cmd->cname->flags &= ~GET_VGNAME_FROM_OPTIONS;
|
||||||
|
|
||||||
return process_each_lv(cmd, cmd->position_argc, cmd->position_argv, NULL, NULL, READ_FOR_UPDATE,
|
return process_each_lv(cmd, cmd->position_argc, cmd->position_argv, NULL, NULL, READ_FOR_UPDATE,
|
||||||
NULL, &_lvconvert_visible_check, &_lvconvert_merge_mirror_images_single);
|
NULL, &_lvconvert_visible_check, &_lvconvert_merge_mirror_images_single);
|
||||||
@ -4552,7 +4552,7 @@ int lvconvert_merge_cmd(struct cmd_context *cmd, int argc, char **argv)
|
|||||||
|
|
||||||
handle->custom_handle = &lr;
|
handle->custom_handle = &lr;
|
||||||
|
|
||||||
cmd->command->flags &= ~GET_VGNAME_FROM_OPTIONS;
|
cmd->cname->flags &= ~GET_VGNAME_FROM_OPTIONS;
|
||||||
|
|
||||||
ret = process_each_lv(cmd, cmd->position_argc, cmd->position_argv, NULL, NULL, READ_FOR_UPDATE,
|
ret = process_each_lv(cmd, cmd->position_argc, cmd->position_argv, NULL, NULL, READ_FOR_UPDATE,
|
||||||
handle, NULL, &_lvconvert_merge_generic_single);
|
handle, NULL, &_lvconvert_merge_generic_single);
|
||||||
|
@ -1092,7 +1092,6 @@ static void _define_commands(void)
|
|||||||
|
|
||||||
void lvm_register_commands(void)
|
void lvm_register_commands(void)
|
||||||
{
|
{
|
||||||
struct command_name *cname;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
memset(&commands, 0, sizeof(commands));
|
memset(&commands, 0, sizeof(commands));
|
||||||
@ -1102,13 +1101,8 @@ void lvm_register_commands(void)
|
|||||||
_cmdline.commands = commands;
|
_cmdline.commands = commands;
|
||||||
_cmdline.num_commands = COMMAND_COUNT;
|
_cmdline.num_commands = COMMAND_COUNT;
|
||||||
|
|
||||||
for (i = 0; i < COMMAND_COUNT; i++) {
|
for (i = 0; i < COMMAND_COUNT; i++)
|
||||||
if (!(cname = _find_command_name(commands[i].name)))
|
|
||||||
log_error(INTERNAL_ERROR "Failed to find command name %s.", commands[i].name);
|
|
||||||
commands[i].cname = cname;
|
|
||||||
commands[i].flags = cname->flags;
|
|
||||||
commands[i].functions = _find_command_function(commands[i].command_line_enum);
|
commands[i].functions = _find_command_function(commands[i].command_line_enum);
|
||||||
}
|
|
||||||
|
|
||||||
_cmdline.command_names = command_names;
|
_cmdline.command_names = command_names;
|
||||||
|
|
||||||
@ -2193,7 +2187,7 @@ static int _get_settings(struct cmd_context *cmd)
|
|||||||
|
|
||||||
cmd->current_settings.archive = arg_int_value(cmd, autobackup_ARG, cmd->current_settings.archive);
|
cmd->current_settings.archive = arg_int_value(cmd, autobackup_ARG, cmd->current_settings.archive);
|
||||||
cmd->current_settings.backup = arg_int_value(cmd, autobackup_ARG, cmd->current_settings.backup);
|
cmd->current_settings.backup = arg_int_value(cmd, autobackup_ARG, cmd->current_settings.backup);
|
||||||
cmd->current_settings.cache_vgmetadata = cmd->command->flags & CACHE_VGMETADATA ? 1 : 0;
|
cmd->current_settings.cache_vgmetadata = cmd->cname->flags & CACHE_VGMETADATA ? 1 : 0;
|
||||||
|
|
||||||
if (arg_is_set(cmd, readonly_ARG)) {
|
if (arg_is_set(cmd, readonly_ARG)) {
|
||||||
cmd->current_settings.activation = 0;
|
cmd->current_settings.activation = 0;
|
||||||
@ -2201,7 +2195,7 @@ static int _get_settings(struct cmd_context *cmd)
|
|||||||
cmd->current_settings.backup = 0;
|
cmd->current_settings.backup = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd->command->flags & LOCKD_VG_SH)
|
if (cmd->cname->flags & LOCKD_VG_SH)
|
||||||
cmd->lockd_vg_default_sh = 1;
|
cmd->lockd_vg_default_sh = 1;
|
||||||
|
|
||||||
cmd->partial_activation = 0;
|
cmd->partial_activation = 0;
|
||||||
@ -2613,7 +2607,7 @@ static int _init_lvmlockd(struct cmd_context *cmd)
|
|||||||
|
|
||||||
static int _cmd_no_meta_proc(struct cmd_context *cmd)
|
static int _cmd_no_meta_proc(struct cmd_context *cmd)
|
||||||
{
|
{
|
||||||
return cmd->command->flags & NO_METADATA_PROCESSING;
|
return cmd->cname->flags & NO_METADATA_PROCESSING;
|
||||||
}
|
}
|
||||||
|
|
||||||
int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
|
int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
|
||||||
@ -2688,6 +2682,11 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
|
|||||||
|
|
||||||
log_debug("Parsing: %s", cmd->cmd_line);
|
log_debug("Parsing: %s", cmd->cmd_line);
|
||||||
|
|
||||||
|
if (!(cmd->cname = _find_command_name(cmd->name))) {
|
||||||
|
log_error("Command name not found.\n");
|
||||||
|
return EINVALID_CMD_LINE;
|
||||||
|
}
|
||||||
|
|
||||||
if (!(cmd->command = _find_command(cmd, cmd->name, &argc, argv)))
|
if (!(cmd->command = _find_command(cmd, cmd->name, &argc, argv)))
|
||||||
return EINVALID_CMD_LINE;
|
return EINVALID_CMD_LINE;
|
||||||
|
|
||||||
@ -2772,7 +2771,7 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cmd->metadata_read_only &&
|
if (cmd->metadata_read_only &&
|
||||||
!(cmd->command->flags & PERMITTED_READ_ONLY)) {
|
!(cmd->cname->flags & PERMITTED_READ_ONLY)) {
|
||||||
log_error("%s: Command not permitted while global/metadata_read_only "
|
log_error("%s: Command not permitted while global/metadata_read_only "
|
||||||
"is set.", cmd->cmd_line);
|
"is set.", cmd->cmd_line);
|
||||||
goto out;
|
goto out;
|
||||||
@ -2832,7 +2831,7 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
|
|||||||
* In this case, disable the *use* of lvmetad by this command, reverting to
|
* In this case, disable the *use* of lvmetad by this command, reverting to
|
||||||
* disk scanning.
|
* disk scanning.
|
||||||
*/
|
*/
|
||||||
if (lvmetad_used() && !(cmd->command->flags & NO_LVMETAD_AUTOSCAN)) {
|
if (lvmetad_used() && !(cmd->cname->flags & NO_LVMETAD_AUTOSCAN)) {
|
||||||
if (cmd->include_foreign_vgs || !lvmetad_token_matches(cmd)) {
|
if (cmd->include_foreign_vgs || !lvmetad_token_matches(cmd)) {
|
||||||
if (lvmetad_used() && !lvmetad_pvscan_all_devs(cmd, cmd->include_foreign_vgs ? 1 : 0)) {
|
if (lvmetad_used() && !lvmetad_pvscan_all_devs(cmd, cmd->include_foreign_vgs ? 1 : 0)) {
|
||||||
log_warn("WARNING: Not using lvmetad because cache update failed.");
|
log_warn("WARNING: Not using lvmetad because cache update failed.");
|
||||||
|
@ -284,7 +284,7 @@ static int _pvscan_autoactivate(struct cmd_context *cmd, struct pvscan_aa_params
|
|||||||
handle->custom_handle = pp;
|
handle->custom_handle = pp;
|
||||||
|
|
||||||
if (all_vgs) {
|
if (all_vgs) {
|
||||||
cmd->command->flags |= ALL_VGS_IS_DEFAULT;
|
cmd->cname->flags |= ALL_VGS_IS_DEFAULT;
|
||||||
pp->refresh_all = 1;
|
pp->refresh_all = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2093,7 +2093,7 @@ static void _choose_vgs_to_process(struct cmd_context *cmd,
|
|||||||
* matches the UUID of a VG. (--select should generally
|
* matches the UUID of a VG. (--select should generally
|
||||||
* be used to select a VG by uuid instead.)
|
* be used to select a VG by uuid instead.)
|
||||||
*/
|
*/
|
||||||
if (!found && (cmd->command->flags & ALLOW_UUID_AS_NAME))
|
if (!found && (cmd->cname->flags & ALLOW_UUID_AS_NAME))
|
||||||
arg_is_uuid = id_read_format_try(&id, sl->str);
|
arg_is_uuid = id_read_format_try(&id, sl->str);
|
||||||
|
|
||||||
if (!found && arg_is_uuid) {
|
if (!found && arg_is_uuid) {
|
||||||
@ -2162,7 +2162,7 @@ int process_each_vg(struct cmd_context *cmd,
|
|||||||
struct dm_list arg_vgnames; /* str_list */
|
struct dm_list arg_vgnames; /* str_list */
|
||||||
struct dm_list vgnameids_on_system; /* vgnameid_list */
|
struct dm_list vgnameids_on_system; /* vgnameid_list */
|
||||||
struct dm_list vgnameids_to_process; /* vgnameid_list */
|
struct dm_list vgnameids_to_process; /* vgnameid_list */
|
||||||
int enable_all_vgs = (cmd->command->flags & ALL_VGS_IS_DEFAULT);
|
int enable_all_vgs = (cmd->cname->flags & ALL_VGS_IS_DEFAULT);
|
||||||
int process_all_vgs_on_system = 0;
|
int process_all_vgs_on_system = 0;
|
||||||
int ret_max = ECMD_PROCESSED;
|
int ret_max = ECMD_PROCESSED;
|
||||||
int ret;
|
int ret;
|
||||||
@ -2209,7 +2209,7 @@ int process_each_vg(struct cmd_context *cmd,
|
|||||||
* label scan to be done. get_vgnameids() will scan labels
|
* label scan to be done. get_vgnameids() will scan labels
|
||||||
* (when not using lvmetad).
|
* (when not using lvmetad).
|
||||||
*/
|
*/
|
||||||
if (cmd->command->flags & REQUIRES_FULL_LABEL_SCAN) {
|
if (cmd->cname->flags & REQUIRES_FULL_LABEL_SCAN) {
|
||||||
dev_cache_full_scan(cmd->full_filter);
|
dev_cache_full_scan(cmd->full_filter);
|
||||||
lvmcache_force_next_label_scan();
|
lvmcache_force_next_label_scan();
|
||||||
}
|
}
|
||||||
@ -3655,7 +3655,7 @@ int process_each_lv(struct cmd_context *cmd,
|
|||||||
struct dm_list arg_lvnames; /* str_list */
|
struct dm_list arg_lvnames; /* str_list */
|
||||||
struct dm_list vgnameids_on_system; /* vgnameid_list */
|
struct dm_list vgnameids_on_system; /* vgnameid_list */
|
||||||
struct dm_list vgnameids_to_process; /* vgnameid_list */
|
struct dm_list vgnameids_to_process; /* vgnameid_list */
|
||||||
int enable_all_vgs = (cmd->command->flags & ALL_VGS_IS_DEFAULT);
|
int enable_all_vgs = (cmd->cname->flags & ALL_VGS_IS_DEFAULT);
|
||||||
int process_all_vgs_on_system = 0;
|
int process_all_vgs_on_system = 0;
|
||||||
int ret_max = ECMD_PROCESSED;
|
int ret_max = ECMD_PROCESSED;
|
||||||
int ret;
|
int ret;
|
||||||
@ -3674,7 +3674,7 @@ int process_each_lv(struct cmd_context *cmd,
|
|||||||
/*
|
/*
|
||||||
* Find any LVs, VGs or tags explicitly provided on the command line.
|
* Find any LVs, VGs or tags explicitly provided on the command line.
|
||||||
*/
|
*/
|
||||||
if (cmd->command->flags & GET_VGNAME_FROM_OPTIONS)
|
if (cmd->cname->flags & GET_VGNAME_FROM_OPTIONS)
|
||||||
ret = _get_arg_lvnames_using_options(cmd, argc, argv, &arg_vgnames, &arg_lvnames, &arg_tags);
|
ret = _get_arg_lvnames_using_options(cmd, argc, argv, &arg_vgnames, &arg_lvnames, &arg_tags);
|
||||||
else
|
else
|
||||||
ret = _get_arg_lvnames(cmd, argc, argv, one_vgname, one_lvname, &arg_vgnames, &arg_lvnames, &arg_tags);
|
ret = _get_arg_lvnames(cmd, argc, argv, one_vgname, one_lvname, &arg_vgnames, &arg_lvnames, &arg_tags);
|
||||||
@ -4032,7 +4032,7 @@ static int _process_duplicate_pvs(struct cmd_context *cmd,
|
|||||||
if (!process_all_devices && !dil)
|
if (!process_all_devices && !dil)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!(cmd->command->flags & ENABLE_DUPLICATE_DEVS))
|
if (!(cmd->cname->flags & ENABLE_DUPLICATE_DEVS))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -4387,7 +4387,7 @@ int process_each_pv(struct cmd_context *cmd,
|
|||||||
goto_out;
|
goto_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((cmd->command->flags & DISALLOW_TAG_ARGS) && !dm_list_empty(&arg_tags)) {
|
if ((cmd->cname->flags & DISALLOW_TAG_ARGS) && !dm_list_empty(&arg_tags)) {
|
||||||
log_error("Tags cannot be used with this command.");
|
log_error("Tags cannot be used with this command.");
|
||||||
return ECMD_FAILED;
|
return ECMD_FAILED;
|
||||||
}
|
}
|
||||||
@ -4396,7 +4396,7 @@ int process_each_pv(struct cmd_context *cmd,
|
|||||||
|
|
||||||
process_all_pvs = dm_list_empty(&arg_pvnames) && dm_list_empty(&arg_tags);
|
process_all_pvs = dm_list_empty(&arg_pvnames) && dm_list_empty(&arg_tags);
|
||||||
|
|
||||||
process_all_devices = process_all_pvs && (cmd->command->flags & ENABLE_ALL_DEVS) && all_is_set;
|
process_all_devices = process_all_pvs && (cmd->cname->flags & ENABLE_ALL_DEVS) && all_is_set;
|
||||||
|
|
||||||
/* Needed for a current listing of the global VG namespace. */
|
/* Needed for a current listing of the global VG namespace. */
|
||||||
if (!only_this_vgname && !lockd_gl(cmd, "sh", 0)) {
|
if (!only_this_vgname && !lockd_gl(cmd, "sh", 0)) {
|
||||||
@ -5285,7 +5285,7 @@ int pvcreate_each_device(struct cmd_context *cmd,
|
|||||||
struct pv_list *vgpvl;
|
struct pv_list *vgpvl;
|
||||||
const char *pv_name;
|
const char *pv_name;
|
||||||
int consistent = 0;
|
int consistent = 0;
|
||||||
int must_use_all = (cmd->command->flags & MUST_USE_ALL_ARGS);
|
int must_use_all = (cmd->cname->flags & MUST_USE_ALL_ARGS);
|
||||||
int found;
|
int found;
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
|
||||||
|
@ -1095,7 +1095,7 @@ static int _lockd_vgchange(struct cmd_context *cmd, int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
if (arg_is_set(cmd, systemid_ARG) || arg_is_set(cmd, locktype_ARG))
|
if (arg_is_set(cmd, systemid_ARG) || arg_is_set(cmd, locktype_ARG))
|
||||||
cmd->command->flags &= ~ALL_VGS_IS_DEFAULT;
|
cmd->cname->flags &= ~ALL_VGS_IS_DEFAULT;
|
||||||
|
|
||||||
if (arg_is_set(cmd, systemid_ARG) || arg_is_set(cmd, locktype_ARG)) {
|
if (arg_is_set(cmd, systemid_ARG) || arg_is_set(cmd, locktype_ARG)) {
|
||||||
/*
|
/*
|
||||||
|
@ -240,7 +240,7 @@ int vgimportclone(struct cmd_context *cmd, int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
log_debug("Finding devices to import.");
|
log_debug("Finding devices to import.");
|
||||||
cmd->command->flags |= ENABLE_DUPLICATE_DEVS;
|
cmd->cname->flags |= ENABLE_DUPLICATE_DEVS;
|
||||||
process_each_pv(cmd, argc, argv, NULL, 0, READ_ALLOW_EXPORTED, handle, _vgimportclone_pv_single);
|
process_each_pv(cmd, argc, argv, NULL, 0, READ_ALLOW_EXPORTED, handle, _vgimportclone_pv_single);
|
||||||
|
|
||||||
if (vp.found_args != argc) {
|
if (vp.found_args != argc) {
|
||||||
|
Loading…
Reference in New Issue
Block a user