public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Reiter <s.reiter@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH qemu 3/3] PVE: PBS: iterate read_image_at until all data is available
Date: Mon, 20 Jul 2020 17:02:20 +0200	[thread overview]
Message-ID: <20200720150220.22996-4-s.reiter@proxmox.com> (raw)
In-Reply-To: <20200720150220.22996-1-s.reiter@proxmox.com>

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
---

Sent as seperate patch for review, but can also be squashed into the PBS bdrv
patch easily.

 block/pbs.c | 31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/block/pbs.c b/block/pbs.c
index 1481a2bfd1..0083406ad9 100644
--- a/block/pbs.c
+++ b/block/pbs.c
@@ -198,7 +198,7 @@ static coroutine_fn int pbs_co_preadv(BlockDriverState *bs,
                                       QEMUIOVector *qiov, int flags)
 {
     BDRVPBSState *s = bs->opaque;
-    int ret;
+    int ret, cur = 0;
     char *pbs_error = NULL;
     uint8_t *buf = malloc(bytes);
 
@@ -207,18 +207,31 @@ static coroutine_fn int pbs_co_preadv(BlockDriverState *bs,
         .ctx = qemu_get_current_aio_context(),
     };
 
-    proxmox_restore_read_image_at_async(s->conn, s->aid, buf, offset, bytes,
-                                        read_callback, (void *) &rcb, &ret, &pbs_error);
+    /* we need to retry until we have either read all requested data or hit the
+     * end of the file - QEMU does not re-call this function in case the
+     * returned value is not equal to 'bytes', it just assumes there is no data
+     * to be read, which breaks unaligned reads */
+    while (cur < bytes) {
+        proxmox_restore_read_image_at_async(s->conn, s->aid, buf + cur, offset + cur, bytes - cur,
+                                            read_callback, (void *) &rcb, &ret, &pbs_error);
+        qemu_coroutine_yield();
 
-    qemu_coroutine_yield();
+        if (ret < 0) {
+            fprintf(stderr, "error during PBS read: %s\n", pbs_error ? pbs_error : "unknown error");
+            if (pbs_error) proxmox_backup_free_error(pbs_error);
+            free(buf);
+            return -EIO;
+        }
 
-    if (ret < 0) {
-        fprintf(stderr, "error during PBS read: %s\n", pbs_error ? pbs_error : "unknown error");
-        if (pbs_error) proxmox_backup_free_error(pbs_error);
-        return -EIO;
+        // EOF
+        if (ret == 0) {
+            break;
+        }
+
+        cur += ret;
     }
 
-    qemu_iovec_from_buf(qiov, 0, buf, bytes);
+    qemu_iovec_from_buf(qiov, 0, buf, cur);
     free(buf);
 
     return ret;
-- 
2.20.1





      parent reply	other threads:[~2020-07-20 15:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-20 15:02 [pbs-devel] [PATCH 0/3] Fix PBS blockdriver for non-VM settings Stefan Reiter
2020-07-20 15:02 ` [pbs-devel] [PATCH backup 1/3] make BufferedFixedReader async Stefan Reiter
2020-07-21  9:37   ` Dominik Csapak
2020-07-20 15:02 ` [pbs-devel] [PATCH backup-qemu 2/3] use new async BufferedFixedReader API Stefan Reiter
2020-07-20 15:02 ` Stefan Reiter [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200720150220.22996-4-s.reiter@proxmox.com \
    --to=s.reiter@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal