master - commands: handle including an optional opt multiple times
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=6360ba3d2d7b1ab9e32...
Commit: 6360ba3d2d7b1ab9e32ad5c660473d2a290ef3fd
Parent: b7831fc14ae9a7b35c1d814486f45f4b3cbadc8b
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Mar 2 13:52:06 2017 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Thu Mar 2 13:52:06 2017 -0600
commands: handle including an optional opt multiple times
When a cmd def includes multiple sets of options (OO_FOO),
allow multiple OO_FOO sets to contain the same option and
avoid repeating it in the cmd def.
---
tools/command.c | 30 +++++++++++++++++++++++++-----
1 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/tools/command.c b/tools/command.c
index a532a10..0187972 100644
--- a/tools/command.c
+++ b/tools/command.c
@@ -845,10 +845,12 @@ static void include_optional_opt_args(struct command *cmd, const char *str)
* This function sets the opt_args.opt value for it.
*/
-static void add_opt_arg(struct command *cmd, char *str, int *takes_arg, int required)
+static void add_opt_arg(struct command *cmd, char *str,
+ int *takes_arg, int *already, int required)
{
char *comma;
int opt;
+ int i;
/* opt_arg.opt set here */
/* opt_arg.def will be set in update_prev_opt_arg() if needed */
@@ -872,6 +874,17 @@ static void add_opt_arg(struct command *cmd, char *str, int *takes_arg, int requ
if (opt == uuidstr_ARG)
opt = uuid_ARG;
+ /* Skip adding an optional opt if it is already included. */
+ if (already && !required) {
+ for (i = 0; i < cmd->oo_count; i++) {
+ if (cmd->optional_opt_args[i].opt == opt) {
+ *already = 1;
+ *takes_arg = opt_names[opt].val_enum ? 1 : 0;
+ return;
+ }
+ }
+ }
+
skip:
if (required > 0)
cmd->required_opt_args[cmd->ro_count++].opt = opt;
@@ -966,13 +979,17 @@ static void update_prev_pos_arg(struct command *cmd, char *str, int required)
static void add_optional_opt_line(struct command *cmd, int argc, char *argv[])
{
int takes_arg = 0;
+ int already;
int i;
for (i = 0; i < argc; i++) {
if (!i && !strncmp(argv[i], "OO:", 3))
continue;
+
+ already = 0;
+
if (is_opt_name(argv[i]))
- add_opt_arg(cmd, argv[i], &takes_arg, OPTIONAL);
+ add_opt_arg(cmd, argv[i], &takes_arg, &already, OPTIONAL);
else if (!strncmp(argv[i], "OO_", 3))
include_optional_opt_args(cmd, argv[i]);
else if (takes_arg)
@@ -983,6 +1000,9 @@ static void add_optional_opt_line(struct command *cmd, int argc, char *argv[])
cmd->cmd_flags |= CMD_FLAG_PARSE_ERROR;
return;
}
+
+ if (already && takes_arg)
+ i++;
}
}
@@ -997,7 +1017,7 @@ static void add_ignore_opt_line(struct command *cmd, int argc, char *argv[])
if (!i && !strncmp(argv[i], "IO:", 3))
continue;
if (is_opt_name(argv[i]))
- add_opt_arg(cmd, argv[i], &takes_arg, IGNORE);
+ add_opt_arg(cmd, argv[i], &takes_arg, NULL, IGNORE);
else if (takes_arg)
update_prev_opt_arg(cmd, argv[i], IGNORE);
else {
@@ -1032,7 +1052,7 @@ static void add_required_opt_line(struct command *cmd, int argc, char *argv[])
for (i = 0; i < argc; i++) {
if (is_opt_name(argv[i]))
- add_opt_arg(cmd, argv[i], &takes_arg, REQUIRED);
+ add_opt_arg(cmd, argv[i], &takes_arg, NULL, REQUIRED);
else if (takes_arg)
update_prev_opt_arg(cmd, argv[i], REQUIRED);
else {
@@ -1090,7 +1110,7 @@ static void add_required_line(struct command *cmd, int argc, char *argv[])
if (is_opt_name(argv[i])) {
/* add new required_opt_arg */
- add_opt_arg(cmd, argv[i], &takes_arg, REQUIRED);
+ add_opt_arg(cmd, argv[i], &takes_arg, NULL, REQUIRED);
prev_was_opt = 1;
prev_was_pos = 0;
6 years
master - lvcreate/lvresize: the --size option accepts signed values
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=b7831fc14ae9a7b35c1...
Commit: b7831fc14ae9a7b35c1d814486f45f4b3cbadc8b
Parent: 70c1fa3764639afd0d2e81968c4495bb3f3c6a73
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Mar 2 12:53:01 2017 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Thu Mar 2 12:53:01 2017 -0600
lvcreate/lvresize: the --size option accepts signed values
There was confusion in the code about whether or not the
--size option accepted a sign. Make it consistent and clear
that it does.
This exposes a new problem in that an option can only
accept one value type, e.g. --size can only accept a
signed number, it cannot accept a positive or negative
number for some commands and reject negative numbers for
others.
In practice, lvcreate accepts only positive --size
values and lvresize accepts positive or negative --size
values. There is currently no way to encode this
difference. Until that is fixed, the man page output
is hacked to avoid printing the [+|-] prefix for sizes
in lvcreate.
---
tools/args.h | 4 +-
tools/command-lines.in | 64 ++++++++++++++++++++++++------------------------
tools/command.c | 64 ++++++++++++++++++++++++++++++++++-------------
tools/lvmcmdline.c | 28 ++++++++++++++++++--
tools/tools.h | 3 +-
tools/vals.h | 4 ++-
6 files changed, 110 insertions(+), 57 deletions(-)
diff --git a/tools/args.h b/tools/args.h
index 471a3c2..eb11f38 100644
--- a/tools/args.h
+++ b/tools/args.h
@@ -1042,7 +1042,7 @@ arg(list_ARG, 'l', "list", 0, 0, 0,
arg(lvmpartition_ARG, 'l', "lvmpartition", 0, 0, 0,
"Only report PVs.\n")
-arg(size_ARG, 'L', "size", sizemb_VAL, 0, 0,
+arg(size_ARG, 'L', "size", ssizemb_VAL, 0, 0,
"#lvcreate\n"
"Specifies the size of the new LV.\n"
"The --size and --extents options are alternate methods of specifying size.\n"
@@ -1104,7 +1104,7 @@ arg(maps_ARG, 'm', "maps", 0, 0, 0,
/* FIXME: should the unused mirrors option be removed from lvextend? */
-arg(mirrors_ARG, 'm', "mirrors", numsigned_VAL, 0, 0,
+arg(mirrors_ARG, 'm', "mirrors", snumber_VAL, 0, 0,
"#lvcreate\n"
"Specifies the number of mirror images in addition to the original LV\n"
"image, e.g. --mirrors 1 means there are two images of the data, the\n"
diff --git a/tools/command-lines.in b/tools/command-lines.in
index 6956c15..295958c 100644
--- a/tools/command-lines.in
+++ b/tools/command-lines.in
@@ -710,7 +710,7 @@ OO_LVCREATE_RAID: --mirrors SNumber, --stripes Number, --stripesize SizeKB,
---
-lvcreate --type error --size SizeMB VG
+lvcreate --type error --size SSizeMB VG
OO: OO_LVCREATE
ID: lvcreate_error_vol
DESC: Create an LV that returns errors when used.
@@ -718,7 +718,7 @@ FLAGS: SECONDARY_SYNTAX
---
-lvcreate --type zero --size SizeMB VG
+lvcreate --type zero --size SSizeMB VG
OO: OO_LVCREATE
ID: lvcreate_zero_vol
DESC: Create an LV that returns zeros when read.
@@ -726,7 +726,7 @@ FLAGS: SECONDARY_SYNTAX
---
-lvcreate --type linear --size SizeMB VG
+lvcreate --type linear --size SSizeMB VG
OO: OO_LVCREATE
OP: PV ...
IO: --mirrors 0, --stripes 1
@@ -734,7 +734,7 @@ ID: lvcreate_linear
DESC: Create a linear LV.
FLAGS: SECONDARY_SYNTAX
-lvcreate --size SizeMB VG
+lvcreate --size SSizeMB VG
OO: --type linear, OO_LVCREATE
OP: PV ...
IO: --mirrors 0, --stripes 1
@@ -743,14 +743,14 @@ DESC: Create a linear LV.
---
-lvcreate --type striped --size SizeMB VG
+lvcreate --type striped --size SSizeMB VG
OO: --stripes Number, --stripesize SizeKB, OO_LVCREATE
OP: PV ...
ID: lvcreate_striped
DESC: Create a striped LV (also see lvcreate --stripes).
FLAGS: SECONDARY_SYNTAX
-lvcreate --stripes Number --size SizeMB VG
+lvcreate --stripes Number --size SSizeMB VG
OO: --type striped, --stripesize SizeKB, OO_LVCREATE
OP: PV ...
ID: lvcreate_striped
@@ -758,7 +758,7 @@ DESC: Create a striped LV (infers --type striped).
---
-lvcreate --type mirror --size SizeMB VG
+lvcreate --type mirror --size SSizeMB VG
OO: --mirrors SNumber, --mirrorlog MirrorLog, --regionsize RegionSize, --stripes Number, OO_LVCREATE
OP: PV ...
ID: lvcreate_mirror
@@ -766,7 +766,7 @@ DESC: Create a mirror LV (also see --type raid1).
FLAGS: SECONDARY_SYNTAX
# alternate form of lvcreate --type raid1|mirror
-lvcreate --mirrors SNumber --size SizeMB VG
+lvcreate --mirrors SNumber --size SSizeMB VG
OO: --type raid1, --type mirror, --mirrorlog MirrorLog, --stripes Number, OO_LVCREATE_RAID, OO_LVCREATE
OP: PV ...
ID: lvcreate_mirror_or_raid1
@@ -774,7 +774,7 @@ DESC: Create a raid1 or mirror LV (infers --type raid1|mirror).
---
-lvcreate --type raid --size SizeMB VG
+lvcreate --type raid --size SSizeMB VG
OO: OO_LVCREATE_RAID, OO_LVCREATE
OP: PV ...
ID: lvcreate_raid_any
@@ -788,7 +788,7 @@ DESC: Create a raid LV (a specific raid level must be used, e.g. raid1).
# another new LV property?
# alternate form of lvcreate --snapshot
-lvcreate --type snapshot --size SizeMB LV
+lvcreate --type snapshot --size SSizeMB LV
OO: --snapshot, --stripes Number, --stripesize SizeKB,
--chunksize SizeKB, OO_LVCREATE
OP: PV ...
@@ -797,7 +797,7 @@ DESC: Create a COW snapshot LV of an origin LV
DESC: (also see --snapshot).
FLAGS: SECONDARY_SYNTAX
-lvcreate --snapshot --size SizeMB LV
+lvcreate --snapshot --size SSizeMB LV
OO: --type snapshot, --stripes Number, --stripesize SizeKB,
--chunksize SizeKB, OO_LVCREATE
OP: PV ...
@@ -807,7 +807,7 @@ DESC: Create a COW snapshot LV of an origin LV.
---
# alternate form of lvcreate --snapshot
-lvcreate --type snapshot --size SizeMB --virtualsize SizeMB VG
+lvcreate --type snapshot --size SSizeMB --virtualsize SizeMB VG
OO: --snapshot, --chunksize SizeKB, OO_LVCREATE
OP: PV ...
ID: lvcreate_cow_snapshot_with_virtual_origin
@@ -815,7 +815,7 @@ DESC: Create a sparse COW snapshot LV of a virtual origin LV
DESC: (also see --snapshot).
FLAGS: SECONDARY_SYNTAX
-lvcreate --snapshot --size SizeMB --virtualsize SizeMB VG
+lvcreate --snapshot --size SSizeMB --virtualsize SizeMB VG
OO: --type snapshot, --chunksize SizeKB, OO_LVCREATE
OP: PV ...
ID: lvcreate_cow_snapshot_with_virtual_origin
@@ -824,7 +824,7 @@ FLAGS: SECONDARY_SYNTAX
---
-lvcreate --type thin-pool --size SizeMB VG
+lvcreate --type thin-pool --size SSizeMB VG
OO: --thinpool LV_new, OO_LVCREATE_POOL, OO_LVCREATE_THIN, OO_LVCREATE,
--stripes Number, --stripesize SizeKB
OP: PV ...
@@ -833,7 +833,7 @@ ID: lvcreate_thinpool
DESC: Create a thin pool.
# alternate form of lvcreate --type thin-pool
-lvcreate --thin --size SizeMB VG
+lvcreate --thin --size SSizeMB VG
OO: --type thin-pool, OO_LVCREATE_POOL, OO_LVCREATE_THIN, OO_LVCREATE,
--stripes Number, --stripesize SizeKB
OP: PV ...
@@ -843,7 +843,7 @@ DESC: Create a thin pool (infers --type thin-pool).
FLAGS: SECONDARY_SYNTAX
# alternate form of lvcreate --type thin-pool
-lvcreate --size SizeMB --thinpool LV_new VG
+lvcreate --size SSizeMB --thinpool LV_new VG
OO: --thin, --type thin-pool, OO_LVCREATE_POOL, OO_LVCREATE_THIN, OO_LVCREATE,
--stripes Number, --stripesize SizeKB
OP: PV ...
@@ -860,14 +860,14 @@ FLAGS: SECONDARY_SYNTAX
# still needs to be listed as an optional addition to
# --type cache-pool.
-lvcreate --type cache-pool --size SizeMB VG
+lvcreate --type cache-pool --size SSizeMB VG
OO: --cache, OO_LVCREATE_POOL, OO_LVCREATE_CACHE, OO_LVCREATE
OP: PV ...
ID: lvcreate_cachepool
DESC: Create a cache pool.
# alternate form of lvcreate --type cache-pool
-lvcreate --type cache-pool --size SizeMB --cachepool LV_new VG
+lvcreate --type cache-pool --size SSizeMB --cachepool LV_new VG
OO: --cache, OO_LVCREATE_POOL, OO_LVCREATE_CACHE, OO_LVCREATE
OP: PV ...
ID: lvcreate_cachepool
@@ -972,7 +972,7 @@ FLAGS: SECONDARY_SYNTAX
# definition. Note that when LV_new is used in arg pos 1,
# it needs to include a VG name, i.e. VG/LV_new
-lvcreate --type thin --virtualsize SizeMB --size SizeMB --thinpool LV_new
+lvcreate --type thin --virtualsize SizeMB --size SSizeMB --thinpool LV_new
OO: --thin, OO_LVCREATE_POOL, OO_LVCREATE_THIN, OO_LVCREATE,
--stripes Number, --stripesize SizeKB
OP: PV ...
@@ -982,7 +982,7 @@ DESC: Create a thin LV, first creating a thin pool for it,
DESC: where the new thin pool is named by the --thinpool arg.
# alternate form of lvcreate --type thin
-lvcreate --thin --virtualsize SizeMB --size SizeMB --thinpool LV_new
+lvcreate --thin --virtualsize SizeMB --size SSizeMB --thinpool LV_new
OO: --type thin, OO_LVCREATE_POOL, OO_LVCREATE_THIN, OO_LVCREATE,
--stripes Number, --stripesize SizeKB
OP: PV ...
@@ -994,7 +994,7 @@ DESC: (variant, infers --type thin).
FLAGS: SECONDARY_SYNTAX
# alternate form of lvcreate --type thin
-lvcreate --type thin --virtualsize SizeMB --size SizeMB LV_new|VG
+lvcreate --type thin --virtualsize SizeMB --size SSizeMB LV_new|VG
OO: --thin, OO_LVCREATE_POOL, OO_LVCREATE_THIN, OO_LVCREATE,
--stripes Number, --stripesize SizeKB
OP: PV ...
@@ -1007,7 +1007,7 @@ DESC: arg is a VG name.
FLAGS: SECONDARY_SYNTAX
# alternate form of lvcreate --type thin
-lvcreate --thin --virtualsize SizeMB --size SizeMB LV_new|VG
+lvcreate --thin --virtualsize SizeMB --size SSizeMB LV_new|VG
OO: --type thin, OO_LVCREATE_POOL, OO_LVCREATE_THIN, OO_LVCREATE,
--stripes Number, --stripesize SizeKB
OP: PV ...
@@ -1021,7 +1021,7 @@ FLAGS: SECONDARY_SYNTAX
---
-lvcreate --size SizeMB --virtualsize SizeMB VG
+lvcreate --size SSizeMB --virtualsize SizeMB VG
OO: --type thin, --type snapshot, --thin, --snapshot, OO_LVCREATE_POOL, OO_LVCREATE_THIN, OO_LVCREATE,
--stripes Number, --stripesize SizeKB
OP: PV ...
@@ -1041,7 +1041,7 @@ FLAGS: SECONDARY_SYNTAX
# but here it applies to creating the new origin that
# is used to create the cache LV
-lvcreate --type cache --size SizeMB --cachepool LV_cachepool VG
+lvcreate --type cache --size SSizeMB --cachepool LV_cachepool VG
OO: --cache, OO_LVCREATE_POOL, OO_LVCREATE_CACHE, OO_LVCREATE,
--stripes Number, --stripesize SizeKB
OP: PV ...
@@ -1051,7 +1051,7 @@ DESC: then combining it with the existing cache pool named
DESC: by the --cachepool arg.
# alternate form of lvcreate --type cache
-lvcreate --size SizeMB --cachepool LV_cachepool VG
+lvcreate --size SSizeMB --cachepool LV_cachepool VG
OO: --type cache, --cache, OO_LVCREATE_CACHE, OO_LVCREATE,
--stripes Number, --stripesize SizeKB
OP: PV ...
@@ -1062,7 +1062,7 @@ DESC: by the --cachepool arg (variant, infers --type cache).
FLAGS: SECONDARY_SYNTAX
# alternate form of lvcreate --type cache
-lvcreate --type cache --size SizeMB LV_cachepool
+lvcreate --type cache --size SSizeMB LV_cachepool
OO: --cache, OO_LVCREATE_POOL, OO_LVCREATE_CACHE, OO_LVCREATE,
--stripes Number, --stripesize SizeKB
OP: PV ...
@@ -1081,7 +1081,7 @@ FLAGS: SECONDARY_SYNTAX
# an already complicated command above.
#
# # alternate form for lvcreate_cache_vol_with_new_origin
-# lvcreate --cache --size SizeMB LV_cachepool
+# lvcreate --cache --size SSizeMB LV_cachepool
# OO: --type cache, --cache, OO_LVCREATE_CACHE, OO_LVCREATE, --stripes Number, --stripesize SizeKB
# OP: PV ...
# ID: lvcreate_cache_vol_with_new_origin
@@ -1093,7 +1093,7 @@ FLAGS: SECONDARY_SYNTAX
# 2. If LV is not a cachepool, then it's a disguised lvconvert.
#
# # FIXME: this should be done by lvconvert, and this command removed
-# lvcreate --type cache --size SizeMB LV
+# lvcreate --type cache --size SSizeMB LV
# OO: OO_LVCREATE_POOL, OO_LVCREATE_CACHE, OO_LVCREATE
# OP: PV ...
# ID: lvcreate_convert_to_cache_vol_with_cachepool
@@ -1110,7 +1110,7 @@ FLAGS: SECONDARY_SYNTAX
# def1: alternate form of lvcreate --type cache, or
# def2: it should be done by lvconvert.
-lvcreate --cache --size SizeMB LV
+lvcreate --cache --size SSizeMB LV
OO: OO_LVCREATE_CACHE, OO_LVCREATE_POOL, OO_LVCREATE,
--stripes Number, --stripesize SizeKB
OP: PV ...
@@ -1144,7 +1144,7 @@ ID: lvdisplay_general
# --extents is not specified; it's an automatic alternative for --size
-lvextend --size SizeMB LV
+lvextend --size SSizeMB LV
OO: --alloc Alloc, --autobackup Bool, --force, --mirrors SNumber,
--nofsck, --nosync, --noudevsync, --reportformat ReportFmt, --resizefs,
--stripes Number, --stripesize SizeKB, --poolmetadatasize SizeMB,
@@ -1188,7 +1188,7 @@ ID: lvmconfig_general
---
-lvreduce --size SizeMB LV
+lvreduce --size SSizeMB LV
OO: --autobackup Bool, --force, --nofsck, --noudevsync,
--reportformat ReportFmt, --resizefs
ID: lvreduce_general
@@ -1216,7 +1216,7 @@ ID: lvrename_lv_lv
# value can be checked to match the existing type; using it doesn't
# currently enable any different behavior.
-lvresize --size SizeMB LV
+lvresize --size SSizeMB LV
OO: --alloc Alloc, --autobackup Bool, --force,
--nofsck, --nosync, --noudevsync, --reportformat ReportFmt, --resizefs,
--stripes Number, --stripesize SizeKB, --poolmetadatasize SizeMB,
diff --git a/tools/command.c b/tools/command.c
index e0db503..a532a10 100644
--- a/tools/command.c
+++ b/tools/command.c
@@ -74,8 +74,9 @@ static inline int cachemode_arg(struct cmd_context *cmd, struct arg_values *av)
static inline int discards_arg(struct cmd_context *cmd, struct arg_values *av) { return 0; }
static inline int mirrorlog_arg(struct cmd_context *cmd, struct arg_values *av) { return 0; }
static inline int size_kb_arg(struct cmd_context *cmd, struct arg_values *av) { return 0; }
+static inline int ssize_kb_arg(struct cmd_context *cmd, struct arg_values *av) { return 0; }
static inline int size_mb_arg(struct cmd_context *cmd, struct arg_values *av) { return 0; }
-static inline int size_mb_arg_with_percent(struct cmd_context *cmd, struct arg_values *av) { return 0; }
+static inline int ssize_mb_arg(struct cmd_context *cmd, struct arg_values *av) { return 0; }
static inline int int_arg(struct cmd_context *cmd, struct arg_values *av) { return 0; }
static inline int uint32_arg(struct cmd_context *cmd, struct arg_values *av) { return 0; }
static inline int int_arg_with_sign(struct cmd_context *cmd, struct arg_values *av) { return 0; }
@@ -1783,7 +1784,7 @@ void print_usage_common_cmd(struct command_name *cname, struct command *cmd)
#ifdef MAN_PAGE_GENERATOR
-static void print_val_man(const char *str)
+static void print_val_man(struct command_name *cname, const char *str)
{
char *line;
char *line_argv[MAX_LINE_ARGC];
@@ -1791,6 +1792,23 @@ static void print_val_man(const char *str)
int i;
/*
+ * FIXME: this is a terrible hack that needs to be fixed.
+ * lvcreate and lvresize both use --size, and --size
+ * accepts a signed number, and a signed number is
+ * printed with a [+|-] prefix. But lvcreate does not
+ * accept negative numbers. We need to do something to
+ * have two (or more) variants of --size, one that can
+ * accept a sign and one that cannot. For now, this
+ * hack just detects when we're going to print
+ * [+|-]Size for "lvcreate" and overrides it to
+ * omit the +|-.
+ */
+ if (!strcmp(cname->name, "lvcreate") && !strcmp(str, "[+|-]Size[m|UNIT]")) {
+ printf("\\fISize\\fP[m|UNIT]");
+ return;
+ }
+
+ /*
* Doing bold k before UNIT creates a lot of
* visual "noise" that makes the text hard to read.
* The extra markup in this case doesn't add anything
@@ -1807,6 +1825,16 @@ static void print_val_man(const char *str)
return;
}
+ if (!strcmp(str, "[+|-]Size[k|UNIT]")) {
+ printf("[\\fB+\\fP|\\fB-\\fP]\\fISize\\fP[k|UNIT]");
+ return;
+ }
+
+ if (!strcmp(str, "[+|-]Size[m|UNIT]")) {
+ printf("[\\fB+\\fP|\\fB-\\fP]\\fISize\\fP[m|UNIT]");
+ return;
+ }
+
if (!strcmp(str, "[+|-]Number")) {
printf("[\\fB+\\fP|\\fB-\\fP]\\fINumber\\fP");
return;
@@ -1868,7 +1896,7 @@ static void print_val_man(const char *str)
printf("\\fB%s\\fP", str);
}
-static void print_def_man(struct arg_def *def, int usage)
+static void print_def_man(struct command_name *cname, struct arg_def *def, int usage)
{
int val_enum;
int lvt_enum;
@@ -1897,7 +1925,7 @@ static void print_def_man(struct arg_def *def, int usage)
printf("%s", val_names[val_enum].name);
printf("\\fP");
} else {
- print_val_man(val_names[val_enum].usage);
+ print_val_man(cname, val_names[val_enum].usage);
}
sep = 1;
@@ -2030,7 +2058,7 @@ void print_man_usage(char *lvmname, struct command *cmd)
if (cmd->required_opt_args[ro].def.val_bits) {
printf(" ");
- print_def_man(&cmd->required_opt_args[ro].def, 1);
+ print_def_man(cname, &cmd->required_opt_args[ro].def, 1);
}
sep++;
@@ -2057,7 +2085,7 @@ void print_man_usage(char *lvmname, struct command *cmd)
if (cmd->required_opt_args[ro].def.val_bits) {
printf(" ");
- print_def_man(&cmd->required_opt_args[ro].def, 1);
+ print_def_man(cname, &cmd->required_opt_args[ro].def, 1);
}
sep++;
@@ -2073,7 +2101,7 @@ void print_man_usage(char *lvmname, struct command *cmd)
for (rp = 0; rp < cmd->rp_count; rp++) {
if (cmd->required_pos_args[rp].def.val_bits) {
printf(" ");
- print_def_man(&cmd->required_pos_args[rp].def, 1);
+ print_def_man(cname, &cmd->required_pos_args[rp].def, 1);
}
}
@@ -2116,7 +2144,7 @@ void print_man_usage(char *lvmname, struct command *cmd)
if (cmd->required_opt_args[ro].def.val_bits) {
printf(" ");
- print_def_man(&cmd->required_opt_args[ro].def, 1);
+ print_def_man(cname, &cmd->required_opt_args[ro].def, 1);
}
sep++;
@@ -2128,7 +2156,7 @@ void print_man_usage(char *lvmname, struct command *cmd)
for (rp = 0; rp < cmd->rp_count; rp++) {
if (cmd->required_pos_args[rp].def.val_bits) {
printf(" ");
- print_def_man(&cmd->required_pos_args[rp].def, 1);
+ print_def_man(cname, &cmd->required_pos_args[rp].def, 1);
}
}
@@ -2175,7 +2203,7 @@ void print_man_usage(char *lvmname, struct command *cmd)
if (cmd->optional_opt_args[oo].def.val_bits) {
printf(" ");
- print_def_man(&cmd->optional_opt_args[oo].def, 1);
+ print_def_man(cname, &cmd->optional_opt_args[oo].def, 1);
}
printf(" ]\n");
printf(".ad b\n");
@@ -2207,7 +2235,7 @@ void print_man_usage(char *lvmname, struct command *cmd)
if (cmd->optional_opt_args[oo].def.val_bits) {
printf(" ");
- print_def_man(&cmd->optional_opt_args[oo].def, 1);
+ print_def_man(cname, &cmd->optional_opt_args[oo].def, 1);
}
printf(" ]\n");
printf(".ad b\n");
@@ -2235,7 +2263,7 @@ void print_man_usage(char *lvmname, struct command *cmd)
for (op = 0; op < cmd->op_count; op++) {
if (cmd->optional_pos_args[op].def.val_bits) {
printf(" ");
- print_def_man(&cmd->optional_pos_args[op].def, 1);
+ print_def_man(cname, &cmd->optional_pos_args[op].def, 1);
}
}
}
@@ -2303,7 +2331,7 @@ void print_man_usage_common_lvm(struct command *cmd)
if (cmd->optional_opt_args[oo].def.val_bits) {
printf(" ");
- print_def_man(&cmd->optional_opt_args[oo].def, 1);
+ print_def_man(cname, &cmd->optional_opt_args[oo].def, 1);
}
printf(" ]\n");
printf(".ad b\n");
@@ -2338,7 +2366,7 @@ void print_man_usage_common_lvm(struct command *cmd)
if (cmd->optional_opt_args[oo].def.val_bits) {
printf(" ");
- print_def_man(&cmd->optional_opt_args[oo].def, 1);
+ print_def_man(cname, &cmd->optional_opt_args[oo].def, 1);
}
printf(" ]\n");
printf(".ad b\n");
@@ -2400,7 +2428,7 @@ void print_man_usage_common_cmd(struct command *cmd)
if (cmd->optional_opt_args[oo].def.val_bits) {
printf(" ");
- print_def_man(&cmd->optional_opt_args[oo].def, 1);
+ print_def_man(cname, &cmd->optional_opt_args[oo].def, 1);
}
printf(" ]\n");
printf(".ad b\n");
@@ -2442,7 +2470,7 @@ void print_man_usage_common_cmd(struct command *cmd)
if (cmd->optional_opt_args[oo].def.val_bits) {
printf(" ");
- print_def_man(&cmd->optional_opt_args[oo].def, 1);
+ print_def_man(cname, &cmd->optional_opt_args[oo].def, 1);
}
printf(" ]\n");
printf(".ad b\n");
@@ -2577,7 +2605,7 @@ void print_man_all_options_list(struct command_name *cname)
printf("\\fP");
} else {
printf(" ");
- print_val_man(val_names[val_enum].usage);
+ print_val_man(cname, val_names[val_enum].usage);
}
printf("\n.ad b\n");
@@ -2625,7 +2653,7 @@ void print_man_all_options_desc(struct command_name *cname)
printf("\\fP");
} else {
printf(" ");
- print_val_man(val_names[val_enum].usage);
+ print_val_man(cname, val_names[val_enum].usage);
}
if (opt_names[opt_enum].flags & ARG_COUNTABLE)
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index d5385a8..5410a1f 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -629,19 +629,41 @@ static int _size_arg(struct cmd_context *cmd __attribute__((unused)),
return 1;
}
+/* negative not accepted */
int size_kb_arg(struct cmd_context *cmd, struct arg_values *av)
{
+ if (!_size_arg(cmd, av, 2, 0))
+ return 0;
+
+ if (av->sign == SIGN_MINUS) {
+ log_error("Size may not be negative.");
+ return 0;
+ }
+
+ return 1;
+}
+
+int ssize_kb_arg(struct cmd_context *cmd, struct arg_values *av)
+{
return _size_arg(cmd, av, 2, 0);
}
int size_mb_arg(struct cmd_context *cmd, struct arg_values *av)
{
- return _size_arg(cmd, av, 2048, 0);
+ if (!_size_arg(cmd, av, 2048, 0))
+ return 0;
+
+ if (av->sign == SIGN_MINUS) {
+ log_error("Size may not be negative.");
+ return 0;
+ }
+
+ return 1;
}
-int size_mb_arg_with_percent(struct cmd_context *cmd, struct arg_values *av)
+int ssize_mb_arg(struct cmd_context *cmd, struct arg_values *av)
{
- return _size_arg(cmd, av, 2048, 1);
+ return _size_arg(cmd, av, 2048, 0);
}
int int_arg(struct cmd_context *cmd __attribute__((unused)), struct arg_values *av)
diff --git a/tools/tools.h b/tools/tools.h
index 1e1e7f1..f2c926f 100644
--- a/tools/tools.h
+++ b/tools/tools.h
@@ -183,8 +183,9 @@ int cachemode_arg(struct cmd_context *cmd, struct arg_values *av);
int discards_arg(struct cmd_context *cmd, struct arg_values *av);
int mirrorlog_arg(struct cmd_context *cmd, struct arg_values *av);
int size_kb_arg(struct cmd_context *cmd, struct arg_values *av);
+int ssize_kb_arg(struct cmd_context *cmd, struct arg_values *av);
int size_mb_arg(struct cmd_context *cmd, struct arg_values *av);
-int size_mb_arg_with_percent(struct cmd_context *cmd, struct arg_values *av);
+int ssize_mb_arg(struct cmd_context *cmd, struct arg_values *av);
int int_arg(struct cmd_context *cmd, struct arg_values *av);
int uint32_arg(struct cmd_context *cmd, struct arg_values *av);
int int_arg_with_sign(struct cmd_context *cmd, struct arg_values *av);
diff --git a/tools/vals.h b/tools/vals.h
index d485926..ab1b715 100644
--- a/tools/vals.h
+++ b/tools/vals.h
@@ -117,8 +117,10 @@ val(discards_VAL, discards_arg, "Discards", "passdown|nopassdown|ignore")
val(mirrorlog_VAL, mirrorlog_arg, "MirrorLog", "core|disk")
val(sizekb_VAL, size_kb_arg, "SizeKB", "Size[k|UNIT]")
val(sizemb_VAL, size_mb_arg, "SizeMB", "Size[m|UNIT]")
+val(ssizekb_VAL, ssize_kb_arg, "SSizeKB", "[+|-]Size[k|UNIT]")
+val(ssizemb_VAL, ssize_mb_arg, "SSizeMB", "[+|-]Size[m|UNIT]")
val(regionsize_VAL, regionsize_arg, "RegionSize", "Size[m|UNIT]")
-val(numsigned_VAL, int_arg_with_sign, "SNumber", "[+|-]Number")
+val(snumber_VAL, int_arg_with_sign, "SNumber", "[+|-]Number")
val(extents_VAL, extents_arg, "Extents", "[+|-]Number[%VG|%PVS|%FREE]")
val(permission_VAL, permission_arg, "Permission", "rw|r")
val(metadatatype_VAL, metadatatype_arg, "MetadataType", "lvm2|lvm1")
6 years
master - tools: Fix overriding of current_settings.
by Alasdair Kergon
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=70c1fa3764639afd0d2...
Commit: 70c1fa3764639afd0d2e81968c4495bb3f3c6a73
Parent: 8df3f300ba9c6d68d6151ecc5e09543251d17db0
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Thu Mar 2 16:41:41 2017 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Thu Mar 2 16:41:41 2017 +0000
tools: Fix overriding of current_settings.
Settings specified in other command line args take precedence over
profiles and --config, which takes precedence over settings in actual
config files.
Since commit 1e2420bca85da9a37570871cd70192e9ae831786 ('commands: new
method for defining commands') commands like this:
lvchange --config 'global/test=1' -ay vg
have been printing the 'TEST MODE' message, but nevertheless making
real changes.
---
tools/lvmcmdline.c | 49 +++++++++++++++++++++++++++++++++++--------------
1 files changed, 35 insertions(+), 14 deletions(-)
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index f5b095c..d5385a8 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -2018,7 +2018,12 @@ int version(struct cmd_context *cmd __attribute__((unused)),
return ECMD_PROCESSED;
}
-static void _get_output_settings(struct cmd_context *cmd)
+static void _reset_current_settings_to_default(struct cmd_context *cmd)
+{
+ cmd->current_settings = cmd->default_settings;
+}
+
+static void _get_current_output_settings_from_args(struct cmd_context *cmd)
{
if (arg_is_set(cmd, debug_ARG))
cmd->current_settings.debug = _LOG_FATAL + (arg_count(cmd, debug_ARG) - 1);
@@ -2033,7 +2038,7 @@ static void _get_output_settings(struct cmd_context *cmd)
}
}
-static void _apply_output_settings(struct cmd_context *cmd)
+static void _apply_current_output_settings(struct cmd_context *cmd)
{
init_debug(cmd->current_settings.debug);
init_debug_classes_logged(cmd->default_settings.debug_classes);
@@ -2041,10 +2046,12 @@ static void _apply_output_settings(struct cmd_context *cmd)
init_silent(cmd->current_settings.silent);
}
-static int _get_settings(struct cmd_context *cmd)
+static int _get_current_settings(struct cmd_context *cmd)
{
const char *activation_mode;
+ _get_current_output_settings_from_args(cmd);
+
if (arg_is_set(cmd, test_ARG))
cmd->current_settings.test = arg_is_set(cmd, test_ARG);
@@ -2217,8 +2224,10 @@ int help(struct cmd_context *cmd __attribute__((unused)), int argc, char **argv)
return ret;
}
-static void _apply_settings(struct cmd_context *cmd)
+static void _apply_current_settings(struct cmd_context *cmd)
{
+ _apply_current_output_settings(cmd);
+
init_test(cmd->current_settings.test);
init_full_scan_done(0);
init_mirror_in_sync(0);
@@ -2542,13 +2551,12 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
}
/*
- * log_debug() can be enabled now that we know the settings
- * from the command. Previous calls to log_debug() will
- * do nothing.
+ * Now we have the command line args, set up any known output logging
+ * options immediately.
*/
- cmd->current_settings = cmd->default_settings;
- _get_output_settings(cmd);
- _apply_output_settings(cmd);
+ _reset_current_settings_to_default(cmd);
+ _get_current_output_settings_from_args(cmd);
+ _apply_current_output_settings(cmd);
log_debug("Parsing: %s", cmd->cmd_line);
@@ -2609,9 +2617,17 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
if (arg_is_set(cmd, readonly_ARG))
cmd->metadata_read_only = 1;
- if ((ret = _get_settings(cmd)))
+ /*
+ * Now that all configs, profiles and command lines args are available,
+ * freshly calculate and apply all settings. Specific command line
+ * options take precedence over config files (which include --config as
+ * that is treated like a config file).
+ */
+ _reset_current_settings_to_default(cmd);
+ if ((ret = _get_current_settings(cmd)))
goto_out;
- _apply_settings(cmd);
+ _apply_current_settings(cmd);
+
if (cmd->degraded_activation)
log_debug("DEGRADED MODE. Incomplete RAID LVs will be processed.");
@@ -2762,8 +2778,13 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
log_debug("Completed: %s", cmd->cmd_line);
- cmd->current_settings = cmd->default_settings;
- _apply_settings(cmd);
+ /*
+ * Reset all settings back to the persistent defaults that
+ * ignore everything supplied on the command line of the
+ * completed command.
+ */
+ _reset_current_settings_to_default(cmd);
+ _apply_current_settings(cmd);
/*
* free off any memory the command used.
6 years
master - commands: adjust syntax error message
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=8df3f300ba9c6d68d61...
Commit: 8df3f300ba9c6d68d6151ecc5e09543251d17db0
Parent: b76852bf35ca89f0c72bf30f1f86884ec53bc4c3
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Mar 2 09:37:54 2017 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Thu Mar 2 09:46:41 2017 -0600
commands: adjust syntax error message
---
tools/command.c | 11 ++++++++---
tools/command.h | 2 +-
tools/lvmcmdline.c | 9 ++++-----
3 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/tools/command.c b/tools/command.c
index 7c5bf7c..e0db503 100644
--- a/tools/command.c
+++ b/tools/command.c
@@ -1597,7 +1597,7 @@ static void print_usage_def(struct arg_def *def)
printf(" ...");
}
-void print_usage(struct command *cmd, int longhelp)
+void print_usage(struct command *cmd, int longhelp, int desc_first)
{
struct command_name *cname = find_command_name(cmd->name);
int onereq = (cmd->cmd_flags & CMD_FLAG_ONE_REQUIRED_OPT) ? 1 : 0;
@@ -1609,7 +1609,7 @@ void print_usage(struct command *cmd, int longhelp)
*/
factor_common_options();
- if (cmd->desc)
+ if (desc_first && cmd->desc)
_print_usage_description(cmd);
printf(" %s", cmd->name);
@@ -1709,7 +1709,12 @@ void print_usage(struct command *cmd, int longhelp)
printf(" ]");
done:
- printf("\n\n");
+ printf("\n");
+
+ if (!desc_first && cmd->desc)
+ _print_usage_description(cmd);
+
+ printf("\n");
return;
}
diff --git a/tools/command.h b/tools/command.h
index c5c801a..36554a3 100644
--- a/tools/command.h
+++ b/tools/command.h
@@ -213,7 +213,7 @@ struct command {
int define_commands(char *run_name);
int command_id_to_enum(const char *str);
-void print_usage(struct command *cmd, int longhelp);
+void print_usage(struct command *cmd, int longhelp, int desc_first);
void print_usage_common_cmd(struct command_name *cname, struct command *cmd);
void print_usage_common_lvm(struct command_name *cname, struct command *cmd);
void factor_common_options(void);
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index e2be7c7..f5b095c 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -1560,11 +1560,10 @@ static struct command *_find_command(struct cmd_context *cmd, const char *path,
if (!best_required) {
/* cmd did not have all the required opt/pos args of any command */
- log_error("Failed to find a matching command definition.");
- log_error("Run '%s --help' for more information.", name);
+ log_error("Incorrect syntax. Run '%s --help' for more information.", name);
if (close_ro) {
- log_warn("Closest command usage is:");
- print_usage(&_cmdline.commands[close_i], 0);
+ log_warn("Nearest similar command has syntax:");
+ print_usage(&_cmdline.commands[close_i], 0, 0);
}
return NULL;
}
@@ -1711,7 +1710,7 @@ static int _usage(const char *name, int longhelp)
if ((_cmdline.commands[i].cmd_flags & CMD_FLAG_SECONDARY_SYNTAX) && !longhelp)
continue;
- print_usage(&_cmdline.commands[i], longhelp);
+ print_usage(&_cmdline.commands[i], longhelp, 1);
cmd = &_cmdline.commands[i];
}
6 years
master - man lvchange: mention special activation vals
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=b76852bf35ca89f0c72...
Commit: b76852bf35ca89f0c72bf30f1f86884ec53bc4c3
Parent: 26ca308ba91454ab34a5eefa8c24d8f70a7c4308
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Mar 2 09:30:27 2017 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Thu Mar 2 09:31:06 2017 -0600
man lvchange: mention special activation vals
used by lvmlockd and clvmd.
---
tools/args.h | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/args.h b/tools/args.h
index 66de6d5..471a3c2 100644
--- a/tools/args.h
+++ b/tools/args.h
@@ -807,8 +807,8 @@ arg(activate_ARG, 'a', "activate", activation_VAL, 0, 0,
"if the list is set but empty, no LVs match.\n"
"Autoactivation should be used during system boot to make it possible\n"
"to select which LVs should be automatically activated by the system.\n"
- "See lvmlockd(8) for more information about activation options for shared VGs.\n"
- "See clvmd(8) for more information about activation options for clustered VGs.\n"
+ "See lvmlockd(8) for more information about activation options \\fBey\\fP and \\fBsy\\fP for shared VGs.\n"
+ "See clvmd(8) for more information about activation options \\fBey\\fP, \\fBsy\\fP, \\fBly\\fP and \\fBln\\fP for clustered VGs.\n"
"#lvcreate\n"
"Controls the active state of the new LV.\n"
"\\fBy\\fP makes the LV active, or available.\n"
6 years
master - lvmdbustest.py: Remove un-used variable
by Tony Asleson
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=26ca308ba91454ab34a...
Commit: 26ca308ba91454ab34a5eefa8c24d8f70a7c4308
Parent: 7b0371e74ecb4ceab18e937508daa66a8d636259
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Wed Mar 1 17:29:40 2017 -0600
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Wed Mar 1 17:47:04 2017 -0600
lvmdbustest.py: Remove un-used variable
Not needed with new validation function.
---
test/dbus/lvmdbustest.py | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/test/dbus/lvmdbustest.py b/test/dbus/lvmdbustest.py
index c0a3d64..58d8d10 100755
--- a/test/dbus/lvmdbustest.py
+++ b/test/dbus/lvmdbustest.py
@@ -483,7 +483,6 @@ class TestDbusService(unittest.TestCase):
(vg, thin_pool) = self._create_raid5_thin_pool()
vg_name_start = vg.Name
- mgr = self.objs[MANAGER_INT][0].Manager
# noinspection PyTypeChecker
self._verify_hidden_lookups(thin_pool.LvCommon, vg_name_start)
6 years
master - lvmdbustest.py: Validate LV lookups
by Tony Asleson
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=7b0371e74ecb4ceab18...
Commit: 7b0371e74ecb4ceab18e937508daa66a8d636259
Parent: 83249f332709037256bf0f3c7c3d3663addaffc6
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Wed Mar 1 17:26:23 2017 -0600
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Wed Mar 1 17:47:04 2017 -0600
lvmdbustest.py: Validate LV lookups
Ensure that the LV lookups work as expected for newly created LVs.
---
test/dbus/lvmdbustest.py | 108 ++++++++++++++++++++++++++++++++--------------
1 files changed, 76 insertions(+), 32 deletions(-)
diff --git a/test/dbus/lvmdbustest.py b/test/dbus/lvmdbustest.py
index 800f590..c0a3d64 100755
--- a/test/dbus/lvmdbustest.py
+++ b/test/dbus/lvmdbustest.py
@@ -267,6 +267,9 @@ class TestDbusService(unittest.TestCase):
def _create_raid5_thin_pool(self, vg=None):
+ meta_name = "meta_r5"
+ data_name = "data_r5"
+
if not vg:
pv_paths = []
for pp in self.objs[PV_INT]:
@@ -276,7 +279,7 @@ class TestDbusService(unittest.TestCase):
lv_meta_path = self.handle_return(
vg.LvCreateRaid(
- dbus.String("meta_r5"),
+ dbus.String(meta_name),
dbus.String("raid5"),
dbus.UInt64(mib(4)),
dbus.UInt32(0),
@@ -284,10 +287,11 @@ class TestDbusService(unittest.TestCase):
dbus.Int32(g_tmo),
EOD)
)
+ self._validate_lookup("%s/%s" % (vg.Name, meta_name), lv_meta_path)
lv_data_path = self.handle_return(
vg.LvCreateRaid(
- dbus.String("data_r5"),
+ dbus.String(data_name),
dbus.String("raid5"),
dbus.UInt64(mib(16)),
dbus.UInt32(0),
@@ -296,6 +300,8 @@ class TestDbusService(unittest.TestCase):
EOD)
)
+ self._validate_lookup("%s/%s" % (vg.Name, data_name), lv_data_path)
+
thin_pool_path = self.handle_return(
vg.CreateThinPool(
dbus.ObjectPath(lv_meta_path),
@@ -492,6 +498,9 @@ class TestDbusService(unittest.TestCase):
dbus.Int32(g_tmo),
EOD))
+ self._validate_lookup(
+ "%s/%s" % (vg_name_start, lv_name), thin_lv_path)
+
self.assertTrue(thin_lv_path != '/')
full_name = "%s/%s" % (vg_name_start, lv_name)
@@ -549,75 +558,88 @@ class TestDbusService(unittest.TestCase):
return lv
def test_lv_create(self):
+ lv_name = lv_n()
vg = self._vg_create().Vg
- self._test_lv_create(
+ lv = self._test_lv_create(
vg.LvCreate,
- (dbus.String(lv_n()), dbus.UInt64(mib(4)),
+ (dbus.String(lv_name), dbus.UInt64(mib(4)),
dbus.Array([], signature='(ott)'), dbus.Int32(g_tmo),
EOD), vg, LV_BASE_INT)
+ self._validate_lookup("%s/%s" % (vg.Name, lv_name), lv.object_path)
def test_lv_create_job(self):
-
+ lv_name = lv_n()
vg = self._vg_create().Vg
(object_path, job_path) = vg.LvCreate(
- dbus.String(lv_n()), dbus.UInt64(mib(4)),
+ dbus.String(lv_name), dbus.UInt64(mib(4)),
dbus.Array([], signature='(ott)'), dbus.Int32(0),
EOD)
self.assertTrue(object_path == '/')
self.assertTrue(job_path != '/')
object_path = self._wait_for_job(job_path)
+
+ self._validate_lookup("%s/%s" % (vg.Name, lv_name), object_path)
self.assertTrue(object_path != '/')
def test_lv_create_linear(self):
+ lv_name = lv_n()
vg = self._vg_create().Vg
- self._test_lv_create(
+ lv = self._test_lv_create(
vg.LvCreateLinear,
- (dbus.String(lv_n()), dbus.UInt64(mib(4)), dbus.Boolean(False),
+ (dbus.String(lv_name), dbus.UInt64(mib(4)), dbus.Boolean(False),
dbus.Int32(g_tmo), EOD),
vg, LV_BASE_INT)
+ self._validate_lookup("%s/%s" % (vg.Name, lv_name), lv.object_path)
def test_lv_create_striped(self):
+ lv_name = lv_n()
pv_paths = []
for pp in self.objs[PV_INT]:
pv_paths.append(pp.object_path)
vg = self._vg_create(pv_paths).Vg
- self._test_lv_create(
+ lv = self._test_lv_create(
vg.LvCreateStriped,
- (dbus.String(lv_n()), dbus.UInt64(mib(4)),
+ (dbus.String(lv_name), dbus.UInt64(mib(4)),
dbus.UInt32(2), dbus.UInt32(8), dbus.Boolean(False),
dbus.Int32(g_tmo), EOD),
vg, LV_BASE_INT)
+ self._validate_lookup("%s/%s" % (vg.Name, lv_name), lv.object_path)
def test_lv_create_mirror(self):
+ lv_name = lv_n()
pv_paths = []
for pp in self.objs[PV_INT]:
pv_paths.append(pp.object_path)
vg = self._vg_create(pv_paths).Vg
- self._test_lv_create(
+ lv = self._test_lv_create(
vg.LvCreateMirror,
- (dbus.String(lv_n()), dbus.UInt64(mib(4)), dbus.UInt32(2),
+ (dbus.String(lv_name), dbus.UInt64(mib(4)), dbus.UInt32(2),
dbus.Int32(g_tmo), EOD), vg, LV_BASE_INT)
+ self._validate_lookup("%s/%s" % (vg.Name, lv_name), lv.object_path)
def test_lv_create_raid(self):
+ lv_name = lv_n()
pv_paths = []
for pp in self.objs[PV_INT]:
pv_paths.append(pp.object_path)
vg = self._vg_create(pv_paths).Vg
- self._test_lv_create(
+ lv = self._test_lv_create(
vg.LvCreateRaid,
- (dbus.String(lv_n()), dbus.String('raid5'), dbus.UInt64(mib(16)),
+ (dbus.String(lv_name), dbus.String('raid5'), dbus.UInt64(mib(16)),
dbus.UInt32(2), dbus.UInt32(8), dbus.Int32(g_tmo),
EOD),
vg,
LV_BASE_INT)
+ self._validate_lookup("%s/%s" % (vg.Name, lv_name), lv.object_path)
def _create_lv(self, thinpool=False, size=None, vg=None):
+ lv_name = lv_n()
interfaces = list(LV_BASE_INT)
if thinpool:
@@ -633,12 +655,15 @@ class TestDbusService(unittest.TestCase):
if size is None:
size = mib(4)
- return self._test_lv_create(
+ lv = self._test_lv_create(
vg.LvCreateLinear,
- (dbus.String(lv_n()), dbus.UInt64(size),
+ (dbus.String(lv_name), dbus.UInt64(size),
dbus.Boolean(thinpool), dbus.Int32(g_tmo), EOD),
vg, interfaces)
+ self._validate_lookup("%s/%s" % (vg.Name, lv_name), lv.object_path)
+ return lv
+
def test_lv_create_rounding(self):
self._create_lv(size=(mib(2) + 13))
@@ -682,26 +707,32 @@ class TestDbusService(unittest.TestCase):
# This returns a LV with the LV interface, need to get a proxy for
# thinpool interface too
- tp = self._create_lv(True)
+ vg = self._vg_create().Vg
+ tp = self._create_lv(thinpool=True, vg=vg)
+
+ lv_name = lv_n('_thin_lv')
thin_path = self.handle_return(
tp.ThinPool.LvCreate(
- dbus.String(lv_n('_thin_lv')),
+ dbus.String(lv_name),
dbus.UInt64(mib(8)),
dbus.Int32(g_tmo),
EOD)
)
+ self._validate_lookup("%s/%s" % (vg.Name, lv_name), thin_path)
lv = ClientProxy(self.bus, thin_path,
interfaces=(LV_COMMON_INT, LV_INT))
+ re_named = 'rename_test' + lv.LvCommon.Name
rc = self.handle_return(
lv.Lv.Rename(
- dbus.String('rename_test' + lv.LvCommon.Name),
+ dbus.String(re_named),
dbus.Int32(g_tmo),
EOD)
)
+ self._validate_lookup("%s/%s" % (vg.Name, re_named), thin_path)
self.assertTrue(rc == '/')
self._check_consistency()
@@ -753,18 +784,18 @@ class TestDbusService(unittest.TestCase):
def test_lv_create_pv_specific(self):
vg = self._vg_create().Vg
-
+ lv_name = lv_n()
pv = vg.Pvs
-
pvp = ClientProxy(self.bus, pv[0], interfaces=(PV_INT,))
- self._test_lv_create(
+ lv = self._test_lv_create(
vg.LvCreate, (
- dbus.String(lv_n()),
+ dbus.String(lv_name),
dbus.UInt64(mib(4)),
dbus.Array([[pvp.object_path, 0, (pvp.Pv.PeCount - 1)]],
signature='(ott)'),
dbus.Int32(g_tmo), EOD), vg, LV_BASE_INT)
+ self._validate_lookup("%s/%s" % (vg.Name, lv_name), lv.object_path)
def test_lv_resize(self):
@@ -951,17 +982,20 @@ class TestDbusService(unittest.TestCase):
vg_proxy = self._vg_create(pv_paths)
for i in range(0, num_lvs):
-
+ lv_name = lv_n()
vg_proxy.update()
if vg_proxy.Vg.FreeCount > 0:
- job = self.handle_return(
+ lv_path = self.handle_return(
vg_proxy.Vg.LvCreateLinear(
- dbus.String(lv_n()),
+ dbus.String(lv_name),
dbus.UInt64(mib(4)),
dbus.Boolean(False),
dbus.Int32(g_tmo),
EOD))
- self.assertTrue(job != '/')
+ self.assertTrue(lv_path != '/')
+ self._validate_lookup(
+ "%s/%s" % (vg_proxy.Vg.Name, lv_name), lv_path)
+
else:
# We ran out of space, test will probably fail
break
@@ -1070,15 +1104,18 @@ class TestDbusService(unittest.TestCase):
def test_lv_tags(self):
vg = self._vg_create().Vg
+ lv_name = lv_n()
lv = self._test_lv_create(
vg.LvCreateLinear,
- (dbus.String(lv_n()),
+ (dbus.String(lv_name),
dbus.UInt64(mib(4)),
dbus.Boolean(False),
dbus.Int32(g_tmo),
EOD),
vg, LV_BASE_INT)
+ self._validate_lookup("%s/%s" % (vg.Name, lv_name), lv.object_path)
+
t = ['Testing', 'tags']
self.handle_return(
@@ -1154,15 +1191,18 @@ class TestDbusService(unittest.TestCase):
def test_vg_activate_deactivate(self):
vg = self._vg_create().Vg
- self._test_lv_create(
+ lv_name = lv_n()
+ lv = self._test_lv_create(
vg.LvCreateLinear, (
- dbus.String(lv_n()),
+ dbus.String(lv_name),
dbus.UInt64(mib(4)),
dbus.Boolean(False),
dbus.Int32(g_tmo),
EOD),
vg, LV_BASE_INT)
+ self._validate_lookup("%s/%s" % (vg.Name, lv_name), lv.object_path)
+
vg.update()
rc = self.handle_return(
@@ -1367,15 +1407,19 @@ class TestDbusService(unittest.TestCase):
def test_snapshot_merge_thin(self):
# Create a thin LV, snapshot it and merge it
- tp = self._create_lv(True)
+ vg = self._vg_create().Vg
+ tp = self._create_lv(thinpool=True, vg=vg)
+ lv_name = lv_n('_thin_lv')
thin_path = self.handle_return(
tp.ThinPool.LvCreate(
- dbus.String(lv_n('_thin_lv')),
+ dbus.String(lv_name),
dbus.UInt64(mib(10)),
dbus.Int32(g_tmo),
EOD))
+ self._validate_lookup("%s/%s" % (vg.Name, lv_name), thin_path)
+
lv_p = ClientProxy(self.bus, thin_path,
interfaces=(LV_INT, LV_COMMON_INT))
6 years
master - lvmdbustest.py: Validate PV device
by Tony Asleson
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=83249f332709037256b...
Commit: 83249f332709037256bf0f3c7c3d3663addaffc6
Parent: 4c89d3794c64b674191bb9c767415cc2ba919e3a
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Wed Mar 1 17:24:08 2017 -0600
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Wed Mar 1 17:47:04 2017 -0600
lvmdbustest.py: Validate PV device
Validate device lookup after PV creation.
---
test/dbus/lvmdbustest.py | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/test/dbus/lvmdbustest.py b/test/dbus/lvmdbustest.py
index 0e27ae3..800f590 100755
--- a/test/dbus/lvmdbustest.py
+++ b/test/dbus/lvmdbustest.py
@@ -198,6 +198,9 @@ class TestDbusService(unittest.TestCase):
self.objs[MANAGER_INT][0].Manager.PvCreate(
dbus.String(device), dbus.Int32(g_tmo), EOD)
)
+
+ self._validate_lookup(device, pv_path)
+
self.assertTrue(pv_path is not None and len(pv_path) > 0)
return pv_path
6 years
master - lvmdbustest.py: Re-name validation function
by Tony Asleson
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=4c89d3794c64b674191...
Commit: 4c89d3794c64b674191bb9c767415cc2ba919e3a
Parent: 10c3d94159e3a740e22bb3c72fef18cb26bfc19f
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Wed Mar 1 17:22:32 2017 -0600
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Wed Mar 1 17:47:04 2017 -0600
lvmdbustest.py: Re-name validation function
Make this name generic as we can use for different types.
---
test/dbus/lvmdbustest.py | 19 ++++++++++---------
1 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/test/dbus/lvmdbustest.py b/test/dbus/lvmdbustest.py
index 7ee4a49..0e27ae3 100755
--- a/test/dbus/lvmdbustest.py
+++ b/test/dbus/lvmdbustest.py
@@ -229,7 +229,7 @@ class TestDbusService(unittest.TestCase):
dbus.Int32(g_tmo),
EOD))
- self._validate_vg_lookup(vg_name, vg_path)
+ self._validate_lookup(vg_name, vg_path)
self.assertTrue(vg_path is not None and len(vg_path) > 0)
return ClientProxy(self.bus, vg_path, interfaces=(VG_INT, ))
@@ -343,9 +343,10 @@ class TestDbusService(unittest.TestCase):
return self.objs[MANAGER_INT][0].\
Manager.LookUpByLvmId(dbus.String(lvm_id))
- def _validate_vg_lookup(self, vg_name, object_path):
- t = self._lookup(vg_name)
- self.assertTrue(object_path == t, "%s != %s" % (object_path, t))
+ def _validate_lookup(self, lvm_name, object_path):
+ t = self._lookup(lvm_name)
+ self.assertTrue(
+ object_path == t, "%s != %s for %s" % (object_path, t, lvm_name))
def test_lookup_by_lvm_id(self):
# For the moment lets just lookup what we know about which is PVs
@@ -932,7 +933,7 @@ class TestDbusService(unittest.TestCase):
self.assertTrue(vg_job and len(vg_job) > 0)
vg_path = self._wait_for_job(vg_job)
- self._validate_vg_lookup(vg_name, vg_path)
+ self._validate_lookup(vg_name, vg_path)
def _test_expired_timer(self, num_lvs):
rc = False
@@ -1521,7 +1522,7 @@ class TestDbusService(unittest.TestCase):
dbus.Array(pv_paths, 'o'),
dbus.Int32(g_tmo),
EOD))
- self._validate_vg_lookup(vg_name, vg_path)
+ self._validate_lookup(vg_name, vg_path)
vg_proxy = ClientProxy(self.bus, vg_path, interfaces=(VG_INT, ))
@@ -1575,7 +1576,7 @@ class TestDbusService(unittest.TestCase):
dbus.Array(pv_paths, 'o'),
dbus.Int32(g_tmo),
EOD))
- self._validate_vg_lookup(vg_name, vg_path)
+ self._validate_lookup(vg_name, vg_path)
vg_proxy = ClientProxy(self.bus, vg_path, interfaces=(VG_INT, ))
@@ -1606,7 +1607,7 @@ class TestDbusService(unittest.TestCase):
dbus.Array(pv_paths, 'o'),
dbus.Int32(g_tmo),
EOD))
- self._validate_vg_lookup(vg_name, vg_path)
+ self._validate_lookup(vg_name, vg_path)
vg_proxy = ClientProxy(self.bus, vg_path, interfaces=(VG_INT, ))
for i in range(1, 64):
@@ -1639,7 +1640,7 @@ class TestDbusService(unittest.TestCase):
dbus.Array(pv_paths, 'o'),
dbus.Int32(g_tmo),
EOD))
- self._validate_vg_lookup(vg_name, vg_path)
+ self._validate_lookup(vg_name, vg_path)
vg_proxy = ClientProxy(self.bus, vg_path, interfaces=(VG_INT, ))
tag = '--h/K.6g0A4FOEatf3+k_nI/Yp&L_u2oy-=j649x:+dUcYWPEo6.IWT0c'
6 years
master - lvmdbustest.py: Verify lookups work immediately after vg create
by Tony Asleson
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=10c3d94159e3a740e22...
Commit: 10c3d94159e3a740e22bb3c72fef18cb26bfc19f
Parent: 157948b5a5f6f651fa56ec45f71b031c1a132c15
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Wed Mar 1 11:09:51 2017 -0600
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Wed Mar 1 17:47:04 2017 -0600
lvmdbustest.py: Verify lookups work immediately after vg create
---
test/dbus/lvmdbustest.py | 25 ++++++++++++++++++++-----
1 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/test/dbus/lvmdbustest.py b/test/dbus/lvmdbustest.py
index 20bf38e..7ee4a49 100755
--- a/test/dbus/lvmdbustest.py
+++ b/test/dbus/lvmdbustest.py
@@ -229,6 +229,7 @@ class TestDbusService(unittest.TestCase):
dbus.Int32(g_tmo),
EOD))
+ self._validate_vg_lookup(vg_name, vg_path)
self.assertTrue(vg_path is not None and len(vg_path) > 0)
return ClientProxy(self.bus, vg_path, interfaces=(VG_INT, ))
@@ -342,6 +343,10 @@ class TestDbusService(unittest.TestCase):
return self.objs[MANAGER_INT][0].\
Manager.LookUpByLvmId(dbus.String(lvm_id))
+ def _validate_vg_lookup(self, vg_name, object_path):
+ t = self._lookup(vg_name)
+ self.assertTrue(object_path == t, "%s != %s" % (object_path, t))
+
def test_lookup_by_lvm_id(self):
# For the moment lets just lookup what we know about which is PVs
# When we start testing VGs and LVs we will test lookups for those
@@ -926,7 +931,8 @@ class TestDbusService(unittest.TestCase):
self.assertTrue(vg_path == '/')
self.assertTrue(vg_job and len(vg_job) > 0)
- self._wait_for_job(vg_job)
+ vg_path = self._wait_for_job(vg_job)
+ self._validate_vg_lookup(vg_name, vg_path)
def _test_expired_timer(self, num_lvs):
rc = False
@@ -1508,12 +1514,14 @@ class TestDbusService(unittest.TestCase):
EOD))
# Create a VG and try to create LVs with different bad names
+ vg_name = vg_n()
vg_path = self.handle_return(
mgr.VgCreate(
- dbus.String(vg_n()),
+ dbus.String(vg_name),
dbus.Array(pv_paths, 'o'),
dbus.Int32(g_tmo),
EOD))
+ self._validate_vg_lookup(vg_name, vg_path)
vg_proxy = ClientProxy(self.bus, vg_path, interfaces=(VG_INT, ))
@@ -1559,13 +1567,16 @@ class TestDbusService(unittest.TestCase):
def test_invalid_tags(self):
mgr = self.objs[MANAGER_INT][0].Manager
pv_paths = [self.objs[PV_INT][0].object_path]
+ vg_name = vg_n()
vg_path = self.handle_return(
mgr.VgCreate(
- dbus.String(vg_n()),
+ dbus.String(vg_name),
dbus.Array(pv_paths, 'o'),
dbus.Int32(g_tmo),
EOD))
+ self._validate_vg_lookup(vg_name, vg_path)
+
vg_proxy = ClientProxy(self.bus, vg_path, interfaces=(VG_INT, ))
for c in self._invalid_tag_characters():
@@ -1587,13 +1598,15 @@ class TestDbusService(unittest.TestCase):
def test_tag_names(self):
mgr = self.objs[MANAGER_INT][0].Manager
pv_paths = [self.objs[PV_INT][0].object_path]
+ vg_name = vg_n()
vg_path = self.handle_return(
mgr.VgCreate(
- dbus.String(vg_n()),
+ dbus.String(vg_name),
dbus.Array(pv_paths, 'o'),
dbus.Int32(g_tmo),
EOD))
+ self._validate_vg_lookup(vg_name, vg_path)
vg_proxy = ClientProxy(self.bus, vg_path, interfaces=(VG_INT, ))
for i in range(1, 64):
@@ -1618,13 +1631,15 @@ class TestDbusService(unittest.TestCase):
def test_tag_regression(self):
mgr = self.objs[MANAGER_INT][0].Manager
pv_paths = [self.objs[PV_INT][0].object_path]
+ vg_name = vg_n()
vg_path = self.handle_return(
mgr.VgCreate(
- dbus.String(vg_n()),
+ dbus.String(vg_name),
dbus.Array(pv_paths, 'o'),
dbus.Int32(g_tmo),
EOD))
+ self._validate_vg_lookup(vg_name, vg_path)
vg_proxy = ClientProxy(self.bus, vg_path, interfaces=(VG_INT, ))
tag = '--h/K.6g0A4FOEatf3+k_nI/Yp&L_u2oy-=j649x:+dUcYWPEo6.IWT0c'
6 years