From patchwork Wed Jul 15 02:26:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Cody X-Patchwork-Id: 495378 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1F7E2140771 for ; Wed, 15 Jul 2015 12:29:56 +1000 (AEST) Received: from localhost ([::1]:33558 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZFCSI-00079Q-9l for incoming@patchwork.ozlabs.org; Tue, 14 Jul 2015 22:29:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46165) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZFCPn-0002aV-HQ for qemu-devel@nongnu.org; Tue, 14 Jul 2015 22:27:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZFCPm-0001FL-D2 for qemu-devel@nongnu.org; Tue, 14 Jul 2015 22:27:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37124) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZFCPg-0001DP-5J; Tue, 14 Jul 2015 22:27:12 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id D02BD41AD2A; Wed, 15 Jul 2015 02:27:11 +0000 (UTC) Received: from localhost (ovpn-112-22.phx2.redhat.com [10.3.112.22]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t6F2R9AH008008 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA256 bits=256 verify=NO); Tue, 14 Jul 2015 22:27:11 -0400 From: Jeff Cody To: qemu-block@nongnu.org Date: Tue, 14 Jul 2015 22:26:57 -0400 Message-Id: <1436927217-383-6-git-send-email-jcody@redhat.com> In-Reply-To: <1436927217-383-1-git-send-email-jcody@redhat.com> References: <1436927217-383-1-git-send-email-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: jcody@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PULL for-2.4 5/5] block/curl: Don't lose original error when a connection fails. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- block/curl.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/block/curl.c b/block/curl.c index 3a2b63e..032cc8a 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 "qapi/qmp/qstring.h" @@ -298,6 +299,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]; @@ -305,7 +318,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; }