From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id E468E64778 for ; Mon, 20 Jul 2020 17:02:27 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E2B47F4E1 for ; Mon, 20 Jul 2020 17:02:27 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 78A9CF4C7 for ; Mon, 20 Jul 2020 17:02:26 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 40CA9431A1 for ; Mon, 20 Jul 2020 17:02:26 +0200 (CEST) From: Stefan Reiter To: pbs-devel@lists.proxmox.com Date: Mon, 20 Jul 2020 17:02:20 +0200 Message-Id: <20200720150220.22996-4-s.reiter@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200720150220.22996-1-s.reiter@proxmox.com> References: <20200720150220.22996-1-s.reiter@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.027 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH qemu 3/3] PVE: PBS: iterate read_image_at until all data is available X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Jul 2020 15:02:27 -0000 Signed-off-by: Stefan Reiter --- 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