thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
9ae3a8
From b7cea737b24456765a21ed43ebd9b68ebbbf3537 Mon Sep 17 00:00:00 2001
9ae3a8
From: John Snow <jsnow@redhat.com>
9ae3a8
Date: Mon, 23 Nov 2015 17:38:21 +0100
9ae3a8
Subject: [PATCH 02/27] cutils: Support 'P' and 'E' suffixes in strtosz()
9ae3a8
9ae3a8
RH-Author: John Snow <jsnow@redhat.com>
9ae3a8
Message-id: <1448300320-7772-3-git-send-email-jsnow@redhat.com>
9ae3a8
Patchwork-id: 68430
9ae3a8
O-Subject: [RHEL-7.3 qemu-kvm PATCH v2 02/21] cutils: Support 'P' and 'E' suffixes in strtosz()
9ae3a8
Bugzilla: 1272523
9ae3a8
RH-Acked-by: Thomas Huth <thuth@redhat.com>
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
RH-Acked-by: Max Reitz <mreitz@redhat.com>
9ae3a8
9ae3a8
From: Kevin Wolf <kwolf@redhat.com>
9ae3a8
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Reviewed-by: Eric Blake <eblake@redhat.com>
9ae3a8
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
(cherry picked from commit 5e00984aef7c1c317e27c0e8acf66526513c770f)
9ae3a8
Signed-off-by: John Snow <jsnow@redhat.com>
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 include/qemu-common.h      |  2 ++
9ae3a8
 monitor.c                  |  8 ++++----
9ae3a8
 qemu-img.c                 | 10 ++++++----
9ae3a8
 tests/qemu-iotests/049.out |  8 ++++----
9ae3a8
 util/cutils.c              |  4 ++++
9ae3a8
 5 files changed, 20 insertions(+), 12 deletions(-)
9ae3a8
9ae3a8
diff --git a/include/qemu-common.h b/include/qemu-common.h
9ae3a8
index aee85e3..67f57c9 100644
9ae3a8
--- a/include/qemu-common.h
9ae3a8
+++ b/include/qemu-common.h
9ae3a8
@@ -178,6 +178,8 @@ int parse_uint_full(const char *s, unsigned long long *value, int base);
9ae3a8
  * A-Z, as strtosz() will use qemu_toupper() on the given argument
9ae3a8
  * prior to comparison.
9ae3a8
  */
9ae3a8
+#define STRTOSZ_DEFSUFFIX_EB	'E'
9ae3a8
+#define STRTOSZ_DEFSUFFIX_PB	'P'
9ae3a8
 #define STRTOSZ_DEFSUFFIX_TB	'T'
9ae3a8
 #define STRTOSZ_DEFSUFFIX_GB	'G'
9ae3a8
 #define STRTOSZ_DEFSUFFIX_MB	'M'
9ae3a8
diff --git a/monitor.c b/monitor.c
9ae3a8
index 6a1d06e..33c5bc8 100644
9ae3a8
--- a/monitor.c
9ae3a8
+++ b/monitor.c
9ae3a8
@@ -94,10 +94,10 @@
9ae3a8
  * 'M'          Non-negative target long (32 or 64 bit), in user mode the
9ae3a8
  *              value is multiplied by 2^20 (think Mebibyte)
9ae3a8
  * 'o'          octets (aka bytes)
9ae3a8
- *              user mode accepts an optional T, t, G, g, M, m, K, k
9ae3a8
- *              suffix, which multiplies the value by 2^40 for
9ae3a8
- *              suffixes T and t, 2^30 for suffixes G and g, 2^20 for
9ae3a8
- *              M and m, 2^10 for K and k
9ae3a8
+ *              user mode accepts an optional E, e, P, p, T, t, G, g, M, m,
9ae3a8
+ *              K, k suffix, which multiplies the value by 2^60 for suffixes E
9ae3a8
+ *              and e, 2^50 for suffixes P and p, 2^40 for suffixes T and t,
9ae3a8
+ *              2^30 for suffixes G and g, 2^20 for M and m, 2^10 for K and k
9ae3a8
  * 'T'          double
9ae3a8
  *              user mode accepts an optional ms, us, ns suffix,
9ae3a8
  *              which divides the value by 1e3, 1e6, 1e9, respectively
9ae3a8
diff --git a/qemu-img.c b/qemu-img.c
9ae3a8
index 9c021e7..eb2d4cb 100644
9ae3a8
--- a/qemu-img.c
9ae3a8
+++ b/qemu-img.c
9ae3a8
@@ -87,8 +87,9 @@ static void help(void)
9ae3a8
            "  'src_cache' is the cache mode used to read input disk images, the valid\n"
9ae3a8
            "    options are the same as for the 'cache' option\n"
