$OpenBSD: patch-block_curl_c,v 1.2 2016/05/13 07:20:46 ajacoutot Exp $

Revert..

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

to be able to build on OpenBSD due to the lack of EPROTO errno.

--- block/curl.c.orig	Wed Mar 30 15:45:01 2016
+++ block/curl.c	Wed Mar 30 20:38:00 2016
@@ -24,7 +24,6 @@
 #include "qemu/osdep.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
-#include "qemu/error-report.h"
 #include "block/block_int.h"
 #include "qapi/qmp/qbool.h"
 #include "qapi/qmp/qstring.h"
@@ -313,18 +312,7 @@ static void curl_multi_check_completion(BDRVCURLState 
             /* 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];
 
@@ -332,7 +320,7 @@ static void curl_multi_check_completion(BDRVCURLState 
                         continue;
                     }
 
-                    acb->common.cb(acb->common.opaque, -EPROTO);
+                    acb->common.cb(acb->common.opaque, -EIO);
                     qemu_aio_unref(acb);
                     state->acb[i] = NULL;
                 }
