Skip to contentSkip to conversation

master - lvcreate/lvresize: the --size option accepts signed values

PATCH David Teigland 1 participant 1 message Mar 2, 2017

lore
Share & tools
lore
#0 lore raw
Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=b7831fc14ae9a7b35c1d814486f45f4b3cbadc8b
Commit:        b7831fc14ae9a7b35c1d814486f45f4b3cbadc8b
Parent:        70c1fa3764639afd0d2e81968c4495bb3f3c6a73
Author:        David Teigland <[email protected]>
AuthorDate:    Thu Mar 2 12:53:01 2017 -0600
Committer:     David Teigland <[email protected]>
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(-)
tools/args.h +2 -2
index 471a3c2..eb11f38 100644
@@ -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"
tools/command-lines.in +32 -32

256 lines not on this page · raw message

tools/command.c +46 -18

185 lines not on this page · raw message

tools/lvmcmdline.c +25 -3
index d5385a8..5410a1f 100644
@@ -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)
tools/tools.h +2 -1
index 1e1e7f1..f2c926f 100644
@@ -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);
tools/vals.h +3 -1
index d485926..ab1b715 100644
@@ -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")