From nobody Wed Nov 19 12:35:24 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1615995667; cv=none; d=zohomail.com; s=zohoarc; b=jnCN6o5r7sZ9sX8MnwmKQ8qwbKRDKlXoAbVneYKwyiQpHO42eOqTkkMplBUFoMDNyo8BopCjf+vmGgtWBtZZmvggvUVBGJg+z98Ah5dKJyb49MicGUZWM9KOcAlgP8aBNE6yGFQFUKtuUg2VC+FWI1A8ZCb1LhnBtn+TRZmlnr0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615995667; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=4ChREDXnZrersaVgH8vCUJeaUh07mfX8iyoJGvtGVTo=; b=XoO5jn29juMy1A1VYa2YPfaoWkFnk5hMAGvp9pppXInEU0/OvD3HSID2Tq4W7zNd7QFSvKy9nlhe7c1Ar4uZU0I2vJJ93MMpcq0nR63QmAoKkdzJPvi6VOoxYlxtf9w5zlnmj495YCg8kUGeRiGZO8cpbh50eyI8RvuUxBOvm6U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615995667264338.5518549802838; Wed, 17 Mar 2021 08:41:07 -0700 (PDT) Received: from localhost ([::1]:42560 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lMYIE-0001Vx-GR for importer@patchew.org; Wed, 17 Mar 2021 11:41:06 -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 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 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) 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= X-MC-Unique: EVU27mJ2NH-st2v2t4otCg-1 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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=3D1935061 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 =3D bs->opaque; CURLAIOCB acb =3D { .co =3D qemu_coroutine_self(), .ret =3D -EINPROGRESS, @@ -906,6 +907,15 @@ static int coroutine_fn curl_co_preadv(BlockDriverStat= e *bs, .bytes =3D bytes }; =20 + if (offset > s->len || bytes > s->len - offset) { + uint64_t req_bytes =3D offset > s->len ? 0 : s->len - offset; + qemu_iovec_memset(qiov, req_bytes, 0, bytes - req_bytes); + bytes =3D req_bytes; + } + if (bytes =3D=3D 0) { + return 0; + } + curl_setup_preadv(bs, &acb); while (acb.ret =3D=3D -EINPROGRESS) { qemu_coroutine_yield(); --=20 2.30.2