mirror of
git://sourceware.org/git/lvm2.git
synced 2025-09-20 05:44:20 +03:00
Compare commits
1 Commits
dev-dct-cm
...
dev-dct-cm
Author | SHA1 | Date | |
---|---|---|---|
|
d9c80f249e |
@@ -54,8 +54,7 @@
|
||||
# it is followed by ..., e.g. VG|LV|Tag ...
|
||||
#
|
||||
# LV can have a suffix indicating the LV type, e.g. LV_linear, LV_thinpool.
|
||||
# LV_raid represents any raidN. LV_type1_type2_type3 when the LV is
|
||||
# limited to multiple specific types.
|
||||
# LV_raid represents any raidN.
|
||||
#
|
||||
# VG, LV can have the suffix _new, indicating the named VG or LV
|
||||
# does not yet exist.
|
||||
@@ -85,6 +84,11 @@
|
||||
# maxrecoveryrate (raidmaxrecoveryrate)
|
||||
# writebehind (raidwritebehind)
|
||||
#
|
||||
# DESC: describe what the command does, with a separate
|
||||
# sentence ending in '.' for each unique operation.
|
||||
# A new line is printed after each '.' so be careful
|
||||
# about where '.' is used.
|
||||
#
|
||||
|
||||
#
|
||||
# For efficiency, sets of options can be defined and reused
|
||||
@@ -114,19 +118,6 @@ OO_ALL: --commandprofile String, --config String, --debug,
|
||||
--driverloaded Bool, --help, --profile String, --quiet,
|
||||
--verbose, --version, --yes
|
||||
|
||||
#
|
||||
# These common options are displayed once at the end of
|
||||
# a given command's usage. This is done to avoid excessive
|
||||
# repetition of common options, which may obscure the more
|
||||
# interesting and relevant parts of a common prototype.
|
||||
# This definition is *only* used when generating the command
|
||||
# usage strings, and is the basis for the division between
|
||||
# the "usage" and "usage_common" strings. This OO defn does
|
||||
# not relate to which optional opts are accepted by commands,
|
||||
# which is defined by the OO line.
|
||||
#
|
||||
OO_USAGE_COMMON: OO_ALL, --force, --test, --noudevsync
|
||||
|
||||
#
|
||||
# pvs, lvs, vgs, fullreport
|
||||
#
|
||||
@@ -230,73 +221,72 @@ OO_LVCONVERT: --alloc Alloc, --background, --force, --noudevsync,
|
||||
--test, --usepolicies
|
||||
|
||||
# FIXME: use different option names for different operations
|
||||
lvconvert --merge LV_linear_striped_raid_thin_snapshot|VG|Tag ...
|
||||
lvconvert --merge LV_linear|LV_striped|LV_raid|LV_thin|LV_snapshot|VG|Tag ...
|
||||
OO: --background, --interval Number
|
||||
DESC: Merge LV that was previously split from a mirror.
|
||||
DESC: Merge thin LV into its origin LV.
|
||||
DESC: Merge COW snapshot LV into its origin.
|
||||
|
||||
lvconvert --type snapshot LV_linear_striped_raid LV_snapshot
|
||||
lvconvert --type snapshot LV_linear|LV_striped|LV_raid LV_snapshot
|
||||
OO: --chunksize SizeKB, --zero Bool, OO_LVCONVERT
|
||||
DESC: Combine LV with a previously split snapshot LV.
|
||||
|
||||
lvconvert --type thin --thinpool LV LV_linear_striped_raid
|
||||
lvconvert --type thin --thinpool LV LV_linear|LV_striped|LV_raid
|
||||
OO: --originname LV_new, OO_LVCONVERT_POOL, OO_LVCONVERT
|
||||
DESC: Convert LV to type thin with an external origin.
|
||||
|
||||
# alternate form of lvconvert --type thin
|
||||
lvconvert --thin --thinpool LV LV_linear_striped_raid
|
||||
lvconvert --thin --thinpool LV LV_linear|LV_striped|LV_raid
|
||||
OO: --type thin, --originname LV_new, OO_LVCONVERT_POOL, OO_LVCONVERT
|
||||
DESC: Convert LV to type thin with an external origin (infers --type thin).
|
||||
|
||||
lvconvert --type cache --cachepool LV LV_linear_striped_raid_thinpool
|
||||
lvconvert --type cache --cachepool LV LV_linear|LV_striped|LV_raid|LV_thinpool
|
||||
OO: --cachepolicy String, --cachesettings String, OO_LVCONVERT_POOL, OO_LVCONVERT
|
||||
DESC: Convert LV to type cache.
|
||||
|
||||
# alternate form of lvconvert --type cache
|
||||
lvconvert --cache --cachepool LV LV_linear_striped_raid_thinpool
|
||||
lvconvert --cache --cachepool LV LV_linear|LV_striped|LV_raid|LV_thinpool
|
||||
OO: --type cache, --cachepolicy String, --cachesettings String, OO_LVCONVERT_POOL, OO_LVCONVERT
|
||||
DESC: Convert LV to type cache (infers --type cache).
|
||||
|
||||
lvconvert --type thin-pool LV_linear_striped_raid_cache
|
||||
lvconvert --type thin-pool LV_linear|LV_striped|LV_raid|LV_cache
|
||||
OO: --discards Discards, --zero Bool, OO_LVCONVERT_POOL, OO_LVCONVERT
|
||||
DESC: Convert LV to type thin-pool.
|
||||
|
||||
lvconvert --type cache-pool LV_linear_striped_raid
|
||||
lvconvert --type cache-pool LV_linear|LV_striped|LV_raid
|
||||
OO: OO_LVCONVERT_POOL, OO_LVCONVERT
|
||||
DESC: Convert LV to type cache-pool.
|
||||
|
||||
lvconvert --type mirror LV_linear_striped_raid
|
||||
lvconvert --type mirror LV_linear|LV_striped|LV_raid
|
||||
OO: OO_LVCONVERT_RAID, OO_LVCONVERT
|
||||
OP: PV ...
|
||||
DESC: Convert LV to type mirror.
|
||||
|
||||
lvconvert --type raid LV_linear_striped_mirror_raid
|
||||
lvconvert --type raid LV_linear|LV_striped|LV_mirror|LV_raid
|
||||
OO: OO_LVCONVERT_RAID, OO_LVCONVERT
|
||||
OP: PV ...
|
||||
DESC: Convert LV to type raid.
|
||||
DESC: Change LV raid type.
|
||||
|
||||
lvconvert --mirrors SNumber LV_raid_mirror
|
||||
lvconvert --mirrors SNumber LV_raid|LV_mirror
|
||||
OO: OO_LVCONVERT
|
||||
OP: PV ...
|
||||
DESC: Change the number of mirror images in the LV.
|
||||
|
||||
lvconvert --mirrors SNumber LV_linear_striped
|
||||
lvconvert --mirrors SNumber LV_linear|LV_striped
|
||||
OO: OO_LVCONVERT_RAID, OO_LVCONVERT
|
||||
OP: PV ...
|
||||
DESC: Alternate form to convert LV to type raid1 or mirror
|
||||
DESC: (use --type raid1|mirror).
|
||||
DESC: Alternate form to convert LV to type raid1 or mirror (use --type raid1|mirror).
|
||||
|
||||
lvconvert --splitmirrors Number --name LV_new LV_raid1_mirror_cache
|
||||
lvconvert --splitmirrors Number --name LV_new LV_raid|LV_mirror|LV_cache
|
||||
OO: OO_LVCONVERT
|
||||
DESC: Split images from a raid1 or mirror LV and use them to create a new LV.
|
||||
|
||||
lvconvert --splitmirrors Number --trackchanges LV_raid1_cache
|
||||
lvconvert --splitmirrors Number --trackchanges LV_raid|LV_cache
|
||||
OO: OO_LVCONVERT
|
||||
DESC: Split images from a raid1 LV and use them to create a new LV.
|
||||
|
||||
lvconvert --repair LV_raid_mirror_thinpool
|
||||
lvconvert --repair LV_raid|LV_mirror|LV_thinpool
|
||||
OO: OO_LVCONVERT
|
||||
DESC: Replace failed PVs in a mirror or raid LV.
|
||||
DESC: Repair a thin pool.
|
||||
@@ -311,7 +301,7 @@ OO: OO_LVCONVERT_RAID, OO_LVCONVERT
|
||||
OP: PV ...
|
||||
DESC: Convert LV to type striped.
|
||||
|
||||
lvconvert --type linear LV_raid_mirror
|
||||
lvconvert --type linear LV_raid|LV_mirror
|
||||
OO: OO_LVCONVERT
|
||||
DESC: Convert LV to type linear.
|
||||
|
||||
@@ -319,11 +309,11 @@ lvconvert --mirrorlog MirrorLog LV_mirror
|
||||
OO: OO_LVCONVERT
|
||||
DESC: Change the type of log used by LV.
|
||||
|
||||
lvconvert --splitcache LV_cachepool_cache_thinpool
|
||||
lvconvert --splitcache LV_cachepool|LV_cache|LV_thinpool
|
||||
OO: OO_LVCONVERT
|
||||
DESC: Separate and preserve a cache pool from a cache LV.
|
||||
|
||||
lvconvert --uncache LV_cache_thinpool
|
||||
lvconvert --uncache LV_cache|LV_thinpool
|
||||
OO: OO_LVCONVERT
|
||||
DESC: Separate and remove a cache pool from a cache LV.
|
||||
|
||||
@@ -347,7 +337,7 @@ lvconvert LV_mirror
|
||||
DESC: Poll LV to collapse resync layers.
|
||||
|
||||
# FIXME: add a new option defining this operation, e.g. --swapmetadata
|
||||
lvconvert --poolmetadata LV LV_thinpool_cachepool
|
||||
lvconvert --poolmetadata LV LV_thinpool|LV_cachepool
|
||||
DESC: Swap metadata LV in a thin pool or cache pool (temporary command).
|
||||
|
||||
|
||||
@@ -395,7 +385,7 @@ DESC: Create a mirror LV.
|
||||
lvcreate --type raid --size SizeMB VG
|
||||
OO: OO_LVCREATE_RAID, OO_LVCREATE
|
||||
OP: PV ...
|
||||
DESC: Create a raid LV (a specific raid level must be used, e.g. raid1.
|
||||
DESC: Create a raid LV (a specific raid level must be used, for example, raid1).
|
||||
|
||||
lvcreate --type snapshot --size SizeMB LV
|
||||
OO: OO_LVCREATE
|
||||
@@ -427,20 +417,17 @@ DESC: Create a thin LV that is a snapshot of an existing thin LV.
|
||||
|
||||
lvcreate --type thin --snapshot --thinpool LV_thinpool LV
|
||||
OO: OO_LVCREATE_POOL, OO_LVCREATE_THIN, OO_LVCREATE
|
||||
DESC: Create a thin LV that is a snapshot of an external origin LV
|
||||
DESC: named in arg pos 1.
|
||||
DESC: Create a thin LV that is a snapshot of an external origin LV named in arg pos 1.
|
||||
|
||||
lvcreate --type thin --virtualsize SizeMB --size SizeMB --thinpool LV_new
|
||||
OO: OO_LVCREATE_POOL, OO_LVCREATE_THIN, OO_LVCREATE
|
||||
OP: PV ...
|
||||
DESC: Create a thin LV, first creating a thin pool for it,
|
||||
DESC: where the new thin pool is named by the --thinpool arg.
|
||||
DESC: Create a thin LV, first creating a thin pool for it, where the new thin pool is named by the --thinpool arg.
|
||||
|
||||
lvcreate --type thin --virtualsize SizeMB --size SizeMB LV_new
|
||||
OO: OO_LVCREATE_POOL, OO_LVCREATE_THIN, OO_LVCREATE
|
||||
OP: PV ...
|
||||
DESC: Create a thin LV, first creating a thin pool for it,
|
||||
DESC: where the new thin pool is named in arg pos 1.
|
||||
DESC: Create a thin LV, first creating a thin pool for it, where the new thin pool is named in arg pos 1.
|
||||
|
||||
lvcreate --type thin --virtualsize SizeMB --size SizeMB VG
|
||||
OO: OO_LVCREATE_POOL, OO_LVCREATE_THIN, OO_LVCREATE
|
||||
@@ -451,19 +438,17 @@ DESC: Create a thin LV, first creating a thin pool for it.
|
||||
lvcreate --type cache --size SizeMB LV
|
||||
OO: OO_LVCREATE_POOL, OO_LVCREATE_CACHE, OO_LVCREATE
|
||||
OP: PV ...
|
||||
DESC: Convert the specified LV to type cache after creating a new
|
||||
DESC: cache pool LV to use.
|
||||
DESC: Convert the specified LV to type cache after creating a new cache pool LV to use.
|
||||
|
||||
lvcreate --type cache --size SizeMB --cachepool LV_cachepool
|
||||
OO: OO_LVCREATE_POOL, OO_LVCREATE_CACHE, OO_LVCREATE
|
||||
OP: PV ...
|
||||
DESC: Create a cache LV, first creating a new origin LV,
|
||||
DESC: then combining it with the existing cache pool in arg pos 1.
|
||||
DESC: Create a cache LV, first creating a new origin LV, then combining it with the existing cache pool in arg pos 1.
|
||||
|
||||
lvcreate --size SizeMB VG
|
||||
OO: --type linear, OO_LVCREATE
|
||||
OP: PV ...
|
||||
DESC: Create a linear LV, --name is usually specified (default --type linear).
|
||||
DESC: Create a linear LV. (default --type linear)
|
||||
|
||||
lvcreate --stripes Number --size SizeMB VG
|
||||
OO: --type striped, --stripesize SizeKB, OO_LVCREATE
|
||||
@@ -478,8 +463,7 @@ DESC: Create a raid1 or mirror LV (infers --type raid1|mirror).
|
||||
lvcreate --snapshot --size SizeMB LV
|
||||
OO: --type snapshot, OO_LVCREATE
|
||||
OP: PV ...
|
||||
DESC: Create a COW snapshot LV of the origin LV in arg pos 1
|
||||
DESC: (infers --type snapshot).
|
||||
DESC: Create a COW snapshot LV of the origin LV in arg pos 1. (infers --type snapshot)
|
||||
|
||||
lvcreate --thin --size SizeMB VG
|
||||
OO: --type thin-pool, OO_LVCREATE_POOL, OO_LVCREATE_THIN, OO_LVCREATE
|
||||
@@ -493,13 +477,11 @@ DESC: Create a cache pool (infers --type cache-pool).
|
||||
|
||||
lvcreate --snapshot LV_thin
|
||||
OO: --type thin, OO_LVCREATE_THIN, OO_LVCREATE
|
||||
DESC: Create a thin LV that is a snapshot of an existing thin LV
|
||||
DESC: (infers --type thin).
|
||||
DESC: Create a thin LV that is a snapshot of an existing thin LV (infers --type thin).
|
||||
|
||||
lvcreate --snapshot --thinpool LV_thinpool LV
|
||||
OO: --type thin, OO_LVCREATE_THIN, OO_LVCREATE
|
||||
DESC: Create a thin LV that is a snapshot of an external origin LV
|
||||
DESC: (infers --type thin).
|
||||
DESC: Create a thin LV that is a snapshot of an external origin LV (infers --type thin).
|
||||
|
||||
lvcreate --virtualsize SizeMB --thinpool LV_thinpool
|
||||
OO: --type thin, OO_LVCREATE_THIN, OO_LVCREATE
|
||||
@@ -508,20 +490,17 @@ DESC: Create a thin LV in a thin pool (infers --type thin).
|
||||
lvcreate --size SizeMB --cachepool LV_cachepool
|
||||
OO: --type cache, OO_LVCREATE_CACHE, OO_LVCREATE
|
||||
OP: PV ...
|
||||
DESC: Create a new origin LV, combining it with an existing
|
||||
DESC: cache pool to create a new cache LV (infers --type cache).
|
||||
DESC: Create a new origin LV, combining it with an existing cache pool to create a new cache LV (infers --type cache).
|
||||
|
||||
lvcreate --thin --virtualsize SizeMB --size SizeMB --thinpool LV_new
|
||||
OO: --type thin, OO_LVCREATE_POOL, OO_LVCREATE_THIN, OO_LVCREATE
|
||||
OP: PV ...
|
||||
DESC: Create a thin LV, first creating a thin pool for it, where the new
|
||||
DESC: thin pool is named by the --thinpool arg (infers --type thin).
|
||||
DESC: Create a thin LV, first creating a thin pool for it, where the new thin pool is named by the --thinpool arg (infers --type thin).
|
||||
|
||||
lvcreate --thin --virtualsize SizeMB --size SizeMB LV_new
|
||||
OO: --type thin, OO_LVCREATE_POOL, OO_LVCREATE_THIN, OO_LVCREATE
|
||||
OP: PV ...
|
||||
DESC: Create a thin LV, first creating a thin pool for it, where the new
|
||||
DESC: thin pool is named in arg pos 1 (infers --type thin).
|
||||
DESC: Create a thin LV, first creating a thin pool for it, where the new thin pool is named in arg pos 1 (infers --type thin).
|
||||
|
||||
lvcreate --size SizeMB --virtualsize SizeMB VG
|
||||
OO: --type thin, --type snapshot, --thin, --snapshot,
|
||||
@@ -560,7 +539,7 @@ OO: --alloc Alloc, --autobackup Bool, --force, --mirrors SNumber,
|
||||
--test
|
||||
OP: PV ...
|
||||
|
||||
lvextend --usepolicies LV_thinpool_snapshot
|
||||
lvextend --usepolicies LV_thinpool|LV_snapshot
|
||||
OO: --alloc Alloc, --autobackup Bool, --force, --mirrors SNumber,
|
||||
--nofsck, --nosync, --noudevsync,
|
||||
--reportformat String, --resizefs,
|
||||
|
@@ -19,6 +19,7 @@
|
||||
#include <ctype.h>
|
||||
#include <getopt.h>
|
||||
|
||||
|
||||
/* needed to include args.h */
|
||||
#define ARG_COUNTABLE 0x00000001
|
||||
#define ARG_GROUPABLE 0x00000002
|
||||
@@ -132,8 +133,6 @@ struct oo_line {
|
||||
int cmd_count;
|
||||
struct command cmd_array[MAX_CMDS];
|
||||
|
||||
struct command common_options; /* for printing common usage */
|
||||
|
||||
#define MAX_OO_LINES 256
|
||||
int oo_line_count;
|
||||
struct oo_line oo_lines[MAX_OO_LINES];
|
||||
@@ -141,36 +140,6 @@ struct oo_line oo_lines[MAX_OO_LINES];
|
||||
|
||||
static void add_optional_opt_line(struct command *cmd, int argc, char *argv[]);
|
||||
|
||||
/*
|
||||
* modifies buf, replacing the sep characters with \0
|
||||
* argv pointers point to positions in buf
|
||||
*/
|
||||
|
||||
static char *split_line(char *buf, int *argc, char **argv, char sep)
|
||||
{
|
||||
char *p = buf, *rp = NULL;
|
||||
int i;
|
||||
|
||||
argv[0] = p;
|
||||
|
||||
for (i = 1; i < MAX_LINE_ARGC; i++) {
|
||||
p = strchr(buf, sep);
|
||||
if (!p)
|
||||
break;
|
||||
*p = '\0';
|
||||
|
||||
argv[i] = p + 1;
|
||||
buf = p + 1;
|
||||
}
|
||||
*argc = i;
|
||||
|
||||
/* we ended by hitting \0, return the point following that */
|
||||
if (!rp)
|
||||
rp = strchr(buf, '\0') + 1;
|
||||
|
||||
return rp;
|
||||
}
|
||||
|
||||
/* convert value string, e.g. Number, to foo_VAL enum */
|
||||
|
||||
static int val_str_to_num(char *str)
|
||||
@@ -268,104 +237,103 @@ static char *val_bits_to_str(int val_bits)
|
||||
* are not exposed to lvm at large, which uses only the ARG_DEF values.
|
||||
*/
|
||||
|
||||
static uint32_t lv_str_to_types(char *str)
|
||||
static int lv_str_to_num(char *str)
|
||||
{
|
||||
char copy[128] = { 0 };
|
||||
char *argv[MAX_LINE_ARGC];
|
||||
int argc;
|
||||
char *name;
|
||||
uint32_t types = 0;
|
||||
char name[32] = { 0 };
|
||||
char *new;
|
||||
int i;
|
||||
|
||||
strncpy(copy, str, 128);
|
||||
/* compare the lv name before the _new suffix */
|
||||
|
||||
split_line(copy, &argc, argv, '_');
|
||||
strncpy(name, str, 31);
|
||||
if ((new = strstr(name, "_new")))
|
||||
*new = '\0';
|
||||
|
||||
for (i = 0; i < argc; i++) {
|
||||
name = argv[i];
|
||||
if (!strcmp(name, "LV"))
|
||||
return 0;
|
||||
|
||||
if (!strcmp(name, "linear"))
|
||||
types |= ARG_DEF_LV_LINEAR;
|
||||
if (!strcmp(name, "LV_linear"))
|
||||
return ARG_DEF_LV_LINEAR;
|
||||
|
||||
if (!strcmp(name, "striped"))
|
||||
types |= ARG_DEF_LV_STRIPED;
|
||||
if (!strcmp(name, "LV_striped"))
|
||||
return ARG_DEF_LV_STRIPED;
|
||||
|
||||
if (!strcmp(name, "snapshot"))
|
||||
types |= ARG_DEF_LV_SNAPSHOT;
|
||||
if (!strcmp(name, "LV_snapshot"))
|
||||
return ARG_DEF_LV_SNAPSHOT;
|
||||
|
||||
if (!strcmp(name, "mirror"))
|
||||
types |= ARG_DEF_LV_MIRROR;
|
||||
if (!strcmp(name, "LV_mirror"))
|
||||
return ARG_DEF_LV_MIRROR;
|
||||
|
||||
if (!strcmp(name, "thin"))
|
||||
types |= ARG_DEF_LV_THIN;
|
||||
if (!strcmp(name, "LV_raid"))
|
||||
return ARG_DEF_LV_RAID;
|
||||
|
||||
if (!strcmp(name, "thinpool"))
|
||||
types |= ARG_DEF_LV_THINPOOL;
|
||||
if (!strcmp(name, "LV_raid0"))
|
||||
return ARG_DEF_LV_RAID0;
|
||||
|
||||
if (!strcmp(name, "cache"))
|
||||
types |= ARG_DEF_LV_CACHE;
|
||||
if (!strcmp(name, "LV_raid1"))
|
||||
return ARG_DEF_LV_RAID1;
|
||||
|
||||
if (!strcmp(name, "cachepool"))
|
||||
types |= ARG_DEF_LV_CACHEPOOL;
|
||||
if (!strcmp(name, "LV_raid4"))
|
||||
return ARG_DEF_LV_RAID4;
|
||||
|
||||
if (!strcmp(name, "raid0"))
|
||||
types |= ARG_DEF_LV_RAID0;
|
||||
if (!strcmp(name, "LV_raid5"))
|
||||
return ARG_DEF_LV_RAID5;
|
||||
|
||||
if (!strcmp(name, "raid1"))
|
||||
types |= ARG_DEF_LV_RAID1;
|
||||
if (!strcmp(name, "LV_raid6"))
|
||||
return ARG_DEF_LV_RAID6;
|
||||
|
||||
if (!strcmp(name, "raid4"))
|
||||
types |= ARG_DEF_LV_RAID4;
|
||||
if (!strcmp(name, "LV_raid10"))
|
||||
return ARG_DEF_LV_RAID10;
|
||||
|
||||
if (!strcmp(name, "raid5"))
|
||||
types |= ARG_DEF_LV_RAID5;
|
||||
if (!strcmp(name, "LV_thin"))
|
||||
return ARG_DEF_LV_THIN;
|
||||
|
||||
if (!strcmp(name, "raid6"))
|
||||
types |= ARG_DEF_LV_RAID6;
|
||||
if (!strcmp(name, "LV_thinpool"))
|
||||
return ARG_DEF_LV_THINPOOL;
|
||||
|
||||
if (!strcmp(name, "raid10"))
|
||||
types |= ARG_DEF_LV_RAID10;
|
||||
if (!strcmp(name, "LV_cache"))
|
||||
return ARG_DEF_LV_CACHE;
|
||||
|
||||
if (!strcmp(name, "raid"))
|
||||
types |= ARG_DEF_LV_RAID;
|
||||
}
|
||||
if (!strcmp(name, "LV_cachepool"))
|
||||
return ARG_DEF_LV_CACHEPOOL;
|
||||
|
||||
return types;
|
||||
printf("Unknown LV type: \"%s\" \"%s\"\n", name, str);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static const char *lv_num_to_str(int num)
|
||||
{
|
||||
switch (num) {
|
||||
case ARG_DEF_LV_LINEAR:
|
||||
return "linear";
|
||||
return "LV_linear";
|
||||
case ARG_DEF_LV_STRIPED:
|
||||
return "striped";
|
||||
return "LV_striped";
|
||||
case ARG_DEF_LV_SNAPSHOT:
|
||||
return "snapshot";
|
||||
return "LV_snapshot";
|
||||
case ARG_DEF_LV_MIRROR:
|
||||
return "mirror";
|
||||
return "LV_mirror";
|
||||
case ARG_DEF_LV_RAID:
|
||||
return "raid";
|
||||
return "LV_raid";
|
||||
case ARG_DEF_LV_RAID0:
|
||||
return "raid0";
|
||||
return "LV_raid0";
|
||||
case ARG_DEF_LV_RAID1:
|
||||
return "raid1";
|
||||
return "LV_raid1";
|
||||
case ARG_DEF_LV_RAID4:
|
||||
return "raid4";
|
||||
return "LV_raid4";
|
||||
case ARG_DEF_LV_RAID5:
|
||||
return "raid5";
|
||||
return "LV_raid5";
|
||||
case ARG_DEF_LV_RAID6:
|
||||
return "raid6";
|
||||
return "LV_raid6";
|
||||
case ARG_DEF_LV_RAID10:
|
||||
return "raid10";
|
||||
return "LV_raid10";
|
||||
case ARG_DEF_LV_THIN:
|
||||
return "thin";
|
||||
return "LV_thin";
|
||||
case ARG_DEF_LV_THINPOOL:
|
||||
return "thinpool";
|
||||
return "LV_thinpool";
|
||||
case ARG_DEF_LV_CACHE:
|
||||
return "cache";
|
||||
return "LV_cache";
|
||||
case ARG_DEF_LV_CACHEPOOL:
|
||||
return "cachepool";
|
||||
return "LV_cachepool";
|
||||
default:
|
||||
printf("lv_num_to_str: unknown LV num: %d\n", num);
|
||||
exit(1);
|
||||
@@ -472,6 +440,36 @@ static char *lv_types_to_flags(int lv_types)
|
||||
return buf_lv_types;
|
||||
}
|
||||
|
||||
/*
|
||||
* modifies buf, replacing the sep characters with \0
|
||||
* argv pointers point to positions in buf
|
||||
*/
|
||||
|
||||
static char *split_line(char *buf, int *argc, char **argv, char sep)
|
||||
{
|
||||
char *p = buf, *rp = NULL;
|
||||
int i;
|
||||
|
||||
argv[0] = p;
|
||||
|
||||
for (i = 1; i < MAX_LINE_ARGC; i++) {
|
||||
p = strchr(buf, sep);
|
||||
if (!p)
|
||||
break;
|
||||
*p = '\0';
|
||||
|
||||
argv[i] = p + 1;
|
||||
buf = p + 1;
|
||||
}
|
||||
*argc = i;
|
||||
|
||||
/* we ended by hitting \0, return the point following that */
|
||||
if (!rp)
|
||||
rp = strchr(buf, '\0') + 1;
|
||||
|
||||
return rp;
|
||||
}
|
||||
|
||||
static const char *is_command_name(char *str)
|
||||
{
|
||||
int i;
|
||||
@@ -576,7 +574,7 @@ static void set_pos_def(struct command *cmd, char *str, struct arg_def *def)
|
||||
def->val_bits |= val_enum_to_bit(val_enum);
|
||||
|
||||
if ((val_enum == lv_VAL) && strstr(name, "_"))
|
||||
def->lv_types = lv_str_to_types(name);
|
||||
def->lv_types |= lv_str_to_num(name);
|
||||
|
||||
if (strstr(name, "_new"))
|
||||
def->flags |= ARG_DEF_FLAG_NEW;
|
||||
@@ -628,7 +626,7 @@ static void set_opt_def(struct command *cmd, char *str, struct arg_def *def)
|
||||
|
||||
if (val_enum == lv_VAL) {
|
||||
if (strstr(name, "_"))
|
||||
def->lv_types = lv_str_to_types(name);
|
||||
def->lv_types |= lv_str_to_num(name);
|
||||
}
|
||||
|
||||
if ((val_enum == vg_VAL) || (val_enum == lv_VAL) || (val_enum == pv_VAL)) {
|
||||
@@ -958,7 +956,20 @@ static void print_def(struct arg_def *def, int usage)
|
||||
else if (val_enum == constnum_VAL)
|
||||
printf("ll%u", (unsigned long long)def->num);
|
||||
|
||||
else {
|
||||
else if ((val_enum == lv_VAL) && !def->lv_types) {
|
||||
if (sep) printf("|");
|
||||
printf("%s", val_names[val_enum].name);
|
||||
sep = 1;
|
||||
|
||||
} else if ((val_enum == lv_VAL) && def->lv_types) {
|
||||
for (i = 0; i < 32; i++) {
|
||||
if (def->lv_types & (1 << i)) {
|
||||
if (sep) printf("|");
|
||||
printf("%s", lv_num_to_str(1 << i));
|
||||
sep = 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (sep) printf("|");
|
||||
|
||||
if (!usage || !val_names[val_enum].usage)
|
||||
@@ -969,13 +980,6 @@ static void print_def(struct arg_def *def, int usage)
|
||||
sep = 1;
|
||||
}
|
||||
|
||||
if (val_enum == lv_VAL && def->lv_types) {
|
||||
for (i = 0; i < 32; i++) {
|
||||
if (def->lv_types & (1 << i))
|
||||
printf("_%s", lv_num_to_str(1 << i));
|
||||
}
|
||||
}
|
||||
|
||||
if ((val_enum == pv_VAL) || (val_enum == vg_VAL) || (val_enum == lv_VAL)) {
|
||||
if (def->flags & ARG_DEF_FLAG_NEW)
|
||||
printf("_new");
|
||||
@@ -1080,35 +1084,10 @@ void print_define_command_count(void)
|
||||
printf("#define COMMAND_COUNT %d\n", cmd_count);
|
||||
}
|
||||
|
||||
static int is_common_opt(int opt)
|
||||
{
|
||||
int oo;
|
||||
|
||||
for (oo = 0; oo < common_options.oo_count; oo++) {
|
||||
if (common_options.optional_opt_args[oo].opt == opt)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* For certain commands (esp commands like lvcreate with many variants), common
|
||||
* options should not be printed for every variation, but once for all. The
|
||||
* list of commands this applies to is fixed for now but could be encoded in
|
||||
* command-lines.in.
|
||||
*
|
||||
* The common options are defined in OO_USAGE_COMMON. Those options
|
||||
* are skipped when creating the usage strings for each variation of
|
||||
* these commands. Instead they are set in the usage_common string.
|
||||
*/
|
||||
|
||||
void print_usage(struct command *cmd, int skip_required)
|
||||
void print_usage(struct command *cmd)
|
||||
{
|
||||
int onereq = (cmd->cmd_flags & CMD_FLAG_ONE_REQUIRED_OPT) ? 1 : 0;
|
||||
int i, sep, ro, rp, oo, op;
|
||||
|
||||
if (skip_required)
|
||||
goto oo_count;
|
||||
int i, ro, rp, oo, op;
|
||||
|
||||
printf("\"%s", cmd->name);
|
||||
|
||||
@@ -1140,37 +1119,25 @@ void print_usage(struct command *cmd, int skip_required)
|
||||
|
||||
printf("\"");
|
||||
|
||||
oo_count:
|
||||
if (!cmd->oo_count)
|
||||
goto op_count;
|
||||
|
||||
sep = 0;
|
||||
printf("\n");
|
||||
printf("\" [");
|
||||
|
||||
if (cmd->oo_count) {
|
||||
for (oo = 0; oo < cmd->oo_count; oo++) {
|
||||
/* skip common opts which are in the usage_common string */
|
||||
if ((cmd != &common_options) && is_common_opt(cmd->optional_opt_args[oo].opt))
|
||||
continue;
|
||||
|
||||
if (!sep) {
|
||||
printf("\n");
|
||||
printf("\" [");
|
||||
}
|
||||
|
||||
if (sep)
|
||||
if (oo)
|
||||
printf(",");
|
||||
|
||||
printf(" %s", opt_names[cmd->optional_opt_args[oo].opt].long_opt);
|
||||
if (cmd->optional_opt_args[oo].def.val_bits) {
|
||||
printf(" ");
|
||||
print_def(&cmd->optional_opt_args[oo].def, 1);
|
||||
}
|
||||
sep = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (sep)
|
||||
printf(" ]\"");
|
||||
printf(" ]\"");
|
||||
|
||||
op_count:
|
||||
if (!cmd->op_count)
|
||||
@@ -1199,8 +1166,6 @@ void print_command_struct(int only_usage)
|
||||
struct command *cmd;
|
||||
int i, j, ro, rp, oo, op;
|
||||
|
||||
include_optional_opt_args(&common_options, "OO_USAGE_COMMON");
|
||||
|
||||
printf("/* Do not edit. This file is generated by scripts/create-commands */\n");
|
||||
printf("/* using command definitions from scripts/command-lines.in */\n");
|
||||
|
||||
@@ -1208,8 +1173,7 @@ void print_command_struct(int only_usage)
|
||||
cmd = &cmd_array[i];
|
||||
|
||||
if (only_usage) {
|
||||
print_usage(cmd, 0);
|
||||
print_usage(&common_options, 1);
|
||||
print_usage(cmd);
|
||||
printf("\n");
|
||||
continue;
|
||||
}
|
||||
@@ -1226,14 +1190,7 @@ void print_command_struct(int only_usage)
|
||||
|
||||
printf("commands[%d].desc = \"%s\";\n", i, cmd->desc ?: "");
|
||||
printf("commands[%d].usage = ", i);
|
||||
print_usage(cmd, 0);
|
||||
|
||||
if (cmd->oo_count) {
|
||||
printf("commands[%d].usage_common = ", i);
|
||||
print_usage(&common_options, 1);
|
||||
} else {
|
||||
printf("commands[%d].usage_common = \"NULL\";\n", i);
|
||||
}
|
||||
print_usage(cmd);
|
||||
|
||||
if (cmd->ro_count) {
|
||||
for (ro = 0; ro < cmd->ro_count; ro++) {
|
||||
@@ -1487,7 +1444,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if (is_desc_line(line_argv[0])) {
|
||||
char *desc = strdup(line_orig);
|
||||
char *desc = strdup(strstr(line_orig, ":") + 2);
|
||||
if (cmd->desc) {
|
||||
cmd->desc = realloc((char *)cmd->desc, strlen(cmd->desc) + strlen(desc) + 2);
|
||||
strcat((char *)cmd->desc, " ");
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -111,8 +111,7 @@ struct pos_arg {
|
||||
struct command {
|
||||
const char *name;
|
||||
const char *desc; /* specific command description from command-lines.h */
|
||||
const char *usage; /* excludes common options like --help, --debug */
|
||||
const char *usage_common; /* includes commmon options like --help, --debug */
|
||||
const char *usage;
|
||||
|
||||
struct command_name *cname;
|
||||
command_fn fn;
|
||||
|
@@ -963,17 +963,15 @@ static int _command_required_pos_matches(struct cmd_context *cmd, int ci, int rp
|
||||
|
||||
#define HELP_LINE_SIZE 1024
|
||||
|
||||
static void _print_usage(const char *usage)
|
||||
static void _print_usage(int ci, int include_optional)
|
||||
{
|
||||
const char *usage = _cmdline.commands[ci].usage;
|
||||
char buf[HELP_LINE_SIZE];
|
||||
int optional_ui = 0;
|
||||
int optional_pos_ui = 0;
|
||||
int ui;
|
||||
int bi;
|
||||
|
||||
if (!usage || !strlen(usage))
|
||||
return;
|
||||
|
||||
/*
|
||||
* copy the required opt_args/pos_args
|
||||
*
|
||||
@@ -989,8 +987,6 @@ static void _print_usage(const char *usage)
|
||||
bi = 0;
|
||||
|
||||
for (ui = 0; ui < strlen(usage); ui++) {
|
||||
if (!bi && ((usage[ui] == ' ') || (usage[ui] == '\n')))
|
||||
continue;
|
||||
|
||||
/* The first "[ " indicates the start of the optional opt_args. */
|
||||
if ((usage[ui] == '[') && (usage[ui+1] == ' ')) {
|
||||
@@ -1000,36 +996,43 @@ static void _print_usage(const char *usage)
|
||||
|
||||
if (usage[ui] == '\0')
|
||||
break;
|
||||
if (usage[ui] == '\n')
|
||||
break;
|
||||
|
||||
buf[bi++] = usage[ui];
|
||||
|
||||
if (usage[ui] == ',') {
|
||||
buf[bi++] = '\n';
|
||||
buf[bi++] = '\t';
|
||||
buf[bi++] = ' ';
|
||||
}
|
||||
|
||||
if (bi == (HELP_LINE_SIZE - 1))
|
||||
break;
|
||||
}
|
||||
|
||||
if (!include_optional) {
|
||||
/* print only the required opt_args/pos_args */
|
||||
log_print("%s", buf);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* print the required opt_args/pos_args
|
||||
*/
|
||||
|
||||
if (bi)
|
||||
log_print("%s", buf);
|
||||
log_print("%s", buf);
|
||||
|
||||
/*
|
||||
* copy the optional opt_args
|
||||
*/
|
||||
|
||||
if (!optional_ui)
|
||||
goto out;
|
||||
return;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
bi = 0;
|
||||
|
||||
buf[bi++] = '\t';
|
||||
|
||||
for (ui = optional_ui; ui < strlen(usage); ui++) {
|
||||
|
||||
/* The second "[ " indicates the start of the optional pos_args. */
|
||||
@@ -1043,15 +1046,11 @@ static void _print_usage(const char *usage)
|
||||
if (usage[ui] == '\n')
|
||||
break;
|
||||
|
||||
if (!bi)
|
||||
buf[bi++] = '\t';
|
||||
|
||||
buf[bi++] = usage[ui];
|
||||
|
||||
if (usage[ui] == ',') {
|
||||
buf[bi++] = '\n';
|
||||
buf[bi++] = '\t';
|
||||
buf[bi++] = ' ';
|
||||
}
|
||||
|
||||
if (bi == (HELP_LINE_SIZE - 1))
|
||||
@@ -1061,29 +1060,26 @@ static void _print_usage(const char *usage)
|
||||
/*
|
||||
* print the optional opt_args
|
||||
*/
|
||||
|
||||
if (bi)
|
||||
log_print("%s", buf);
|
||||
log_print("%s", buf);
|
||||
|
||||
/*
|
||||
* copy the optional pos_args
|
||||
*/
|
||||
|
||||
if (!optional_pos_ui)
|
||||
goto out;
|
||||
return;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
bi = 0;
|
||||
|
||||
buf[bi++] = '\t';
|
||||
|
||||
for (ui = optional_pos_ui; ui < strlen(usage); ui++) {
|
||||
if (usage[ui] == '\0')
|
||||
break;
|
||||
if (usage[ui] == '\n')
|
||||
break;
|
||||
|
||||
if (!bi)
|
||||
buf[bi++] = '\t';
|
||||
|
||||
buf[bi++] = usage[ui];
|
||||
|
||||
if (bi == (HELP_LINE_SIZE - 1))
|
||||
@@ -1093,13 +1089,14 @@ static void _print_usage(const char *usage)
|
||||
/*
|
||||
* print the optional pos_args
|
||||
*/
|
||||
|
||||
if (bi)
|
||||
log_print("%s", buf);
|
||||
out:
|
||||
return;
|
||||
log_print("%s", buf);
|
||||
}
|
||||
|
||||
/*
|
||||
* A description is a string with multiple sentences each ending in periods.
|
||||
* Print each sentence on a new line.
|
||||
*/
|
||||
|
||||
static void _print_description(int ci)
|
||||
{
|
||||
const char *desc = _cmdline.commands[ci].desc;
|
||||
@@ -1113,27 +1110,20 @@ static void _print_description(int ci)
|
||||
if (desc[di] == '\n')
|
||||
continue;
|
||||
|
||||
if (!strncmp(&desc[di], "DESC:", 5)) {
|
||||
if (bi) {
|
||||
log_print("%s", buf);
|
||||
memset(buf, 0, sizeof(buf));
|
||||
bi = 0;
|
||||
}
|
||||
di += 5;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!bi && desc[di] == ' ')
|
||||
continue;
|
||||
|
||||
buf[bi++] = desc[di];
|
||||
|
||||
if (desc[di] == '.') {
|
||||
log_print("%s", buf);
|
||||
memset(buf, 0, sizeof(buf));
|
||||
bi = 0;
|
||||
}
|
||||
|
||||
if (bi == (HELP_LINE_SIZE - 1))
|
||||
break;
|
||||
}
|
||||
|
||||
if (bi)
|
||||
log_print("%s", buf);
|
||||
}
|
||||
|
||||
static struct command *_find_command(struct cmd_context *cmd, const char *path, int *argc, char **argv)
|
||||
@@ -1249,7 +1239,7 @@ static struct command *_find_command(struct cmd_context *cmd, const char *path,
|
||||
log_error("Failed to find a matching command definition.\n");
|
||||
if (closest_count) {
|
||||
log_warn("Closest command usage is:");
|
||||
_print_usage(_cmdline.commands[closest_i].usage);
|
||||
_print_usage(closest_i, 0);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -1344,7 +1334,6 @@ static void _short_usage(const char *name)
|
||||
static int _usage(const char *name, int help_count)
|
||||
{
|
||||
struct command_name *cname = _find_command_name(name);
|
||||
const char *usage_common = NULL;
|
||||
int i;
|
||||
|
||||
if (!cname) {
|
||||
@@ -1361,16 +1350,7 @@ static int _usage(const char *name, int help_count)
|
||||
if (strlen(_cmdline.commands[i].desc))
|
||||
_print_description(i);
|
||||
|
||||
usage_common = _cmdline.commands[i].usage_common;
|
||||
|
||||
_print_usage(_cmdline.commands[i].usage);
|
||||
log_print(" "); /* for built-in \n */
|
||||
}
|
||||
|
||||
/* Common options are printed once for all variants of a command name. */
|
||||
if (usage_common) {
|
||||
log_print("Common options:");
|
||||
_print_usage(usage_common);
|
||||
_print_usage(i, help_count > 1);
|
||||
log_print(" "); /* for built-in \n */
|
||||
}
|
||||
|
||||
@@ -1382,9 +1362,9 @@ static int _usage(const char *name, int help_count)
|
||||
*/
|
||||
log_print("Usage notes:");
|
||||
log_print(". Variable parameters are: Number, String, PV, VG, LV, Tag.");
|
||||
log_print(". Select indicates that a required positional parameter can");
|
||||
log_print(" be omitted if the --select option is used.");
|
||||
log_print(". --size Number can be replaced with --extents NumberExtents.");
|
||||
log_print(". Select indicates that the positional arg can be omitted");
|
||||
log_print(" if the --select option is used.");
|
||||
log_print(". For required options listed in parentheses, e.g. (--A, --B),");
|
||||
log_print(" any one is required, after which the others are optional.");
|
||||
log_print(". The _new suffix indicates the VG or LV must not yet exist.");
|
||||
@@ -1836,7 +1816,7 @@ static int _process_common_commands(struct cmd_context *cmd)
|
||||
_usage(cmd->command->name, arg_count(cmd, help_ARG));
|
||||
|
||||
if (arg_count(cmd, help_ARG) < 2)
|
||||
log_print("(Use --help --help for usage notes.)");
|
||||
log_print("(Use --help --help to include optional parameters.)");
|
||||
return ECMD_PROCESSED;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user