1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-22 17:35:59 +03:00
lvm2/tools
David Teigland d1a149b51d commands: new method for defining commands
. Define a prototype for every lvm command.
. Verify every user command matches one.
. Generate help text and man pages from them.

The new file command-lines.in defines a prototype for every
unique lvm command.  A unique lvm command is a unique
combination of: command name + required option args +
required positional args.  Each of these prototypes also
includes the optional option args and optional positional
args that the command will accept, a description, and a
unique string ID for the definition.  Any valid command
will match one of the prototypes.

Here's an example of the lvresize command definitions from
command-lines.in, there are three unique lvresize commands:

lvresize --size SizeMB LV
OO: --alloc Alloc, --autobackup Bool, --force,
--nofsck, --nosync, --noudevsync, --reportformat String, --resizefs,
--stripes Number, --stripesize SizeKB, --test, --poolmetadatasize SizeMB
OP: PV ...
ID: lvresize_by_size
DESC: Resize an LV by a specified size.

lvresize LV PV ...
OO: --alloc Alloc, --autobackup Bool, --force,
--nofsck, --nosync, --noudevsync,
--reportformat String, --resizefs, --stripes Number, --stripesize SizeKB,
--test
ID: lvresize_by_pv
DESC: Resize an LV by a specified PV.

lvresize --poolmetadatasize SizeMB LV_thinpool
OO: --alloc Alloc, --autobackup Bool, --force,
--nofsck, --nosync, --noudevsync,
--reportformat String, --stripes Number, --stripesize SizeKB,
--test
OP: PV ...
ID: lvresize_pool_metadata_by_size
DESC: Resize the metadata SubLV of a pool LV.

The three commands have separate definitions because they have
different required parameters.  Required parameters are specified
on the first line of the definition.  Optional options are
listed after OO, and optional positional args are listed after OP.

This data is used to generate corresponding command definition
structures for lvm in command-lines.h.  "usage" text is also
generated, so it is always in sync with the definitions.

Example of the corresponding generated structure in
command-lines.h for the first lvresize prototype
(these structures are never edited directly):

commands[78].name = "lvresize";
commands[78].command_line_id = "lvresize_by_size";
commands[78].command_line_enum = lvresize_by_size_CMD;
commands[78].fn = lvresize;
commands[78].ro_count = 1;
commands[78].rp_count = 1;
commands[78].oo_count = 22;
commands[78].op_count = 1;
commands[78].desc = "DESC: Resize an LV by a specified size.";
commands[78].usage = "lvresize --size Number[m|unit] LV"
" [ --alloc contiguous|cling|normal|anywhere|inherit,
   --autobackup y|n, --nofsck, --nosync, --reportformat String,
   --resizefs, --stripes Number, --stripesize Number[k|unit],
   --poolmetadatasize Number[m|unit] ]"
" [ PV ... ]";
commands[78].usage_common =
" [ --commandprofile String, --config String, --debug,
    --driverloaded y|n, --help, --profile String, --quiet,
    --verbose, --version, --yes, --force, --test, --noudevsync ]";
