yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
34b321
From 8adbd2914ccd44e0b1766690b514bda213b88740 Mon Sep 17 00:00:00 2001
34b321
From: John Snow <jsnow@redhat.com>
34b321
Date: Mon, 23 Nov 2015 17:38:39 +0100
34b321
Subject: [PATCH 20/27] qemu-io: Correct error messages
34b321
34b321
RH-Author: John Snow <jsnow@redhat.com>
34b321
Message-id: <1448300320-7772-21-git-send-email-jsnow@redhat.com>
34b321
Patchwork-id: 68446
34b321
O-Subject: [RHEL-7.3 qemu-kvm PATCH v2 20/21] qemu-io: Correct error messages
34b321
Bugzilla: 1272523
34b321
RH-Acked-by: Thomas Huth <thuth@redhat.com>
34b321
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
34b321
RH-Acked-by: Max Reitz <mreitz@redhat.com>
34b321
34b321
Reported-by: Max Reitz <mreitz@redhat.com>
34b321
Signed-off-by: John Snow <jsnow@redhat.com>
34b321
Reviewed-by: Eric Blake <eblake@redhat.com>
34b321
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
34b321
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
34b321
(cherry picked from commit a9ecfa004f2dd83df612daac4a87dfc3a0feba28)
34b321
Signed-off-by: John Snow <jsnow@redhat.com>
34b321
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
34b321
34b321
Conflicts:
34b321
  qemu-io-cmds.c:
34b321
    - Fixes to sigraise are not backported.
34b321
34b321
Signed-off-by: John Snow <jsnow@redhat.com>
34b321
---
34b321
 qemu-io-cmds.c | 51 +++++++++++++++++++++++++++++++++------------------
34b321
 1 file changed, 33 insertions(+), 18 deletions(-)
34b321
34b321
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
34b321
index 6ea027d..b41d6ee 100644
34b321
--- a/qemu-io-cmds.c
34b321
+++ b/qemu-io-cmds.c
34b321
@@ -134,6 +134,21 @@ static int64_t cvtnum(const char *s)
34b321
     return ret;
34b321
 }
34b321
 
34b321
+static void print_cvtnum_err(int64_t rc, const char *arg)
34b321
+{
34b321
+    switch (rc) {
34b321
+    case -EINVAL:
34b321
+        printf("Parsing error: non-numeric argument,"
34b321
+               " or extraneous/unrecognized suffix -- %s\n", arg);
34b321
+        break;
34b321
+    case -ERANGE:
34b321
+        printf("Parsing error: argument too large -- %s\n", arg);
34b321
+        break;
34b321
+    default:
34b321
+        printf("Parsing error: %s\n", arg);
34b321
+    }
34b321
+}
34b321
+
34b321
 #define EXABYTES(x)     ((long long)(x) << 60)
34b321
 #define PETABYTES(x)    ((long long)(x) << 50)
34b321
 #define TERABYTES(x)    ((long long)(x) << 40)
