public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [RFC qemu] vma: create: support 64KiB-unaligned input images
Date: Wed, 16 Feb 2022 14:17:48 +0100	[thread overview]
Message-ID: <20220216131748.87052-1-f.ebner@proxmox.com> (raw)

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.ebner@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.lamprecht@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.ebner@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





                 reply	other threads:[~2022-02-16 13:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220216131748.87052-1-f.ebner@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=pve-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