mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-30 17:18:21 +03:00
command: more static const declaration
Use static const for declared arrays. Access to arrays through get_ functions().
This commit is contained in:
parent
d2f953c9db
commit
45d9b2c470
@ -39,7 +39,7 @@ struct cmd_name {
|
||||
|
||||
/* create table of value names, e.g. String, and corresponding enum from vals.h */
|
||||
|
||||
const struct val_name val_names[VAL_COUNT + 1] = {
|
||||
static const struct val_name val_names[VAL_COUNT + 1] = {
|
||||
#define val(a, b, c, d) { # a, a, b, c, d },
|
||||
#include "vals.h"
|
||||
#undef val
|
||||
@ -47,7 +47,7 @@ const struct val_name val_names[VAL_COUNT + 1] = {
|
||||
|
||||
/* create table of option names, e.g. --foo, and corresponding enum from args.h */
|
||||
|
||||
struct opt_name opt_names[ARG_COUNT + 1] = {
|
||||
static struct opt_name opt_names[ARG_COUNT + 1] = {
|
||||
#define arg(a, b, c, d, e, f, g) { # a, a, b, "", "--" c, d, e, f, g },
|
||||
#include "args.h"
|
||||
#undef arg
|
||||
@ -55,7 +55,7 @@ struct opt_name opt_names[ARG_COUNT + 1] = {
|
||||
|
||||
/* create table of lv property names, e.g. lv_is_foo, and corresponding enum from lv_props.h */
|
||||
|
||||
const struct lv_prop lv_props[LVP_COUNT + 1] = {
|
||||
static const struct lv_prop lv_props[LVP_COUNT + 1] = {
|
||||
#define lvp(a, b, c) { # a, a, b, c },
|
||||
#include "lv_props.h"
|
||||
#undef lvp
|
||||
@ -63,7 +63,7 @@ const struct lv_prop lv_props[LVP_COUNT + 1] = {
|
||||
|
||||
/* create table of lv type names, e.g. linear and corresponding enum from lv_types.h */
|
||||
|
||||
const struct lv_type lv_types[LVT_COUNT + 1] = {
|
||||
static const struct lv_type lv_types[LVT_COUNT + 1] = {
|
||||
#define lvt(a, b, c) { # a, a, b, c },
|
||||
#include "lv_types.h"
|
||||
#undef lvt
|
||||
@ -71,7 +71,7 @@ const struct lv_type lv_types[LVT_COUNT + 1] = {
|
||||
|
||||
/* create table of command IDs */
|
||||
|
||||
const struct cmd_name cmd_names[CMD_COUNT + 1] = {
|
||||
static const struct cmd_name cmd_names[CMD_COUNT + 1] = {
|
||||
#define cmd(a, b) { # a, a, # b },
|
||||
#include "../include/cmds.h"
|
||||
#undef cmd
|
||||
@ -102,6 +102,30 @@ struct command_name command_names[] = {
|
||||
};
|
||||
extern struct command commands[COMMAND_COUNT]; /* defined in lvmcmdline.c */
|
||||
|
||||
const struct opt_name *get_opt_name(int opt)
|
||||
{
|
||||
return &opt_names[opt];
|
||||
}
|
||||
|
||||
const struct val_name *get_val_name(int val)
|
||||
{
|
||||
return &val_names[val];
|
||||
}
|
||||
|
||||
const struct lv_prop *get_lv_prop(int lvp_enum)
|
||||
{
|
||||
if (!lvp_enum)
|
||||
return NULL;
|
||||
return &lv_props[lvp_enum];
|
||||
}
|
||||
|
||||
const struct lv_type *get_lv_type(int lvt_enum)
|
||||
{
|
||||
if (!lvt_enum)
|
||||
return NULL;
|
||||
return &lv_types[lvt_enum];
|
||||
}
|
||||
|
||||
#endif /* MAN_PAGE_GENERATOR */
|
||||
|
||||
/* array of pointers into opt_names[] that is sorted alphabetically (by long opt name) */
|
||||
|
@ -2869,7 +2869,7 @@ static int _lvconvert_swap_pool_metadata(struct cmd_context *cmd,
|
||||
struct volume_group *vg = lv->vg;
|
||||
struct logical_volume *prev_metadata_lv;
|
||||
struct lv_segment *seg;
|
||||
struct lv_type *lvtype;
|
||||
const struct lv_type *lvtype;
|
||||
char meta_name[NAME_LEN];
|
||||
const char *swap_lock_args = NULL;
|
||||
uint32_t chunk_size;
|
||||
@ -4618,7 +4618,7 @@ static int _lvconvert_cachepool_attach_single(struct cmd_context *cmd,
|
||||
|
||||
if (!lv_is_cache_pool(cachepool_lv)) {
|
||||
int lvt_enum = get_lvt_enum(cachepool_lv);
|
||||
struct lv_type *lvtype = get_lv_type(lvt_enum);
|
||||
const struct lv_type *lvtype = get_lv_type(lvt_enum);
|
||||
|
||||
if (lvt_enum != striped_LVT && lvt_enum != linear_LVT && lvt_enum != raid_LVT) {
|
||||
log_error("LV %s with type %s cannot be converted to a cache pool.",
|
||||
@ -4724,7 +4724,7 @@ static int _lvconvert_to_thin_with_external_single(struct cmd_context *cmd,
|
||||
|
||||
if (!lv_is_thin_pool(thinpool_lv)) {
|
||||
int lvt_enum = get_lvt_enum(thinpool_lv);
|
||||
struct lv_type *lvtype = get_lv_type(lvt_enum);
|
||||
const struct lv_type *lvtype = get_lv_type(lvt_enum);
|
||||
|
||||
if (lvt_enum != striped_LVT && lvt_enum != linear_LVT && lvt_enum != raid_LVT) {
|
||||
log_error("LV %s with type %s cannot be converted to a thin pool.",
|
||||
@ -4873,7 +4873,7 @@ static int _lvconvert_to_pool_or_swap_metadata_single(struct cmd_context *cmd,
|
||||
int to_thinpool = 0;
|
||||
int to_cachepool = 0;
|
||||
int lvt_enum = get_lvt_enum(lv);
|
||||
struct lv_type *lvtype;
|
||||
const struct lv_type *lvtype;
|
||||
|
||||
switch (cmd->command->command_enum) {
|
||||
case lvconvert_to_thinpool_or_swap_metadata_CMD:
|
||||
@ -5204,7 +5204,7 @@ static int _lvconvert_raid_types_check(struct cmd_context *cmd, struct logical_v
|
||||
int lv_is_named_arg)
|
||||
{
|
||||
int lvt_enum = get_lvt_enum(lv);
|
||||
struct lv_type *lvtype = get_lv_type(lvt_enum);
|
||||
const struct lv_type *lvtype = get_lv_type(lvt_enum);
|
||||
|
||||
if (!lv_is_visible(lv)) {
|
||||
if (!lv_is_cache_pool_metadata(lv) &&
|
||||
|
@ -19,7 +19,7 @@
|
||||
struct cmd_context;
|
||||
|
||||
struct cmdline_context {
|
||||
struct opt_name *opt_names;
|
||||
const struct opt_name *opt_names;
|
||||
struct command *commands;
|
||||
int num_commands;
|
||||
struct command_name *command_names;
|
||||
|
@ -49,26 +49,6 @@ extern char *optarg;
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Table of valid --option values.
|
||||
*/
|
||||
extern struct val_name val_names[VAL_COUNT + 1];
|
||||
|
||||
/*
|
||||
* Table of valid --option's
|
||||
*/
|
||||
extern struct opt_name opt_names[ARG_COUNT + 1];
|
||||
|
||||
/*
|
||||
* Table of LV properties
|
||||
*/
|
||||
extern struct lv_prop lv_props[LVP_COUNT + 1];
|
||||
|
||||
/*
|
||||
* Table of LV types
|
||||
*/
|
||||
extern struct lv_type lv_types[LVT_COUNT + 1];
|
||||
|
||||
/*
|
||||
* Table of command names
|
||||
*/
|
||||
@ -1409,20 +1389,6 @@ int lvm_register_commands(struct cmd_context *cmd, const char *run_name)
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct lv_prop *get_lv_prop(int lvp_enum)
|
||||
{
|
||||
if (!lvp_enum)
|
||||
return NULL;
|
||||
return &lv_props[lvp_enum];
|
||||
}
|
||||
|
||||
struct lv_type *get_lv_type(int lvt_enum)
|
||||
{
|
||||
if (!lvt_enum)
|
||||
return NULL;
|
||||
return &lv_types[lvt_enum];
|
||||
}
|
||||
|
||||
struct command *get_command(int cmd_enum)
|
||||
{
|
||||
int i;
|
||||
@ -2159,7 +2125,7 @@ static void _usage_all(void)
|
||||
|
||||
static void _add_getopt_arg(int opt_enum, char **optstrp, struct option **longoptsp)
|
||||
{
|
||||
struct opt_name *a = _cmdline.opt_names + opt_enum;
|
||||
const struct opt_name *a = _cmdline.opt_names + opt_enum;
|
||||
|
||||
if (a->short_opt) {
|
||||
*(*optstrp)++ = a->short_opt;
|
||||
@ -2242,7 +2208,7 @@ static int _process_command_line(struct cmd_context *cmd, int *argc, char ***arg
|
||||
{
|
||||
char str[((ARG_COUNT + 1) * 2) + 1], *ptr = str;
|
||||
struct option opts[ARG_COUNT + 1], *o = opts;
|
||||
struct opt_name *a;
|
||||
const struct opt_name *a;
|
||||
struct arg_values *av;
|
||||
struct arg_value_group_list *current_group = NULL;
|
||||
int arg_enum; /* e.g. foo_ARG */
|
||||
@ -2338,7 +2304,7 @@ static int _process_command_line(struct cmd_context *cmd, int *argc, char ***arg
|
||||
|
||||
av->value = optarg;
|
||||
|
||||
if (!val_names[a->val_enum].fn(cmd, av)) {
|
||||
if (!get_val_name(a->val_enum)->fn(cmd, av)) {
|
||||
log_error("Invalid argument for %s: %s", a->long_opt, optarg);
|
||||
return 0;
|
||||
}
|
||||
@ -3518,7 +3484,7 @@ struct cmd_context *init_lvm(unsigned set_connections,
|
||||
return_NULL;
|
||||
}
|
||||
|
||||
_cmdline.opt_names = &opt_names[0];
|
||||
_cmdline.opt_names = get_opt_name(0);
|
||||
|
||||
if (stored_errno()) {
|
||||
destroy_toolcontext(cmd);
|
||||
|
@ -2653,7 +2653,7 @@ void opt_array_to_str(struct cmd_context *cmd, int *opts, int count,
|
||||
|
||||
static void _lvp_bits_to_str(uint64_t bits, char *buf, int len)
|
||||
{
|
||||
struct lv_prop *prop;
|
||||
const struct lv_prop *prop;
|
||||
int lvp_enum;
|
||||
int pos = 0;
|
||||
int ret;
|
||||
@ -2674,7 +2674,7 @@ static void _lvp_bits_to_str(uint64_t bits, char *buf, int len)
|
||||
|
||||
static void _lvt_bits_to_str(uint64_t bits, char *buf, int len)
|
||||
{
|
||||
struct lv_type *type;
|
||||
const struct lv_type *type;
|
||||
int lvt_enum;
|
||||
int pos = 0;
|
||||
int ret;
|
||||
@ -2910,7 +2910,7 @@ int get_lvt_enum(struct logical_volume *lv)
|
||||
static int _lv_types_match(struct cmd_context *cmd, struct logical_volume *lv, uint64_t lvt_bits,
|
||||
uint64_t *match_bits, uint64_t *unmatch_bits)
|
||||
{
|
||||
struct lv_type *type;
|
||||
const struct lv_type *type;
|
||||
int lvt_enum;
|
||||
int found_a_match = 0;
|
||||
int match;
|
||||
@ -2959,7 +2959,7 @@ static int _lv_types_match(struct cmd_context *cmd, struct logical_volume *lv, u
|
||||
static int _lv_props_match(struct cmd_context *cmd, struct logical_volume *lv, uint64_t lvp_bits,
|
||||
uint64_t *match_bits, uint64_t *unmatch_bits)
|
||||
{
|
||||
struct lv_prop *prop;
|
||||
const struct lv_prop *prop;
|
||||
int lvp_enum;
|
||||
int found_a_mismatch = 0;
|
||||
int match;
|
||||
@ -3014,7 +3014,7 @@ static int _check_lv_types(struct cmd_context *cmd, struct logical_volume *lv, i
|
||||
ret = _lv_types_match(cmd, lv, cmd->command->required_pos_args[pos-1].def.lvt_bits, NULL, NULL);
|
||||
if (!ret) {
|
||||
int lvt_enum = get_lvt_enum(lv);
|
||||
struct lv_type *type = get_lv_type(lvt_enum);
|
||||
const struct lv_type *type = get_lv_type(lvt_enum);
|
||||
if (!type) {
|
||||
log_warn("WARNING: Command on LV %s does not accept LV type unknown (%d).",
|
||||
display_lvname(lv), lvt_enum);
|
||||
@ -3032,8 +3032,8 @@ static int _check_lv_types(struct cmd_context *cmd, struct logical_volume *lv, i
|
||||
static int _check_lv_rules(struct cmd_context *cmd, struct logical_volume *lv)
|
||||
{
|
||||
char buf[64];
|
||||
struct cmd_rule *rule;
|
||||
struct lv_type *lvtype = NULL;
|
||||
const struct cmd_rule *rule;
|
||||
const struct lv_type *lvtype = NULL;
|
||||
uint64_t lv_props_match_bits = 0, lv_props_unmatch_bits = 0;
|
||||
uint64_t lv_types_match_bits = 0, lv_types_unmatch_bits = 0;
|
||||
int opts_match_count = 0, opts_unmatch_count = 0;
|
||||
|
@ -172,8 +172,10 @@ int vgchange_locktype_cmd(struct cmd_context *cmd, int argc, char **argv);
|
||||
int vgchange_lock_start_stop_cmd(struct cmd_context *cmd, int argc, char **argv);
|
||||
int vgchange_systemid_cmd(struct cmd_context *cmd, int argc, char **argv);
|
||||
|
||||
struct lv_prop *get_lv_prop(int lvp_enum);
|
||||
struct lv_type *get_lv_type(int lvt_enum);
|
||||
const struct opt_name *get_opt_name(int opt);
|
||||
const struct val_name *get_val_name(int val);
|
||||
const struct lv_prop *get_lv_prop(int lvp_enum);
|
||||
const struct lv_type *get_lv_type(int lvt_enum);
|
||||
struct command *get_command(int cmd_enum);
|
||||
|
||||
int lvchange_properties_cmd(struct cmd_context *cmd, int argc, char **argv);
|
||||
|
Loading…
Reference in New Issue
Block a user