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] [PATCH v2 qemu 4/4] vma: create: register all streams before entering coroutines
Date: Mon, 14 Feb 2022 12:02:52 +0100	[thread overview]
Message-ID: <20220214110257.160945-1-f.ebner@proxmox.com> (raw)
In-Reply-To: <20220211092435.84731-1-f.ebner@proxmox.com>

Otherwise, the header might already get written by a coroutine and
registering further streams will fail after that.

Also adds a missing g_list_free call for the other GList that's used.

Reported in the community forum:
https://forum.proxmox.com/threads/104744/

Reproducer script (increase beyond 30 if the issue isn't triggered yet):
> #!/usr/bin/perl
>
> my $dir = "./vma-create-bug";
> mkdir $dir;
>
> my $archive_path = "$dir/vzdump-qemu-104-2202_02_02-00_00_00.vma";
> unlink $archive_path;
>
> my $cmd = "vma create $archive_path -v";
> for (my $i = 0; $i < 30; $i++) {
>   system("truncate -s 1M $dir/drive-virtio$i.img");
>   $cmd .= " drive-virtio$i=$dir/drive-virtio$i.img";
> }
> system($cmd);

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

A late addition to v2.

 ...VE-Backup-add-vma-backup-format-code.patch | 24 +++++++++++++++----
 1 file changed, 19 insertions(+), 5 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 d28065e..c4ed5bb 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,14 +4,16 @@ 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]
+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             | 839 +++++++++++++++++++++++++++++++++++++++++++++
+ vma.c             | 851 +++++++++++++++++++++++++++++++++++++++++++++
  vma.h             | 150 ++++++++
- 6 files changed, 2643 insertions(+)
+ 6 files changed, 2655 insertions(+)
  create mode 100644 vma-reader.c
  create mode 100644 vma-writer.c
  create mode 100644 vma.c
@@ -1714,10 +1716,10 @@ index 0000000000..11d8321ffd
 +}
 diff --git a/vma.c b/vma.c
 new file mode 100644
-index 0000000000..2eea2fc281
+index 0000000000..df542b7732
 --- /dev/null
 +++ b/vma.c
-@@ -0,0 +1,839 @@
+@@ -0,0 +1,851 @@
 +/*
 + * VMA: Virtual Machine Archive
 + *
@@ -2293,6 +2295,7 @@ index 0000000000..2eea2fc281
 +    int i, c;
 +    int verbose = 0;
 +    const char *archivename;
++    GList *backup_coroutines = NULL;
 +    GList *config_files = NULL;
 +
 +    for (;;) {
@@ -2381,7 +2384,9 @@ index 0000000000..2eea2fc281
 +        job->dev_id = dev_id;
 +
 +        Coroutine *co = qemu_coroutine_create(backup_run, job);
-+        qemu_coroutine_enter(co);
++        // Don't enter coroutine yet, because it might write the header before
++        // all streams can be registered.
++        backup_coroutines = g_list_append(backup_coroutines, co);
 +    }
 +
 +    VmaStatus vmastat;
@@ -2389,6 +2394,13 @@ index 0000000000..2eea2fc281
 +    int last_percent = -1;
 +
 +    if (devcount) {
++        GList *entry = backup_coroutines;
++        while (entry && entry->data) {
++            Coroutine *co = entry->data;
++            qemu_coroutine_enter(co);
++            entry = g_list_next(entry);
++        }
++
 +        while (1) {
 +            main_loop_wait(false);
 +            vma_writer_get_status(vmaw, &vmastat);
@@ -2453,6 +2465,8 @@ index 0000000000..2eea2fc281
 +        g_error("creating vma archive failed");
 +    }
 +
++    g_list_free(backup_coroutines);
++    g_list_free(config_files);
 +    vma_writer_destroy(vmaw);
 +    return 0;
 +}
-- 
2.30.2





  parent reply	other threads:[~2022-02-14 11:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-11  9:24 [pve-devel] [PATCH v2 qemu 1/3] update submodule and patches to 6.2.0 Fabian Ebner
2022-02-11  9:24 ` [pve-devel] [PATCH v2 qemu 2/3] fix getopt-string when introducing -n option for qemu-img dd Fabian Ebner
2022-02-11  9:24 ` [pve-devel] [PATCH v2 qemu 3/3] add patch for loading a snapshot with " Fabian Ebner
2022-02-14 11:02 ` Fabian Ebner [this message]
2022-02-14 14:51   ` [pve-devel] applied: [PATCH v2 qemu 4/4] vma: create: register all streams before entering coroutines Thomas Lamprecht
2022-02-15 15:08 ` [pve-devel] applied-series: [PATCH v2 qemu 1/3] update submodule and patches to 6.2.0 Thomas Lamprecht

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=20220214110257.160945-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