1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-10-27 10:25:13 +03:00
lvm2/tools/commands.h
David Teigland 1e2420bca8 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.

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> ]

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.
2017-02-13 08:20:10 -06:00

245 lines
5.9 KiB
C

/*
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
* Copyright (C) 2004-2014 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License v.2.1.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
xx(config,
"Display and manipulate configuration information",
PERMITTED_READ_ONLY | NO_METADATA_PROCESSING)
xx(devtypes,
"Display recognised built-in block device types",
PERMITTED_READ_ONLY | NO_METADATA_PROCESSING)
xx(dumpconfig,
"Display and manipulate configuration information",
PERMITTED_READ_ONLY | NO_METADATA_PROCESSING)
xx(formats,
"List available metadata formats",
PERMITTED_READ_ONLY | NO_METADATA_PROCESSING)
xx(help,
"Display help for commands",
PERMITTED_READ_ONLY | NO_METADATA_PROCESSING)
xx(fullreport,
"Display full report",
PERMITTED_READ_ONLY | ALL_VGS_IS_DEFAULT | LOCKD_VG_SH)
xx(lastlog,
"Display last command's log report",
PERMITTED_READ_ONLY | NO_METADATA_PROCESSING)
xx(lvchange,
"Change the attributes of logical volume(s)",
CACHE_VGMETADATA | PERMITTED_READ_ONLY)
xx(lvconvert,
"Change logical volume layout",
0)
xx(lvcreate,
"Create a logical volume",
0)
xx(lvdisplay,
"Display information about a logical volume",
PERMITTED_READ_ONLY | ALL_VGS_IS_DEFAULT | LOCKD_VG_SH)
xx(lvextend,
"Add space to a logical volume",
0)
xx(lvmchange,
"With the device mapper, this is obsolete and does nothing.",
0)
xx(lvmconfig,
"Display and manipulate configuration information",
PERMITTED_READ_ONLY | NO_METADATA_PROCESSING)
xx(lvmdiskscan,
"List devices that may be used as physical volumes",
PERMITTED_READ_ONLY | ENABLE_ALL_DEVS)
xx(lvmsadc,
"Collect activity data",
0)
xx(lvmsar,
"Create activity report",
0)
xx(lvreduce,
"Reduce the size of a logical volume",
0)
xx(lvremove,
"Remove logical volume(s) from the system",
ALL_VGS_IS_DEFAULT) /* all VGs only with --select */
xx(lvrename,
"Rename a logical volume",
0)
xx(lvresize,
"Resize a logical volume",
0)
xx(lvs,
"Display information about logical volumes",
PERMITTED_READ_ONLY | ALL_VGS_IS_DEFAULT | LOCKD_VG_SH)
xx(lvscan,
"List all logical volumes in all volume groups",
PERMITTED_READ_ONLY | ALL_VGS_IS_DEFAULT | LOCKD_VG_SH | NO_LVMETAD_AUTOSCAN)
xx(pvchange,
"Change attributes of physical volume(s)",
0)
xx(pvresize,
"Resize physical volume(s)",
0)
xx(pvck,
"Check the consistency of physical volume(s)",
LOCKD_VG_SH)
xx(pvcreate,
"Initialize physical volume(s) for use by LVM",
ENABLE_ALL_DEVS)
xx(pvdata,
"Display the on-disk metadata for physical volume(s)",
0)
xx(pvdisplay,
"Display various attributes of physical volume(s)",
CACHE_VGMETADATA | PERMITTED_READ_ONLY | ENABLE_ALL_DEVS | ENABLE_DUPLICATE_DEVS | LOCKD_VG_SH)
/* ALL_VGS_IS_DEFAULT is for polldaemon to find pvmoves in-progress using process_each_vg. */
xx(pvmove,
"Move extents from one physical volume to another",
ALL_VGS_IS_DEFAULT | DISALLOW_TAG_ARGS)
xx(lvpoll,
"Continue already initiated poll operation on a logical volume",
0)
xx(pvremove,
"Remove LVM label(s) from physical volume(s)",
ENABLE_ALL_DEVS)
xx(pvs,
"Display information about physical volumes",
CACHE_VGMETADATA | PERMITTED_READ_ONLY | ALL_VGS_IS_DEFAULT | ENABLE_ALL_DEVS | ENABLE_DUPLICATE_DEVS | LOCKD_VG_SH)
xx(pvscan,
"List all physical volumes",
PERMITTED_READ_ONLY | LOCKD_VG_SH | NO_LVMETAD_AUTOSCAN)
xx(segtypes,
"List available segment types",
PERMITTED_READ_ONLY | NO_METADATA_PROCESSING)
xx(systemid,
"Display the system ID, if any, currently set on this host",
PERMITTED_READ_ONLY | NO_METADATA_PROCESSING)
xx(tags,
"List tags defined on this host",
PERMITTED_READ_ONLY | NO_METADATA_PROCESSING)
xx(vgcfgbackup,
"Backup volume group configuration(s)",
PERMITTED_READ_ONLY | ALL_VGS_IS_DEFAULT | LOCKD_VG_SH)
xx(vgcfgrestore,
"Restore volume group configuration",
0)
xx(vgchange,
"Change volume group attributes",
CACHE_VGMETADATA | PERMITTED_READ_ONLY | ALL_VGS_IS_DEFAULT)
xx(vgck,
"Check the consistency of volume group(s)",
ALL_VGS_IS_DEFAULT | LOCKD_VG_SH)
xx(vgconvert,
"Change volume group metadata format",
0)
xx(vgcreate,
"Create a volume group",
MUST_USE_ALL_ARGS | ENABLE_ALL_DEVS)
xx(vgdisplay,
"Display volume group information",
PERMITTED_READ_ONLY | ALL_VGS_IS_DEFAULT | LOCKD_VG_SH)
xx(vgexport,
"Unregister volume group(s) from the system",
ALL_VGS_IS_DEFAULT)
xx(vgextend,
"Add physical volumes to a volume group",
MUST_USE_ALL_ARGS | ENABLE_ALL_DEVS)
xx(vgimport,
"Register exported volume group with system",
ALL_VGS_IS_DEFAULT | NO_LVMETAD_AUTOSCAN)
xx(vgimportclone,
"Import a VG from cloned PVs",
NO_LVMETAD_AUTOSCAN)
xx(vgmerge,
"Merge volume groups",
0)
xx(vgmknodes,
"Create the special files for volume group devices in /dev",
ALL_VGS_IS_DEFAULT)
xx(vgreduce,
"Remove physical volume(s) from a volume group",
0)
xx(vgremove,
"Remove volume group(s)",
ALL_VGS_IS_DEFAULT) /* all VGs only with select */
xx(vgrename,
"Rename a volume group",
ALLOW_UUID_AS_NAME | REQUIRES_FULL_LABEL_SCAN)
xx(vgs,
"Display information about volume groups",
PERMITTED_READ_ONLY | ALL_VGS_IS_DEFAULT | LOCKD_VG_SH)
xx(vgscan,
"Search for all volume groups",
PERMITTED_READ_ONLY | ALL_VGS_IS_DEFAULT | LOCKD_VG_SH | NO_LVMETAD_AUTOSCAN)
xx(vgsplit,
"Move physical volumes into a new or existing volume group",
0)
xx(version,
"Display software and driver version information",
PERMITTED_READ_ONLY | NO_METADATA_PROCESSING)