[pbs-devel] [PATCH qemu 3/3] PVE: PBS: iterate read_image_at until all data is available
Stefan Reiter
s.reiter at proxmox.com
Mon Jul 20 17:02:20 CEST 2020
Signed-off-by: Stefan Reiter <s.reiter at 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
More information about the pbs-devel
mailing list