1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00
lvm2/scripts
David Teigland 20773abea0 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-20 13:40:27 -05:00
..
lvm2create_initrd doc: change fsf address 2016-01-21 12:11:37 +01:00
.gitignore gitignore: Update for in-place build. 2015-07-27 13:18:35 +01:00
blk_availability_init_red_hat.in blkdeactivate: add -m|--mpathoption disablequeueing and use it for blk-availability systemd service and initscript 2016-07-12 10:01:07 +02:00
blk_availability_systemd_red_hat.service.in blkdeactivate: add -m|--mpathoption disablequeueing and use it for blk-availability systemd service and initscript 2016-07-12 10:01:07 +02:00
blkdeactivate.sh.in scripts: blkdeactivate: fix typo for DEV_DIR when executing blkdeactivate -m disablequeueing 2016-07-20 13:48:59 +02:00
clvmd_fix_conf.sh Use /bin/bash for scripts with bashisms 2010-05-14 11:33:20 +00:00
clvmd_init_red_hat.in scripts: clvmd: replace awk functionality with LVM's selection 2015-01-09 16:41:07 +01:00
cmirrord_init_red_hat.in initscripts: add pidfile reference in chkconfig header for clvmd and cmirrord 2013-06-07 14:07:56 +02:00
com.redhat.lvmdbus1.conf lvmdbus: Add new daemon. 2016-02-17 23:53:35 +00:00
com.redhat.lvmdbus1.service.in dbus: fix the systemd service providing the DBus service 2016-02-26 10:20:08 +01:00
command-lines.in commands: new method for defining commands 2016-10-20 13:40:27 -05:00
create-commands.c commands: new method for defining commands 2016-10-20 13:40:27 -05:00
dm_event_systemd_red_hat.service.in systemd: use {local,remote}-fs-pre.target instead of {local,remote}-fs.target 2015-09-23 13:30:51 +02:00
dm_event_systemd_red_hat.socket.in systemd: use RemoveOnStop for dm-event.socket and lvm2-lvmetad.socket 2014-06-13 15:45:25 +02:00
fsadm.sh fsadm: use stat to get major:minor pair for non-standard /dev layouts 2016-03-18 17:21:47 +01:00
gdbinit doc: change fsf address 2016-01-21 12:11:37 +01:00
lvm2_activation_generator_systemd_red_hat.c systemd: fix extra space in unit generated by lvm2-activation-generator 2016-09-26 09:54:19 +02:00
lvm2_cluster_activation_red_hat.sh.in scripts: clvmd: replace awk functionality with LVM's selection 2015-01-09 16:41:07 +01:00
lvm2_cluster_activation_systemd_red_hat.service.in systemd: do not use default dependencies for clvmd/cmirrord units 2014-02-14 14:37:19 +01:00
lvm2_clvmd_systemd_red_hat.service.in systemd: use {local,remote}-fs-pre.target instead of {local,remote}-fs.target 2015-09-23 13:30:51 +02:00
lvm2_cmirrord_systemd_red_hat.service.in systemd: use {local,remote}-fs-pre.target instead of {local,remote}-fs.target 2015-09-23 13:30:51 +02:00
lvm2_lvmdbusd_systemd_red_hat.service.in lvmdbusd: Remove --udev in service file 2016-03-21 17:28:51 -05:00
lvm2_lvmetad_init_red_hat.in doc: change fsf address 2016-01-21 12:11:37 +01:00
lvm2_lvmetad_systemd_red_hat.service.in systemd: cleanup for lvmetad systemd unit 2014-02-10 16:20:45 +01:00
lvm2_lvmetad_systemd_red_hat.socket.in systemd: use RemoveOnStop for dm-event.socket and lvm2-lvmetad.socket 2014-06-13 15:45:25 +02:00
lvm2_lvmlockd_systemd_red_hat.service.in Add lvmlockd 2015-07-02 15:42:26 -05:00
lvm2_lvmlocking_systemd_red_hat.service.in Add lvmlockd 2015-07-02 15:42:26 -05:00
lvm2_lvmpolld_init_red_hat.in doc: change fsf address 2016-01-21 12:11:37 +01:00
lvm2_lvmpolld_systemd_red_hat.service.in lvmpolld: Add standalone polldaemon. 2015-05-09 00:59:18 +01:00
lvm2_lvmpolld_systemd_red_hat.socket.in lvmpolld: Add standalone polldaemon. 2015-05-09 00:59:18 +01:00
lvm2_monitoring_init_red_hat.in doc: change fsf address 2016-01-21 12:11:37 +01:00
lvm2_monitoring_init_rhel4 doc: change fsf address 2016-01-21 12:11:37 +01:00
lvm2_monitoring_systemd_red_hat.service.in systemd: use {local,remote}-fs-pre.target instead of {local,remote}-fs.target 2015-09-23 13:30:51 +02:00
lvm2_pvscan_systemd_red_hat@.service.in systemd: disable service start rate limiting for lvm2-pvscan@.service 2016-09-27 10:48:01 +02:00
lvm2_tmpfiles_red_hat.conf.in Use 'd' instead of 'D' in tmpfiles configuration to not overwrite any existing directory. 2012-02-23 14:24:30 +00:00
lvmconf_lockingtype2.sh doc: change fsf address 2016-01-21 12:11:37 +01:00
lvmconf.sh doc: change fsf address 2016-01-21 12:11:37 +01:00
lvmdump.sh.in lvmdump: Use O_DIRECT to gather metadata. 2016-09-15 14:00:39 +01:00
Makefile.in make: also clean up lvmdump.sh with substitutions - there's original lvmdump.sh.in 2016-09-23 12:48:52 +02:00
relpath.awk doc: change fsf address 2016-01-21 12:11:37 +01:00
vg_convert change two files in different directories 2006-06-06 17:44:11 +00:00
vgimportclone.sh vgimportclone: fix VG name variable reference in error message after failed PV uuid change 2016-01-21 14:47:48 +01:00
VolumeGroup.ocf Add OCF support 2010-11-05 16:18:38 +00:00