master - args: add priorities for grouping args
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=d23c5b93183675199ff78ff288e4bbd12f935515 Commit: d23c5b93183675199ff78ff288e4bbd12f935515 Parent: 9c37b7ed7c33bb6e66daf369fd563c52f6743282 Author: Peter Rajnoha <[email protected]> AuthorDate: Fri Jun 17 11:03:14 2016 +0200 Committer: Peter Rajnoha <[email protected]> CommitterDate: Mon Jun 20 11:33:42 2016 +0200
args: add priorities for grouping args
Groupable args (the ones marked with ARG_GROUPABLE flag) start a new group of args if:
- this is the first time we hit such a groupable arg,
- or if non-countable arg is repeated.
However, there may be cases where we want to give priorities when forming groups and hence force new group creation if we hit an arg with higher grouping priority.
For example, let's assume (for now) hypothetical sequence of args used:
lvs -o lv_name --configreport log -o log_type --configreport lv -o +vg_name
Without giving any priorites, we end up with:
lvs -o lv_name --configreport log -o log_type --configreport lv -o +vg_name
| | | | | |
\__________GROUP1___________/ \________GROUP2___________/ \_GROUP3_/This is because we hit "-o" as the first groupable arg. The --configreport, even though it's groupable too, it falls into the previous "-o" group.
While we may need to give priority to the --configreport arg that should always start a new group in this scenario instead:
lvs -o lv_name --configreport log -o log_type --configreport lv -o +vg_name
| | | | | |
\_GROUP1_/ \_________GROUP2___________/ \_________GROUP3__________/So here "-o" started a new group but since "--configreport" has higher priority than "-o", it starts fresh new group now and hence the rest of the command line's args are grouped by --configreport now.
--- WHATS_NEW | 1 + tools/args.h | 396 ++++++++++++++++++++++++++-------------------------- tools/lvmcmdline.c | 14 ++- tools/tools.h | 4 +- 4 files changed, 213 insertions(+), 202 deletions(-)
WHATS_NEW +1 -0
@@ -1,5 +1,6 @@ Version 2.02.158 - ================================= + Add support for priorities on grouping command arguments. Add report/{pvs,vgs,lvs,pvsegs,segs}_{cols,sort}_full to lvm.conf. Add lvm fullreport command for joined PV, VG, LV and segment report per VG. Integrate report group handling and cmd log report into cmd processing code.
tools/args.h +198 -198
413 lines not on this page · raw message
tools/lvmcmdline.c +11 -3
@@ -53,7 +53,7 @@ extern char *optarg;* Table of valid switches */ static struct arg_props _arg_props[ARG_COUNT +1 ] = { -#define arg(a, b, c, d, e) {b, "", "--" c, d, e}, +#define arg(a, b, c, d, e, f) {b, "", "--" c, d, e, f}, #include "args.h" #undef arg };
@@ -920,14 +920,22 @@ static int _process_command_line(struct cmd_context *cmd, int *argc, av = &cmd->arg_values[arg];if (a->flags &ARG_GROUPABLE ) { -/* Start a new group of arguments the first time or if a non-countable argument is repeated. */ -if (!current_group || (current_group->arg_values[arg].count && !(a->flags &ARG_COUNTABLE ))) { +/* +* Start a new group of arguments: +* - the first time, +* - or if a non-countable argument is repeated, +* - or if argument has higher priority than current group. +*/ +if (!current_group || + (current_group->arg_values[arg].count && !(a->flags &ARG_COUNTABLE )) || + (current_group->prio < a->prio)) {/* FIXME Reduce size including only groupable args */ if (!(current_group =dm_pool_zalloc (cmd->mem,sizeof (struct arg_value_group_list ) +sizeof (*cmd->arg_values) *ARG_COUNT ))) {log_fatal ("Unable to allocate memory for command line arguments." );return 0 ; } + current_group->prio = a->prio;dm_list_add (&cmd->arg_value_groups, ¤t_group->list); }/* Maintain total argument count as well as count within each group */
tools/tools.h +3 -1
@@ -59,7 +59,7 @@ typedef int (*command_fn) (struct cmd_context * cmd, int argc, char **argv);/* define the enums for the command line switches */ enum { -#define arg(a, b, c, d, e) a , +#define arg(a, b, c, d, e, f) a ,#include "args.h" #undef arg };
@@ -87,11 +87,13 @@ struct arg_props {int (*fn) (struct cmd_context *cmd,struct arg_values *av);uint32_t flags; +uint32_t prio; };struct arg_value_group_list {struct dm_list list;struct arg_values arg_values[0 ]; +uint32_t prio; };#define CACHE_VGMETADATA 0x00000001