34b321
@@ -355,13 +370,13 @@ create_iovec(BlockDriverState *bs, QEMUIOVector *qiov, char **argv, int nr_iov,
34b321
 
34b321
         len = cvtnum(arg);
34b321
         if (len < 0) {
34b321
-            printf("non-numeric length argument -- %s\n", arg);
34b321
+            print_cvtnum_err(len, arg);
34b321
             goto fail;
34b321
         }
34b321
 
34b321
         /* should be SIZE_T_MAX, but that doesn't exist */
34b321
         if (len > INT_MAX) {
34b321
-            printf("too large length argument -- %s\n", arg);
34b321
+            printf("Argument '%s' exceeds maximum size %d\n", arg, INT_MAX);
34b321
             goto fail;
34b321
         }
34b321
 
34b321
@@ -688,7 +703,7 @@ static int read_f(BlockDriverState *bs, int argc, char **argv)
34b321
             lflag = 1;
34b321
             pattern_count = cvtnum(optarg);
34b321
             if (pattern_count < 0) {
34b321
-                printf("non-numeric length argument -- %s\n", optarg);
34b321
+                print_cvtnum_err(pattern_count, optarg);
34b321
                 return 0;
34b321
             }
34b321
             break;
34b321
@@ -709,7 +724,7 @@ static int read_f(BlockDriverState *bs, int argc, char **argv)
34b321
             sflag = 1;
34b321
             pattern_offset = cvtnum(optarg);
34b321
             if (pattern_offset < 0) {
34b321
-                printf("non-numeric length argument -- %s\n", optarg);
34b321
+                print_cvtnum_err(pattern_offset, optarg);
34b321
                 return 0;
34b321
             }
34b321
             break;
34b321
@@ -732,14 +747,14 @@ static int read_f(BlockDriverState *bs, int argc, char **argv)
34b321
 
34b321
     offset = cvtnum(argv[optind]);
34b321
     if (offset < 0) {
34b321
-        printf("non-numeric length argument -- %s\n", argv[optind]);
34b321
+        print_cvtnum_err(offset, argv[optind]);
34b321
         return 0;
34b321
     }
34b321
 
34b321
     optind++;
34b321
     count = cvtnum(argv[optind]);
34b321
     if (count < 0) {
34b321
-        printf("non-numeric length argument -- %s\n", argv[optind]);
34b321
+        print_cvtnum_err(count, argv[optind]);
34b321
         return 0;
34b321
     } else if (count > SIZE_MAX) {
34b321
         printf("length cannot exceed %" PRIu64 ", given %s\n",
34b321
@@ -894,7 +909,7 @@ static int readv_f(BlockDriverState *bs, int argc, char **argv)
34b321
 
34b321
     offset = cvtnum(argv[optind]);
34b321
     if (offset < 0) {
34b321
-        printf("non-numeric length argument -- %s\n", argv[optind]);
34b321
+        print_cvtnum_err(offset, argv[optind]);
34b321
         return 0;
34b321
     }
34b321
     optind++;
34b321
@@ -1043,14 +1058,14 @@ static int write_f(BlockDriverState *bs, int argc, char **argv)
34b321
 
34b321
     offset = cvtnum(argv[optind]);
34b321
     if (offset < 0) {
34b321
-        printf("non-numeric length argument -- %s\n", argv[optind]);
34b321
+        print_cvtnum_err(offset, argv[optind]);
34b321
         return 0;
34b321
     }
34b321
 
34b321
     optind++;
34b321
     count = cvtnum(argv[optind]);
34b321
     if (count < 0) {
34b321
-        printf("non-numeric length argument -- %s\n", argv[optind]);
34b321
+        print_cvtnum_err(count, argv[optind]);
34b321
         return 0;
34b321
     } else if (count > SIZE_MAX) {
34b321
         printf("length cannot exceed %" PRIu64 ", given %s\n",
34b321
@@ -1179,7 +1194,7 @@ static int writev_f(BlockDriverState *bs, int argc, char **argv)
34b321
 
34b321
     offset = cvtnum(argv[optind]);
34b321
     if (offset < 0) {
34b321
-        printf("non-numeric length argument -- %s\n", argv[optind]);
34b321
+        print_cvtnum_err(offset, argv[optind]);
34b321
         return 0;
34b321
     }
34b321
     optind++;
34b321
@@ -1306,7 +1321,7 @@ static int multiwrite_f(BlockDriverState *bs, int argc, char **argv)
34b321
         /* Read the offset of the request */
34b321
         offset = cvtnum(argv[optind]);
34b321
         if (offset < 0) {
34b321
-            printf("non-numeric offset argument -- %s\n", argv[optind]);
34b321
+            print_cvtnum_err(offset, argv[optind]);
34b321
             goto out;
34b321
         }
34b321
         optind++;
34b321
@@ -1526,7 +1541,7 @@ static int aio_read_f(BlockDriverState *bs, int argc, char **argv)
34b321
 
34b321
     ctx->offset = cvtnum(argv[optind]);
34b321
     if (ctx->offset < 0) {
34b321
-        printf("non-numeric length argument -- %s\n", argv[optind]);
34b321
+        print_cvtnum_err(ctx->offset, argv[optind]);
34b321
         g_free(ctx);
34b321
         return 0;
34b321
     }
34b321
@@ -1618,7 +1633,7 @@ static int aio_write_f(BlockDriverState *bs, int argc, char **argv)
34b321
 
34b321
     ctx->offset = cvtnum(argv[optind]);
34b321
     if (ctx->offset < 0) {
34b321
-        printf("non-numeric length argument -- %s\n", argv[optind]);
34b321
+        print_cvtnum_err(ctx->offset, argv[optind]);
34b321
         g_free(ctx);
34b321
         return 0;
34b321
     }
34b321
@@ -1676,7 +1691,7 @@ static int truncate_f(BlockDriverState *bs, int argc, char **argv)
34b321
 
34b321
     offset = cvtnum(argv[1]);
34b321
     if (offset < 0) {
34b321
-        printf("non-numeric truncate argument -- %s\n", argv[1]);
34b321
+        print_cvtnum_err(offset, argv[1]);
34b321
         return 0;
34b321
     }
34b321
 
34b321
@@ -1822,14 +1837,14 @@ static int discard_f(BlockDriverState *bs, int argc, char **argv)
34b321
 
34b321
     offset = cvtnum(argv[optind]);
34b321
     if (offset < 0) {
34b321
-        printf("non-numeric length argument -- %s\n", argv[optind]);
34b321
+        print_cvtnum_err(offset, argv[optind]);
34b321
         return 0;
34b321
     }
34b321
 
34b321
     optind++;
34b321
     count = cvtnum(argv[optind]);
34b321
     if (count < 0) {
34b321
-        printf("non-numeric length argument -- %s\n", argv[optind]);
34b321
+        print_cvtnum_err(count, argv[optind]);
34b321
         return 0;
34b321
     } else if (count >> BDRV_SECTOR_BITS > INT_MAX) {
34b321
         printf("length cannot exceed %"PRIu64", given %s\n",
34b321
@@ -1867,7 +1882,7 @@ static int alloc_f(BlockDriverState *bs, int argc, char **argv)
34b321
 
34b321
     offset = cvtnum(argv[1]);
34b321
     if (offset < 0) {
34b321
-        printf("non-numeric offset argument -- %s\n", argv[1]);
34b321
+        print_cvtnum_err(offset, argv[1]);
34b321
         return 0;
34b321
     } else if (offset & 0x1ff) {
34b321
         printf("offset %" PRId64 " is not sector aligned\n",
34b321
@@ -1878,7 +1893,7 @@ static int alloc_f(BlockDriverState *bs, int argc, char **argv)
34b321
     if (argc == 3) {
34b321
         nb_sectors = cvtnum(argv[2]);
34b321
         if (nb_sectors < 0) {
34b321
-            printf("non-numeric length argument -- %s\n", argv[2]);
34b321
+            print_cvtnum_err(nb_sectors, argv[2]);
34b321
             return 0;
34b321
         } else if (nb_sectors > INT_MAX) {
34b321
             printf("length argument cannot exceed %d, given %s\n",
34b321
-- 
34b321
1.8.3.1
34b321