commands[78].required_opt_args[0].opt = size_ARG;
commands[78].required_opt_args[0].def.val_bits = val_enum_to_bit(sizemb_VAL);
commands[78].required_pos_args[0].pos = 1;
commands[78].required_pos_args[0].def.val_bits = val_enum_to_bit(lv_VAL);
commands[78].optional_opt_args[0].opt = commandprofile_ARG;
commands[78].optional_opt_args[0].def.val_bits = val_enum_to_bit(string_VAL);
commands[78].optional_opt_args[1].opt = config_ARG;
commands[78].optional_opt_args[1].def.val_bits = val_enum_to_bit(string_VAL);
commands[78].optional_opt_args[2].opt = debug_ARG;
commands[78].optional_opt_args[3].opt = driverloaded_ARG;
commands[78].optional_opt_args[3].def.val_bits = val_enum_to_bit(bool_VAL);
commands[78].optional_opt_args[4].opt = help_ARG;
commands[78].optional_opt_args[5].opt = profile_ARG;
commands[78].optional_opt_args[5].def.val_bits = val_enum_to_bit(string_VAL);
commands[78].optional_opt_args[6].opt = quiet_ARG;
commands[78].optional_opt_args[7].opt = verbose_ARG;
commands[78].optional_opt_args[8].opt = version_ARG;
commands[78].optional_opt_args[9].opt = yes_ARG;
commands[78].optional_opt_args[10].opt = alloc_ARG;
commands[78].optional_opt_args[10].def.val_bits = val_enum_to_bit(alloc_VAL);
commands[78].optional_opt_args[11].opt = autobackup_ARG;
commands[78].optional_opt_args[11].def.val_bits = val_enum_to_bit(bool_VAL);
commands[78].optional_opt_args[12].opt = force_ARG;
commands[78].optional_opt_args[13].opt = nofsck_ARG;
commands[78].optional_opt_args[14].opt = nosync_ARG;
commands[78].optional_opt_args[15].opt = noudevsync_ARG;
commands[78].optional_opt_args[16].opt = reportformat_ARG;
commands[78].optional_opt_args[16].def.val_bits = val_enum_to_bit(string_VAL);
commands[78].optional_opt_args[17].opt = resizefs_ARG;
commands[78].optional_opt_args[18].opt = stripes_ARG;
commands[78].optional_opt_args[18].def.val_bits = val_enum_to_bit(number_VAL);
commands[78].optional_opt_args[19].opt = stripesize_ARG;
commands[78].optional_opt_args[19].def.val_bits = val_enum_to_bit(sizekb_VAL);
commands[78].optional_opt_args[20].opt = test_ARG;
commands[78].optional_opt_args[21].opt = poolmetadatasize_ARG;
commands[78].optional_opt_args[21].def.val_bits = val_enum_to_bit(sizemb_VAL);
commands[78].optional_pos_args[0].pos = 2;
commands[78].optional_pos_args[0].def.val_bits = val_enum_to_bit(pv_VAL);
commands[78].optional_pos_args[0].def.flags = ARG_DEF_FLAG_MAY_REPEAT;

Every user-entered command is compared against the set of
command structures, and matched with one.  An error is
reported if an entered command does not have the required
parameters for any definition.  The closest match is printed
as a suggestion, and running lvresize --help will display
the usage for each possible lvresize command, e.g.:

$ lvresize --help
  lvresize - Resize a logical volume

  Resize an LV by a specified size.
  lvresize --size Number[m|unit] LV
  	[ --alloc contiguous|cling|normal|anywhere|inherit,
	  --autobackup y|n,
	  --nofsck,
	  --nosync,
	  --reportformat String,
	  --resizefs,
	  --stripes Number,
	  --stripesize Number[k|unit],
	  --poolmetadatasize Number[m|unit] ]
  	[ PV ... ]

  Resize an LV by a specified PV.
  lvresize LV PV ...
  	[ --alloc contiguous|cling|normal|anywhere|inherit,
	  --autobackup y|n,
	  --nofsck,
	  --nosync,
	  --reportformat String,
	  --resizefs,
	  --stripes Number,
	  --stripesize Number[k|unit] ]

  Resize the metadata SubLV of a pool LV.
  lvresize --poolmetadatasize Number[m|unit] LV_thinpool
  	[ --alloc contiguous|cling|normal|anywhere|inherit,
	  --autobackup y|n,
	  --nofsck,
	  --nosync,
	  --reportformat String,
	  --stripes Number,
	  --stripesize Number[k|unit] ]
  	[ PV ... ]

  Common options:
  	[ --commandprofile String,
	  --config String,
	  --debug,
	  --driverloaded y|n,
	  --help,
	  --profile String,
	  --quiet,
	  --verbose,
	  --version,
	  --yes,
	  --force,
	  --test,
	  --noudevsync ]

  (Use --help --help for usage notes.)

$ lvresize --poolmetadatasize 4
  Failed to find a matching command definition.
  Closest command usage is:
  lvresize --poolmetadatasize Number[m|unit] LV_thinpool

Man page prototypes are also generated from the same original
command definitions, and are always in sync with the code
and help text.

