Patchwork [v3,2/2] qemu-img:report size overflow error message

login
register
mail settings
Submitter liguang
Date Dec. 17, 2012, 1:49 a.m.
Message ID <1355708963-17675-2-git-send-email-lig.fnst@cn.fujitsu.com>
Download mbox | patch
Permalink /patch/206768/
State New
Headers show

Comments

liguang - Dec. 17, 2012, 1:49 a.m.
qemu-img will complain when qcow or qcow2
size overflow for 64 bits, report the right
message in this condition.

$./qemu-img create -f qcow2 /tmp/foo 0x10000000000000000
before change:
qemu-img: Invalid image size specified! You may use k, M, G or T suffixes for
qemu-img: kilobytes, megabytes, gigabytes and terabytes.

after change:
qemu-img: Image size must be less than 8 EiB!

Signed-off-by: liguang <lig.fnst@cn.fujitsu.com>
---
 qemu-img.c |   16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)

Patch

diff --git a/qemu-img.c b/qemu-img.c
index e29e01b..203e3cb 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -347,11 +347,17 @@  static int img_create(int argc, char **argv)
         char *end;
         sval = strtosz_suffix(argv[optind++], &end, STRTOSZ_DEFSUFFIX_B);
         if (sval < 0 || *end) {
-            error_report("Invalid image size specified! You may use k, M, G or "
-                  "T suffixes for ");
-            error_report("kilobytes, megabytes, gigabytes and terabytes.");
-            ret = -1;
-            goto out;
+            if (sval == -ERANGE) {
+                error_report("Image size must be less than 8 EiB!");
+                ret = -1;
+                goto out;
+            } else {
+                error_report("Invalid image size specified! You may use k, M, G or "
+                             "T suffixes for ");
+                error_report("kilobytes, megabytes, gigabytes and terabytes.");
+                ret = -1;
+                goto out;
+            }
         }
         img_size = (uint64_t)sval;
     }