1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-22 17:35:59 +03:00
lvm2/man
David Teigland 17a255b8d5 commands: new method for defining commands
. Define a prototype for every lvm command.
. Match every user command with one definition.
. 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, --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
ID: lvresize_by_pv
DESC: Resize an LV by specified PV extents.
FLAGS: SECONDARY_SYNTAX

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

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

The prototype syntax used for help/man output includes
required --option and positional args on the first line,
and optional --option and positional args enclosed in [ ]
on subsequent lines.

  command_name <required_opt_args> <required_pos_args>
          [ <optional_opt_args> ]
          [ <optional_pos_args> ]

$ lvresize --help
  lvresize - Resize a logical volume

  Resize an LV by a specified size.
  lvresize --size Number[m|unit] LV
        [ --resizefs,
          --poolmetadatasize Number[m|unit],
          COMMON_OPTIONS ]
        [ PV ... ]

  Resize a pool metadata SubLV by a specified size.
  lvresize --poolmetadatasize Number[m|unit] LV_thinpool
        [ COMMON_OPTIONS ]
        [ PV ... ]

  Common options:
        [ --alloc contiguous|cling|cling_by_tags|normal|anywhere|inherit,
          --nosync,
          --reportformat String,
          --autobackup y|n,
          --stripes Number,
          --stripesize Number[k|unit],
          --nofsck,
          --commandprofile String,
          --config String,
          --debug,
          --driverloaded y|n,
          --help,
          --profile String,
          --quiet,
          --verbose,
          --version,
          --yes,
          --test,
          --force,
          --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

Command definitions that are not to be advertised/suggested
have the flag SECONDARY_SYNTAX.  These commands will not be
printed in the normal help output.

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 per-command-name
implementation functions.

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-11-03 15:02:55 -05:00
..
blkdeactivate.8.in blkdeactivate: add -m|--mpathoption disablequeueing and use it for blk-availability systemd service and initscript 2016-07-12 10:01:07 +02:00
clvmd.8.in man: update lvm pages 2015-10-01 15:03:34 +02:00
cmirrord.8.in man: improve cmirrord.8 manpage 2015-11-16 01:15:03 +01:00
dmeventd.8.in dmeventd: support logging on stdout 2015-10-13 15:22:57 +02:00
dmsetup.8.in man: fix dmsetup stats 2016-09-26 12:38:32 +02:00
dmstats.8.in man: explain deletion of 1st group member in dmstats.8.in 2016-08-08 19:29:12 +01:00
fsadm.8.in man: fsadm 2015-10-06 15:21:36 +02:00
lvchange.8.in lvchange: Allow device specification when requesting a repair 2016-08-05 16:01:46 +02:00
lvconvert.8.in man: lvconvert mention required option 2016-08-17 14:56:01 -05:00
lvcreate.8.in thin: enforce there is some free space in thin pool metadata 2016-09-19 14:00:56 +02:00
lvdisplay.8.in man: document --configreport, --logonly, --reportformat 2016-06-24 14:51:20 +02:00
lvextend.8.in man: document --configreport, --logonly, --reportformat 2016-06-24 14:51:20 +02:00
lvm2-activation-generator.8.in systemd: use {local,remote}-fs-pre.target instead of {local,remote}-fs.target 2015-09-23 13:30:51 +02:00
lvm-config.8.in man: Fix recursive lvm-config man page. 2015-05-07 12:07:40 +01:00
lvm-dumpconfig.8.in config: Introduce lvmconfig. 2015-04-28 17:00:37 +01:00
lvm-fullreport.8.in man: add lvm fullreport man page 2016-08-09 18:49:11 +02:00
lvm-lvpoll.8.in lvm-lvpoll.8.in: man page for built-in command 2015-05-15 20:32:16 +02:00
lvm.8.in man: Additional info on exit statuses. 2016-09-07 01:57:09 +01:00
lvm.conf.5.in man: add lvmlocal.conf to config cascade 2015-07-08 10:02:28 -07:00
lvmcache.7.in man lvmcache: include chunk size 2015-11-23 11:57:41 -06:00
lvmchange.8.in man: properly escape - 2014-06-11 11:10:55 +02:00
lvmconf.8.in man: drop superfluous '--' in lvmconf man page for --enable/disable-halvm 2015-09-22 14:28:31 +02:00
lvmconfig.8.in man: lvmconfig: add note about --type diff and --mergedconfig 2016-06-02 14:07:07 +02:00
lvmdbusd.8.in lvmdbus: Add new daemon. 2016-02-17 23:53:35 +00:00
lvmdiskscan.8.in man: properly escape - 2014-06-11 11:10:55 +02:00
lvmdump.8.in lvmdump: also collect output from lsblk command when running lvmdump -s 2016-06-09 13:54:15 +02:00
lvmetad.8.in man: include info about disabled lvmetad 2016-08-03 15:42:12 -05:00
lvmlockctl.8.in man lvmlockctl: add man page 2015-09-04 11:05:13 -05:00
lvmlockd.8.in man lvmlockd: mention pvmove restriction 2016-01-12 12:01:53 -06:00
lvmpolld.8.in lvmpolld.8.in: add missing space 2015-09-02 17:24:34 +02:00
lvmraid.7.in man lvmraid: comment out unfinished features 2016-09-06 15:13:59 -05:00
lvmreport.7.in man: add lvmreport man page 2016-09-12 14:11:39 +02:00
lvmsadc.8.in man: properly escape - 2014-06-11 11:10:55 +02:00
lvmsar.8.in man: properly escape - 2014-06-11 11:10:55 +02:00
lvmsystemid.7.in doc: describe lvmlockd/lvmpolld features as available if LVM compiled with lockd/polld support 2016-03-30 14:10:56 +02:00
lvmthin.7.in man: lvmthin clean up syntax example 2016-07-27 13:13:59 -05:00
lvreduce.8.in man: document --configreport, --logonly, --reportformat 2016-06-24 14:51:20 +02:00
lvremove.8.in man: document --configreport, --logonly, --reportformat 2016-06-24 14:51:20 +02:00
lvrename.8.in man: document --configreport, --logonly, --reportformat 2016-06-24 14:51:20 +02:00
lvresize.8.in man: document --configreport, --logonly, --reportformat 2016-06-24 14:51:20 +02:00
lvs.8.in man: fix references to names for --configreport arg in pvs, vgs and lvs man page 2016-08-09 18:49:11 +02:00
lvscan.8.in man: document --configreport, --logonly, --reportformat 2016-06-24 14:51:20 +02:00
Makefile.in commands: new method for defining commands 2016-11-03 15:02:55 -05:00
pvchange.8.in man: document --configreport, --logonly, --reportformat 2016-06-24 14:51:20 +02:00
pvck.8.in man: properly escape - 2014-06-11 11:10:55 +02:00
pvcreate.8.in man: document --configreport, --logonly, --reportformat 2016-06-24 14:51:20 +02:00
pvdisplay.8.in man: document --configreport, --logonly, --reportformat 2016-06-24 14:51:20 +02:00
pvmove.8.in man: document --configreport, --logonly, --reportformat 2016-06-24 14:51:20 +02:00
pvremove.8.in man: document --configreport, --logonly, --reportformat 2016-06-24 14:51:20 +02:00
pvresize.8.in man: document --configreport, --logonly, --reportformat 2016-06-24 14:51:20 +02:00
pvs.8.in man: fix references to names for --configreport arg in pvs, vgs and lvs man page 2016-08-09 18:49:11 +02:00
pvscan.8.in man: minor corrections in pvscan 2016-08-03 15:49:43 -05:00
vgcfgbackup.8.in man: document --configreport, --logonly, --reportformat 2016-06-24 14:51:20 +02:00
vgcfgrestore.8.in man: properly escape - 2014-06-11 11:10:55 +02:00
vgchange.8.in man: document --configreport, --logonly, --reportformat 2016-06-24 14:51:20 +02:00
vgck.8.in man: document --configreport, --logonly, --reportformat 2016-06-24 14:51:20 +02:00
vgconvert.8.in man: document --configreport, --logonly, --reportformat 2016-06-24 14:51:20 +02:00
vgcreate.8.in man: document --configreport, --logonly, --reportformat 2016-06-24 14:51:20 +02:00
vgdisplay.8.in man: document --configreport, --logonly, --reportformat 2016-06-24 14:51:20 +02:00
vgexport.8.in man: document --configreport, --logonly, --reportformat 2016-06-24 14:51:20 +02:00
vgextend.8.in man: document --configreport, --logonly, --reportformat 2016-06-24 14:51:20 +02:00
vgimport.8.in man: document --configreport, --logonly, --reportformat 2016-06-24 14:51:20 +02:00
vgimportclone.8.in man: properly escape - 2014-06-11 11:10:55 +02:00
vgmerge.8.in man: properly escape - 2014-06-11 11:10:55 +02:00
vgmknodes.8.in man: document --configreport, --logonly, --reportformat 2016-06-24 14:51:20 +02:00
vgreduce.8.in man: document --configreport, --logonly, --reportformat 2016-06-24 14:51:20 +02:00
vgremove.8.in man: document --configreport, --logonly, --reportformat 2016-06-24 14:51:20 +02:00
vgrename.8.in man: document --configreport, --logonly, --reportformat 2016-06-24 14:51:20 +02:00
vgs.8.in man: fix references to names for --configreport arg in pvs, vgs and lvs man page 2016-08-09 18:49:11 +02:00
vgscan.8.in man: document --configreport, --logonly, --reportformat 2016-06-24 14:51:20 +02:00
vgsplit.8.in man: properly escape - 2014-06-11 11:10:55 +02:00