Blame SOURCES/kvm-block-curl-Don-t-lose-original-error-when-a-connecti.patch

9ae3a8
From 264a2066904d31c46860e0bac8790d57e6498b80 Mon Sep 17 00:00:00 2001
9ae3a8
From: Richard Jones <rjones@redhat.com>
9ae3a8
Date: Thu, 16 Jul 2015 15:41:54 +0200
9ae3a8
Subject: [PATCH 1/5] block/curl: Don't lose original error when a connection
9ae3a8
 fails.
9ae3a8
9ae3a8
Message-id: <1437061314-4775-1-git-send-email-rjones@redhat.com>
9ae3a8
Patchwork-id: 67043
9ae3a8
O-Subject: [RHEL-7.2 qemu-kvm PATCH v3] block/curl: Don't lose original error when a connection fails.
9ae3a8
Bugzilla: 1235812
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
9ae3a8
From: "Richard W.M. Jones" <rjones@redhat.com>
9ae3a8
9ae3a8
Currently if qemu is connected to a curl source (eg. web server), and
9ae3a8
the web server fails / times out / dies, you always see a bogus EIO
9ae3a8
"Input/output error".
9ae3a8
9ae3a8
For example, choose a large file located on any local webserver which
9ae3a8
you control:
9ae3a8
9ae3a8
  $ qemu-img convert -p http://example.com/large.iso /tmp/test
9ae3a8
9ae3a8
Once it starts copying the file, stop the webserver and you will see
9ae3a8
qemu-img fail with:
9ae3a8
9ae3a8
  qemu-img: error while reading sector 61440: Input/output error
9ae3a8
9ae3a8
This patch does two things: Firstly print the actual error from curl
9ae3a8
so it doesn't get lost.  Secondly, change EIO to EPROTO.  EPROTO is a
9ae3a8
POSIX.1 compatible errno which more accurately reflects that there was
9ae3a8
a protocol error, rather than some kind of hardware failure.
9ae3a8
9ae3a8
After this patch is applied, the error changes to:
9ae3a8
9ae3a8
  $ qemu-img convert -p http://example.com/large.iso /tmp/test
9ae3a8
  qemu-img: curl: transfer closed with 469989 bytes remaining to read
9ae3a8
  qemu-img: error while reading sector 16384: Protocol error
9ae3a8
9ae3a8
Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
9ae3a8
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
Signed-off-by: Jeff Cody <jcody@redhat.com>
9ae3a8
9ae3a8
BZ: https://bugzilla.redhat.com/1235812
9ae3a8
Brew: http://brewweb.devel.redhat.com/brew/taskinfo?taskID=9529354
9ae3a8
Upstream-status: 796a060bc0fab40953997976a2e30d9d6235bc7b
9ae3a8
---
9ae3a8
 block/curl.c | 15 ++++++++++++++-
9ae3a8
 1 file changed, 14 insertions(+), 1 deletion(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 block/curl.c | 15 ++++++++++++++-
9ae3a8
 1 file changed, 14 insertions(+), 1 deletion(-)
9ae3a8
9ae3a8
diff --git a/block/curl.c b/block/curl.c
9ae3a8
index 3088329..dfa8cee 100644
9ae3a8
--- a/block/curl.c
9ae3a8
+++ b/block/curl.c
9ae3a8
@@ -22,6 +22,7 @@
9ae3a8
  * THE SOFTWARE.
9ae3a8
  */
9ae3a8
 #include "qemu-common.h"
9ae3a8
+#include "qemu/error-report.h"
9ae3a8
 #include "block/block_int.h"
9ae3a8
 #include "qapi/qmp/qbool.h"
9ae3a8
 #include <curl/curl.h>
9ae3a8
@@ -294,6 +295,18 @@ static void curl_multi_check_completion(BDRVCURLState *s)
9ae3a8
             /* ACBs for successful messages get completed in curl_read_cb */
9ae3a8
             if (msg->data.result != CURLE_OK) {
9ae3a8
                 int i;
9ae3a8
+                static int errcount = 100;
9ae3a8
+
9ae3a8
+                /* Don't lose the original error message from curl, since
9ae3a8
+                 * it contains extra data.
9ae3a8
+                 */
9ae3a8
+                if (errcount > 0) {
9ae3a8
+                    error_report("curl: %s", state->errmsg);
9ae3a8
+                    if (--errcount == 0) {
9ae3a8
+                        error_report("curl: further errors suppressed");
9ae3a8
+                    }
9ae3a8
+                }
9ae3a8
+
9ae3a8
                 for (i = 0; i < CURL_NUM_ACB; i++) {
9ae3a8
                     CURLAIOCB *acb = state->acb[i];
9ae3a8
 
9ae3a8
@@ -301,7 +314,7 @@ static void curl_multi_check_completion(BDRVCURLState *s)
9ae3a8
                         continue;
9ae3a8
                     }
9ae3a8
 
9ae3a8
-                    acb->common.cb(acb->common.opaque, -EIO);
9ae3a8
+                    acb->common.cb(acb->common.opaque, -EPROTO);
9ae3a8
                     qemu_aio_release(acb);
9ae3a8
                     state->acb[i] = NULL;
9ae3a8
                 }
9ae3a8
-- 
9ae3a8
1.8.3.1
9ae3a8