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