9ae3a8
            "  'size' is the disk image size in bytes. Optional suffixes\n"
9ae3a8
-           "    'k' or 'K' (kilobyte, 1024), 'M' (megabyte, 1024k), 'G' (gigabyte, 1024M)\n"
9ae3a8
-           "    and T (terabyte, 1024G) are supported. 'b' is ignored.\n"
9ae3a8
+           "    'k' or 'K' (kilobyte, 1024), 'M' (megabyte, 1024k), 'G' (gigabyte, 1024M),\n"
9ae3a8
+           "    'T' (terabyte, 1024G), 'P' (petabyte, 1024T) and 'E' (exabyte, 1024P)  are\n"
9ae3a8
+           "    supported. 'b' is ignored.\n"
9ae3a8
            "  'output_filename' is the destination disk image filename\n"
9ae3a8
            "  'output_fmt' is the destination format\n"
9ae3a8
            "  'options' is a comma separated list of format specific options in a\n"
9ae3a8
@@ -417,8 +418,9 @@ static int img_create(int argc, char **argv)
9ae3a8
                 error_report("Image size must be less than 8 EiB!");
9ae3a8
             } else {
9ae3a8
                 error_report("Invalid image size specified! You may use k, M, "
9ae3a8
-                      "G or T suffixes for ");
9ae3a8
-                error_report("kilobytes, megabytes, gigabytes and terabytes.");
9ae3a8
+                      "G, T, P or E suffixes for ");
9ae3a8
+                error_report("kilobytes, megabytes, gigabytes, terabytes, "
9ae3a8
+                             "petabytes and exabytes.");
9ae3a8
             }
9ae3a8
             goto fail;
9ae3a8
         }
9ae3a8
diff --git a/tests/qemu-iotests/049.out b/tests/qemu-iotests/049.out
9ae3a8
index b2fcf0b..3e56772 100644
9ae3a8
--- a/tests/qemu-iotests/049.out
9ae3a8
+++ b/tests/qemu-iotests/049.out
9ae3a8
@@ -108,15 +108,15 @@ qemu-img: TEST_DIR/t.qcow2: Could not resize image: Operation not supported
9ae3a8
 Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 size=-1024 encryption=off cluster_size=65536 lazy_refcounts=off 
9ae3a8
 
9ae3a8
 qemu-img create -f qcow2 TEST_DIR/t.qcow2 -- 1kilobyte
9ae3a8
-qemu-img: Invalid image size specified! You may use k, M, G or T suffixes for 
9ae3a8
-qemu-img: kilobytes, megabytes, gigabytes and terabytes.
9ae3a8
+qemu-img: Invalid image size specified! You may use k, M, G, T, P or E suffixes for 
9ae3a8
+qemu-img: kilobytes, megabytes, gigabytes, terabytes, petabytes and exabytes.
9ae3a8
 
9ae3a8
 qemu-img create -f qcow2 -o size=1kilobyte TEST_DIR/t.qcow2
9ae3a8
 Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 size=1024 encryption=off cluster_size=65536 lazy_refcounts=off 
9ae3a8
 
9ae3a8
 qemu-img create -f qcow2 TEST_DIR/t.qcow2 -- foobar
9ae3a8
-qemu-img: Invalid image size specified! You may use k, M, G or T suffixes for 
9ae3a8
-qemu-img: kilobytes, megabytes, gigabytes and terabytes.
9ae3a8
+qemu-img: Invalid image size specified! You may use k, M, G, T, P or E suffixes for 
9ae3a8
+qemu-img: kilobytes, megabytes, gigabytes, terabytes, petabytes and exabytes.
9ae3a8
 
9ae3a8
 qemu-img create -f qcow2 -o size=foobar TEST_DIR/t.qcow2
9ae3a8
 qemu-img: Parameter 'size' expects a size
9ae3a8
diff --git a/util/cutils.c b/util/cutils.c
9ae3a8
index a165819..8f28896 100644
9ae3a8
--- a/util/cutils.c
9ae3a8
+++ b/util/cutils.c
9ae3a8
@@ -267,6 +267,10 @@ static int64_t suffix_mul(char suffix, int64_t unit)
9ae3a8
         return unit * unit * unit;
9ae3a8
     case STRTOSZ_DEFSUFFIX_TB:
9ae3a8
         return unit * unit * unit * unit;
9ae3a8
+    case STRTOSZ_DEFSUFFIX_PB:
9ae3a8
+        return unit * unit * unit * unit * unit;
9ae3a8
+    case STRTOSZ_DEFSUFFIX_EB:
9ae3a8
+        return unit * unit * unit * unit * unit * unit;
9ae3a8
     }
9ae3a8
     return -1;
9ae3a8
 }
9ae3a8
-- 
9ae3a8
1.8.3.1
9ae3a8