qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] curl: Allow reading after EOF
@ 2021-03-17 15:17 Kevin Wolf
  2021-03-17 15:32 ` Eric Blake
  2021-03-17 16:12 ` Daniel P. Berrangé
  0 siblings, 2 replies; 7+ messages in thread
From: Kevin Wolf @ 2021-03-17 15:17 UTC (permalink / raw)
  To: qemu-block; +Cc: kwolf, afrosi, qemu-devel, mreitz

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 <afrosi@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---

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();
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-03-17 17:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-17 15:17 [RFC PATCH] curl: Allow reading after EOF Kevin Wolf
2021-03-17 15:32 ` Eric Blake
2021-03-17 15:46   ` Eric Blake
2021-03-17 16:38     ` Kevin Wolf
2021-03-17 16:12 ` Daniel P. Berrangé
2021-03-17 16:43   ` Kevin Wolf
2021-03-17 17:29     ` Eric Blake

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).