master - help: fix missing required option
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=b4e78b26f53194ef8b3...
Commit: b4e78b26f53194ef8b3b1e623715c96db1046e42
Parent: 4d0172ff15c8af6e5df22afca1c8dc9725c3684f
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Wed Mar 8 15:00:27 2017 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Wed Mar 8 15:00:27 2017 -0600
help: fix missing required option
Fix for previous commit 4d0172ff15c.
---
tools/command.c | 3 ---
1 files changed, 0 insertions(+), 3 deletions(-)
diff --git a/tools/command.c b/tools/command.c
index d001f94..1f31468 100644
--- a/tools/command.c
+++ b/tools/command.c
@@ -1701,9 +1701,6 @@ void print_usage(struct command *cmd, int longhelp, int desc_first)
for (ro = 0; ro < cmd->ro_count; ro++) {
opt_enum = cmd->required_opt_args[ro].opt;
- if (!opt_names[opt_enum].short_opt)
- continue;
-
if ((opt_enum == size_ARG) && command_has_alternate_extents(cmd->name))
include_extents = 1;
6 years, 3 months
master - man/help: use order of required options from cmd def
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=4d0172ff15c8af6e5df...
Commit: 4d0172ff15c8af6e5df22afca1c8dc9725c3684f
Parent: 3d5182c81946bb7e7e0a704ce3e4585968055dc8
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Wed Mar 8 14:51:08 2017 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Wed Mar 8 14:51:08 2017 -0600
man/help: use order of required options from cmd def
Follow the same as written in command-lines.in
---
tools/command-lines.in | 3 ++-
tools/command.c | 32 +++-----------------------------
2 files changed, 5 insertions(+), 30 deletions(-)
diff --git a/tools/command-lines.in b/tools/command-lines.in
index 4f2ab44..150f572 100644
--- a/tools/command-lines.in
+++ b/tools/command-lines.in
@@ -350,7 +350,8 @@ lvconvert --type raid LV
OO: OO_LVCONVERT_RAID, OO_LVCONVERT
OP: PV ...
ID: lvconvert_raid_types
-DESC: Convert LV to raid or change raid layout.
+DESC: Convert LV to raid or change raid layout
+DESC: (a specific raid level must be used, e.g. raid1).
RULE: all not lv_is_locked lv_is_pvmove
lvconvert --mirrors SNumber LV
diff --git a/tools/command.c b/tools/command.c
index 0d56e51..d001f94 100644
--- a/tools/command.c
+++ b/tools/command.c
@@ -1698,8 +1698,6 @@ void print_usage(struct command *cmd, int longhelp, int desc_first)
if (cmd->ro_count) {
first = 1;
- /* print options with short opts */
-
for (ro = 0; ro < cmd->ro_count; ro++) {
opt_enum = cmd->required_opt_args[ro].opt;
@@ -1717,35 +1715,11 @@ void print_usage(struct command *cmd, int longhelp, int desc_first)
first = 0;
}
- printf(" -%c|%s", opt_names[opt_enum].short_opt, opt_names[opt_enum].long_opt);
- if (cmd->required_opt_args[ro].def.val_bits) {
- printf(" ");
- print_usage_def(cmd, opt_enum, &cmd->required_opt_args[ro].def);
- }
- }
-
- /* print options without short opts */
-
- for (ro = 0; ro < cmd->ro_count; ro++) {
- opt_enum = cmd->required_opt_args[ro].opt;
-
if (opt_names[opt_enum].short_opt)
- continue;
-
- if ((opt_enum == size_ARG) && command_has_alternate_extents(cmd->name))
- include_extents = 1;
-
- if (onereq) {
- if (first)
- printf("\n\t(");
- else {
- printf(",\n\t ");
- printf(" "); /* align for no short opt */
- }
- first = 0;
- }
+ printf(" -%c|%s", opt_names[opt_enum].short_opt, opt_names[opt_enum].long_opt);
+ else
+ printf(" %s", opt_names[opt_enum].long_opt);
- printf(" %s", opt_names[opt_enum].long_opt);
if (cmd->required_opt_args[ro].def.val_bits) {
printf(" ");
print_usage_def(cmd, opt_enum, &cmd->required_opt_args[ro].def);
6 years, 3 months
master - man: add more references to topical man pages
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=3d5182c81946bb7e7e0...
Commit: 3d5182c81946bb7e7e0a704ce3e4585968055dc8
Parent: 14c7912f45ec9df0fc72e1e3844f04faf6590edf
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Wed Mar 8 14:43:30 2017 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Wed Mar 8 14:43:30 2017 -0600
man: add more references to topical man pages
---
tools/args.h | 65 ++++++++++++++++++++++++++++++++++-----------------------
1 files changed, 39 insertions(+), 26 deletions(-)
diff --git a/tools/args.h b/tools/args.h
index 821c56d..a9ffe5b 100644
--- a/tools/args.h
+++ b/tools/args.h
@@ -37,7 +37,8 @@ arg(activationmode_ARG, '\0', "activationmode", activationmode_VAL, 0, 0,
"(This does not include the \"mirror\" type, see \"raid1\" instead.)\n"
"\\fBpartial\\fP allows any LV with missing PVs to be activated, and\n"
"should only be used for recovery or repair.\n"
- "For default, see lvm.conf/activation_mode.\n")
+ "For default, see lvm.conf/activation_mode.\n"
+ "See \\fBlvmraid\\fP(7) for more information.\n")
arg(addtag_ARG, '\0', "addtag", tag_VAL, ARG_GROUPABLE, 0,
"Adds a tag to a PV, VG or LV. This option can be repeated to add\n"
@@ -62,7 +63,7 @@ arg(alloc_ARG, '\0', "alloc", alloc_VAL, 0, 0,
"e.g. by placing two stripes on the same PV.\n"
"Optional positional PV args on the command line can also be used to limit\n"
"which PVs the command will use for allocation.\n"
- "See lvm(8) for more information about allocation.\n")
+ "See \\fBlvm\\fP(8) for more information about allocation.\n")
arg(atomic_ARG, '\0', "atomic", 0, 0, 0,
"Makes a pvmove operation atomic, ensuring that all affected LVs are\n"
@@ -119,13 +120,13 @@ arg(cachepool_ARG, '\0', "cachepool", lv_VAL, 0, 0,
arg(commandprofile_ARG, '\0', "commandprofile", string_VAL, 0, 0,
"The command profile to use for command configuration.\n"
- "See lvm.conf(5) for more information about profiles.\n")
+ "See \\fBlvm.conf\\fP(5) for more information about profiles.\n")
arg(config_ARG, '\0', "config", string_VAL, 0, 0,
"Config settings for the command. These override lvm.conf settings.\n"
"The String arg uses the same format as lvm.conf,\n"
"or may use section/field syntax.\n"
- "See lvm.conf(5) for more information about config.\n")
+ "See \\fBlvm.conf\\fP(5) for more information about config.\n")
arg(configreport_ARG, '\0', "configreport", configreport_VAL, ARG_GROUPABLE, 1,
"See lvmreport(7).\n")
@@ -149,7 +150,7 @@ arg(deltag_ARG, '\0', "deltag", tag_VAL, ARG_GROUPABLE, 0,
arg(detachprofile_ARG, '\0', "detachprofile", 0, 0, 0,
"Detaches a metadata profile from a VG or LV.\n"
- "See lvm.conf(5) for more information about profiles.\n")
+ "See \\fBlvm.conf\\fP(5) for more information about profiles.\n")
arg(discards_ARG, '\0', "discards", discards_VAL, 0, 0,
"Specifies how the device-mapper thin pool layer in the kernel should\n"
@@ -158,7 +159,8 @@ arg(discards_ARG, '\0', "discards", discards_VAL, 0, 0,
"\\fBnopassdown\\fP causes the thin pool to process discards itself to\n"
"allow reuse of unneeded extents in the thin pool.\n"
"\\fBpassdown\\fP causes the thin pool to process discards itself\n"
- "(like nopassdown) and pass the discards to the underlying device.\n")
+ "(like nopassdown) and pass the discards to the underlying device.\n"
+ "See \\fBlvmthin\\fP(7) for more information.\n")
arg(driverloaded_ARG, '\0', "driverloaded", bool_VAL, 0, 0,
"If set to no, the command will not attempt to use device-mapper.\n"
@@ -171,7 +173,8 @@ arg(errorwhenfull_ARG, '\0', "errorwhenfull", bool_VAL, 0, 0,
"When no, device-mapper will queue these I/O requests for a\n"
"period of time to allow the thin pool to be extended.\n"
"Errors are returned if no space is available after the timeout.\n"
- "(Also see dm-thin-pool kernel module option no_space_timeout.)\n")
+ "(Also see dm-thin-pool kernel module option no_space_timeout.)\n"
+ "See \\fBlvmthin\\fP(7) for more information.\n")
arg(force_long_ARG, '\0', "force", 0, ARG_COUNTABLE, 0,
"Force metadata restore even with thin pool LVs.\n"
@@ -250,7 +253,8 @@ arg(longhelp_ARG, '\0', "longhelp", 0, 0, 0,
arg(maxrecoveryrate_ARG, '\0', "maxrecoveryrate", sizekb_VAL, 0, 0,
"Sets the maximum recovery rate for a RAID LV. The rate value\n"
"is an amount of data per second for each device in the array.\n"
- "Setting the rate to 0 means it will be unbounded.\n")
+ "Setting the rate to 0 means it will be unbounded.\n"
+ "See \\fBlvmraid\\fP(7) for more information.\n")
arg(merge_ARG, '\0', "merge", 0, 0, 0,
"An alias for --mergethin, --mergemirrors, or --mergesnapshot,\n"
@@ -277,7 +281,8 @@ arg(mergesnapshot_ARG, '\0', "mergesnapshot", 0, 0, 0,
arg(mergethin_ARG, '\0', "mergethin", 0, 0, 0,
"Merge thin LV into its origin LV.\n"
"The origin thin LV takes the content of the thin snapshot,\n"
- "and the thin snapshot LV is removed.\n")
+ "and the thin snapshot LV is removed.\n"
+ "See \\fBlvmthin\\fP(7) for more information.\n")
arg(mergedconfig_ARG, '\0', "mergedconfig", 0, 0, 0,
"When the command is run with --config\n"
@@ -286,7 +291,7 @@ arg(mergedconfig_ARG, '\0', "mergedconfig", 0, 0, 0,
"merge all the contents of the \"config cascade\" before displaying it.\n"
"Without merging, only the configuration at the front of the\n"
"cascade is displayed.\n"
- "See lvm.conf(5) for more information about config.\n")
+ "See \\fBlvm.conf\\fP(5) for more information about config.\n")
arg(metadataignore_ARG, '\0', "metadataignore", bool_VAL, 0, 0,
"Specifies the metadataignore property of a PV.\n"
@@ -296,7 +301,7 @@ arg(metadataignore_ARG, '\0', "metadataignore", bool_VAL, 0, 0,
arg(metadataprofile_ARG, '\0', "metadataprofile", string_VAL, 0, 0,
"The metadata profile to use for command configuration.\n"
- "See lvm.conf(5) for more information about profiles.\n")
+ "See \\fBlvm.conf\\fP(5) for more information about profiles.\n")
arg(metadatasize_ARG, '\0', "metadatasize", sizemb_VAL, 0, 0,
"The approximate amount of space used for each VG metadata area.\n"
@@ -312,7 +317,8 @@ arg(minor_ARG, '\0', "minor", number_VAL, ARG_GROUPABLE, 0,
arg(minrecoveryrate_ARG, '\0', "minrecoveryrate", sizekb_VAL, 0, 0,
"Sets the minimum recovery rate for a RAID LV. The rate value\n"
"is an amount of data per second for each device in the array.\n"
- "Setting the rate to 0 means it will be unbounded.\n")
+ "Setting the rate to 0 means it will be unbounded.\n"
+ "See \\fBlvmraid\\fP(7) for more information.\n")
arg(mirrorlog_ARG, '\0', "mirrorlog", mirrorlog_VAL, 0, 0,
"Specifies the type of mirror log for LVs with the \"mirror\" type\n"
@@ -477,16 +483,19 @@ arg(rebuild_ARG, '\0', "rebuild", pv_VAL, ARG_GROUPABLE, 0,
"repeating this option.\n"
"Use this option in place of --resync or --syncaction repair when the\n"
"PVs with corrupted data are known, and their data should be reconstructed\n"
- "rather than reconstructing default (rotating) data.\n")
+ "rather than reconstructing default (rotating) data.\n"
+ "See \\fBlvmraid\\fP(7) for more information.\n")
arg(repair_ARG, '\0', "repair", 0, 0, 0,
"Replace failed PVs in a raid or mirror LV, or run a repair\n"
- "utility on a thin pool.\n")
+ "utility on a thin pool. See \\fBlvmraid\\fP(7) and \\fBlvmthin\\fP(7)\n"
+ "for more information.\n")
arg(replace_ARG, '\0', "replace", pv_VAL, ARG_GROUPABLE, 0,
"Replace a specific PV in a raid LV with another PV.\n"
"The new PV to use can be optionally specified after the LV.\n"
- "Multiple PVs can be replaced by repeating this option.\n")
+ "Multiple PVs can be replaced by repeating this option.\n"
+ "See \\fBlvmraid\\fP(7) for more information.\n")
arg(reportformat_ARG, '\0', "reportformat", reportformat_VAL, 0, 0,
"Overrides current output format for reports which is defined globally by\n"
@@ -494,7 +503,7 @@ arg(reportformat_ARG, '\0', "reportformat", reportformat_VAL, 0, 0,
"\\fBbasic\\fP is the original format with columns and rows.\n"
"If there is more than one report per command, each report is prefixed\n"
"with the report name for identification. \\fBjson\\fP produces report\n"
- "output in JSON format.\n")
+ "output in JSON format. See \\fBlvmreport\\fP(7) for more information.\n")
arg(restorefile_ARG, '\0', "restorefile", string_VAL, 0, 0,
"In conjunction with --uuid, this reads the file (produced by\n"
@@ -515,7 +524,8 @@ arg(resync_ARG, '\0', "resync", 0, 0, 0,
"Also see --rebuild to synchronize a specific PV.\n"
"During synchronization, data is read from the primary mirror device\n"
"and copied to the others. This can take considerable time, during\n"
- "which the LV is without a complete redundant copy of the data.\n")
+ "which the LV is without a complete redundant copy of the data.\n"
+ "See \\fBlvmraid\\fP(7) for more information.\n")
arg(rows_ARG, '\0', "rows", 0, 0, 0,
"Output columns as rows.\n")
@@ -653,8 +663,8 @@ arg(trustcache_ARG, '\0', "trustcache", 0, 0, 0,
"Avoids certain device scanning during command processing. Do not use.\n")
arg(type_ARG, '\0', "type", segtype_VAL, 0, 0,
- "Specifies an LV type, or \"segment type\".\n"
- "See usage definitions for specific ways to use these types.\n"
+ "The LV type, also known as \"segment type\" or \"segtype\".\n"
+ "See usage descriptions for the specific ways to use these types.\n"
"For more information about redundancy and performance (\\fBraid\\fP<N>, \\fBmirror\\fP, \\fBstriped\\fP, \\fBlinear\\fP) see \\fBlvmraid\\fP(7).\n"
"For thin provisioning (\\fBthin\\fP, \\fBthin-pool\\fP) see \\fBlvmthin\\fP(7).\n"
"For performance caching (\\fBcache\\fP, \\fBcache-pool\\fP) see \\fBlvmcache\\fP(7).\n"
@@ -673,7 +683,7 @@ arg(uncache_ARG, '\0', "uncache", 0, 0, 0,
arg(cachepolicy_ARG, '\0', "cachepolicy", string_VAL, 0, 0,
"Specifies the cache policy for a cache LV.\n"
- "See lvmcache(7) for more information.\n")
+ "See \\fBlvmcache\\fP(7) for more information.\n")
arg(cachesettings_ARG, '\0', "cachesettings", string_VAL, ARG_GROUPABLE, 0,
"Specifies tunable values for a cache LV in \"Key = Value\" form.\n"
@@ -682,7 +692,7 @@ arg(cachesettings_ARG, '\0', "cachesettings", string_VAL, ARG_GROUPABLE, 0,
"The special string value \\fBdefault\\fP switches\n"
"settings back to their default kernel values and removes\n"
"them from the list of settings stored in LVM metadata.\n"
- "See lvmcache(7) for more information.\n")
+ "See \\fBlvmcache\\fP(7) for more information.\n")
arg(unconfigured_ARG, '\0', "unconfigured", 0, 0, 0,
"Internal option used for generating config file during build.\n")
@@ -884,7 +894,8 @@ arg(chunksize_ARG, 'c', "chunksize", sizekb_VAL, 0, 0,
"For a thin pool the value must be between 64KiB and 1GiB\n"
"and the default value starts with 64 and scales up to fit the\n"
"pool metadata size within 128MiB, if the pool metadata size is not specified.\n"
- "The value must be a multiple of 64KiB.\n")
+ "The value must be a multiple of 64KiB.\n"
+ "See \\fBlvmthin\\fP(7) and \\fBlvmcache\\fP(7) for more information.\n")
arg(clustered_ARG, 'c', "clustered", bool_VAL, 0, 0,
"#vgcreate\n"
@@ -950,7 +961,7 @@ arg(help_ARG, 'h', "help", 0, 0, 0,
arg(cache_ARG, 'H', "cache", 0, 0, 0,
"Specifies the command is handling a cache LV or cache pool.\n"
"See --type cache and --type cache-pool.\n"
- "See lvmcache(7) for more information about LVM caching.\n")
+ "See \\fBlvmcache\\fP(7) for more information about LVM caching.\n")
arg(history_ARG, 'H', "history", 0, 0, 0,
"Include historical LVs in the output.\n"
@@ -1121,6 +1132,7 @@ arg(mirrors_ARG, 'm', "mirrors", snumber_VAL, 0, 0,
"Use lvm.conf global/mirror_segtype_default and\n"
"global/raid10_segtype_default to configure the default types.\n"
"See the --nosync option for avoiding initial image synchronization.\n"
+ "See \\fBlvmraid\\fP(7) for more information.\n"
"#lvconvert\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"
@@ -1137,6 +1149,7 @@ arg(mirrors_ARG, 'm', "mirrors", snumber_VAL, 0, 0,
"the number is added to the current number of images,\n"
"or the minus prefix \\fB-\\fP can be used, in which case\n"
"the number is subtracted from the current number of images.\n"
+ "See \\fBlvmraid\\fP(7) for more information.\n"
"#lvextend\n"
"Not used.\n")
@@ -1272,7 +1285,7 @@ arg(snapshot_ARG, 's', "snapshot", 0, 0, 0,
"when a thin pool is specified. Unprovisioned blocks in the thin snapshot\n"
"LV are read from the external origin LV. The external origin LV must\n"
"be read-only.\n"
- "See lvmthin(7) for more information about LVM thin provisioning.\n"
+ "See \\fBlvmthin\\fP(7) for more information about LVM thin provisioning.\n"
"COW snapshots are created when a size is specified. The size is allocated\n"
"from space in the VG, and is the amount of space that can be used\n"
"for saving COW blocks as writes occur to the origin or snapshot.\n"
@@ -1318,7 +1331,7 @@ arg(test_ARG, 't', "test", 0, 0, 0,
arg(thin_ARG, 'T', "thin", 0, 0, 0,
"Specifies the command is handling a thin LV or thin pool.\n"
"See --type thin, --type thin-pool, and --virtualsize.\n"
- "See lvmthin(7) for more information about LVM thin provisioning.\n")
+ "See \\fBlvmthin\\fP(7) for more information about LVM thin provisioning.\n")
arg(uuid_ARG, 'u', "uuid", 0, 0, 0,
"#pvchange\n"
@@ -1350,7 +1363,7 @@ arg(volumegroup_ARG, 'V', "volumegroup", 0, 0, 0, NULL)
arg(virtualsize_ARG, 'V', "virtualsize", sizemb_VAL, 0, 0,
"The virtual size of a new thin LV.\n"
- "See lvmthin(7) for more information about LVM thin provisioning.\n"
+ "See \\fBlvmthin\\fP(7) for more information about LVM thin provisioning.\n"
"Using virtual size (-V) and actual size (-L) together creates\n"
"a sparse LV.\n"
"lvm.conf global/sparse_segtype_default determines the\n"
6 years, 3 months
master - tests: add test for relative option values
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=14c7912f45ec9df0fc7...
Commit: 14c7912f45ec9df0fc72e1e3844f04faf6590edf
Parent: a6a2788e7cb3a7bce73b03644351f15f26a6ad36
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Wed Mar 8 13:51:33 2017 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Wed Mar 8 13:51:33 2017 -0600
tests: add test for relative option values
Combinations of: lvcreate/lvresize/lvextend/lvreduce,
--size/--extents/--poolmetadatasize, +/-/nosign.
---
test/shell/relative-sign-options.sh | 80 +++++++++++++++++++++++++++++++++++
1 files changed, 80 insertions(+), 0 deletions(-)
diff --git a/test/shell/relative-sign-options.sh b/test/shell/relative-sign-options.sh
new file mode 100644
index 0000000..00f5791
--- /dev/null
+++ b/test/shell/relative-sign-options.sh
@@ -0,0 +1,80 @@
+#!/bin/sh
+# Copyright (C) 2008-2013 Red Hat, Inc. All rights reserved.
+#
+# 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 General Public License v.2.
+#
+# You should have received a copy of the GNU 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
+
+test_description='Exercise toollib process_each_lv'
+SKIP_WITH_LVMPOLLD=1
+
+# disable lvmetad logging as it bogs down test systems
+export LVM_TEST_LVMETAD_DEBUG_OPTS=${LVM_TEST_LVMETAD_DEBUG_OPTS-}
+
+. lib/inittest
+
+aux prepare_vg 1 256
+
+lvcreate -an -n $lv1 -l4 $vg
+lvcreate -an -n $lv2 -L4 $vg
+lvcreate -an -n $lv3 -l+4 $vg
+lvcreate -an -n $lv4 -L+4 $vg
+not lvcreate -n $lv5 -l-4 $vg
+not lvcreate -n $lv5 -L-4 $vg
+
+lvremove $vg/$lv1
+lvremove $vg/$lv2
+lvremove $vg/$lv3
+lvremove $vg/$lv4
+
+lvcreate -an -n $lv1 -l4 $vg
+lvresize -y -l8 $vg/$lv1
+lvresize -y -L16 $vg/$lv1
+lvresize -y -l+1 $vg/$lv1
+lvresize -y -L+1 $vg/$lv1
+lvresize -y -l-1 $vg/$lv1
+lvresize -y -L-1 $vg/$lv1
+
+lvcreate -an -n $lv2 -l4 $vg
+lvextend -y -l8 $vg/$lv2
+lvextend -y -L16 $vg/$lv2
+lvextend -y -l+1 $vg/$lv2
+lvextend -y -L+1 $vg/$lv2
+not lvextend -y -l-1 $vg/$lv2
+not lvextend -y -L-1 $vg/$lv2
+
+lvcreate -an -n $lv3 -l64 $vg
+lvreduce -y -l32 $vg/$lv3
+lvreduce -y -L8 $vg/$lv3
+lvreduce -y -l-1 $vg/$lv3
+lvreduce -y -L-1 $vg/$lv3
+not lvreduce -y -l+1 $vg/$lv3
+not lvreduce -y -L+1 $vg/$lv3
+
+# relative with percent extents
+
+lvcreate -an -n $lv6 -l+100%FREE $vg
+lvremove $vg/$lv6
+
+lvcreate -an -n $lv6 -l1 $vg
+lvextend -y -l+100%FREE $vg/$lv6
+lvremove $vg/$lv6
+
+lvcreate -an -n $lv6 -l1 $vg
+lvresize -y -l+100%FREE $vg/$lv6
+lvremove $vg/$lv6
+
+# relative poolmetadatasize
+
+lvcreate --type thin-pool -L64 --poolmetadatasize 32 -n $lv7 $vg
+lvresize --poolmetadatasize 64 $vg/$lv7
+lvresize --poolmetadatasize +8 $vg/$lv7
+not lvresize -y --poolmetadatasize -8 $vg/$lv7
+
+lvextend --poolmetadatasize +8 $vg/$lv7
+
+vgremove -y $vg
6 years, 3 months
master - commands: clean up and unify signed option value handling
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=a6a2788e7cb3a7bce73...
Commit: a6a2788e7cb3a7bce73b03644351f15f26a6ad36
Parent: 7f25fbe1547f06f4de880fbf6d28b83cebc7e16d
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue Mar 7 16:55:07 2017 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Wed Mar 8 12:54:43 2017 -0600
commands: clean up and unify signed option value handling
Add new values for different sign variations, resulting in:
size_VAL no sign accepted
ssize_VAL accepts + or -
psize_VAL accepts +
nsize_VAL accpets -
extents_VAL no sign accepted
sextents_VAL accepts + or -
pextents_VAL accepts +
nextents_VAL accepts -
Depending on the command being run, change the option
values for --size, --extents, --poolmetadatasize to
use the appropriate value from above.
lvcreate uses no sign (but accepts + and ignores it).
lvresize accepts +|- for a relative change.
lvextend accepts + for a relative change.
lvreduce accepts - for a relative change.
---
tools/args.h | 31 ++++----
tools/command-lines.in | 70 ++++++++--------
tools/command.c | 204 +++++++++++++++++++++++++++++++++---------------
tools/command.h | 2 +
tools/lvmcmdline.c | 86 +++++++++++++++++++-
tools/tools.h | 5 +
tools/vals.h | 13 ++--
7 files changed, 287 insertions(+), 124 deletions(-)
diff --git a/tools/args.h b/tools/args.h
index 7bb177d..821c56d 100644
--- a/tools/args.h
+++ b/tools/args.h
@@ -414,7 +414,7 @@ arg(pooldatasize_ARG, '\0', "pooldatasize", sizemb_VAL, 0, 0, NULL)
arg(poolmetadata_ARG, '\0', "poolmetadata", lv_VAL, 0, 0,
"The name of a an LV to use for storing pool metadata.\n")
-arg(poolmetadatasize_ARG, '\0', "poolmetadatasize", ssizemb_VAL, 0, 0,
+arg(poolmetadatasize_ARG, '\0', "poolmetadatasize", sizemb_VAL, 0, 0,
"#lvcreate\n"
"#lvconvert\n"
"Specifies the size of the new pool metadata LV.\n"
@@ -994,6 +994,11 @@ arg(logicalvolume_ARG, 'l', "logicalvolume", uint32_VAL, 0, 0,
arg(maxlogicalvolumes_ARG, 'l', "maxlogicalvolumes", uint32_VAL, 0, 0,
"Sets the maximum number of LVs allowed in a VG.\n")
+/*
+ * The extents_VAL is overriden in configure_command_option_values()
+ * according to the command being run. Different commands accept
+ * different signs with the value.
+ */
arg(extents_ARG, 'l', "extents", extents_VAL, 0, 0,
"#lvcreate\n"
"Specifies the size of the new LV in logical extents.\n"
@@ -1029,9 +1034,9 @@ arg(extents_ARG, 'l', "extents", extents_VAL, 0, 0,
"When expressed as a percentage, the size defines an upper limit for the\n"
"number of logical extents in the new LV. The precise number of logical\n"
"extents in the new LV is not determined until the command has completed.\n"
- "The plus \\fB+\\fP or minus \\fB-\\fP prefix can be used, in which case\n"
- "the value is not an absolute size, but is an amount added or subtracted\n"
- "relative to the current size.\n")
+ "When the plus \\fB+\\fP or minus \\fB-\\fP prefix is used,\n"
+ "the value is not an absolute size, but is relative and added or subtracted\n"
+ "from the current size.\n")
arg(list_ARG, 'l', "list", 0, 0, 0,
"#lvmconfig\n"
@@ -1049,14 +1054,11 @@ arg(lvmpartition_ARG, 'l', "lvmpartition", 0, 0, 0,
"Only report PVs.\n")
/*
- * FIXME: for lvcreate, size only accepts absolute values, no +|-,
- * for lvresize, size can relative +|-, for lvreduce, size
- * can be relative -, and for lvextend, size can be relative +.
- * Should we define separate val enums for each of those cases,
- * and at the start of the command, change the val type for
- * size_ARG? The same for extents_ARG.
+ * The sizemb_VAL is overriden in configure_command_option_values()
+ * according to the command being run. Different commands accept
+ * different signs with the value.
*/
-arg(size_ARG, 'L', "size", ssizemb_VAL, 0, 0,
+arg(size_ARG, 'L', "size", sizemb_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"
@@ -1069,10 +1071,9 @@ arg(size_ARG, 'L', "size", ssizemb_VAL, 0, 0,
"The --size and --extents options are alternate methods of specifying size.\n"
"The total number of physical extents used will be\n"
"greater when redundant data is needed for RAID levels.\n"
- "The plus prefix \\fB+\\fP can be used, in which case\n"
- "the value is added to the current size,\n"
- "or the minus prefix \\fB-\\fP can be used, in which case\n"
- "the value is subtracted from the current size.\n")
+ "When the plus \\fB+\\fP or minus \\fB-\\fP prefix is used,\n"
+ "the value is not an absolute size, but is relative and added or subtracted\n"
+ "from the current size.\n")
arg(persistent_ARG, 'M', "persistent", bool_VAL, 0, 0,
"When yes, makes the specified minor number persistent.\n")
diff --git a/tools/command-lines.in b/tools/command-lines.in
index b1405b6..4f2ab44 100644
--- a/tools/command-lines.in
+++ b/tools/command-lines.in
@@ -307,7 +307,7 @@ RULE: all not LV_thinpool LV_cachepool
OO_LVCONVERT_RAID: --mirrors SNumber, --stripes_long Number,
--stripesize SizeKB, --regionsize RegionSize, --interval Number
-OO_LVCONVERT_POOL: --poolmetadata LV, --poolmetadatasize SSizeMB,
+OO_LVCONVERT_POOL: --poolmetadata LV, --poolmetadatasize SizeMB,
--poolmetadataspare Bool, --readahead Readahead, --chunksize SizeKB
OO_LVCONVERT_CACHE: --cachemode CacheMode, --cachepolicy String,
@@ -702,7 +702,7 @@ OO_LVCREATE: --addtag Tag, --alloc Alloc, --autobackup Bool, --activate Active,
OO_LVCREATE_CACHE: --cachemode CacheMode, --cachepolicy String, --cachesettings String,
--chunksize SizeKB
-OO_LVCREATE_POOL: --poolmetadatasize SSizeMB, --poolmetadataspare Bool, --chunksize SizeKB
+OO_LVCREATE_POOL: --poolmetadatasize SizeMB, --poolmetadataspare Bool, --chunksize SizeKB
OO_LVCREATE_THIN: --discards Discards, --errorwhenfull Bool
@@ -711,7 +711,7 @@ OO_LVCREATE_RAID: --mirrors SNumber, --stripes Number, --stripesize SizeKB,
---
-lvcreate --type error --size SSizeMB VG
+lvcreate --type error --size SizeMB VG
OO: OO_LVCREATE
ID: lvcreate_error_vol
DESC: Create an LV that returns errors when used.
@@ -719,7 +719,7 @@ FLAGS: SECONDARY_SYNTAX
---
-lvcreate --type zero --size SSizeMB VG
+lvcreate --type zero --size SizeMB VG
OO: OO_LVCREATE
ID: lvcreate_zero_vol
DESC: Create an LV that returns zeros when read.
@@ -727,7 +727,7 @@ FLAGS: SECONDARY_SYNTAX
---
-lvcreate --type linear --size SSizeMB VG
+lvcreate --type linear --size SizeMB VG
OO: OO_LVCREATE
OP: PV ...
IO: --mirrors 0, --stripes 1
@@ -735,7 +735,7 @@ ID: lvcreate_linear
DESC: Create a linear LV.
FLAGS: SECONDARY_SYNTAX
-lvcreate --size SSizeMB VG
+lvcreate --size SizeMB VG
OO: --type linear, OO_LVCREATE
OP: PV ...
IO: --mirrors 0, --stripes 1
@@ -744,14 +744,14 @@ DESC: Create a linear LV.
---
-lvcreate --type striped --size SSizeMB VG
+lvcreate --type striped --size SizeMB 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 SSizeMB VG
+lvcreate --stripes Number --size SizeMB VG
OO: --type striped, --stripesize SizeKB, OO_LVCREATE
OP: PV ...
ID: lvcreate_striped
@@ -759,7 +759,7 @@ DESC: Create a striped LV (infers --type striped).
---
-lvcreate --type mirror --size SSizeMB VG
+lvcreate --type mirror --size SizeMB VG
OO: --mirrors SNumber, --mirrorlog MirrorLog, --regionsize RegionSize, --stripes Number, OO_LVCREATE
OP: PV ...
ID: lvcreate_mirror
@@ -767,7 +767,7 @@ DESC: Create a mirror LV (also see --type raid1).
FLAGS: SECONDARY_SYNTAX
# alternate form of lvcreate --type raid1|mirror
-lvcreate --mirrors SNumber --size SSizeMB VG
+lvcreate --mirrors SNumber --size SizeMB VG
OO: --type raid1, --type mirror, --mirrorlog MirrorLog, --stripes Number, OO_LVCREATE_RAID, OO_LVCREATE
OP: PV ...
ID: lvcreate_mirror_or_raid1
@@ -775,7 +775,7 @@ DESC: Create a raid1 or mirror LV (infers --type raid1|mirror).
---
-lvcreate --type raid --size SSizeMB VG
+lvcreate --type raid --size SizeMB VG
OO: OO_LVCREATE_RAID, OO_LVCREATE
OP: PV ...
ID: lvcreate_raid_any
@@ -789,7 +789,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 SSizeMB LV
+lvcreate --type snapshot --size SizeMB LV
OO: --snapshot, --stripes Number, --stripesize SizeKB,
--chunksize SizeKB, OO_LVCREATE
OP: PV ...
@@ -798,7 +798,7 @@ DESC: Create a COW snapshot LV of an origin LV
DESC: (also see --snapshot).
FLAGS: SECONDARY_SYNTAX
-lvcreate --snapshot --size SSizeMB LV
+lvcreate --snapshot --size SizeMB LV
OO: --type snapshot, --stripes Number, --stripesize SizeKB,
--chunksize SizeKB, OO_LVCREATE
OP: PV ...
@@ -808,7 +808,7 @@ DESC: Create a COW snapshot LV of an origin LV.
---
# alternate form of lvcreate --snapshot
-lvcreate --type snapshot --size SSizeMB --virtualsize SizeMB VG
+lvcreate --type snapshot --size SizeMB --virtualsize SizeMB VG
OO: --snapshot, --chunksize SizeKB, OO_LVCREATE
OP: PV ...
ID: lvcreate_cow_snapshot_with_virtual_origin
@@ -816,7 +816,7 @@ DESC: Create a sparse COW snapshot LV of a virtual origin LV
DESC: (also see --snapshot).
FLAGS: SECONDARY_SYNTAX
-lvcreate --snapshot --size SSizeMB --virtualsize SizeMB VG
+lvcreate --snapshot --size SizeMB --virtualsize SizeMB VG
OO: --type snapshot, --chunksize SizeKB, OO_LVCREATE
OP: PV ...
ID: lvcreate_cow_snapshot_with_virtual_origin
@@ -825,7 +825,7 @@ FLAGS: SECONDARY_SYNTAX
---
-lvcreate --type thin-pool --size SSizeMB VG
+lvcreate --type thin-pool --size SizeMB VG
OO: --thinpool LV_new, OO_LVCREATE_POOL, OO_LVCREATE_THIN, OO_LVCREATE,
--stripes Number, --stripesize SizeKB
OP: PV ...
@@ -834,7 +834,7 @@ ID: lvcreate_thinpool
DESC: Create a thin pool.
# alternate form of lvcreate --type thin-pool
-lvcreate --thin --size SSizeMB VG
+lvcreate --thin --size SizeMB VG
OO: --type thin-pool, OO_LVCREATE_POOL, OO_LVCREATE_THIN, OO_LVCREATE,
--stripes Number, --stripesize SizeKB
OP: PV ...
@@ -844,7 +844,7 @@ DESC: Create a thin pool (infers --type thin-pool).
FLAGS: SECONDARY_SYNTAX
# alternate form of lvcreate --type thin-pool
-lvcreate --size SSizeMB --thinpool LV_new VG
+lvcreate --size SizeMB --thinpool LV_new VG
OO: --thin, --type thin-pool, OO_LVCREATE_POOL, OO_LVCREATE_THIN, OO_LVCREATE,
--stripes Number, --stripesize SizeKB
OP: PV ...
@@ -861,14 +861,14 @@ FLAGS: SECONDARY_SYNTAX
# still needs to be listed as an optional addition to
# --type cache-pool.
-lvcreate --type cache-pool --size SSizeMB VG
+lvcreate --type cache-pool --size SizeMB 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 SSizeMB --cachepool LV_new VG
+lvcreate --type cache-pool --size SizeMB --cachepool LV_new VG
OO: --cache, OO_LVCREATE_POOL, OO_LVCREATE_CACHE, OO_LVCREATE
OP: PV ...
ID: lvcreate_cachepool
@@ -973,7 +973,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 SSizeMB --thinpool LV_new
+lvcreate --type thin --virtualsize SizeMB --size SizeMB --thinpool LV_new
OO: --thin, OO_LVCREATE_POOL, OO_LVCREATE_THIN, OO_LVCREATE,
--stripes Number, --stripesize SizeKB
OP: PV ...
@@ -983,7 +983,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 SSizeMB --thinpool LV_new
+lvcreate --thin --virtualsize SizeMB --size SizeMB --thinpool LV_new
OO: --type thin, OO_LVCREATE_POOL, OO_LVCREATE_THIN, OO_LVCREATE,
--stripes Number, --stripesize SizeKB
OP: PV ...
@@ -995,7 +995,7 @@ DESC: (variant, infers --type thin).
FLAGS: SECONDARY_SYNTAX
# alternate form of lvcreate --type thin
-lvcreate --type thin --virtualsize SizeMB --size SSizeMB LV_new|VG
+lvcreate --type thin --virtualsize SizeMB --size SizeMB LV_new|VG
OO: --thin, OO_LVCREATE_POOL, OO_LVCREATE_THIN, OO_LVCREATE,
--stripes Number, --stripesize SizeKB
OP: PV ...
@@ -1008,7 +1008,7 @@ DESC: arg is a VG name.
FLAGS: SECONDARY_SYNTAX
# alternate form of lvcreate --type thin
-lvcreate --thin --virtualsize SizeMB --size SSizeMB LV_new|VG
+lvcreate --thin --virtualsize SizeMB --size SizeMB LV_new|VG
OO: --type thin, OO_LVCREATE_POOL, OO_LVCREATE_THIN, OO_LVCREATE,
--stripes Number, --stripesize SizeKB
OP: PV ...
@@ -1022,7 +1022,7 @@ FLAGS: SECONDARY_SYNTAX
---
-lvcreate --size SSizeMB --virtualsize SizeMB VG
+lvcreate --size SizeMB --virtualsize SizeMB VG
OO: --type thin, --type snapshot, --thin, --snapshot, OO_LVCREATE_POOL, OO_LVCREATE_THIN, OO_LVCREATE,
--stripes Number, --stripesize SizeKB
OP: PV ...
@@ -1042,7 +1042,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 SSizeMB --cachepool LV_cachepool VG
+lvcreate --type cache --size SizeMB --cachepool LV_cachepool VG
OO: --cache, OO_LVCREATE_POOL, OO_LVCREATE_CACHE, OO_LVCREATE,
--stripes Number, --stripesize SizeKB
OP: PV ...
@@ -1052,7 +1052,7 @@ DESC: then combining it with the existing cache pool named
DESC: by the --cachepool arg.
# alternate form of lvcreate --type cache
-lvcreate --size SSizeMB --cachepool LV_cachepool VG
+lvcreate --size SizeMB --cachepool LV_cachepool VG
OO: --type cache, --cache, OO_LVCREATE_CACHE, OO_LVCREATE,
--stripes Number, --stripesize SizeKB
OP: PV ...
@@ -1063,7 +1063,7 @@ DESC: by the --cachepool arg (variant, infers --type cache).
FLAGS: SECONDARY_SYNTAX
# alternate form of lvcreate --type cache
-lvcreate --type cache --size SSizeMB LV_cachepool
+lvcreate --type cache --size SizeMB LV_cachepool
OO: --cache, OO_LVCREATE_POOL, OO_LVCREATE_CACHE, OO_LVCREATE,
--stripes Number, --stripesize SizeKB
OP: PV ...
@@ -1082,7 +1082,7 @@ FLAGS: SECONDARY_SYNTAX
# an already complicated command above.
#
# # alternate form for lvcreate_cache_vol_with_new_origin
-# lvcreate --cache --size SSizeMB LV_cachepool
+# lvcreate --cache --size SizeMB LV_cachepool
# OO: --type cache, --cache, OO_LVCREATE_CACHE, OO_LVCREATE, --stripes Number, --stripesize SizeKB
# OP: PV ...
# ID: lvcreate_cache_vol_with_new_origin
@@ -1094,7 +1094,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 SSizeMB LV
+# lvcreate --type cache --size SizeMB LV
# OO: OO_LVCREATE_POOL, OO_LVCREATE_CACHE, OO_LVCREATE
# OP: PV ...
# ID: lvcreate_convert_to_cache_vol_with_cachepool
@@ -1111,7 +1111,7 @@ FLAGS: SECONDARY_SYNTAX
# def1: alternate form of lvcreate --type cache, or
# def2: it should be done by lvconvert.
-lvcreate --cache --size SSizeMB LV
+lvcreate --cache --size SizeMB LV
OO: OO_LVCREATE_CACHE, OO_LVCREATE_POOL, OO_LVCREATE,
--stripes Number, --stripesize SizeKB
OP: PV ...
@@ -1145,10 +1145,10 @@ ID: lvdisplay_general
# --extents is not specified; it's an automatic alternative for --size
-lvextend --size SSizeMB LV
+lvextend --size PSizeMB LV
OO: --alloc Alloc, --autobackup Bool, --force, --mirrors SNumber,
--nofsck, --nosync, --noudevsync, --reportformat ReportFmt, --resizefs,
---stripes Number, --stripesize SizeKB, --poolmetadatasize SSizeMB,
+--stripes Number, --stripesize SizeKB, --poolmetadatasize PSizeMB,
--type SegType
OP: PV ...
ID: lvextend_by_size
@@ -1162,7 +1162,7 @@ OO: --alloc Alloc, --autobackup Bool, --force, --mirrors SNumber,
ID: lvextend_by_pv
DESC: Extend an LV by specified PV extents.
-lvextend --poolmetadatasize SSizeMB LV_thinpool
+lvextend --poolmetadatasize PSizeMB LV_thinpool
OO: --alloc Alloc, --autobackup Bool, --force, --mirrors SNumber,
--nofsck, --nosync, --noudevsync,
--reportformat ReportFmt, --stripes Number, --stripesize SizeKB,
@@ -1189,7 +1189,7 @@ ID: lvmconfig_general
---
-lvreduce --size SSizeMB LV
+lvreduce --size NSizeMB LV
OO: --autobackup Bool, --force, --nofsck, --noudevsync,
--reportformat ReportFmt, --resizefs
ID: lvreduce_general
diff --git a/tools/command.c b/tools/command.c
index bfd3d7d..0d56e51 100644
--- a/tools/command.c
+++ b/tools/command.c
@@ -77,10 +77,15 @@ static inline int size_kb_arg(struct cmd_context *cmd, struct arg_values *av) {
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 ssize_mb_arg(struct cmd_context *cmd, struct arg_values *av) { return 0; }
+static inline int psize_mb_arg(struct cmd_context *cmd, struct arg_values *av) { return 0; }
+static inline int nsize_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; }
static inline int extents_arg(struct cmd_context *cmd, struct arg_values *av) { return 0; }
+static inline int sextents_arg(struct cmd_context *cmd, struct arg_values *av) { return 0; }
+static inline int pextents_arg(struct cmd_context *cmd, struct arg_values *av) { return 0; }
+static inline int nextents_arg(struct cmd_context *cmd, struct arg_values *av) { return 0; }
static inline int major_arg(struct cmd_context *cmd, struct arg_values *av) { return 0; }
static inline int minor_arg(struct cmd_context *cmd, struct arg_values *av) { return 0; }
static inline int string_arg(struct cmd_context *cmd, struct arg_values *av) { return 0; }
@@ -1513,6 +1518,61 @@ int define_commands(char *run_name)
return 1;
}
+/*
+ * This does not change the option vals in the cmd defs in commands[]
+ * which are used when printing help/man output.
+ *
+ * The specific val types for each command are specified in
+ * command-lines.in/commands[], and those are used for printing
+ * man/help. But the opt_names[] array for each option is global
+ * and has no command name context. So the opt_names[] array always
+ * specifies a non-signed val, e.g. sizemb_VAL, extents_VAL. The
+ * opt_names[] array is used by run time processing, and for part
+ * of the help/man output. This adjusts the opt_names[] val types
+ * according to the command being run.
+ */
+void configure_command_option_values(const char *name)
+{
+ if (!strcmp(name, "lvresize")) {
+ /* relative +|- allowed */
+ opt_names[size_ARG].val_enum = ssizemb_VAL;
+ opt_names[extents_ARG].val_enum = sextents_VAL;
+ opt_names[poolmetadatasize_ARG].val_enum = ssizemb_VAL;
+ return;
+ }
+
+ if (!strcmp(name, "lvextend")) {
+ /* relative + allowed */
+ opt_names[size_ARG].val_enum = psizemb_VAL;
+ opt_names[extents_ARG].val_enum = pextents_VAL;
+ opt_names[poolmetadatasize_ARG].val_enum = psizemb_VAL;
+ return;
+ }
+
+ if (!strcmp(name, "lvreduce")) {
+ /* relative - allowed */
+ opt_names[size_ARG].val_enum = nsizemb_VAL;
+ opt_names[extents_ARG].val_enum = nextents_VAL;
+ return;
+ }
+
+ if (!strcmp(name, "lvcreate")) {
+ /*
+ * lvcreate is a bit of a mess because it has previously
+ * accepted + but used it as an absolute value, so we
+ * have to recognize it. (We don't want to show the +
+ * option in man/help, though, since it's confusing,
+ * so there's a special case when printing man/help
+ * output to show sizemb_VAL/extents_VAL rather than
+ * psizemb_VAL/pextents_VAL.)
+ */
+ opt_names[size_ARG].val_enum = psizemb_VAL;
+ opt_names[extents_ARG].val_enum = pextents_VAL;
+ opt_names[poolmetadatasize_ARG].val_enum = psizemb_VAL;
+ return;
+ }
+}
+
/* type_LVT to "type" */
static const char *lvt_enum_to_name(int lvt_enum)
@@ -1555,29 +1615,21 @@ static void _print_usage_description(struct command *cmd)
}
}
-static void print_val_usage(struct command *cmd, int val_enum)
+static void print_val_usage(struct command *cmd, int opt_enum, int val_enum)
{
- int squash_sign_prefix;
+ int is_relative_opt = (opt_enum == size_ARG) ||
+ (opt_enum == extents_ARG) ||
+ (opt_enum == poolmetadatasize_ARG);
/*
- * lvcreate does not take a relative [+|-] value
- * for --size or --extents.
- * Should we also squash - for lvextend and + for lvreduce?
- *
- * Should also squash +|- in front of poolmetadatasize value
- * in lvcreate and lvconvert, and squash - in front of
- * poolmetadatasize value in lvresize/lvextend.
+ * Suppress the [+] prefix for lvcreate which we have to
+ * accept for backwards compat, but don't want to advertise.
*/
- squash_sign_prefix = !strcmp(cmd->name, "lvcreate");
-
- if ((val_enum == ssizemb_VAL) && squash_sign_prefix) {
- printf("Size[m|UNIT]");
- return;
- }
-
- if ((val_enum == extents_VAL) && squash_sign_prefix) {
- printf("Number[PERCENT]");
- return;
+ if (!strcmp(cmd->name, "lvcreate") && is_relative_opt) {
+ if (val_enum == psizemb_VAL)
+ val_enum = sizemb_VAL;
+ else if (val_enum == pextents_VAL)
+ val_enum = extents_VAL;
}
if (!val_names[val_enum].usage)
@@ -1603,7 +1655,7 @@ static void print_usage_def(struct command *cmd, int opt_enum, struct arg_def *d
else {
if (sep) printf("|");
- print_val_usage(cmd, val_enum);
+ print_val_usage(cmd, opt_enum, val_enum);
sep = 1;
}
@@ -1724,7 +1776,7 @@ void print_usage(struct command *cmd, int longhelp, int desc_first)
if (cmd->oo_count) {
if (include_extents) {
printf("\n\t[ -l|--extents ");
- print_val_usage(cmd, extents_VAL);
+ print_val_usage(cmd, extents_ARG, opt_names[extents_ARG].val_enum);
printf(" ]");
}
@@ -2028,59 +2080,75 @@ void print_usage_notes(struct command_name *cname)
* Otherwise, this function has to be updated in
* sync with any string changes in vals.h
*/
-static void print_val_man(struct command_name *cname, int val_enum)
+static void print_val_man(struct command_name *cname, int opt_enum, int val_enum)
{
const char *str = val_names[val_enum].usage;
char *line;
char *line_argv[MAX_LINE_ARGC];
int line_argc;
int i;
- int squash_sign_prefix;
+ int is_relative_opt = (opt_enum == size_ARG) ||
+ (opt_enum == extents_ARG) ||
+ (opt_enum == poolmetadatasize_ARG);
/*
- * lvcreate does not take a relative [+|-] value
- * for --size or --extents.
- * Should we also squash - for lvextend and + for lvreduce?
- *
- * Should also squash +|- in front of poolmetadatasize value
- * in lvcreate and lvconvert, and squash - in front of
- * poolmetadatasize value in lvresize/lvextend.
+ * Suppress the [+] prefix for lvcreate which we have to
+ * accept for backwards compat, but don't want to advertise.
*/
- squash_sign_prefix = !strcmp(cname->name, "lvcreate");
+ if (!strcmp(cname->name, "lvcreate") && is_relative_opt) {
+ if (val_enum == psizemb_VAL)
+ val_enum = sizemb_VAL;
+ else if (val_enum == pextents_VAL)
+ val_enum = extents_VAL;
+ }
+
+ if (val_enum == sizemb_VAL) {
+ printf("\\fISize\\fP[m|UNIT]");
+ return;
+ }
if (val_enum == ssizemb_VAL) {
- if (squash_sign_prefix)
- printf("\\fISize\\fP[m|UNIT]");
- else
- printf("[\\fB+\\fP|\\fB-\\fP]\\fISize\\fP[m|UNIT]");
+ printf("[\\fB+\\fP|\\fB-\\fP]\\fISize\\fP[m|UNIT]");
+ return;
+ }
+
+ if (val_enum == psizemb_VAL) {
+ printf("[\\fB+\\fP]\\fISize\\fP[m|UNIT]");
+ return;
+ }
+
+ if (val_enum == nsizemb_VAL) {
+ printf("[\\fB-\\fP]\\fISize\\fP[m|UNIT]");
return;
}
if (val_enum == extents_VAL) {
- if (squash_sign_prefix)
- printf("\\fINumber\\fP[PERCENT]");
- else
- printf("[\\fB+\\fP|\\fB-\\fP]\\fINumber\\fP[PERCENT]");
+ printf("\\fINumber\\fP[PERCENT]");
return;
}
- if (val_enum == sizekb_VAL) {
- printf("\\fISize\\fP[k|UNIT]");
+ if (val_enum == sextents_VAL) {
+ printf("[\\fB+\\fP|\\fB-\\fP]\\fINumber\\fP[PERCENT]");
return;
}
- if (val_enum == sizemb_VAL) {
- printf("\\fISize\\fP[m|UNIT]");
+ if (val_enum == pextents_VAL) {
+ printf("[\\fB+\\fP]\\fINumber\\fP[PERCENT]");
return;
}
- if (val_enum == ssizekb_VAL) {
- printf("[\\fB+\\fP|\\fB-\\fP]\\fISize\\fP[k|UNIT]");
+ if (val_enum == nextents_VAL) {
+ printf("[\\fB-\\fP]\\fINumber\\fP[PERCENT]");
return;
}
- if (val_enum == ssizemb_VAL) {
- printf("[\\fB+\\fP|\\fB-\\fP]\\fISize\\fP[m|UNIT]");
+ if (val_enum == sizekb_VAL) {
+ printf("\\fISize\\fP[k|UNIT]");
+ return;
+ }
+
+ if (val_enum == ssizekb_VAL) {
+ printf("[\\fB+\\fP|\\fB-\\fP]\\fISize\\fP[k|UNIT]");
return;
}
@@ -2127,7 +2195,7 @@ static void print_val_man(struct command_name *cname, int val_enum)
printf("\\fB%s\\fP", str);
}
-static void print_def_man(struct command_name *cname, struct arg_def *def, int usage)
+static void print_def_man(struct command_name *cname, int opt_enum, struct arg_def *def, int usage)
{
int val_enum;
int lvt_enum;
@@ -2156,7 +2224,7 @@ static void print_def_man(struct command_name *cname, struct arg_def *def, int u
printf("%s", val_names[val_enum].name);
printf("\\fP");
} else {
- print_val_man(cname, val_enum);
+ print_val_man(cname, opt_enum, val_enum);
}
sep = 1;
@@ -2290,7 +2358,7 @@ void print_man_usage(char *lvmname, struct command *cmd)
if (cmd->required_opt_args[ro].def.val_bits) {
printf(" ");
- print_def_man(cname, &cmd->required_opt_args[ro].def, 1);
+ print_def_man(cname, opt_enum, &cmd->required_opt_args[ro].def, 1);
}
sep++;
@@ -2317,7 +2385,7 @@ void print_man_usage(char *lvmname, struct command *cmd)
if (cmd->required_opt_args[ro].def.val_bits) {
printf(" ");
- print_def_man(cname, &cmd->required_opt_args[ro].def, 1);
+ print_def_man(cname, opt_enum, &cmd->required_opt_args[ro].def, 1);
}
sep++;
@@ -2333,7 +2401,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(cname, &cmd->required_pos_args[rp].def, 1);
+ print_def_man(cname, 0, &cmd->required_pos_args[rp].def, 1);
}
}
@@ -2379,7 +2447,7 @@ void print_man_usage(char *lvmname, struct command *cmd)
if (cmd->required_opt_args[ro].def.val_bits) {
printf(" ");
- print_def_man(cname, &cmd->required_opt_args[ro].def, 1);
+ print_def_man(cname, opt_enum, &cmd->required_opt_args[ro].def, 1);
}
sep++;
@@ -2391,7 +2459,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(cname, &cmd->required_pos_args[rp].def, 1);
+ print_def_man(cname, 0, &cmd->required_pos_args[rp].def, 1);
}
}
@@ -2415,9 +2483,14 @@ void print_man_usage(char *lvmname, struct command *cmd)
printf(".RS 4\n");
if (include_extents) {
+ /*
+ * NB we don't just pass extents_VAL here because the
+ * actual val type for extents_ARG has been adjusted
+ * in opt_names[] according to the command name.
+ */
printf(".ad l\n");
printf("[ \\fB-l\\fP|\\fB--extents\\fP ");
- print_val_man(cname, extents_VAL);
+ print_val_man(cname, extents_ARG, opt_names[extents_ARG].val_enum);
printf(" ]\n");
printf(".ad b\n");
sep = 1;
@@ -2447,7 +2520,7 @@ void print_man_usage(char *lvmname, struct command *cmd)
if (cmd->optional_opt_args[oo].def.val_bits) {
printf(" ");
- print_def_man(cname, &cmd->optional_opt_args[oo].def, 1);
+ print_def_man(cname, opt_enum, &cmd->optional_opt_args[oo].def, 1);
}
printf(" ]\n");
printf(".ad b\n");
@@ -2479,7 +2552,7 @@ void print_man_usage(char *lvmname, struct command *cmd)
if (cmd->optional_opt_args[oo].def.val_bits) {
printf(" ");
- print_def_man(cname, &cmd->optional_opt_args[oo].def, 1);
+ print_def_man(cname, opt_enum, &cmd->optional_opt_args[oo].def, 1);
}
printf(" ]\n");
printf(".ad b\n");
@@ -2507,7 +2580,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(cname, &cmd->optional_pos_args[op].def, 1);
+ print_def_man(cname, 0, &cmd->optional_pos_args[op].def, 1);
}
}
}
@@ -2575,7 +2648,7 @@ void print_man_usage_common_lvm(struct command *cmd)
if (cmd->optional_opt_args[oo].def.val_bits) {
printf(" ");
- print_def_man(cname, &cmd->optional_opt_args[oo].def, 1);
+ print_def_man(cname, opt_enum, &cmd->optional_opt_args[oo].def, 1);
}
printf(" ]\n");
printf(".ad b\n");
@@ -2610,7 +2683,7 @@ void print_man_usage_common_lvm(struct command *cmd)
if (cmd->optional_opt_args[oo].def.val_bits) {
printf(" ");
- print_def_man(cname, &cmd->optional_opt_args[oo].def, 1);
+ print_def_man(cname, opt_enum, &cmd->optional_opt_args[oo].def, 1);
}
printf(" ]\n");
printf(".ad b\n");
@@ -2672,7 +2745,7 @@ void print_man_usage_common_cmd(struct command *cmd)
if (cmd->optional_opt_args[oo].def.val_bits) {
printf(" ");
- print_def_man(cname, &cmd->optional_opt_args[oo].def, 1);
+ print_def_man(cname, opt_enum, &cmd->optional_opt_args[oo].def, 1);
}
printf(" ]\n");
printf(".ad b\n");
@@ -2714,7 +2787,7 @@ void print_man_usage_common_cmd(struct command *cmd)
if (cmd->optional_opt_args[oo].def.val_bits) {
printf(" ");
- print_def_man(cname, &cmd->optional_opt_args[oo].def, 1);
+ print_def_man(cname, opt_enum, &cmd->optional_opt_args[oo].def, 1);
}
printf(" ]\n");
printf(".ad b\n");
@@ -2849,7 +2922,7 @@ void print_man_all_options_list(struct command_name *cname)
printf("\\fP");
} else {
printf(" ");
- print_val_man(cname, val_enum);
+ print_val_man(cname, opt_enum, val_enum);
}
printf("\n.ad b\n");
@@ -2897,7 +2970,7 @@ void print_man_all_options_desc(struct command_name *cname)
printf("\\fP");
} else {
printf(" ");
- print_val_man(cname, val_enum);
+ print_val_man(cname, opt_enum, val_enum);
}
if (opt_names[opt_enum].flags & ARG_COUNTABLE)
@@ -3382,6 +3455,9 @@ int main(int argc, char *argv[])
define_commands(NULL);
+ if (cmdname)
+ configure_command_option_values(cmdname);
+
factor_common_options();
if (primary)
diff --git a/tools/command.h b/tools/command.h
index 891349a..668428f 100644
--- a/tools/command.h
+++ b/tools/command.h
@@ -17,6 +17,7 @@
#define _LVM_COMMAND_H
struct cmd_context;
+struct logical_volume;
/* old per-command-name function */
typedef int (*command_fn) (struct cmd_context *cmd, int argc, char **argv);
@@ -262,5 +263,6 @@ void print_usage_common_lvm(struct command_name *cname, struct command *cmd);
void print_usage_notes(struct command_name *cname);
void factor_common_options(void);
int command_has_alternate_extents(const char *name);
+void configure_command_option_values(const char *name);
#endif
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index f46e283..9bc7f60 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -633,8 +633,8 @@ int size_mb_arg(struct cmd_context *cmd, struct arg_values *av)
if (!_size_arg(cmd, av, 2048, 0))
return 0;
- if (av->sign == SIGN_MINUS) {
- log_error("Size may not be negative.");
+ if ((av->sign == SIGN_MINUS) || (av->sign == SIGN_PLUS)) {
+ log_error("Size may not be relative/signed.");
return 0;
}
@@ -646,6 +646,32 @@ int ssize_mb_arg(struct cmd_context *cmd, struct arg_values *av)
return _size_arg(cmd, av, 2048, 0);
}
+int psize_mb_arg(struct cmd_context *cmd, struct arg_values *av)
+{
+ 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 nsize_mb_arg(struct cmd_context *cmd, struct arg_values *av)
+{
+ if (!_size_arg(cmd, av, 2048, 0))
+ return 0;
+
+ if (av->sign == SIGN_PLUS) {
+ log_error("Size may not be positive.");
+ return 0;
+ }
+
+ return 1;
+}
+
int int_arg(struct cmd_context *cmd __attribute__((unused)), struct arg_values *av)
{
char *ptr;
@@ -674,8 +700,8 @@ int int_arg_with_sign(struct cmd_context *cmd __attribute__((unused)), struct ar
return 1;
}
-int extents_arg(struct cmd_context *cmd __attribute__((unused)),
- struct arg_values *av)
+static int _extents_arg(struct cmd_context *cmd __attribute__((unused)),
+ struct arg_values *av)
{
char *ptr;
@@ -699,6 +725,54 @@ int extents_arg(struct cmd_context *cmd __attribute__((unused)),
return 1;
}
+int extents_arg(struct cmd_context *cmd __attribute__((unused)),
+ struct arg_values *av)
+{
+ if (!_extents_arg(cmd, av))
+ return 0;
+
+ if ((av->sign == SIGN_MINUS) || (av->sign == SIGN_PLUS)) {
+ log_error("Extents may not be relative/signed.");
+ return 0;
+ }
+
+ return 1;
+}
+
+int sextents_arg(struct cmd_context *cmd __attribute__((unused)),
+ struct arg_values *av)
+{
+ return _extents_arg(cmd, av);
+}
+
+int pextents_arg(struct cmd_context *cmd __attribute__((unused)),
+ struct arg_values *av)
+{
+ if (!_extents_arg(cmd, av))
+ return 0;
+
+ if (av->sign == SIGN_MINUS) {
+ log_error("Extents may not be negative.");
+ return 0;
+ }
+
+ return 1;
+}
+
+int nextents_arg(struct cmd_context *cmd __attribute__((unused)),
+ struct arg_values *av)
+{
+ if (!_extents_arg(cmd, av))
+ return 0;
+
+ if (av->sign == SIGN_PLUS) {
+ log_error("Extents may not be positive.");
+ return 0;
+ }
+
+ return 1;
+}
+
int string_arg(struct cmd_context *cmd __attribute__((unused)),
struct arg_values *av __attribute__((unused)))
{
@@ -1686,6 +1760,8 @@ static int _usage(const char *name, int longhelp, int skip_notes)
return 0;
}
+ configure_command_option_values(name);
+
/*
* Looks at all variants of each command name and figures out
* which options are common to all variants (for compact output)
@@ -2516,6 +2592,8 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
cmd->name = dm_pool_strdup(cmd->mem, argv[0]);
+ configure_command_option_values(cmd->name);
+
/* eliminate '-' from all options starting with -- */
for (i = 1; i < argc; i++) {
diff --git a/tools/tools.h b/tools/tools.h
index fe3699e..630349a 100644
--- a/tools/tools.h
+++ b/tools/tools.h
@@ -151,10 +151,15 @@ 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 ssize_mb_arg(struct cmd_context *cmd, struct arg_values *av);
+int psize_mb_arg(struct cmd_context *cmd, struct arg_values *av);
+int nsize_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);
int extents_arg(struct cmd_context *cmd, struct arg_values *av);
+int sextents_arg(struct cmd_context *cmd, struct arg_values *av);
+int pextents_arg(struct cmd_context *cmd, struct arg_values *av);
+int nextents_arg(struct cmd_context *cmd, struct arg_values *av);
int major_arg(struct cmd_context *cmd, struct arg_values *av);
int minor_arg(struct cmd_context *cmd, struct arg_values *av);
int string_arg(struct cmd_context *cmd, struct arg_values *av);
diff --git a/tools/vals.h b/tools/vals.h
index 4c70640..ef97ecb 100644
--- a/tools/vals.h
+++ b/tools/vals.h
@@ -92,10 +92,6 @@
* --size and other option args treat upper/lower letters
* the same, all as 1024 SI base. For this reason, we
* should avoid suggesting the upper case letters.
- *
- * FIXME: negative numbers should be automatically rejected
- * for anything but int_arg_with_sign(), e.g.
- * size_mb_arg() should reject a negative number.
*/
val(none_VAL, NULL, "None", "ERR") /* unused, for enum value 0 */
@@ -116,12 +112,17 @@ val(cachemode_VAL, cachemode_arg, "CacheMode", "writethrough|writeback|passthrou
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(sizemb_VAL, size_mb_arg, "SizeMB", "Size[m|UNIT]")
val(ssizemb_VAL, ssize_mb_arg, "SSizeMB", "[+|-]Size[m|UNIT]")
+val(psizemb_VAL, psize_mb_arg, "PSizeMB", "[+]Size[m|UNIT]")
+val(nsizemb_VAL, nsize_mb_arg, "NSizeMB", "[-]Size[m|UNIT]")
val(regionsize_VAL, regionsize_arg, "RegionSize", "Size[m|UNIT]")
val(snumber_VAL, int_arg_with_sign, "SNumber", "[+|-]Number")
-val(extents_VAL, extents_arg, "Extents", "[+|-]Number[PERCENT]")
+val(extents_VAL, extents_arg, "Extents", "Number[PERCENT]")
+val(sextents_VAL, sextents_arg, "SExtents", "[+|-]Number[PERCENT]")
+val(pextents_VAL, pextents_arg, "PExtents", "[+]Number[PERCENT]")
+val(nextents_VAL, nextents_arg, "NExtents", "[-]Number[PERCENT]")
val(permission_VAL, permission_arg, "Permission", "rw|r")
val(metadatatype_VAL, metadatatype_arg, "MetadataType", "lvm2|lvm1")
val(units_VAL, string_arg, "Units", "r|R|h|H|b|B|s|S|k|K|m|M|g|G|t|T|p|P|e|E")
6 years, 3 months
master - report: fix segfault
by Heinz Mauelshagen
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=7f25fbe1547f06f4de8...
Commit: 7f25fbe1547f06f4de880fbf6d28b83cebc7e16d
Parent: 11f1556d5dbfb843f894b64d1e0cd2ff6197851a
Author: Heinz Mauelshagen <heinzm(a)redhat.com>
AuthorDate: Wed Mar 8 18:31:20 2017 +0100
Committer: Heinz Mauelshagen <heinzm(a)redhat.com>
CommitterDate: Wed Mar 8 18:32:01 2017 +0100
report: fix segfault
Commit f4b30b0daef3 which was about displaying visible
LV size when reshape space is allocated did not account
for undefined first lv segment.
---
lib/report/report.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/report/report.c b/lib/report/report.c
index 4204d47..b5791c6 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -2304,7 +2304,7 @@ static int _lv_size_disp(struct dm_report *rh, struct dm_pool *mem,
const struct lv_segment *seg = first_seg(lv);
uint64_t size = lv->le_count;
- if (!lv_is_raid_image(lv))
+ if (seg && !lv_is_raid_image(lv))
size -= seg->reshape_len * (seg->area_count > 2 ? seg->area_count : 1);
size *= lv->vg->extent_size;
6 years, 3 months
master - commands: combine duplicate arrays for lv types and props
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=11f1556d5dbfb843f89...
Commit: 11f1556d5dbfb843f894b64d1e0cd2ff6197851a
Parent: 690f60473352e9909df95fae96a5d99b8b0c9db7
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue Mar 7 12:08:23 2017 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Wed Mar 8 11:03:02 2017 -0600
commands: combine duplicate arrays for lv types and props
Like opt and val arrays in previous commit, combine duplicate
arrays for lv types and props in command.c and lvmcmdline.c.
Also move the command_names array to be defined in command.c
so it's consistent with the others.
---
tools/command.c | 48 ++++++++++++++++++++----------------------------
tools/command.h | 19 +++++++++++++++++++
tools/lvconvert.c | 8 ++++----
tools/lvmcmdline.c | 26 +++++++-------------------
tools/toollib.c | 12 ++++++------
tools/tools.h | 19 ++-----------------
6 files changed, 58 insertions(+), 74 deletions(-)
diff --git a/tools/command.c b/tools/command.c
index 71056bf..bfd3d7d 100644
--- a/tools/command.c
+++ b/tools/command.c
@@ -167,22 +167,6 @@ enum {
#include "command.h" /* defines struct command */
#include "command-count.h" /* defines COMMAND_COUNT */
-/* see lvp_names[] below, also see lv_props[] in tools.h and lv_props.h */
-
-struct lvp_name {
- const char *enum_name; /* "is_foo_LVP" */
- int lvp_enum; /* is_foo_LVP */
- const char *name; /* "lv_is_foo" */
-};
-
-/* see lvt_names[] below, also see lv_types[] in tools.h and lv_types.h */
-
-struct lvt_name {
- const char *enum_name; /* "foo_LVT" */
- int lvt_enum; /* foo_LVT */
- const char *name; /* "foo" */
-};
-
/* see cmd_names[] below, one for each unique "ID" in command-lines.in */
struct cmd_name {
@@ -209,16 +193,16 @@ struct opt_name opt_names[ARG_COUNT + 1] = {
/* create table of lv property names, e.g. lv_is_foo, and corresponding enum from lv_props.h */
-struct lvp_name lvp_names[LVP_COUNT + 1] = {
-#define lvp(a, b, c) { # a, a, b },
+struct lv_prop lv_props[LVP_COUNT + 1] = {
+#define lvp(a, b, c) { # a, a, b, c },
#include "lv_props.h"
#undef lvp
};
/* create table of lv type names, e.g. linear and corresponding enum from lv_types.h */
-struct lvt_name lvt_names[LVT_COUNT + 1] = {
-#define lvt(a, b, c) { # a, a, b },
+struct lv_type lv_types[LVT_COUNT + 1] = {
+#define lvt(a, b, c) { # a, a, b, c },
#include "lv_types.h"
#undef lvt
};
@@ -237,16 +221,24 @@ struct cmd_name cmd_names[CMD_COUNT + 1] = {
*/
#ifdef MAN_PAGE_GENERATOR
+
struct command_name command_names[MAX_COMMAND_NAMES] = {
#define xx(a, b, c...) { # a, b, c },
#include "commands.h"
#undef xx
};
struct command commands[COMMAND_COUNT];
-#else
-extern struct command_name command_names[MAX_COMMAND_NAMES]; /* defined in lvmcmdline.c */
+
+#else /* MAN_PAGE_GENERATOR */
+
+struct command_name command_names[MAX_COMMAND_NAMES] = {
+#define xx(a, b, c...) { # a, b, c, a},
+#include "commands.h"
+#undef xx
+};
extern struct command commands[COMMAND_COUNT]; /* defined in lvmcmdline.c */
-#endif
+
+#endif /* MAN_PAGE_GENERATOR */
/* array of pointers into opt_names[] that is sorted alphabetically (by long opt name) */
@@ -422,8 +414,8 @@ static int lvp_name_to_enum(struct command *cmd, char *str)
int i;
for (i = 1; i < LVP_COUNT; i++) {
- if (!strcmp(str, lvp_names[i].name))
- return lvp_names[i].lvp_enum;
+ if (!strcmp(str, lv_props[i].name))
+ return lv_props[i].lvp_enum;
}
log_error("Parsing command defs: unknown lv property %s", str);
@@ -438,8 +430,8 @@ static int lvt_name_to_enum(struct command *cmd, char *str)
int i;
for (i = 1; i < LVT_COUNT; i++) {
- if (!strcmp(str, lvt_names[i].name))
- return lvt_names[i].lvt_enum;
+ if (!strcmp(str, lv_types[i].name))
+ return lv_types[i].lvt_enum;
}
log_error("Parsing command defs: unknown lv type %s", str);
@@ -1525,7 +1517,7 @@ int define_commands(char *run_name)
static const char *lvt_enum_to_name(int lvt_enum)
{
- return lvt_names[lvt_enum].name;
+ return lv_types[lvt_enum].name;
}
static void _print_usage_description(struct command *cmd)
diff --git a/tools/command.h b/tools/command.h
index 7652d74..891349a 100644
--- a/tools/command.h
+++ b/tools/command.h
@@ -235,6 +235,25 @@ struct val_name {
const char *usage;
};
+/* see global lv_props[] */
+
+struct lv_prop {
+ const char *enum_name; /* "is_foo_LVP" */
+ int lvp_enum; /* is_foo_LVP */
+ const char *name; /* "lv_is_foo" */
+ int (*fn) (struct cmd_context *cmd, struct logical_volume *lv); /* lv_is_foo() */
+};
+
+/* see global lv_types[] */
+
+struct lv_type {
+ const char *enum_name; /* "foo_LVT" */
+ int lvt_enum; /* foo_LVT */
+ const char *name; /* "foo" */
+ int (*fn) (struct cmd_context *cmd, struct logical_volume *lv); /* lv_is_foo() */
+};
+
+
int define_commands(char *run_name);
int command_id_to_enum(const char *str);
void print_usage(struct command *cmd, int longhelp, int desc_first);
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index c82dab2..97d17e4 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -2523,7 +2523,7 @@ static int _lvconvert_swap_pool_metadata(struct cmd_context *cmd,
struct volume_group *vg = lv->vg;
struct logical_volume *prev_metadata_lv;
struct lv_segment *seg;
- struct lv_types *lvtype;
+ struct lv_type *lvtype;
char meta_name[NAME_LEN];
const char *swap_name;
uint32_t chunk_size;
@@ -3841,7 +3841,7 @@ static int _lvconvert_to_cache_vol_single(struct cmd_context *cmd,
if (!lv_is_cache_pool(cachepool_lv)) {
int lvt_enum = get_lvt_enum(cachepool_lv);
- struct lv_types *lvtype = get_lv_type(lvt_enum);
+ struct lv_type *lvtype = get_lv_type(lvt_enum);
if (lvt_enum != striped_LVT && lvt_enum != linear_LVT && lvt_enum != raid_LVT) {
log_error("LV %s with type %s cannot be converted to a cache pool.",
@@ -3950,7 +3950,7 @@ static int _lvconvert_to_thin_with_external_single(struct cmd_context *cmd,
if (!lv_is_thin_pool(thinpool_lv)) {
int lvt_enum = get_lvt_enum(thinpool_lv);
- struct lv_types *lvtype = get_lv_type(lvt_enum);
+ struct lv_type *lvtype = get_lv_type(lvt_enum);
if (lvt_enum != striped_LVT && lvt_enum != linear_LVT && lvt_enum != raid_LVT) {
log_error("LV %s with type %s cannot be converted to a thin pool.",
@@ -4274,7 +4274,7 @@ static int _lvconvert_raid_types_check(struct cmd_context *cmd, struct logical_v
int lv_is_named_arg)
{
int lvt_enum = get_lvt_enum(lv);
- struct lv_types *lvtype = get_lv_type(lvt_enum);
+ struct lv_type *lvtype = get_lv_type(lvt_enum);
if (!lv_is_visible(lv)) {
if (!lv_is_cache_pool_metadata(lv) &&
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index 404641f..f46e283 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -63,29 +63,17 @@ extern struct opt_name opt_names[ARG_COUNT + 1];
/*
* Table of LV properties
*/
-static struct lv_props _lv_props[LVP_COUNT + 1] = {
-#define lvp(a, b, c) {a, b, c},
-#include "lv_props.h"
-#undef lvp
-};
+extern struct lv_prop lv_props[LVP_COUNT + 1];
/*
* Table of LV types
*/
-static struct lv_types _lv_types[LVT_COUNT + 1] = {
-#define lvt(a, b, c) {a, b, c},
-#include "lv_types.h"
-#undef lvt
-};
+extern struct lv_type lv_types[LVT_COUNT + 1];
/*
* Table of command names
*/
-struct command_name command_names[MAX_COMMAND_NAMES] = {
-#define xx(a, b, c...) { # a, b, c, a},
-#include "commands.h"
-#undef xx
-};
+extern struct command_name command_names[MAX_COMMAND_NAMES];
/*
* Table of commands (as defined in command-lines.in)
@@ -1197,18 +1185,18 @@ int lvm_register_commands(char *name)
return 1;
}
-struct lv_props *get_lv_prop(int lvp_enum)
+struct lv_prop *get_lv_prop(int lvp_enum)
{
if (!lvp_enum)
return NULL;
- return &_lv_props[lvp_enum];
+ return &lv_props[lvp_enum];
}
-struct lv_types *get_lv_type(int lvt_enum)
+struct lv_type *get_lv_type(int lvt_enum)
{
if (!lvt_enum)
return NULL;
- return &_lv_types[lvt_enum];
+ return &lv_types[lvt_enum];
}
struct command *get_command(int cmd_enum)
diff --git a/tools/toollib.c b/tools/toollib.c
index 0e45d80..f2951a7 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -2366,7 +2366,7 @@ void opt_array_to_str(struct cmd_context *cmd, int *opts, int count,
static void lvp_bits_to_str(uint64_t bits, char *buf, int len)
{
- struct lv_props *prop;
+ struct lv_prop *prop;
int lvp_enum;
int pos = 0;
int ret;
@@ -2387,7 +2387,7 @@ static void lvp_bits_to_str(uint64_t bits, char *buf, int len)
static void lvt_bits_to_str(uint64_t bits, char *buf, int len)
{
- struct lv_types *type;
+ struct lv_type *type;
int lvt_enum;
int pos = 0;
int ret;
@@ -2593,7 +2593,7 @@ int get_lvt_enum(struct logical_volume *lv)
static int _lv_types_match(struct cmd_context *cmd, struct logical_volume *lv, uint64_t lvt_bits,
uint64_t *match_bits, uint64_t *unmatch_bits)
{
- struct lv_types *type;
+ struct lv_type *type;
int lvt_enum;
int found_a_match = 0;
int match;
@@ -2642,7 +2642,7 @@ static int _lv_types_match(struct cmd_context *cmd, struct logical_volume *lv, u
static int _lv_props_match(struct cmd_context *cmd, struct logical_volume *lv, uint64_t lvp_bits,
uint64_t *match_bits, uint64_t *unmatch_bits)
{
- struct lv_props *prop;
+ struct lv_prop *prop;
int lvp_enum;
int found_a_mismatch = 0;
int match;
@@ -2697,7 +2697,7 @@ static int _check_lv_types(struct cmd_context *cmd, struct logical_volume *lv, i
ret = _lv_types_match(cmd, lv, cmd->command->required_pos_args[pos-1].def.lvt_bits, NULL, NULL);
if (!ret) {
int lvt_enum = get_lvt_enum(lv);
- struct lv_types *type = get_lv_type(lvt_enum);
+ struct lv_type *type = get_lv_type(lvt_enum);
log_warn("Operation on LV %s which has invalid type %s.",
display_lvname(lv), type ? type->name : "unknown");
}
@@ -2711,7 +2711,7 @@ static int _check_lv_rules(struct cmd_context *cmd, struct logical_volume *lv)
{
char buf[64];
struct cmd_rule *rule;
- struct lv_types *lvtype = NULL;
+ struct lv_type *lvtype = NULL;
uint64_t lv_props_match_bits, lv_props_unmatch_bits;
uint64_t lv_types_match_bits, lv_types_unmatch_bits;
int opts_match_count, opts_unmatch_count;
diff --git a/tools/tools.h b/tools/tools.h
index cb3ffa0..fe3699e 100644
--- a/tools/tools.h
+++ b/tools/tools.h
@@ -114,21 +114,6 @@ struct arg_value_group_list {
uint32_t prio;
};
-/* a global table of possible LV properties */
-struct lv_props {
- int lvp_enum; /* is_foo_LVP from lv_props.h */
- const char *name; /* "lv_is_foo" used in command-lines.in */
- int (*fn) (struct cmd_context *cmd, struct logical_volume *lv); /* lv_is_foo() */
-};
-
-/* a global table of possible LV types */
-/* (as exposed externally in command line interface, not exactly as internal segtype is used) */
-struct lv_types {
- int lvt_enum; /* is_foo_LVT from lv_types.h */
- const char *name; /* "foo" used in command-lines.in, i.e. LV_foo */
- int (*fn) (struct cmd_context *cmd, struct logical_volume *lv); /* lv_is_foo() */
-};
-
#define CACHE_VGMETADATA 0x00000001
#define PERMITTED_READ_ONLY 0x00000002
/* Process all VGs if none specified on the command line. */
@@ -232,8 +217,8 @@ int vgchange_activate(struct cmd_context *cmd, struct volume_group *vg,
int vgchange_background_polling(struct cmd_context *cmd, struct volume_group *vg);
-struct lv_props *get_lv_prop(int lvp_enum);
-struct lv_types *get_lv_type(int lvt_enum);
+struct lv_prop *get_lv_prop(int lvp_enum);
+struct lv_type *get_lv_type(int lvt_enum);
struct command *get_command(int cmd_enum);
int lvchange_properties_cmd(struct cmd_context *cmd, int argc, char **argv);
6 years, 3 months
master - commands: combine duplicate arrays for opt and val
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=690f60473352e9909df...
Commit: 690f60473352e9909df95fae96a5d99b8b0c9db7
Parent: f48e6b2690c43120ec87e4fa913b2bd952a53511
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue Mar 7 11:47:44 2017 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Wed Mar 8 11:03:02 2017 -0600
commands: combine duplicate arrays for opt and val
command.c and lvmcmdline.c each had a full array defining
all options and values. This duplication was not removed
when the command.c code was merged into the run time.
---
tools/command.c | 25 -------------------
tools/command.h | 24 ++++++++++++++++++
tools/lvm.c | 8 +++---
tools/lvm2cmdline.h | 2 +-
tools/lvmcmdline.c | 66 ++++++++++++++++++++++----------------------------
tools/tools.h | 20 ---------------
tools/vals.h | 2 +-
7 files changed, 59 insertions(+), 88 deletions(-)
diff --git a/tools/command.c b/tools/command.c
index d184208..71056bf 100644
--- a/tools/command.c
+++ b/tools/command.c
@@ -167,31 +167,6 @@ enum {
#include "command.h" /* defines struct command */
#include "command-count.h" /* defines COMMAND_COUNT */
-
-/* see opt_names[] below, also see arg_props[] in tools.h and args.h */
-
-struct opt_name {
- const char *name; /* "foo_ARG" */
- int opt_enum; /* foo_ARG */
- const char short_opt; /* -f */
- char _padding[7];
- const char *long_opt; /* --foo */
- int val_enum; /* xyz_VAL when --foo takes a val like "--foo xyz" */
- uint32_t flags;
- uint32_t prio;
- const char *desc;
-};
-
-/* see val_names[] below, also see val_props[] in tools.h and vals.h */
-
-struct val_name {
- const char *enum_name; /* "foo_VAL" */
- int val_enum; /* foo_VAL */
- int (*fn) (struct cmd_context *cmd, struct arg_values *av); /* foo_arg() */
- const char *name; /* FooVal */
- const char *usage;
-};
-
/* see lvp_names[] below, also see lv_props[] in tools.h and lv_props.h */
struct lvp_name {
diff --git a/tools/command.h b/tools/command.h
index 2e4dba3..7652d74 100644
--- a/tools/command.h
+++ b/tools/command.h
@@ -211,6 +211,30 @@ struct command {
int pos_count; /* temp counter used by create-command */
};
+/* see global opt_names[] */
+
+struct opt_name {
+ const char *name; /* "foo_ARG" */
+ int opt_enum; /* foo_ARG */
+ const char short_opt; /* -f */
+ char _padding[7];
+ const char *long_opt; /* --foo */
+ int val_enum; /* xyz_VAL when --foo takes a val like "--foo xyz" */
+ uint32_t flags;
+ uint32_t prio;
+ const char *desc;
+};
+
+/* see global val_names[] */
+
+struct val_name {
+ const char *enum_name; /* "foo_VAL" */
+ int val_enum; /* foo_VAL */
+ int (*fn) (struct cmd_context *cmd, struct arg_values *av); /* foo_arg() */
+ const char *name; /* FooVal */
+ const char *usage;
+};
+
int define_commands(char *run_name);
int command_id_to_enum(const char *str);
void print_usage(struct command *cmd, int longhelp, int desc_first);
diff --git a/tools/lvm.c b/tools/lvm.c
index 5fd9918..0554007 100644
--- a/tools/lvm.c
+++ b/tools/lvm.c
@@ -97,8 +97,8 @@ static char *_list_args(const char *text, int state)
while (match_no < cname->num_args) {
char s[3];
char c;
- if (!(c = (_cmdline->arg_props +
- cname->valid_args[match_no++])->short_arg))
+ if (!(c = (_cmdline->opt_names +
+ cname->valid_args[match_no++])->short_opt))
continue;
sprintf(s, "-%c", c);
@@ -113,8 +113,8 @@ static char *_list_args(const char *text, int state)
while (match_no - cname->num_args < cname->num_args) {
const char *l;
- l = (_cmdline->arg_props +
- cname->valid_args[match_no++ - cname->num_args])->long_arg;
+ l = (_cmdline->opt_names +
+ cname->valid_args[match_no++ - cname->num_args])->long_opt;
if (*(l + 2) && !strncmp(text, l, len))
return strdup(l);
}
diff --git a/tools/lvm2cmdline.h b/tools/lvm2cmdline.h
index 5c5eaee..7353c7a 100644
--- a/tools/lvm2cmdline.h
+++ b/tools/lvm2cmdline.h
@@ -19,7 +19,7 @@
struct cmd_context;
struct cmdline_context {
- struct arg_props *arg_props;
+ struct opt_name *opt_names;
struct command *commands;
int num_commands;
struct command_name *command_names;
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index ad638af..404641f 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -53,20 +53,12 @@ extern char *optarg;
/*
* Table of valid --option values.
*/
-static struct val_props _val_props[VAL_COUNT + 1] = {
-#define val(a, b, c, d) {a, b, c, d},
-#include "vals.h"
-#undef val
-};
+extern struct val_name val_names[VAL_COUNT + 1];
/*
* Table of valid --option's
*/
-static struct arg_props _arg_props[ARG_COUNT + 1] = {
-#define arg(a, b, c, d, e, f, g) {a, b, "", "--" c, d, e, f, g},
-#include "args.h"
-#undef arg
-};
+extern struct opt_name opt_names[ARG_COUNT + 1];
/*
* Table of LV properties
@@ -277,7 +269,7 @@ unsigned grouped_arg_is_set(const struct arg_values *av, int a)
const char *arg_long_option_name(int a)
{
- return _cmdline.arg_props[a].long_arg;
+ return _cmdline.opt_names[a].long_opt;
}
const char *arg_value(const struct cmd_context *cmd, int a)
@@ -316,7 +308,7 @@ int32_t first_grouped_arg_int_value(const struct cmd_context *cmd, int a, const
int32_t arg_int_value(const struct cmd_context *cmd, int a, const int32_t def)
{
- return (_cmdline.arg_props[a].flags & ARG_GROUPABLE) ?
+ return (_cmdline.opt_names[a].flags & ARG_GROUPABLE) ?
first_grouped_arg_int_value(cmd, a, def) : (arg_is_set(cmd, a) ? cmd->opt_arg_values[a].i_value : def);
}
@@ -1088,7 +1080,7 @@ static void _set_valid_args_for_command_name(int ci)
for (i = 0; i < ARG_COUNT; i++) {
if (all_args[i]) {
- opt_enum = _cmdline.arg_props[i].arg_enum;
+ opt_enum = _cmdline.opt_names[i].opt_enum;
command_names[ci].valid_args[num_args] = opt_enum;
num_args++;
@@ -1789,12 +1781,12 @@ static void _usage_all(void)
* can't have more than 'a' long arguments.
*/
-static void _add_getopt_arg(int arg_enum, char **optstrp, struct option **longoptsp)
+static void _add_getopt_arg(int opt_enum, char **optstrp, struct option **longoptsp)
{
- struct arg_props *a = _cmdline.arg_props + arg_enum;
+ struct opt_name *a = _cmdline.opt_names + opt_enum;
- if (a->short_arg) {
- *(*optstrp)++ = a->short_arg;
+ if (a->short_opt) {
+ *(*optstrp)++ = a->short_opt;
if (a->val_enum)
*(*optstrp)++ = ':';
@@ -1802,8 +1794,8 @@ static void _add_getopt_arg(int arg_enum, char **optstrp, struct option **longop
#ifdef HAVE_GETOPTLONG
/* long_arg is "--foo", so +2 is the offset of the name after "--" */
- if (*(a->long_arg + 2)) {
- (*longoptsp)->name = a->long_arg + 2;
+ if (*(a->long_opt + 2)) {
+ (*longoptsp)->name = a->long_opt + 2;
(*longoptsp)->has_arg = a->val_enum ? 1 : 0;
(*longoptsp)->flag = NULL;
@@ -1820,10 +1812,10 @@ static void _add_getopt_arg(int arg_enum, char **optstrp, struct option **longop
* (11 is the enum value for --cachepool, so 11+128)
*/
- if (a->short_arg)
- (*longoptsp)->val = a->short_arg;
+ if (a->short_opt)
+ (*longoptsp)->val = a->short_opt;
else
- (*longoptsp)->val = arg_enum + 128;
+ (*longoptsp)->val = opt_enum + 128;
(*longoptsp)++;
}
#endif
@@ -1856,14 +1848,14 @@ static int _find_arg(const char *cmd_name, int goval)
for (i = 0; i < cname->num_args; i++) {
arg_enum = cname->valid_args[i];
- /* assert arg_enum == _cmdline.arg_props[arg_enum].arg_enum */
+ /* assert arg_enum == _cmdline.opt_names[arg_enum].arg_enum */
/* the value returned by getopt matches the ascii value of single letter option */
- if (_cmdline.arg_props[arg_enum].short_arg && (goval == _cmdline.arg_props[arg_enum].short_arg))
+ if (_cmdline.opt_names[arg_enum].short_opt && (goval == _cmdline.opt_names[arg_enum].short_opt))
return arg_enum;
/* the value returned by getopt matches the enum value plus 128 */
- if (!_cmdline.arg_props[arg_enum].short_arg && (goval == (arg_enum + 128)))
+ if (!_cmdline.opt_names[arg_enum].short_opt && (goval == (arg_enum + 128)))
return arg_enum;
}
@@ -1874,7 +1866,7 @@ static int _process_command_line(struct cmd_context *cmd, int *argc, char ***arg
{
char str[((ARG_COUNT + 1) * 2) + 1], *ptr = str;
struct option opts[ARG_COUNT + 1], *o = opts;
- struct arg_props *a;
+ struct opt_name *a;
struct arg_values *av;
struct arg_value_group_list *current_group = NULL;
struct command_name *cname;
@@ -1893,7 +1885,7 @@ static int _process_command_line(struct cmd_context *cmd, int *argc, char ***arg
/*
* create the short-form character array (str) and the long-form option
* array (opts) to pass to the getopt_long() function. IOW we generate
- * the arguments to pass to getopt_long() from the args.h/arg_props data.
+ * the arguments to pass to getopt_long() from the opt_names data.
*/
for (i = 0; i < cname->num_args; i++)
_add_getopt_arg(cname->valid_args[i], &ptr, &o);
@@ -1917,7 +1909,7 @@ static int _process_command_line(struct cmd_context *cmd, int *argc, char ***arg
return 0;
}
- a = _cmdline.arg_props + arg_enum;
+ a = _cmdline.opt_names + arg_enum;
av = &cmd->opt_arg_values[arg_enum];
@@ -1947,10 +1939,10 @@ static int _process_command_line(struct cmd_context *cmd, int *argc, char ***arg
if (av->count && !(a->flags & ARG_COUNTABLE)) {
log_error("Option%s%c%s%s may not be repeated.",
- a->short_arg ? " -" : "",
- a->short_arg ? : ' ',
- (a->short_arg && a->long_arg) ?
- "/" : "", a->long_arg ? : "");
+ a->short_opt ? " -" : "",
+ a->short_opt ? : ' ',
+ (a->short_opt && a->long_opt) ?
+ "/" : "", a->long_opt ? : "");
return 0;
}
@@ -1962,8 +1954,8 @@ static int _process_command_line(struct cmd_context *cmd, int *argc, char ***arg
av->value = optarg;
- if (!_val_props[a->val_enum].fn(cmd, av)) {
- log_error("Invalid argument for %s: %s", a->long_arg, optarg);
+ if (!val_names[a->val_enum].fn(cmd, av)) {
+ log_error("Invalid argument for %s: %s", a->long_opt, optarg);
return 0;
}
}
@@ -1997,12 +1989,12 @@ static int _merge_synonym(struct cmd_context *cmd, int oldarg, int newarg)
if (arg_is_set(cmd, oldarg) && arg_is_set(cmd, newarg)) {
log_error("%s and %s are synonyms. Please only supply one.",
- _cmdline.arg_props[oldarg].long_arg, _cmdline.arg_props[newarg].long_arg);
+ _cmdline.opt_names[oldarg].long_opt, _cmdline.opt_names[newarg].long_opt);
return 0;
}
/* Not groupable? */
- if (!(_cmdline.arg_props[oldarg].flags & ARG_GROUPABLE)) {
+ if (!(_cmdline.opt_names[oldarg].flags & ARG_GROUPABLE)) {
if (arg_is_set(cmd, oldarg))
_copy_arg_values(cmd->opt_arg_values, oldarg, newarg);
return 1;
@@ -3085,7 +3077,7 @@ struct cmd_context *init_lvm(unsigned set_connections, unsigned set_filters)
return_NULL;
}
- _cmdline.arg_props = &_arg_props[0];
+ _cmdline.opt_names = &opt_names[0];
if (stored_errno()) {
destroy_toolcontext(cmd);
diff --git a/tools/tools.h b/tools/tools.h
index f2c926f..cb3ffa0 100644
--- a/tools/tools.h
+++ b/tools/tools.h
@@ -108,32 +108,12 @@ struct arg_values {
/* void *ptr; // Currently not used. */
};
-/* a global table of possible --option's */
-struct arg_props {
- int arg_enum; /* foo_ARG from args.h */
- const char short_arg;
- char _padding[7];
- const char *long_arg;
- int val_enum; /* foo_VAL from vals.h */
- uint32_t flags;
- uint32_t prio;
- const char *desc;
-};
-
struct arg_value_group_list {
struct dm_list list;
struct arg_values arg_values[0];
uint32_t prio;
};
-/* a global table of possible --option values */
-struct val_props {
- int val_enum; /* foo_VAL from vals.h */
- int (*fn) (struct cmd_context *cmd, struct arg_values *av);
- const char *name;
- const char *usage;
-};
-
/* a global table of possible LV properties */
struct lv_props {
int lvp_enum; /* is_foo_LVP from lv_props.h */
diff --git a/tools/vals.h b/tools/vals.h
index ed572ee..4c70640 100644
--- a/tools/vals.h
+++ b/tools/vals.h
@@ -63,7 +63,7 @@
* then also be added to the usage string for the val type here.
* It would be nice if the accepted values could be defined in a
* more consistent way, and perhaps in a single place, perhaps in
- * struct val_props.
+ * struct val_names.
*
* The usage text for an option is not always the full
* set of words accepted for an option, but may be a
6 years, 3 months
master - help: avoid end notes repetition in lvm help all
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=f48e6b2690c43120ec8...
Commit: f48e6b2690c43120ec87e4fa913b2bd952a53511
Parent: ed58672029567858709113b67337e4dfaf31d210
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue Mar 7 12:01:06 2017 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Wed Mar 8 11:03:02 2017 -0600
help: avoid end notes repetition in lvm help all
---
tools/command.c | 6 +++---
tools/command.h | 2 +-
tools/lvmcmdline.c | 15 ++++++++++-----
3 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/tools/command.c b/tools/command.c
index 5fc5ff3..d184208 100644
--- a/tools/command.c
+++ b/tools/command.c
@@ -1989,9 +1989,9 @@ void print_usage_common_cmd(struct command_name *cname, struct command *cmd)
printf("\n\n");
}
-void print_usage_notes(struct command_name *cname, struct command *cmd)
+void print_usage_notes(struct command_name *cname)
{
- if (command_has_alternate_extents(cname->name)) {
+ if (cname && command_has_alternate_extents(cname->name)) {
printf(" Special options for command:\n");
printf(" [ --extents Number[PERCENT] ]\n"
" The --extents option can be used in place of --size.\n"
@@ -1999,7 +1999,7 @@ void print_usage_notes(struct command_name *cname, struct command *cmd)
printf("\n");
}
- if (!strcmp(cname->name, "lvcreate")) {
+ if (cname && !strcmp(cname->name, "lvcreate")) {
printf(" [ --name String ]\n"
" The --name option is not required but is typically used.\n"
" When a name is not specified, a new LV name is generated\n"
diff --git a/tools/command.h b/tools/command.h
index 0109853..2e4dba3 100644
--- a/tools/command.h
+++ b/tools/command.h
@@ -216,7 +216,7 @@ int command_id_to_enum(const char *str);
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 print_usage_notes(struct command_name *cname, struct command *cmd);
+void print_usage_notes(struct command_name *cname);
void factor_common_options(void);
int command_has_alternate_extents(const char *name);
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index 53856ce..ad638af 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -1694,7 +1694,7 @@ static void _short_usage(const char *name)
log_error("Run `%s --help' for more information.", name);
}
-static int _usage(const char *name, int longhelp)
+static int _usage(const char *name, int longhelp, int skip_notes)
{
struct command_name *cname = find_command_name(name);
struct command *cmd;
@@ -1739,8 +1739,11 @@ static int _usage(const char *name, int longhelp)
print_usage_common_lvm(cname, cmd);
}
+ if (skip_notes)
+ return 1;
+
if (longhelp)
- print_usage_notes(cname, cmd);
+ print_usage_notes(cname);
else
log_print("Use --longhelp to show all options and advanced commands.");
@@ -1754,8 +1757,10 @@ static void _usage_all(void)
for (i = 0; i < MAX_COMMAND_NAMES; i++) {
if (!command_names[i].name)
break;
- _usage(command_names[i].name, 1);
+ _usage(command_names[i].name, 1, 1);
}
+
+ print_usage_notes(NULL);
}
/*
@@ -2202,7 +2207,7 @@ static int _process_common_commands(struct cmd_context *cmd)
if (arg_is_set(cmd, help_ARG) ||
arg_is_set(cmd, longhelp_ARG) ||
arg_is_set(cmd, help2_ARG)) {
- _usage(cmd->name, arg_is_set(cmd, longhelp_ARG));
+ _usage(cmd->name, arg_is_set(cmd, longhelp_ARG), 0);
return ECMD_PROCESSED;
}
@@ -2240,7 +2245,7 @@ int help(struct cmd_context *cmd __attribute__((unused)), int argc, char **argv)
else {
int i;
for (i = 0; i < argc; i++)
- if (!_usage(argv[i], 0))
+ if (!_usage(argv[i], 0, 0))
ret = EINVALID_CMD_LINE;
}
6 years, 3 months
master - metadata: comments
by Heinz Mauelshagen
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=ed58672029567858709...
Commit: ed58672029567858709113b67337e4dfaf31d210
Parent: 3a5561e5ab5c916df8f90cc880ce2acb04ee2ecb
Author: Heinz Mauelshagen <heinzm(a)redhat.com>
AuthorDate: Wed Mar 8 15:13:59 2017 +0100
Committer: Heinz Mauelshagen <heinzm(a)redhat.com>
CommitterDate: Wed Mar 8 15:13:59 2017 +0100
metadata: comments
log_count,nosync,stripes,stripe_size,,... are also used for raid.
---
lib/metadata/metadata-exported.h | 16 ++++++++--------
1 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index 4d02d04..4960499 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -916,8 +916,8 @@ struct lvcreate_params {
int wipe_signatures; /* all */
int32_t major; /* all */
int32_t minor; /* all */
- int log_count; /* mirror */
- int nosync; /* mirror */
+ int log_count; /* mirror/RAID */
+ int nosync; /* mirror/RAID */
int pool_metadata_spare; /* pools */
int type; /* type arg is given */
int temporary; /* temporary LV */
@@ -948,15 +948,15 @@ struct lvcreate_params {
#define PASS_ARG_ZERO 0x08
int passed_args;
- uint32_t stripes; /* striped */
- uint32_t stripe_size; /* striped */
+ uint32_t stripes; /* striped/RAID */
+ uint32_t stripe_size; /* striped/RAID */
uint32_t chunk_size; /* snapshot */
- uint32_t region_size; /* mirror */
+ uint32_t region_size; /* mirror/RAID */
- unsigned stripes_supplied; /* striped */
- unsigned stripe_size_supplied; /* striped */
+ unsigned stripes_supplied; /* striped/RAID */
+ unsigned stripe_size_supplied; /* striped/RAID */
- uint32_t mirrors; /* mirror */
+ uint32_t mirrors; /* mirror/RAID */
uint32_t min_recovery_rate; /* RAID */
uint32_t max_recovery_rate; /* RAID */
6 years, 3 months