Very early in command execution, a matching command definition
is found.  lvm then knows the operation being done, and that
the provided args conform to the definition.  This will allow
lots of ad hoc checking/validation to be removed throughout
the code.

Each command definition can also be routed to a specific
function to implement it.  The function is associated with
an enum value for the command definition (generated from
the ID string.)  These per-command-definition implementation
functions have not yet been created, so all commands
currently fall back to the existing implementation.

Using per-command-definition functions will allow lots of
code to be removed which tries to figure out what the
command is meant to do.  This is currently based on ad hoc
and complicated option analysis.  When using the new
functions, what the command is doing is already known
from the associated command definition.

So, this first phase validates every user-entered command
against the set of command prototypes, then calls the existing
implementation.  The second phase can associate an implementation
function with each definition, and take further advantage of the
known operation to avoid the complicated option analysis.
2016-10-19 15:09:18 -05:00
..
.exported_symbols generate liblvm2cmd exported symbols too 2010-06-25 18:23:10 +00:00
.gitignore gitignore: Update for in-place build. 2015-07-27 13:18:35 +01:00
args.h commands: new method for defining commands 2016-10-19 15:09:18 -05:00
cmdnames.h doc: change fsf address 2016-01-21 12:11:37 +01:00
command-lines-count.h commands: new method for defining commands 2016-10-19 15:09:18 -05:00
command-lines.h commands: new method for defining commands 2016-10-19 15:09:18 -05:00
command.h commands: new method for defining commands 2016-10-19 15:09:18 -05:00
commands.h commands: new method for defining commands 2016-10-19 15:09:18 -05:00
dmsetup.c coverity: dmsetup: fix possible use of uninitialized value 2016-09-21 15:52:23 +02:00
dumpconfig.c coverity: easier to follow set-up of vsn variable 2016-07-13 21:52:14 +02:00
errors.h doc: change fsf address 2016-01-21 12:11:37 +01:00
formats.c doc: change fsf address 2016-01-21 12:11:37 +01:00
lvchange.c commands: new method for defining commands 2016-10-19 15:09:18 -05:00
lvconvert_poll.c cleanup: substract integers 2016-05-27 15:47:24 +02:00
lvconvert_poll.h doc: change fsf address 2016-01-21 12:11:37 +01:00
lvconvert.c lvconvert: still use strcmp for now 2016-10-12 11:18:23 +02:00
lvcreate.c raid10: Fix #stripes in lvcreate msg when too many. 2016-08-30 12:04:23 +01:00
lvdisplay.c tools: Use arg_is_set instead of arg_count. 2016-06-21 22:24:52 +01:00
lvextend.c doc: change fsf address 2016-01-21 12:11:37 +01:00
lvm2cmd-static.c doc: change fsf address 2016-01-21 12:11:37 +01:00
lvm2cmd.c doc: change fsf address 2016-01-21 12:11:37 +01:00
lvm2cmd.h doc: change fsf address 2016-01-21 12:11:37 +01:00
lvm2cmdline.h commands: new method for defining commands 2016-10-19 15:09:18 -05:00
lvm-static.c doc: change fsf address 2016-01-21 12:11:37 +01:00
lvm.c commands: new method for defining commands 2016-10-19 15:09:18 -05:00
lvmchange.c doc: change fsf address 2016-01-21 12:11:37 +01:00
lvmcmdlib.c commands: new method for defining commands 2016-10-19 15:09:18 -05:00
lvmcmdline.c commands: new method for defining commands 2016-10-19 15:09:18 -05:00
lvmdiskscan.c tools: Use arg_is_set instead of arg_count. 2016-06-21 22:24:52 +01:00
lvpoll.c doc: change fsf address 2016-01-21 12:11:37 +01:00
lvreduce.c doc: change fsf address 2016-01-21 12:11:37 +01:00
lvremove.c lvconvert: use process_each_lv 2016-05-25 15:05:49 -05:00
lvrename.c toollib: make it possible to also process internal VGs, add 'include_internal' switch to process_each_vg fn 2016-06-20 11:33:42 +02:00
lvresize.c lvresize: let pass even protected names like _tmeta 2016-06-24 00:39:14 +02:00
lvscan.c tools: Use arg_is_set instead of arg_count. 2016-06-21 22:24:52 +01:00
Makefile.in vgimportclone: add native command 2016-06-22 13:13:10 -05:00
polldaemon.c toollib: make it possible to also process internal VGs, add 'include_internal' switch to process_each_vg fn 2016-06-20 11:33:42 +02:00
pvchange.c lvmetad: two phase vg_update 2016-06-28 02:30:31 +01:00
pvck.c doc: change fsf address 2016-01-21 12:11:37 +01:00
pvcreate.c lvmetad: two phase vg_update 2016-06-28 02:30:31 +01:00
pvdisplay.c lvmetad: two phase vg_update 2016-06-28 02:30:31 +01:00
pvmove_poll.c doc: change fsf address 2016-01-21 12:11:37 +01:00
pvmove_poll.h doc: change fsf address 2016-01-21 12:11:37 +01:00
pvmove.c pvmove: fix regression introduced with 8e9d5d12ae 2016-08-15 19:31:04 +02:00
pvremove.c lvmetad: two phase vg_update 2016-06-28 02:30:31 +01:00
pvresize.c toollib: add 'parent' field to processing_handle; init report format only if there's no parent 2016-06-20 11:33:41 +02:00
pvscan.c lvmetad: two phase vg_update 2016-06-28 02:30:31 +01:00
reporter.c cache: report metadata percentage 2016-09-09 15:01:35 +02:00
segtypes.c doc: change fsf address 2016-01-21 12:11:37 +01:00
stub.h doc: change fsf address 2016-01-21 12:11:37 +01:00
tags.c doc: change fsf address 2016-01-21 12:11:37 +01:00
tool.h doc: change fsf address 2016-01-21 12:11:37 +01:00
toollib.c commands: new method for defining commands 2016-10-19 15:09:18 -05:00
toollib.h toollib: Record whether or not stripes/stripe_size args supplied. 2016-08-19 13:51:43 +01:00
tools.h commands: new method for defining commands 2016-10-19 15:09:18 -05:00
vals.h commands: new method for defining commands 2016-10-19 15:09:18 -05:00
vgcfgbackup.c tools: Use arg_is_set instead of arg_count. 2016-06-21 22:24:52 +01:00
vgcfgrestore.c lvmetad: two phase vg_update 2016-06-28 02:30:31 +01:00
vgchange.c lvmlockd: improve message for lock-start 2016-07-25 10:43:06 -05:00
vgck.c toollib: make it possible to also process internal VGs, add 'include_internal' switch to process_each_vg fn 2016-06-20 11:33:42 +02:00
vgconvert.c tools: Use arg_is_set instead of arg_count. 2016-06-21 22:24:52 +01:00
vgcreate.c vgcreate: allow pvcreate force option 2016-07-06 14:10:53 -05:00
vgdisplay.c tools: Use arg_is_set instead of arg_count. 2016-06-21 22:24:52 +01:00
vgexport.c tools: Use arg_is_set instead of arg_count. 2016-06-21 22:24:52 +01:00
vgextend.c lvmetad: two phase vg_update 2016-06-28 02:30:31 +01:00
vgimport.c tools: Use arg_is_set instead of arg_count. 2016-06-21 22:24:52 +01:00
vgimportclone.c lvmetad: two phase vg_update 2016-06-28 02:30:31 +01:00
vgmerge.c doc: change fsf address 2016-01-21 12:11:37 +01:00
vgmknodes.c tools: Use arg_is_set instead of arg_count. 2016-06-21 22:24:52 +01:00
vgreduce.c tools: Use arg_is_set instead of arg_count. 2016-06-21 22:24:52 +01:00
vgremove.c toollib: make it possible to also process internal VGs, add 'include_internal' switch to process_each_vg fn 2016-06-20 11:33:42 +02:00
vgrename.c lvmetad: two phase vg_update 2016-06-28 02:30:31 +01:00
vgscan.c lvmetad: two phase vg_update 2016-06-28 02:30:31 +01:00
vgsplit.c vgsplit: fix regression processing thin external origins 2016-08-16 23:57:09 +02:00