which fixes backing up templates with such disks in PVE, for example
efitype=4m EFI disks on a file-based storage (size = 540672).

If there is not enough left to read, blk_co_preadv will return -EIO,
so limit the size in the last iteration.

For writing, an unaligned end is already handled correctly.

The call to memset is not strictly necessary, because writing also
checks that it doesn't write data beyond the end of the image. But
there are two reasons to do it:
1. It's cleaner that way.
2. It allows detecting when the final piece is all zeroes, which might
   not happen if the buffer still contains data from the previous
   iteration.

Signed-off-by: Fabian Ebner <f.eb...@proxmox.com>
---

RFC, because I'm no vma expert :)

 ...VE-Backup-add-vma-backup-format-code.patch | 21 ++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git 
a/debian/patches/pve/0025-PVE-Backup-add-vma-backup-format-code.patch 
b/debian/patches/pve/0025-PVE-Backup-add-vma-backup-format-code.patch
index c4ed5bb..a875253 100644
--- a/debian/patches/pve/0025-PVE-Backup-add-vma-backup-format-code.patch
+++ b/debian/patches/pve/0025-PVE-Backup-add-vma-backup-format-code.patch
@@ -4,16 +4,17 @@ Date: Mon, 6 Apr 2020 12:16:57 +0200
 Subject: [PATCH] PVE-Backup: add vma backup format code
 
 Signed-off-by: Thomas Lamprecht <t.lampre...@proxmox.com>
-[FE: create: register all streams before entering coroutines]
+[FE: create: register all streams before entering coroutines
+     fix reading 64KiB-unalinged images]
 Signed-off-by: Fabian Ebner <f.eb...@proxmox.com>
 ---
  block/meson.build |   2 +
  meson.build       |   5 +
  vma-reader.c      | 857 ++++++++++++++++++++++++++++++++++++++++++++++
  vma-writer.c      | 790 ++++++++++++++++++++++++++++++++++++++++++
- vma.c             | 851 +++++++++++++++++++++++++++++++++++++++++++++
+ vma.c             | 857 ++++++++++++++++++++++++++++++++++++++++++++++
  vma.h             | 150 ++++++++
- 6 files changed, 2655 insertions(+)
+ 6 files changed, 2661 insertions(+)
  create mode 100644 vma-reader.c
  create mode 100644 vma-writer.c
  create mode 100644 vma.c
@@ -1716,10 +1717,10 @@ index 0000000000..11d8321ffd
 +}
 diff --git a/vma.c b/vma.c
 new file mode 100644
-index 0000000000..df542b7732
+index 0000000000..abfcc534b8
 --- /dev/null
 +++ b/vma.c
-@@ -0,0 +1,851 @@
+@@ -0,0 +1,857 @@
 +/*
 + * VMA: Virtual Machine Archive
 + *
@@ -2251,7 +2252,7 @@ index 0000000000..df542b7732
 +    struct iovec iov;
 +    QEMUIOVector qiov;
 +
-+    int64_t start, end;
++    int64_t start, end, readlen;
 +    int ret = 0;
 +
 +    unsigned char *buf = blk_blockalign(job->target, VMA_CLUSTER_SIZE);
@@ -2265,8 +2266,14 @@ index 0000000000..df542b7732
 +        iov.iov_len = VMA_CLUSTER_SIZE;
 +        qemu_iovec_init_external(&qiov, &iov, 1);
 +
++        if (start + 1 == end) {
++            memset(buf, 0, VMA_CLUSTER_SIZE);
++            readlen = job->len - start * VMA_CLUSTER_SIZE;
++        } else {
++            readlen = VMA_CLUSTER_SIZE;
++        }
 +        ret = blk_co_preadv(job->target, start * VMA_CLUSTER_SIZE,
-+                            VMA_CLUSTER_SIZE, &qiov, 0);
++                            readlen, &qiov, 0);
 +        if (ret < 0) {
 +            vma_writer_set_error(job->vmaw, "read error", -1);
 +            goto out;
-- 
2.30.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to