From patchwork Wed Mar 17 15:17:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 1454790 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Ci2gKYqd; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F0vTt5z74z9s1l for ; Thu, 18 Mar 2021 02:39:29 +1100 (AEDT) Received: from localhost ([::1]:38596 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lMYGc-00089V-JF for incoming@patchwork.ozlabs.org; Wed, 17 Mar 2021 11:39:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45182) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMXvh-00077i-Bz for qemu-devel@nongnu.org; Wed, 17 Mar 2021 11:17:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:26553) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMXvd-0005eh-Op for qemu-devel@nongnu.org; Wed, 17 Mar 2021 11:17:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615994264; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=4ChREDXnZrersaVgH8vCUJeaUh07mfX8iyoJGvtGVTo=; b=Ci2gKYqd6mbZAhqG2GtbrIq4/iInhTnBUZGllXvP6uDD3pHejvM3NiqEQA1CrbHjZpcp3r zkhoxjrAOVUCrPpp8gXM8szDHYsKw4GGticvuXXwYgdyxMFsnP0uH/OOCFHpnDabNHSsDx pq8xTAuIdyyuohKBPWByI0Lyv26ZP1g= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-222-EVU27mJ2NH-st2v2t4otCg-1; Wed, 17 Mar 2021 11:17:42 -0400 X-MC-Unique: EVU27mJ2NH-st2v2t4otCg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D629018C8C27; Wed, 17 Mar 2021 15:17:39 +0000 (UTC) Received: from merkur.fritz.box (ovpn-114-202.ams2.redhat.com [10.36.114.202]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8EF0A1037E82; Wed, 17 Mar 2021 15:17:38 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH] curl: Allow reading after EOF Date: Wed, 17 Mar 2021 16:17:34 +0100 Message-Id: <20210317151734.41656-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.251, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, afrosi@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This makes the curl driver more consistent with file-posix in that it doesn't return errors any more for reading after the end of the remote file. Instead, zeros are returned for these areas. This inconsistency was reported in: https://bugzilla.redhat.com/show_bug.cgi?id=1935061 Note that the image used in this bug report has a corrupted snapshot table, which means that the qcow2 driver tries to do a zero-length read after EOF on its image file. The old behaviour of the curl driver can hardly be called a bug, but the inconsistency turned out to be confusing. Reported-by: Alice Frosi Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- It is not entirely clear to me if this is something we want to do. If we do care about consistency between protocol drivers, something like this should probably be done in block/io.c eventually - but that would require converting bs->total_sectors to byte granularity first. Any opinions on what the most desirable semantics would be and whether we should patch individual drivers until we can have a generic solution? block/curl.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/block/curl.c b/block/curl.c index 50e741a0d7..a8d87a1813 100644 --- a/block/curl.c +++ b/block/curl.c @@ -898,6 +898,7 @@ out: static int coroutine_fn curl_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int flags) { + BDRVCURLState *s = bs->opaque; CURLAIOCB acb = { .co = qemu_coroutine_self(), .ret = -EINPROGRESS, @@ -906,6 +907,15 @@ static int coroutine_fn curl_co_preadv(BlockDriverState *bs, .bytes = bytes }; + if (offset > s->len || bytes > s->len - offset) { + uint64_t req_bytes = offset > s->len ? 0 : s->len - offset; + qemu_iovec_memset(qiov, req_bytes, 0, bytes - req_bytes); + bytes = req_bytes; + } + if (bytes == 0) { + return 0; + } + curl_setup_preadv(bs, &acb); while (acb.ret == -EINPROGRESS) { qemu_coroutine_yield();