cmd->autotype = dm_pool_strdup(cmdtool->libmem, line_argv[1]);
}
-#define MAX_RULE_OPTS 64
-
static void _add_rule(struct cmd_context *cmdtool, struct command *cmd,
int line_argc, char *line_argv[])
{
int check = 0;
if (cmd->rule_count == CMD_MAX_RULES) {
- log_error("Parsing command defs: too many rules for cmd.");
+ log_error("Parsing command defs: too many rules for cmd, increate CMD_MAX_RULES.");
cmd->cmd_flags |= CMD_FLAG_PARSE_ERROR;
return;
}
}
else if (!strncmp(arg, "--", 2)) {
- if (!rule->opts) {
- if (!(rule->opts = dm_pool_alloc(cmdtool->libmem, MAX_RULE_OPTS * sizeof(int)))) {
- log_error("Parsing command defs: no mem.");
- cmd->cmd_flags |= CMD_FLAG_PARSE_ERROR;
- return;
- }
- memset(rule->opts, 0, MAX_RULE_OPTS * sizeof(int));
- }
-
- if (!rule->check_opts) {
- if (!(rule->check_opts = dm_pool_alloc(cmdtool->libmem, MAX_RULE_OPTS * sizeof(int)))) {
- log_error("Parsing command defs: no mem.");
- cmd->cmd_flags |= CMD_FLAG_PARSE_ERROR;
- return;
- }
- memset(rule->check_opts, 0, MAX_RULE_OPTS * sizeof(int));
+ if (rule->opts_count >= MAX_RULE_OPTS || rule->check_opts_count >= MAX_RULE_OPTS) {
+ log_error("Parsing command defs: too many cmd_rule options for cmd, increase MAX_RULE_OPTS.");
+ cmd->cmd_flags |= CMD_FLAG_PARSE_ERROR;
+ return;
}
if (check)
#define RULE_INVALID 1
#define RULE_REQUIRE 2
+#define MAX_RULE_OPTS 8
struct cmd_rule {
- int *opts; /* if any option in this list is set, the check may apply */
uint64_t lvt_bits; /* if LV has one of these types (lvt_enum_to_bit), the check may apply */
uint64_t lvp_bits; /* if LV has all of these properties (lvp_enum_to_bit), the check may apply */
- int *check_opts; /* used options must [not] be in this list */
uint64_t check_lvt_bits; /* LV must [not] have one of these type */
uint64_t check_lvp_bits; /* LV must [not] have all of these properties */
+ uint16_t opts[MAX_RULE_OPTS]; /* if any option in this list is set, the check may apply */
+ uint16_t check_opts[MAX_RULE_OPTS];/* used options must [not] be in this list */
+
uint16_t rule; /* RULE_INVALID, RULE_REQUIRE: check values must [not] be true */
uint16_t opts_count; /* entries in opts[] */
uint16_t check_opts_count; /* entries in check_opts[] */
.origin_list = DM_LIST_HEAD_INIT(_historical_lv_segment.origin_list),
};
-int opt_in_list_is_set(struct cmd_context *cmd, int *opts, int count,
+int opt_in_list_is_set(struct cmd_context *cmd, const uint16_t *opts, int count,
int *match_count, int *unmatch_count)
{
int match = 0;
return match ? 1 : 0;
}
-void opt_array_to_str(struct cmd_context *cmd, int *opts, int count,
+void opt_array_to_str(struct cmd_context *cmd, const uint16_t *opts, int count,
char *buf, int len)
{
int pos = 0;
* Check the options, LV types, LV properties.
*/
- if (rule->check_opts)
+ if (rule->check_opts_count)
opt_in_list_is_set(cmd, rule->check_opts, rule->check_opts_count,
&opts_match_count, &opts_unmatch_count);
/* Fail if any invalid options are set. */
- if (rule->check_opts && (rule->rule == RULE_INVALID) && opts_match_count) {
+ if (rule->check_opts_count && (rule->rule == RULE_INVALID) && opts_match_count) {
memset(buf, 0, sizeof(buf));
opt_array_to_str(cmd, rule->check_opts, rule->check_opts_count, buf, sizeof(buf));
log_warn("WARNING: Command on LV %s has invalid use of option %s.",
/* Fail if any required options are not set. */
- if (rule->check_opts && (rule->rule == RULE_REQUIRE) && opts_unmatch_count) {
+ if (rule->check_opts_count && (rule->rule == RULE_REQUIRE) && opts_unmatch_count) {
memset(buf, 0, sizeof(buf));
opt_array_to_str(cmd, rule->check_opts, rule->check_opts_count, buf, sizeof(buf));
log_warn("WARNING: Command on LV %s requires option %s.",
const char *skip_dev_dir(struct cmd_context *cmd, const char *vg_name,
unsigned *dev_dir_found);
-int opt_in_list_is_set(struct cmd_context *cmd, int *opts, int count,
+int opt_in_list_is_set(struct cmd_context *cmd, const uint16_t *opts, int count,
int *match_count, int *unmatch_count);
-void opt_array_to_str(struct cmd_context *cmd, int *opts, int count,
+void opt_array_to_str(struct cmd_context *cmd, const uint16_t *opts, int count,
char *buf, int len);
int pvcreate_params_from_args(struct cmd_context *cmd, struct pvcreate_params *pp);