]> git.proxmox.com Git - pve-qemu.git/commitdiff
clean up pve/ patches by squashing patches of patches
authorStefan Reiter <s.reiter@proxmox.com>
Wed, 3 Mar 2021 09:56:02 +0000 (10:56 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 3 Mar 2021 13:29:05 +0000 (14:29 +0100)
No functional change intended.

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
53 files changed:
debian/patches/pve/0028-PVE-Backup-proxmox-backup-patches-for-qemu.patch
debian/patches/pve/0029-PVE-Backup-pbs-restore-new-command-to-restore-from-p.patch
debian/patches/pve/0030-PVE-Backup-avoid-coroutines-to-fix-AIO-freeze-cleanu.patch [deleted file]
debian/patches/pve/0030-drive-mirror-add-support-for-sync-bitmap-mode-never.patch [new file with mode: 0644]
debian/patches/pve/0031-drive-mirror-add-support-for-conditional-and-always-.patch [new file with mode: 0644]
debian/patches/pve/0031-drive-mirror-add-support-for-sync-bitmap-mode-never.patch [deleted file]
debian/patches/pve/0032-drive-mirror-add-support-for-conditional-and-always-.patch [deleted file]
debian/patches/pve/0032-mirror-add-check-for-bitmap-mode-without-bitmap.patch [new file with mode: 0644]
debian/patches/pve/0033-mirror-add-check-for-bitmap-mode-without-bitmap.patch [deleted file]
debian/patches/pve/0033-mirror-switch-to-bdrv_dirty_bitmap_merge_internal.patch [new file with mode: 0644]
debian/patches/pve/0034-iotests-add-test-for-bitmap-mirror.patch [new file with mode: 0644]
debian/patches/pve/0034-mirror-switch-to-bdrv_dirty_bitmap_merge_internal.patch [deleted file]
debian/patches/pve/0035-iotests-add-test-for-bitmap-mirror.patch [deleted file]
debian/patches/pve/0035-mirror-move-some-checks-to-qmp.patch [new file with mode: 0644]
debian/patches/pve/0036-PVE-Backup-Add-dirty-bitmap-tracking-for-incremental.patch [new file with mode: 0644]
debian/patches/pve/0036-mirror-move-some-checks-to-qmp.patch [deleted file]
debian/patches/pve/0037-PVE-Backup-Add-dirty-bitmap-tracking-for-incremental.patch [deleted file]
debian/patches/pve/0037-PVE-various-PBS-fixes.patch [new file with mode: 0644]
debian/patches/pve/0038-PVE-Add-PBS-block-driver-to-map-backup-archives-into.patch [new file with mode: 0644]
debian/patches/pve/0038-PVE-backup-rename-incremental-to-use-dirty-bitmap.patch [deleted file]
debian/patches/pve/0039-PVE-add-query_proxmox_support-QMP-command.patch [new file with mode: 0644]
debian/patches/pve/0039-PVE-fixup-pbs-restore-API.patch [deleted file]
debian/patches/pve/0040-PVE-add-query-pbs-bitmap-info-QMP-call.patch [new file with mode: 0644]
debian/patches/pve/0040-PVE-always-set-dirty-counter-for-non-incremental-bac.patch [deleted file]
debian/patches/pve/0041-PVE-redirect-stderr-to-journal-when-daemonized.patch [new file with mode: 0644]
debian/patches/pve/0041-PVE-use-proxmox_backup_check_incremental.patch [deleted file]
debian/patches/pve/0042-PVE-Add-sequential-job-transaction-support.patch [new file with mode: 0644]
debian/patches/pve/0042-PVE-fixup-pbs-backup-add-compress-and-encrypt-option.patch [deleted file]
debian/patches/pve/0043-PVE-Add-PBS-block-driver-to-map-backup-archives-into.patch [deleted file]
debian/patches/pve/0043-PVE-Backup-Use-a-transaction-to-synchronize-job-stat.patch [new file with mode: 0644]
debian/patches/pve/0044-PVE-Backup-Don-t-block-on-finishing-and-cleanup-crea.patch [new file with mode: 0644]
debian/patches/pve/0044-PVE-add-query_proxmox_support-QMP-command.patch [deleted file]
debian/patches/pve/0045-PVE-Migrate-dirty-bitmap-state-via-savevm.patch [new file with mode: 0644]
debian/patches/pve/0045-pbs-fix-missing-crypt-and-compress-parameters.patch [deleted file]
debian/patches/pve/0046-PVE-handle-PBS-write-callback-with-big-blocks-correc.patch [deleted file]
debian/patches/pve/0046-migration-block-dirty-bitmap-migrate-other-bitmaps-e.patch [new file with mode: 0644]
debian/patches/pve/0047-PVE-add-zero-block-handling-to-PBS-dump-callback.patch [deleted file]
debian/patches/pve/0047-PVE-fall-back-to-open-iscsi-initiatorname.patch [new file with mode: 0644]
debian/patches/pve/0048-PVE-Use-coroutine-QMP-for-backup-cancel_backup.patch [new file with mode: 0644]
debian/patches/pve/0048-PVE-add-query-pbs-bitmap-info-QMP-call.patch [deleted file]
debian/patches/pve/0049-PBS-add-master-key-support.patch [new file with mode: 0644]
debian/patches/pve/0049-PVE-redirect-stderr-to-journal-when-daemonized.patch [deleted file]
debian/patches/pve/0050-PVE-Add-sequential-job-transaction-support.patch [deleted file]
debian/patches/pve/0051-PVE-Backup-Use-a-transaction-to-synchronize-job-stat.patch [deleted file]
debian/patches/pve/0052-PVE-Backup-Use-more-coroutines-and-don-t-block-on-fi.patch [deleted file]
debian/patches/pve/0053-PVE-fix-and-clean-up-error-handling-for-create_backu.patch [deleted file]
debian/patches/pve/0054-PVE-Migrate-dirty-bitmap-state-via-savevm.patch [deleted file]
debian/patches/pve/0055-migration-block-dirty-bitmap-migrate-other-bitmaps-e.patch [deleted file]
debian/patches/pve/0056-PVE-fix-aborting-multiple-CREATED-jobs-in-sequential.patch [deleted file]
debian/patches/pve/0057-PVE-fall-back-to-open-iscsi-initiatorname.patch [deleted file]
debian/patches/pve/0058-PVE-Use-coroutine-QMP-for-backup-cancel_backup.patch [deleted file]
debian/patches/pve/0059-PBS-add-master-key-support.patch [deleted file]
debian/patches/series

index cb8334ee34006851fdf5b7b5c8e5f2586719e785..37bb98a79c246066cc63685b286dca2338bd7c48 100644 (file)
@@ -3,6 +3,9 @@ From: Dietmar Maurer <dietmar@proxmox.com>
 Date: Mon, 6 Apr 2020 12:16:59 +0200
 Subject: [PATCH] PVE-Backup: proxmox backup patches for qemu
 
+Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
+[PVE-Backup: avoid coroutines to fix AIO freeze, cleanups]
+Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
 ---
  block/meson.build              |   5 +
  block/monitor/block-hmp-cmds.c |  33 ++
@@ -15,11 +18,11 @@ Subject: [PATCH] PVE-Backup: proxmox backup patches for qemu
  monitor/hmp-cmds.c             |  44 ++
  proxmox-backup-client.c        | 176 ++++++
  proxmox-backup-client.h        |  59 ++
- pve-backup.c                   | 955 +++++++++++++++++++++++++++++++++
+ pve-backup.c                   | 957 +++++++++++++++++++++++++++++++++
  qapi/block-core.json           | 109 ++++
  qapi/common.json               |  13 +
  qapi/machine.json              |  15 +-
- 15 files changed, 1444 insertions(+), 14 deletions(-)
+ 15 files changed, 1446 insertions(+), 14 deletions(-)
  create mode 100644 proxmox-backup-client.c
  create mode 100644 proxmox-backup-client.h
  create mode 100644 pve-backup.c
@@ -507,10 +510,10 @@ index 0000000000..1dda8b7d8f
 +#endif /* PROXMOX_BACKUP_CLIENT_H */
 diff --git a/pve-backup.c b/pve-backup.c
 new file mode 100644
-index 0000000000..55441eb9d1
+index 0000000000..d40f3f2fd6
 --- /dev/null
 +++ b/pve-backup.c
-@@ -0,0 +1,955 @@
+@@ -0,0 +1,957 @@
 +#include "proxmox-backup-client.h"
 +#include "vma.h"
 +
@@ -524,11 +527,27 @@ index 0000000000..55441eb9d1
 +
 +/* PVE backup state and related function */
 +
++/*
++ * Note: A resume from a qemu_coroutine_yield can happen in a different thread,
++ * so you may not use normal mutexes within coroutines:
++ *
++ * ---bad-example---
++ * qemu_rec_mutex_lock(lock)
++ * ...
++ * qemu_coroutine_yield() // wait for something
++ * // we are now inside a different thread
++ * qemu_rec_mutex_unlock(lock) // Crash - wrong thread!!
++ * ---end-bad-example--
++ *
++ * ==> Always use CoMutext inside coroutines.
++ * ==> Never acquire/release AioContext withing coroutines (because that use QemuRecMutex)
++ *
++ */
 +
 +static struct PVEBackupState {
 +    struct {
-+        // Everithing accessed from qmp command, protected using rwlock
-+        CoRwlock rwlock;
++        // Everithing accessed from qmp_backup_query command is protected using lock
++        QemuMutex lock;
 +        Error *error;
 +        time_t start_time;
 +        time_t end_time;
@@ -538,19 +557,20 @@ index 0000000000..55441eb9d1
 +        size_t total;
 +        size_t transferred;
 +        size_t zero_bytes;
-+        bool cancel;
 +    } stat;
 +    int64_t speed;
 +    VmaWriter *vmaw;
 +    ProxmoxBackupHandle *pbs;
 +    GList *di_list;
-+    CoMutex backup_mutex;
++    QemuMutex backup_mutex;
++    CoMutex dump_callback_mutex;
 +} backup_state;
 +
 +static void pvebackup_init(void)
 +{
-+    qemu_co_rwlock_init(&backup_state.stat.rwlock);
-+    qemu_co_mutex_init(&backup_state.backup_mutex);
++    qemu_mutex_init(&backup_state.stat.lock);
++    qemu_mutex_init(&backup_state.backup_mutex);
++    qemu_co_mutex_init(&backup_state.dump_callback_mutex);
 +}
 +
 +// initialize PVEBackupState at startup
@@ -565,10 +585,54 @@ index 0000000000..55441eb9d1
 +    BlockDriverState *target;
 +} PVEBackupDevInfo;
 +
-+static void pvebackup_co_run_next_job(void);
++static void pvebackup_run_next_job(void);
 +
++static BlockJob *
++lookup_active_block_job(PVEBackupDevInfo *di)
++{
++    if (!di->completed && di->bs) {
++        for (BlockJob *job = block_job_next(NULL); job; job = block_job_next(job)) {
++            if (job->job.driver->job_type != JOB_TYPE_BACKUP) {
++                continue;
++            }
++
++            BackupBlockJob *bjob = container_of(job, BackupBlockJob, common);
++            if (bjob && bjob->source_bs == di->bs) {
++                return job;
++            }
++        }
++    }
++    return NULL;
++}
++
++static void pvebackup_propagate_error(Error *err)
++{
++    qemu_mutex_lock(&backup_state.stat.lock);
++    error_propagate(&backup_state.stat.error, err);
++    qemu_mutex_unlock(&backup_state.stat.lock);
++}
++
++static bool pvebackup_error_or_canceled(void)
++{
++    qemu_mutex_lock(&backup_state.stat.lock);
++    bool error_or_canceled = !!backup_state.stat.error;
++    qemu_mutex_unlock(&backup_state.stat.lock);
++
++    return error_or_canceled;
++}
++
++static void pvebackup_add_transfered_bytes(size_t transferred, size_t zero_bytes)
++{
++    qemu_mutex_lock(&backup_state.stat.lock);
++    backup_state.stat.zero_bytes += zero_bytes;
++    backup_state.stat.transferred += transferred;
++    qemu_mutex_unlock(&backup_state.stat.lock);
++}
++
++// This may get called from multiple coroutines in multiple io-threads
++// Note1: this may get called after job_cancel()
 +static int coroutine_fn
-+pvebackup_co_dump_cb(
++pvebackup_co_dump_pbs_cb(
 +    void *opaque,
 +    uint64_t start,
 +    uint64_t bytes,
@@ -580,137 +644,127 @@ index 0000000000..55441eb9d1
 +    const unsigned char *buf = pbuf;
 +    PVEBackupDevInfo *di = opaque;
 +
-+    qemu_co_rwlock_rdlock(&backup_state.stat.rwlock);
-+    bool cancel = backup_state.stat.cancel;
-+    qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
++    assert(backup_state.pbs);
++
++    Error *local_err = NULL;
++    int pbs_res = -1;
++
++    qemu_co_mutex_lock(&backup_state.dump_callback_mutex);
 +
-+    if (cancel) {
-+        return size; // return success
++    // avoid deadlock if job is cancelled
++    if (pvebackup_error_or_canceled()) {
++        qemu_co_mutex_unlock(&backup_state.dump_callback_mutex);
++        return -1;
 +    }
 +
-+    qemu_co_mutex_lock(&backup_state.backup_mutex);
++    pbs_res = proxmox_backup_co_write_data(backup_state.pbs, di->dev_id, buf, start, size, &local_err);
++    qemu_co_mutex_unlock(&backup_state.dump_callback_mutex);
++
++    if (pbs_res < 0) {
++        pvebackup_propagate_error(local_err);
++        return pbs_res;
++    } else {
++        pvebackup_add_transfered_bytes(size, !buf ? size : 0);
++    }
++
++    return size;
++}
++
++// This may get called from multiple coroutines in multiple io-threads
++static int coroutine_fn
++pvebackup_co_dump_vma_cb(
++    void *opaque,
++    uint64_t start,
++    uint64_t bytes,
++    const void *pbuf)
++{
++    assert(qemu_in_coroutine());
++
++    const uint64_t size = bytes;
++    const unsigned char *buf = pbuf;
++    PVEBackupDevInfo *di = opaque;
 +
 +    int ret = -1;
 +
-+    if (backup_state.vmaw) {
-+        size_t zero_bytes = 0;
-+        uint64_t remaining = size;
-+
-+        uint64_t cluster_num = start / VMA_CLUSTER_SIZE;
-+        if ((cluster_num * VMA_CLUSTER_SIZE) != start) {
-+            qemu_co_rwlock_rdlock(&backup_state.stat.rwlock);
-+            if (!backup_state.stat.error) {
-+                qemu_co_rwlock_upgrade(&backup_state.stat.rwlock);
-+                error_setg(&backup_state.stat.error,
-+                           "got unaligned write inside backup dump "
-+                           "callback (sector %ld)", start);
-+            }
-+            qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
-+            qemu_co_mutex_unlock(&backup_state.backup_mutex);
-+            return -1; // not aligned to cluster size
-+        }
++    assert(backup_state.vmaw);
 +
-+        while (remaining > 0) {
-+            ret = vma_writer_write(backup_state.vmaw, di->dev_id, cluster_num,
-+                                   buf, &zero_bytes);
-+            ++cluster_num;
-+            if (buf) {
-+                buf += VMA_CLUSTER_SIZE;
-+            }
-+            if (ret < 0) {
-+                qemu_co_rwlock_rdlock(&backup_state.stat.rwlock);
-+                if (!backup_state.stat.error) {
-+                    qemu_co_rwlock_upgrade(&backup_state.stat.rwlock);
-+                    vma_writer_error_propagate(backup_state.vmaw, &backup_state.stat.error);
-+                }
-+                qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
++    uint64_t remaining = size;
 +
-+                qemu_co_mutex_unlock(&backup_state.backup_mutex);
-+                return ret;
-+            } else {
-+                qemu_co_rwlock_wrlock(&backup_state.stat.rwlock);
-+                backup_state.stat.zero_bytes += zero_bytes;
-+                if (remaining >= VMA_CLUSTER_SIZE) {
-+                    backup_state.stat.transferred += VMA_CLUSTER_SIZE;
-+                    remaining -= VMA_CLUSTER_SIZE;
-+                } else {
-+                    backup_state.stat.transferred += remaining;
-+                    remaining = 0;
-+                }
-+                qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
-+            }
-+        }
-+    } else if (backup_state.pbs) {
++    uint64_t cluster_num = start / VMA_CLUSTER_SIZE;
++    if ((cluster_num * VMA_CLUSTER_SIZE) != start) {
 +        Error *local_err = NULL;
-+        int pbs_res = -1;
++        error_setg(&local_err,
++                   "got unaligned write inside backup dump "
++                   "callback (sector %ld)", start);
++        pvebackup_propagate_error(local_err);
++        return -1; // not aligned to cluster size
++    }
 +
-+        pbs_res = proxmox_backup_co_write_data(backup_state.pbs, di->dev_id, buf, start, size, &local_err);
++    while (remaining > 0) {
++        qemu_co_mutex_lock(&backup_state.dump_callback_mutex);
++        // avoid deadlock if job is cancelled
++        if (pvebackup_error_or_canceled()) {
++            qemu_co_mutex_unlock(&backup_state.dump_callback_mutex);
++            return -1;
++        }
 +
-+        qemu_co_rwlock_wrlock(&backup_state.stat.rwlock);
++        size_t zero_bytes = 0;
++        ret = vma_writer_write(backup_state.vmaw, di->dev_id, cluster_num, buf, &zero_bytes);
++        qemu_co_mutex_unlock(&backup_state.dump_callback_mutex);
 +
-+        if (pbs_res < 0) {
-+            error_propagate(&backup_state.stat.error, local_err);
-+            qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
-+            qemu_co_mutex_unlock(&backup_state.backup_mutex);
-+            return pbs_res;
++        ++cluster_num;
++        if (buf) {
++            buf += VMA_CLUSTER_SIZE;
++        }
++        if (ret < 0) {
++            Error *local_err = NULL;
++            vma_writer_error_propagate(backup_state.vmaw, &local_err);
++            pvebackup_propagate_error(local_err);
++            return ret;
 +        } else {
-+            if (!buf) {
-+                backup_state.stat.zero_bytes += size;
++            if (remaining >= VMA_CLUSTER_SIZE) {
++                assert(ret == VMA_CLUSTER_SIZE);
++                pvebackup_add_transfered_bytes(VMA_CLUSTER_SIZE, zero_bytes);
++                remaining -= VMA_CLUSTER_SIZE;
++            } else {
++                assert(ret == remaining);
++                pvebackup_add_transfered_bytes(remaining, zero_bytes);
++                remaining = 0;
 +            }
-+            backup_state.stat.transferred += size;
-+        }
-+
-+        qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
-+
-+    } else {
-+        qemu_co_rwlock_wrlock(&backup_state.stat.rwlock);
-+        if (!buf) {
-+            backup_state.stat.zero_bytes += size;
 +        }
-+        backup_state.stat.transferred += size;
-+        qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
 +    }
 +
-+    qemu_co_mutex_unlock(&backup_state.backup_mutex);
-+
 +    return size;
 +}
 +
-+static void coroutine_fn pvebackup_co_cleanup(void)
++// assumes the caller holds backup_mutex
++static void coroutine_fn pvebackup_co_cleanup(void *unused)
 +{
 +    assert(qemu_in_coroutine());
 +
-+    qemu_co_mutex_lock(&backup_state.backup_mutex);
-+
-+    qemu_co_rwlock_wrlock(&backup_state.stat.rwlock);
++    qemu_mutex_lock(&backup_state.stat.lock);
 +    backup_state.stat.end_time = time(NULL);
-+    qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
++    qemu_mutex_unlock(&backup_state.stat.lock);
 +
 +    if (backup_state.vmaw) {
 +        Error *local_err = NULL;
 +        vma_writer_close(backup_state.vmaw, &local_err);
 +
 +        if (local_err != NULL) {
-+            qemu_co_rwlock_wrlock(&backup_state.stat.rwlock);
-+            error_propagate(&backup_state.stat.error, local_err);
-+            qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
-+        }
++            pvebackup_propagate_error(local_err);
++         }
 +
 +        backup_state.vmaw = NULL;
 +    }
 +
 +    if (backup_state.pbs) {
-+        qemu_co_rwlock_rdlock(&backup_state.stat.rwlock);
-+        bool error_or_canceled = backup_state.stat.error || backup_state.stat.cancel;
-+        if (!error_or_canceled) {
++        if (!pvebackup_error_or_canceled()) {
 +            Error *local_err = NULL;
 +            proxmox_backup_co_finish(backup_state.pbs, &local_err);
 +            if (local_err != NULL) {
-+                qemu_co_rwlock_upgrade(&backup_state.stat.rwlock);
-+                error_propagate(&backup_state.stat.error, local_err);
-+             }
++                pvebackup_propagate_error(local_err);
++            }
 +        }
-+        qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
 +
 +        proxmox_backup_disconnect(backup_state.pbs);
 +        backup_state.pbs = NULL;
@@ -718,43 +772,14 @@ index 0000000000..55441eb9d1
 +
 +    g_list_free(backup_state.di_list);
 +    backup_state.di_list = NULL;
-+    qemu_co_mutex_unlock(&backup_state.backup_mutex);
 +}
 +
-+typedef struct PVEBackupCompeteCallbackData {
-+    PVEBackupDevInfo *di;
-+    int result;
-+} PVEBackupCompeteCallbackData;
-+
-+static void coroutine_fn pvebackup_co_complete_cb(void *opaque)
++// assumes the caller holds backup_mutex
++static void coroutine_fn pvebackup_complete_stream(void *opaque)
 +{
-+    assert(qemu_in_coroutine());
-+
-+    PVEBackupCompeteCallbackData *cb_data = opaque;
-+
-+    qemu_co_mutex_lock(&backup_state.backup_mutex);
-+
-+    PVEBackupDevInfo *di = cb_data->di;
-+    int ret = cb_data->result;
-+
-+    di->completed = true;
-+
-+    qemu_co_rwlock_rdlock(&backup_state.stat.rwlock);
-+    bool error_or_canceled = backup_state.stat.error || backup_state.stat.cancel;
-+
-+    if (ret < 0 && !backup_state.stat.error) {
-+        qemu_co_rwlock_upgrade(&backup_state.stat.rwlock);
-+        error_setg(&backup_state.stat.error, "job failed with err %d - %s",
-+                   ret, strerror(-ret));
-+    }
-+    qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
-+
-+    di->bs = NULL;
++    PVEBackupDevInfo *di = opaque;
 +
-+    if (di->target) {
-+        bdrv_unref(di->target);
-+        di->target = NULL;
-+    }
++    bool error_or_canceled = pvebackup_error_or_canceled();
 +
 +    if (backup_state.vmaw) {
 +        vma_writer_close_stream(backup_state.vmaw, di->dev_id);
@@ -764,110 +789,101 @@ index 0000000000..55441eb9d1
 +        Error *local_err = NULL;
 +        proxmox_backup_co_close_image(backup_state.pbs, di->dev_id, &local_err);
 +        if (local_err != NULL) {
-+            qemu_co_rwlock_wrlock(&backup_state.stat.rwlock);
-+            error_propagate(&backup_state.stat.error, local_err);
-+            qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
++            pvebackup_propagate_error(local_err);
 +        }
 +    }
++}
 +
-+    // remove self from job queue
-+    backup_state.di_list = g_list_remove(backup_state.di_list, di);
-+    g_free(di);
++static void pvebackup_complete_cb(void *opaque, int ret)
++{
++    assert(!qemu_in_coroutine());
 +
-+    int pending_jobs = g_list_length(backup_state.di_list);
++    PVEBackupDevInfo *di = opaque;
 +
-+    qemu_co_mutex_unlock(&backup_state.backup_mutex);
++    qemu_mutex_lock(&backup_state.backup_mutex);
 +
-+    if (pending_jobs > 0) {
-+        pvebackup_co_run_next_job();
-+    } else {
-+        pvebackup_co_cleanup();
++    di->completed = true;
++
++    if (ret < 0) {
++        Error *local_err = NULL;
++        error_setg(&local_err, "job failed with err %d - %s", ret, strerror(-ret));
++        pvebackup_propagate_error(local_err);
 +    }
-+}
 +
-+static void pvebackup_complete_cb(void *opaque, int ret)
-+{
-+    // This can be called from the main loop, or from a coroutine
-+    PVEBackupCompeteCallbackData cb_data = {
-+        .di = opaque,
-+        .result = ret,
-+    };
++    di->bs = NULL;
 +
-+    if (qemu_in_coroutine()) {
-+        pvebackup_co_complete_cb(&cb_data);
-+    } else {
-+        block_on_coroutine_fn(pvebackup_co_complete_cb, &cb_data);
-+    }
-+}
++    assert(di->target == NULL);
 +
-+static void coroutine_fn pvebackup_co_cancel(void *opaque)
-+{
-+    assert(qemu_in_coroutine());
++    block_on_coroutine_fn(pvebackup_complete_stream, di);
 +
-+    qemu_co_rwlock_wrlock(&backup_state.stat.rwlock);
-+    backup_state.stat.cancel = true;
-+    qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
++    // remove self from job queue
++    backup_state.di_list = g_list_remove(backup_state.di_list, di);
 +
-+    qemu_co_mutex_lock(&backup_state.backup_mutex);
++    g_free(di);
 +
-+    // Avoid race between block jobs and backup-cancel command:
-+    if (!(backup_state.vmaw || backup_state.pbs)) {
-+        qemu_co_mutex_unlock(&backup_state.backup_mutex);
-+        return;
-+    }
++    qemu_mutex_unlock(&backup_state.backup_mutex);
 +
-+    qemu_co_rwlock_rdlock(&backup_state.stat.rwlock);
-+    if (!backup_state.stat.error) {
-+        qemu_co_rwlock_upgrade(&backup_state.stat.rwlock);
-+        error_setg(&backup_state.stat.error, "backup cancelled");
-+    }
-+    qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
++    pvebackup_run_next_job();
++}
++
++static void pvebackup_cancel(void)
++{
++    assert(!qemu_in_coroutine());
++
++    Error *cancel_err = NULL;
++    error_setg(&cancel_err, "backup canceled");
++    pvebackup_propagate_error(cancel_err);
++
++    qemu_mutex_lock(&backup_state.backup_mutex);
 +
 +    if (backup_state.vmaw) {
 +        /* make sure vma writer does not block anymore */
-+        vma_writer_set_error(backup_state.vmaw, "backup cancelled");
++        vma_writer_set_error(backup_state.vmaw, "backup canceled");
 +    }
 +
 +    if (backup_state.pbs) {
-+        proxmox_backup_abort(backup_state.pbs, "backup cancelled");
++        proxmox_backup_abort(backup_state.pbs, "backup canceled");
 +    }
 +
-+    bool running_jobs = 0;
-+    GList *l = backup_state.di_list;
-+    while (l) {
-+        PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
-+        l = g_list_next(l);
-+        if (!di->completed && di->bs) {
-+            for (BlockJob *job = block_job_next(NULL); job; job = block_job_next(job)) {
-+                if (job->job.driver->job_type != JOB_TYPE_BACKUP) {
-+                    continue;
-+                }
++    qemu_mutex_unlock(&backup_state.backup_mutex);
 +
-+                BackupBlockJob *bjob = container_of(job, BackupBlockJob, common);
-+                if (bjob && bjob->source_bs == di->bs) {
-+                    AioContext *aio_context = job->job.aio_context;
-+                    aio_context_acquire(aio_context);
++    for(;;) {
 +
-+                    if (!di->completed) {
-+                        running_jobs += 1;
-+                        job_cancel(&job->job, false);
-+                    }
-+                    aio_context_release(aio_context);
-+                }
++        BlockJob *next_job = NULL;
++
++        qemu_mutex_lock(&backup_state.backup_mutex);
++
++        GList *l = backup_state.di_list;
++        while (l) {
++            PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
++            l = g_list_next(l);
++
++            BlockJob *job = lookup_active_block_job(di);
++            if (job != NULL) {
++                next_job = job;
++                break;
 +            }
 +        }
-+    }
 +
-+    qemu_co_mutex_unlock(&backup_state.backup_mutex);
++        qemu_mutex_unlock(&backup_state.backup_mutex);
 +
-+    if (running_jobs == 0) pvebackup_co_cleanup(); // else job will call completion handler
++        if (next_job) {
++            AioContext *aio_context = next_job->job.aio_context;
++            aio_context_acquire(aio_context);
++            job_cancel_sync(&next_job->job);
++            aio_context_release(aio_context);
++        } else {
++            break;
++        }
++    }
 +}
 +
 +void qmp_backup_cancel(Error **errp)
 +{
-+    block_on_coroutine_fn(pvebackup_co_cancel, NULL);
++    pvebackup_cancel();
 +}
 +
++// assumes the caller holds backup_mutex
 +static int coroutine_fn pvebackup_co_add_config(
 +    const char *file,
 +    const char *name,
@@ -919,46 +935,97 @@ index 0000000000..55441eb9d1
 +
 +bool job_should_pause(Job *job);
 +
-+static void coroutine_fn pvebackup_co_run_next_job(void)
++static void pvebackup_run_next_job(void)
 +{
-+    assert(qemu_in_coroutine());
++    assert(!qemu_in_coroutine());
 +
-+    qemu_co_mutex_lock(&backup_state.backup_mutex);
++    qemu_mutex_lock(&backup_state.backup_mutex);
 +
 +    GList *l = backup_state.di_list;
 +    while (l) {
 +        PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
 +        l = g_list_next(l);
-+        if (!di->completed && di->bs) {
-+            for (BlockJob *job = block_job_next(NULL); job; job = block_job_next(job)) {
-+                if (job->job.driver->job_type != JOB_TYPE_BACKUP) {
-+                    continue;
-+                }
 +
-+                BackupBlockJob *bjob = container_of(job, BackupBlockJob, common);
-+                if (bjob && bjob->source_bs == di->bs) {
-+                    AioContext *aio_context = job->job.aio_context;
-+                    qemu_co_mutex_unlock(&backup_state.backup_mutex);
-+                    aio_context_acquire(aio_context);
-+
-+                    if (job_should_pause(&job->job)) {
-+                        qemu_co_rwlock_rdlock(&backup_state.stat.rwlock);
-+                        bool error_or_canceled = backup_state.stat.error || backup_state.stat.cancel;
-+                        qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
-+
-+                        if (error_or_canceled) {
-+                            job_cancel(&job->job, false);
-+                        } else {
-+                            job_resume(&job->job);
-+                        }
-+                    }
-+                    aio_context_release(aio_context);
-+                    return;
++        BlockJob *job = lookup_active_block_job(di);
++
++        if (job) {
++            qemu_mutex_unlock(&backup_state.backup_mutex);
++
++            AioContext *aio_context = job->job.aio_context;
++            aio_context_acquire(aio_context);
++
++            if (job_should_pause(&job->job)) {
++                bool error_or_canceled = pvebackup_error_or_canceled();
++                if (error_or_canceled) {
++                    job_cancel_sync(&job->job);
++                } else {
++                    job_resume(&job->job);
 +                }
 +            }
++            aio_context_release(aio_context);
++            return;
 +        }
 +    }
-+    qemu_co_mutex_unlock(&backup_state.backup_mutex);
++
++    block_on_coroutine_fn(pvebackup_co_cleanup, NULL); // no more jobs, run cleanup
++
++    qemu_mutex_unlock(&backup_state.backup_mutex);
++}
++
++static bool create_backup_jobs(void) {
++
++    assert(!qemu_in_coroutine());
++
++    Error *local_err = NULL;
++
++    /* create and start all jobs (paused state) */
++    GList *l =  backup_state.di_list;
++    while (l) {
++        PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
++        l = g_list_next(l);
++
++        assert(di->target != NULL);
++
++        AioContext *aio_context = bdrv_get_aio_context(di->bs);
++        aio_context_acquire(aio_context);
++
++        BlockJob *job = backup_job_create(
++            NULL, di->bs, di->target, backup_state.speed, MIRROR_SYNC_MODE_FULL, NULL,
++            BITMAP_SYNC_MODE_NEVER, false, NULL, BLOCKDEV_ON_ERROR_REPORT, BLOCKDEV_ON_ERROR_REPORT,
++            JOB_DEFAULT, pvebackup_complete_cb, di, 1, NULL, &local_err);
++
++        aio_context_release(aio_context);
++
++        if (!job || local_err != NULL) {
++            Error *create_job_err = NULL;
++            error_setg(&create_job_err, "backup_job_create failed: %s",
++                       local_err ? error_get_pretty(local_err) : "null");
++
++            pvebackup_propagate_error(create_job_err);
++            break;
++        }
++        job_start(&job->job);
++
++        bdrv_unref(di->target);
++        di->target = NULL;
++    }
++
++    bool errors = pvebackup_error_or_canceled();
++
++    if (errors) {
++        l = backup_state.di_list;
++        while (l) {
++            PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
++            l = g_list_next(l);
++
++            if (di->target) {
++                bdrv_unref(di->target);
++                di->target = NULL;
++            }
++        }
++    }
++
++    return errors;
 +}
 +
 +typedef struct QmpBackupTask {
@@ -989,7 +1056,8 @@ index 0000000000..55441eb9d1
 +    UuidInfo *result;
 +} QmpBackupTask;
 +
-+static void coroutine_fn pvebackup_co_start(void *opaque)
++// assumes the caller holds backup_mutex
++static void coroutine_fn pvebackup_co_prepare(void *opaque)
 +{
 +    assert(qemu_in_coroutine());
 +
@@ -1008,16 +1076,12 @@ index 0000000000..55441eb9d1
 +    GList *di_list = NULL;
 +    GList *l;
 +    UuidInfo *uuid_info;
-+    BlockJob *job;
 +
 +    const char *config_name = "qemu-server.conf";
 +    const char *firewall_name = "qemu-server.fw";
 +
-+    qemu_co_mutex_lock(&backup_state.backup_mutex);
-+
 +    if (backup_state.di_list) {
-+        qemu_co_mutex_unlock(&backup_state.backup_mutex);
-+        error_set(task->errp, ERROR_CLASS_GENERIC_ERROR,
++         error_set(task->errp, ERROR_CLASS_GENERIC_ERROR,
 +                  "previous backup not finished");
 +        return;
 +    }
@@ -1140,7 +1204,7 @@ index 0000000000..55441eb9d1
 +            if (dev_id < 0)
 +                goto err;
 +
-+            if (!(di->target = bdrv_backup_dump_create(dump_cb_block_size, di->size, pvebackup_co_dump_cb, di, task->errp))) {
++            if (!(di->target = bdrv_backup_dump_create(dump_cb_block_size, di->size, pvebackup_co_dump_pbs_cb, di, task->errp))) {
 +                goto err;
 +            }
 +
@@ -1161,7 +1225,7 @@ index 0000000000..55441eb9d1
 +            PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
 +            l = g_list_next(l);
 +
-+            if (!(di->target = bdrv_backup_dump_create(VMA_CLUSTER_SIZE, di->size, pvebackup_co_dump_cb, di, task->errp))) {
++            if (!(di->target = bdrv_backup_dump_create(VMA_CLUSTER_SIZE, di->size, pvebackup_co_dump_vma_cb, di, task->errp))) {
 +                goto err;
 +            }
 +
@@ -1226,9 +1290,7 @@ index 0000000000..55441eb9d1
 +    }
 +    /* initialize global backup_state now */
 +
-+    qemu_co_rwlock_wrlock(&backup_state.stat.rwlock);
-+
-+    backup_state.stat.cancel = false;
++    qemu_mutex_lock(&backup_state.stat.lock);
 +
 +    if (backup_state.stat.error) {
 +        error_free(backup_state.stat.error);
@@ -1251,7 +1313,7 @@ index 0000000000..55441eb9d1
 +    backup_state.stat.transferred = 0;
 +    backup_state.stat.zero_bytes = 0;
 +
-+    qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
++    qemu_mutex_unlock(&backup_state.stat.lock);
 +
 +    backup_state.speed = (task->has_speed && task->speed > 0) ? task->speed : 0;
 +
@@ -1260,48 +1322,6 @@ index 0000000000..55441eb9d1
 +
 +    backup_state.di_list = di_list;
 +
-+    /* start all jobs (paused state) */
-+    l = di_list;
-+    while (l) {
-+        PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
-+        l = g_list_next(l);
-+
-+        // make sure target runs in same aoi_context as source
-+        AioContext *aio_context = bdrv_get_aio_context(di->bs);
-+        aio_context_acquire(aio_context);
-+        GSList *ignore = NULL;
-+        bdrv_set_aio_context_ignore(di->target, aio_context, &ignore);
-+        g_slist_free(ignore);
-+        aio_context_release(aio_context);
-+
-+        job = backup_job_create(NULL, di->bs, di->target, backup_state.speed, MIRROR_SYNC_MODE_FULL, NULL,
-+                                BITMAP_SYNC_MODE_NEVER, false, NULL, BLOCKDEV_ON_ERROR_REPORT, BLOCKDEV_ON_ERROR_REPORT,
-+                                JOB_DEFAULT, pvebackup_complete_cb, di, 1, NULL, &local_err);
-+        if (!job || local_err != NULL) {
-+            qemu_co_rwlock_wrlock(&backup_state.stat.rwlock);
-+            error_setg(&backup_state.stat.error, "backup_job_create failed");
-+            qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
-+            break;
-+        }
-+        job_start(&job->job);
-+        if (di->target) {
-+            bdrv_unref(di->target);
-+            di->target = NULL;
-+        }
-+    }
-+
-+    qemu_co_mutex_unlock(&backup_state.backup_mutex);
-+
-+    qemu_co_rwlock_rdlock(&backup_state.stat.rwlock);
-+    bool no_errors = !backup_state.stat.error;
-+    qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
-+
-+    if (no_errors) {
-+        pvebackup_co_run_next_job(); // run one job
-+    } else {
-+        pvebackup_co_cancel(NULL);
-+    }
-+
 +    uuid_info = g_malloc0(sizeof(*uuid_info));
 +    uuid_info->UUID = uuid_str;
 +
@@ -1344,8 +1364,6 @@ index 0000000000..55441eb9d1
 +        rmdir(backup_dir);
 +    }
 +
-+    qemu_co_mutex_unlock(&backup_state.backup_mutex);
-+
 +    task->result = NULL;
 +    return;
 +}
@@ -1389,32 +1407,31 @@ index 0000000000..55441eb9d1
 +        .errp = errp,
 +    };
 +
-+    block_on_coroutine_fn(pvebackup_co_start, &task);
++    qemu_mutex_lock(&backup_state.backup_mutex);
 +
-+    return task.result;
-+}
++    block_on_coroutine_fn(pvebackup_co_prepare, &task);
 +
++    if (*errp == NULL) {
++        create_backup_jobs();
++        qemu_mutex_unlock(&backup_state.backup_mutex);
++        pvebackup_run_next_job();
++    } else {
++        qemu_mutex_unlock(&backup_state.backup_mutex);
++    }
 +
-+typedef struct QmpQueryBackupTask {
-+    Error **errp;
-+    BackupStatus *result;
-+} QmpQueryBackupTask;
++    return task.result;
++}
 +
-+static void coroutine_fn pvebackup_co_query(void *opaque)
++BackupStatus *qmp_query_backup(Error **errp)
 +{
-+    assert(qemu_in_coroutine());
-+
-+    QmpQueryBackupTask *task = opaque;
-+
 +    BackupStatus *info = g_malloc0(sizeof(*info));
 +
-+    qemu_co_rwlock_rdlock(&backup_state.stat.rwlock);
++    qemu_mutex_lock(&backup_state.stat.lock);
 +
 +    if (!backup_state.stat.start_time) {
 +        /* not started, return {} */
-+        task->result = info;
-+        qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
-+        return;
++        qemu_mutex_unlock(&backup_state.stat.lock);
++        return info;
 +    }
 +
 +    info->has_status = true;
@@ -1450,21 +1467,9 @@ index 0000000000..55441eb9d1
 +    info->has_transferred = true;
 +    info->transferred = backup_state.stat.transferred;
 +
-+    task->result = info;
-+
-+    qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
-+}
-+
-+BackupStatus *qmp_query_backup(Error **errp)
-+{
-+    QmpQueryBackupTask task = {
-+        .errp = errp,
-+        .result = NULL,
-+    };
-+
-+    block_on_coroutine_fn(pvebackup_co_query, &task);
++    qemu_mutex_unlock(&backup_state.stat.lock);
 +
-+    return task.result;
++    return info;
 +}
 diff --git a/qapi/block-core.json b/qapi/block-core.json
 index 7957b9867d..be67dc3376 100644
index 2b04e1fc78921e424263f6532b12319935a0e23e..fcdbceaf09c553989987b808851b55216ad097d4 100644 (file)
@@ -7,8 +7,8 @@ Subject: [PATCH] PVE-Backup: pbs-restore - new command to restore from proxmox
 Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
 ---
  meson.build   |   4 +
- pbs-restore.c | 218 ++++++++++++++++++++++++++++++++++++++++++++++++++
- 2 files changed, 222 insertions(+)
+ pbs-restore.c | 224 ++++++++++++++++++++++++++++++++++++++++++++++++++
+ 2 files changed, 228 insertions(+)
  create mode 100644 pbs-restore.c
 
 diff --git a/meson.build b/meson.build
@@ -28,10 +28,10 @@ index 3094f98c47..6f1fafee14 100644
    subdir('contrib/elf2dmp')
 diff --git a/pbs-restore.c b/pbs-restore.c
 new file mode 100644
-index 0000000000..d4daee7e91
+index 0000000000..4d3f925a1b
 --- /dev/null
 +++ b/pbs-restore.c
-@@ -0,0 +1,218 @@
+@@ -0,0 +1,224 @@
 +/*
 + * Qemu image restore helper for Proxmox Backup
 + *
@@ -195,13 +195,19 @@ index 0000000000..d4daee7e91
 +        fprintf(stderr, "connecting to repository '%s'\n", repository);
 +    }
 +    char *pbs_error = NULL;
-+    ProxmoxRestoreHandle *conn = proxmox_restore_connect(
++    ProxmoxRestoreHandle *conn = proxmox_restore_new(
 +        repository, snapshot, password, keyfile, key_password, fingerprint, &pbs_error);
 +    if (conn == NULL) {
 +        fprintf(stderr, "restore failed: %s\n", pbs_error);
 +        return -1;
 +    }
 +
++    int res = proxmox_restore_connect(conn, &pbs_error);
++    if (res < 0 || pbs_error) {
++        fprintf(stderr, "restore failed (connection error): %s\n", pbs_error);
++        return -1;
++    }
++
 +    QDict *options = qdict_new();
 +
 +    if (format) {
@@ -232,7 +238,7 @@ index 0000000000..d4daee7e91
 +        fprintf(stderr, "starting to restore snapshot '%s'\n", snapshot);
 +        fflush(stderr); // ensure we do not get printed after the progress log
 +    }
-+    int res = proxmox_restore_image(
++    res = proxmox_restore_image(
 +        conn,
 +        archive_name,
 +        write_callback,
diff --git a/debian/patches/pve/0030-PVE-Backup-avoid-coroutines-to-fix-AIO-freeze-cleanu.patch b/debian/patches/pve/0030-PVE-Backup-avoid-coroutines-to-fix-AIO-freeze-cleanu.patch
deleted file mode 100644 (file)
index 0d874ce..0000000
+++ /dev/null
@@ -1,914 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: Dietmar Maurer <dietmar@proxmox.com>
-Date: Mon, 6 Apr 2020 12:17:00 +0200
-Subject: [PATCH] PVE-Backup: avoid coroutines to fix AIO freeze, cleanups
-
-We observed various AIO pool loop freezes, so we decided to avoid
-coroutines and restrict ourselfes using similar code as upstream
-(see blockdev.c: do_backup_common).
-
-* avoid coroutine for job related code (causes hangs with iothreads)
-    - We then acquire/release all mutexes outside coroutines now, so we can now
-      correctly use a normal mutex.
-
-* split pvebackup_co_dump_cb into:
-    - pvebackup_co_dump_pbs_cb and
-    - pvebackup_co_dump_pbs_cb
-
-* new helper functions
-    - pvebackup_propagate_error
-    - pvebackup_error_or_canceled
-    - pvebackup_add_transfered_bytes
-
-* avoid cancel flag (not needed)
-
-* simplify backup_cancel logic
-
-There is progress on upstream to support running qmp commands inside
-coroutines, see:
-https://lists.gnu.org/archive/html/qemu-devel/2020-02/msg04852.html
-
-We should consider using that when it is available in upstream qemu.
-
-Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
----
- pve-backup.c | 638 ++++++++++++++++++++++++++-------------------------
- 1 file changed, 320 insertions(+), 318 deletions(-)
-
-diff --git a/pve-backup.c b/pve-backup.c
-index 55441eb9d1..d40f3f2fd6 100644
---- a/pve-backup.c
-+++ b/pve-backup.c
-@@ -11,11 +11,27 @@
- /* PVE backup state and related function */
-+/*
-+ * Note: A resume from a qemu_coroutine_yield can happen in a different thread,
-+ * so you may not use normal mutexes within coroutines:
-+ *
-+ * ---bad-example---
-+ * qemu_rec_mutex_lock(lock)
-+ * ...
-+ * qemu_coroutine_yield() // wait for something
-+ * // we are now inside a different thread
-+ * qemu_rec_mutex_unlock(lock) // Crash - wrong thread!!
-+ * ---end-bad-example--
-+ *
-+ * ==> Always use CoMutext inside coroutines.
-+ * ==> Never acquire/release AioContext withing coroutines (because that use QemuRecMutex)
-+ *
-+ */
- static struct PVEBackupState {
-     struct {
--        // Everithing accessed from qmp command, protected using rwlock
--        CoRwlock rwlock;
-+        // Everithing accessed from qmp_backup_query command is protected using lock
-+        QemuMutex lock;
-         Error *error;
-         time_t start_time;
-         time_t end_time;
-@@ -25,19 +41,20 @@ static struct PVEBackupState {
-         size_t total;
-         size_t transferred;
-         size_t zero_bytes;
--        bool cancel;
-     } stat;
-     int64_t speed;
-     VmaWriter *vmaw;
-     ProxmoxBackupHandle *pbs;
-     GList *di_list;
--    CoMutex backup_mutex;
-+    QemuMutex backup_mutex;
-+    CoMutex dump_callback_mutex;
- } backup_state;
- static void pvebackup_init(void)
- {
--    qemu_co_rwlock_init(&backup_state.stat.rwlock);
--    qemu_co_mutex_init(&backup_state.backup_mutex);
-+    qemu_mutex_init(&backup_state.stat.lock);
-+    qemu_mutex_init(&backup_state.backup_mutex);
-+    qemu_co_mutex_init(&backup_state.dump_callback_mutex);
- }
- // initialize PVEBackupState at startup
-@@ -52,10 +69,54 @@ typedef struct PVEBackupDevInfo {
-     BlockDriverState *target;
- } PVEBackupDevInfo;
--static void pvebackup_co_run_next_job(void);
-+static void pvebackup_run_next_job(void);
-+static BlockJob *
-+lookup_active_block_job(PVEBackupDevInfo *di)
-+{
-+    if (!di->completed && di->bs) {
-+        for (BlockJob *job = block_job_next(NULL); job; job = block_job_next(job)) {
-+            if (job->job.driver->job_type != JOB_TYPE_BACKUP) {
-+                continue;
-+            }
-+
-+            BackupBlockJob *bjob = container_of(job, BackupBlockJob, common);
-+            if (bjob && bjob->source_bs == di->bs) {
-+                return job;
-+            }
-+        }
-+    }
-+    return NULL;
-+}
-+
-+static void pvebackup_propagate_error(Error *err)
-+{
-+    qemu_mutex_lock(&backup_state.stat.lock);
-+    error_propagate(&backup_state.stat.error, err);
-+    qemu_mutex_unlock(&backup_state.stat.lock);
-+}
-+
-+static bool pvebackup_error_or_canceled(void)
-+{
-+    qemu_mutex_lock(&backup_state.stat.lock);
-+    bool error_or_canceled = !!backup_state.stat.error;
-+    qemu_mutex_unlock(&backup_state.stat.lock);
-+
-+    return error_or_canceled;
-+}
-+
-+static void pvebackup_add_transfered_bytes(size_t transferred, size_t zero_bytes)
-+{
-+    qemu_mutex_lock(&backup_state.stat.lock);
-+    backup_state.stat.zero_bytes += zero_bytes;
-+    backup_state.stat.transferred += transferred;
-+    qemu_mutex_unlock(&backup_state.stat.lock);
-+}
-+
-+// This may get called from multiple coroutines in multiple io-threads
-+// Note1: this may get called after job_cancel()
- static int coroutine_fn
--pvebackup_co_dump_cb(
-+pvebackup_co_dump_pbs_cb(
-     void *opaque,
-     uint64_t start,
-     uint64_t bytes,
-@@ -67,137 +128,127 @@ pvebackup_co_dump_cb(
-     const unsigned char *buf = pbuf;
-     PVEBackupDevInfo *di = opaque;
--    qemu_co_rwlock_rdlock(&backup_state.stat.rwlock);
--    bool cancel = backup_state.stat.cancel;
--    qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
-+    assert(backup_state.pbs);
-+
-+    Error *local_err = NULL;
-+    int pbs_res = -1;
-+
-+    qemu_co_mutex_lock(&backup_state.dump_callback_mutex);
--    if (cancel) {
--        return size; // return success
-+    // avoid deadlock if job is cancelled
-+    if (pvebackup_error_or_canceled()) {
-+        qemu_co_mutex_unlock(&backup_state.dump_callback_mutex);
-+        return -1;
-     }
--    qemu_co_mutex_lock(&backup_state.backup_mutex);
-+    pbs_res = proxmox_backup_co_write_data(backup_state.pbs, di->dev_id, buf, start, size, &local_err);
-+    qemu_co_mutex_unlock(&backup_state.dump_callback_mutex);
--    int ret = -1;
-+    if (pbs_res < 0) {
-+        pvebackup_propagate_error(local_err);
-+        return pbs_res;
-+    } else {
-+        pvebackup_add_transfered_bytes(size, !buf ? size : 0);
-+    }
--    if (backup_state.vmaw) {
--        size_t zero_bytes = 0;
--        uint64_t remaining = size;
--
--        uint64_t cluster_num = start / VMA_CLUSTER_SIZE;
--        if ((cluster_num * VMA_CLUSTER_SIZE) != start) {
--            qemu_co_rwlock_rdlock(&backup_state.stat.rwlock);
--            if (!backup_state.stat.error) {
--                qemu_co_rwlock_upgrade(&backup_state.stat.rwlock);
--                error_setg(&backup_state.stat.error,
--                           "got unaligned write inside backup dump "
--                           "callback (sector %ld)", start);
--            }
--            qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
--            qemu_co_mutex_unlock(&backup_state.backup_mutex);
--            return -1; // not aligned to cluster size
--        }
-+    return size;
-+}
--        while (remaining > 0) {
--            ret = vma_writer_write(backup_state.vmaw, di->dev_id, cluster_num,
--                                   buf, &zero_bytes);
--            ++cluster_num;
--            if (buf) {
--                buf += VMA_CLUSTER_SIZE;
--            }
--            if (ret < 0) {
--                qemu_co_rwlock_rdlock(&backup_state.stat.rwlock);
--                if (!backup_state.stat.error) {
--                    qemu_co_rwlock_upgrade(&backup_state.stat.rwlock);
--                    vma_writer_error_propagate(backup_state.vmaw, &backup_state.stat.error);
--                }
--                qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
-+// This may get called from multiple coroutines in multiple io-threads
-+static int coroutine_fn
-+pvebackup_co_dump_vma_cb(
-+    void *opaque,
-+    uint64_t start,
-+    uint64_t bytes,
-+    const void *pbuf)
-+{
-+    assert(qemu_in_coroutine());
--                qemu_co_mutex_unlock(&backup_state.backup_mutex);
--                return ret;
--            } else {
--                qemu_co_rwlock_wrlock(&backup_state.stat.rwlock);
--                backup_state.stat.zero_bytes += zero_bytes;
--                if (remaining >= VMA_CLUSTER_SIZE) {
--                    backup_state.stat.transferred += VMA_CLUSTER_SIZE;
--                    remaining -= VMA_CLUSTER_SIZE;
--                } else {
--                    backup_state.stat.transferred += remaining;
--                    remaining = 0;
--                }
--                qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
--            }
--        }
--    } else if (backup_state.pbs) {
--        Error *local_err = NULL;
--        int pbs_res = -1;
-+    const uint64_t size = bytes;
-+    const unsigned char *buf = pbuf;
-+    PVEBackupDevInfo *di = opaque;
--        pbs_res = proxmox_backup_co_write_data(backup_state.pbs, di->dev_id, buf, start, size, &local_err);
-+    int ret = -1;
--        qemu_co_rwlock_wrlock(&backup_state.stat.rwlock);
-+    assert(backup_state.vmaw);
--        if (pbs_res < 0) {
--            error_propagate(&backup_state.stat.error, local_err);
--            qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
--            qemu_co_mutex_unlock(&backup_state.backup_mutex);
--            return pbs_res;
--        } else {
--            if (!buf) {
--                backup_state.stat.zero_bytes += size;
--            }
--            backup_state.stat.transferred += size;
-+    uint64_t remaining = size;
-+
-+    uint64_t cluster_num = start / VMA_CLUSTER_SIZE;
-+    if ((cluster_num * VMA_CLUSTER_SIZE) != start) {
-+        Error *local_err = NULL;
-+        error_setg(&local_err,
-+                   "got unaligned write inside backup dump "
-+                   "callback (sector %ld)", start);
-+        pvebackup_propagate_error(local_err);
-+        return -1; // not aligned to cluster size
-+    }
-+
-+    while (remaining > 0) {
-+        qemu_co_mutex_lock(&backup_state.dump_callback_mutex);
-+        // avoid deadlock if job is cancelled
-+        if (pvebackup_error_or_canceled()) {
-+            qemu_co_mutex_unlock(&backup_state.dump_callback_mutex);
-+            return -1;
-         }
--        qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
-+        size_t zero_bytes = 0;
-+        ret = vma_writer_write(backup_state.vmaw, di->dev_id, cluster_num, buf, &zero_bytes);
-+        qemu_co_mutex_unlock(&backup_state.dump_callback_mutex);
--    } else {
--        qemu_co_rwlock_wrlock(&backup_state.stat.rwlock);
--        if (!buf) {
--            backup_state.stat.zero_bytes += size;
-+        ++cluster_num;
-+        if (buf) {
-+            buf += VMA_CLUSTER_SIZE;
-+        }
-+        if (ret < 0) {
-+            Error *local_err = NULL;
-+            vma_writer_error_propagate(backup_state.vmaw, &local_err);
-+            pvebackup_propagate_error(local_err);
-+            return ret;
-+        } else {
-+            if (remaining >= VMA_CLUSTER_SIZE) {
-+                assert(ret == VMA_CLUSTER_SIZE);
-+                pvebackup_add_transfered_bytes(VMA_CLUSTER_SIZE, zero_bytes);
-+                remaining -= VMA_CLUSTER_SIZE;
-+            } else {
-+                assert(ret == remaining);
-+                pvebackup_add_transfered_bytes(remaining, zero_bytes);
-+                remaining = 0;
-+            }
-         }
--        backup_state.stat.transferred += size;
--        qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
-     }
--    qemu_co_mutex_unlock(&backup_state.backup_mutex);
--
-     return size;
- }
--static void coroutine_fn pvebackup_co_cleanup(void)
-+// assumes the caller holds backup_mutex
-+static void coroutine_fn pvebackup_co_cleanup(void *unused)
- {
-     assert(qemu_in_coroutine());
--    qemu_co_mutex_lock(&backup_state.backup_mutex);
--
--    qemu_co_rwlock_wrlock(&backup_state.stat.rwlock);
-+    qemu_mutex_lock(&backup_state.stat.lock);
-     backup_state.stat.end_time = time(NULL);
--    qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
-+    qemu_mutex_unlock(&backup_state.stat.lock);
-     if (backup_state.vmaw) {
-         Error *local_err = NULL;
-         vma_writer_close(backup_state.vmaw, &local_err);
-         if (local_err != NULL) {
--            qemu_co_rwlock_wrlock(&backup_state.stat.rwlock);
--            error_propagate(&backup_state.stat.error, local_err);
--            qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
--        }
-+            pvebackup_propagate_error(local_err);
-+         }
-         backup_state.vmaw = NULL;
-     }
-     if (backup_state.pbs) {
--        qemu_co_rwlock_rdlock(&backup_state.stat.rwlock);
--        bool error_or_canceled = backup_state.stat.error || backup_state.stat.cancel;
--        if (!error_or_canceled) {
-+        if (!pvebackup_error_or_canceled()) {
-             Error *local_err = NULL;
-             proxmox_backup_co_finish(backup_state.pbs, &local_err);
-             if (local_err != NULL) {
--                qemu_co_rwlock_upgrade(&backup_state.stat.rwlock);
--                error_propagate(&backup_state.stat.error, local_err);
--             }
-+                pvebackup_propagate_error(local_err);
-+            }
-         }
--        qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
-         proxmox_backup_disconnect(backup_state.pbs);
-         backup_state.pbs = NULL;
-@@ -205,43 +256,14 @@ static void coroutine_fn pvebackup_co_cleanup(void)
-     g_list_free(backup_state.di_list);
-     backup_state.di_list = NULL;
--    qemu_co_mutex_unlock(&backup_state.backup_mutex);
- }
--typedef struct PVEBackupCompeteCallbackData {
--    PVEBackupDevInfo *di;
--    int result;
--} PVEBackupCompeteCallbackData;
--
--static void coroutine_fn pvebackup_co_complete_cb(void *opaque)
-+// assumes the caller holds backup_mutex
-+static void coroutine_fn pvebackup_complete_stream(void *opaque)
- {
--    assert(qemu_in_coroutine());
--
--    PVEBackupCompeteCallbackData *cb_data = opaque;
--
--    qemu_co_mutex_lock(&backup_state.backup_mutex);
--
--    PVEBackupDevInfo *di = cb_data->di;
--    int ret = cb_data->result;
--
--    di->completed = true;
--
--    qemu_co_rwlock_rdlock(&backup_state.stat.rwlock);
--    bool error_or_canceled = backup_state.stat.error || backup_state.stat.cancel;
--
--    if (ret < 0 && !backup_state.stat.error) {
--        qemu_co_rwlock_upgrade(&backup_state.stat.rwlock);
--        error_setg(&backup_state.stat.error, "job failed with err %d - %s",
--                   ret, strerror(-ret));
--    }
--    qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
--
--    di->bs = NULL;
-+    PVEBackupDevInfo *di = opaque;
--    if (di->target) {
--        bdrv_unref(di->target);
--        di->target = NULL;
--    }
-+    bool error_or_canceled = pvebackup_error_or_canceled();
-     if (backup_state.vmaw) {
-         vma_writer_close_stream(backup_state.vmaw, di->dev_id);
-@@ -251,110 +273,101 @@ static void coroutine_fn pvebackup_co_complete_cb(void *opaque)
-         Error *local_err = NULL;
-         proxmox_backup_co_close_image(backup_state.pbs, di->dev_id, &local_err);
-         if (local_err != NULL) {
--            qemu_co_rwlock_wrlock(&backup_state.stat.rwlock);
--            error_propagate(&backup_state.stat.error, local_err);
--            qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
-+            pvebackup_propagate_error(local_err);
-         }
-     }
-+}
--    // remove self from job queue
--    backup_state.di_list = g_list_remove(backup_state.di_list, di);
--    g_free(di);
-+static void pvebackup_complete_cb(void *opaque, int ret)
-+{
-+    assert(!qemu_in_coroutine());
--    int pending_jobs = g_list_length(backup_state.di_list);
-+    PVEBackupDevInfo *di = opaque;
--    qemu_co_mutex_unlock(&backup_state.backup_mutex);
-+    qemu_mutex_lock(&backup_state.backup_mutex);
--    if (pending_jobs > 0) {
--        pvebackup_co_run_next_job();
--    } else {
--        pvebackup_co_cleanup();
-+    di->completed = true;
-+
-+    if (ret < 0) {
-+        Error *local_err = NULL;
-+        error_setg(&local_err, "job failed with err %d - %s", ret, strerror(-ret));
-+        pvebackup_propagate_error(local_err);
-     }
--}
--static void pvebackup_complete_cb(void *opaque, int ret)
--{
--    // This can be called from the main loop, or from a coroutine
--    PVEBackupCompeteCallbackData cb_data = {
--        .di = opaque,
--        .result = ret,
--    };
-+    di->bs = NULL;
--    if (qemu_in_coroutine()) {
--        pvebackup_co_complete_cb(&cb_data);
--    } else {
--        block_on_coroutine_fn(pvebackup_co_complete_cb, &cb_data);
--    }
--}
-+    assert(di->target == NULL);
--static void coroutine_fn pvebackup_co_cancel(void *opaque)
--{
--    assert(qemu_in_coroutine());
-+    block_on_coroutine_fn(pvebackup_complete_stream, di);
--    qemu_co_rwlock_wrlock(&backup_state.stat.rwlock);
--    backup_state.stat.cancel = true;
--    qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
-+    // remove self from job queue
-+    backup_state.di_list = g_list_remove(backup_state.di_list, di);
--    qemu_co_mutex_lock(&backup_state.backup_mutex);
-+    g_free(di);
--    // Avoid race between block jobs and backup-cancel command:
--    if (!(backup_state.vmaw || backup_state.pbs)) {
--        qemu_co_mutex_unlock(&backup_state.backup_mutex);
--        return;
--    }
-+    qemu_mutex_unlock(&backup_state.backup_mutex);
--    qemu_co_rwlock_rdlock(&backup_state.stat.rwlock);
--    if (!backup_state.stat.error) {
--        qemu_co_rwlock_upgrade(&backup_state.stat.rwlock);
--        error_setg(&backup_state.stat.error, "backup cancelled");
--    }
--    qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
-+    pvebackup_run_next_job();
-+}
-+
-+static void pvebackup_cancel(void)
-+{
-+    assert(!qemu_in_coroutine());
-+
-+    Error *cancel_err = NULL;
-+    error_setg(&cancel_err, "backup canceled");
-+    pvebackup_propagate_error(cancel_err);
-+
-+    qemu_mutex_lock(&backup_state.backup_mutex);
-     if (backup_state.vmaw) {
-         /* make sure vma writer does not block anymore */
--        vma_writer_set_error(backup_state.vmaw, "backup cancelled");
-+        vma_writer_set_error(backup_state.vmaw, "backup canceled");
-     }
-     if (backup_state.pbs) {
--        proxmox_backup_abort(backup_state.pbs, "backup cancelled");
-+        proxmox_backup_abort(backup_state.pbs, "backup canceled");
-     }
--    bool running_jobs = 0;
--    GList *l = backup_state.di_list;
--    while (l) {
--        PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
--        l = g_list_next(l);
--        if (!di->completed && di->bs) {
--            for (BlockJob *job = block_job_next(NULL); job; job = block_job_next(job)) {
--                if (job->job.driver->job_type != JOB_TYPE_BACKUP) {
--                    continue;
--                }
-+    qemu_mutex_unlock(&backup_state.backup_mutex);
--                BackupBlockJob *bjob = container_of(job, BackupBlockJob, common);
--                if (bjob && bjob->source_bs == di->bs) {
--                    AioContext *aio_context = job->job.aio_context;
--                    aio_context_acquire(aio_context);
-+    for(;;) {
--                    if (!di->completed) {
--                        running_jobs += 1;
--                        job_cancel(&job->job, false);
--                    }
--                    aio_context_release(aio_context);
--                }
-+        BlockJob *next_job = NULL;
-+
-+        qemu_mutex_lock(&backup_state.backup_mutex);
-+
-+        GList *l = backup_state.di_list;
-+        while (l) {
-+            PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
-+            l = g_list_next(l);
-+
-+            BlockJob *job = lookup_active_block_job(di);
-+            if (job != NULL) {
-+                next_job = job;
-+                break;
-             }
-         }
--    }
--    qemu_co_mutex_unlock(&backup_state.backup_mutex);
-+        qemu_mutex_unlock(&backup_state.backup_mutex);
--    if (running_jobs == 0) pvebackup_co_cleanup(); // else job will call completion handler
-+        if (next_job) {
-+            AioContext *aio_context = next_job->job.aio_context;
-+            aio_context_acquire(aio_context);
-+            job_cancel_sync(&next_job->job);
-+            aio_context_release(aio_context);
-+        } else {
-+            break;
-+        }
-+    }
- }
- void qmp_backup_cancel(Error **errp)
- {
--    block_on_coroutine_fn(pvebackup_co_cancel, NULL);
-+    pvebackup_cancel();
- }
-+// assumes the caller holds backup_mutex
- static int coroutine_fn pvebackup_co_add_config(
-     const char *file,
-     const char *name,
-@@ -406,46 +419,97 @@ static int coroutine_fn pvebackup_co_add_config(
- bool job_should_pause(Job *job);
--static void coroutine_fn pvebackup_co_run_next_job(void)
-+static void pvebackup_run_next_job(void)
- {
--    assert(qemu_in_coroutine());
-+    assert(!qemu_in_coroutine());
--    qemu_co_mutex_lock(&backup_state.backup_mutex);
-+    qemu_mutex_lock(&backup_state.backup_mutex);
-     GList *l = backup_state.di_list;
-     while (l) {
-         PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
-         l = g_list_next(l);
--        if (!di->completed && di->bs) {
--            for (BlockJob *job = block_job_next(NULL); job; job = block_job_next(job)) {
--                if (job->job.driver->job_type != JOB_TYPE_BACKUP) {
--                    continue;
--                }
--                BackupBlockJob *bjob = container_of(job, BackupBlockJob, common);
--                if (bjob && bjob->source_bs == di->bs) {
--                    AioContext *aio_context = job->job.aio_context;
--                    qemu_co_mutex_unlock(&backup_state.backup_mutex);
--                    aio_context_acquire(aio_context);
--
--                    if (job_should_pause(&job->job)) {
--                        qemu_co_rwlock_rdlock(&backup_state.stat.rwlock);
--                        bool error_or_canceled = backup_state.stat.error || backup_state.stat.cancel;
--                        qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
--
--                        if (error_or_canceled) {
--                            job_cancel(&job->job, false);
--                        } else {
--                            job_resume(&job->job);
--                        }
--                    }
--                    aio_context_release(aio_context);
--                    return;
-+        BlockJob *job = lookup_active_block_job(di);
-+
-+        if (job) {
-+            qemu_mutex_unlock(&backup_state.backup_mutex);
-+
-+            AioContext *aio_context = job->job.aio_context;
-+            aio_context_acquire(aio_context);
-+
-+            if (job_should_pause(&job->job)) {
-+                bool error_or_canceled = pvebackup_error_or_canceled();
-+                if (error_or_canceled) {
-+                    job_cancel_sync(&job->job);
-+                } else {
-+                    job_resume(&job->job);
-                 }
-             }
-+            aio_context_release(aio_context);
-+            return;
-+        }
-+    }
-+
-+    block_on_coroutine_fn(pvebackup_co_cleanup, NULL); // no more jobs, run cleanup
-+
-+    qemu_mutex_unlock(&backup_state.backup_mutex);
-+}
-+
-+static bool create_backup_jobs(void) {
-+
-+    assert(!qemu_in_coroutine());
-+
-+    Error *local_err = NULL;
-+
-+    /* create and start all jobs (paused state) */
-+    GList *l =  backup_state.di_list;
-+    while (l) {
-+        PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
-+        l = g_list_next(l);
-+
-+        assert(di->target != NULL);
-+
-+        AioContext *aio_context = bdrv_get_aio_context(di->bs);
-+        aio_context_acquire(aio_context);
-+
-+        BlockJob *job = backup_job_create(
-+            NULL, di->bs, di->target, backup_state.speed, MIRROR_SYNC_MODE_FULL, NULL,
-+            BITMAP_SYNC_MODE_NEVER, false, NULL, BLOCKDEV_ON_ERROR_REPORT, BLOCKDEV_ON_ERROR_REPORT,
-+            JOB_DEFAULT, pvebackup_complete_cb, di, 1, NULL, &local_err);
-+
-+        aio_context_release(aio_context);
-+
-+        if (!job || local_err != NULL) {
-+            Error *create_job_err = NULL;
-+            error_setg(&create_job_err, "backup_job_create failed: %s",
-+                       local_err ? error_get_pretty(local_err) : "null");
-+
-+            pvebackup_propagate_error(create_job_err);
-+            break;
-+        }
-+        job_start(&job->job);
-+
-+        bdrv_unref(di->target);
-+        di->target = NULL;
-+    }
-+
-+    bool errors = pvebackup_error_or_canceled();
-+
-+    if (errors) {
-+        l = backup_state.di_list;
-+        while (l) {
-+            PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
-+            l = g_list_next(l);
-+
-+            if (di->target) {
-+                bdrv_unref(di->target);
-+                di->target = NULL;
-+            }
-         }
-     }
--    qemu_co_mutex_unlock(&backup_state.backup_mutex);
-+
-+    return errors;
- }
- typedef struct QmpBackupTask {
-@@ -476,7 +540,8 @@ typedef struct QmpBackupTask {
-     UuidInfo *result;
- } QmpBackupTask;
--static void coroutine_fn pvebackup_co_start(void *opaque)
-+// assumes the caller holds backup_mutex
-+static void coroutine_fn pvebackup_co_prepare(void *opaque)
- {
-     assert(qemu_in_coroutine());
-@@ -495,16 +560,12 @@ static void coroutine_fn pvebackup_co_start(void *opaque)
-     GList *di_list = NULL;
-     GList *l;
-     UuidInfo *uuid_info;
--    BlockJob *job;
-     const char *config_name = "qemu-server.conf";
-     const char *firewall_name = "qemu-server.fw";
--    qemu_co_mutex_lock(&backup_state.backup_mutex);
--
-     if (backup_state.di_list) {
--        qemu_co_mutex_unlock(&backup_state.backup_mutex);
--        error_set(task->errp, ERROR_CLASS_GENERIC_ERROR,
-+         error_set(task->errp, ERROR_CLASS_GENERIC_ERROR,
-                   "previous backup not finished");
-         return;
-     }
-@@ -627,7 +688,7 @@ static void coroutine_fn pvebackup_co_start(void *opaque)
-             if (dev_id < 0)
-                 goto err;
--            if (!(di->target = bdrv_backup_dump_create(dump_cb_block_size, di->size, pvebackup_co_dump_cb, di, task->errp))) {
-+            if (!(di->target = bdrv_backup_dump_create(dump_cb_block_size, di->size, pvebackup_co_dump_pbs_cb, di, task->errp))) {
-                 goto err;
-             }
-@@ -648,7 +709,7 @@ static void coroutine_fn pvebackup_co_start(void *opaque)
-             PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
-             l = g_list_next(l);
--            if (!(di->target = bdrv_backup_dump_create(VMA_CLUSTER_SIZE, di->size, pvebackup_co_dump_cb, di, task->errp))) {
-+            if (!(di->target = bdrv_backup_dump_create(VMA_CLUSTER_SIZE, di->size, pvebackup_co_dump_vma_cb, di, task->errp))) {
-                 goto err;
-             }
-@@ -713,9 +774,7 @@ static void coroutine_fn pvebackup_co_start(void *opaque)
-     }
-     /* initialize global backup_state now */
--    qemu_co_rwlock_wrlock(&backup_state.stat.rwlock);
--
--    backup_state.stat.cancel = false;
-+    qemu_mutex_lock(&backup_state.stat.lock);
-     if (backup_state.stat.error) {
-         error_free(backup_state.stat.error);
-@@ -738,7 +797,7 @@ static void coroutine_fn pvebackup_co_start(void *opaque)
-     backup_state.stat.transferred = 0;
-     backup_state.stat.zero_bytes = 0;
--    qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
-+    qemu_mutex_unlock(&backup_state.stat.lock);
-     backup_state.speed = (task->has_speed && task->speed > 0) ? task->speed : 0;
-@@ -747,48 +806,6 @@ static void coroutine_fn pvebackup_co_start(void *opaque)
-     backup_state.di_list = di_list;
--    /* start all jobs (paused state) */
--    l = di_list;
--    while (l) {
--        PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
--        l = g_list_next(l);
--
--        // make sure target runs in same aoi_context as source
--        AioContext *aio_context = bdrv_get_aio_context(di->bs);
--        aio_context_acquire(aio_context);
--        GSList *ignore = NULL;
--        bdrv_set_aio_context_ignore(di->target, aio_context, &ignore);
--        g_slist_free(ignore);
--        aio_context_release(aio_context);
--
--        job = backup_job_create(NULL, di->bs, di->target, backup_state.speed, MIRROR_SYNC_MODE_FULL, NULL,
--                                BITMAP_SYNC_MODE_NEVER, false, NULL, BLOCKDEV_ON_ERROR_REPORT, BLOCKDEV_ON_ERROR_REPORT,
--                                JOB_DEFAULT, pvebackup_complete_cb, di, 1, NULL, &local_err);
--        if (!job || local_err != NULL) {
--            qemu_co_rwlock_wrlock(&backup_state.stat.rwlock);
--            error_setg(&backup_state.stat.error, "backup_job_create failed");
--            qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
--            break;
--        }
--        job_start(&job->job);
--        if (di->target) {
--            bdrv_unref(di->target);
--            di->target = NULL;
--        }
--    }
--
--    qemu_co_mutex_unlock(&backup_state.backup_mutex);
--
--    qemu_co_rwlock_rdlock(&backup_state.stat.rwlock);
--    bool no_errors = !backup_state.stat.error;
--    qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
--
--    if (no_errors) {
--        pvebackup_co_run_next_job(); // run one job
--    } else {
--        pvebackup_co_cancel(NULL);
--    }
--
-     uuid_info = g_malloc0(sizeof(*uuid_info));
-     uuid_info->UUID = uuid_str;
-@@ -831,8 +848,6 @@ err:
-         rmdir(backup_dir);
-     }
--    qemu_co_mutex_unlock(&backup_state.backup_mutex);
--
-     task->result = NULL;
-     return;
- }
-@@ -876,32 +891,31 @@ UuidInfo *qmp_backup(
-         .errp = errp,
-     };
--    block_on_coroutine_fn(pvebackup_co_start, &task);
-+    qemu_mutex_lock(&backup_state.backup_mutex);
--    return task.result;
--}
-+    block_on_coroutine_fn(pvebackup_co_prepare, &task);
-+    if (*errp == NULL) {
-+        create_backup_jobs();
-+        qemu_mutex_unlock(&backup_state.backup_mutex);
-+        pvebackup_run_next_job();
-+    } else {
-+        qemu_mutex_unlock(&backup_state.backup_mutex);
-+    }
--typedef struct QmpQueryBackupTask {
--    Error **errp;
--    BackupStatus *result;
--} QmpQueryBackupTask;
-+    return task.result;
-+}
--static void coroutine_fn pvebackup_co_query(void *opaque)
-+BackupStatus *qmp_query_backup(Error **errp)
- {
--    assert(qemu_in_coroutine());
--
--    QmpQueryBackupTask *task = opaque;
--
-     BackupStatus *info = g_malloc0(sizeof(*info));
--    qemu_co_rwlock_rdlock(&backup_state.stat.rwlock);
-+    qemu_mutex_lock(&backup_state.stat.lock);
-     if (!backup_state.stat.start_time) {
-         /* not started, return {} */
--        task->result = info;
--        qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
--        return;
-+        qemu_mutex_unlock(&backup_state.stat.lock);
-+        return info;
-     }
-     info->has_status = true;
-@@ -937,19 +951,7 @@ static void coroutine_fn pvebackup_co_query(void *opaque)
-     info->has_transferred = true;
-     info->transferred = backup_state.stat.transferred;
--    task->result = info;
-+    qemu_mutex_unlock(&backup_state.stat.lock);
--    qemu_co_rwlock_unlock(&backup_state.stat.rwlock);
--}
--
--BackupStatus *qmp_query_backup(Error **errp)
--{
--    QmpQueryBackupTask task = {
--        .errp = errp,
--        .result = NULL,
--    };
--
--    block_on_coroutine_fn(pvebackup_co_query, &task);
--
--    return task.result;
-+    return info;
- }
diff --git a/debian/patches/pve/0030-drive-mirror-add-support-for-sync-bitmap-mode-never.patch b/debian/patches/pve/0030-drive-mirror-add-support-for-sync-bitmap-mode-never.patch
new file mode 100644 (file)
index 0000000..3e324a3
--- /dev/null
@@ -0,0 +1,439 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: John Snow <jsnow@redhat.com>
+Date: Mon, 6 Apr 2020 12:17:03 +0200
+Subject: [PATCH] drive-mirror: add support for sync=bitmap mode=never
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+This patch adds support for the "BITMAP" sync mode to drive-mirror and
+blockdev-mirror. It adds support only for the BitmapSyncMode "never,"
+because it's the simplest mode.
+
+This mode simply uses a user-provided bitmap as an initial copy
+manifest, and then does not clear any bits in the bitmap at the
+conclusion of the operation.
+
+Any new writes dirtied during the operation are copied out, in contrast
+to backup. Note that whether these writes are reflected in the bitmap
+at the conclusion of the operation depends on whether that bitmap is
+actually recording!
+
+This patch was originally based on one by Ma Haocong, but it has since
+been modified pretty heavily.
+
+Suggested-by: Ma Haocong <mahaocong@didichuxing.com>
+Signed-off-by: Ma Haocong <mahaocong@didichuxing.com>
+Signed-off-by: John Snow <jsnow@redhat.com>
+Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
+---
+ block/mirror.c              | 98 ++++++++++++++++++++++++++++++-------
+ blockdev.c                  | 39 +++++++++++++--
+ include/block/block_int.h   |  4 +-
+ qapi/block-core.json        | 29 +++++++++--
+ tests/test-block-iothread.c |  4 +-
+ 5 files changed, 145 insertions(+), 29 deletions(-)
+
+diff --git a/block/mirror.c b/block/mirror.c
+index 8e1ad6eceb..97843992c2 100644
+--- a/block/mirror.c
++++ b/block/mirror.c
+@@ -50,7 +50,7 @@ typedef struct MirrorBlockJob {
+     BlockDriverState *to_replace;
+     /* Used to block operations on the drive-mirror-replace target */
+     Error *replace_blocker;
+-    bool is_none_mode;
++    MirrorSyncMode sync_mode;
+     BlockMirrorBackingMode backing_mode;
+     /* Whether the target image requires explicit zero-initialization */
+     bool zero_target;
+@@ -65,6 +65,8 @@ typedef struct MirrorBlockJob {
+     size_t buf_size;
+     int64_t bdev_length;
+     unsigned long *cow_bitmap;
++    BdrvDirtyBitmap *sync_bitmap;
++    BitmapSyncMode bitmap_mode;
+     BdrvDirtyBitmap *dirty_bitmap;
+     BdrvDirtyBitmapIter *dbi;
+     uint8_t *buf;
+@@ -677,7 +679,8 @@ static int mirror_exit_common(Job *job)
+     bdrv_child_refresh_perms(mirror_top_bs, mirror_top_bs->backing,
+                              &error_abort);
+     if (!abort && s->backing_mode == MIRROR_SOURCE_BACKING_CHAIN) {
+-        BlockDriverState *backing = s->is_none_mode ? src : s->base;
++        BlockDriverState *backing;
++        backing = s->sync_mode == MIRROR_SYNC_MODE_NONE ? src : s->base;
+         BlockDriverState *unfiltered_target = bdrv_skip_filters(target_bs);
+         if (bdrv_cow_bs(unfiltered_target) != backing) {
+@@ -774,6 +777,16 @@ static void mirror_abort(Job *job)
+     assert(ret == 0);
+ }
++/* Always called after commit/abort. */
++static void mirror_clean(Job *job)
++{
++    MirrorBlockJob *s = container_of(job, MirrorBlockJob, common.job);
++
++    if (s->sync_bitmap) {
++        bdrv_dirty_bitmap_set_busy(s->sync_bitmap, false);
++    }
++}
++
+ static void coroutine_fn mirror_throttle(MirrorBlockJob *s)
+ {
+     int64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
+@@ -955,7 +968,8 @@ static int coroutine_fn mirror_run(Job *job, Error **errp)
+     mirror_free_init(s);
+     s->last_pause_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
+-    if (!s->is_none_mode) {
++    if ((s->sync_mode == MIRROR_SYNC_MODE_TOP) ||
++        (s->sync_mode == MIRROR_SYNC_MODE_FULL)) {
+         ret = mirror_dirty_init(s);
+         if (ret < 0 || job_is_cancelled(&s->common.job)) {
+             goto immediate_exit;
+@@ -1188,6 +1202,7 @@ static const BlockJobDriver mirror_job_driver = {
+         .run                    = mirror_run,
+         .prepare                = mirror_prepare,
+         .abort                  = mirror_abort,
++        .clean                  = mirror_clean,
+         .pause                  = mirror_pause,
+         .complete               = mirror_complete,
+     },
+@@ -1203,6 +1218,7 @@ static const BlockJobDriver commit_active_job_driver = {
+         .run                    = mirror_run,
+         .prepare                = mirror_prepare,
+         .abort                  = mirror_abort,
++        .clean                  = mirror_clean,
+         .pause                  = mirror_pause,
+         .complete               = mirror_complete,
+     },
+@@ -1550,7 +1566,10 @@ static BlockJob *mirror_start_job(
+                              BlockCompletionFunc *cb,
+                              void *opaque,
+                              const BlockJobDriver *driver,
+-                             bool is_none_mode, BlockDriverState *base,
++                             MirrorSyncMode sync_mode,
++                             BdrvDirtyBitmap *bitmap,
++                             BitmapSyncMode bitmap_mode,
++                             BlockDriverState *base,
+                              bool auto_complete, const char *filter_node_name,
+                              bool is_mirror, MirrorCopyMode copy_mode,
+                              Error **errp)
+@@ -1563,10 +1582,39 @@ static BlockJob *mirror_start_job(
+     Error *local_err = NULL;
+     int ret;
+-    if (granularity == 0) {
+-        granularity = bdrv_get_default_bitmap_granularity(target);
++    if (sync_mode == MIRROR_SYNC_MODE_INCREMENTAL) {
++        error_setg(errp, "Sync mode '%s' not supported",
++                   MirrorSyncMode_str(sync_mode));
++        return NULL;
++    } else if (sync_mode == MIRROR_SYNC_MODE_BITMAP) {
++        if (!bitmap) {
++            error_setg(errp, "Must provide a valid bitmap name for '%s'"
++                       " sync mode",
++                       MirrorSyncMode_str(sync_mode));
++            return NULL;
++        } else if (bitmap_mode != BITMAP_SYNC_MODE_NEVER) {
++            error_setg(errp,
++                       "Bitmap Sync Mode '%s' is not supported by Mirror",
++                       BitmapSyncMode_str(bitmap_mode));
++        }
++    } else if (bitmap) {
++        error_setg(errp,
++                   "sync mode '%s' is not compatible with bitmaps",
++                   MirrorSyncMode_str(sync_mode));
++        return NULL;
+     }
++    if (bitmap) {
++        if (granularity) {
++            error_setg(errp, "granularity (%d)"
++                       "cannot be specified when a bitmap is provided",
++                       granularity);
++            return NULL;
++        }
++        granularity = bdrv_dirty_bitmap_granularity(bitmap);
++    } else if (granularity == 0) {
++        granularity = bdrv_get_default_bitmap_granularity(target);
++    }
+     assert(is_power_of_2(granularity));
+     if (buf_size < 0) {
+@@ -1705,7 +1753,9 @@ static BlockJob *mirror_start_job(
+     s->replaces = g_strdup(replaces);
+     s->on_source_error = on_source_error;
+     s->on_target_error = on_target_error;
+-    s->is_none_mode = is_none_mode;
++    s->sync_mode = sync_mode;
++    s->sync_bitmap = bitmap;
++    s->bitmap_mode = bitmap_mode;
+     s->backing_mode = backing_mode;
+     s->zero_target = zero_target;
+     s->copy_mode = copy_mode;
+@@ -1726,6 +1776,18 @@ static BlockJob *mirror_start_job(
+         bdrv_disable_dirty_bitmap(s->dirty_bitmap);
+     }
++    if (s->sync_bitmap) {
++        bdrv_dirty_bitmap_set_busy(s->sync_bitmap, true);
++    }
++
++    if (s->sync_mode == MIRROR_SYNC_MODE_BITMAP) {
++        bdrv_merge_dirty_bitmap(s->dirty_bitmap, s->sync_bitmap,
++                                NULL, &local_err);
++        if (local_err) {
++            goto fail;
++        }
++    }
++
+     ret = block_job_add_bdrv(&s->common, "source", bs, 0,
+                              BLK_PERM_WRITE_UNCHANGED | BLK_PERM_WRITE |
+                              BLK_PERM_CONSISTENT_READ,
+@@ -1803,6 +1865,9 @@ fail:
+         if (s->dirty_bitmap) {
+             bdrv_release_dirty_bitmap(s->dirty_bitmap);
+         }
++        if (s->sync_bitmap) {
++            bdrv_dirty_bitmap_set_busy(s->sync_bitmap, false);
++        }
+         job_early_fail(&s->common.job);
+     }
+@@ -1820,29 +1885,23 @@ void mirror_start(const char *job_id, BlockDriverState *bs,
+                   BlockDriverState *target, const char *replaces,
+                   int creation_flags, int64_t speed,
+                   uint32_t granularity, int64_t buf_size,
+-                  MirrorSyncMode mode, BlockMirrorBackingMode backing_mode,
++                  MirrorSyncMode mode, BdrvDirtyBitmap *bitmap,
++                  BitmapSyncMode bitmap_mode,
++                  BlockMirrorBackingMode backing_mode,
+                   bool zero_target,
+                   BlockdevOnError on_source_error,
+                   BlockdevOnError on_target_error,
+                   bool unmap, const char *filter_node_name,
+                   MirrorCopyMode copy_mode, Error **errp)
+ {
+-    bool is_none_mode;
+     BlockDriverState *base;
+-    if ((mode == MIRROR_SYNC_MODE_INCREMENTAL) ||
+-        (mode == MIRROR_SYNC_MODE_BITMAP)) {
+-        error_setg(errp, "Sync mode '%s' not supported",
+-                   MirrorSyncMode_str(mode));
+-        return;
+-    }
+-    is_none_mode = mode == MIRROR_SYNC_MODE_NONE;
+     base = mode == MIRROR_SYNC_MODE_TOP ? bdrv_backing_chain_next(bs) : NULL;
+     mirror_start_job(job_id, bs, creation_flags, target, replaces,
+                      speed, granularity, buf_size, backing_mode, zero_target,
+                      on_source_error, on_target_error, unmap, NULL, NULL,
+-                     &mirror_job_driver, is_none_mode, base, false,
+-                     filter_node_name, true, copy_mode, errp);
++                     &mirror_job_driver, mode, bitmap, bitmap_mode, base,
++                     false, filter_node_name, true, copy_mode, errp);
+ }
+ BlockJob *commit_active_start(const char *job_id, BlockDriverState *bs,
+@@ -1868,7 +1927,8 @@ BlockJob *commit_active_start(const char *job_id, BlockDriverState *bs,
+                      job_id, bs, creation_flags, base, NULL, speed, 0, 0,
+                      MIRROR_LEAVE_BACKING_CHAIN, false,
+                      on_error, on_error, true, cb, opaque,
+-                     &commit_active_job_driver, false, base, auto_complete,
++                     &commit_active_job_driver, MIRROR_SYNC_MODE_FULL,
++                     NULL, 0, base, auto_complete,
+                      filter_node_name, false, MIRROR_COPY_MODE_BACKGROUND,
+                      &local_err);
+     if (local_err) {
+diff --git a/blockdev.c b/blockdev.c
+index bae80b9177..c79e081f57 100644
+--- a/blockdev.c
++++ b/blockdev.c
+@@ -2931,6 +2931,10 @@ static void blockdev_mirror_common(const char *job_id, BlockDriverState *bs,
+                                    BlockDriverState *target,
+                                    bool has_replaces, const char *replaces,
+                                    enum MirrorSyncMode sync,
++                                   bool has_bitmap,
++                                   const char *bitmap_name,
++                                   bool has_bitmap_mode,
++                                   BitmapSyncMode bitmap_mode,
+                                    BlockMirrorBackingMode backing_mode,
+                                    bool zero_target,
+                                    bool has_speed, int64_t speed,
+@@ -2950,6 +2954,7 @@ static void blockdev_mirror_common(const char *job_id, BlockDriverState *bs,
+ {
+     BlockDriverState *unfiltered_bs;
+     int job_flags = JOB_DEFAULT;
++    BdrvDirtyBitmap *bitmap = NULL;
+     if (!has_speed) {
+         speed = 0;
+@@ -3004,6 +3009,29 @@ static void blockdev_mirror_common(const char *job_id, BlockDriverState *bs,
+         sync = MIRROR_SYNC_MODE_FULL;
+     }
++    if (has_bitmap) {
++        if (granularity) {
++            error_setg(errp, "Granularity and bitmap cannot both be set");
++            return;
++        }
++
++        if (!has_bitmap_mode) {
++            error_setg(errp, "bitmap-mode must be specified if"
++                       " a bitmap is provided");
++            return;
++        }
++
++        bitmap = bdrv_find_dirty_bitmap(bs, bitmap_name);
++        if (!bitmap) {
++            error_setg(errp, "Dirty bitmap '%s' not found", bitmap_name);
++            return;
++        }
++
++        if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_ALLOW_RO, errp)) {
++            return;
++        }
++    }
++
+     if (!has_replaces) {
+         /* We want to mirror from @bs, but keep implicit filters on top */
+         unfiltered_bs = bdrv_skip_implicit_filters(bs);
+@@ -3050,8 +3078,8 @@ static void blockdev_mirror_common(const char *job_id, BlockDriverState *bs,
+      * and will allow to check whether the node still exist at mirror completion
+      */
+     mirror_start(job_id, bs, target,
+-                 has_replaces ? replaces : NULL, job_flags,
+-                 speed, granularity, buf_size, sync, backing_mode, zero_target,
++                 has_replaces ? replaces : NULL, job_flags, speed, granularity,
++                 buf_size, sync, bitmap, bitmap_mode, backing_mode, zero_target,
+                  on_source_error, on_target_error, unmap, filter_node_name,
+                  copy_mode, errp);
+ }
+@@ -3196,6 +3224,8 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp)
+     blockdev_mirror_common(arg->has_job_id ? arg->job_id : NULL, bs, target_bs,
+                            arg->has_replaces, arg->replaces, arg->sync,
++                           arg->has_bitmap, arg->bitmap,
++                           arg->has_bitmap_mode, arg->bitmap_mode,
+                            backing_mode, zero_target,
+                            arg->has_speed, arg->speed,
+                            arg->has_granularity, arg->granularity,
+@@ -3217,6 +3247,8 @@ void qmp_blockdev_mirror(bool has_job_id, const char *job_id,
+                          const char *device, const char *target,
+                          bool has_replaces, const char *replaces,
+                          MirrorSyncMode sync,
++                         bool has_bitmap, const char *bitmap,
++                         bool has_bitmap_mode, BitmapSyncMode bitmap_mode,
+                          bool has_speed, int64_t speed,
+                          bool has_granularity, uint32_t granularity,
+                          bool has_buf_size, int64_t buf_size,
+@@ -3266,7 +3298,8 @@ void qmp_blockdev_mirror(bool has_job_id, const char *job_id,
+     }
+     blockdev_mirror_common(has_job_id ? job_id : NULL, bs, target_bs,
+-                           has_replaces, replaces, sync, backing_mode,
++                           has_replaces, replaces, sync, has_bitmap,
++                           bitmap, has_bitmap_mode, bitmap_mode, backing_mode,
+                            zero_target, has_speed, speed,
+                            has_granularity, granularity,
+                            has_buf_size, buf_size,
+diff --git a/include/block/block_int.h b/include/block/block_int.h
+index 9fa282ff54..1bd4b64522 100644
+--- a/include/block/block_int.h
++++ b/include/block/block_int.h
+@@ -1260,7 +1260,9 @@ void mirror_start(const char *job_id, BlockDriverState *bs,
+                   BlockDriverState *target, const char *replaces,
+                   int creation_flags, int64_t speed,
+                   uint32_t granularity, int64_t buf_size,
+-                  MirrorSyncMode mode, BlockMirrorBackingMode backing_mode,
++                  MirrorSyncMode mode, BdrvDirtyBitmap *bitmap,
++                  BitmapSyncMode bitmap_mode,
++                  BlockMirrorBackingMode backing_mode,
+                   bool zero_target,
+                   BlockdevOnError on_source_error,
+                   BlockdevOnError on_target_error,
+diff --git a/qapi/block-core.json b/qapi/block-core.json
+index be67dc3376..9054db608c 100644
+--- a/qapi/block-core.json
++++ b/qapi/block-core.json
+@@ -2080,10 +2080,19 @@
+ #        (all the disk, only the sectors allocated in the topmost image, or
+ #        only new I/O).
+ #
++# @bitmap: The name of a bitmap to use for sync=bitmap mode. This argument must
++#          be present for bitmap mode and absent otherwise. The bitmap's
++#          granularity is used instead of @granularity (since 4.1).
++#
++# @bitmap-mode: Specifies the type of data the bitmap should contain after
++#               the operation concludes. Must be present if sync is "bitmap".
++#               Must NOT be present otherwise. (Since 4.1)
++#
+ # @granularity: granularity of the dirty bitmap, default is 64K
+ #               if the image format doesn't have clusters, 4K if the clusters
+ #               are smaller than that, else the cluster size.  Must be a
+-#               power of 2 between 512 and 64M (since 1.4).
++#               power of 2 between 512 and 64M. Must not be specified if
++#               @bitmap is present (since 1.4).
+ #
+ # @buf-size: maximum amount of data in flight from source to
+ #            target (since 1.4).
+@@ -2121,7 +2130,9 @@
+ { 'struct': 'DriveMirror',
+   'data': { '*job-id': 'str', 'device': 'str', 'target': 'str',
+             '*format': 'str', '*node-name': 'str', '*replaces': 'str',
+-            'sync': 'MirrorSyncMode', '*mode': 'NewImageMode',
++            'sync': 'MirrorSyncMode', '*bitmap': 'str',
++            '*bitmap-mode': 'BitmapSyncMode',
++            '*mode': 'NewImageMode',
+             '*speed': 'int', '*granularity': 'uint32',
+             '*buf-size': 'int', '*on-source-error': 'BlockdevOnError',
+             '*on-target-error': 'BlockdevOnError',
+@@ -2389,10 +2400,19 @@
+ #        (all the disk, only the sectors allocated in the topmost image, or
+ #        only new I/O).
+ #
++# @bitmap: The name of a bitmap to use for sync=bitmap mode. This argument must
++#          be present for bitmap mode and absent otherwise. The bitmap's
++#          granularity is used instead of @granularity (since 4.1).
++#
++# @bitmap-mode: Specifies the type of data the bitmap should contain after
++#               the operation concludes. Must be present if sync is "bitmap".
++#               Must NOT be present otherwise. (Since 4.1)
++#
+ # @granularity: granularity of the dirty bitmap, default is 64K
+ #               if the image format doesn't have clusters, 4K if the clusters
+ #               are smaller than that, else the cluster size.  Must be a
+-#               power of 2 between 512 and 64M
++#               power of 2 between 512 and 64M . Must not be specified if
++#               @bitmap is present.
+ #
+ # @buf-size: maximum amount of data in flight from source to
+ #            target
+@@ -2441,7 +2461,8 @@
+ { 'command': 'blockdev-mirror',
+   'data': { '*job-id': 'str', 'device': 'str', 'target': 'str',
+             '*replaces': 'str',
+-            'sync': 'MirrorSyncMode',
++            'sync': 'MirrorSyncMode', '*bitmap': 'str',
++            '*bitmap-mode': 'BitmapSyncMode',
+             '*speed': 'int', '*granularity': 'uint32',
+             '*buf-size': 'int', '*on-source-error': 'BlockdevOnError',
+             '*on-target-error': 'BlockdevOnError',
+diff --git a/tests/test-block-iothread.c b/tests/test-block-iothread.c
+index 3f866a35c6..500ede71c8 100644
+--- a/tests/test-block-iothread.c
++++ b/tests/test-block-iothread.c
+@@ -623,8 +623,8 @@ static void test_propagate_mirror(void)
+     /* Start a mirror job */
+     mirror_start("job0", src, target, NULL, JOB_DEFAULT, 0, 0, 0,
+-                 MIRROR_SYNC_MODE_NONE, MIRROR_OPEN_BACKING_CHAIN, false,
+-                 BLOCKDEV_ON_ERROR_REPORT, BLOCKDEV_ON_ERROR_REPORT,
++                 MIRROR_SYNC_MODE_NONE, NULL, 0, MIRROR_OPEN_BACKING_CHAIN,
++                 false, BLOCKDEV_ON_ERROR_REPORT, BLOCKDEV_ON_ERROR_REPORT,
+                  false, "filter_node", MIRROR_COPY_MODE_BACKGROUND,
+                  &error_abort);
+     job = job_get("job0");
diff --git a/debian/patches/pve/0031-drive-mirror-add-support-for-conditional-and-always-.patch b/debian/patches/pve/0031-drive-mirror-add-support-for-conditional-and-always-.patch
new file mode 100644 (file)
index 0000000..5a87360
--- /dev/null
@@ -0,0 +1,80 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: John Snow <jsnow@redhat.com>
+Date: Mon, 6 Apr 2020 12:17:04 +0200
+Subject: [PATCH] drive-mirror: add support for conditional and always bitmap
+ sync modes
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Teach mirror two new tricks for using bitmaps:
+
+Always: no matter what, we synchronize the copy_bitmap back to the
+sync_bitmap. In effect, this allows us resume a failed mirror at a later
+date.
+
+Conditional: On success only, we sync the bitmap. This is akin to
+incremental backup modes; we can use this bitmap to later refresh a
+successfully created mirror.
+
+Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
+---
+ block/mirror.c | 24 ++++++++++++++++++------
+ 1 file changed, 18 insertions(+), 6 deletions(-)
+
+diff --git a/block/mirror.c b/block/mirror.c
+index 97843992c2..d1cce079da 100644
+--- a/block/mirror.c
++++ b/block/mirror.c
+@@ -654,8 +654,6 @@ static int mirror_exit_common(Job *job)
+         bdrv_unfreeze_backing_chain(mirror_top_bs, target_bs);
+     }
+-    bdrv_release_dirty_bitmap(s->dirty_bitmap);
+-
+     /* Make sure that the source BDS doesn't go away during bdrv_replace_node,
+      * before we can call bdrv_drained_end */
+     bdrv_ref(src);
+@@ -755,6 +753,18 @@ static int mirror_exit_common(Job *job)
+     blk_set_perm(bjob->blk, 0, BLK_PERM_ALL, &error_abort);
+     blk_insert_bs(bjob->blk, mirror_top_bs, &error_abort);
++    if (s->sync_bitmap) {
++        if (s->bitmap_mode == BITMAP_SYNC_MODE_ALWAYS ||
++            (s->bitmap_mode == BITMAP_SYNC_MODE_ON_SUCCESS &&
++             job->ret == 0 && ret == 0)) {
++            /* Success; synchronize copy back to sync. */
++            bdrv_clear_dirty_bitmap(s->sync_bitmap, NULL);
++            bdrv_merge_dirty_bitmap(s->sync_bitmap, s->dirty_bitmap,
++                                    NULL, &error_abort);
++        }
++    }
++    bdrv_release_dirty_bitmap(s->dirty_bitmap);
++
+     bs_opaque->job = NULL;
+     bdrv_drained_end(src);
+@@ -1592,10 +1602,6 @@ static BlockJob *mirror_start_job(
+                        " sync mode",
+                        MirrorSyncMode_str(sync_mode));
+             return NULL;
+-        } else if (bitmap_mode != BITMAP_SYNC_MODE_NEVER) {
+-            error_setg(errp,
+-                       "Bitmap Sync Mode '%s' is not supported by Mirror",
+-                       BitmapSyncMode_str(bitmap_mode));
+         }
+     } else if (bitmap) {
+         error_setg(errp,
+@@ -1612,6 +1618,12 @@ static BlockJob *mirror_start_job(
+             return NULL;
+         }
+         granularity = bdrv_dirty_bitmap_granularity(bitmap);
++
++        if (bitmap_mode != BITMAP_SYNC_MODE_NEVER) {
++            if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_DEFAULT, errp)) {
++                return NULL;
++            }
++        }
+     } else if (granularity == 0) {
+         granularity = bdrv_get_default_bitmap_granularity(target);
+     }
diff --git a/debian/patches/pve/0031-drive-mirror-add-support-for-sync-bitmap-mode-never.patch b/debian/patches/pve/0031-drive-mirror-add-support-for-sync-bitmap-mode-never.patch
deleted file mode 100644 (file)
index 3e324a3..0000000
+++ /dev/null
@@ -1,439 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: John Snow <jsnow@redhat.com>
-Date: Mon, 6 Apr 2020 12:17:03 +0200
-Subject: [PATCH] drive-mirror: add support for sync=bitmap mode=never
-MIME-Version: 1.0
-Content-Type: text/plain; charset=UTF-8
-Content-Transfer-Encoding: 8bit
-
-This patch adds support for the "BITMAP" sync mode to drive-mirror and
-blockdev-mirror. It adds support only for the BitmapSyncMode "never,"
-because it's the simplest mode.
-
-This mode simply uses a user-provided bitmap as an initial copy
-manifest, and then does not clear any bits in the bitmap at the
-conclusion of the operation.
-
-Any new writes dirtied during the operation are copied out, in contrast
-to backup. Note that whether these writes are reflected in the bitmap
-at the conclusion of the operation depends on whether that bitmap is
-actually recording!
-
-This patch was originally based on one by Ma Haocong, but it has since
-been modified pretty heavily.
-
-Suggested-by: Ma Haocong <mahaocong@didichuxing.com>
-Signed-off-by: Ma Haocong <mahaocong@didichuxing.com>
-Signed-off-by: John Snow <jsnow@redhat.com>
-Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
----
- block/mirror.c              | 98 ++++++++++++++++++++++++++++++-------
- blockdev.c                  | 39 +++++++++++++--
- include/block/block_int.h   |  4 +-
- qapi/block-core.json        | 29 +++++++++--
- tests/test-block-iothread.c |  4 +-
- 5 files changed, 145 insertions(+), 29 deletions(-)
-
-diff --git a/block/mirror.c b/block/mirror.c
-index 8e1ad6eceb..97843992c2 100644
---- a/block/mirror.c
-+++ b/block/mirror.c
-@@ -50,7 +50,7 @@ typedef struct MirrorBlockJob {
-     BlockDriverState *to_replace;
-     /* Used to block operations on the drive-mirror-replace target */
-     Error *replace_blocker;
--    bool is_none_mode;
-+    MirrorSyncMode sync_mode;
-     BlockMirrorBackingMode backing_mode;
-     /* Whether the target image requires explicit zero-initialization */
-     bool zero_target;
-@@ -65,6 +65,8 @@ typedef struct MirrorBlockJob {
-     size_t buf_size;
-     int64_t bdev_length;
-     unsigned long *cow_bitmap;
-+    BdrvDirtyBitmap *sync_bitmap;
-+    BitmapSyncMode bitmap_mode;
-     BdrvDirtyBitmap *dirty_bitmap;
-     BdrvDirtyBitmapIter *dbi;
-     uint8_t *buf;
-@@ -677,7 +679,8 @@ static int mirror_exit_common(Job *job)
-     bdrv_child_refresh_perms(mirror_top_bs, mirror_top_bs->backing,
-                              &error_abort);
-     if (!abort && s->backing_mode == MIRROR_SOURCE_BACKING_CHAIN) {
--        BlockDriverState *backing = s->is_none_mode ? src : s->base;
-+        BlockDriverState *backing;
-+        backing = s->sync_mode == MIRROR_SYNC_MODE_NONE ? src : s->base;
-         BlockDriverState *unfiltered_target = bdrv_skip_filters(target_bs);
-         if (bdrv_cow_bs(unfiltered_target) != backing) {
-@@ -774,6 +777,16 @@ static void mirror_abort(Job *job)
-     assert(ret == 0);
- }
-+/* Always called after commit/abort. */
-+static void mirror_clean(Job *job)
-+{
-+    MirrorBlockJob *s = container_of(job, MirrorBlockJob, common.job);
-+
-+    if (s->sync_bitmap) {
-+        bdrv_dirty_bitmap_set_busy(s->sync_bitmap, false);
-+    }
-+}
-+
- static void coroutine_fn mirror_throttle(MirrorBlockJob *s)
- {
-     int64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
-@@ -955,7 +968,8 @@ static int coroutine_fn mirror_run(Job *job, Error **errp)
-     mirror_free_init(s);
-     s->last_pause_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
--    if (!s->is_none_mode) {
-+    if ((s->sync_mode == MIRROR_SYNC_MODE_TOP) ||
-+        (s->sync_mode == MIRROR_SYNC_MODE_FULL)) {
-         ret = mirror_dirty_init(s);
-         if (ret < 0 || job_is_cancelled(&s->common.job)) {
-             goto immediate_exit;
-@@ -1188,6 +1202,7 @@ static const BlockJobDriver mirror_job_driver = {
-         .run                    = mirror_run,
-         .prepare                = mirror_prepare,
-         .abort                  = mirror_abort,
-+        .clean                  = mirror_clean,
-         .pause                  = mirror_pause,
-         .complete               = mirror_complete,
-     },
-@@ -1203,6 +1218,7 @@ static const BlockJobDriver commit_active_job_driver = {
-         .run                    = mirror_run,
-         .prepare                = mirror_prepare,
-         .abort                  = mirror_abort,
-+        .clean                  = mirror_clean,
-         .pause                  = mirror_pause,
-         .complete               = mirror_complete,
-     },
-@@ -1550,7 +1566,10 @@ static BlockJob *mirror_start_job(
-                              BlockCompletionFunc *cb,
-                              void *opaque,
-                              const BlockJobDriver *driver,
--                             bool is_none_mode, BlockDriverState *base,
-+                             MirrorSyncMode sync_mode,
-+                             BdrvDirtyBitmap *bitmap,
-+                             BitmapSyncMode bitmap_mode,
-+                             BlockDriverState *base,
-                              bool auto_complete, const char *filter_node_name,
-                              bool is_mirror, MirrorCopyMode copy_mode,
-                              Error **errp)
-@@ -1563,10 +1582,39 @@ static BlockJob *mirror_start_job(
-     Error *local_err = NULL;
-     int ret;
--    if (granularity == 0) {
--        granularity = bdrv_get_default_bitmap_granularity(target);
-+    if (sync_mode == MIRROR_SYNC_MODE_INCREMENTAL) {
-+        error_setg(errp, "Sync mode '%s' not supported",
-+                   MirrorSyncMode_str(sync_mode));
-+        return NULL;
-+    } else if (sync_mode == MIRROR_SYNC_MODE_BITMAP) {
-+        if (!bitmap) {
-+            error_setg(errp, "Must provide a valid bitmap name for '%s'"
-+                       " sync mode",
-+                       MirrorSyncMode_str(sync_mode));
-+            return NULL;
-+        } else if (bitmap_mode != BITMAP_SYNC_MODE_NEVER) {
-+            error_setg(errp,
-+                       "Bitmap Sync Mode '%s' is not supported by Mirror",
-+                       BitmapSyncMode_str(bitmap_mode));
-+        }
-+    } else if (bitmap) {
-+        error_setg(errp,
-+                   "sync mode '%s' is not compatible with bitmaps",
-+                   MirrorSyncMode_str(sync_mode));
-+        return NULL;
-     }
-+    if (bitmap) {
-+        if (granularity) {
-+            error_setg(errp, "granularity (%d)"
-+                       "cannot be specified when a bitmap is provided",
-+                       granularity);
-+            return NULL;
-+        }
-+        granularity = bdrv_dirty_bitmap_granularity(bitmap);
-+    } else if (granularity == 0) {
-+        granularity = bdrv_get_default_bitmap_granularity(target);
-+    }
-     assert(is_power_of_2(granularity));
-     if (buf_size < 0) {
-@@ -1705,7 +1753,9 @@ static BlockJob *mirror_start_job(
-     s->replaces = g_strdup(replaces);
-     s->on_source_error = on_source_error;
-     s->on_target_error = on_target_error;
--    s->is_none_mode = is_none_mode;
-+    s->sync_mode = sync_mode;
-+    s->sync_bitmap = bitmap;
-+    s->bitmap_mode = bitmap_mode;
-     s->backing_mode = backing_mode;
-     s->zero_target = zero_target;
-     s->copy_mode = copy_mode;
-@@ -1726,6 +1776,18 @@ static BlockJob *mirror_start_job(
-         bdrv_disable_dirty_bitmap(s->dirty_bitmap);
-     }
-+    if (s->sync_bitmap) {
-+        bdrv_dirty_bitmap_set_busy(s->sync_bitmap, true);
-+    }
-+
-+    if (s->sync_mode == MIRROR_SYNC_MODE_BITMAP) {
-+        bdrv_merge_dirty_bitmap(s->dirty_bitmap, s->sync_bitmap,
-+                                NULL, &local_err);
-+        if (local_err) {
-+            goto fail;
-+        }
-+    }
-+
-     ret = block_job_add_bdrv(&s->common, "source", bs, 0,
-                              BLK_PERM_WRITE_UNCHANGED | BLK_PERM_WRITE |
-                              BLK_PERM_CONSISTENT_READ,
-@@ -1803,6 +1865,9 @@ fail:
-         if (s->dirty_bitmap) {
-             bdrv_release_dirty_bitmap(s->dirty_bitmap);
-         }
-+        if (s->sync_bitmap) {
-+            bdrv_dirty_bitmap_set_busy(s->sync_bitmap, false);
-+        }
-         job_early_fail(&s->common.job);
-     }
-@@ -1820,29 +1885,23 @@ void mirror_start(const char *job_id, BlockDriverState *bs,
-                   BlockDriverState *target, const char *replaces,
-                   int creation_flags, int64_t speed,
-                   uint32_t granularity, int64_t buf_size,
--                  MirrorSyncMode mode, BlockMirrorBackingMode backing_mode,
-+                  MirrorSyncMode mode, BdrvDirtyBitmap *bitmap,
-+                  BitmapSyncMode bitmap_mode,
-+                  BlockMirrorBackingMode backing_mode,
-                   bool zero_target,
-                   BlockdevOnError on_source_error,
-                   BlockdevOnError on_target_error,
-                   bool unmap, const char *filter_node_name,
-                   MirrorCopyMode copy_mode, Error **errp)
- {
--    bool is_none_mode;
-     BlockDriverState *base;
--    if ((mode == MIRROR_SYNC_MODE_INCREMENTAL) ||
--        (mode == MIRROR_SYNC_MODE_BITMAP)) {
--        error_setg(errp, "Sync mode '%s' not supported",
--                   MirrorSyncMode_str(mode));
--        return;
--    }
--    is_none_mode = mode == MIRROR_SYNC_MODE_NONE;
-     base = mode == MIRROR_SYNC_MODE_TOP ? bdrv_backing_chain_next(bs) : NULL;
-     mirror_start_job(job_id, bs, creation_flags, target, replaces,
-                      speed, granularity, buf_size, backing_mode, zero_target,
-                      on_source_error, on_target_error, unmap, NULL, NULL,
--                     &mirror_job_driver, is_none_mode, base, false,
--                     filter_node_name, true, copy_mode, errp);
-+                     &mirror_job_driver, mode, bitmap, bitmap_mode, base,
-+                     false, filter_node_name, true, copy_mode, errp);
- }
- BlockJob *commit_active_start(const char *job_id, BlockDriverState *bs,
-@@ -1868,7 +1927,8 @@ BlockJob *commit_active_start(const char *job_id, BlockDriverState *bs,
-                      job_id, bs, creation_flags, base, NULL, speed, 0, 0,
-                      MIRROR_LEAVE_BACKING_CHAIN, false,
-                      on_error, on_error, true, cb, opaque,
--                     &commit_active_job_driver, false, base, auto_complete,
-+                     &commit_active_job_driver, MIRROR_SYNC_MODE_FULL,
-+                     NULL, 0, base, auto_complete,
-                      filter_node_name, false, MIRROR_COPY_MODE_BACKGROUND,
-                      &local_err);
-     if (local_err) {
-diff --git a/blockdev.c b/blockdev.c
-index bae80b9177..c79e081f57 100644
---- a/blockdev.c
-+++ b/blockdev.c
-@@ -2931,6 +2931,10 @@ static void blockdev_mirror_common(const char *job_id, BlockDriverState *bs,
-                                    BlockDriverState *target,
-                                    bool has_replaces, const char *replaces,
-                                    enum MirrorSyncMode sync,
-+                                   bool has_bitmap,
-+                                   const char *bitmap_name,
-+                                   bool has_bitmap_mode,
-+                                   BitmapSyncMode bitmap_mode,
-                                    BlockMirrorBackingMode backing_mode,
-                                    bool zero_target,
-                                    bool has_speed, int64_t speed,
-@@ -2950,6 +2954,7 @@ static void blockdev_mirror_common(const char *job_id, BlockDriverState *bs,
- {
-     BlockDriverState *unfiltered_bs;
-     int job_flags = JOB_DEFAULT;
-+    BdrvDirtyBitmap *bitmap = NULL;
-     if (!has_speed) {
-         speed = 0;
-@@ -3004,6 +3009,29 @@ static void blockdev_mirror_common(const char *job_id, BlockDriverState *bs,
-         sync = MIRROR_SYNC_MODE_FULL;
-     }
-+    if (has_bitmap) {
-+        if (granularity) {
-+            error_setg(errp, "Granularity and bitmap cannot both be set");
-+            return;
-+        }
-+
-+        if (!has_bitmap_mode) {
-+            error_setg(errp, "bitmap-mode must be specified if"
-+                       " a bitmap is provided");
-+            return;
-+        }
-+
-+        bitmap = bdrv_find_dirty_bitmap(bs, bitmap_name);
-+        if (!bitmap) {
-+            error_setg(errp, "Dirty bitmap '%s' not found", bitmap_name);
-+            return;
-+        }
-+
-+        if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_ALLOW_RO, errp)) {
-+            return;
-+        }
-+    }
-+
-     if (!has_replaces) {
-         /* We want to mirror from @bs, but keep implicit filters on top */
-         unfiltered_bs = bdrv_skip_implicit_filters(bs);
-@@ -3050,8 +3078,8 @@ static void blockdev_mirror_common(const char *job_id, BlockDriverState *bs,
-      * and will allow to check whether the node still exist at mirror completion
-      */
-     mirror_start(job_id, bs, target,
--                 has_replaces ? replaces : NULL, job_flags,
--                 speed, granularity, buf_size, sync, backing_mode, zero_target,
-+                 has_replaces ? replaces : NULL, job_flags, speed, granularity,
-+                 buf_size, sync, bitmap, bitmap_mode, backing_mode, zero_target,
-                  on_source_error, on_target_error, unmap, filter_node_name,
-                  copy_mode, errp);
- }
-@@ -3196,6 +3224,8 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp)
-     blockdev_mirror_common(arg->has_job_id ? arg->job_id : NULL, bs, target_bs,
-                            arg->has_replaces, arg->replaces, arg->sync,
-+                           arg->has_bitmap, arg->bitmap,
-+                           arg->has_bitmap_mode, arg->bitmap_mode,
-                            backing_mode, zero_target,
-                            arg->has_speed, arg->speed,
-                            arg->has_granularity, arg->granularity,
-@@ -3217,6 +3247,8 @@ void qmp_blockdev_mirror(bool has_job_id, const char *job_id,
-                          const char *device, const char *target,
-                          bool has_replaces, const char *replaces,
-                          MirrorSyncMode sync,
-+                         bool has_bitmap, const char *bitmap,
-+                         bool has_bitmap_mode, BitmapSyncMode bitmap_mode,
-                          bool has_speed, int64_t speed,
-                          bool has_granularity, uint32_t granularity,
-                          bool has_buf_size, int64_t buf_size,
-@@ -3266,7 +3298,8 @@ void qmp_blockdev_mirror(bool has_job_id, const char *job_id,
-     }
-     blockdev_mirror_common(has_job_id ? job_id : NULL, bs, target_bs,
--                           has_replaces, replaces, sync, backing_mode,
-+                           has_replaces, replaces, sync, has_bitmap,
-+                           bitmap, has_bitmap_mode, bitmap_mode, backing_mode,
-                            zero_target, has_speed, speed,
-                            has_granularity, granularity,
-                            has_buf_size, buf_size,
-diff --git a/include/block/block_int.h b/include/block/block_int.h
-index 9fa282ff54..1bd4b64522 100644
---- a/include/block/block_int.h
-+++ b/include/block/block_int.h
-@@ -1260,7 +1260,9 @@ void mirror_start(const char *job_id, BlockDriverState *bs,
-                   BlockDriverState *target, const char *replaces,
-                   int creation_flags, int64_t speed,
-                   uint32_t granularity, int64_t buf_size,
--                  MirrorSyncMode mode, BlockMirrorBackingMode backing_mode,
-+                  MirrorSyncMode mode, BdrvDirtyBitmap *bitmap,
-+                  BitmapSyncMode bitmap_mode,
-+                  BlockMirrorBackingMode backing_mode,
-                   bool zero_target,
-                   BlockdevOnError on_source_error,
-                   BlockdevOnError on_target_error,
-diff --git a/qapi/block-core.json b/qapi/block-core.json
-index be67dc3376..9054db608c 100644
---- a/qapi/block-core.json
-+++ b/qapi/block-core.json
-@@ -2080,10 +2080,19 @@
- #        (all the disk, only the sectors allocated in the topmost image, or
- #        only new I/O).
- #
-+# @bitmap: The name of a bitmap to use for sync=bitmap mode. This argument must
-+#          be present for bitmap mode and absent otherwise. The bitmap's
-+#          granularity is used instead of @granularity (since 4.1).
-+#
-+# @bitmap-mode: Specifies the type of data the bitmap should contain after
-+#               the operation concludes. Must be present if sync is "bitmap".
-+#               Must NOT be present otherwise. (Since 4.1)
-+#
- # @granularity: granularity of the dirty bitmap, default is 64K
- #               if the image format doesn't have clusters, 4K if the clusters
- #               are smaller than that, else the cluster size.  Must be a
--#               power of 2 between 512 and 64M (since 1.4).
-+#               power of 2 between 512 and 64M. Must not be specified if
-+#               @bitmap is present (since 1.4).
- #
- # @buf-size: maximum amount of data in flight from source to
- #            target (since 1.4).
-@@ -2121,7 +2130,9 @@
- { 'struct': 'DriveMirror',
-   'data': { '*job-id': 'str', 'device': 'str', 'target': 'str',
-             '*format': 'str', '*node-name': 'str', '*replaces': 'str',
--            'sync': 'MirrorSyncMode', '*mode': 'NewImageMode',
-+            'sync': 'MirrorSyncMode', '*bitmap': 'str',
-+            '*bitmap-mode': 'BitmapSyncMode',
-+            '*mode': 'NewImageMode',
-             '*speed': 'int', '*granularity': 'uint32',
-             '*buf-size': 'int', '*on-source-error': 'BlockdevOnError',
-             '*on-target-error': 'BlockdevOnError',
-@@ -2389,10 +2400,19 @@
- #        (all the disk, only the sectors allocated in the topmost image, or
- #        only new I/O).
- #
-+# @bitmap: The name of a bitmap to use for sync=bitmap mode. This argument must
-+#          be present for bitmap mode and absent otherwise. The bitmap's
-+#          granularity is used instead of @granularity (since 4.1).
-+#
-+# @bitmap-mode: Specifies the type of data the bitmap should contain after
-+#               the operation concludes. Must be present if sync is "bitmap".
-+#               Must NOT be present otherwise. (Since 4.1)
-+#
- # @granularity: granularity of the dirty bitmap, default is 64K
- #               if the image format doesn't have clusters, 4K if the clusters
- #               are smaller than that, else the cluster size.  Must be a
--#               power of 2 between 512 and 64M
-+#               power of 2 between 512 and 64M . Must not be specified if
-+#               @bitmap is present.
- #
- # @buf-size: maximum amount of data in flight from source to
- #            target
-@@ -2441,7 +2461,8 @@
- { 'command': 'blockdev-mirror',
-   'data': { '*job-id': 'str', 'device': 'str', 'target': 'str',
-             '*replaces': 'str',
--            'sync': 'MirrorSyncMode',
-+            'sync': 'MirrorSyncMode', '*bitmap': 'str',
-+            '*bitmap-mode': 'BitmapSyncMode',
-             '*speed': 'int', '*granularity': 'uint32',
-             '*buf-size': 'int', '*on-source-error': 'BlockdevOnError',
-             '*on-target-error': 'BlockdevOnError',
-diff --git a/tests/test-block-iothread.c b/tests/test-block-iothread.c
-index 3f866a35c6..500ede71c8 100644
---- a/tests/test-block-iothread.c
-+++ b/tests/test-block-iothread.c
-@@ -623,8 +623,8 @@ static void test_propagate_mirror(void)
-     /* Start a mirror job */
-     mirror_start("job0", src, target, NULL, JOB_DEFAULT, 0, 0, 0,
--                 MIRROR_SYNC_MODE_NONE, MIRROR_OPEN_BACKING_CHAIN, false,
--                 BLOCKDEV_ON_ERROR_REPORT, BLOCKDEV_ON_ERROR_REPORT,
-+                 MIRROR_SYNC_MODE_NONE, NULL, 0, MIRROR_OPEN_BACKING_CHAIN,
-+                 false, BLOCKDEV_ON_ERROR_REPORT, BLOCKDEV_ON_ERROR_REPORT,
-                  false, "filter_node", MIRROR_COPY_MODE_BACKGROUND,
-                  &error_abort);
-     job = job_get("job0");
diff --git a/debian/patches/pve/0032-drive-mirror-add-support-for-conditional-and-always-.patch b/debian/patches/pve/0032-drive-mirror-add-support-for-conditional-and-always-.patch
deleted file mode 100644 (file)
index 5a87360..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: John Snow <jsnow@redhat.com>
-Date: Mon, 6 Apr 2020 12:17:04 +0200
-Subject: [PATCH] drive-mirror: add support for conditional and always bitmap
- sync modes
-MIME-Version: 1.0
-Content-Type: text/plain; charset=UTF-8
-Content-Transfer-Encoding: 8bit
-
-Teach mirror two new tricks for using bitmaps:
-
-Always: no matter what, we synchronize the copy_bitmap back to the
-sync_bitmap. In effect, this allows us resume a failed mirror at a later
-date.
-
-Conditional: On success only, we sync the bitmap. This is akin to
-incremental backup modes; we can use this bitmap to later refresh a
-successfully created mirror.
-
-Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
----
- block/mirror.c | 24 ++++++++++++++++++------
- 1 file changed, 18 insertions(+), 6 deletions(-)
-
-diff --git a/block/mirror.c b/block/mirror.c
-index 97843992c2..d1cce079da 100644
---- a/block/mirror.c
-+++ b/block/mirror.c
-@@ -654,8 +654,6 @@ static int mirror_exit_common(Job *job)
-         bdrv_unfreeze_backing_chain(mirror_top_bs, target_bs);
-     }
--    bdrv_release_dirty_bitmap(s->dirty_bitmap);
--
-     /* Make sure that the source BDS doesn't go away during bdrv_replace_node,
-      * before we can call bdrv_drained_end */
-     bdrv_ref(src);
-@@ -755,6 +753,18 @@ static int mirror_exit_common(Job *job)
-     blk_set_perm(bjob->blk, 0, BLK_PERM_ALL, &error_abort);
-     blk_insert_bs(bjob->blk, mirror_top_bs, &error_abort);
-+    if (s->sync_bitmap) {
-+        if (s->bitmap_mode == BITMAP_SYNC_MODE_ALWAYS ||
-+            (s->bitmap_mode == BITMAP_SYNC_MODE_ON_SUCCESS &&
-+             job->ret == 0 && ret == 0)) {
-+            /* Success; synchronize copy back to sync. */
-+            bdrv_clear_dirty_bitmap(s->sync_bitmap, NULL);
-+            bdrv_merge_dirty_bitmap(s->sync_bitmap, s->dirty_bitmap,
-+                                    NULL, &error_abort);
-+        }
-+    }
-+    bdrv_release_dirty_bitmap(s->dirty_bitmap);
-+
-     bs_opaque->job = NULL;
-     bdrv_drained_end(src);
-@@ -1592,10 +1602,6 @@ static BlockJob *mirror_start_job(
-                        " sync mode",
-                        MirrorSyncMode_str(sync_mode));
-             return NULL;
--        } else if (bitmap_mode != BITMAP_SYNC_MODE_NEVER) {
--            error_setg(errp,
--                       "Bitmap Sync Mode '%s' is not supported by Mirror",
--                       BitmapSyncMode_str(bitmap_mode));
-         }
-     } else if (bitmap) {
-         error_setg(errp,
-@@ -1612,6 +1618,12 @@ static BlockJob *mirror_start_job(
-             return NULL;
-         }
-         granularity = bdrv_dirty_bitmap_granularity(bitmap);
-+
-+        if (bitmap_mode != BITMAP_SYNC_MODE_NEVER) {
-+            if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_DEFAULT, errp)) {
-+                return NULL;
-+            }
-+        }
-     } else if (granularity == 0) {
-         granularity = bdrv_get_default_bitmap_granularity(target);
-     }
diff --git a/debian/patches/pve/0032-mirror-add-check-for-bitmap-mode-without-bitmap.patch b/debian/patches/pve/0032-mirror-add-check-for-bitmap-mode-without-bitmap.patch
new file mode 100644 (file)
index 0000000..97077f3
--- /dev/null
@@ -0,0 +1,30 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= <f.gruenbichler@proxmox.com>
+Date: Mon, 6 Apr 2020 12:17:05 +0200
+Subject: [PATCH] mirror: add check for bitmap-mode without bitmap
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+as one without the other does not make much sense with the current set
+of modes.
+
+Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
+---
+ blockdev.c | 3 +++
+ 1 file changed, 3 insertions(+)
+
+diff --git a/blockdev.c b/blockdev.c
+index c79e081f57..827f004069 100644
+--- a/blockdev.c
++++ b/blockdev.c
+@@ -3030,6 +3030,9 @@ static void blockdev_mirror_common(const char *job_id, BlockDriverState *bs,
+         if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_ALLOW_RO, errp)) {
+             return;
+         }
++    } else if (has_bitmap_mode) {
++        error_setg(errp, "Cannot specify bitmap sync mode without a bitmap");
++        return;
+     }
+     if (!has_replaces) {
diff --git a/debian/patches/pve/0033-mirror-add-check-for-bitmap-mode-without-bitmap.patch b/debian/patches/pve/0033-mirror-add-check-for-bitmap-mode-without-bitmap.patch
deleted file mode 100644 (file)
index 97077f3..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= <f.gruenbichler@proxmox.com>
-Date: Mon, 6 Apr 2020 12:17:05 +0200
-Subject: [PATCH] mirror: add check for bitmap-mode without bitmap
-MIME-Version: 1.0
-Content-Type: text/plain; charset=UTF-8
-Content-Transfer-Encoding: 8bit
-
-as one without the other does not make much sense with the current set
-of modes.
-
-Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
----
- blockdev.c | 3 +++
- 1 file changed, 3 insertions(+)
-
-diff --git a/blockdev.c b/blockdev.c
-index c79e081f57..827f004069 100644
---- a/blockdev.c
-+++ b/blockdev.c
-@@ -3030,6 +3030,9 @@ static void blockdev_mirror_common(const char *job_id, BlockDriverState *bs,
-         if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_ALLOW_RO, errp)) {
-             return;
-         }
-+    } else if (has_bitmap_mode) {
-+        error_setg(errp, "Cannot specify bitmap sync mode without a bitmap");
-+        return;
-     }
-     if (!has_replaces) {
diff --git a/debian/patches/pve/0033-mirror-switch-to-bdrv_dirty_bitmap_merge_internal.patch b/debian/patches/pve/0033-mirror-switch-to-bdrv_dirty_bitmap_merge_internal.patch
new file mode 100644 (file)
index 0000000..8b3c1e2
--- /dev/null
@@ -0,0 +1,42 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= <f.gruenbichler@proxmox.com>
+Date: Mon, 6 Apr 2020 12:17:06 +0200
+Subject: [PATCH] mirror: switch to bdrv_dirty_bitmap_merge_internal
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+since sync_bitmap is busy at the point of merging, and we checked access
+beforehand.
+
+Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
+---
+ block/mirror.c | 8 ++++----
+ 1 file changed, 4 insertions(+), 4 deletions(-)
+
+diff --git a/block/mirror.c b/block/mirror.c
+index d1cce079da..e6140cf018 100644
+--- a/block/mirror.c
++++ b/block/mirror.c
+@@ -759,8 +759,8 @@ static int mirror_exit_common(Job *job)
+              job->ret == 0 && ret == 0)) {
+             /* Success; synchronize copy back to sync. */
+             bdrv_clear_dirty_bitmap(s->sync_bitmap, NULL);
+-            bdrv_merge_dirty_bitmap(s->sync_bitmap, s->dirty_bitmap,
+-                                    NULL, &error_abort);
++            bdrv_dirty_bitmap_merge_internal(s->sync_bitmap, s->dirty_bitmap,
++                                             NULL, true);
+         }
+     }
+     bdrv_release_dirty_bitmap(s->dirty_bitmap);
+@@ -1793,8 +1793,8 @@ static BlockJob *mirror_start_job(
+     }
+     if (s->sync_mode == MIRROR_SYNC_MODE_BITMAP) {
+-        bdrv_merge_dirty_bitmap(s->dirty_bitmap, s->sync_bitmap,
+-                                NULL, &local_err);
++        bdrv_dirty_bitmap_merge_internal(s->dirty_bitmap, s->sync_bitmap,
++                                         NULL, true);
+         if (local_err) {
+             goto fail;
+         }
diff --git a/debian/patches/pve/0034-iotests-add-test-for-bitmap-mirror.patch b/debian/patches/pve/0034-iotests-add-test-for-bitmap-mirror.patch
new file mode 100644 (file)
index 0000000..07a66d6
--- /dev/null
@@ -0,0 +1,3447 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= <f.gruenbichler@proxmox.com>
+Date: Mon, 6 Apr 2020 12:17:07 +0200
+Subject: [PATCH] iotests: add test for bitmap mirror
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+heavily based on/practically forked off iotest 257 for bitmap backups,
+but:
+
+- no writes to filter node 'mirror-top' between completion and
+finalization, as those seem to deadlock?
+- no inclusion of not-yet-available full/top sync modes in combination
+with bitmaps
+- extra set of reference/test mirrors to verify that writes in parallel
+with active mirror work
+
+intentionally keeping copyright and ownership of original test case to
+honor provenance.
+
+Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
+---
+ tests/qemu-iotests/384     |  547 +++++++
+ tests/qemu-iotests/384.out | 2846 ++++++++++++++++++++++++++++++++++++
+ tests/qemu-iotests/group   |    1 +
+ 3 files changed, 3394 insertions(+)
+ create mode 100755 tests/qemu-iotests/384
+ create mode 100644 tests/qemu-iotests/384.out
+
+diff --git a/tests/qemu-iotests/384 b/tests/qemu-iotests/384
+new file mode 100755
+index 0000000000..b04a8e651a
+--- /dev/null
++++ b/tests/qemu-iotests/384
+@@ -0,0 +1,547 @@
++#!/usr/bin/env python3
++#
++# Test bitmap-sync mirrors (incremental, differential, and partials)
++#
++# Copyright (c) 2019 John Snow for Red Hat, Inc.
++#
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 2 of the License, or
++# (at your option) any later version.
++#
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with this program.  If not, see <http://www.gnu.org/licenses/>.
++#
++# owner=jsnow@redhat.com
++
++import math
++import os
++
++import iotests
++from iotests import log, qemu_img
++
++SIZE = 64 * 1024 * 1024
++GRANULARITY = 64 * 1024
++
++
++class Pattern:
++    def __init__(self, byte, offset, size=GRANULARITY):
++        self.byte = byte
++        self.offset = offset
++        self.size = size
++
++    def bits(self, granularity):
++        lower = self.offset // granularity
++        upper = (self.offset + self.size - 1) // granularity
++        return set(range(lower, upper + 1))
++
++
++class PatternGroup:
++    """Grouping of Pattern objects. Initialize with an iterable of Patterns."""
++    def __init__(self, patterns):
++        self.patterns = patterns
++
++    def bits(self, granularity):
++        """Calculate the unique bits dirtied by this pattern grouping"""
++        res = set()
++        for pattern in self.patterns:
++            res |= pattern.bits(granularity)
++        return res
++
++
++GROUPS = [
++    PatternGroup([
++        # Batch 0: 4 clusters
++        Pattern('0x49', 0x0000000),
++        Pattern('0x6c', 0x0100000),   # 1M
++        Pattern('0x6f', 0x2000000),   # 32M
++        Pattern('0x76', 0x3ff0000)]), # 64M - 64K
++    PatternGroup([
++        # Batch 1: 6 clusters (3 new)
++        Pattern('0x65', 0x0000000),   # Full overwrite
++        Pattern('0x77', 0x00f8000),   # Partial-left (1M-32K)
++        Pattern('0x72', 0x2008000),   # Partial-right (32M+32K)
++        Pattern('0x69', 0x3fe0000)]), # Adjacent-left (64M - 128K)
++    PatternGroup([
++        # Batch 2: 7 clusters (3 new)
++        Pattern('0x74', 0x0010000),   # Adjacent-right
++        Pattern('0x69', 0x00e8000),   # Partial-left  (1M-96K)
++        Pattern('0x6e', 0x2018000),   # Partial-right (32M+96K)
++        Pattern('0x67', 0x3fe0000,
++                2*GRANULARITY)]),     # Overwrite [(64M-128K)-64M)
++    PatternGroup([
++        # Batch 3: 8 clusters (5 new)
++        # Carefully chosen such that nothing re-dirties the one cluster
++        # that copies out successfully before failure in Group #1.
++        Pattern('0xaa', 0x0010000,
++                3*GRANULARITY),       # Overwrite and 2x Adjacent-right
++        Pattern('0xbb', 0x00d8000),   # Partial-left (1M-160K)
++        Pattern('0xcc', 0x2028000),   # Partial-right (32M+160K)
++        Pattern('0xdd', 0x3fc0000)]), # New; leaving a gap to the right
++]
++
++
++class EmulatedBitmap:
++    def __init__(self, granularity=GRANULARITY):
++        self._bits = set()
++        self.granularity = granularity
++
++    def dirty_bits(self, bits):
++        self._bits |= set(bits)
++
++    def dirty_group(self, n):
++        self.dirty_bits(GROUPS[n].bits(self.granularity))
++
++    def clear(self):
++        self._bits = set()
++
++    def clear_bits(self, bits):
++        self._bits -= set(bits)
++
++    def clear_bit(self, bit):
++        self.clear_bits({bit})
++
++    def clear_group(self, n):
++        self.clear_bits(GROUPS[n].bits(self.granularity))
++
++    @property
++    def first_bit(self):
++        return sorted(self.bits)[0]
++
++    @property
++    def bits(self):
++        return self._bits
++
++    @property
++    def count(self):
++        return len(self.bits)
++
++    def compare(self, qmp_bitmap):
++        """
++        Print a nice human-readable message checking that a bitmap as reported
++        by the QMP interface has as many bits set as we expect it to.
++        """
++
++        name = qmp_bitmap.get('name', '(anonymous)')
++        log("= Checking Bitmap {:s} =".format(name))
++
++        want = self.count
++        have = qmp_bitmap['count'] // qmp_bitmap['granularity']
++
++        log("expecting {:d} dirty sectors; have {:d}. {:s}".format(
++            want, have, "OK!" if want == have else "ERROR!"))
++        log('')
++
++
++class Drive:
++    """Represents, vaguely, a drive attached to a VM.
++    Includes format, graph, and device information."""
++
++    def __init__(self, path, vm=None):
++        self.path = path
++        self.vm = vm
++        self.fmt = None
++        self.size = None
++        self.node = None
++
++    def img_create(self, fmt, size):
++        self.fmt = fmt
++        self.size = size
++        iotests.qemu_img_create('-f', self.fmt, self.path, str(self.size))
++
++    def create_target(self, name, fmt, size):
++        basename = os.path.basename(self.path)
++        file_node_name = "file_{}".format(basename)
++        vm = self.vm
++
++        log(vm.command('blockdev-create', job_id='bdc-file-job',
++                       options={
++                           'driver': 'file',
++                           'filename': self.path,
++                           'size': 0,
++                       }))
++        vm.run_job('bdc-file-job')
++        log(vm.command('blockdev-add', driver='file',
++                       node_name=file_node_name, filename=self.path))
++
++        log(vm.command('blockdev-create', job_id='bdc-fmt-job',
++                       options={
++                           'driver': fmt,
++                           'file': file_node_name,
++                           'size': size,
++                       }))
++        vm.run_job('bdc-fmt-job')
++        log(vm.command('blockdev-add', driver=fmt,
++                       node_name=name,
++                       file=file_node_name))
++        self.fmt = fmt
++        self.size = size
++        self.node = name
++
++def blockdev_mirror(vm, device, target, sync, **kwargs):
++    # Strip any arguments explicitly nulled by the caller:
++    kwargs = {key: val for key, val in kwargs.items() if val is not None}
++    result = vm.qmp_log('blockdev-mirror',
++                        device=device,
++                        target=target,
++                        sync=sync,
++                        filter_node_name='mirror-top',
++                        **kwargs)
++    return result
++
++def blockdev_mirror_mktarget(drive, target_id, filepath, sync, **kwargs):
++    target_drive = Drive(filepath, vm=drive.vm)
++    target_drive.create_target(target_id, drive.fmt, drive.size)
++    blockdev_mirror(drive.vm, drive.node, target_id, sync, **kwargs)
++
++def reference_mirror(drive, n, filepath):
++    log("--- Reference mirror #{:d} ---\n".format(n))
++    target_id = "ref_target_{:d}".format(n)
++    job_id = "ref_mirror_{:d}".format(n)
++    blockdev_mirror_mktarget(drive, target_id, filepath, "full",
++                             job_id=job_id)
++    drive.vm.run_job(job_id, auto_dismiss=True)
++    log('')
++
++def mirror(drive, n, filepath, sync, **kwargs):
++    log("--- Test mirror #{:d} ---\n".format(n))
++    target_id = "mirror_target_{:d}".format(n)
++    job_id = "mirror_{:d}".format(n)
++    kwargs.setdefault('auto-finalize', False)
++    blockdev_mirror_mktarget(drive, target_id, filepath, sync,
++                             job_id=job_id, **kwargs)
++    return job_id
++
++def perform_writes(drive, n, filter_node_name=None):
++    log("--- Write #{:d} ---\n".format(n))
++    for pattern in GROUPS[n].patterns:
++        cmd = "write -P{:s} 0x{:07x} 0x{:x}".format(
++            pattern.byte,
++            pattern.offset,
++            pattern.size)
++        log(cmd)
++        log(drive.vm.hmp_qemu_io(filter_node_name or drive.node, cmd))
++    bitmaps = drive.vm.query_bitmaps()
++    log({'bitmaps': bitmaps}, indent=2)
++    log('')
++    return bitmaps
++
++
++def compare_images(image, reference, baseimg=None, expected_match=True):
++    """
++    Print a nice human-readable message comparing these images.
++    """
++    expected_ret = 0 if expected_match else 1
++    if baseimg:
++        assert qemu_img("rebase", "-u", "-b", baseimg, image) == 0
++    ret = qemu_img("compare", image, reference)
++    log('qemu_img compare "{:s}" "{:s}" ==> {:s}, {:s}'.format(
++        image, reference,
++        "Identical" if ret == 0 else "Mismatch",
++        "OK!" if ret == expected_ret else "ERROR!"),
++        filters=[iotests.filter_testfiles])
++
++def test_bitmap_sync(bsync_mode, msync_mode='bitmap', failure=None):
++    """
++    Test bitmap mirror routines.
++
++    :param bsync_mode: Is the Bitmap Sync mode, and can be any of:
++        - on-success: This is the "incremental" style mode. Bitmaps are
++                      synchronized to what was copied out only on success.
++                      (Partial images must be discarded.)
++        - never:      This is the "differential" style mode.
++                      Bitmaps are never synchronized.
++        - always:     This is a "best effort" style mode.
++                      Bitmaps are always synchronized, regardless of failure.
++                      (Partial images must be kept.)
++
++    :param msync_mode: The mirror sync mode to use for the first mirror.
++                       Can be any one of:
++        - bitmap: mirrors based on bitmap manifest.
++        - full:   Full mirrors.
++        - top:    Full mirrors of the top layer only.
++
++    :param failure: Is the (optional) failure mode, and can be any of:
++        - None:         No failure. Test the normative path. Default.
++        - simulated:    Cancel the job right before it completes.
++                        This also tests writes "during" the job.
++        - intermediate: This tests a job that fails mid-process and produces
++                        an incomplete mirror. Testing limitations prevent
++                        testing competing writes.
++    """
++    with iotests.FilePaths(['img', 'bsync1', 'bsync2', 'bsync3',
++                            'fmirror0', 'fmirror1', 'fmirror2', 'fmirror3']) as \
++                            (img_path, bsync1, bsync2, bsync3,
++                             fmirror0, fmirror1, fmirror2, fmirror3), \
++         iotests.VM() as vm:
++
++        mode = "Mode {:s}; Bitmap Sync {:s}".format(msync_mode, bsync_mode)
++        preposition = "with" if failure else "without"
++        cond = "{:s} {:s}".format(preposition,
++                                  "{:s} failure".format(failure) if failure
++                                  else "failure")
++        log("\n=== {:s} {:s} ===\n".format(mode, cond))
++
++        log('--- Preparing image & VM ---\n')
++        drive0 = Drive(img_path, vm=vm)
++        drive0.img_create(iotests.imgfmt, SIZE)
++        vm.add_device("{},id=scsi0".format(iotests.get_virtio_scsi_device()))
++        vm.launch()
++
++        file_config = {
++            'driver': 'file',
++            'filename': drive0.path
++        }
++
++        if failure == 'intermediate':
++            file_config = {
++                'driver': 'blkdebug',
++                'image': file_config,
++                'set-state': [{
++                    'event': 'flush_to_disk',
++                    'state': 1,
++                    'new_state': 2
++                }, {
++                    'event': 'read_aio',
++                    'state': 2,
++                    'new_state': 3
++                }, {
++                    'event': 'read_aio',
++                    'state': 3,
++                    'new_state': 4
++                }],
++                'inject-error': [{
++                    'event': 'read_aio',
++                    'errno': 5,
++                    'state': 3,
++                    'immediately': False,
++                    'once': True
++                }, {
++                    'event': 'read_aio',
++                    'errno': 5,
++                    'state': 4,
++                    'immediately': False,
++                    'once': True
++                }]
++            }
++
++        drive0.node = 'drive0'
++        vm.qmp_log('blockdev-add',
++                   filters=[iotests.filter_qmp_testfiles],
++                   node_name=drive0.node,
++                   driver=drive0.fmt,
++                   file=file_config)
++        log('')
++
++        # 0 - Writes and Reference mirror
++        perform_writes(drive0, 0)
++        reference_mirror(drive0, 0, fmirror0)
++        log('--- Add Bitmap ---\n')
++        vm.qmp_log("block-dirty-bitmap-add", node=drive0.node,
++                   name="bitmap0", granularity=GRANULARITY)
++        log('')
++        ebitmap = EmulatedBitmap()
++
++        # 1 - Writes and Reference mirror
++        bitmaps = perform_writes(drive0, 1)
++        ebitmap.dirty_group(1)
++        bitmap = vm.get_bitmap(drive0.node, 'bitmap0', bitmaps=bitmaps)
++        ebitmap.compare(bitmap)
++        reference_mirror(drive0, 1, fmirror1)
++
++        # 1 - Test mirror (w/ Optional induced failure)
++        if failure == 'intermediate':
++            # Activate blkdebug induced failure for second-to-next read
++            log(vm.hmp_qemu_io(drive0.node, 'flush'))
++            log('')
++        job = mirror(drive0, 1, bsync1, msync_mode,
++                     bitmap="bitmap0", bitmap_mode=bsync_mode)
++
++        vm.run_job(job, auto_dismiss=True, auto_finalize=False,
++                   cancel=(failure == 'simulated'))
++        bitmaps = vm.query_bitmaps()
++        log({'bitmaps': bitmaps}, indent=2)
++        log('')
++
++        if bsync_mode == 'always':
++            if failure == 'intermediate':
++                # We manage to copy one sector (one bit) before the error.
++                ebitmap.clear_bit(ebitmap.first_bit)
++            else:
++                # successful mirror / cancelled complete mirror
++                ebitmap.clear()
++
++        if bsync_mode == 'on-success' and not failure:
++            ebitmap.clear()
++
++        ebitmap.compare(vm.get_bitmap(drive0.node, 'bitmap0', bitmaps=bitmaps))
++
++        # 2 - Reference mirror
++        reference_mirror(drive0, 2, fmirror2)
++
++        # 2 - Bitmap mirror with writes before completion
++        job = mirror(drive0, 2, bsync2, "bitmap",
++                     bitmap="bitmap0", bitmap_mode=bsync_mode)
++
++        bitmaps = perform_writes(drive0, 2)
++        ebitmap.dirty_group(2)
++        ebitmap.compare(vm.get_bitmap(drive0.node, 'bitmap0', bitmaps=bitmaps))
++
++        # don't use run_job as that logs too much even with use_log=False
++        events = [('JOB_STATUS_CHANGE', {'data': {'id': job}})]
++        while True:
++            ev = iotests.filter_qmp_event(vm.events_wait(events, timeout=10))
++            status = ev['data']['status']
++            if status == 'ready':
++                vm.qmp('job-complete', id=job)
++            elif status == 'standby':
++                vm.qmp('job-resume', id=job)
++            elif status == 'pending':
++                vm.qmp('job-finalize', id=job)
++            elif status == 'null':
++                break
++
++        if bsync_mode != 'never':
++            ebitmap.clear()
++
++        bitmaps = vm.query_bitmaps()
++        ebitmap.compare(vm.get_bitmap(drive0.node, 'bitmap0', bitmaps=bitmaps))
++
++        # 3 - Writes and Reference mirror
++        bitmaps = perform_writes(drive0, 3)
++        ebitmap.dirty_group(3)
++        ebitmap.compare(vm.get_bitmap(drive0.node, 'bitmap0', bitmaps=bitmaps))
++        reference_mirror(drive0, 3, fmirror3)
++
++        # 3 - Bitmap mirror (In failure modes, this is a recovery.)
++        job = mirror(drive0, 3, bsync3, "bitmap",
++                     bitmap="bitmap0", bitmap_mode=bsync_mode)
++
++        vm.run_job(job, auto_dismiss=True, auto_finalize=False)
++        bitmaps = vm.query_bitmaps()
++
++        log({'bitmaps': bitmaps}, indent=2)
++        log('')
++        if bsync_mode != 'never':
++            ebitmap.clear()
++        ebitmap.compare(vm.get_bitmap(drive0.node, 'bitmap0', bitmaps=bitmaps))
++
++        log('--- Cleanup ---\n')
++        vm.qmp_log("block-dirty-bitmap-remove",
++                   node=drive0.node, name="bitmap0")
++        bitmaps = vm.query_bitmaps()
++        log({'bitmaps': bitmaps}, indent=2)
++        vm.shutdown()
++        log('')
++
++        log('--- Verification ---\n')
++        compare_images(bsync1, fmirror1, baseimg=fmirror0,
++                       expected_match=failure != 'intermediate')
++        if not failure or bsync_mode == 'always':
++            # Always keep the last mirror on success or when using 'always'
++            base = bsync1
++        else:
++            base = fmirror1
++
++        compare_images(bsync2, fmirror2, baseimg=base, expected_match=0)
++        compare_images(bsync3, fmirror3, baseimg=bsync2)
++        compare_images(img_path, fmirror3)
++        log('')
++
++def test_mirror_api():
++    """
++    Test malformed and prohibited invocations of the mirror API.
++    """
++    with iotests.FilePaths(['img', 'bsync1']) as \
++         (img_path, mirror_path), \
++         iotests.VM() as vm:
++
++        log("\n=== API failure tests ===\n")
++        log('--- Preparing image & VM ---\n')
++        drive0 = Drive(img_path, vm=vm)
++        drive0.img_create(iotests.imgfmt, SIZE)
++        vm.add_device("{},id=scsi0".format(iotests.get_virtio_scsi_device()))
++        vm.launch()
++
++        file_config = {
++            'driver': 'file',
++            'filename': drive0.path
++        }
++
++        drive0.node = 'drive0'
++        vm.qmp_log('blockdev-add',
++                   filters=[iotests.filter_qmp_testfiles],
++                   node_name=drive0.node,
++                   driver=drive0.fmt,
++                   file=file_config)
++        log('')
++
++        target0 = Drive(mirror_path, vm=vm)
++        target0.create_target("mirror_target", drive0.fmt, drive0.size)
++        log('')
++
++        vm.qmp_log("block-dirty-bitmap-add", node=drive0.node,
++                   name="bitmap0", granularity=GRANULARITY)
++        log('')
++
++        log('-- Testing invalid QMP commands --\n')
++
++        error_cases = {
++            'incremental': {
++                None:        ['on-success', 'always', 'never', None],
++                'bitmap404': ['on-success', 'always', 'never', None],
++                'bitmap0':   ['always', 'never']
++            },
++            'bitmap': {
++                None:        ['on-success', 'always', 'never', None],
++                'bitmap404': ['on-success', 'always', 'never', None],
++                'bitmap0':   [None],
++            },
++            'full': {
++                None:        ['on-success', 'always', 'never'],
++                'bitmap404': ['on-success', 'always', 'never', None],
++                'bitmap0':   ['on-success', 'always', 'never', None],
++            },
++            'top': {
++                None:        ['on-success', 'always', 'never'],
++                'bitmap404': ['on-success', 'always', 'never', None],
++                'bitmap0':   ['on-success', 'always', 'never', None],
++            },
++            'none': {
++                None:        ['on-success', 'always', 'never'],
++                'bitmap404': ['on-success', 'always', 'never', None],
++                'bitmap0':   ['on-success', 'always', 'never', None],
++            }
++        }
++
++        # Dicts, as always, are not stably-ordered prior to 3.7, so use tuples:
++        for sync_mode in ('incremental', 'bitmap', 'full', 'top', 'none'):
++            log("-- Sync mode {:s} tests --\n".format(sync_mode))
++            for bitmap in (None, 'bitmap404', 'bitmap0'):
++                for policy in error_cases[sync_mode][bitmap]:
++                    blockdev_mirror(drive0.vm, drive0.node, "mirror_target",
++                                    sync_mode, job_id='api_job',
++                                    bitmap=bitmap, bitmap_mode=policy)
++                    log('')
++
++
++def main():
++    for bsync_mode in ("never", "on-success", "always"):
++        for failure in ("simulated", "intermediate", None):
++            test_bitmap_sync(bsync_mode, "bitmap", failure)
++
++#    for sync_mode in ('full', 'top'):
++#        for bsync_mode in ('on-success', 'always'):
++#            for failure in ('simulated', 'intermediate', None):
++#                test_bitmap_sync(bsync_mode, sync_mode, failure)
++
++    test_mirror_api()
++
++if __name__ == '__main__':
++    iotests.script_main(main, supported_fmts=['qcow2'],
++                        supported_protocols=['file'])
+diff --git a/tests/qemu-iotests/384.out b/tests/qemu-iotests/384.out
+new file mode 100644
+index 0000000000..9b7408b6d6
+--- /dev/null
++++ b/tests/qemu-iotests/384.out
+@@ -0,0 +1,2846 @@
++
++=== Mode bitmap; Bitmap Sync never with simulated failure ===
++
++--- Preparing image & VM ---
++
++{"execute": "blockdev-add", "arguments": {"driver": "qcow2", "file": {"driver": "file", "filename": "TEST_DIR/PID-img"}, "node-name": "drive0"}}
++{"return": {}}
++
++--- Write #0 ---
++
++write -P0x49 0x0000000 0x10000
++{"return": ""}
++write -P0x6c 0x0100000 0x10000
++{"return": ""}
++write -P0x6f 0x2000000 0x10000
++{"return": ""}
++write -P0x76 0x3ff0000 0x10000
++{"return": ""}
++{
++  "bitmaps": {}
++}
++
++--- Reference mirror #0 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_0", "sync": "full", "target": "ref_target_0"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_0"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++--- Add Bitmap ---
++
++{"execute": "block-dirty-bitmap-add", "arguments": {"granularity": 65536, "name": "bitmap0", "node": "drive0"}}
++{"return": {}}
++
++--- Write #1 ---
++
++write -P0x65 0x0000000 0x10000
++{"return": ""}
++write -P0x77 0x00f8000 0x10000
++{"return": ""}
++write -P0x72 0x2008000 0x10000
++{"return": ""}
++write -P0x69 0x3fe0000 0x10000
++{"return": ""}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 393216,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 6 dirty sectors; have 6. OK!
++
++--- Reference mirror #1 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_1", "sync": "full", "target": "ref_target_1"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_1"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++--- Test mirror #1 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_1", "sync": "bitmap", "target": "mirror_target_1"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "mirror_1"}}
++{"return": {}}
++{"data": {"device": "mirror_1", "len": 393216, "offset": 393216, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"execute": "job-cancel", "arguments": {"id": "mirror_1"}}
++{"return": {}}
++{"data": {"id": "mirror_1", "type": "mirror"}, "event": "BLOCK_JOB_PENDING", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "mirror_1", "len": 393216, "offset": 393216, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_CANCELLED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 393216,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 6 dirty sectors; have 6. OK!
++
++--- Reference mirror #2 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_2", "sync": "full", "target": "ref_target_2"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_2"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++--- Test mirror #2 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_2", "sync": "bitmap", "target": "mirror_target_2"}}
++{"return": {}}
++--- Write #2 ---
++
++write -P0x74 0x0010000 0x10000
++{"return": ""}
++write -P0x69 0x00e8000 0x10000
++{"return": ""}
++write -P0x6e 0x2018000 0x10000
++{"return": ""}
++write -P0x67 0x3fe0000 0x20000
++{"return": ""}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 262144,
++        "granularity": 65536,
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      },
++      {
++        "busy": true,
++        "count": 655360,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "locked"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 10 dirty sectors; have 10. OK!
++
++= Checking Bitmap bitmap0 =
++expecting 10 dirty sectors; have 10. OK!
++
++--- Write #3 ---
++
++write -P0xaa 0x0010000 0x30000
++{"return": ""}
++write -P0xbb 0x00d8000 0x10000
++{"return": ""}
++write -P0xcc 0x2028000 0x10000
++{"return": ""}
++write -P0xdd 0x3fc0000 0x10000
++{"return": ""}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 983040,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 15 dirty sectors; have 15. OK!
++
++--- Reference mirror #3 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_3", "sync": "full", "target": "ref_target_3"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_3"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++--- Test mirror #3 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_3", "sync": "bitmap", "target": "mirror_target_3"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "mirror_3"}}
++{"return": {}}
++{"data": {"device": "mirror_3", "len": 983040, "offset": 983040, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"execute": "job-finalize", "arguments": {"id": "mirror_3"}}
++{"return": {}}
++{"data": {"id": "mirror_3", "type": "mirror"}, "event": "BLOCK_JOB_PENDING", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "mirror_3", "len": 983040, "offset": 983040, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 983040,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 15 dirty sectors; have 15. OK!
++
++--- Cleanup ---
++
++{"execute": "block-dirty-bitmap-remove", "arguments": {"name": "bitmap0", "node": "drive0"}}
++{"return": {}}
++{
++  "bitmaps": {}
++}
++
++--- Verification ---
++
++qemu_img compare "TEST_DIR/PID-bsync1" "TEST_DIR/PID-fmirror1" ==> Identical, OK!
++qemu_img compare "TEST_DIR/PID-bsync2" "TEST_DIR/PID-fmirror2" ==> Mismatch, OK!
++qemu_img compare "TEST_DIR/PID-bsync3" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
++qemu_img compare "TEST_DIR/PID-img" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
++
++
++=== Mode bitmap; Bitmap Sync never with intermediate failure ===
++
++--- Preparing image & VM ---
++
++{"execute": "blockdev-add", "arguments": {"driver": "qcow2", "file": {"driver": "blkdebug", "image": {"driver": "file", "filename": "TEST_DIR/PID-img"}, "inject-error": [{"errno": 5, "event": "read_aio", "immediately": false, "once": true, "state": 3}, {"errno": 5, "event": "read_aio", "immediately": false, "once": true, "state": 4}], "set-state": [{"event": "flush_to_disk", "new-state": 2, "state": 1}, {"event": "read_aio", "new-state": 3, "state": 2}, {"event": "read_aio", "new-state": 4, "state": 3}]}, "node-name": "drive0"}}
++{"return": {}}
++
++--- Write #0 ---
++
++write -P0x49 0x0000000 0x10000
++{"return": ""}
++write -P0x6c 0x0100000 0x10000
++{"return": ""}
++write -P0x6f 0x2000000 0x10000
++{"return": ""}
++write -P0x76 0x3ff0000 0x10000
++{"return": ""}
++{
++  "bitmaps": {}
++}
++
++--- Reference mirror #0 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_0", "sync": "full", "target": "ref_target_0"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_0"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++--- Add Bitmap ---
++
++{"execute": "block-dirty-bitmap-add", "arguments": {"granularity": 65536, "name": "bitmap0", "node": "drive0"}}
++{"return": {}}
++
++--- Write #1 ---
++
++write -P0x65 0x0000000 0x10000
++{"return": ""}
++write -P0x77 0x00f8000 0x10000
++{"return": ""}
++write -P0x72 0x2008000 0x10000
++{"return": ""}
++write -P0x69 0x3fe0000 0x10000
++{"return": ""}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 393216,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 6 dirty sectors; have 6. OK!
++
++--- Reference mirror #1 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_1", "sync": "full", "target": "ref_target_1"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_1"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++{"return": ""}
++
++--- Test mirror #1 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_1", "sync": "bitmap", "target": "mirror_target_1"}}
++{"return": {}}
++{"data": {"action": "report", "device": "mirror_1", "operation": "read"}, "event": "BLOCK_JOB_ERROR", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"action": "report", "device": "mirror_1", "operation": "read"}, "event": "BLOCK_JOB_ERROR", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "mirror_1", "error": "Input/output error", "len": 393216, "offset": 65536, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 393216,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 6 dirty sectors; have 6. OK!
++
++--- Reference mirror #2 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_2", "sync": "full", "target": "ref_target_2"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_2"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++--- Test mirror #2 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_2", "sync": "bitmap", "target": "mirror_target_2"}}
++{"return": {}}
++--- Write #2 ---
++
++write -P0x74 0x0010000 0x10000
++{"return": ""}
++write -P0x69 0x00e8000 0x10000
++{"return": ""}
++write -P0x6e 0x2018000 0x10000
++{"return": ""}
++write -P0x67 0x3fe0000 0x20000
++{"return": ""}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 262144,
++        "granularity": 65536,
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      },
++      {
++        "busy": true,
++        "count": 655360,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "locked"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 10 dirty sectors; have 10. OK!
++
++= Checking Bitmap bitmap0 =
++expecting 10 dirty sectors; have 10. OK!
++
++--- Write #3 ---
++
++write -P0xaa 0x0010000 0x30000
++{"return": ""}
++write -P0xbb 0x00d8000 0x10000
++{"return": ""}
++write -P0xcc 0x2028000 0x10000
++{"return": ""}
++write -P0xdd 0x3fc0000 0x10000
++{"return": ""}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 983040,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 15 dirty sectors; have 15. OK!
++
++--- Reference mirror #3 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_3", "sync": "full", "target": "ref_target_3"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_3"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++--- Test mirror #3 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_3", "sync": "bitmap", "target": "mirror_target_3"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "mirror_3"}}
++{"return": {}}
++{"data": {"device": "mirror_3", "len": 983040, "offset": 983040, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"execute": "job-finalize", "arguments": {"id": "mirror_3"}}
++{"return": {}}
++{"data": {"id": "mirror_3", "type": "mirror"}, "event": "BLOCK_JOB_PENDING", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "mirror_3", "len": 983040, "offset": 983040, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 983040,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 15 dirty sectors; have 15. OK!
++
++--- Cleanup ---
++
++{"execute": "block-dirty-bitmap-remove", "arguments": {"name": "bitmap0", "node": "drive0"}}
++{"return": {}}
++{
++  "bitmaps": {}
++}
++
++--- Verification ---
++
++qemu_img compare "TEST_DIR/PID-bsync1" "TEST_DIR/PID-fmirror1" ==> Mismatch, OK!
++qemu_img compare "TEST_DIR/PID-bsync2" "TEST_DIR/PID-fmirror2" ==> Mismatch, OK!
++qemu_img compare "TEST_DIR/PID-bsync3" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
++qemu_img compare "TEST_DIR/PID-img" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
++
++
++=== Mode bitmap; Bitmap Sync never without failure ===
++
++--- Preparing image & VM ---
++
++{"execute": "blockdev-add", "arguments": {"driver": "qcow2", "file": {"driver": "file", "filename": "TEST_DIR/PID-img"}, "node-name": "drive0"}}
++{"return": {}}
++
++--- Write #0 ---
++
++write -P0x49 0x0000000 0x10000
++{"return": ""}
++write -P0x6c 0x0100000 0x10000
++{"return": ""}
++write -P0x6f 0x2000000 0x10000
++{"return": ""}
++write -P0x76 0x3ff0000 0x10000
++{"return": ""}
++{
++  "bitmaps": {}
++}
++
++--- Reference mirror #0 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_0", "sync": "full", "target": "ref_target_0"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_0"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++--- Add Bitmap ---
++
++{"execute": "block-dirty-bitmap-add", "arguments": {"granularity": 65536, "name": "bitmap0", "node": "drive0"}}
++{"return": {}}
++
++--- Write #1 ---
++
++write -P0x65 0x0000000 0x10000
++{"return": ""}
++write -P0x77 0x00f8000 0x10000
++{"return": ""}
++write -P0x72 0x2008000 0x10000
++{"return": ""}
++write -P0x69 0x3fe0000 0x10000
++{"return": ""}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 393216,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 6 dirty sectors; have 6. OK!
++
++--- Reference mirror #1 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_1", "sync": "full", "target": "ref_target_1"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_1"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++--- Test mirror #1 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_1", "sync": "bitmap", "target": "mirror_target_1"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "mirror_1"}}
++{"return": {}}
++{"data": {"device": "mirror_1", "len": 393216, "offset": 393216, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"execute": "job-finalize", "arguments": {"id": "mirror_1"}}
++{"return": {}}
++{"data": {"id": "mirror_1", "type": "mirror"}, "event": "BLOCK_JOB_PENDING", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "mirror_1", "len": 393216, "offset": 393216, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 393216,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 6 dirty sectors; have 6. OK!
++
++--- Reference mirror #2 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_2", "sync": "full", "target": "ref_target_2"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_2"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++--- Test mirror #2 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_2", "sync": "bitmap", "target": "mirror_target_2"}}
++{"return": {}}
++--- Write #2 ---
++
++write -P0x74 0x0010000 0x10000
++{"return": ""}
++write -P0x69 0x00e8000 0x10000
++{"return": ""}
++write -P0x6e 0x2018000 0x10000
++{"return": ""}
++write -P0x67 0x3fe0000 0x20000
++{"return": ""}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 262144,
++        "granularity": 65536,
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      },
++      {
++        "busy": true,
++        "count": 655360,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "locked"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 10 dirty sectors; have 10. OK!
++
++= Checking Bitmap bitmap0 =
++expecting 10 dirty sectors; have 10. OK!
++
++--- Write #3 ---
++
++write -P0xaa 0x0010000 0x30000
++{"return": ""}
++write -P0xbb 0x00d8000 0x10000
++{"return": ""}
++write -P0xcc 0x2028000 0x10000
++{"return": ""}
++write -P0xdd 0x3fc0000 0x10000
++{"return": ""}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 983040,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 15 dirty sectors; have 15. OK!
++
++--- Reference mirror #3 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_3", "sync": "full", "target": "ref_target_3"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_3"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++--- Test mirror #3 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_3", "sync": "bitmap", "target": "mirror_target_3"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "mirror_3"}}
++{"return": {}}
++{"data": {"device": "mirror_3", "len": 983040, "offset": 983040, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"execute": "job-finalize", "arguments": {"id": "mirror_3"}}
++{"return": {}}
++{"data": {"id": "mirror_3", "type": "mirror"}, "event": "BLOCK_JOB_PENDING", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "mirror_3", "len": 983040, "offset": 983040, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 983040,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 15 dirty sectors; have 15. OK!
++
++--- Cleanup ---
++
++{"execute": "block-dirty-bitmap-remove", "arguments": {"name": "bitmap0", "node": "drive0"}}
++{"return": {}}
++{
++  "bitmaps": {}
++}
++
++--- Verification ---
++
++qemu_img compare "TEST_DIR/PID-bsync1" "TEST_DIR/PID-fmirror1" ==> Identical, OK!
++qemu_img compare "TEST_DIR/PID-bsync2" "TEST_DIR/PID-fmirror2" ==> Mismatch, OK!
++qemu_img compare "TEST_DIR/PID-bsync3" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
++qemu_img compare "TEST_DIR/PID-img" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
++
++
++=== Mode bitmap; Bitmap Sync on-success with simulated failure ===
++
++--- Preparing image & VM ---
++
++{"execute": "blockdev-add", "arguments": {"driver": "qcow2", "file": {"driver": "file", "filename": "TEST_DIR/PID-img"}, "node-name": "drive0"}}
++{"return": {}}
++
++--- Write #0 ---
++
++write -P0x49 0x0000000 0x10000
++{"return": ""}
++write -P0x6c 0x0100000 0x10000
++{"return": ""}
++write -P0x6f 0x2000000 0x10000
++{"return": ""}
++write -P0x76 0x3ff0000 0x10000
++{"return": ""}
++{
++  "bitmaps": {}
++}
++
++--- Reference mirror #0 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_0", "sync": "full", "target": "ref_target_0"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_0"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++--- Add Bitmap ---
++
++{"execute": "block-dirty-bitmap-add", "arguments": {"granularity": 65536, "name": "bitmap0", "node": "drive0"}}
++{"return": {}}
++
++--- Write #1 ---
++
++write -P0x65 0x0000000 0x10000
++{"return": ""}
++write -P0x77 0x00f8000 0x10000
++{"return": ""}
++write -P0x72 0x2008000 0x10000
++{"return": ""}
++write -P0x69 0x3fe0000 0x10000
++{"return": ""}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 393216,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 6 dirty sectors; have 6. OK!
++
++--- Reference mirror #1 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_1", "sync": "full", "target": "ref_target_1"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_1"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++--- Test mirror #1 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_1", "sync": "bitmap", "target": "mirror_target_1"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "mirror_1"}}
++{"return": {}}
++{"data": {"device": "mirror_1", "len": 393216, "offset": 393216, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"execute": "job-cancel", "arguments": {"id": "mirror_1"}}
++{"return": {}}
++{"data": {"id": "mirror_1", "type": "mirror"}, "event": "BLOCK_JOB_PENDING", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "mirror_1", "len": 393216, "offset": 393216, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_CANCELLED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 393216,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 6 dirty sectors; have 6. OK!
++
++--- Reference mirror #2 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_2", "sync": "full", "target": "ref_target_2"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_2"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++--- Test mirror #2 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_2", "sync": "bitmap", "target": "mirror_target_2"}}
++{"return": {}}
++--- Write #2 ---
++
++write -P0x74 0x0010000 0x10000
++{"return": ""}
++write -P0x69 0x00e8000 0x10000
++{"return": ""}
++write -P0x6e 0x2018000 0x10000
++{"return": ""}
++write -P0x67 0x3fe0000 0x20000
++{"return": ""}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 262144,
++        "granularity": 65536,
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      },
++      {
++        "busy": true,
++        "count": 655360,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "locked"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 10 dirty sectors; have 10. OK!
++
++= Checking Bitmap bitmap0 =
++expecting 0 dirty sectors; have 0. OK!
++
++--- Write #3 ---
++
++write -P0xaa 0x0010000 0x30000
++{"return": ""}
++write -P0xbb 0x00d8000 0x10000
++{"return": ""}
++write -P0xcc 0x2028000 0x10000
++{"return": ""}
++write -P0xdd 0x3fc0000 0x10000
++{"return": ""}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 524288,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 8 dirty sectors; have 8. OK!
++
++--- Reference mirror #3 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_3", "sync": "full", "target": "ref_target_3"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_3"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++--- Test mirror #3 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_3", "sync": "bitmap", "target": "mirror_target_3"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "mirror_3"}}
++{"return": {}}
++{"data": {"device": "mirror_3", "len": 524288, "offset": 524288, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"execute": "job-finalize", "arguments": {"id": "mirror_3"}}
++{"return": {}}
++{"data": {"id": "mirror_3", "type": "mirror"}, "event": "BLOCK_JOB_PENDING", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "mirror_3", "len": 524288, "offset": 524288, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 0,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 0 dirty sectors; have 0. OK!
++
++--- Cleanup ---
++
++{"execute": "block-dirty-bitmap-remove", "arguments": {"name": "bitmap0", "node": "drive0"}}
++{"return": {}}
++{
++  "bitmaps": {}
++}
++
++--- Verification ---
++
++qemu_img compare "TEST_DIR/PID-bsync1" "TEST_DIR/PID-fmirror1" ==> Identical, OK!
++qemu_img compare "TEST_DIR/PID-bsync2" "TEST_DIR/PID-fmirror2" ==> Mismatch, OK!
++qemu_img compare "TEST_DIR/PID-bsync3" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
++qemu_img compare "TEST_DIR/PID-img" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
++
++
++=== Mode bitmap; Bitmap Sync on-success with intermediate failure ===
++
++--- Preparing image & VM ---
++
++{"execute": "blockdev-add", "arguments": {"driver": "qcow2", "file": {"driver": "blkdebug", "image": {"driver": "file", "filename": "TEST_DIR/PID-img"}, "inject-error": [{"errno": 5, "event": "read_aio", "immediately": false, "once": true, "state": 3}, {"errno": 5, "event": "read_aio", "immediately": false, "once": true, "state": 4}], "set-state": [{"event": "flush_to_disk", "new-state": 2, "state": 1}, {"event": "read_aio", "new-state": 3, "state": 2}, {"event": "read_aio", "new-state": 4, "state": 3}]}, "node-name": "drive0"}}
++{"return": {}}
++
++--- Write #0 ---
++
++write -P0x49 0x0000000 0x10000
++{"return": ""}
++write -P0x6c 0x0100000 0x10000
++{"return": ""}
++write -P0x6f 0x2000000 0x10000
++{"return": ""}
++write -P0x76 0x3ff0000 0x10000
++{"return": ""}
++{
++  "bitmaps": {}
++}
++
++--- Reference mirror #0 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_0", "sync": "full", "target": "ref_target_0"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_0"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++--- Add Bitmap ---
++
++{"execute": "block-dirty-bitmap-add", "arguments": {"granularity": 65536, "name": "bitmap0", "node": "drive0"}}
++{"return": {}}
++
++--- Write #1 ---
++
++write -P0x65 0x0000000 0x10000
++{"return": ""}
++write -P0x77 0x00f8000 0x10000
++{"return": ""}
++write -P0x72 0x2008000 0x10000
++{"return": ""}
++write -P0x69 0x3fe0000 0x10000
++{"return": ""}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 393216,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 6 dirty sectors; have 6. OK!
++
++--- Reference mirror #1 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_1", "sync": "full", "target": "ref_target_1"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_1"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++{"return": ""}
++
++--- Test mirror #1 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_1", "sync": "bitmap", "target": "mirror_target_1"}}
++{"return": {}}
++{"data": {"action": "report", "device": "mirror_1", "operation": "read"}, "event": "BLOCK_JOB_ERROR", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"action": "report", "device": "mirror_1", "operation": "read"}, "event": "BLOCK_JOB_ERROR", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "mirror_1", "error": "Input/output error", "len": 393216, "offset": 65536, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 393216,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 6 dirty sectors; have 6. OK!
++
++--- Reference mirror #2 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_2", "sync": "full", "target": "ref_target_2"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_2"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++--- Test mirror #2 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_2", "sync": "bitmap", "target": "mirror_target_2"}}
++{"return": {}}
++--- Write #2 ---
++
++write -P0x74 0x0010000 0x10000
++{"return": ""}
++write -P0x69 0x00e8000 0x10000
++{"return": ""}
++write -P0x6e 0x2018000 0x10000
++{"return": ""}
++write -P0x67 0x3fe0000 0x20000
++{"return": ""}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 262144,
++        "granularity": 65536,
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      },
++      {
++        "busy": true,
++        "count": 655360,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "locked"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 10 dirty sectors; have 10. OK!
++
++= Checking Bitmap bitmap0 =
++expecting 0 dirty sectors; have 0. OK!
++
++--- Write #3 ---
++
++write -P0xaa 0x0010000 0x30000
++{"return": ""}
++write -P0xbb 0x00d8000 0x10000
++{"return": ""}
++write -P0xcc 0x2028000 0x10000
++{"return": ""}
++write -P0xdd 0x3fc0000 0x10000
++{"return": ""}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 524288,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 8 dirty sectors; have 8. OK!
++
++--- Reference mirror #3 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_3", "sync": "full", "target": "ref_target_3"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_3"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++--- Test mirror #3 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_3", "sync": "bitmap", "target": "mirror_target_3"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "mirror_3"}}
++{"return": {}}
++{"data": {"device": "mirror_3", "len": 524288, "offset": 524288, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"execute": "job-finalize", "arguments": {"id": "mirror_3"}}
++{"return": {}}
++{"data": {"id": "mirror_3", "type": "mirror"}, "event": "BLOCK_JOB_PENDING", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "mirror_3", "len": 524288, "offset": 524288, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 0,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 0 dirty sectors; have 0. OK!
++
++--- Cleanup ---
++
++{"execute": "block-dirty-bitmap-remove", "arguments": {"name": "bitmap0", "node": "drive0"}}
++{"return": {}}
++{
++  "bitmaps": {}
++}
++
++--- Verification ---
++
++qemu_img compare "TEST_DIR/PID-bsync1" "TEST_DIR/PID-fmirror1" ==> Mismatch, OK!
++qemu_img compare "TEST_DIR/PID-bsync2" "TEST_DIR/PID-fmirror2" ==> Mismatch, OK!
++qemu_img compare "TEST_DIR/PID-bsync3" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
++qemu_img compare "TEST_DIR/PID-img" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
++
++
++=== Mode bitmap; Bitmap Sync on-success without failure ===
++
++--- Preparing image & VM ---
++
++{"execute": "blockdev-add", "arguments": {"driver": "qcow2", "file": {"driver": "file", "filename": "TEST_DIR/PID-img"}, "node-name": "drive0"}}
++{"return": {}}
++
++--- Write #0 ---
++
++write -P0x49 0x0000000 0x10000
++{"return": ""}
++write -P0x6c 0x0100000 0x10000
++{"return": ""}
++write -P0x6f 0x2000000 0x10000
++{"return": ""}
++write -P0x76 0x3ff0000 0x10000
++{"return": ""}
++{
++  "bitmaps": {}
++}
++
++--- Reference mirror #0 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_0", "sync": "full", "target": "ref_target_0"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_0"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++--- Add Bitmap ---
++
++{"execute": "block-dirty-bitmap-add", "arguments": {"granularity": 65536, "name": "bitmap0", "node": "drive0"}}
++{"return": {}}
++
++--- Write #1 ---
++
++write -P0x65 0x0000000 0x10000
++{"return": ""}
++write -P0x77 0x00f8000 0x10000
++{"return": ""}
++write -P0x72 0x2008000 0x10000
++{"return": ""}
++write -P0x69 0x3fe0000 0x10000
++{"return": ""}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 393216,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 6 dirty sectors; have 6. OK!
++
++--- Reference mirror #1 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_1", "sync": "full", "target": "ref_target_1"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_1"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++--- Test mirror #1 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_1", "sync": "bitmap", "target": "mirror_target_1"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "mirror_1"}}
++{"return": {}}
++{"data": {"device": "mirror_1", "len": 393216, "offset": 393216, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"execute": "job-finalize", "arguments": {"id": "mirror_1"}}
++{"return": {}}
++{"data": {"id": "mirror_1", "type": "mirror"}, "event": "BLOCK_JOB_PENDING", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "mirror_1", "len": 393216, "offset": 393216, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 0,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 0 dirty sectors; have 0. OK!
++
++--- Reference mirror #2 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_2", "sync": "full", "target": "ref_target_2"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_2"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++--- Test mirror #2 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_2", "sync": "bitmap", "target": "mirror_target_2"}}
++{"return": {}}
++--- Write #2 ---
++
++write -P0x74 0x0010000 0x10000
++{"return": ""}
++write -P0x69 0x00e8000 0x10000
++{"return": ""}
++write -P0x6e 0x2018000 0x10000
++{"return": ""}
++write -P0x67 0x3fe0000 0x20000
++{"return": ""}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 458752,
++        "granularity": 65536,
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      },
++      {
++        "busy": true,
++        "count": 458752,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "locked"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 7 dirty sectors; have 7. OK!
++
++= Checking Bitmap bitmap0 =
++expecting 0 dirty sectors; have 0. OK!
++
++--- Write #3 ---
++
++write -P0xaa 0x0010000 0x30000
++{"return": ""}
++write -P0xbb 0x00d8000 0x10000
++{"return": ""}
++write -P0xcc 0x2028000 0x10000
++{"return": ""}
++write -P0xdd 0x3fc0000 0x10000
++{"return": ""}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 524288,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 8 dirty sectors; have 8. OK!
++
++--- Reference mirror #3 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_3", "sync": "full", "target": "ref_target_3"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_3"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++--- Test mirror #3 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_3", "sync": "bitmap", "target": "mirror_target_3"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "mirror_3"}}
++{"return": {}}
++{"data": {"device": "mirror_3", "len": 524288, "offset": 524288, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"execute": "job-finalize", "arguments": {"id": "mirror_3"}}
++{"return": {}}
++{"data": {"id": "mirror_3", "type": "mirror"}, "event": "BLOCK_JOB_PENDING", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "mirror_3", "len": 524288, "offset": 524288, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 0,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 0 dirty sectors; have 0. OK!
++
++--- Cleanup ---
++
++{"execute": "block-dirty-bitmap-remove", "arguments": {"name": "bitmap0", "node": "drive0"}}
++{"return": {}}
++{
++  "bitmaps": {}
++}
++
++--- Verification ---
++
++qemu_img compare "TEST_DIR/PID-bsync1" "TEST_DIR/PID-fmirror1" ==> Identical, OK!
++qemu_img compare "TEST_DIR/PID-bsync2" "TEST_DIR/PID-fmirror2" ==> Mismatch, OK!
++qemu_img compare "TEST_DIR/PID-bsync3" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
++qemu_img compare "TEST_DIR/PID-img" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
++
++
++=== Mode bitmap; Bitmap Sync always with simulated failure ===
++
++--- Preparing image & VM ---
++
++{"execute": "blockdev-add", "arguments": {"driver": "qcow2", "file": {"driver": "file", "filename": "TEST_DIR/PID-img"}, "node-name": "drive0"}}
++{"return": {}}
++
++--- Write #0 ---
++
++write -P0x49 0x0000000 0x10000
++{"return": ""}
++write -P0x6c 0x0100000 0x10000
++{"return": ""}
++write -P0x6f 0x2000000 0x10000
++{"return": ""}
++write -P0x76 0x3ff0000 0x10000
++{"return": ""}
++{
++  "bitmaps": {}
++}
++
++--- Reference mirror #0 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_0", "sync": "full", "target": "ref_target_0"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_0"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++--- Add Bitmap ---
++
++{"execute": "block-dirty-bitmap-add", "arguments": {"granularity": 65536, "name": "bitmap0", "node": "drive0"}}
++{"return": {}}
++
++--- Write #1 ---
++
++write -P0x65 0x0000000 0x10000
++{"return": ""}
++write -P0x77 0x00f8000 0x10000
++{"return": ""}
++write -P0x72 0x2008000 0x10000
++{"return": ""}
++write -P0x69 0x3fe0000 0x10000
++{"return": ""}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 393216,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 6 dirty sectors; have 6. OK!
++
++--- Reference mirror #1 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_1", "sync": "full", "target": "ref_target_1"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_1"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++--- Test mirror #1 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_1", "sync": "bitmap", "target": "mirror_target_1"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "mirror_1"}}
++{"return": {}}
++{"data": {"device": "mirror_1", "len": 393216, "offset": 393216, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"execute": "job-cancel", "arguments": {"id": "mirror_1"}}
++{"return": {}}
++{"data": {"id": "mirror_1", "type": "mirror"}, "event": "BLOCK_JOB_PENDING", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "mirror_1", "len": 393216, "offset": 393216, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_CANCELLED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 0,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 0 dirty sectors; have 0. OK!
++
++--- Reference mirror #2 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_2", "sync": "full", "target": "ref_target_2"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_2"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++--- Test mirror #2 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_2", "sync": "bitmap", "target": "mirror_target_2"}}
++{"return": {}}
++--- Write #2 ---
++
++write -P0x74 0x0010000 0x10000
++{"return": ""}
++write -P0x69 0x00e8000 0x10000
++{"return": ""}
++write -P0x6e 0x2018000 0x10000
++{"return": ""}
++write -P0x67 0x3fe0000 0x20000
++{"return": ""}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 458752,
++        "granularity": 65536,
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      },
++      {
++        "busy": true,
++        "count": 458752,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "locked"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 7 dirty sectors; have 7. OK!
++
++= Checking Bitmap bitmap0 =
++expecting 0 dirty sectors; have 0. OK!
++
++--- Write #3 ---
++
++write -P0xaa 0x0010000 0x30000
++{"return": ""}
++write -P0xbb 0x00d8000 0x10000
++{"return": ""}
++write -P0xcc 0x2028000 0x10000
++{"return": ""}
++write -P0xdd 0x3fc0000 0x10000
++{"return": ""}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 524288,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 8 dirty sectors; have 8. OK!
++
++--- Reference mirror #3 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_3", "sync": "full", "target": "ref_target_3"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_3"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++--- Test mirror #3 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_3", "sync": "bitmap", "target": "mirror_target_3"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "mirror_3"}}
++{"return": {}}
++{"data": {"device": "mirror_3", "len": 524288, "offset": 524288, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"execute": "job-finalize", "arguments": {"id": "mirror_3"}}
++{"return": {}}
++{"data": {"id": "mirror_3", "type": "mirror"}, "event": "BLOCK_JOB_PENDING", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "mirror_3", "len": 524288, "offset": 524288, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 0,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 0 dirty sectors; have 0. OK!
++
++--- Cleanup ---
++
++{"execute": "block-dirty-bitmap-remove", "arguments": {"name": "bitmap0", "node": "drive0"}}
++{"return": {}}
++{
++  "bitmaps": {}
++}
++
++--- Verification ---
++
++qemu_img compare "TEST_DIR/PID-bsync1" "TEST_DIR/PID-fmirror1" ==> Identical, OK!
++qemu_img compare "TEST_DIR/PID-bsync2" "TEST_DIR/PID-fmirror2" ==> Mismatch, OK!
++qemu_img compare "TEST_DIR/PID-bsync3" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
++qemu_img compare "TEST_DIR/PID-img" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
++
++
++=== Mode bitmap; Bitmap Sync always with intermediate failure ===
++
++--- Preparing image & VM ---
++
++{"execute": "blockdev-add", "arguments": {"driver": "qcow2", "file": {"driver": "blkdebug", "image": {"driver": "file", "filename": "TEST_DIR/PID-img"}, "inject-error": [{"errno": 5, "event": "read_aio", "immediately": false, "once": true, "state": 3}, {"errno": 5, "event": "read_aio", "immediately": false, "once": true, "state": 4}], "set-state": [{"event": "flush_to_disk", "new-state": 2, "state": 1}, {"event": "read_aio", "new-state": 3, "state": 2}, {"event": "read_aio", "new-state": 4, "state": 3}]}, "node-name": "drive0"}}
++{"return": {}}
++
++--- Write #0 ---
++
++write -P0x49 0x0000000 0x10000
++{"return": ""}
++write -P0x6c 0x0100000 0x10000
++{"return": ""}
++write -P0x6f 0x2000000 0x10000
++{"return": ""}
++write -P0x76 0x3ff0000 0x10000
++{"return": ""}
++{
++  "bitmaps": {}
++}
++
++--- Reference mirror #0 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_0", "sync": "full", "target": "ref_target_0"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_0"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++--- Add Bitmap ---
++
++{"execute": "block-dirty-bitmap-add", "arguments": {"granularity": 65536, "name": "bitmap0", "node": "drive0"}}
++{"return": {}}
++
++--- Write #1 ---
++
++write -P0x65 0x0000000 0x10000
++{"return": ""}
++write -P0x77 0x00f8000 0x10000
++{"return": ""}
++write -P0x72 0x2008000 0x10000
++{"return": ""}
++write -P0x69 0x3fe0000 0x10000
++{"return": ""}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 393216,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 6 dirty sectors; have 6. OK!
++
++--- Reference mirror #1 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_1", "sync": "full", "target": "ref_target_1"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_1"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++{"return": ""}
++
++--- Test mirror #1 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_1", "sync": "bitmap", "target": "mirror_target_1"}}
++{"return": {}}
++{"data": {"action": "report", "device": "mirror_1", "operation": "read"}, "event": "BLOCK_JOB_ERROR", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"action": "report", "device": "mirror_1", "operation": "read"}, "event": "BLOCK_JOB_ERROR", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "mirror_1", "error": "Input/output error", "len": 393216, "offset": 65536, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 327680,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 5 dirty sectors; have 5. OK!
++
++--- Reference mirror #2 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_2", "sync": "full", "target": "ref_target_2"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_2"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++--- Test mirror #2 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_2", "sync": "bitmap", "target": "mirror_target_2"}}
++{"return": {}}
++--- Write #2 ---
++
++write -P0x74 0x0010000 0x10000
++{"return": ""}
++write -P0x69 0x00e8000 0x10000
++{"return": ""}
++write -P0x6e 0x2018000 0x10000
++{"return": ""}
++write -P0x67 0x3fe0000 0x20000
++{"return": ""}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 262144,
++        "granularity": 65536,
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      },
++      {
++        "busy": true,
++        "count": 589824,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "locked"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 9 dirty sectors; have 9. OK!
++
++= Checking Bitmap bitmap0 =
++expecting 0 dirty sectors; have 0. OK!
++
++--- Write #3 ---
++
++write -P0xaa 0x0010000 0x30000
++{"return": ""}
++write -P0xbb 0x00d8000 0x10000
++{"return": ""}
++write -P0xcc 0x2028000 0x10000
++{"return": ""}
++write -P0xdd 0x3fc0000 0x10000
++{"return": ""}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 524288,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 8 dirty sectors; have 8. OK!
++
++--- Reference mirror #3 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_3", "sync": "full", "target": "ref_target_3"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_3"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++--- Test mirror #3 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_3", "sync": "bitmap", "target": "mirror_target_3"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "mirror_3"}}
++{"return": {}}
++{"data": {"device": "mirror_3", "len": 524288, "offset": 524288, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"execute": "job-finalize", "arguments": {"id": "mirror_3"}}
++{"return": {}}
++{"data": {"id": "mirror_3", "type": "mirror"}, "event": "BLOCK_JOB_PENDING", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "mirror_3", "len": 524288, "offset": 524288, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 0,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 0 dirty sectors; have 0. OK!
++
++--- Cleanup ---
++
++{"execute": "block-dirty-bitmap-remove", "arguments": {"name": "bitmap0", "node": "drive0"}}
++{"return": {}}
++{
++  "bitmaps": {}
++}
++
++--- Verification ---
++
++qemu_img compare "TEST_DIR/PID-bsync1" "TEST_DIR/PID-fmirror1" ==> Mismatch, OK!
++qemu_img compare "TEST_DIR/PID-bsync2" "TEST_DIR/PID-fmirror2" ==> Mismatch, OK!
++qemu_img compare "TEST_DIR/PID-bsync3" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
++qemu_img compare "TEST_DIR/PID-img" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
++
++
++=== Mode bitmap; Bitmap Sync always without failure ===
++
++--- Preparing image & VM ---
++
++{"execute": "blockdev-add", "arguments": {"driver": "qcow2", "file": {"driver": "file", "filename": "TEST_DIR/PID-img"}, "node-name": "drive0"}}
++{"return": {}}
++
++--- Write #0 ---
++
++write -P0x49 0x0000000 0x10000
++{"return": ""}
++write -P0x6c 0x0100000 0x10000
++{"return": ""}
++write -P0x6f 0x2000000 0x10000
++{"return": ""}
++write -P0x76 0x3ff0000 0x10000
++{"return": ""}
++{
++  "bitmaps": {}
++}
++
++--- Reference mirror #0 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_0", "sync": "full", "target": "ref_target_0"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_0"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++--- Add Bitmap ---
++
++{"execute": "block-dirty-bitmap-add", "arguments": {"granularity": 65536, "name": "bitmap0", "node": "drive0"}}
++{"return": {}}
++
++--- Write #1 ---
++
++write -P0x65 0x0000000 0x10000
++{"return": ""}
++write -P0x77 0x00f8000 0x10000
++{"return": ""}
++write -P0x72 0x2008000 0x10000
++{"return": ""}
++write -P0x69 0x3fe0000 0x10000
++{"return": ""}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 393216,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 6 dirty sectors; have 6. OK!
++
++--- Reference mirror #1 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_1", "sync": "full", "target": "ref_target_1"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_1"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++--- Test mirror #1 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_1", "sync": "bitmap", "target": "mirror_target_1"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "mirror_1"}}
++{"return": {}}
++{"data": {"device": "mirror_1", "len": 393216, "offset": 393216, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"execute": "job-finalize", "arguments": {"id": "mirror_1"}}
++{"return": {}}
++{"data": {"id": "mirror_1", "type": "mirror"}, "event": "BLOCK_JOB_PENDING", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "mirror_1", "len": 393216, "offset": 393216, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 0,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 0 dirty sectors; have 0. OK!
++
++--- Reference mirror #2 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_2", "sync": "full", "target": "ref_target_2"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_2"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++--- Test mirror #2 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_2", "sync": "bitmap", "target": "mirror_target_2"}}
++{"return": {}}
++--- Write #2 ---
++
++write -P0x74 0x0010000 0x10000
++{"return": ""}
++write -P0x69 0x00e8000 0x10000
++{"return": ""}
++write -P0x6e 0x2018000 0x10000
++{"return": ""}
++write -P0x67 0x3fe0000 0x20000
++{"return": ""}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 458752,
++        "granularity": 65536,
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      },
++      {
++        "busy": true,
++        "count": 458752,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "locked"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 7 dirty sectors; have 7. OK!
++
++= Checking Bitmap bitmap0 =
++expecting 0 dirty sectors; have 0. OK!
++
++--- Write #3 ---
++
++write -P0xaa 0x0010000 0x30000
++{"return": ""}
++write -P0xbb 0x00d8000 0x10000
++{"return": ""}
++write -P0xcc 0x2028000 0x10000
++{"return": ""}
++write -P0xdd 0x3fc0000 0x10000
++{"return": ""}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 524288,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 8 dirty sectors; have 8. OK!
++
++--- Reference mirror #3 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_3", "sync": "full", "target": "ref_target_3"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "ref_mirror_3"}}
++{"return": {}}
++{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++
++--- Test mirror #3 ---
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_3", "sync": "bitmap", "target": "mirror_target_3"}}
++{"return": {}}
++{"execute": "job-complete", "arguments": {"id": "mirror_3"}}
++{"return": {}}
++{"data": {"device": "mirror_3", "len": 524288, "offset": 524288, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"execute": "job-finalize", "arguments": {"id": "mirror_3"}}
++{"return": {}}
++{"data": {"id": "mirror_3", "type": "mirror"}, "event": "BLOCK_JOB_PENDING", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{"data": {"device": "mirror_3", "len": 524288, "offset": 524288, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
++{
++  "bitmaps": {
++    "drive0": [
++      {
++        "busy": false,
++        "count": 0,
++        "granularity": 65536,
++        "name": "bitmap0",
++        "persistent": false,
++        "recording": true,
++        "status": "active"
++      }
++    ]
++  }
++}
++
++= Checking Bitmap bitmap0 =
++expecting 0 dirty sectors; have 0. OK!
++
++--- Cleanup ---
++
++{"execute": "block-dirty-bitmap-remove", "arguments": {"name": "bitmap0", "node": "drive0"}}
++{"return": {}}
++{
++  "bitmaps": {}
++}
++
++--- Verification ---
++
++qemu_img compare "TEST_DIR/PID-bsync1" "TEST_DIR/PID-fmirror1" ==> Identical, OK!
++qemu_img compare "TEST_DIR/PID-bsync2" "TEST_DIR/PID-fmirror2" ==> Mismatch, OK!
++qemu_img compare "TEST_DIR/PID-bsync3" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
++qemu_img compare "TEST_DIR/PID-img" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
++
++
++=== API failure tests ===
++
++--- Preparing image & VM ---
++
++{"execute": "blockdev-add", "arguments": {"driver": "qcow2", "file": {"driver": "file", "filename": "TEST_DIR/PID-img"}, "node-name": "drive0"}}
++{"return": {}}
++
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
++{"return": {}}
++{}
++{}
++{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
++{"return": {}}
++{}
++
++{"execute": "block-dirty-bitmap-add", "arguments": {"granularity": 65536, "name": "bitmap0", "node": "drive0"}}
++{"return": {}}
++
++-- Testing invalid QMP commands --
++
++-- Sync mode incremental tests --
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
++
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Sync mode 'incremental' not supported"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "bitmap-mode must be specified if a bitmap is provided"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Sync mode 'incremental' not supported"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Sync mode 'incremental' not supported"}}
++
++-- Sync mode bitmap tests --
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "bitmap", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "bitmap", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "bitmap", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
++
++{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "bitmap", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Must provide a valid bitmap name for 'bitmap' sync mode"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "bitmap", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "bitmap", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "bitmap", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "bitmap", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "bitmap-mode must be specified if a bitmap is provided"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "bitmap", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "bitmap-mode must be specified if a bitmap is provided"}}
++
++-- Sync mode full tests --
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "bitmap-mode must be specified if a bitmap is provided"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "sync mode 'full' is not compatible with bitmaps"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "sync mode 'full' is not compatible with bitmaps"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "sync mode 'full' is not compatible with bitmaps"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "bitmap-mode must be specified if a bitmap is provided"}}
++
++-- Sync mode top tests --
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "bitmap-mode must be specified if a bitmap is provided"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "sync mode 'full' is not compatible with bitmaps"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "sync mode 'full' is not compatible with bitmaps"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "sync mode 'full' is not compatible with bitmaps"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "bitmap-mode must be specified if a bitmap is provided"}}
++
++-- Sync mode none tests --
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "bitmap-mode must be specified if a bitmap is provided"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "sync mode 'none' is not compatible with bitmaps"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "sync mode 'none' is not compatible with bitmaps"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "sync mode 'none' is not compatible with bitmaps"}}
++
++{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
++{"error": {"class": "GenericError", "desc": "bitmap-mode must be specified if a bitmap is provided"}}
++
+diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
+index 2960dff728..952dceba1f 100644
+--- a/tests/qemu-iotests/group
++++ b/tests/qemu-iotests/group
+@@ -270,6 +270,7 @@
+ 253 rw quick
+ 254 rw backing quick
+ 255 rw quick
++384 rw
+ 256 rw auto quick
+ 257 rw
+ 258 rw quick
diff --git a/debian/patches/pve/0034-mirror-switch-to-bdrv_dirty_bitmap_merge_internal.patch b/debian/patches/pve/0034-mirror-switch-to-bdrv_dirty_bitmap_merge_internal.patch
deleted file mode 100644 (file)
index 8b3c1e2..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= <f.gruenbichler@proxmox.com>
-Date: Mon, 6 Apr 2020 12:17:06 +0200
-Subject: [PATCH] mirror: switch to bdrv_dirty_bitmap_merge_internal
-MIME-Version: 1.0
-Content-Type: text/plain; charset=UTF-8
-Content-Transfer-Encoding: 8bit
-
-since sync_bitmap is busy at the point of merging, and we checked access
-beforehand.
-
-Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
----
- block/mirror.c | 8 ++++----
- 1 file changed, 4 insertions(+), 4 deletions(-)
-
-diff --git a/block/mirror.c b/block/mirror.c
-index d1cce079da..e6140cf018 100644
---- a/block/mirror.c
-+++ b/block/mirror.c
-@@ -759,8 +759,8 @@ static int mirror_exit_common(Job *job)
-              job->ret == 0 && ret == 0)) {
-             /* Success; synchronize copy back to sync. */
-             bdrv_clear_dirty_bitmap(s->sync_bitmap, NULL);
--            bdrv_merge_dirty_bitmap(s->sync_bitmap, s->dirty_bitmap,
--                                    NULL, &error_abort);
-+            bdrv_dirty_bitmap_merge_internal(s->sync_bitmap, s->dirty_bitmap,
-+                                             NULL, true);
-         }
-     }
-     bdrv_release_dirty_bitmap(s->dirty_bitmap);
-@@ -1793,8 +1793,8 @@ static BlockJob *mirror_start_job(
-     }
-     if (s->sync_mode == MIRROR_SYNC_MODE_BITMAP) {
--        bdrv_merge_dirty_bitmap(s->dirty_bitmap, s->sync_bitmap,
--                                NULL, &local_err);
-+        bdrv_dirty_bitmap_merge_internal(s->dirty_bitmap, s->sync_bitmap,
-+                                         NULL, true);
-         if (local_err) {
-             goto fail;
-         }
diff --git a/debian/patches/pve/0035-iotests-add-test-for-bitmap-mirror.patch b/debian/patches/pve/0035-iotests-add-test-for-bitmap-mirror.patch
deleted file mode 100644 (file)
index 07a66d6..0000000
+++ /dev/null
@@ -1,3447 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= <f.gruenbichler@proxmox.com>
-Date: Mon, 6 Apr 2020 12:17:07 +0200
-Subject: [PATCH] iotests: add test for bitmap mirror
-MIME-Version: 1.0
-Content-Type: text/plain; charset=UTF-8
-Content-Transfer-Encoding: 8bit
-
-heavily based on/practically forked off iotest 257 for bitmap backups,
-but:
-
-- no writes to filter node 'mirror-top' between completion and
-finalization, as those seem to deadlock?
-- no inclusion of not-yet-available full/top sync modes in combination
-with bitmaps
-- extra set of reference/test mirrors to verify that writes in parallel
-with active mirror work
-
-intentionally keeping copyright and ownership of original test case to
-honor provenance.
-
-Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
----
- tests/qemu-iotests/384     |  547 +++++++
- tests/qemu-iotests/384.out | 2846 ++++++++++++++++++++++++++++++++++++
- tests/qemu-iotests/group   |    1 +
- 3 files changed, 3394 insertions(+)
- create mode 100755 tests/qemu-iotests/384
- create mode 100644 tests/qemu-iotests/384.out
-
-diff --git a/tests/qemu-iotests/384 b/tests/qemu-iotests/384
-new file mode 100755
-index 0000000000..b04a8e651a
---- /dev/null
-+++ b/tests/qemu-iotests/384
-@@ -0,0 +1,547 @@
-+#!/usr/bin/env python3
-+#
-+# Test bitmap-sync mirrors (incremental, differential, and partials)
-+#
-+# Copyright (c) 2019 John Snow for Red Hat, Inc.
-+#
-+# This program is free software; you can redistribute it and/or modify
-+# it under the terms of the GNU General Public License as published by
-+# the Free Software Foundation; either version 2 of the License, or
-+# (at your option) any later version.
-+#
-+# This program is distributed in the hope that it will be useful,
-+# but WITHOUT ANY WARRANTY; without even the implied warranty of
-+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+# GNU General Public License for more details.
-+#
-+# You should have received a copy of the GNU General Public License
-+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-+#
-+# owner=jsnow@redhat.com
-+
-+import math
-+import os
-+
-+import iotests
-+from iotests import log, qemu_img
-+
-+SIZE = 64 * 1024 * 1024
-+GRANULARITY = 64 * 1024
-+
-+
-+class Pattern:
-+    def __init__(self, byte, offset, size=GRANULARITY):
-+        self.byte = byte
-+        self.offset = offset
-+        self.size = size
-+
-+    def bits(self, granularity):
-+        lower = self.offset // granularity
-+        upper = (self.offset + self.size - 1) // granularity
-+        return set(range(lower, upper + 1))
-+
-+
-+class PatternGroup:
-+    """Grouping of Pattern objects. Initialize with an iterable of Patterns."""
-+    def __init__(self, patterns):
-+        self.patterns = patterns
-+
-+    def bits(self, granularity):
-+        """Calculate the unique bits dirtied by this pattern grouping"""
-+        res = set()
-+        for pattern in self.patterns:
-+            res |= pattern.bits(granularity)
-+        return res
-+
-+
-+GROUPS = [
-+    PatternGroup([
-+        # Batch 0: 4 clusters
-+        Pattern('0x49', 0x0000000),
-+        Pattern('0x6c', 0x0100000),   # 1M
-+        Pattern('0x6f', 0x2000000),   # 32M
-+        Pattern('0x76', 0x3ff0000)]), # 64M - 64K
-+    PatternGroup([
-+        # Batch 1: 6 clusters (3 new)
-+        Pattern('0x65', 0x0000000),   # Full overwrite
-+        Pattern('0x77', 0x00f8000),   # Partial-left (1M-32K)
-+        Pattern('0x72', 0x2008000),   # Partial-right (32M+32K)
-+        Pattern('0x69', 0x3fe0000)]), # Adjacent-left (64M - 128K)
-+    PatternGroup([
-+        # Batch 2: 7 clusters (3 new)
-+        Pattern('0x74', 0x0010000),   # Adjacent-right
-+        Pattern('0x69', 0x00e8000),   # Partial-left  (1M-96K)
-+        Pattern('0x6e', 0x2018000),   # Partial-right (32M+96K)
-+        Pattern('0x67', 0x3fe0000,
-+                2*GRANULARITY)]),     # Overwrite [(64M-128K)-64M)
-+    PatternGroup([
-+        # Batch 3: 8 clusters (5 new)
-+        # Carefully chosen such that nothing re-dirties the one cluster
-+        # that copies out successfully before failure in Group #1.
-+        Pattern('0xaa', 0x0010000,
-+                3*GRANULARITY),       # Overwrite and 2x Adjacent-right
-+        Pattern('0xbb', 0x00d8000),   # Partial-left (1M-160K)
-+        Pattern('0xcc', 0x2028000),   # Partial-right (32M+160K)
-+        Pattern('0xdd', 0x3fc0000)]), # New; leaving a gap to the right
-+]
-+
-+
-+class EmulatedBitmap:
-+    def __init__(self, granularity=GRANULARITY):
-+        self._bits = set()
-+        self.granularity = granularity
-+
-+    def dirty_bits(self, bits):
-+        self._bits |= set(bits)
-+
-+    def dirty_group(self, n):
-+        self.dirty_bits(GROUPS[n].bits(self.granularity))
-+
-+    def clear(self):
-+        self._bits = set()
-+
-+    def clear_bits(self, bits):
-+        self._bits -= set(bits)
-+
-+    def clear_bit(self, bit):
-+        self.clear_bits({bit})
-+
-+    def clear_group(self, n):
-+        self.clear_bits(GROUPS[n].bits(self.granularity))
-+
-+    @property
-+    def first_bit(self):
-+        return sorted(self.bits)[0]
-+
-+    @property
-+    def bits(self):
-+        return self._bits
-+
-+    @property
-+    def count(self):
-+        return len(self.bits)
-+
-+    def compare(self, qmp_bitmap):
-+        """
-+        Print a nice human-readable message checking that a bitmap as reported
-+        by the QMP interface has as many bits set as we expect it to.
-+        """
-+
-+        name = qmp_bitmap.get('name', '(anonymous)')
-+        log("= Checking Bitmap {:s} =".format(name))
-+
-+        want = self.count
-+        have = qmp_bitmap['count'] // qmp_bitmap['granularity']
-+
-+        log("expecting {:d} dirty sectors; have {:d}. {:s}".format(
-+            want, have, "OK!" if want == have else "ERROR!"))
-+        log('')
-+
-+
-+class Drive:
-+    """Represents, vaguely, a drive attached to a VM.
-+    Includes format, graph, and device information."""
-+
-+    def __init__(self, path, vm=None):
-+        self.path = path
-+        self.vm = vm
-+        self.fmt = None
-+        self.size = None
-+        self.node = None
-+
-+    def img_create(self, fmt, size):
-+        self.fmt = fmt
-+        self.size = size
-+        iotests.qemu_img_create('-f', self.fmt, self.path, str(self.size))
-+
-+    def create_target(self, name, fmt, size):
-+        basename = os.path.basename(self.path)
-+        file_node_name = "file_{}".format(basename)
-+        vm = self.vm
-+
-+        log(vm.command('blockdev-create', job_id='bdc-file-job',
-+                       options={
-+                           'driver': 'file',
-+                           'filename': self.path,
-+                           'size': 0,
-+                       }))
-+        vm.run_job('bdc-file-job')
-+        log(vm.command('blockdev-add', driver='file',
-+                       node_name=file_node_name, filename=self.path))
-+
-+        log(vm.command('blockdev-create', job_id='bdc-fmt-job',
-+                       options={
-+                           'driver': fmt,
-+                           'file': file_node_name,
-+                           'size': size,
-+                       }))
-+        vm.run_job('bdc-fmt-job')
-+        log(vm.command('blockdev-add', driver=fmt,
-+                       node_name=name,
-+                       file=file_node_name))
-+        self.fmt = fmt
-+        self.size = size
-+        self.node = name
-+
-+def blockdev_mirror(vm, device, target, sync, **kwargs):
-+    # Strip any arguments explicitly nulled by the caller:
-+    kwargs = {key: val for key, val in kwargs.items() if val is not None}
-+    result = vm.qmp_log('blockdev-mirror',
-+                        device=device,
-+                        target=target,
-+                        sync=sync,
-+                        filter_node_name='mirror-top',
-+                        **kwargs)
-+    return result
-+
-+def blockdev_mirror_mktarget(drive, target_id, filepath, sync, **kwargs):
-+    target_drive = Drive(filepath, vm=drive.vm)
-+    target_drive.create_target(target_id, drive.fmt, drive.size)
-+    blockdev_mirror(drive.vm, drive.node, target_id, sync, **kwargs)
-+
-+def reference_mirror(drive, n, filepath):
-+    log("--- Reference mirror #{:d} ---\n".format(n))
-+    target_id = "ref_target_{:d}".format(n)
-+    job_id = "ref_mirror_{:d}".format(n)
-+    blockdev_mirror_mktarget(drive, target_id, filepath, "full",
-+                             job_id=job_id)
-+    drive.vm.run_job(job_id, auto_dismiss=True)
-+    log('')
-+
-+def mirror(drive, n, filepath, sync, **kwargs):
-+    log("--- Test mirror #{:d} ---\n".format(n))
-+    target_id = "mirror_target_{:d}".format(n)
-+    job_id = "mirror_{:d}".format(n)
-+    kwargs.setdefault('auto-finalize', False)
-+    blockdev_mirror_mktarget(drive, target_id, filepath, sync,
-+                             job_id=job_id, **kwargs)
-+    return job_id
-+
-+def perform_writes(drive, n, filter_node_name=None):
-+    log("--- Write #{:d} ---\n".format(n))
-+    for pattern in GROUPS[n].patterns:
-+        cmd = "write -P{:s} 0x{:07x} 0x{:x}".format(
-+            pattern.byte,
-+            pattern.offset,
-+            pattern.size)
-+        log(cmd)
-+        log(drive.vm.hmp_qemu_io(filter_node_name or drive.node, cmd))
-+    bitmaps = drive.vm.query_bitmaps()
-+    log({'bitmaps': bitmaps}, indent=2)
-+    log('')
-+    return bitmaps
-+
-+
-+def compare_images(image, reference, baseimg=None, expected_match=True):
-+    """
-+    Print a nice human-readable message comparing these images.
-+    """
-+    expected_ret = 0 if expected_match else 1
-+    if baseimg:
-+        assert qemu_img("rebase", "-u", "-b", baseimg, image) == 0
-+    ret = qemu_img("compare", image, reference)
-+    log('qemu_img compare "{:s}" "{:s}" ==> {:s}, {:s}'.format(
-+        image, reference,
-+        "Identical" if ret == 0 else "Mismatch",
-+        "OK!" if ret == expected_ret else "ERROR!"),
-+        filters=[iotests.filter_testfiles])
-+
-+def test_bitmap_sync(bsync_mode, msync_mode='bitmap', failure=None):
-+    """
-+    Test bitmap mirror routines.
-+
-+    :param bsync_mode: Is the Bitmap Sync mode, and can be any of:
-+        - on-success: This is the "incremental" style mode. Bitmaps are
-+                      synchronized to what was copied out only on success.
-+                      (Partial images must be discarded.)
-+        - never:      This is the "differential" style mode.
-+                      Bitmaps are never synchronized.
-+        - always:     This is a "best effort" style mode.
-+                      Bitmaps are always synchronized, regardless of failure.
-+                      (Partial images must be kept.)
-+
-+    :param msync_mode: The mirror sync mode to use for the first mirror.
-+                       Can be any one of:
-+        - bitmap: mirrors based on bitmap manifest.
-+        - full:   Full mirrors.
-+        - top:    Full mirrors of the top layer only.
-+
-+    :param failure: Is the (optional) failure mode, and can be any of:
-+        - None:         No failure. Test the normative path. Default.
-+        - simulated:    Cancel the job right before it completes.
-+                        This also tests writes "during" the job.
-+        - intermediate: This tests a job that fails mid-process and produces
-+                        an incomplete mirror. Testing limitations prevent
-+                        testing competing writes.
-+    """
-+    with iotests.FilePaths(['img', 'bsync1', 'bsync2', 'bsync3',
-+                            'fmirror0', 'fmirror1', 'fmirror2', 'fmirror3']) as \
-+                            (img_path, bsync1, bsync2, bsync3,
-+                             fmirror0, fmirror1, fmirror2, fmirror3), \
-+         iotests.VM() as vm:
-+
-+        mode = "Mode {:s}; Bitmap Sync {:s}".format(msync_mode, bsync_mode)
-+        preposition = "with" if failure else "without"
-+        cond = "{:s} {:s}".format(preposition,
-+                                  "{:s} failure".format(failure) if failure
-+                                  else "failure")
-+        log("\n=== {:s} {:s} ===\n".format(mode, cond))
-+
-+        log('--- Preparing image & VM ---\n')
-+        drive0 = Drive(img_path, vm=vm)
-+        drive0.img_create(iotests.imgfmt, SIZE)
-+        vm.add_device("{},id=scsi0".format(iotests.get_virtio_scsi_device()))
-+        vm.launch()
-+
-+        file_config = {
-+            'driver': 'file',
-+            'filename': drive0.path
-+        }
-+
-+        if failure == 'intermediate':
-+            file_config = {
-+                'driver': 'blkdebug',
-+                'image': file_config,
-+                'set-state': [{
-+                    'event': 'flush_to_disk',
-+                    'state': 1,
-+                    'new_state': 2
-+                }, {
-+                    'event': 'read_aio',
-+                    'state': 2,
-+                    'new_state': 3
-+                }, {
-+                    'event': 'read_aio',
-+                    'state': 3,
-+                    'new_state': 4
-+                }],
-+                'inject-error': [{
-+                    'event': 'read_aio',
-+                    'errno': 5,
-+                    'state': 3,
-+                    'immediately': False,
-+                    'once': True
-+                }, {
-+                    'event': 'read_aio',
-+                    'errno': 5,
-+                    'state': 4,
-+                    'immediately': False,
-+                    'once': True
-+                }]
-+            }
-+
-+        drive0.node = 'drive0'
-+        vm.qmp_log('blockdev-add',
-+                   filters=[iotests.filter_qmp_testfiles],
-+                   node_name=drive0.node,
-+                   driver=drive0.fmt,
-+                   file=file_config)
-+        log('')
-+
-+        # 0 - Writes and Reference mirror
-+        perform_writes(drive0, 0)
-+        reference_mirror(drive0, 0, fmirror0)
-+        log('--- Add Bitmap ---\n')
-+        vm.qmp_log("block-dirty-bitmap-add", node=drive0.node,
-+                   name="bitmap0", granularity=GRANULARITY)
-+        log('')
-+        ebitmap = EmulatedBitmap()
-+
-+        # 1 - Writes and Reference mirror
-+        bitmaps = perform_writes(drive0, 1)
-+        ebitmap.dirty_group(1)
-+        bitmap = vm.get_bitmap(drive0.node, 'bitmap0', bitmaps=bitmaps)
-+        ebitmap.compare(bitmap)
-+        reference_mirror(drive0, 1, fmirror1)
-+
-+        # 1 - Test mirror (w/ Optional induced failure)
-+        if failure == 'intermediate':
-+            # Activate blkdebug induced failure for second-to-next read
-+            log(vm.hmp_qemu_io(drive0.node, 'flush'))
-+            log('')
-+        job = mirror(drive0, 1, bsync1, msync_mode,
-+                     bitmap="bitmap0", bitmap_mode=bsync_mode)
-+
-+        vm.run_job(job, auto_dismiss=True, auto_finalize=False,
-+                   cancel=(failure == 'simulated'))
-+        bitmaps = vm.query_bitmaps()
-+        log({'bitmaps': bitmaps}, indent=2)
-+        log('')
-+
-+        if bsync_mode == 'always':
-+            if failure == 'intermediate':
-+                # We manage to copy one sector (one bit) before the error.
-+                ebitmap.clear_bit(ebitmap.first_bit)
-+            else:
-+                # successful mirror / cancelled complete mirror
-+                ebitmap.clear()
-+
-+        if bsync_mode == 'on-success' and not failure:
-+            ebitmap.clear()
-+
-+        ebitmap.compare(vm.get_bitmap(drive0.node, 'bitmap0', bitmaps=bitmaps))
-+
-+        # 2 - Reference mirror
-+        reference_mirror(drive0, 2, fmirror2)
-+
-+        # 2 - Bitmap mirror with writes before completion
-+        job = mirror(drive0, 2, bsync2, "bitmap",
-+                     bitmap="bitmap0", bitmap_mode=bsync_mode)
-+
-+        bitmaps = perform_writes(drive0, 2)
-+        ebitmap.dirty_group(2)
-+        ebitmap.compare(vm.get_bitmap(drive0.node, 'bitmap0', bitmaps=bitmaps))
-+
-+        # don't use run_job as that logs too much even with use_log=False
-+        events = [('JOB_STATUS_CHANGE', {'data': {'id': job}})]
-+        while True:
-+            ev = iotests.filter_qmp_event(vm.events_wait(events, timeout=10))
-+            status = ev['data']['status']
-+            if status == 'ready':
-+                vm.qmp('job-complete', id=job)
-+            elif status == 'standby':
-+                vm.qmp('job-resume', id=job)
-+            elif status == 'pending':
-+                vm.qmp('job-finalize', id=job)
-+            elif status == 'null':
-+                break
-+
-+        if bsync_mode != 'never':
-+            ebitmap.clear()
-+
-+        bitmaps = vm.query_bitmaps()
-+        ebitmap.compare(vm.get_bitmap(drive0.node, 'bitmap0', bitmaps=bitmaps))
-+
-+        # 3 - Writes and Reference mirror
-+        bitmaps = perform_writes(drive0, 3)
-+        ebitmap.dirty_group(3)
-+        ebitmap.compare(vm.get_bitmap(drive0.node, 'bitmap0', bitmaps=bitmaps))
-+        reference_mirror(drive0, 3, fmirror3)
-+
-+        # 3 - Bitmap mirror (In failure modes, this is a recovery.)
-+        job = mirror(drive0, 3, bsync3, "bitmap",
-+                     bitmap="bitmap0", bitmap_mode=bsync_mode)
-+
-+        vm.run_job(job, auto_dismiss=True, auto_finalize=False)
-+        bitmaps = vm.query_bitmaps()
-+
-+        log({'bitmaps': bitmaps}, indent=2)
-+        log('')
-+        if bsync_mode != 'never':
-+            ebitmap.clear()
-+        ebitmap.compare(vm.get_bitmap(drive0.node, 'bitmap0', bitmaps=bitmaps))
-+
-+        log('--- Cleanup ---\n')
-+        vm.qmp_log("block-dirty-bitmap-remove",
-+                   node=drive0.node, name="bitmap0")
-+        bitmaps = vm.query_bitmaps()
-+        log({'bitmaps': bitmaps}, indent=2)
-+        vm.shutdown()
-+        log('')
-+
-+        log('--- Verification ---\n')
-+        compare_images(bsync1, fmirror1, baseimg=fmirror0,
-+                       expected_match=failure != 'intermediate')
-+        if not failure or bsync_mode == 'always':
-+            # Always keep the last mirror on success or when using 'always'
-+            base = bsync1
-+        else:
-+            base = fmirror1
-+
-+        compare_images(bsync2, fmirror2, baseimg=base, expected_match=0)
-+        compare_images(bsync3, fmirror3, baseimg=bsync2)
-+        compare_images(img_path, fmirror3)
-+        log('')
-+
-+def test_mirror_api():
-+    """
-+    Test malformed and prohibited invocations of the mirror API.
-+    """
-+    with iotests.FilePaths(['img', 'bsync1']) as \
-+         (img_path, mirror_path), \
-+         iotests.VM() as vm:
-+
-+        log("\n=== API failure tests ===\n")
-+        log('--- Preparing image & VM ---\n')
-+        drive0 = Drive(img_path, vm=vm)
-+        drive0.img_create(iotests.imgfmt, SIZE)
-+        vm.add_device("{},id=scsi0".format(iotests.get_virtio_scsi_device()))
-+        vm.launch()
-+
-+        file_config = {
-+            'driver': 'file',
-+            'filename': drive0.path
-+        }
-+
-+        drive0.node = 'drive0'
-+        vm.qmp_log('blockdev-add',
-+                   filters=[iotests.filter_qmp_testfiles],
-+                   node_name=drive0.node,
-+                   driver=drive0.fmt,
-+                   file=file_config)
-+        log('')
-+
-+        target0 = Drive(mirror_path, vm=vm)
-+        target0.create_target("mirror_target", drive0.fmt, drive0.size)
-+        log('')
-+
-+        vm.qmp_log("block-dirty-bitmap-add", node=drive0.node,
-+                   name="bitmap0", granularity=GRANULARITY)
-+        log('')
-+
-+        log('-- Testing invalid QMP commands --\n')
-+
-+        error_cases = {
-+            'incremental': {
-+                None:        ['on-success', 'always', 'never', None],
-+                'bitmap404': ['on-success', 'always', 'never', None],
-+                'bitmap0':   ['always', 'never']
-+            },
-+            'bitmap': {
-+                None:        ['on-success', 'always', 'never', None],
-+                'bitmap404': ['on-success', 'always', 'never', None],
-+                'bitmap0':   [None],
-+            },
-+            'full': {
-+                None:        ['on-success', 'always', 'never'],
-+                'bitmap404': ['on-success', 'always', 'never', None],
-+                'bitmap0':   ['on-success', 'always', 'never', None],
-+            },
-+            'top': {
-+                None:        ['on-success', 'always', 'never'],
-+                'bitmap404': ['on-success', 'always', 'never', None],
-+                'bitmap0':   ['on-success', 'always', 'never', None],
-+            },
-+            'none': {
-+                None:        ['on-success', 'always', 'never'],
-+                'bitmap404': ['on-success', 'always', 'never', None],
-+                'bitmap0':   ['on-success', 'always', 'never', None],
-+            }
-+        }
-+
-+        # Dicts, as always, are not stably-ordered prior to 3.7, so use tuples:
-+        for sync_mode in ('incremental', 'bitmap', 'full', 'top', 'none'):
-+            log("-- Sync mode {:s} tests --\n".format(sync_mode))
-+            for bitmap in (None, 'bitmap404', 'bitmap0'):
-+                for policy in error_cases[sync_mode][bitmap]:
-+                    blockdev_mirror(drive0.vm, drive0.node, "mirror_target",
-+                                    sync_mode, job_id='api_job',
-+                                    bitmap=bitmap, bitmap_mode=policy)
-+                    log('')
-+
-+
-+def main():
-+    for bsync_mode in ("never", "on-success", "always"):
-+        for failure in ("simulated", "intermediate", None):
-+            test_bitmap_sync(bsync_mode, "bitmap", failure)
-+
-+#    for sync_mode in ('full', 'top'):
-+#        for bsync_mode in ('on-success', 'always'):
-+#            for failure in ('simulated', 'intermediate', None):
-+#                test_bitmap_sync(bsync_mode, sync_mode, failure)
-+
-+    test_mirror_api()
-+
-+if __name__ == '__main__':
-+    iotests.script_main(main, supported_fmts=['qcow2'],
-+                        supported_protocols=['file'])
-diff --git a/tests/qemu-iotests/384.out b/tests/qemu-iotests/384.out
-new file mode 100644
-index 0000000000..9b7408b6d6
---- /dev/null
-+++ b/tests/qemu-iotests/384.out
-@@ -0,0 +1,2846 @@
-+
-+=== Mode bitmap; Bitmap Sync never with simulated failure ===
-+
-+--- Preparing image & VM ---
-+
-+{"execute": "blockdev-add", "arguments": {"driver": "qcow2", "file": {"driver": "file", "filename": "TEST_DIR/PID-img"}, "node-name": "drive0"}}
-+{"return": {}}
-+
-+--- Write #0 ---
-+
-+write -P0x49 0x0000000 0x10000
-+{"return": ""}
-+write -P0x6c 0x0100000 0x10000
-+{"return": ""}
-+write -P0x6f 0x2000000 0x10000
-+{"return": ""}
-+write -P0x76 0x3ff0000 0x10000
-+{"return": ""}
-+{
-+  "bitmaps": {}
-+}
-+
-+--- Reference mirror #0 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_0", "sync": "full", "target": "ref_target_0"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_0"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+--- Add Bitmap ---
-+
-+{"execute": "block-dirty-bitmap-add", "arguments": {"granularity": 65536, "name": "bitmap0", "node": "drive0"}}
-+{"return": {}}
-+
-+--- Write #1 ---
-+
-+write -P0x65 0x0000000 0x10000
-+{"return": ""}
-+write -P0x77 0x00f8000 0x10000
-+{"return": ""}
-+write -P0x72 0x2008000 0x10000
-+{"return": ""}
-+write -P0x69 0x3fe0000 0x10000
-+{"return": ""}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 393216,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 6 dirty sectors; have 6. OK!
-+
-+--- Reference mirror #1 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_1", "sync": "full", "target": "ref_target_1"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_1"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+--- Test mirror #1 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_1", "sync": "bitmap", "target": "mirror_target_1"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "mirror_1"}}
-+{"return": {}}
-+{"data": {"device": "mirror_1", "len": 393216, "offset": 393216, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"execute": "job-cancel", "arguments": {"id": "mirror_1"}}
-+{"return": {}}
-+{"data": {"id": "mirror_1", "type": "mirror"}, "event": "BLOCK_JOB_PENDING", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "mirror_1", "len": 393216, "offset": 393216, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_CANCELLED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 393216,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 6 dirty sectors; have 6. OK!
-+
-+--- Reference mirror #2 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_2", "sync": "full", "target": "ref_target_2"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_2"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+--- Test mirror #2 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_2", "sync": "bitmap", "target": "mirror_target_2"}}
-+{"return": {}}
-+--- Write #2 ---
-+
-+write -P0x74 0x0010000 0x10000
-+{"return": ""}
-+write -P0x69 0x00e8000 0x10000
-+{"return": ""}
-+write -P0x6e 0x2018000 0x10000
-+{"return": ""}
-+write -P0x67 0x3fe0000 0x20000
-+{"return": ""}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 262144,
-+        "granularity": 65536,
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      },
-+      {
-+        "busy": true,
-+        "count": 655360,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "locked"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 10 dirty sectors; have 10. OK!
-+
-+= Checking Bitmap bitmap0 =
-+expecting 10 dirty sectors; have 10. OK!
-+
-+--- Write #3 ---
-+
-+write -P0xaa 0x0010000 0x30000
-+{"return": ""}
-+write -P0xbb 0x00d8000 0x10000
-+{"return": ""}
-+write -P0xcc 0x2028000 0x10000
-+{"return": ""}
-+write -P0xdd 0x3fc0000 0x10000
-+{"return": ""}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 983040,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 15 dirty sectors; have 15. OK!
-+
-+--- Reference mirror #3 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_3", "sync": "full", "target": "ref_target_3"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_3"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+--- Test mirror #3 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_3", "sync": "bitmap", "target": "mirror_target_3"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "mirror_3"}}
-+{"return": {}}
-+{"data": {"device": "mirror_3", "len": 983040, "offset": 983040, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"execute": "job-finalize", "arguments": {"id": "mirror_3"}}
-+{"return": {}}
-+{"data": {"id": "mirror_3", "type": "mirror"}, "event": "BLOCK_JOB_PENDING", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "mirror_3", "len": 983040, "offset": 983040, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 983040,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 15 dirty sectors; have 15. OK!
-+
-+--- Cleanup ---
-+
-+{"execute": "block-dirty-bitmap-remove", "arguments": {"name": "bitmap0", "node": "drive0"}}
-+{"return": {}}
-+{
-+  "bitmaps": {}
-+}
-+
-+--- Verification ---
-+
-+qemu_img compare "TEST_DIR/PID-bsync1" "TEST_DIR/PID-fmirror1" ==> Identical, OK!
-+qemu_img compare "TEST_DIR/PID-bsync2" "TEST_DIR/PID-fmirror2" ==> Mismatch, OK!
-+qemu_img compare "TEST_DIR/PID-bsync3" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
-+qemu_img compare "TEST_DIR/PID-img" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
-+
-+
-+=== Mode bitmap; Bitmap Sync never with intermediate failure ===
-+
-+--- Preparing image & VM ---
-+
-+{"execute": "blockdev-add", "arguments": {"driver": "qcow2", "file": {"driver": "blkdebug", "image": {"driver": "file", "filename": "TEST_DIR/PID-img"}, "inject-error": [{"errno": 5, "event": "read_aio", "immediately": false, "once": true, "state": 3}, {"errno": 5, "event": "read_aio", "immediately": false, "once": true, "state": 4}], "set-state": [{"event": "flush_to_disk", "new-state": 2, "state": 1}, {"event": "read_aio", "new-state": 3, "state": 2}, {"event": "read_aio", "new-state": 4, "state": 3}]}, "node-name": "drive0"}}
-+{"return": {}}
-+
-+--- Write #0 ---
-+
-+write -P0x49 0x0000000 0x10000
-+{"return": ""}
-+write -P0x6c 0x0100000 0x10000
-+{"return": ""}
-+write -P0x6f 0x2000000 0x10000
-+{"return": ""}
-+write -P0x76 0x3ff0000 0x10000
-+{"return": ""}
-+{
-+  "bitmaps": {}
-+}
-+
-+--- Reference mirror #0 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_0", "sync": "full", "target": "ref_target_0"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_0"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+--- Add Bitmap ---
-+
-+{"execute": "block-dirty-bitmap-add", "arguments": {"granularity": 65536, "name": "bitmap0", "node": "drive0"}}
-+{"return": {}}
-+
-+--- Write #1 ---
-+
-+write -P0x65 0x0000000 0x10000
-+{"return": ""}
-+write -P0x77 0x00f8000 0x10000
-+{"return": ""}
-+write -P0x72 0x2008000 0x10000
-+{"return": ""}
-+write -P0x69 0x3fe0000 0x10000
-+{"return": ""}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 393216,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 6 dirty sectors; have 6. OK!
-+
-+--- Reference mirror #1 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_1", "sync": "full", "target": "ref_target_1"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_1"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+{"return": ""}
-+
-+--- Test mirror #1 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_1", "sync": "bitmap", "target": "mirror_target_1"}}
-+{"return": {}}
-+{"data": {"action": "report", "device": "mirror_1", "operation": "read"}, "event": "BLOCK_JOB_ERROR", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"action": "report", "device": "mirror_1", "operation": "read"}, "event": "BLOCK_JOB_ERROR", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "mirror_1", "error": "Input/output error", "len": 393216, "offset": 65536, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 393216,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 6 dirty sectors; have 6. OK!
-+
-+--- Reference mirror #2 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_2", "sync": "full", "target": "ref_target_2"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_2"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+--- Test mirror #2 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_2", "sync": "bitmap", "target": "mirror_target_2"}}
-+{"return": {}}
-+--- Write #2 ---
-+
-+write -P0x74 0x0010000 0x10000
-+{"return": ""}
-+write -P0x69 0x00e8000 0x10000
-+{"return": ""}
-+write -P0x6e 0x2018000 0x10000
-+{"return": ""}
-+write -P0x67 0x3fe0000 0x20000
-+{"return": ""}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 262144,
-+        "granularity": 65536,
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      },
-+      {
-+        "busy": true,
-+        "count": 655360,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "locked"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 10 dirty sectors; have 10. OK!
-+
-+= Checking Bitmap bitmap0 =
-+expecting 10 dirty sectors; have 10. OK!
-+
-+--- Write #3 ---
-+
-+write -P0xaa 0x0010000 0x30000
-+{"return": ""}
-+write -P0xbb 0x00d8000 0x10000
-+{"return": ""}
-+write -P0xcc 0x2028000 0x10000
-+{"return": ""}
-+write -P0xdd 0x3fc0000 0x10000
-+{"return": ""}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 983040,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 15 dirty sectors; have 15. OK!
-+
-+--- Reference mirror #3 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_3", "sync": "full", "target": "ref_target_3"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_3"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+--- Test mirror #3 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_3", "sync": "bitmap", "target": "mirror_target_3"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "mirror_3"}}
-+{"return": {}}
-+{"data": {"device": "mirror_3", "len": 983040, "offset": 983040, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"execute": "job-finalize", "arguments": {"id": "mirror_3"}}
-+{"return": {}}
-+{"data": {"id": "mirror_3", "type": "mirror"}, "event": "BLOCK_JOB_PENDING", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "mirror_3", "len": 983040, "offset": 983040, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 983040,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 15 dirty sectors; have 15. OK!
-+
-+--- Cleanup ---
-+
-+{"execute": "block-dirty-bitmap-remove", "arguments": {"name": "bitmap0", "node": "drive0"}}
-+{"return": {}}
-+{
-+  "bitmaps": {}
-+}
-+
-+--- Verification ---
-+
-+qemu_img compare "TEST_DIR/PID-bsync1" "TEST_DIR/PID-fmirror1" ==> Mismatch, OK!
-+qemu_img compare "TEST_DIR/PID-bsync2" "TEST_DIR/PID-fmirror2" ==> Mismatch, OK!
-+qemu_img compare "TEST_DIR/PID-bsync3" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
-+qemu_img compare "TEST_DIR/PID-img" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
-+
-+
-+=== Mode bitmap; Bitmap Sync never without failure ===
-+
-+--- Preparing image & VM ---
-+
-+{"execute": "blockdev-add", "arguments": {"driver": "qcow2", "file": {"driver": "file", "filename": "TEST_DIR/PID-img"}, "node-name": "drive0"}}
-+{"return": {}}
-+
-+--- Write #0 ---
-+
-+write -P0x49 0x0000000 0x10000
-+{"return": ""}
-+write -P0x6c 0x0100000 0x10000
-+{"return": ""}
-+write -P0x6f 0x2000000 0x10000
-+{"return": ""}
-+write -P0x76 0x3ff0000 0x10000
-+{"return": ""}
-+{
-+  "bitmaps": {}
-+}
-+
-+--- Reference mirror #0 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_0", "sync": "full", "target": "ref_target_0"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_0"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+--- Add Bitmap ---
-+
-+{"execute": "block-dirty-bitmap-add", "arguments": {"granularity": 65536, "name": "bitmap0", "node": "drive0"}}
-+{"return": {}}
-+
-+--- Write #1 ---
-+
-+write -P0x65 0x0000000 0x10000
-+{"return": ""}
-+write -P0x77 0x00f8000 0x10000
-+{"return": ""}
-+write -P0x72 0x2008000 0x10000
-+{"return": ""}
-+write -P0x69 0x3fe0000 0x10000
-+{"return": ""}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 393216,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 6 dirty sectors; have 6. OK!
-+
-+--- Reference mirror #1 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_1", "sync": "full", "target": "ref_target_1"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_1"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+--- Test mirror #1 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_1", "sync": "bitmap", "target": "mirror_target_1"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "mirror_1"}}
-+{"return": {}}
-+{"data": {"device": "mirror_1", "len": 393216, "offset": 393216, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"execute": "job-finalize", "arguments": {"id": "mirror_1"}}
-+{"return": {}}
-+{"data": {"id": "mirror_1", "type": "mirror"}, "event": "BLOCK_JOB_PENDING", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "mirror_1", "len": 393216, "offset": 393216, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 393216,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 6 dirty sectors; have 6. OK!
-+
-+--- Reference mirror #2 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_2", "sync": "full", "target": "ref_target_2"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_2"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+--- Test mirror #2 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_2", "sync": "bitmap", "target": "mirror_target_2"}}
-+{"return": {}}
-+--- Write #2 ---
-+
-+write -P0x74 0x0010000 0x10000
-+{"return": ""}
-+write -P0x69 0x00e8000 0x10000
-+{"return": ""}
-+write -P0x6e 0x2018000 0x10000
-+{"return": ""}
-+write -P0x67 0x3fe0000 0x20000
-+{"return": ""}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 262144,
-+        "granularity": 65536,
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      },
-+      {
-+        "busy": true,
-+        "count": 655360,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "locked"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 10 dirty sectors; have 10. OK!
-+
-+= Checking Bitmap bitmap0 =
-+expecting 10 dirty sectors; have 10. OK!
-+
-+--- Write #3 ---
-+
-+write -P0xaa 0x0010000 0x30000
-+{"return": ""}
-+write -P0xbb 0x00d8000 0x10000
-+{"return": ""}
-+write -P0xcc 0x2028000 0x10000
-+{"return": ""}
-+write -P0xdd 0x3fc0000 0x10000
-+{"return": ""}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 983040,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 15 dirty sectors; have 15. OK!
-+
-+--- Reference mirror #3 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_3", "sync": "full", "target": "ref_target_3"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_3"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+--- Test mirror #3 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_3", "sync": "bitmap", "target": "mirror_target_3"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "mirror_3"}}
-+{"return": {}}
-+{"data": {"device": "mirror_3", "len": 983040, "offset": 983040, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"execute": "job-finalize", "arguments": {"id": "mirror_3"}}
-+{"return": {}}
-+{"data": {"id": "mirror_3", "type": "mirror"}, "event": "BLOCK_JOB_PENDING", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "mirror_3", "len": 983040, "offset": 983040, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 983040,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 15 dirty sectors; have 15. OK!
-+
-+--- Cleanup ---
-+
-+{"execute": "block-dirty-bitmap-remove", "arguments": {"name": "bitmap0", "node": "drive0"}}
-+{"return": {}}
-+{
-+  "bitmaps": {}
-+}
-+
-+--- Verification ---
-+
-+qemu_img compare "TEST_DIR/PID-bsync1" "TEST_DIR/PID-fmirror1" ==> Identical, OK!
-+qemu_img compare "TEST_DIR/PID-bsync2" "TEST_DIR/PID-fmirror2" ==> Mismatch, OK!
-+qemu_img compare "TEST_DIR/PID-bsync3" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
-+qemu_img compare "TEST_DIR/PID-img" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
-+
-+
-+=== Mode bitmap; Bitmap Sync on-success with simulated failure ===
-+
-+--- Preparing image & VM ---
-+
-+{"execute": "blockdev-add", "arguments": {"driver": "qcow2", "file": {"driver": "file", "filename": "TEST_DIR/PID-img"}, "node-name": "drive0"}}
-+{"return": {}}
-+
-+--- Write #0 ---
-+
-+write -P0x49 0x0000000 0x10000
-+{"return": ""}
-+write -P0x6c 0x0100000 0x10000
-+{"return": ""}
-+write -P0x6f 0x2000000 0x10000
-+{"return": ""}
-+write -P0x76 0x3ff0000 0x10000
-+{"return": ""}
-+{
-+  "bitmaps": {}
-+}
-+
-+--- Reference mirror #0 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_0", "sync": "full", "target": "ref_target_0"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_0"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+--- Add Bitmap ---
-+
-+{"execute": "block-dirty-bitmap-add", "arguments": {"granularity": 65536, "name": "bitmap0", "node": "drive0"}}
-+{"return": {}}
-+
-+--- Write #1 ---
-+
-+write -P0x65 0x0000000 0x10000
-+{"return": ""}
-+write -P0x77 0x00f8000 0x10000
-+{"return": ""}
-+write -P0x72 0x2008000 0x10000
-+{"return": ""}
-+write -P0x69 0x3fe0000 0x10000
-+{"return": ""}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 393216,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 6 dirty sectors; have 6. OK!
-+
-+--- Reference mirror #1 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_1", "sync": "full", "target": "ref_target_1"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_1"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+--- Test mirror #1 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_1", "sync": "bitmap", "target": "mirror_target_1"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "mirror_1"}}
-+{"return": {}}
-+{"data": {"device": "mirror_1", "len": 393216, "offset": 393216, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"execute": "job-cancel", "arguments": {"id": "mirror_1"}}
-+{"return": {}}
-+{"data": {"id": "mirror_1", "type": "mirror"}, "event": "BLOCK_JOB_PENDING", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "mirror_1", "len": 393216, "offset": 393216, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_CANCELLED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 393216,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 6 dirty sectors; have 6. OK!
-+
-+--- Reference mirror #2 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_2", "sync": "full", "target": "ref_target_2"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_2"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+--- Test mirror #2 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_2", "sync": "bitmap", "target": "mirror_target_2"}}
-+{"return": {}}
-+--- Write #2 ---
-+
-+write -P0x74 0x0010000 0x10000
-+{"return": ""}
-+write -P0x69 0x00e8000 0x10000
-+{"return": ""}
-+write -P0x6e 0x2018000 0x10000
-+{"return": ""}
-+write -P0x67 0x3fe0000 0x20000
-+{"return": ""}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 262144,
-+        "granularity": 65536,
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      },
-+      {
-+        "busy": true,
-+        "count": 655360,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "locked"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 10 dirty sectors; have 10. OK!
-+
-+= Checking Bitmap bitmap0 =
-+expecting 0 dirty sectors; have 0. OK!
-+
-+--- Write #3 ---
-+
-+write -P0xaa 0x0010000 0x30000
-+{"return": ""}
-+write -P0xbb 0x00d8000 0x10000
-+{"return": ""}
-+write -P0xcc 0x2028000 0x10000
-+{"return": ""}
-+write -P0xdd 0x3fc0000 0x10000
-+{"return": ""}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 524288,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 8 dirty sectors; have 8. OK!
-+
-+--- Reference mirror #3 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_3", "sync": "full", "target": "ref_target_3"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_3"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+--- Test mirror #3 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_3", "sync": "bitmap", "target": "mirror_target_3"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "mirror_3"}}
-+{"return": {}}
-+{"data": {"device": "mirror_3", "len": 524288, "offset": 524288, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"execute": "job-finalize", "arguments": {"id": "mirror_3"}}
-+{"return": {}}
-+{"data": {"id": "mirror_3", "type": "mirror"}, "event": "BLOCK_JOB_PENDING", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "mirror_3", "len": 524288, "offset": 524288, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 0,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 0 dirty sectors; have 0. OK!
-+
-+--- Cleanup ---
-+
-+{"execute": "block-dirty-bitmap-remove", "arguments": {"name": "bitmap0", "node": "drive0"}}
-+{"return": {}}
-+{
-+  "bitmaps": {}
-+}
-+
-+--- Verification ---
-+
-+qemu_img compare "TEST_DIR/PID-bsync1" "TEST_DIR/PID-fmirror1" ==> Identical, OK!
-+qemu_img compare "TEST_DIR/PID-bsync2" "TEST_DIR/PID-fmirror2" ==> Mismatch, OK!
-+qemu_img compare "TEST_DIR/PID-bsync3" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
-+qemu_img compare "TEST_DIR/PID-img" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
-+
-+
-+=== Mode bitmap; Bitmap Sync on-success with intermediate failure ===
-+
-+--- Preparing image & VM ---
-+
-+{"execute": "blockdev-add", "arguments": {"driver": "qcow2", "file": {"driver": "blkdebug", "image": {"driver": "file", "filename": "TEST_DIR/PID-img"}, "inject-error": [{"errno": 5, "event": "read_aio", "immediately": false, "once": true, "state": 3}, {"errno": 5, "event": "read_aio", "immediately": false, "once": true, "state": 4}], "set-state": [{"event": "flush_to_disk", "new-state": 2, "state": 1}, {"event": "read_aio", "new-state": 3, "state": 2}, {"event": "read_aio", "new-state": 4, "state": 3}]}, "node-name": "drive0"}}
-+{"return": {}}
-+
-+--- Write #0 ---
-+
-+write -P0x49 0x0000000 0x10000
-+{"return": ""}
-+write -P0x6c 0x0100000 0x10000
-+{"return": ""}
-+write -P0x6f 0x2000000 0x10000
-+{"return": ""}
-+write -P0x76 0x3ff0000 0x10000
-+{"return": ""}
-+{
-+  "bitmaps": {}
-+}
-+
-+--- Reference mirror #0 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_0", "sync": "full", "target": "ref_target_0"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_0"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+--- Add Bitmap ---
-+
-+{"execute": "block-dirty-bitmap-add", "arguments": {"granularity": 65536, "name": "bitmap0", "node": "drive0"}}
-+{"return": {}}
-+
-+--- Write #1 ---
-+
-+write -P0x65 0x0000000 0x10000
-+{"return": ""}
-+write -P0x77 0x00f8000 0x10000
-+{"return": ""}
-+write -P0x72 0x2008000 0x10000
-+{"return": ""}
-+write -P0x69 0x3fe0000 0x10000
-+{"return": ""}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 393216,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 6 dirty sectors; have 6. OK!
-+
-+--- Reference mirror #1 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_1", "sync": "full", "target": "ref_target_1"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_1"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+{"return": ""}
-+
-+--- Test mirror #1 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_1", "sync": "bitmap", "target": "mirror_target_1"}}
-+{"return": {}}
-+{"data": {"action": "report", "device": "mirror_1", "operation": "read"}, "event": "BLOCK_JOB_ERROR", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"action": "report", "device": "mirror_1", "operation": "read"}, "event": "BLOCK_JOB_ERROR", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "mirror_1", "error": "Input/output error", "len": 393216, "offset": 65536, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 393216,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 6 dirty sectors; have 6. OK!
-+
-+--- Reference mirror #2 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_2", "sync": "full", "target": "ref_target_2"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_2"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+--- Test mirror #2 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_2", "sync": "bitmap", "target": "mirror_target_2"}}
-+{"return": {}}
-+--- Write #2 ---
-+
-+write -P0x74 0x0010000 0x10000
-+{"return": ""}
-+write -P0x69 0x00e8000 0x10000
-+{"return": ""}
-+write -P0x6e 0x2018000 0x10000
-+{"return": ""}
-+write -P0x67 0x3fe0000 0x20000
-+{"return": ""}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 262144,
-+        "granularity": 65536,
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      },
-+      {
-+        "busy": true,
-+        "count": 655360,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "locked"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 10 dirty sectors; have 10. OK!
-+
-+= Checking Bitmap bitmap0 =
-+expecting 0 dirty sectors; have 0. OK!
-+
-+--- Write #3 ---
-+
-+write -P0xaa 0x0010000 0x30000
-+{"return": ""}
-+write -P0xbb 0x00d8000 0x10000
-+{"return": ""}
-+write -P0xcc 0x2028000 0x10000
-+{"return": ""}
-+write -P0xdd 0x3fc0000 0x10000
-+{"return": ""}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 524288,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 8 dirty sectors; have 8. OK!
-+
-+--- Reference mirror #3 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_3", "sync": "full", "target": "ref_target_3"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_3"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+--- Test mirror #3 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_3", "sync": "bitmap", "target": "mirror_target_3"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "mirror_3"}}
-+{"return": {}}
-+{"data": {"device": "mirror_3", "len": 524288, "offset": 524288, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"execute": "job-finalize", "arguments": {"id": "mirror_3"}}
-+{"return": {}}
-+{"data": {"id": "mirror_3", "type": "mirror"}, "event": "BLOCK_JOB_PENDING", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "mirror_3", "len": 524288, "offset": 524288, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 0,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 0 dirty sectors; have 0. OK!
-+
-+--- Cleanup ---
-+
-+{"execute": "block-dirty-bitmap-remove", "arguments": {"name": "bitmap0", "node": "drive0"}}
-+{"return": {}}
-+{
-+  "bitmaps": {}
-+}
-+
-+--- Verification ---
-+
-+qemu_img compare "TEST_DIR/PID-bsync1" "TEST_DIR/PID-fmirror1" ==> Mismatch, OK!
-+qemu_img compare "TEST_DIR/PID-bsync2" "TEST_DIR/PID-fmirror2" ==> Mismatch, OK!
-+qemu_img compare "TEST_DIR/PID-bsync3" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
-+qemu_img compare "TEST_DIR/PID-img" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
-+
-+
-+=== Mode bitmap; Bitmap Sync on-success without failure ===
-+
-+--- Preparing image & VM ---
-+
-+{"execute": "blockdev-add", "arguments": {"driver": "qcow2", "file": {"driver": "file", "filename": "TEST_DIR/PID-img"}, "node-name": "drive0"}}
-+{"return": {}}
-+
-+--- Write #0 ---
-+
-+write -P0x49 0x0000000 0x10000
-+{"return": ""}
-+write -P0x6c 0x0100000 0x10000
-+{"return": ""}
-+write -P0x6f 0x2000000 0x10000
-+{"return": ""}
-+write -P0x76 0x3ff0000 0x10000
-+{"return": ""}
-+{
-+  "bitmaps": {}
-+}
-+
-+--- Reference mirror #0 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_0", "sync": "full", "target": "ref_target_0"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_0"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+--- Add Bitmap ---
-+
-+{"execute": "block-dirty-bitmap-add", "arguments": {"granularity": 65536, "name": "bitmap0", "node": "drive0"}}
-+{"return": {}}
-+
-+--- Write #1 ---
-+
-+write -P0x65 0x0000000 0x10000
-+{"return": ""}
-+write -P0x77 0x00f8000 0x10000
-+{"return": ""}
-+write -P0x72 0x2008000 0x10000
-+{"return": ""}
-+write -P0x69 0x3fe0000 0x10000
-+{"return": ""}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 393216,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 6 dirty sectors; have 6. OK!
-+
-+--- Reference mirror #1 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_1", "sync": "full", "target": "ref_target_1"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_1"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+--- Test mirror #1 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_1", "sync": "bitmap", "target": "mirror_target_1"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "mirror_1"}}
-+{"return": {}}
-+{"data": {"device": "mirror_1", "len": 393216, "offset": 393216, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"execute": "job-finalize", "arguments": {"id": "mirror_1"}}
-+{"return": {}}
-+{"data": {"id": "mirror_1", "type": "mirror"}, "event": "BLOCK_JOB_PENDING", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "mirror_1", "len": 393216, "offset": 393216, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 0,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 0 dirty sectors; have 0. OK!
-+
-+--- Reference mirror #2 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_2", "sync": "full", "target": "ref_target_2"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_2"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+--- Test mirror #2 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_2", "sync": "bitmap", "target": "mirror_target_2"}}
-+{"return": {}}
-+--- Write #2 ---
-+
-+write -P0x74 0x0010000 0x10000
-+{"return": ""}
-+write -P0x69 0x00e8000 0x10000
-+{"return": ""}
-+write -P0x6e 0x2018000 0x10000
-+{"return": ""}
-+write -P0x67 0x3fe0000 0x20000
-+{"return": ""}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 458752,
-+        "granularity": 65536,
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      },
-+      {
-+        "busy": true,
-+        "count": 458752,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "locked"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 7 dirty sectors; have 7. OK!
-+
-+= Checking Bitmap bitmap0 =
-+expecting 0 dirty sectors; have 0. OK!
-+
-+--- Write #3 ---
-+
-+write -P0xaa 0x0010000 0x30000
-+{"return": ""}
-+write -P0xbb 0x00d8000 0x10000
-+{"return": ""}
-+write -P0xcc 0x2028000 0x10000
-+{"return": ""}
-+write -P0xdd 0x3fc0000 0x10000
-+{"return": ""}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 524288,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 8 dirty sectors; have 8. OK!
-+
-+--- Reference mirror #3 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_3", "sync": "full", "target": "ref_target_3"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_3"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+--- Test mirror #3 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_3", "sync": "bitmap", "target": "mirror_target_3"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "mirror_3"}}
-+{"return": {}}
-+{"data": {"device": "mirror_3", "len": 524288, "offset": 524288, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"execute": "job-finalize", "arguments": {"id": "mirror_3"}}
-+{"return": {}}
-+{"data": {"id": "mirror_3", "type": "mirror"}, "event": "BLOCK_JOB_PENDING", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "mirror_3", "len": 524288, "offset": 524288, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 0,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 0 dirty sectors; have 0. OK!
-+
-+--- Cleanup ---
-+
-+{"execute": "block-dirty-bitmap-remove", "arguments": {"name": "bitmap0", "node": "drive0"}}
-+{"return": {}}
-+{
-+  "bitmaps": {}
-+}
-+
-+--- Verification ---
-+
-+qemu_img compare "TEST_DIR/PID-bsync1" "TEST_DIR/PID-fmirror1" ==> Identical, OK!
-+qemu_img compare "TEST_DIR/PID-bsync2" "TEST_DIR/PID-fmirror2" ==> Mismatch, OK!
-+qemu_img compare "TEST_DIR/PID-bsync3" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
-+qemu_img compare "TEST_DIR/PID-img" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
-+
-+
-+=== Mode bitmap; Bitmap Sync always with simulated failure ===
-+
-+--- Preparing image & VM ---
-+
-+{"execute": "blockdev-add", "arguments": {"driver": "qcow2", "file": {"driver": "file", "filename": "TEST_DIR/PID-img"}, "node-name": "drive0"}}
-+{"return": {}}
-+
-+--- Write #0 ---
-+
-+write -P0x49 0x0000000 0x10000
-+{"return": ""}
-+write -P0x6c 0x0100000 0x10000
-+{"return": ""}
-+write -P0x6f 0x2000000 0x10000
-+{"return": ""}
-+write -P0x76 0x3ff0000 0x10000
-+{"return": ""}
-+{
-+  "bitmaps": {}
-+}
-+
-+--- Reference mirror #0 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_0", "sync": "full", "target": "ref_target_0"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_0"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+--- Add Bitmap ---
-+
-+{"execute": "block-dirty-bitmap-add", "arguments": {"granularity": 65536, "name": "bitmap0", "node": "drive0"}}
-+{"return": {}}
-+
-+--- Write #1 ---
-+
-+write -P0x65 0x0000000 0x10000
-+{"return": ""}
-+write -P0x77 0x00f8000 0x10000
-+{"return": ""}
-+write -P0x72 0x2008000 0x10000
-+{"return": ""}
-+write -P0x69 0x3fe0000 0x10000
-+{"return": ""}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 393216,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 6 dirty sectors; have 6. OK!
-+
-+--- Reference mirror #1 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_1", "sync": "full", "target": "ref_target_1"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_1"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+--- Test mirror #1 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_1", "sync": "bitmap", "target": "mirror_target_1"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "mirror_1"}}
-+{"return": {}}
-+{"data": {"device": "mirror_1", "len": 393216, "offset": 393216, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"execute": "job-cancel", "arguments": {"id": "mirror_1"}}
-+{"return": {}}
-+{"data": {"id": "mirror_1", "type": "mirror"}, "event": "BLOCK_JOB_PENDING", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "mirror_1", "len": 393216, "offset": 393216, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_CANCELLED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 0,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 0 dirty sectors; have 0. OK!
-+
-+--- Reference mirror #2 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_2", "sync": "full", "target": "ref_target_2"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_2"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+--- Test mirror #2 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_2", "sync": "bitmap", "target": "mirror_target_2"}}
-+{"return": {}}
-+--- Write #2 ---
-+
-+write -P0x74 0x0010000 0x10000
-+{"return": ""}
-+write -P0x69 0x00e8000 0x10000
-+{"return": ""}
-+write -P0x6e 0x2018000 0x10000
-+{"return": ""}
-+write -P0x67 0x3fe0000 0x20000
-+{"return": ""}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 458752,
-+        "granularity": 65536,
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      },
-+      {
-+        "busy": true,
-+        "count": 458752,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "locked"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 7 dirty sectors; have 7. OK!
-+
-+= Checking Bitmap bitmap0 =
-+expecting 0 dirty sectors; have 0. OK!
-+
-+--- Write #3 ---
-+
-+write -P0xaa 0x0010000 0x30000
-+{"return": ""}
-+write -P0xbb 0x00d8000 0x10000
-+{"return": ""}
-+write -P0xcc 0x2028000 0x10000
-+{"return": ""}
-+write -P0xdd 0x3fc0000 0x10000
-+{"return": ""}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 524288,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 8 dirty sectors; have 8. OK!
-+
-+--- Reference mirror #3 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_3", "sync": "full", "target": "ref_target_3"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_3"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+--- Test mirror #3 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_3", "sync": "bitmap", "target": "mirror_target_3"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "mirror_3"}}
-+{"return": {}}
-+{"data": {"device": "mirror_3", "len": 524288, "offset": 524288, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"execute": "job-finalize", "arguments": {"id": "mirror_3"}}
-+{"return": {}}
-+{"data": {"id": "mirror_3", "type": "mirror"}, "event": "BLOCK_JOB_PENDING", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "mirror_3", "len": 524288, "offset": 524288, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 0,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 0 dirty sectors; have 0. OK!
-+
-+--- Cleanup ---
-+
-+{"execute": "block-dirty-bitmap-remove", "arguments": {"name": "bitmap0", "node": "drive0"}}
-+{"return": {}}
-+{
-+  "bitmaps": {}
-+}
-+
-+--- Verification ---
-+
-+qemu_img compare "TEST_DIR/PID-bsync1" "TEST_DIR/PID-fmirror1" ==> Identical, OK!
-+qemu_img compare "TEST_DIR/PID-bsync2" "TEST_DIR/PID-fmirror2" ==> Mismatch, OK!
-+qemu_img compare "TEST_DIR/PID-bsync3" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
-+qemu_img compare "TEST_DIR/PID-img" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
-+
-+
-+=== Mode bitmap; Bitmap Sync always with intermediate failure ===
-+
-+--- Preparing image & VM ---
-+
-+{"execute": "blockdev-add", "arguments": {"driver": "qcow2", "file": {"driver": "blkdebug", "image": {"driver": "file", "filename": "TEST_DIR/PID-img"}, "inject-error": [{"errno": 5, "event": "read_aio", "immediately": false, "once": true, "state": 3}, {"errno": 5, "event": "read_aio", "immediately": false, "once": true, "state": 4}], "set-state": [{"event": "flush_to_disk", "new-state": 2, "state": 1}, {"event": "read_aio", "new-state": 3, "state": 2}, {"event": "read_aio", "new-state": 4, "state": 3}]}, "node-name": "drive0"}}
-+{"return": {}}
-+
-+--- Write #0 ---
-+
-+write -P0x49 0x0000000 0x10000
-+{"return": ""}
-+write -P0x6c 0x0100000 0x10000
-+{"return": ""}
-+write -P0x6f 0x2000000 0x10000
-+{"return": ""}
-+write -P0x76 0x3ff0000 0x10000
-+{"return": ""}
-+{
-+  "bitmaps": {}
-+}
-+
-+--- Reference mirror #0 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_0", "sync": "full", "target": "ref_target_0"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_0"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+--- Add Bitmap ---
-+
-+{"execute": "block-dirty-bitmap-add", "arguments": {"granularity": 65536, "name": "bitmap0", "node": "drive0"}}
-+{"return": {}}
-+
-+--- Write #1 ---
-+
-+write -P0x65 0x0000000 0x10000
-+{"return": ""}
-+write -P0x77 0x00f8000 0x10000
-+{"return": ""}
-+write -P0x72 0x2008000 0x10000
-+{"return": ""}
-+write -P0x69 0x3fe0000 0x10000
-+{"return": ""}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 393216,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 6 dirty sectors; have 6. OK!
-+
-+--- Reference mirror #1 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_1", "sync": "full", "target": "ref_target_1"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_1"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+{"return": ""}
-+
-+--- Test mirror #1 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_1", "sync": "bitmap", "target": "mirror_target_1"}}
-+{"return": {}}
-+{"data": {"action": "report", "device": "mirror_1", "operation": "read"}, "event": "BLOCK_JOB_ERROR", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"action": "report", "device": "mirror_1", "operation": "read"}, "event": "BLOCK_JOB_ERROR", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "mirror_1", "error": "Input/output error", "len": 393216, "offset": 65536, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 327680,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 5 dirty sectors; have 5. OK!
-+
-+--- Reference mirror #2 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_2", "sync": "full", "target": "ref_target_2"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_2"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+--- Test mirror #2 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_2", "sync": "bitmap", "target": "mirror_target_2"}}
-+{"return": {}}
-+--- Write #2 ---
-+
-+write -P0x74 0x0010000 0x10000
-+{"return": ""}
-+write -P0x69 0x00e8000 0x10000
-+{"return": ""}
-+write -P0x6e 0x2018000 0x10000
-+{"return": ""}
-+write -P0x67 0x3fe0000 0x20000
-+{"return": ""}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 262144,
-+        "granularity": 65536,
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      },
-+      {
-+        "busy": true,
-+        "count": 589824,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "locked"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 9 dirty sectors; have 9. OK!
-+
-+= Checking Bitmap bitmap0 =
-+expecting 0 dirty sectors; have 0. OK!
-+
-+--- Write #3 ---
-+
-+write -P0xaa 0x0010000 0x30000
-+{"return": ""}
-+write -P0xbb 0x00d8000 0x10000
-+{"return": ""}
-+write -P0xcc 0x2028000 0x10000
-+{"return": ""}
-+write -P0xdd 0x3fc0000 0x10000
-+{"return": ""}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 524288,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 8 dirty sectors; have 8. OK!
-+
-+--- Reference mirror #3 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_3", "sync": "full", "target": "ref_target_3"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_3"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+--- Test mirror #3 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_3", "sync": "bitmap", "target": "mirror_target_3"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "mirror_3"}}
-+{"return": {}}
-+{"data": {"device": "mirror_3", "len": 524288, "offset": 524288, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"execute": "job-finalize", "arguments": {"id": "mirror_3"}}
-+{"return": {}}
-+{"data": {"id": "mirror_3", "type": "mirror"}, "event": "BLOCK_JOB_PENDING", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "mirror_3", "len": 524288, "offset": 524288, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 0,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 0 dirty sectors; have 0. OK!
-+
-+--- Cleanup ---
-+
-+{"execute": "block-dirty-bitmap-remove", "arguments": {"name": "bitmap0", "node": "drive0"}}
-+{"return": {}}
-+{
-+  "bitmaps": {}
-+}
-+
-+--- Verification ---
-+
-+qemu_img compare "TEST_DIR/PID-bsync1" "TEST_DIR/PID-fmirror1" ==> Mismatch, OK!
-+qemu_img compare "TEST_DIR/PID-bsync2" "TEST_DIR/PID-fmirror2" ==> Mismatch, OK!
-+qemu_img compare "TEST_DIR/PID-bsync3" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
-+qemu_img compare "TEST_DIR/PID-img" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
-+
-+
-+=== Mode bitmap; Bitmap Sync always without failure ===
-+
-+--- Preparing image & VM ---
-+
-+{"execute": "blockdev-add", "arguments": {"driver": "qcow2", "file": {"driver": "file", "filename": "TEST_DIR/PID-img"}, "node-name": "drive0"}}
-+{"return": {}}
-+
-+--- Write #0 ---
-+
-+write -P0x49 0x0000000 0x10000
-+{"return": ""}
-+write -P0x6c 0x0100000 0x10000
-+{"return": ""}
-+write -P0x6f 0x2000000 0x10000
-+{"return": ""}
-+write -P0x76 0x3ff0000 0x10000
-+{"return": ""}
-+{
-+  "bitmaps": {}
-+}
-+
-+--- Reference mirror #0 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_0", "sync": "full", "target": "ref_target_0"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_0"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_0", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+--- Add Bitmap ---
-+
-+{"execute": "block-dirty-bitmap-add", "arguments": {"granularity": 65536, "name": "bitmap0", "node": "drive0"}}
-+{"return": {}}
-+
-+--- Write #1 ---
-+
-+write -P0x65 0x0000000 0x10000
-+{"return": ""}
-+write -P0x77 0x00f8000 0x10000
-+{"return": ""}
-+write -P0x72 0x2008000 0x10000
-+{"return": ""}
-+write -P0x69 0x3fe0000 0x10000
-+{"return": ""}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 393216,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 6 dirty sectors; have 6. OK!
-+
-+--- Reference mirror #1 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_1", "sync": "full", "target": "ref_target_1"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_1"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_1", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+--- Test mirror #1 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_1", "sync": "bitmap", "target": "mirror_target_1"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "mirror_1"}}
-+{"return": {}}
-+{"data": {"device": "mirror_1", "len": 393216, "offset": 393216, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"execute": "job-finalize", "arguments": {"id": "mirror_1"}}
-+{"return": {}}
-+{"data": {"id": "mirror_1", "type": "mirror"}, "event": "BLOCK_JOB_PENDING", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "mirror_1", "len": 393216, "offset": 393216, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 0,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 0 dirty sectors; have 0. OK!
-+
-+--- Reference mirror #2 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_2", "sync": "full", "target": "ref_target_2"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_2"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_2", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+--- Test mirror #2 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_2", "sync": "bitmap", "target": "mirror_target_2"}}
-+{"return": {}}
-+--- Write #2 ---
-+
-+write -P0x74 0x0010000 0x10000
-+{"return": ""}
-+write -P0x69 0x00e8000 0x10000
-+{"return": ""}
-+write -P0x6e 0x2018000 0x10000
-+{"return": ""}
-+write -P0x67 0x3fe0000 0x20000
-+{"return": ""}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 458752,
-+        "granularity": 65536,
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      },
-+      {
-+        "busy": true,
-+        "count": 458752,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "locked"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 7 dirty sectors; have 7. OK!
-+
-+= Checking Bitmap bitmap0 =
-+expecting 0 dirty sectors; have 0. OK!
-+
-+--- Write #3 ---
-+
-+write -P0xaa 0x0010000 0x30000
-+{"return": ""}
-+write -P0xbb 0x00d8000 0x10000
-+{"return": ""}
-+write -P0xcc 0x2028000 0x10000
-+{"return": ""}
-+write -P0xdd 0x3fc0000 0x10000
-+{"return": ""}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 524288,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 8 dirty sectors; have 8. OK!
-+
-+--- Reference mirror #3 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "ref_mirror_3", "sync": "full", "target": "ref_target_3"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "ref_mirror_3"}}
-+{"return": {}}
-+{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "ref_mirror_3", "len": 67108864, "offset": 67108864, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+
-+--- Test mirror #3 ---
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+{"execute": "blockdev-mirror", "arguments": {"auto-finalize": false, "bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "mirror_3", "sync": "bitmap", "target": "mirror_target_3"}}
-+{"return": {}}
-+{"execute": "job-complete", "arguments": {"id": "mirror_3"}}
-+{"return": {}}
-+{"data": {"device": "mirror_3", "len": 524288, "offset": 524288, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"execute": "job-finalize", "arguments": {"id": "mirror_3"}}
-+{"return": {}}
-+{"data": {"id": "mirror_3", "type": "mirror"}, "event": "BLOCK_JOB_PENDING", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{"data": {"device": "mirror_3", "len": 524288, "offset": 524288, "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
-+{
-+  "bitmaps": {
-+    "drive0": [
-+      {
-+        "busy": false,
-+        "count": 0,
-+        "granularity": 65536,
-+        "name": "bitmap0",
-+        "persistent": false,
-+        "recording": true,
-+        "status": "active"
-+      }
-+    ]
-+  }
-+}
-+
-+= Checking Bitmap bitmap0 =
-+expecting 0 dirty sectors; have 0. OK!
-+
-+--- Cleanup ---
-+
-+{"execute": "block-dirty-bitmap-remove", "arguments": {"name": "bitmap0", "node": "drive0"}}
-+{"return": {}}
-+{
-+  "bitmaps": {}
-+}
-+
-+--- Verification ---
-+
-+qemu_img compare "TEST_DIR/PID-bsync1" "TEST_DIR/PID-fmirror1" ==> Identical, OK!
-+qemu_img compare "TEST_DIR/PID-bsync2" "TEST_DIR/PID-fmirror2" ==> Mismatch, OK!
-+qemu_img compare "TEST_DIR/PID-bsync3" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
-+qemu_img compare "TEST_DIR/PID-img" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
-+
-+
-+=== API failure tests ===
-+
-+--- Preparing image & VM ---
-+
-+{"execute": "blockdev-add", "arguments": {"driver": "qcow2", "file": {"driver": "file", "filename": "TEST_DIR/PID-img"}, "node-name": "drive0"}}
-+{"return": {}}
-+
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-file-job"}}
-+{"return": {}}
-+{}
-+{}
-+{"execute": "job-dismiss", "arguments": {"id": "bdc-fmt-job"}}
-+{"return": {}}
-+{}
-+
-+{"execute": "block-dirty-bitmap-add", "arguments": {"granularity": 65536, "name": "bitmap0", "node": "drive0"}}
-+{"return": {}}
-+
-+-- Testing invalid QMP commands --
-+
-+-- Sync mode incremental tests --
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Sync mode 'incremental' not supported"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "bitmap-mode must be specified if a bitmap is provided"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Sync mode 'incremental' not supported"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Sync mode 'incremental' not supported"}}
-+
-+-- Sync mode bitmap tests --
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "bitmap", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "bitmap", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "bitmap", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "bitmap", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Must provide a valid bitmap name for 'bitmap' sync mode"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "bitmap", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "bitmap", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "bitmap", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "bitmap", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "bitmap-mode must be specified if a bitmap is provided"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "bitmap", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "bitmap-mode must be specified if a bitmap is provided"}}
-+
-+-- Sync mode full tests --
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "bitmap-mode must be specified if a bitmap is provided"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "sync mode 'full' is not compatible with bitmaps"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "sync mode 'full' is not compatible with bitmaps"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "sync mode 'full' is not compatible with bitmaps"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "bitmap-mode must be specified if a bitmap is provided"}}
-+
-+-- Sync mode top tests --
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "bitmap-mode must be specified if a bitmap is provided"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "sync mode 'full' is not compatible with bitmaps"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "sync mode 'full' is not compatible with bitmaps"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "sync mode 'full' is not compatible with bitmaps"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "bitmap-mode must be specified if a bitmap is provided"}}
-+
-+-- Sync mode none tests --
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "bitmap-mode must be specified if a bitmap is provided"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "sync mode 'none' is not compatible with bitmaps"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "sync mode 'none' is not compatible with bitmaps"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "sync mode 'none' is not compatible with bitmaps"}}
-+
-+{"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
-+{"error": {"class": "GenericError", "desc": "bitmap-mode must be specified if a bitmap is provided"}}
-+
-diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
-index 2960dff728..952dceba1f 100644
---- a/tests/qemu-iotests/group
-+++ b/tests/qemu-iotests/group
-@@ -270,6 +270,7 @@
- 253 rw quick
- 254 rw backing quick
- 255 rw quick
-+384 rw
- 256 rw auto quick
- 257 rw
- 258 rw quick
diff --git a/debian/patches/pve/0035-mirror-move-some-checks-to-qmp.patch b/debian/patches/pve/0035-mirror-move-some-checks-to-qmp.patch
new file mode 100644 (file)
index 0000000..bfbb49f
--- /dev/null
@@ -0,0 +1,272 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= <f.gruenbichler@proxmox.com>
+Date: Mon, 6 Apr 2020 12:17:08 +0200
+Subject: [PATCH] mirror: move some checks to qmp
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+and assert the passing conditions in block/mirror.c. while incremental
+mode was never available for drive-mirror, it makes the interface more
+uniform w.r.t. backup block jobs.
+
+Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
+---
+ block/mirror.c             | 28 +++------------
+ blockdev.c                 | 29 +++++++++++++++
+ tests/qemu-iotests/384.out | 72 +++++++++++++++++++-------------------
+ 3 files changed, 70 insertions(+), 59 deletions(-)
+
+diff --git a/block/mirror.c b/block/mirror.c
+index e6140cf018..3a08239a78 100644
+--- a/block/mirror.c
++++ b/block/mirror.c
+@@ -1592,31 +1592,13 @@ static BlockJob *mirror_start_job(
+     Error *local_err = NULL;
+     int ret;
+-    if (sync_mode == MIRROR_SYNC_MODE_INCREMENTAL) {
+-        error_setg(errp, "Sync mode '%s' not supported",
+-                   MirrorSyncMode_str(sync_mode));
+-        return NULL;
+-    } else if (sync_mode == MIRROR_SYNC_MODE_BITMAP) {
+-        if (!bitmap) {
+-            error_setg(errp, "Must provide a valid bitmap name for '%s'"
+-                       " sync mode",
+-                       MirrorSyncMode_str(sync_mode));
+-            return NULL;
+-        }
+-    } else if (bitmap) {
+-        error_setg(errp,
+-                   "sync mode '%s' is not compatible with bitmaps",
+-                   MirrorSyncMode_str(sync_mode));
+-        return NULL;
+-    }
++    /* QMP interface protects us from these cases */
++    assert(sync_mode != MIRROR_SYNC_MODE_INCREMENTAL);
++    assert((bitmap && sync_mode == MIRROR_SYNC_MODE_BITMAP) ||
++           (!bitmap && sync_mode != MIRROR_SYNC_MODE_BITMAP));
++    assert(!(bitmap && granularity));
+     if (bitmap) {
+-        if (granularity) {
+-            error_setg(errp, "granularity (%d)"
+-                       "cannot be specified when a bitmap is provided",
+-                       granularity);
+-            return NULL;
+-        }
+         granularity = bdrv_dirty_bitmap_granularity(bitmap);
+         if (bitmap_mode != BITMAP_SYNC_MODE_NEVER) {
+diff --git a/blockdev.c b/blockdev.c
+index 827f004069..e2f826ca62 100644
+--- a/blockdev.c
++++ b/blockdev.c
+@@ -3009,7 +3009,36 @@ static void blockdev_mirror_common(const char *job_id, BlockDriverState *bs,
+         sync = MIRROR_SYNC_MODE_FULL;
+     }
++    if ((sync == MIRROR_SYNC_MODE_BITMAP) ||
++        (sync == MIRROR_SYNC_MODE_INCREMENTAL)) {
++        /* done before desugaring 'incremental' to print the right message */
++        if (!has_bitmap) {
++            error_setg(errp, "Must provide a valid bitmap name for "
++                       "'%s' sync mode", MirrorSyncMode_str(sync));
++            return;
++        }
++    }
++
++    if (sync == MIRROR_SYNC_MODE_INCREMENTAL) {
++        if (has_bitmap_mode &&
++            bitmap_mode != BITMAP_SYNC_MODE_ON_SUCCESS) {
++            error_setg(errp, "Bitmap sync mode must be '%s' "
++                       "when using sync mode '%s'",
++                       BitmapSyncMode_str(BITMAP_SYNC_MODE_ON_SUCCESS),
++                       MirrorSyncMode_str(sync));
++            return;
++        }
++        has_bitmap_mode = true;
++        sync = MIRROR_SYNC_MODE_BITMAP;
++        bitmap_mode = BITMAP_SYNC_MODE_ON_SUCCESS;
++    }
++
+     if (has_bitmap) {
++        if (sync != MIRROR_SYNC_MODE_BITMAP) {
++            error_setg(errp, "Sync mode '%s' not supported with bitmap.",
++                       MirrorSyncMode_str(sync));
++            return;
++        }
+         if (granularity) {
+             error_setg(errp, "Granularity and bitmap cannot both be set");
+             return;
+diff --git a/tests/qemu-iotests/384.out b/tests/qemu-iotests/384.out
+index 9b7408b6d6..06a2e29058 100644
+--- a/tests/qemu-iotests/384.out
++++ b/tests/qemu-iotests/384.out
+@@ -2681,45 +2681,45 @@ qemu_img compare "TEST_DIR/PID-img" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
+ -- Sync mode incremental tests --
+ {"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
++{"error": {"class": "GenericError", "desc": "Must provide a valid bitmap name for 'incremental' sync mode"}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
++{"error": {"class": "GenericError", "desc": "Must provide a valid bitmap name for 'incremental' sync mode"}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
++{"error": {"class": "GenericError", "desc": "Must provide a valid bitmap name for 'incremental' sync mode"}}
+ {"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "Sync mode 'incremental' not supported"}}
++{"error": {"class": "GenericError", "desc": "Must provide a valid bitmap name for 'incremental' sync mode"}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
+ {"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
++{"error": {"class": "GenericError", "desc": "Bitmap sync mode must be 'on-success' when using sync mode 'incremental'"}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
++{"error": {"class": "GenericError", "desc": "Bitmap sync mode must be 'on-success' when using sync mode 'incremental'"}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "bitmap-mode must be specified if a bitmap is provided"}}
++{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "Sync mode 'incremental' not supported"}}
++{"error": {"class": "GenericError", "desc": "Bitmap sync mode must be 'on-success' when using sync mode 'incremental'"}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "Sync mode 'incremental' not supported"}}
++{"error": {"class": "GenericError", "desc": "Bitmap sync mode must be 'on-success' when using sync mode 'incremental'"}}
+ -- Sync mode bitmap tests --
+ {"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "bitmap", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
++{"error": {"class": "GenericError", "desc": "Must provide a valid bitmap name for 'bitmap' sync mode"}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "bitmap", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
++{"error": {"class": "GenericError", "desc": "Must provide a valid bitmap name for 'bitmap' sync mode"}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "bitmap", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
++{"error": {"class": "GenericError", "desc": "Must provide a valid bitmap name for 'bitmap' sync mode"}}
+ {"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "bitmap", "target": "mirror_target"}}
+ {"error": {"class": "GenericError", "desc": "Must provide a valid bitmap name for 'bitmap' sync mode"}}
+@@ -2751,28 +2751,28 @@ qemu_img compare "TEST_DIR/PID-img" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
+ {"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
++{"error": {"class": "GenericError", "desc": "Sync mode 'full' not supported with bitmap."}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
++{"error": {"class": "GenericError", "desc": "Sync mode 'full' not supported with bitmap."}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
++{"error": {"class": "GenericError", "desc": "Sync mode 'full' not supported with bitmap."}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "bitmap-mode must be specified if a bitmap is provided"}}
++{"error": {"class": "GenericError", "desc": "Sync mode 'full' not supported with bitmap."}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "sync mode 'full' is not compatible with bitmaps"}}
++{"error": {"class": "GenericError", "desc": "Sync mode 'full' not supported with bitmap."}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "sync mode 'full' is not compatible with bitmaps"}}
++{"error": {"class": "GenericError", "desc": "Sync mode 'full' not supported with bitmap."}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "sync mode 'full' is not compatible with bitmaps"}}
++{"error": {"class": "GenericError", "desc": "Sync mode 'full' not supported with bitmap."}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "bitmap-mode must be specified if a bitmap is provided"}}
++{"error": {"class": "GenericError", "desc": "Sync mode 'full' not supported with bitmap."}}
+ -- Sync mode top tests --
+@@ -2786,28 +2786,28 @@ qemu_img compare "TEST_DIR/PID-img" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
+ {"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
++{"error": {"class": "GenericError", "desc": "Sync mode 'full' not supported with bitmap."}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
++{"error": {"class": "GenericError", "desc": "Sync mode 'full' not supported with bitmap."}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
++{"error": {"class": "GenericError", "desc": "Sync mode 'full' not supported with bitmap."}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "bitmap-mode must be specified if a bitmap is provided"}}
++{"error": {"class": "GenericError", "desc": "Sync mode 'full' not supported with bitmap."}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "sync mode 'full' is not compatible with bitmaps"}}
++{"error": {"class": "GenericError", "desc": "Sync mode 'full' not supported with bitmap."}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "sync mode 'full' is not compatible with bitmaps"}}
++{"error": {"class": "GenericError", "desc": "Sync mode 'full' not supported with bitmap."}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "sync mode 'full' is not compatible with bitmaps"}}
++{"error": {"class": "GenericError", "desc": "Sync mode 'full' not supported with bitmap."}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "bitmap-mode must be specified if a bitmap is provided"}}
++{"error": {"class": "GenericError", "desc": "Sync mode 'full' not supported with bitmap."}}
+ -- Sync mode none tests --
+@@ -2821,26 +2821,26 @@ qemu_img compare "TEST_DIR/PID-img" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
+ {"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
++{"error": {"class": "GenericError", "desc": "Sync mode 'none' not supported with bitmap."}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
++{"error": {"class": "GenericError", "desc": "Sync mode 'none' not supported with bitmap."}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
++{"error": {"class": "GenericError", "desc": "Sync mode 'none' not supported with bitmap."}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "bitmap-mode must be specified if a bitmap is provided"}}
++{"error": {"class": "GenericError", "desc": "Sync mode 'none' not supported with bitmap."}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "sync mode 'none' is not compatible with bitmaps"}}
++{"error": {"class": "GenericError", "desc": "Sync mode 'none' not supported with bitmap."}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "sync mode 'none' is not compatible with bitmaps"}}
++{"error": {"class": "GenericError", "desc": "Sync mode 'none' not supported with bitmap."}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "sync mode 'none' is not compatible with bitmaps"}}
++{"error": {"class": "GenericError", "desc": "Sync mode 'none' not supported with bitmap."}}
+ {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
+-{"error": {"class": "GenericError", "desc": "bitmap-mode must be specified if a bitmap is provided"}}
++{"error": {"class": "GenericError", "desc": "Sync mode 'none' not supported with bitmap."}}
diff --git a/debian/patches/pve/0036-PVE-Backup-Add-dirty-bitmap-tracking-for-incremental.patch b/debian/patches/pve/0036-PVE-Backup-Add-dirty-bitmap-tracking-for-incremental.patch
new file mode 100644 (file)
index 0000000..99322ce
--- /dev/null
@@ -0,0 +1,452 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Stefan Reiter <s.reiter@proxmox.com>
+Date: Mon, 29 Jun 2020 11:06:03 +0200
+Subject: [PATCH] PVE-Backup: Add dirty-bitmap tracking for incremental backups
+
+Uses QEMU's existing MIRROR_SYNC_MODE_BITMAP and a dirty-bitmap on top
+of all backed-up drives. This will only execute the data-write callback
+for any changed chunks, the PBS rust code will reuse chunks from the
+previous index for everything it doesn't receive if reuse_index is true.
+
+On error or cancellation, remove all dirty bitmaps to ensure
+consistency.
+
+Add PBS/incremental specific information to query backup info QMP and
+HMP commands.
+
+Only supported for PBS backups.
+
+Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
+Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
+Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
+---
+ block/monitor/block-hmp-cmds.c |   1 +
+ monitor/hmp-cmds.c             |  45 ++++++++++----
+ proxmox-backup-client.c        |   3 +-
+ proxmox-backup-client.h        |   1 +
+ pve-backup.c                   | 103 ++++++++++++++++++++++++++++++---
+ qapi/block-core.json           |  12 +++-
+ 6 files changed, 142 insertions(+), 23 deletions(-)
+
+diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c
+index 9ba7c774a2..056d14deee 100644
+--- a/block/monitor/block-hmp-cmds.c
++++ b/block/monitor/block-hmp-cmds.c
+@@ -1039,6 +1039,7 @@ void hmp_backup(Monitor *mon, const QDict *qdict)
+         false, NULL, // PBS fingerprint
+         false, NULL, // PBS backup-id
+         false, 0, // PBS backup-time
++        false, false, // PBS incremental
+         true, dir ? BACKUP_FORMAT_DIR : BACKUP_FORMAT_VMA,
+         false, NULL, false, NULL, !!devlist,
+         devlist, qdict_haskey(qdict, "speed"), speed, &error);
+diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
+index 182e79c943..604026bb37 100644
+--- a/monitor/hmp-cmds.c
++++ b/monitor/hmp-cmds.c
+@@ -221,19 +221,42 @@ void hmp_info_backup(Monitor *mon, const QDict *qdict)
+             monitor_printf(mon, "End time: %s", ctime(&info->end_time));
+         }
+-        int per = (info->has_total && info->total &&
+-            info->has_transferred && info->transferred) ?
+-            (info->transferred * 100)/info->total : 0;
+-        int zero_per = (info->has_total && info->total &&
+-                        info->has_zero_bytes && info->zero_bytes) ?
+-            (info->zero_bytes * 100)/info->total : 0;
+         monitor_printf(mon, "Backup file: %s\n", info->backup_file);
+         monitor_printf(mon, "Backup uuid: %s\n", info->uuid);
+-        monitor_printf(mon, "Total size: %zd\n", info->total);
+-        monitor_printf(mon, "Transferred bytes: %zd (%d%%)\n",
+-                       info->transferred, per);
+-        monitor_printf(mon, "Zero bytes: %zd (%d%%)\n",
+-                       info->zero_bytes, zero_per);
++
++        if (!(info->has_total && info->total))  {
++            // this should not happen normally
++            monitor_printf(mon, "Total size: %d\n", 0);
++        } else {
++            bool incremental = false;
++            size_t total_or_dirty = info->total;
++            if (info->has_transferred) {
++                if (info->has_dirty && info->dirty) {
++                     if (info->dirty < info->total) {
++                        total_or_dirty = info->dirty;
++                        incremental = true;
++                    }
++                }
++            }
++
++            int per = (info->transferred * 100)/total_or_dirty;
++
++            monitor_printf(mon, "Backup mode: %s\n", incremental ? "incremental" : "full");
++
++            int zero_per = (info->has_zero_bytes && info->zero_bytes) ?
++                (info->zero_bytes * 100)/info->total : 0;
++            monitor_printf(mon, "Total size: %zd\n", info->total);
++            monitor_printf(mon, "Transferred bytes: %zd (%d%%)\n",
++                           info->transferred, per);
++            monitor_printf(mon, "Zero bytes: %zd (%d%%)\n",
++                           info->zero_bytes, zero_per);
++
++            if (info->has_reused) {
++                int reused_per = (info->reused * 100)/total_or_dirty;
++                monitor_printf(mon, "Reused bytes: %zd (%d%%)\n",
++                               info->reused, reused_per);
++            }
++        }
+     }
+     qapi_free_BackupStatus(info);
+diff --git a/proxmox-backup-client.c b/proxmox-backup-client.c
+index a8f6653a81..4ce7bc0b5e 100644
+--- a/proxmox-backup-client.c
++++ b/proxmox-backup-client.c
+@@ -89,6 +89,7 @@ proxmox_backup_co_register_image(
+     ProxmoxBackupHandle *pbs,
+     const char *device_name,
+     uint64_t size,
++    bool incremental,
+     Error **errp)
+ {
+     Coroutine *co = qemu_coroutine_self();
+@@ -98,7 +99,7 @@ proxmox_backup_co_register_image(
+     int pbs_res = -1;
+     proxmox_backup_register_image_async(
+-        pbs, device_name, size ,proxmox_backup_schedule_wake, &waker, &pbs_res, &pbs_err);
++        pbs, device_name, size, incremental, proxmox_backup_schedule_wake, &waker, &pbs_res, &pbs_err);
+     qemu_coroutine_yield();
+     if (pbs_res < 0) {
+         if (errp) error_setg(errp, "backup register image failed: %s", pbs_err ? pbs_err : "unknown error");
+diff --git a/proxmox-backup-client.h b/proxmox-backup-client.h
+index 1dda8b7d8f..8cbf645b2c 100644
+--- a/proxmox-backup-client.h
++++ b/proxmox-backup-client.h
+@@ -32,6 +32,7 @@ proxmox_backup_co_register_image(
+     ProxmoxBackupHandle *pbs,
+     const char *device_name,
+     uint64_t size,
++    bool incremental,
+     Error **errp);
+diff --git a/pve-backup.c b/pve-backup.c
+index d40f3f2fd6..1cd9d31d7c 100644
+--- a/pve-backup.c
++++ b/pve-backup.c
+@@ -28,6 +28,8 @@
+  *
+  */
++const char *PBS_BITMAP_NAME = "pbs-incremental-dirty-bitmap";
++
+ static struct PVEBackupState {
+     struct {
+         // Everithing accessed from qmp_backup_query command is protected using lock
+@@ -39,7 +41,9 @@ static struct PVEBackupState {
+         uuid_t uuid;
+         char uuid_str[37];
+         size_t total;
++        size_t dirty;
+         size_t transferred;
++        size_t reused;
+         size_t zero_bytes;
+     } stat;
+     int64_t speed;
+@@ -66,6 +70,7 @@ typedef struct PVEBackupDevInfo {
+     uint8_t dev_id;
+     bool completed;
+     char targetfile[PATH_MAX];
++    BdrvDirtyBitmap *bitmap;
+     BlockDriverState *target;
+ } PVEBackupDevInfo;
+@@ -105,11 +110,12 @@ static bool pvebackup_error_or_canceled(void)
+     return error_or_canceled;
+ }
+-static void pvebackup_add_transfered_bytes(size_t transferred, size_t zero_bytes)
++static void pvebackup_add_transfered_bytes(size_t transferred, size_t zero_bytes, size_t reused)
+ {
+     qemu_mutex_lock(&backup_state.stat.lock);
+     backup_state.stat.zero_bytes += zero_bytes;
+     backup_state.stat.transferred += transferred;
++    backup_state.stat.reused += reused;
+     qemu_mutex_unlock(&backup_state.stat.lock);
+ }
+@@ -148,7 +154,8 @@ pvebackup_co_dump_pbs_cb(
+         pvebackup_propagate_error(local_err);
+         return pbs_res;
+     } else {
+-        pvebackup_add_transfered_bytes(size, !buf ? size : 0);
++        size_t reused = (pbs_res == 0) ? size : 0;
++        pvebackup_add_transfered_bytes(size, !buf ? size : 0, reused);
+     }
+     return size;
+@@ -208,11 +215,11 @@ pvebackup_co_dump_vma_cb(
+         } else {
+             if (remaining >= VMA_CLUSTER_SIZE) {
+                 assert(ret == VMA_CLUSTER_SIZE);
+-                pvebackup_add_transfered_bytes(VMA_CLUSTER_SIZE, zero_bytes);
++                pvebackup_add_transfered_bytes(VMA_CLUSTER_SIZE, zero_bytes, 0);
+                 remaining -= VMA_CLUSTER_SIZE;
+             } else {
+                 assert(ret == remaining);
+-                pvebackup_add_transfered_bytes(remaining, zero_bytes);
++                pvebackup_add_transfered_bytes(remaining, zero_bytes, 0);
+                 remaining = 0;
+             }
+         }
+@@ -248,6 +255,18 @@ static void coroutine_fn pvebackup_co_cleanup(void *unused)
+             if (local_err != NULL) {
+                 pvebackup_propagate_error(local_err);
+             }
++        } else {
++            // on error or cancel we cannot ensure synchronization of dirty
++            // bitmaps with backup server, so remove all and do full backup next
++            GList *l = backup_state.di_list;
++            while (l) {
++                PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
++                l = g_list_next(l);
++
++                if (di->bitmap) {
++                    bdrv_release_dirty_bitmap(di->bitmap);
++                }
++            }
+         }
+         proxmox_backup_disconnect(backup_state.pbs);
+@@ -303,6 +322,12 @@ static void pvebackup_complete_cb(void *opaque, int ret)
+     // remove self from job queue
+     backup_state.di_list = g_list_remove(backup_state.di_list, di);
++    if (di->bitmap && ret < 0) {
++        // on error or cancel we cannot ensure synchronization of dirty
++        // bitmaps with backup server, so remove all and do full backup next
++        bdrv_release_dirty_bitmap(di->bitmap);
++    }
++
+     g_free(di);
+     qemu_mutex_unlock(&backup_state.backup_mutex);
+@@ -470,12 +495,18 @@ static bool create_backup_jobs(void) {
+         assert(di->target != NULL);
++        MirrorSyncMode sync_mode = MIRROR_SYNC_MODE_FULL;
++        BitmapSyncMode bitmap_mode = BITMAP_SYNC_MODE_NEVER;
++        if (di->bitmap) {
++            sync_mode = MIRROR_SYNC_MODE_BITMAP;
++            bitmap_mode = BITMAP_SYNC_MODE_ON_SUCCESS;
++        }
+         AioContext *aio_context = bdrv_get_aio_context(di->bs);
+         aio_context_acquire(aio_context);
+         BlockJob *job = backup_job_create(
+-            NULL, di->bs, di->target, backup_state.speed, MIRROR_SYNC_MODE_FULL, NULL,
+-            BITMAP_SYNC_MODE_NEVER, false, NULL, BLOCKDEV_ON_ERROR_REPORT, BLOCKDEV_ON_ERROR_REPORT,
++            NULL, di->bs, di->target, backup_state.speed, sync_mode, di->bitmap,
++            bitmap_mode, false, NULL, BLOCKDEV_ON_ERROR_REPORT, BLOCKDEV_ON_ERROR_REPORT,
+             JOB_DEFAULT, pvebackup_complete_cb, di, 1, NULL, &local_err);
+         aio_context_release(aio_context);
+@@ -526,6 +557,8 @@ typedef struct QmpBackupTask {
+     const char *fingerprint;
+     bool has_fingerprint;
+     int64_t backup_time;
++    bool has_use_dirty_bitmap;
++    bool use_dirty_bitmap;
+     bool has_format;
+     BackupFormat format;
+     bool has_config_file;
+@@ -617,6 +650,7 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+     }
+     size_t total = 0;
++    size_t dirty = 0;
+     l = di_list;
+     while (l) {
+@@ -654,6 +688,8 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+         int dump_cb_block_size = PROXMOX_BACKUP_DEFAULT_CHUNK_SIZE; // Hardcoded (4M)
+         firewall_name = "fw.conf";
++        bool use_dirty_bitmap = task->has_use_dirty_bitmap && task->use_dirty_bitmap;
++
+         char *pbs_err = NULL;
+         pbs = proxmox_backup_new(
+             task->backup_file,
+@@ -673,7 +709,8 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+             goto err;
+         }
+-        if (proxmox_backup_co_connect(pbs, task->errp) < 0)
++        int connect_result = proxmox_backup_co_connect(pbs, task->errp);
++        if (connect_result < 0)
+             goto err;
+         /* register all devices */
+@@ -684,9 +721,40 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+             const char *devname = bdrv_get_device_name(di->bs);
+-            int dev_id = proxmox_backup_co_register_image(pbs, devname, di->size, task->errp);
+-            if (dev_id < 0)
++            BdrvDirtyBitmap *bitmap = bdrv_find_dirty_bitmap(di->bs, PBS_BITMAP_NAME);
++            bool expect_only_dirty = false;
++
++            if (use_dirty_bitmap) {
++                if (bitmap == NULL) {
++                    bitmap = bdrv_create_dirty_bitmap(di->bs, dump_cb_block_size, PBS_BITMAP_NAME, task->errp);
++                    if (!bitmap) {
++                        goto err;
++                    }
++                } else {
++                    expect_only_dirty = proxmox_backup_check_incremental(pbs, devname, di->size) != 0;
++                }
++
++                if (expect_only_dirty) {
++                    dirty += bdrv_get_dirty_count(bitmap);
++                } else {
++                    /* mark entire bitmap as dirty to make full backup */
++                    bdrv_set_dirty_bitmap(bitmap, 0, di->size);
++                    dirty += di->size;
++                }
++                di->bitmap = bitmap;
++            } else {
++                dirty += di->size;
++
++                /* after a full backup the old dirty bitmap is invalid anyway */
++                if (bitmap != NULL) {
++                    bdrv_release_dirty_bitmap(bitmap);
++                }
++            }
++
++            int dev_id = proxmox_backup_co_register_image(pbs, devname, di->size, expect_only_dirty, task->errp);
++            if (dev_id < 0) {
+                 goto err;
++            }
+             if (!(di->target = bdrv_backup_dump_create(dump_cb_block_size, di->size, pvebackup_co_dump_pbs_cb, di, task->errp))) {
+                 goto err;
+@@ -695,6 +763,8 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+             di->dev_id = dev_id;
+         }
+     } else if (format == BACKUP_FORMAT_VMA) {
++        dirty = total;
++
+         vmaw = vma_writer_create(task->backup_file, uuid, &local_err);
+         if (!vmaw) {
+             if (local_err) {
+@@ -722,6 +792,8 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+             }
+         }
+     } else if (format == BACKUP_FORMAT_DIR) {
++        dirty = total;
++
+         if (mkdir(task->backup_file, 0640) != 0) {
+             error_setg_errno(task->errp, errno, "can't create directory '%s'\n",
+                              task->backup_file);
+@@ -794,8 +866,10 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+     char *uuid_str = g_strdup(backup_state.stat.uuid_str);
+     backup_state.stat.total = total;
++    backup_state.stat.dirty = dirty;
+     backup_state.stat.transferred = 0;
+     backup_state.stat.zero_bytes = 0;
++    backup_state.stat.reused = format == BACKUP_FORMAT_PBS && dirty >= total ? 0 : total - dirty;
+     qemu_mutex_unlock(&backup_state.stat.lock);
+@@ -819,6 +893,10 @@ err:
+         PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
+         l = g_list_next(l);
++        if (di->bitmap) {
++            bdrv_release_dirty_bitmap(di->bitmap);
++        }
++
+         if (di->target) {
+             bdrv_unref(di->target);
+         }
+@@ -860,6 +938,7 @@ UuidInfo *qmp_backup(
+     bool has_fingerprint, const char *fingerprint,
+     bool has_backup_id, const char *backup_id,
+     bool has_backup_time, int64_t backup_time,
++    bool has_use_dirty_bitmap, bool use_dirty_bitmap,
+     bool has_format, BackupFormat format,
+     bool has_config_file, const char *config_file,
+     bool has_firewall_file, const char *firewall_file,
+@@ -878,6 +957,8 @@ UuidInfo *qmp_backup(
+         .backup_id = backup_id,
+         .has_backup_time = has_backup_time,
+         .backup_time = backup_time,
++        .has_use_dirty_bitmap = has_use_dirty_bitmap,
++        .use_dirty_bitmap = use_dirty_bitmap,
+         .has_format = has_format,
+         .format = format,
+         .has_config_file = has_config_file,
+@@ -946,10 +1027,14 @@ BackupStatus *qmp_query_backup(Error **errp)
+     info->has_total = true;
+     info->total = backup_state.stat.total;
++    info->has_dirty = true;
++    info->dirty = backup_state.stat.dirty;
+     info->has_zero_bytes = true;
+     info->zero_bytes = backup_state.stat.zero_bytes;
+     info->has_transferred = true;
+     info->transferred = backup_state.stat.transferred;
++    info->has_reused = true;
++    info->reused = backup_state.stat.reused;
+     qemu_mutex_unlock(&backup_state.stat.lock);
+diff --git a/qapi/block-core.json b/qapi/block-core.json
+index 9054db608c..d4e1c98c50 100644
+--- a/qapi/block-core.json
++++ b/qapi/block-core.json
+@@ -758,8 +758,13 @@
+ #
+ # @total: total amount of bytes involved in the backup process
+ #
++# @dirty: with incremental mode (PBS) this is the amount of bytes involved
++#         in the backup process which are marked dirty.
++#
+ # @transferred: amount of bytes already backed up.
+ #
++# @reused: amount of bytes reused due to deduplication.
++#
+ # @zero-bytes: amount of 'zero' bytes detected.
+ #
+ # @start-time: time (epoch) when backup job started.
+@@ -772,8 +777,8 @@
+ #
+ ##
+ { 'struct': 'BackupStatus',
+-  'data': {'*status': 'str', '*errmsg': 'str', '*total': 'int',
+-           '*transferred': 'int', '*zero-bytes': 'int',
++  'data': {'*status': 'str', '*errmsg': 'str', '*total': 'int', '*dirty': 'int',
++           '*transferred': 'int', '*zero-bytes': 'int', '*reused': 'int',
+            '*start-time': 'int', '*end-time': 'int',
+            '*backup-file': 'str', '*uuid': 'str' } }
+@@ -816,6 +821,8 @@
+ #
+ # @backup-time: backup timestamp (Unix epoch, required for format 'pbs')
+ #
++# @use-dirty-bitmap: use dirty bitmap to detect incremental changes since last job (optional for format 'pbs')
++#
+ # Returns: the uuid of the backup job
+ #
+ ##
+@@ -826,6 +833,7 @@
+                                     '*fingerprint': 'str',
+                                     '*backup-id': 'str',
+                                     '*backup-time': 'int',
++                                    '*use-dirty-bitmap': 'bool',
+                                     '*format': 'BackupFormat',
+                                     '*config-file': 'str',
+                                     '*firewall-file': 'str',
diff --git a/debian/patches/pve/0036-mirror-move-some-checks-to-qmp.patch b/debian/patches/pve/0036-mirror-move-some-checks-to-qmp.patch
deleted file mode 100644 (file)
index bfbb49f..0000000
+++ /dev/null
@@ -1,272 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= <f.gruenbichler@proxmox.com>
-Date: Mon, 6 Apr 2020 12:17:08 +0200
-Subject: [PATCH] mirror: move some checks to qmp
-MIME-Version: 1.0
-Content-Type: text/plain; charset=UTF-8
-Content-Transfer-Encoding: 8bit
-
-and assert the passing conditions in block/mirror.c. while incremental
-mode was never available for drive-mirror, it makes the interface more
-uniform w.r.t. backup block jobs.
-
-Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
----
- block/mirror.c             | 28 +++------------
- blockdev.c                 | 29 +++++++++++++++
- tests/qemu-iotests/384.out | 72 +++++++++++++++++++-------------------
- 3 files changed, 70 insertions(+), 59 deletions(-)
-
-diff --git a/block/mirror.c b/block/mirror.c
-index e6140cf018..3a08239a78 100644
---- a/block/mirror.c
-+++ b/block/mirror.c
-@@ -1592,31 +1592,13 @@ static BlockJob *mirror_start_job(
-     Error *local_err = NULL;
-     int ret;
--    if (sync_mode == MIRROR_SYNC_MODE_INCREMENTAL) {
--        error_setg(errp, "Sync mode '%s' not supported",
--                   MirrorSyncMode_str(sync_mode));
--        return NULL;
--    } else if (sync_mode == MIRROR_SYNC_MODE_BITMAP) {
--        if (!bitmap) {
--            error_setg(errp, "Must provide a valid bitmap name for '%s'"
--                       " sync mode",
--                       MirrorSyncMode_str(sync_mode));
--            return NULL;
--        }
--    } else if (bitmap) {
--        error_setg(errp,
--                   "sync mode '%s' is not compatible with bitmaps",
--                   MirrorSyncMode_str(sync_mode));
--        return NULL;
--    }
-+    /* QMP interface protects us from these cases */
-+    assert(sync_mode != MIRROR_SYNC_MODE_INCREMENTAL);
-+    assert((bitmap && sync_mode == MIRROR_SYNC_MODE_BITMAP) ||
-+           (!bitmap && sync_mode != MIRROR_SYNC_MODE_BITMAP));
-+    assert(!(bitmap && granularity));
-     if (bitmap) {
--        if (granularity) {
--            error_setg(errp, "granularity (%d)"
--                       "cannot be specified when a bitmap is provided",
--                       granularity);
--            return NULL;
--        }
-         granularity = bdrv_dirty_bitmap_granularity(bitmap);
-         if (bitmap_mode != BITMAP_SYNC_MODE_NEVER) {
-diff --git a/blockdev.c b/blockdev.c
-index 827f004069..e2f826ca62 100644
---- a/blockdev.c
-+++ b/blockdev.c
-@@ -3009,7 +3009,36 @@ static void blockdev_mirror_common(const char *job_id, BlockDriverState *bs,
-         sync = MIRROR_SYNC_MODE_FULL;
-     }
-+    if ((sync == MIRROR_SYNC_MODE_BITMAP) ||
-+        (sync == MIRROR_SYNC_MODE_INCREMENTAL)) {
-+        /* done before desugaring 'incremental' to print the right message */
-+        if (!has_bitmap) {
-+            error_setg(errp, "Must provide a valid bitmap name for "
-+                       "'%s' sync mode", MirrorSyncMode_str(sync));
-+            return;
-+        }
-+    }
-+
-+    if (sync == MIRROR_SYNC_MODE_INCREMENTAL) {
-+        if (has_bitmap_mode &&
-+            bitmap_mode != BITMAP_SYNC_MODE_ON_SUCCESS) {
-+            error_setg(errp, "Bitmap sync mode must be '%s' "
-+                       "when using sync mode '%s'",
-+                       BitmapSyncMode_str(BITMAP_SYNC_MODE_ON_SUCCESS),
-+                       MirrorSyncMode_str(sync));
-+            return;
-+        }
-+        has_bitmap_mode = true;
-+        sync = MIRROR_SYNC_MODE_BITMAP;
-+        bitmap_mode = BITMAP_SYNC_MODE_ON_SUCCESS;
-+    }
-+
-     if (has_bitmap) {
-+        if (sync != MIRROR_SYNC_MODE_BITMAP) {
-+            error_setg(errp, "Sync mode '%s' not supported with bitmap.",
-+                       MirrorSyncMode_str(sync));
-+            return;
-+        }
-         if (granularity) {
-             error_setg(errp, "Granularity and bitmap cannot both be set");
-             return;
-diff --git a/tests/qemu-iotests/384.out b/tests/qemu-iotests/384.out
-index 9b7408b6d6..06a2e29058 100644
---- a/tests/qemu-iotests/384.out
-+++ b/tests/qemu-iotests/384.out
-@@ -2681,45 +2681,45 @@ qemu_img compare "TEST_DIR/PID-img" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
- -- Sync mode incremental tests --
- {"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
-+{"error": {"class": "GenericError", "desc": "Must provide a valid bitmap name for 'incremental' sync mode"}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
-+{"error": {"class": "GenericError", "desc": "Must provide a valid bitmap name for 'incremental' sync mode"}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
-+{"error": {"class": "GenericError", "desc": "Must provide a valid bitmap name for 'incremental' sync mode"}}
- {"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "Sync mode 'incremental' not supported"}}
-+{"error": {"class": "GenericError", "desc": "Must provide a valid bitmap name for 'incremental' sync mode"}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
- {"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
-+{"error": {"class": "GenericError", "desc": "Bitmap sync mode must be 'on-success' when using sync mode 'incremental'"}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
-+{"error": {"class": "GenericError", "desc": "Bitmap sync mode must be 'on-success' when using sync mode 'incremental'"}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "bitmap-mode must be specified if a bitmap is provided"}}
-+{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "Sync mode 'incremental' not supported"}}
-+{"error": {"class": "GenericError", "desc": "Bitmap sync mode must be 'on-success' when using sync mode 'incremental'"}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "incremental", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "Sync mode 'incremental' not supported"}}
-+{"error": {"class": "GenericError", "desc": "Bitmap sync mode must be 'on-success' when using sync mode 'incremental'"}}
- -- Sync mode bitmap tests --
- {"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "bitmap", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
-+{"error": {"class": "GenericError", "desc": "Must provide a valid bitmap name for 'bitmap' sync mode"}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "bitmap", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
-+{"error": {"class": "GenericError", "desc": "Must provide a valid bitmap name for 'bitmap' sync mode"}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "bitmap", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
-+{"error": {"class": "GenericError", "desc": "Must provide a valid bitmap name for 'bitmap' sync mode"}}
- {"execute": "blockdev-mirror", "arguments": {"device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "bitmap", "target": "mirror_target"}}
- {"error": {"class": "GenericError", "desc": "Must provide a valid bitmap name for 'bitmap' sync mode"}}
-@@ -2751,28 +2751,28 @@ qemu_img compare "TEST_DIR/PID-img" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
- {"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
-+{"error": {"class": "GenericError", "desc": "Sync mode 'full' not supported with bitmap."}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
-+{"error": {"class": "GenericError", "desc": "Sync mode 'full' not supported with bitmap."}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
-+{"error": {"class": "GenericError", "desc": "Sync mode 'full' not supported with bitmap."}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "bitmap-mode must be specified if a bitmap is provided"}}
-+{"error": {"class": "GenericError", "desc": "Sync mode 'full' not supported with bitmap."}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "sync mode 'full' is not compatible with bitmaps"}}
-+{"error": {"class": "GenericError", "desc": "Sync mode 'full' not supported with bitmap."}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "sync mode 'full' is not compatible with bitmaps"}}
-+{"error": {"class": "GenericError", "desc": "Sync mode 'full' not supported with bitmap."}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "sync mode 'full' is not compatible with bitmaps"}}
-+{"error": {"class": "GenericError", "desc": "Sync mode 'full' not supported with bitmap."}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "full", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "bitmap-mode must be specified if a bitmap is provided"}}
-+{"error": {"class": "GenericError", "desc": "Sync mode 'full' not supported with bitmap."}}
- -- Sync mode top tests --
-@@ -2786,28 +2786,28 @@ qemu_img compare "TEST_DIR/PID-img" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
- {"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
-+{"error": {"class": "GenericError", "desc": "Sync mode 'full' not supported with bitmap."}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
-+{"error": {"class": "GenericError", "desc": "Sync mode 'full' not supported with bitmap."}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
-+{"error": {"class": "GenericError", "desc": "Sync mode 'full' not supported with bitmap."}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "bitmap-mode must be specified if a bitmap is provided"}}
-+{"error": {"class": "GenericError", "desc": "Sync mode 'full' not supported with bitmap."}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "sync mode 'full' is not compatible with bitmaps"}}
-+{"error": {"class": "GenericError", "desc": "Sync mode 'full' not supported with bitmap."}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "sync mode 'full' is not compatible with bitmaps"}}
-+{"error": {"class": "GenericError", "desc": "Sync mode 'full' not supported with bitmap."}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "sync mode 'full' is not compatible with bitmaps"}}
-+{"error": {"class": "GenericError", "desc": "Sync mode 'full' not supported with bitmap."}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "top", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "bitmap-mode must be specified if a bitmap is provided"}}
-+{"error": {"class": "GenericError", "desc": "Sync mode 'full' not supported with bitmap."}}
- -- Sync mode none tests --
-@@ -2821,26 +2821,26 @@ qemu_img compare "TEST_DIR/PID-img" "TEST_DIR/PID-fmirror3" ==> Identical, OK!
- {"error": {"class": "GenericError", "desc": "Cannot specify bitmap sync mode without a bitmap"}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
-+{"error": {"class": "GenericError", "desc": "Sync mode 'none' not supported with bitmap."}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
-+{"error": {"class": "GenericError", "desc": "Sync mode 'none' not supported with bitmap."}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap404' not found"}}
-+{"error": {"class": "GenericError", "desc": "Sync mode 'none' not supported with bitmap."}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap404", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "bitmap-mode must be specified if a bitmap is provided"}}
-+{"error": {"class": "GenericError", "desc": "Sync mode 'none' not supported with bitmap."}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "on-success", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "sync mode 'none' is not compatible with bitmaps"}}
-+{"error": {"class": "GenericError", "desc": "Sync mode 'none' not supported with bitmap."}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "always", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "sync mode 'none' is not compatible with bitmaps"}}
-+{"error": {"class": "GenericError", "desc": "Sync mode 'none' not supported with bitmap."}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "bitmap-mode": "never", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "sync mode 'none' is not compatible with bitmaps"}}
-+{"error": {"class": "GenericError", "desc": "Sync mode 'none' not supported with bitmap."}}
- {"execute": "blockdev-mirror", "arguments": {"bitmap": "bitmap0", "device": "drive0", "filter-node-name": "mirror-top", "job-id": "api_job", "sync": "none", "target": "mirror_target"}}
--{"error": {"class": "GenericError", "desc": "bitmap-mode must be specified if a bitmap is provided"}}
-+{"error": {"class": "GenericError", "desc": "Sync mode 'none' not supported with bitmap."}}
diff --git a/debian/patches/pve/0037-PVE-Backup-Add-dirty-bitmap-tracking-for-incremental.patch b/debian/patches/pve/0037-PVE-Backup-Add-dirty-bitmap-tracking-for-incremental.patch
deleted file mode 100644 (file)
index b5c2dab..0000000
+++ /dev/null
@@ -1,444 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: Stefan Reiter <s.reiter@proxmox.com>
-Date: Mon, 29 Jun 2020 11:06:03 +0200
-Subject: [PATCH] PVE-Backup: Add dirty-bitmap tracking for incremental backups
-
-Uses QEMU's existing MIRROR_SYNC_MODE_BITMAP and a dirty-bitmap on top
-of all backed-up drives. This will only execute the data-write callback
-for any changed chunks, the PBS rust code will reuse chunks from the
-previous index for everything it doesn't receive if reuse_index is true.
-
-On error or cancellation, remove all dirty bitmaps to ensure
-consistency.
-
-Add PBS/incremental specific information to query backup info QMP and
-HMP commands.
-
-Only supported for PBS backups.
-
-Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
-Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
-Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
----
- block/monitor/block-hmp-cmds.c |  1 +
- monitor/hmp-cmds.c             | 45 ++++++++++++----
- proxmox-backup-client.c        |  3 +-
- proxmox-backup-client.h        |  1 +
- pve-backup.c                   | 95 ++++++++++++++++++++++++++++++----
- qapi/block-core.json           | 12 ++++-
- 6 files changed, 134 insertions(+), 23 deletions(-)
-
-diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c
-index 9ba7c774a2..056d14deee 100644
---- a/block/monitor/block-hmp-cmds.c
-+++ b/block/monitor/block-hmp-cmds.c
-@@ -1039,6 +1039,7 @@ void hmp_backup(Monitor *mon, const QDict *qdict)
-         false, NULL, // PBS fingerprint
-         false, NULL, // PBS backup-id
-         false, 0, // PBS backup-time
-+        false, false, // PBS incremental
-         true, dir ? BACKUP_FORMAT_DIR : BACKUP_FORMAT_VMA,
-         false, NULL, false, NULL, !!devlist,
-         devlist, qdict_haskey(qdict, "speed"), speed, &error);
-diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
-index 182e79c943..604026bb37 100644
---- a/monitor/hmp-cmds.c
-+++ b/monitor/hmp-cmds.c
-@@ -221,19 +221,42 @@ void hmp_info_backup(Monitor *mon, const QDict *qdict)
-             monitor_printf(mon, "End time: %s", ctime(&info->end_time));
-         }
--        int per = (info->has_total && info->total &&
--            info->has_transferred && info->transferred) ?
--            (info->transferred * 100)/info->total : 0;
--        int zero_per = (info->has_total && info->total &&
--                        info->has_zero_bytes && info->zero_bytes) ?
--            (info->zero_bytes * 100)/info->total : 0;
-         monitor_printf(mon, "Backup file: %s\n", info->backup_file);
-         monitor_printf(mon, "Backup uuid: %s\n", info->uuid);
--        monitor_printf(mon, "Total size: %zd\n", info->total);
--        monitor_printf(mon, "Transferred bytes: %zd (%d%%)\n",
--                       info->transferred, per);
--        monitor_printf(mon, "Zero bytes: %zd (%d%%)\n",
--                       info->zero_bytes, zero_per);
-+
-+        if (!(info->has_total && info->total))  {
-+            // this should not happen normally
-+            monitor_printf(mon, "Total size: %d\n", 0);
-+        } else {
-+            bool incremental = false;
-+            size_t total_or_dirty = info->total;
-+            if (info->has_transferred) {
-+                if (info->has_dirty && info->dirty) {
-+                     if (info->dirty < info->total) {
-+                        total_or_dirty = info->dirty;
-+                        incremental = true;
-+                    }
-+                }
-+            }
-+
-+            int per = (info->transferred * 100)/total_or_dirty;
-+
-+            monitor_printf(mon, "Backup mode: %s\n", incremental ? "incremental" : "full");
-+
-+            int zero_per = (info->has_zero_bytes && info->zero_bytes) ?
-+                (info->zero_bytes * 100)/info->total : 0;
-+            monitor_printf(mon, "Total size: %zd\n", info->total);
-+            monitor_printf(mon, "Transferred bytes: %zd (%d%%)\n",
-+                           info->transferred, per);
-+            monitor_printf(mon, "Zero bytes: %zd (%d%%)\n",
-+                           info->zero_bytes, zero_per);
-+
-+            if (info->has_reused) {
-+                int reused_per = (info->reused * 100)/total_or_dirty;
-+                monitor_printf(mon, "Reused bytes: %zd (%d%%)\n",
-+                               info->reused, reused_per);
-+            }
-+        }
-     }
-     qapi_free_BackupStatus(info);
-diff --git a/proxmox-backup-client.c b/proxmox-backup-client.c
-index a8f6653a81..4ce7bc0b5e 100644
---- a/proxmox-backup-client.c
-+++ b/proxmox-backup-client.c
-@@ -89,6 +89,7 @@ proxmox_backup_co_register_image(
-     ProxmoxBackupHandle *pbs,
-     const char *device_name,
-     uint64_t size,
-+    bool incremental,
-     Error **errp)
- {
-     Coroutine *co = qemu_coroutine_self();
-@@ -98,7 +99,7 @@ proxmox_backup_co_register_image(
-     int pbs_res = -1;
-     proxmox_backup_register_image_async(
--        pbs, device_name, size ,proxmox_backup_schedule_wake, &waker, &pbs_res, &pbs_err);
-+        pbs, device_name, size, incremental, proxmox_backup_schedule_wake, &waker, &pbs_res, &pbs_err);
-     qemu_coroutine_yield();
-     if (pbs_res < 0) {
-         if (errp) error_setg(errp, "backup register image failed: %s", pbs_err ? pbs_err : "unknown error");
-diff --git a/proxmox-backup-client.h b/proxmox-backup-client.h
-index 1dda8b7d8f..8cbf645b2c 100644
---- a/proxmox-backup-client.h
-+++ b/proxmox-backup-client.h
-@@ -32,6 +32,7 @@ proxmox_backup_co_register_image(
-     ProxmoxBackupHandle *pbs,
-     const char *device_name,
-     uint64_t size,
-+    bool incremental,
-     Error **errp);
-diff --git a/pve-backup.c b/pve-backup.c
-index d40f3f2fd6..d50f03a050 100644
---- a/pve-backup.c
-+++ b/pve-backup.c
-@@ -28,6 +28,8 @@
-  *
-  */
-+const char *PBS_BITMAP_NAME = "pbs-incremental-dirty-bitmap";
-+
- static struct PVEBackupState {
-     struct {
-         // Everithing accessed from qmp_backup_query command is protected using lock
-@@ -39,7 +41,9 @@ static struct PVEBackupState {
-         uuid_t uuid;
-         char uuid_str[37];
-         size_t total;
-+        size_t dirty;
-         size_t transferred;
-+        size_t reused;
-         size_t zero_bytes;
-     } stat;
-     int64_t speed;
-@@ -66,6 +70,7 @@ typedef struct PVEBackupDevInfo {
-     uint8_t dev_id;
-     bool completed;
-     char targetfile[PATH_MAX];
-+    BdrvDirtyBitmap *bitmap;
-     BlockDriverState *target;
- } PVEBackupDevInfo;
-@@ -105,11 +110,12 @@ static bool pvebackup_error_or_canceled(void)
-     return error_or_canceled;
- }
--static void pvebackup_add_transfered_bytes(size_t transferred, size_t zero_bytes)
-+static void pvebackup_add_transfered_bytes(size_t transferred, size_t zero_bytes, size_t reused)
- {
-     qemu_mutex_lock(&backup_state.stat.lock);
-     backup_state.stat.zero_bytes += zero_bytes;
-     backup_state.stat.transferred += transferred;
-+    backup_state.stat.reused += reused;
-     qemu_mutex_unlock(&backup_state.stat.lock);
- }
-@@ -148,7 +154,8 @@ pvebackup_co_dump_pbs_cb(
-         pvebackup_propagate_error(local_err);
-         return pbs_res;
-     } else {
--        pvebackup_add_transfered_bytes(size, !buf ? size : 0);
-+        size_t reused = (pbs_res == 0) ? size : 0;
-+        pvebackup_add_transfered_bytes(size, !buf ? size : 0, reused);
-     }
-     return size;
-@@ -208,11 +215,11 @@ pvebackup_co_dump_vma_cb(
-         } else {
-             if (remaining >= VMA_CLUSTER_SIZE) {
-                 assert(ret == VMA_CLUSTER_SIZE);
--                pvebackup_add_transfered_bytes(VMA_CLUSTER_SIZE, zero_bytes);
-+                pvebackup_add_transfered_bytes(VMA_CLUSTER_SIZE, zero_bytes, 0);
-                 remaining -= VMA_CLUSTER_SIZE;
-             } else {
-                 assert(ret == remaining);
--                pvebackup_add_transfered_bytes(remaining, zero_bytes);
-+                pvebackup_add_transfered_bytes(remaining, zero_bytes, 0);
-                 remaining = 0;
-             }
-         }
-@@ -248,6 +255,18 @@ static void coroutine_fn pvebackup_co_cleanup(void *unused)
-             if (local_err != NULL) {
-                 pvebackup_propagate_error(local_err);
-             }
-+        } else {
-+            // on error or cancel we cannot ensure synchronization of dirty
-+            // bitmaps with backup server, so remove all and do full backup next
-+            GList *l = backup_state.di_list;
-+            while (l) {
-+                PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
-+                l = g_list_next(l);
-+
-+                if (di->bitmap) {
-+                    bdrv_release_dirty_bitmap(di->bitmap);
-+                }
-+            }
-         }
-         proxmox_backup_disconnect(backup_state.pbs);
-@@ -303,6 +322,12 @@ static void pvebackup_complete_cb(void *opaque, int ret)
-     // remove self from job queue
-     backup_state.di_list = g_list_remove(backup_state.di_list, di);
-+    if (di->bitmap && ret < 0) {
-+        // on error or cancel we cannot ensure synchronization of dirty
-+        // bitmaps with backup server, so remove all and do full backup next
-+        bdrv_release_dirty_bitmap(di->bitmap);
-+    }
-+
-     g_free(di);
-     qemu_mutex_unlock(&backup_state.backup_mutex);
-@@ -470,12 +495,18 @@ static bool create_backup_jobs(void) {
-         assert(di->target != NULL);
-+        MirrorSyncMode sync_mode = MIRROR_SYNC_MODE_FULL;
-+        BitmapSyncMode bitmap_mode = BITMAP_SYNC_MODE_NEVER;
-+        if (di->bitmap) {
-+            sync_mode = MIRROR_SYNC_MODE_BITMAP;
-+            bitmap_mode = BITMAP_SYNC_MODE_ON_SUCCESS;
-+        }
-         AioContext *aio_context = bdrv_get_aio_context(di->bs);
-         aio_context_acquire(aio_context);
-         BlockJob *job = backup_job_create(
--            NULL, di->bs, di->target, backup_state.speed, MIRROR_SYNC_MODE_FULL, NULL,
--            BITMAP_SYNC_MODE_NEVER, false, NULL, BLOCKDEV_ON_ERROR_REPORT, BLOCKDEV_ON_ERROR_REPORT,
-+            NULL, di->bs, di->target, backup_state.speed, sync_mode, di->bitmap,
-+            bitmap_mode, false, NULL, BLOCKDEV_ON_ERROR_REPORT, BLOCKDEV_ON_ERROR_REPORT,
-             JOB_DEFAULT, pvebackup_complete_cb, di, 1, NULL, &local_err);
-         aio_context_release(aio_context);
-@@ -526,6 +557,8 @@ typedef struct QmpBackupTask {
-     const char *fingerprint;
-     bool has_fingerprint;
-     int64_t backup_time;
-+    bool has_incremental;
-+    bool incremental;
-     bool has_format;
-     BackupFormat format;
-     bool has_config_file;
-@@ -617,6 +650,7 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-     }
-     size_t total = 0;
-+    size_t dirty = 0;
-     l = di_list;
-     while (l) {
-@@ -654,6 +688,8 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-         int dump_cb_block_size = PROXMOX_BACKUP_DEFAULT_CHUNK_SIZE; // Hardcoded (4M)
-         firewall_name = "fw.conf";
-+        bool incremental = task->has_incremental && task->incremental;
-+
-         char *pbs_err = NULL;
-         pbs = proxmox_backup_new(
-             task->backup_file,
-@@ -673,7 +709,8 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-             goto err;
-         }
--        if (proxmox_backup_co_connect(pbs, task->errp) < 0)
-+        int connect_result = proxmox_backup_co_connect(pbs, task->errp);
-+        if (connect_result < 0)
-             goto err;
-         /* register all devices */
-@@ -684,9 +721,32 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-             const char *devname = bdrv_get_device_name(di->bs);
--            int dev_id = proxmox_backup_co_register_image(pbs, devname, di->size, task->errp);
--            if (dev_id < 0)
-+            BdrvDirtyBitmap *bitmap = bdrv_find_dirty_bitmap(di->bs, PBS_BITMAP_NAME);
-+
-+            bool use_incremental = false;
-+            if (incremental) {
-+                if (bitmap == NULL) {
-+                    bitmap = bdrv_create_dirty_bitmap(di->bs, dump_cb_block_size, PBS_BITMAP_NAME, task->errp);
-+                    if (!bitmap) {
-+                        goto err;
-+                    }
-+                    /* mark entire bitmap as dirty to make full backup first */
-+                    bdrv_set_dirty_bitmap(bitmap, 0, di->size);
-+                    dirty += di->size;
-+                } else {
-+                    use_incremental = true;
-+                    dirty += bdrv_get_dirty_count(bitmap);
-+                }
-+                di->bitmap = bitmap;
-+            } else if (bitmap != NULL) {
-+                dirty += di->size;
-+                bdrv_release_dirty_bitmap(bitmap);
-+            }
-+
-+            int dev_id = proxmox_backup_co_register_image(pbs, devname, di->size, use_incremental, task->errp);
-+            if (dev_id < 0) {
-                 goto err;
-+            }
-             if (!(di->target = bdrv_backup_dump_create(dump_cb_block_size, di->size, pvebackup_co_dump_pbs_cb, di, task->errp))) {
-                 goto err;
-@@ -695,6 +755,8 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-             di->dev_id = dev_id;
-         }
-     } else if (format == BACKUP_FORMAT_VMA) {
-+        dirty = total;
-+
-         vmaw = vma_writer_create(task->backup_file, uuid, &local_err);
-         if (!vmaw) {
-             if (local_err) {
-@@ -722,6 +784,8 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-             }
-         }
-     } else if (format == BACKUP_FORMAT_DIR) {
-+        dirty = total;
-+
-         if (mkdir(task->backup_file, 0640) != 0) {
-             error_setg_errno(task->errp, errno, "can't create directory '%s'\n",
-                              task->backup_file);
-@@ -794,8 +858,10 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-     char *uuid_str = g_strdup(backup_state.stat.uuid_str);
-     backup_state.stat.total = total;
-+    backup_state.stat.dirty = dirty;
-     backup_state.stat.transferred = 0;
-     backup_state.stat.zero_bytes = 0;
-+    backup_state.stat.reused = dirty >= total ? 0 : total - dirty;
-     qemu_mutex_unlock(&backup_state.stat.lock);
-@@ -819,6 +885,10 @@ err:
-         PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
-         l = g_list_next(l);
-+        if (di->bitmap) {
-+            bdrv_release_dirty_bitmap(di->bitmap);
-+        }
-+
-         if (di->target) {
-             bdrv_unref(di->target);
-         }
-@@ -860,6 +930,7 @@ UuidInfo *qmp_backup(
-     bool has_fingerprint, const char *fingerprint,
-     bool has_backup_id, const char *backup_id,
-     bool has_backup_time, int64_t backup_time,
-+    bool has_incremental, bool incremental,
-     bool has_format, BackupFormat format,
-     bool has_config_file, const char *config_file,
-     bool has_firewall_file, const char *firewall_file,
-@@ -878,6 +949,8 @@ UuidInfo *qmp_backup(
-         .backup_id = backup_id,
-         .has_backup_time = has_backup_time,
-         .backup_time = backup_time,
-+        .has_incremental = has_incremental,
-+        .incremental = incremental,
-         .has_format = has_format,
-         .format = format,
-         .has_config_file = has_config_file,
-@@ -946,10 +1019,14 @@ BackupStatus *qmp_query_backup(Error **errp)
-     info->has_total = true;
-     info->total = backup_state.stat.total;
-+    info->has_dirty = true;
-+    info->dirty = backup_state.stat.dirty;
-     info->has_zero_bytes = true;
-     info->zero_bytes = backup_state.stat.zero_bytes;
-     info->has_transferred = true;
-     info->transferred = backup_state.stat.transferred;
-+    info->has_reused = true;
-+    info->reused = backup_state.stat.reused;
-     qemu_mutex_unlock(&backup_state.stat.lock);
-diff --git a/qapi/block-core.json b/qapi/block-core.json
-index 9054db608c..aadd5329b3 100644
---- a/qapi/block-core.json
-+++ b/qapi/block-core.json
-@@ -758,8 +758,13 @@
- #
- # @total: total amount of bytes involved in the backup process
- #
-+# @dirty: with incremental mode, this is the amount of bytes involved
-+#         in the backup process which are marked dirty.
-+#
- # @transferred: amount of bytes already backed up.
- #
-+# @reused: amount of bytes reused due to deduplication.
-+#
- # @zero-bytes: amount of 'zero' bytes detected.
- #
- # @start-time: time (epoch) when backup job started.
-@@ -772,8 +777,8 @@
- #
- ##
- { 'struct': 'BackupStatus',
--  'data': {'*status': 'str', '*errmsg': 'str', '*total': 'int',
--           '*transferred': 'int', '*zero-bytes': 'int',
-+  'data': {'*status': 'str', '*errmsg': 'str', '*total': 'int', '*dirty': 'int',
-+           '*transferred': 'int', '*zero-bytes': 'int', '*reused': 'int',
-            '*start-time': 'int', '*end-time': 'int',
-            '*backup-file': 'str', '*uuid': 'str' } }
-@@ -816,6 +821,8 @@
- #
- # @backup-time: backup timestamp (Unix epoch, required for format 'pbs')
- #
-+# @incremental: sync incremental changes since last job (optional for format 'pbs')
-+#
- # Returns: the uuid of the backup job
- #
- ##
-@@ -826,6 +833,7 @@
-                                     '*fingerprint': 'str',
-                                     '*backup-id': 'str',
-                                     '*backup-time': 'int',
-+                                    '*incremental': 'bool',
-                                     '*format': 'BackupFormat',
-                                     '*config-file': 'str',
-                                     '*firewall-file': 'str',
diff --git a/debian/patches/pve/0037-PVE-various-PBS-fixes.patch b/debian/patches/pve/0037-PVE-various-PBS-fixes.patch
new file mode 100644 (file)
index 0000000..7ab4bfe
--- /dev/null
@@ -0,0 +1,218 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Dietmar Maurer <dietmar@proxmox.com>
+Date: Thu, 9 Jul 2020 12:53:08 +0200
+Subject: [PATCH] PVE: various PBS fixes
+
+pbs: fix crypt and compress parameters
+Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
+
+PVE: handle PBS write callback with big blocks correctly
+Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
+
+PVE: add zero block handling to PBS dump callback
+Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
+---
+ block/monitor/block-hmp-cmds.c |  4 ++-
+ pve-backup.c                   | 57 +++++++++++++++++++++++++++-------
+ qapi/block-core.json           |  6 ++++
+ 3 files changed, 54 insertions(+), 13 deletions(-)
+
+diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c
+index 056d14deee..46c63b1cf9 100644
+--- a/block/monitor/block-hmp-cmds.c
++++ b/block/monitor/block-hmp-cmds.c
+@@ -1039,7 +1039,9 @@ void hmp_backup(Monitor *mon, const QDict *qdict)
+         false, NULL, // PBS fingerprint
+         false, NULL, // PBS backup-id
+         false, 0, // PBS backup-time
+-        false, false, // PBS incremental
++        false, false, // PBS use-dirty-bitmap
++        false, false, // PBS compress
++        false, false, // PBS encrypt
+         true, dir ? BACKUP_FORMAT_DIR : BACKUP_FORMAT_VMA,
+         false, NULL, false, NULL, !!devlist,
+         devlist, qdict_haskey(qdict, "speed"), speed, &error);
+diff --git a/pve-backup.c b/pve-backup.c
+index 1cd9d31d7c..b8182aaf89 100644
+--- a/pve-backup.c
++++ b/pve-backup.c
+@@ -8,6 +8,7 @@
+ #include "block/blockjob.h"
+ #include "qapi/qapi-commands-block.h"
+ #include "qapi/qmp/qerror.h"
++#include "qemu/cutils.h"
+ /* PVE backup state and related function */
+@@ -67,6 +68,7 @@ opts_init(pvebackup_init);
+ typedef struct PVEBackupDevInfo {
+     BlockDriverState *bs;
+     size_t size;
++    uint64_t block_size;
+     uint8_t dev_id;
+     bool completed;
+     char targetfile[PATH_MAX];
+@@ -135,10 +137,13 @@ pvebackup_co_dump_pbs_cb(
+     PVEBackupDevInfo *di = opaque;
+     assert(backup_state.pbs);
++    assert(buf);
+     Error *local_err = NULL;
+     int pbs_res = -1;
++    bool is_zero_block = size == di->block_size && buffer_is_zero(buf, size);
++
+     qemu_co_mutex_lock(&backup_state.dump_callback_mutex);
+     // avoid deadlock if job is cancelled
+@@ -147,17 +152,29 @@ pvebackup_co_dump_pbs_cb(
+         return -1;
+     }
+-    pbs_res = proxmox_backup_co_write_data(backup_state.pbs, di->dev_id, buf, start, size, &local_err);
+-    qemu_co_mutex_unlock(&backup_state.dump_callback_mutex);
++    uint64_t transferred = 0;
++    uint64_t reused = 0;
++    while (transferred < size) {
++        uint64_t left = size - transferred;
++        uint64_t to_transfer = left < di->block_size ? left : di->block_size;
+-    if (pbs_res < 0) {
+-        pvebackup_propagate_error(local_err);
+-        return pbs_res;
+-    } else {
+-        size_t reused = (pbs_res == 0) ? size : 0;
+-        pvebackup_add_transfered_bytes(size, !buf ? size : 0, reused);
++        pbs_res = proxmox_backup_co_write_data(backup_state.pbs, di->dev_id,
++            is_zero_block ? NULL : buf + transferred, start + transferred,
++            to_transfer, &local_err);
++        transferred += to_transfer;
++
++        if (pbs_res < 0) {
++            pvebackup_propagate_error(local_err);
++            qemu_co_mutex_unlock(&backup_state.dump_callback_mutex);
++            return pbs_res;
++        }
++
++        reused += pbs_res == 0 ? to_transfer : 0;
+     }
++    qemu_co_mutex_unlock(&backup_state.dump_callback_mutex);
++    pvebackup_add_transfered_bytes(size, is_zero_block ? size : 0, reused);
++
+     return size;
+ }
+@@ -178,6 +195,7 @@ pvebackup_co_dump_vma_cb(
+     int ret = -1;
+     assert(backup_state.vmaw);
++    assert(buf);
+     uint64_t remaining = size;
+@@ -204,9 +222,7 @@ pvebackup_co_dump_vma_cb(
+         qemu_co_mutex_unlock(&backup_state.dump_callback_mutex);
+         ++cluster_num;
+-        if (buf) {
+-            buf += VMA_CLUSTER_SIZE;
+-        }
++        buf += VMA_CLUSTER_SIZE;
+         if (ret < 0) {
+             Error *local_err = NULL;
+             vma_writer_error_propagate(backup_state.vmaw, &local_err);
+@@ -567,6 +583,10 @@ typedef struct QmpBackupTask {
+     const char *firewall_file;
+     bool has_devlist;
+     const char *devlist;
++    bool has_compress;
++    bool compress;
++    bool has_encrypt;
++    bool encrypt;
+     bool has_speed;
+     int64_t speed;
+     Error **errp;
+@@ -690,6 +710,7 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+         bool use_dirty_bitmap = task->has_use_dirty_bitmap && task->use_dirty_bitmap;
++
+         char *pbs_err = NULL;
+         pbs = proxmox_backup_new(
+             task->backup_file,
+@@ -699,8 +720,10 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+             task->has_password ? task->password : NULL,
+             task->has_keyfile ? task->keyfile : NULL,
+             task->has_key_password ? task->key_password : NULL,
++            task->has_compress ? task->compress : true,
++            task->has_encrypt ? task->encrypt : task->has_keyfile,
+             task->has_fingerprint ? task->fingerprint : NULL,
+-            &pbs_err);
++             &pbs_err);
+         if (!pbs) {
+             error_set(task->errp, ERROR_CLASS_GENERIC_ERROR,
+@@ -719,6 +742,8 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+             PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
+             l = g_list_next(l);
++            di->block_size = dump_cb_block_size;
++
+             const char *devname = bdrv_get_device_name(di->bs);
+             BdrvDirtyBitmap *bitmap = bdrv_find_dirty_bitmap(di->bs, PBS_BITMAP_NAME);
+@@ -939,6 +964,8 @@ UuidInfo *qmp_backup(
+     bool has_backup_id, const char *backup_id,
+     bool has_backup_time, int64_t backup_time,
+     bool has_use_dirty_bitmap, bool use_dirty_bitmap,
++    bool has_compress, bool compress,
++    bool has_encrypt, bool encrypt,
+     bool has_format, BackupFormat format,
+     bool has_config_file, const char *config_file,
+     bool has_firewall_file, const char *firewall_file,
+@@ -949,6 +976,8 @@ UuidInfo *qmp_backup(
+         .backup_file = backup_file,
+         .has_password = has_password,
+         .password = password,
++        .has_keyfile = has_keyfile,
++        .keyfile = keyfile,
+         .has_key_password = has_key_password,
+         .key_password = key_password,
+         .has_fingerprint = has_fingerprint,
+@@ -959,6 +988,10 @@ UuidInfo *qmp_backup(
+         .backup_time = backup_time,
+         .has_use_dirty_bitmap = has_use_dirty_bitmap,
+         .use_dirty_bitmap = use_dirty_bitmap,
++        .has_compress = has_compress,
++        .compress = compress,
++        .has_encrypt = has_encrypt,
++        .encrypt = encrypt,
+         .has_format = has_format,
+         .format = format,
+         .has_config_file = has_config_file,
+diff --git a/qapi/block-core.json b/qapi/block-core.json
+index d4e1c98c50..0fda1e3fd3 100644
+--- a/qapi/block-core.json
++++ b/qapi/block-core.json
+@@ -823,6 +823,10 @@
+ #
+ # @use-dirty-bitmap: use dirty bitmap to detect incremental changes since last job (optional for format 'pbs')
+ #
++# @compress: use compression (optional for format 'pbs', defaults to true)
++#
++# @encrypt: use encryption ((optional for format 'pbs', defaults to true if there is a keyfile)
++#
+ # Returns: the uuid of the backup job
+ #
+ ##
+@@ -834,6 +838,8 @@
+                                     '*backup-id': 'str',
+                                     '*backup-time': 'int',
+                                     '*use-dirty-bitmap': 'bool',
++                                    '*compress': 'bool',
++                                    '*encrypt': 'bool',
+                                     '*format': 'BackupFormat',
+                                     '*config-file': 'str',
+                                     '*firewall-file': 'str',
diff --git a/debian/patches/pve/0038-PVE-Add-PBS-block-driver-to-map-backup-archives-into.patch b/debian/patches/pve/0038-PVE-Add-PBS-block-driver-to-map-backup-archives-into.patch
new file mode 100644 (file)
index 0000000..4c31eaa
--- /dev/null
@@ -0,0 +1,400 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Stefan Reiter <s.reiter@proxmox.com>
+Date: Wed, 8 Jul 2020 09:50:54 +0200
+Subject: [PATCH] PVE: Add PBS block driver to map backup archives into VMs
+
+Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
+[error cleanups, file_open implementation]
+Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
+---
+ block/meson.build    |   3 +
+ block/pbs.c          | 271 +++++++++++++++++++++++++++++++++++++++++++
+ configure            |   9 ++
+ meson.build          |   1 +
+ qapi/block-core.json |  14 ++-
+ 5 files changed, 297 insertions(+), 1 deletion(-)
+ create mode 100644 block/pbs.c
+
+diff --git a/block/meson.build b/block/meson.build
+index dfae565db3..a070060e53 100644
+--- a/block/meson.build
++++ b/block/meson.build
+@@ -49,6 +49,9 @@ block_ss.add(files(
+   '../pve-backup.c',
+ ), libproxmox_backup_qemu)
++block_ss.add(when: 'CONFIG_PBS_BDRV', if_true: files('pbs.c'))
++block_ss.add(when: 'CONFIG_PBS_BDRV', if_true: libproxmox_backup_qemu)
++
+ softmmu_ss.add(when: 'CONFIG_TCG', if_true: files('blkreplay.c'))
+diff --git a/block/pbs.c b/block/pbs.c
+new file mode 100644
+index 0000000000..1481a2bfd1
+--- /dev/null
++++ b/block/pbs.c
+@@ -0,0 +1,271 @@
++/*
++ * Proxmox Backup Server read-only block driver
++ */
++
++#include "qemu/osdep.h"
++#include "qapi/error.h"
++#include "qapi/qmp/qdict.h"
++#include "qapi/qmp/qstring.h"
++#include "qemu/module.h"
++#include "qemu/option.h"
++#include "qemu/cutils.h"
++#include "block/block_int.h"
++
++#include <proxmox-backup-qemu.h>
++
++#define PBS_OPT_REPOSITORY "repository"
++#define PBS_OPT_SNAPSHOT "snapshot"
++#define PBS_OPT_ARCHIVE "archive"
++#define PBS_OPT_KEYFILE "keyfile"
++#define PBS_OPT_PASSWORD "password"
++#define PBS_OPT_FINGERPRINT "fingerprint"
++#define PBS_OPT_ENCRYPTION_PASSWORD "key_password"
++
++typedef struct {
++    ProxmoxRestoreHandle *conn;
++    char aid;
++    int64_t length;
++
++    char *repository;
++    char *snapshot;
++    char *archive;
++} BDRVPBSState;
++
++static QemuOptsList runtime_opts = {
++    .name = "pbs",
++    .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head),
++    .desc = {
++        {
++            .name = PBS_OPT_REPOSITORY,
++            .type = QEMU_OPT_STRING,
++            .help = "The server address and repository to connect to.",
++        },
++        {
++            .name = PBS_OPT_SNAPSHOT,
++            .type = QEMU_OPT_STRING,
++            .help = "The snapshot to read.",
++        },
++        {
++            .name = PBS_OPT_ARCHIVE,
++            .type = QEMU_OPT_STRING,
++            .help = "Which archive within the snapshot should be accessed.",
++        },
++        {
++            .name = PBS_OPT_PASSWORD,
++            .type = QEMU_OPT_STRING,
++            .help = "Server password. Can be passed as env var 'PBS_PASSWORD'.",
++        },
++        {
++            .name = PBS_OPT_FINGERPRINT,
++            .type = QEMU_OPT_STRING,
++            .help = "Server fingerprint. Can be passed as env var 'PBS_FINGERPRINT'.",
++        },
++        {
++            .name = PBS_OPT_ENCRYPTION_PASSWORD,
++            .type = QEMU_OPT_STRING,
++            .help = "Optional: Key password. Can be passed as env var 'PBS_ENCRYPTION_PASSWORD'.",
++        },
++        {
++            .name = PBS_OPT_KEYFILE,
++            .type = QEMU_OPT_STRING,
++            .help = "Optional: The path to the keyfile to use.",
++        },
++        { /* end of list */ }
++    },
++};
++
++
++// filename format:
++// pbs:repository=<repo>,snapshot=<snap>,password=<pw>,key_password=<kpw>,fingerprint=<fp>,archive=<archive>
++static void pbs_parse_filename(const char *filename, QDict *options,
++                                     Error **errp)
++{
++
++    if (!strstart(filename, "pbs:", &filename)) {
++        if (errp) error_setg(errp, "pbs_parse_filename failed - missing 'pbs:' prefix");
++    }
++
++
++    QemuOpts *opts = qemu_opts_parse_noisily(&runtime_opts, filename, false);
++    if (!opts) {
++        if (errp) error_setg(errp, "pbs_parse_filename failed");
++        return;
++    }
++
++    qemu_opts_to_qdict(opts, options);
++
++    qemu_opts_del(opts);
++}
++
++static int pbs_open(BlockDriverState *bs, QDict *options, int flags,
++                    Error **errp)
++{
++    QemuOpts *opts;
++    BDRVPBSState *s = bs->opaque;
++    char *pbs_error = NULL;
++
++    opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
++    qemu_opts_absorb_qdict(opts, options, &error_abort);
++
++    s->repository = g_strdup(qemu_opt_get(opts, PBS_OPT_REPOSITORY));
++    s->snapshot = g_strdup(qemu_opt_get(opts, PBS_OPT_SNAPSHOT));
++    s->archive = g_strdup(qemu_opt_get(opts, PBS_OPT_ARCHIVE));
++    const char *keyfile = qemu_opt_get(opts, PBS_OPT_KEYFILE);
++    const char *password = qemu_opt_get(opts, PBS_OPT_PASSWORD);
++    const char *fingerprint = qemu_opt_get(opts, PBS_OPT_FINGERPRINT);
++    const char *key_password = qemu_opt_get(opts, PBS_OPT_ENCRYPTION_PASSWORD);
++
++    if (!password) {
++        password = getenv("PBS_PASSWORD");
++    }
++    if (!fingerprint) {
++        fingerprint = getenv("PBS_FINGERPRINT");
++    }
++    if (!key_password) {
++        key_password = getenv("PBS_ENCRYPTION_PASSWORD");
++    }
++
++    /* connect to PBS server in read mode */
++    s->conn = proxmox_restore_new(s->repository, s->snapshot, password,
++        keyfile, key_password, fingerprint, &pbs_error);
++
++    /* invalidates qemu_opt_get char pointers from above */
++    qemu_opts_del(opts);
++
++    if (!s->conn) {
++        if (pbs_error && errp) error_setg(errp, "PBS restore_new failed: %s", pbs_error);
++        if (pbs_error) proxmox_backup_free_error(pbs_error);
++        return -ENOMEM;
++    }
++
++    int ret = proxmox_restore_connect(s->conn, &pbs_error);
++    if (ret < 0) {
++        if (pbs_error && errp) error_setg(errp, "PBS connect failed: %s", pbs_error);
++        if (pbs_error) proxmox_backup_free_error(pbs_error);
++        return -ECONNREFUSED;
++    }
++
++    /* acquire handle and length */
++    s->aid = proxmox_restore_open_image(s->conn, s->archive, &pbs_error);
++    if (s->aid < 0) {
++        if (pbs_error && errp) error_setg(errp, "PBS open_image failed: %s", pbs_error);
++        if (pbs_error) proxmox_backup_free_error(pbs_error);
++        return -ENODEV;
++    }
++    s->length = proxmox_restore_get_image_length(s->conn, s->aid, &pbs_error);
++    if (s->length < 0) {
++        if (pbs_error && errp) error_setg(errp, "PBS get_image_length failed: %s", pbs_error);
++        if (pbs_error) proxmox_backup_free_error(pbs_error);
++        return -EINVAL;
++    }
++
++    return 0;
++}
++
++static int pbs_file_open(BlockDriverState *bs, QDict *options, int flags,
++                         Error **errp)
++{
++    return pbs_open(bs, options, flags, errp);
++}
++
++static void pbs_close(BlockDriverState *bs) {
++    BDRVPBSState *s = bs->opaque;
++    g_free(s->repository);
++    g_free(s->snapshot);
++    g_free(s->archive);
++    proxmox_restore_disconnect(s->conn);
++}
++
++static int64_t pbs_getlength(BlockDriverState *bs)
++{
++    BDRVPBSState *s = bs->opaque;
++    return s->length;
++}
++
++typedef struct ReadCallbackData {
++    Coroutine *co;
++    AioContext *ctx;
++} ReadCallbackData;
++
++static void read_callback(void *callback_data)
++{
++    ReadCallbackData *rcb = callback_data;
++    aio_co_schedule(rcb->ctx, rcb->co);
++}
++
++static coroutine_fn int pbs_co_preadv(BlockDriverState *bs,
++                                      uint64_t offset, uint64_t bytes,
++                                      QEMUIOVector *qiov, int flags)
++{
++    BDRVPBSState *s = bs->opaque;
++    int ret;
++    char *pbs_error = NULL;
++    uint8_t *buf = malloc(bytes);
++
++    ReadCallbackData rcb = {
++        .co = qemu_coroutine_self(),
++        .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);
++
++    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);
++        return -EIO;
++    }
++
++    qemu_iovec_from_buf(qiov, 0, buf, bytes);
++    free(buf);
++
++    return ret;
++}
++
++static coroutine_fn int pbs_co_pwritev(BlockDriverState *bs,
++                                       uint64_t offset, uint64_t bytes,
++                                       QEMUIOVector *qiov, int flags)
++{
++    fprintf(stderr, "pbs-bdrv: cannot write to backup file, make sure "
++           "any attached disk devices are set to read-only!\n");
++    return -EPERM;
++}
++
++static void pbs_refresh_filename(BlockDriverState *bs)
++{
++    BDRVPBSState *s = bs->opaque;
++    snprintf(bs->exact_filename, sizeof(bs->exact_filename), "%s/%s(%s)",
++             s->repository, s->snapshot, s->archive);
++}
++
++static const char *const pbs_strong_runtime_opts[] = {
++    NULL
++};
++
++static BlockDriver bdrv_pbs_co = {
++    .format_name            = "pbs",
++    .protocol_name          = "pbs",
++    .instance_size          = sizeof(BDRVPBSState),
++
++    .bdrv_parse_filename    = pbs_parse_filename,
++
++    .bdrv_file_open         = pbs_file_open,
++    .bdrv_open              = pbs_open,
++    .bdrv_close             = pbs_close,
++    .bdrv_getlength         = pbs_getlength,
++
++    .bdrv_co_preadv         = pbs_co_preadv,
++    .bdrv_co_pwritev        = pbs_co_pwritev,
++
++    .bdrv_refresh_filename  = pbs_refresh_filename,
++    .strong_runtime_opts    = pbs_strong_runtime_opts,
++};
++
++static void bdrv_pbs_init(void)
++{
++    bdrv_register(&bdrv_pbs_co);
++}
++
++block_init(bdrv_pbs_init);
+diff --git a/configure b/configure
+index 18c26e0389..33d9933871 100755
+--- a/configure
++++ b/configure
+@@ -436,6 +436,7 @@ vvfat="yes"
+ qed="yes"
+ parallels="yes"
+ sheepdog="no"
++pbs_bdrv="yes"
+ libxml2=""
+ debug_mutex="no"
+ libpmem=""
+@@ -1461,6 +1462,10 @@ for opt do
+   ;;
+   --enable-sheepdog) sheepdog="yes"
+   ;;
++  --disable-pbs-bdrv) pbs_bdrv="no"
++  ;;
++  --enable-pbs-bdrv) pbs_bdrv="yes"
++  ;;
+   --disable-vhost-user) vhost_user="no"
+   ;;
+   --enable-vhost-user) vhost_user="yes"
+@@ -1843,6 +1848,7 @@ disabled with --disable-FEATURE, default is enabled if available:
+   qed             qed image format support
+   parallels       parallels image format support
+   sheepdog        sheepdog block driver support (deprecated)
++  pbs-bdrv        Proxmox backup server read-only block driver support
+   crypto-afalg    Linux AF_ALG crypto backend driver
+   capstone        capstone disassembler support
+   debug-mutex     mutex debugging support
+@@ -6682,6 +6688,9 @@ if test "$sheepdog" = "yes" ; then
+   add_to deprecated_features "sheepdog"
+   echo "CONFIG_SHEEPDOG=y" >> $config_host_mak
+ fi
++if test "$pbs_bdrv" = "yes" ; then
++  echo "CONFIG_PBS_BDRV=y" >> $config_host_mak
++fi
+ if test "$pty_h" = "yes" ; then
+   echo "HAVE_PTY_H=y" >> $config_host_mak
+ fi
+diff --git a/meson.build b/meson.build
+index 6f1fafee14..4d156d35ce 100644
+--- a/meson.build
++++ b/meson.build
+@@ -2199,6 +2199,7 @@ summary_info += {'vvfat support':     config_host.has_key('CONFIG_VVFAT')}
+ summary_info += {'qed support':       config_host.has_key('CONFIG_QED')}
+ summary_info += {'parallels support': config_host.has_key('CONFIG_PARALLELS')}
+ summary_info += {'sheepdog support':  config_host.has_key('CONFIG_SHEEPDOG')}
++summary_info += {'PBS bdrv support':  config_host.has_key('CONFIG_PBS_BDRV')}
+ summary_info += {'capstone':          capstone_opt == 'disabled' ? false : capstone_opt}
+ summary_info += {'libpmem support':   config_host.has_key('CONFIG_LIBPMEM')}
+ summary_info += {'libdaxctl support': config_host.has_key('CONFIG_LIBDAXCTL')}
+diff --git a/qapi/block-core.json b/qapi/block-core.json
+index 0fda1e3fd3..553112d998 100644
+--- a/qapi/block-core.json
++++ b/qapi/block-core.json
+@@ -2975,7 +2975,7 @@
+             'luks', 'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallels',
+             'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'rbd',
+             { 'name': 'replication', 'if': 'defined(CONFIG_REPLICATION)' },
+-            'sheepdog',
++            'sheepdog', 'pbs',
+             'ssh', 'throttle', 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat' ] }
+ ##
+@@ -3039,6 +3039,17 @@
+ { 'struct': 'BlockdevOptionsNull',
+   'data': { '*size': 'int', '*latency-ns': 'uint64', '*read-zeroes': 'bool' } }
++##
++# @BlockdevOptionsPbs:
++#
++# Driver specific block device options for the PBS backend.
++#
++##
++{ 'struct': 'BlockdevOptionsPbs',
++  'data': { 'repository': 'str', 'snapshot': 'str', 'archive': 'str',
++            '*keyfile': 'str', '*password': 'str', '*fingerprint': 'str',
++            '*key_password': 'str' } }
++
+ ##
+ # @BlockdevOptionsNVMe:
+ #
+@@ -4148,6 +4159,7 @@
+       'nfs':        'BlockdevOptionsNfs',
+       'null-aio':   'BlockdevOptionsNull',
+       'null-co':    'BlockdevOptionsNull',
++      'pbs':        'BlockdevOptionsPbs',
+       'nvme':       'BlockdevOptionsNVMe',
+       'parallels':  'BlockdevOptionsGenericFormat',
+       'qcow2':      'BlockdevOptionsQcow2',
diff --git a/debian/patches/pve/0038-PVE-backup-rename-incremental-to-use-dirty-bitmap.patch b/debian/patches/pve/0038-PVE-backup-rename-incremental-to-use-dirty-bitmap.patch
deleted file mode 100644 (file)
index 56b9c32..0000000
+++ /dev/null
@@ -1,126 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: Thomas Lamprecht <t.lamprecht@proxmox.com>
-Date: Mon, 6 Jul 2020 20:05:16 +0200
-Subject: [PATCH] PVE backup: rename incremental to use-dirty-bitmap
-
-Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
-Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
----
- pve-backup.c         | 22 +++++++++++-----------
- qapi/block-core.json |  6 +++---
- 2 files changed, 14 insertions(+), 14 deletions(-)
-
-diff --git a/pve-backup.c b/pve-backup.c
-index d50f03a050..7bf54b4c5d 100644
---- a/pve-backup.c
-+++ b/pve-backup.c
-@@ -557,8 +557,8 @@ typedef struct QmpBackupTask {
-     const char *fingerprint;
-     bool has_fingerprint;
-     int64_t backup_time;
--    bool has_incremental;
--    bool incremental;
-+    bool has_use_dirty_bitmap;
-+    bool use_dirty_bitmap;
-     bool has_format;
-     BackupFormat format;
-     bool has_config_file;
-@@ -688,7 +688,7 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-         int dump_cb_block_size = PROXMOX_BACKUP_DEFAULT_CHUNK_SIZE; // Hardcoded (4M)
-         firewall_name = "fw.conf";
--        bool incremental = task->has_incremental && task->incremental;
-+        bool use_dirty_bitmap = task->has_use_dirty_bitmap && task->use_dirty_bitmap;
-         char *pbs_err = NULL;
-         pbs = proxmox_backup_new(
-@@ -722,9 +722,9 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-             const char *devname = bdrv_get_device_name(di->bs);
-             BdrvDirtyBitmap *bitmap = bdrv_find_dirty_bitmap(di->bs, PBS_BITMAP_NAME);
-+            bool expect_only_dirty = false;
--            bool use_incremental = false;
--            if (incremental) {
-+            if (use_dirty_bitmap) {
-                 if (bitmap == NULL) {
-                     bitmap = bdrv_create_dirty_bitmap(di->bs, dump_cb_block_size, PBS_BITMAP_NAME, task->errp);
-                     if (!bitmap) {
-@@ -734,7 +734,7 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-                     bdrv_set_dirty_bitmap(bitmap, 0, di->size);
-                     dirty += di->size;
-                 } else {
--                    use_incremental = true;
-+                    expect_only_dirty = true;
-                     dirty += bdrv_get_dirty_count(bitmap);
-                 }
-                 di->bitmap = bitmap;
-@@ -743,7 +743,7 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-                 bdrv_release_dirty_bitmap(bitmap);
-             }
--            int dev_id = proxmox_backup_co_register_image(pbs, devname, di->size, use_incremental, task->errp);
-+            int dev_id = proxmox_backup_co_register_image(pbs, devname, di->size, expect_only_dirty, task->errp);
-             if (dev_id < 0) {
-                 goto err;
-             }
-@@ -861,7 +861,7 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-     backup_state.stat.dirty = dirty;
-     backup_state.stat.transferred = 0;
-     backup_state.stat.zero_bytes = 0;
--    backup_state.stat.reused = dirty >= total ? 0 : total - dirty;
-+    backup_state.stat.reused = format == BACKUP_FORMAT_PBS && dirty >= total ? 0 : total - dirty;
-     qemu_mutex_unlock(&backup_state.stat.lock);
-@@ -930,7 +930,7 @@ UuidInfo *qmp_backup(
-     bool has_fingerprint, const char *fingerprint,
-     bool has_backup_id, const char *backup_id,
-     bool has_backup_time, int64_t backup_time,
--    bool has_incremental, bool incremental,
-+    bool has_use_dirty_bitmap, bool use_dirty_bitmap,
-     bool has_format, BackupFormat format,
-     bool has_config_file, const char *config_file,
-     bool has_firewall_file, const char *firewall_file,
-@@ -949,8 +949,8 @@ UuidInfo *qmp_backup(
-         .backup_id = backup_id,
-         .has_backup_time = has_backup_time,
-         .backup_time = backup_time,
--        .has_incremental = has_incremental,
--        .incremental = incremental,
-+        .has_use_dirty_bitmap = has_use_dirty_bitmap,
-+        .use_dirty_bitmap = use_dirty_bitmap,
-         .has_format = has_format,
-         .format = format,
-         .has_config_file = has_config_file,
-diff --git a/qapi/block-core.json b/qapi/block-core.json
-index aadd5329b3..d4e1c98c50 100644
---- a/qapi/block-core.json
-+++ b/qapi/block-core.json
-@@ -758,7 +758,7 @@
- #
- # @total: total amount of bytes involved in the backup process
- #
--# @dirty: with incremental mode, this is the amount of bytes involved
-+# @dirty: with incremental mode (PBS) this is the amount of bytes involved
- #         in the backup process which are marked dirty.
- #
- # @transferred: amount of bytes already backed up.
-@@ -821,7 +821,7 @@
- #
- # @backup-time: backup timestamp (Unix epoch, required for format 'pbs')
- #
--# @incremental: sync incremental changes since last job (optional for format 'pbs')
-+# @use-dirty-bitmap: use dirty bitmap to detect incremental changes since last job (optional for format 'pbs')
- #
- # Returns: the uuid of the backup job
- #
-@@ -833,7 +833,7 @@
-                                     '*fingerprint': 'str',
-                                     '*backup-id': 'str',
-                                     '*backup-time': 'int',
--                                    '*incremental': 'bool',
-+                                    '*use-dirty-bitmap': 'bool',
-                                     '*format': 'BackupFormat',
-                                     '*config-file': 'str',
-                                     '*firewall-file': 'str',
diff --git a/debian/patches/pve/0039-PVE-add-query_proxmox_support-QMP-command.patch b/debian/patches/pve/0039-PVE-add-query_proxmox_support-QMP-command.patch
new file mode 100644 (file)
index 0000000..5697adf
--- /dev/null
@@ -0,0 +1,69 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Stefan Reiter <s.reiter@proxmox.com>
+Date: Wed, 8 Jul 2020 11:57:53 +0200
+Subject: [PATCH] PVE: add query_proxmox_support QMP command
+
+Generic interface for future use, currently used for PBS dirty-bitmap
+backup support.
+
+Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
+Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
+[PVE: query-proxmox-support: include library version]
+Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
+---
+ pve-backup.c         |  8 ++++++++
+ qapi/block-core.json | 25 +++++++++++++++++++++++++
+ 2 files changed, 33 insertions(+)
+
+diff --git a/pve-backup.c b/pve-backup.c
+index b8182aaf89..40c2697b37 100644
+--- a/pve-backup.c
++++ b/pve-backup.c
+@@ -1073,3 +1073,11 @@ BackupStatus *qmp_query_backup(Error **errp)
+     return info;
+ }
++
++ProxmoxSupportStatus *qmp_query_proxmox_support(Error **errp)
++{
++    ProxmoxSupportStatus *ret = g_malloc0(sizeof(*ret));
++    ret->pbs_library_version = g_strdup(proxmox_backup_qemu_version());
++    ret->pbs_dirty_bitmap = true;
++    return ret;
++}
+diff --git a/qapi/block-core.json b/qapi/block-core.json
+index 553112d998..e0a0a60354 100644
+--- a/qapi/block-core.json
++++ b/qapi/block-core.json
+@@ -868,6 +868,31 @@
+ ##
+ { 'command': 'backup-cancel' }
++##
++# @ProxmoxSupportStatus:
++#
++# Contains info about supported features added by Proxmox.
++#
++# @pbs-dirty-bitmap: True if dirty-bitmap-incremental backups to PBS are
++#                    supported.
++#
++# @pbs-library-version: Running version of libproxmox-backup-qemu0 library.
++#
++##
++{ 'struct': 'ProxmoxSupportStatus',
++  'data': { 'pbs-dirty-bitmap': 'bool',
++            'pbs-library-version': 'str' } }
++
++##
++# @query-proxmox-support:
++#
++# Returns information about supported features added by Proxmox.
++#
++# Returns: @ProxmoxSupportStatus
++#
++##
++{ 'command': 'query-proxmox-support', 'returns': 'ProxmoxSupportStatus' }
++
+ ##
+ # @BlockDeviceTimedStats:
+ #
diff --git a/debian/patches/pve/0039-PVE-fixup-pbs-restore-API.patch b/debian/patches/pve/0039-PVE-fixup-pbs-restore-API.patch
deleted file mode 100644 (file)
index cc8f30a..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: Stefan Reiter <s.reiter@proxmox.com>
-Date: Mon, 6 Jul 2020 14:40:12 +0200
-Subject: [PATCH] PVE: fixup pbs-restore API
-
-Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
----
- pbs-restore.c | 10 ++++++++--
- 1 file changed, 8 insertions(+), 2 deletions(-)
-
-diff --git a/pbs-restore.c b/pbs-restore.c
-index d4daee7e91..4d3f925a1b 100644
---- a/pbs-restore.c
-+++ b/pbs-restore.c
-@@ -161,13 +161,19 @@ int main(int argc, char **argv)
-         fprintf(stderr, "connecting to repository '%s'\n", repository);
-     }
-     char *pbs_error = NULL;
--    ProxmoxRestoreHandle *conn = proxmox_restore_connect(
-+    ProxmoxRestoreHandle *conn = proxmox_restore_new(
-         repository, snapshot, password, keyfile, key_password, fingerprint, &pbs_error);
-     if (conn == NULL) {
-         fprintf(stderr, "restore failed: %s\n", pbs_error);
-         return -1;
-     }
-+    int res = proxmox_restore_connect(conn, &pbs_error);
-+    if (res < 0 || pbs_error) {
-+        fprintf(stderr, "restore failed (connection error): %s\n", pbs_error);
-+        return -1;
-+    }
-+
-     QDict *options = qdict_new();
-     if (format) {
-@@ -198,7 +204,7 @@ int main(int argc, char **argv)
-         fprintf(stderr, "starting to restore snapshot '%s'\n", snapshot);
-         fflush(stderr); // ensure we do not get printed after the progress log
-     }
--    int res = proxmox_restore_image(
-+    res = proxmox_restore_image(
-         conn,
-         archive_name,
-         write_callback,
diff --git a/debian/patches/pve/0040-PVE-add-query-pbs-bitmap-info-QMP-call.patch b/debian/patches/pve/0040-PVE-add-query-pbs-bitmap-info-QMP-call.patch
new file mode 100644 (file)
index 0000000..828bf4e
--- /dev/null
@@ -0,0 +1,437 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Stefan Reiter <s.reiter@proxmox.com>
+Date: Wed, 19 Aug 2020 17:02:00 +0200
+Subject: [PATCH] PVE: add query-pbs-bitmap-info QMP call
+
+Returns advanced information about dirty bitmaps used (or not used) for
+the latest PBS backup.
+
+Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
+---
+ monitor/hmp-cmds.c   |  28 ++++++-----
+ pve-backup.c         | 117 ++++++++++++++++++++++++++++++++-----------
+ qapi/block-core.json |  56 +++++++++++++++++++++
+ 3 files changed, 159 insertions(+), 42 deletions(-)
+
+diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
+index 604026bb37..95f4e7f5c1 100644
+--- a/monitor/hmp-cmds.c
++++ b/monitor/hmp-cmds.c
+@@ -198,6 +198,7 @@ void hmp_info_mice(Monitor *mon, const QDict *qdict)
+ void hmp_info_backup(Monitor *mon, const QDict *qdict)
+ {
+     BackupStatus *info;
++    PBSBitmapInfoList *bitmap_info;
+     info = qmp_query_backup(NULL);
+@@ -228,26 +229,29 @@ void hmp_info_backup(Monitor *mon, const QDict *qdict)
+             // this should not happen normally
+             monitor_printf(mon, "Total size: %d\n", 0);
+         } else {
+-            bool incremental = false;
+             size_t total_or_dirty = info->total;
+-            if (info->has_transferred) {
+-                if (info->has_dirty && info->dirty) {
+-                     if (info->dirty < info->total) {
+-                        total_or_dirty = info->dirty;
+-                        incremental = true;
+-                    }
+-                }
++            bitmap_info = qmp_query_pbs_bitmap_info(NULL);
++
++            while (bitmap_info) {
++                monitor_printf(mon, "Drive %s:\n",
++                        bitmap_info->value->drive);
++                monitor_printf(mon, "  bitmap action: %s\n",
++                        PBSBitmapAction_str(bitmap_info->value->action));
++                monitor_printf(mon, "  size: %zd\n",
++                        bitmap_info->value->size);
++                monitor_printf(mon, "  dirty: %zd\n",
++                        bitmap_info->value->dirty);
++                bitmap_info = bitmap_info->next;
+             }
+-            int per = (info->transferred * 100)/total_or_dirty;
+-
+-            monitor_printf(mon, "Backup mode: %s\n", incremental ? "incremental" : "full");
++            qapi_free_PBSBitmapInfoList(bitmap_info);
+             int zero_per = (info->has_zero_bytes && info->zero_bytes) ?
+                 (info->zero_bytes * 100)/info->total : 0;
+             monitor_printf(mon, "Total size: %zd\n", info->total);
++            int trans_per = (info->transferred * 100)/total_or_dirty;
+             monitor_printf(mon, "Transferred bytes: %zd (%d%%)\n",
+-                           info->transferred, per);
++                           info->transferred, trans_per);
+             monitor_printf(mon, "Zero bytes: %zd (%d%%)\n",
+                            info->zero_bytes, zero_per);
+diff --git a/pve-backup.c b/pve-backup.c
+index 40c2697b37..1e7b92a950 100644
+--- a/pve-backup.c
++++ b/pve-backup.c
+@@ -46,6 +46,7 @@ static struct PVEBackupState {
+         size_t transferred;
+         size_t reused;
+         size_t zero_bytes;
++        GList *bitmap_list;
+     } stat;
+     int64_t speed;
+     VmaWriter *vmaw;
+@@ -670,7 +671,6 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+     }
+     size_t total = 0;
+-    size_t dirty = 0;
+     l = di_list;
+     while (l) {
+@@ -691,18 +691,33 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+     uuid_generate(uuid);
++    qemu_mutex_lock(&backup_state.stat.lock);
++    backup_state.stat.reused = 0;
++
++    /* clear previous backup's bitmap_list */
++    if (backup_state.stat.bitmap_list) {
++        GList *bl = backup_state.stat.bitmap_list;
++        while (bl) {
++            g_free(((PBSBitmapInfo *)bl->data)->drive);
++            g_free(bl->data);
++            bl = g_list_next(bl);
++        }
++        g_list_free(backup_state.stat.bitmap_list);
++        backup_state.stat.bitmap_list = NULL;
++    }
++
+     if (format == BACKUP_FORMAT_PBS) {
+         if (!task->has_password) {
+             error_set(task->errp, ERROR_CLASS_GENERIC_ERROR, "missing parameter 'password'");
+-            goto err;
++            goto err_mutex;
+         }
+         if (!task->has_backup_id) {
+             error_set(task->errp, ERROR_CLASS_GENERIC_ERROR, "missing parameter 'backup-id'");
+-            goto err;
++            goto err_mutex;
+         }
+         if (!task->has_backup_time) {
+             error_set(task->errp, ERROR_CLASS_GENERIC_ERROR, "missing parameter 'backup-time'");
+-            goto err;
++            goto err_mutex;
+         }
+         int dump_cb_block_size = PROXMOX_BACKUP_DEFAULT_CHUNK_SIZE; // Hardcoded (4M)
+@@ -729,12 +744,12 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+             error_set(task->errp, ERROR_CLASS_GENERIC_ERROR,
+                       "proxmox_backup_new failed: %s", pbs_err);
+             proxmox_backup_free_error(pbs_err);
+-            goto err;
++            goto err_mutex;
+         }
+         int connect_result = proxmox_backup_co_connect(pbs, task->errp);
+         if (connect_result < 0)
+-            goto err;
++            goto err_mutex;
+         /* register all devices */
+         l = di_list;
+@@ -745,6 +760,8 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+             di->block_size = dump_cb_block_size;
+             const char *devname = bdrv_get_device_name(di->bs);
++            PBSBitmapAction action = PBS_BITMAP_ACTION_NOT_USED;
++            size_t dirty = di->size;
+             BdrvDirtyBitmap *bitmap = bdrv_find_dirty_bitmap(di->bs, PBS_BITMAP_NAME);
+             bool expect_only_dirty = false;
+@@ -753,49 +770,59 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+                 if (bitmap == NULL) {
+                     bitmap = bdrv_create_dirty_bitmap(di->bs, dump_cb_block_size, PBS_BITMAP_NAME, task->errp);
+                     if (!bitmap) {
+-                        goto err;
++                        goto err_mutex;
+                     }
++                    action = PBS_BITMAP_ACTION_NEW;
+                 } else {
+                     expect_only_dirty = proxmox_backup_check_incremental(pbs, devname, di->size) != 0;
+                 }
+                 if (expect_only_dirty) {
+-                    dirty += bdrv_get_dirty_count(bitmap);
++                    /* track clean chunks as reused */
++                    dirty = MIN(bdrv_get_dirty_count(bitmap), di->size);
++                    backup_state.stat.reused += di->size - dirty;
++                    action = PBS_BITMAP_ACTION_USED;
+                 } else {
+                     /* mark entire bitmap as dirty to make full backup */
+                     bdrv_set_dirty_bitmap(bitmap, 0, di->size);
+-                    dirty += di->size;
++                    if (action != PBS_BITMAP_ACTION_NEW) {
++                        action = PBS_BITMAP_ACTION_INVALID;
++                    }
+                 }
+                 di->bitmap = bitmap;
+             } else {
+-                dirty += di->size;
+-
+                 /* after a full backup the old dirty bitmap is invalid anyway */
+                 if (bitmap != NULL) {
+                     bdrv_release_dirty_bitmap(bitmap);
++                    action = PBS_BITMAP_ACTION_NOT_USED_REMOVED;
+                 }
+             }
+             int dev_id = proxmox_backup_co_register_image(pbs, devname, di->size, expect_only_dirty, task->errp);
+             if (dev_id < 0) {
+-                goto err;
++                goto err_mutex;
+             }
+             if (!(di->target = bdrv_backup_dump_create(dump_cb_block_size, di->size, pvebackup_co_dump_pbs_cb, di, task->errp))) {
+-                goto err;
++                goto err_mutex;
+             }
+             di->dev_id = dev_id;
++
++            PBSBitmapInfo *info = g_malloc(sizeof(*info));
++            info->drive = g_strdup(devname);
++            info->action = action;
++            info->size = di->size;
++            info->dirty = dirty;
++            backup_state.stat.bitmap_list = g_list_append(backup_state.stat.bitmap_list, info);
+         }
+     } else if (format == BACKUP_FORMAT_VMA) {
+-        dirty = total;
+-
+         vmaw = vma_writer_create(task->backup_file, uuid, &local_err);
+         if (!vmaw) {
+             if (local_err) {
+                 error_propagate(task->errp, local_err);
+             }
+-            goto err;
++            goto err_mutex;
+         }
+         /* register all devices for vma writer */
+@@ -805,7 +832,7 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+             l = g_list_next(l);
+             if (!(di->target = bdrv_backup_dump_create(VMA_CLUSTER_SIZE, di->size, pvebackup_co_dump_vma_cb, di, task->errp))) {
+-                goto err;
++                goto err_mutex;
+             }
+             const char *devname = bdrv_get_device_name(di->bs);
+@@ -813,16 +840,14 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+             if (di->dev_id <= 0) {
+                 error_set(task->errp, ERROR_CLASS_GENERIC_ERROR,
+                           "register_stream failed");
+-                goto err;
++                goto err_mutex;
+             }
+         }
+     } else if (format == BACKUP_FORMAT_DIR) {
+-        dirty = total;
+-
+         if (mkdir(task->backup_file, 0640) != 0) {
+             error_setg_errno(task->errp, errno, "can't create directory '%s'\n",
+                              task->backup_file);
+-            goto err;
++            goto err_mutex;
+         }
+         backup_dir = task->backup_file;
+@@ -839,18 +864,18 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+                             di->size, flags, false, &local_err);
+             if (local_err) {
+                 error_propagate(task->errp, local_err);
+-                goto err;
++                goto err_mutex;
+             }
+             di->target = bdrv_open(di->targetfile, NULL, NULL, flags, &local_err);
+             if (!di->target) {
+                 error_propagate(task->errp, local_err);
+-                goto err;
++                goto err_mutex;
+             }
+         }
+     } else {
+         error_set(task->errp, ERROR_CLASS_GENERIC_ERROR, "unknown backup format");
+-        goto err;
++        goto err_mutex;
+     }
+@@ -858,7 +883,7 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+     if (task->has_config_file) {
+         if (pvebackup_co_add_config(task->config_file, config_name, format, backup_dir,
+                                     vmaw, pbs, task->errp) != 0) {
+-            goto err;
++            goto err_mutex;
+         }
+     }
+@@ -866,12 +891,11 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+     if (task->has_firewall_file) {
+         if (pvebackup_co_add_config(task->firewall_file, firewall_name, format, backup_dir,
+                                     vmaw, pbs, task->errp) != 0) {
+-            goto err;
++            goto err_mutex;
+         }
+     }
+     /* initialize global backup_state now */
+-
+-    qemu_mutex_lock(&backup_state.stat.lock);
++    /* note: 'reused' and 'bitmap_list' are initialized earlier */
+     if (backup_state.stat.error) {
+         error_free(backup_state.stat.error);
+@@ -891,10 +915,9 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+     char *uuid_str = g_strdup(backup_state.stat.uuid_str);
+     backup_state.stat.total = total;
+-    backup_state.stat.dirty = dirty;
++    backup_state.stat.dirty = total - backup_state.stat.reused;
+     backup_state.stat.transferred = 0;
+     backup_state.stat.zero_bytes = 0;
+-    backup_state.stat.reused = format == BACKUP_FORMAT_PBS && dirty >= total ? 0 : total - dirty;
+     qemu_mutex_unlock(&backup_state.stat.lock);
+@@ -911,6 +934,9 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+     task->result = uuid_info;
+     return;
++err_mutex:
++    qemu_mutex_unlock(&backup_state.stat.lock);
++
+ err:
+     l = di_list;
+@@ -1074,10 +1100,41 @@ BackupStatus *qmp_query_backup(Error **errp)
+     return info;
+ }
++PBSBitmapInfoList *qmp_query_pbs_bitmap_info(Error **errp)
++{
++    PBSBitmapInfoList *head = NULL, **p_next = &head;
++
++    qemu_mutex_lock(&backup_state.stat.lock);
++
++    GList *l = backup_state.stat.bitmap_list;
++    while (l) {
++        PBSBitmapInfo *info = (PBSBitmapInfo *)l->data;
++        l = g_list_next(l);
++
++        /* clone bitmap info to avoid auto free after QMP marshalling */
++        PBSBitmapInfo *info_ret = g_malloc0(sizeof(*info_ret));
++        info_ret->drive = g_strdup(info->drive);
++        info_ret->action = info->action;
++        info_ret->size = info->size;
++        info_ret->dirty = info->dirty;
++
++        PBSBitmapInfoList *info_list = g_malloc0(sizeof(*info_list));
++        info_list->value = info_ret;
++
++        *p_next = info_list;
++        p_next = &info_list->next;
++    }
++
++    qemu_mutex_unlock(&backup_state.stat.lock);
++
++    return head;
++}
++
+ ProxmoxSupportStatus *qmp_query_proxmox_support(Error **errp)
+ {
+     ProxmoxSupportStatus *ret = g_malloc0(sizeof(*ret));
+     ret->pbs_library_version = g_strdup(proxmox_backup_qemu_version());
+     ret->pbs_dirty_bitmap = true;
++    ret->query_bitmap_info = true;
+     return ret;
+ }
+diff --git a/qapi/block-core.json b/qapi/block-core.json
+index e0a0a60354..b368371e8e 100644
+--- a/qapi/block-core.json
++++ b/qapi/block-core.json
+@@ -876,11 +876,14 @@
+ # @pbs-dirty-bitmap: True if dirty-bitmap-incremental backups to PBS are
+ #                    supported.
+ #
++# @query-bitmap-info: True if the 'query-pbs-bitmap-info' QMP call is supported.
++#
+ # @pbs-library-version: Running version of libproxmox-backup-qemu0 library.
+ #
+ ##
+ { 'struct': 'ProxmoxSupportStatus',
+   'data': { 'pbs-dirty-bitmap': 'bool',
++            'query-bitmap-info': 'bool',
+             'pbs-library-version': 'str' } }
+ ##
+@@ -893,6 +896,59 @@
+ ##
+ { 'command': 'query-proxmox-support', 'returns': 'ProxmoxSupportStatus' }
++##
++# @PBSBitmapAction:
++#
++# An action taken on a dirty-bitmap when a backup job was started.
++#
++# @not-used: Bitmap mode was not enabled.
++#
++# @not-used-removed: Bitmap mode was not enabled, but a bitmap from a
++#                    previous backup still existed and was removed.
++#
++# @new: A new bitmap was attached to the drive for this backup.
++#
++# @used: An existing bitmap will be used to only backup changed data.
++#
++# @invalid: A bitmap existed, but had to be cleared since it's associated
++#           base snapshot did not match the base given for the current job or
++#           the crypt mode has changed.
++#
++##
++{ 'enum': 'PBSBitmapAction',
++  'data': ['not-used', 'not-used-removed', 'new', 'used', 'invalid'] }
++
++##
++# @PBSBitmapInfo:
++#
++# Contains information about dirty bitmaps used for each drive in a PBS backup.
++#
++# @drive: The underlying drive.
++#
++# @action: The action that was taken when the backup started.
++#
++# @size: The total size of the drive.
++#
++# @dirty: How much of the drive is considered dirty and will be backed up,
++#         or 'size' if everything will be.
++#
++##
++{ 'struct': 'PBSBitmapInfo',
++  'data': { 'drive': 'str', 'action': 'PBSBitmapAction', 'size': 'int',
++            'dirty': 'int' } }
++
++##
++# @query-pbs-bitmap-info:
++#
++# Returns information about dirty bitmaps used on the most recently started
++# backup. Returns nothing when the last backup was not using PBS or if no
++# backup occured in this session.
++#
++# Returns: @PBSBitmapInfo
++#
++##
++{ 'command': 'query-pbs-bitmap-info', 'returns': ['PBSBitmapInfo'] }
++
+ ##
+ # @BlockDeviceTimedStats:
+ #
diff --git a/debian/patches/pve/0040-PVE-always-set-dirty-counter-for-non-incremental-bac.patch b/debian/patches/pve/0040-PVE-always-set-dirty-counter-for-non-incremental-bac.patch
deleted file mode 100644 (file)
index c7b267e..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: Stefan Reiter <s.reiter@proxmox.com>
-Date: Mon, 6 Jul 2020 14:40:13 +0200
-Subject: [PATCH] PVE: always set dirty counter for non-incremental backups
-
-Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
----
- pve-backup.c | 8 ++++++--
- 1 file changed, 6 insertions(+), 2 deletions(-)
-
-diff --git a/pve-backup.c b/pve-backup.c
-index 7bf54b4c5d..1f2a0bbe8c 100644
---- a/pve-backup.c
-+++ b/pve-backup.c
-@@ -738,9 +738,13 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-                     dirty += bdrv_get_dirty_count(bitmap);
-                 }
-                 di->bitmap = bitmap;
--            } else if (bitmap != NULL) {
-+            } else {
-                 dirty += di->size;
--                bdrv_release_dirty_bitmap(bitmap);
-+
-+                /* after a full backup the old dirty bitmap is invalid anyway */
-+                if (bitmap != NULL) {
-+                    bdrv_release_dirty_bitmap(bitmap);
-+                }
-             }
-             int dev_id = proxmox_backup_co_register_image(pbs, devname, di->size, expect_only_dirty, task->errp);
diff --git a/debian/patches/pve/0041-PVE-redirect-stderr-to-journal-when-daemonized.patch b/debian/patches/pve/0041-PVE-redirect-stderr-to-journal-when-daemonized.patch
new file mode 100644 (file)
index 0000000..7fb3c4f
--- /dev/null
@@ -0,0 +1,60 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Stefan Reiter <s.reiter@proxmox.com>
+Date: Tue, 12 Jan 2021 14:12:20 +0100
+Subject: [PATCH] PVE: redirect stderr to journal when daemonized
+
+QEMU uses the logging for error messages usually, so LOG_ERR is most
+fitting.
+
+Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
+---
+ meson.build | 2 ++
+ os-posix.c  | 7 +++++--
+ 2 files changed, 7 insertions(+), 2 deletions(-)
+
+diff --git a/meson.build b/meson.build
+index 4d156d35ce..737ea9e5d7 100644
+--- a/meson.build
++++ b/meson.build
+@@ -726,6 +726,7 @@ keyutils = dependency('libkeyutils', required: false,
+ has_gettid = cc.has_function('gettid')
+ libuuid = cc.find_library('uuid', required: true)
++libsystemd = cc.find_library('systemd', required: true)
+ libproxmox_backup_qemu = cc.find_library('proxmox_backup_qemu', required: true)
+ # Malloc tests
+@@ -1539,6 +1540,7 @@ blockdev_ss.add(files(
+ # os-posix.c contains POSIX-specific functions used by qemu-storage-daemon,
+ # os-win32.c does not
+ blockdev_ss.add(when: 'CONFIG_POSIX', if_true: files('os-posix.c'))
++blockdev_ss.add(when: 'CONFIG_POSIX', if_true: libsystemd)
+ softmmu_ss.add(when: 'CONFIG_WIN32', if_true: [files('os-win32.c')])
+ common_ss.add(files('cpus-common.c'))
+diff --git a/os-posix.c b/os-posix.c
+index 1de2839554..ac4f652923 100644
+--- a/os-posix.c
++++ b/os-posix.c
+@@ -28,6 +28,8 @@
+ #include <pwd.h>
+ #include <grp.h>
+ #include <libgen.h>
++#include <systemd/sd-journal.h>
++#include <syslog.h>
+ #include "qemu-common.h"
+ /* Needed early for CONFIG_BSD etc. */
+@@ -288,9 +290,10 @@ void os_setup_post(void)
+         dup2(fd, 0);
+         dup2(fd, 1);
+-        /* In case -D is given do not redirect stderr to /dev/null */
++        /* In case -D is given do not redirect stderr to journal */
+         if (!qemu_logfile) {
+-            dup2(fd, 2);
++            int journal_fd = sd_journal_stream_fd("QEMU", LOG_ERR, 0);
++            dup2(journal_fd, 2);
+         }
+         close(fd);
diff --git a/debian/patches/pve/0041-PVE-use-proxmox_backup_check_incremental.patch b/debian/patches/pve/0041-PVE-use-proxmox_backup_check_incremental.patch
deleted file mode 100644 (file)
index c55357f..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: Stefan Reiter <s.reiter@proxmox.com>
-Date: Mon, 6 Jul 2020 14:40:14 +0200
-Subject: [PATCH] PVE: use proxmox_backup_check_incremental
-
-Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
-Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
----
- pve-backup.c | 12 ++++++++----
- 1 file changed, 8 insertions(+), 4 deletions(-)
-
-diff --git a/pve-backup.c b/pve-backup.c
-index 1f2a0bbe8c..1cd9d31d7c 100644
---- a/pve-backup.c
-+++ b/pve-backup.c
-@@ -730,12 +730,16 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-                     if (!bitmap) {
-                         goto err;
-                     }
--                    /* mark entire bitmap as dirty to make full backup first */
--                    bdrv_set_dirty_bitmap(bitmap, 0, di->size);
--                    dirty += di->size;
-                 } else {
--                    expect_only_dirty = true;
-+                    expect_only_dirty = proxmox_backup_check_incremental(pbs, devname, di->size) != 0;
-+                }
-+
-+                if (expect_only_dirty) {
-                     dirty += bdrv_get_dirty_count(bitmap);
-+                } else {
-+                    /* mark entire bitmap as dirty to make full backup */
-+                    bdrv_set_dirty_bitmap(bitmap, 0, di->size);
-+                    dirty += di->size;
-                 }
-                 di->bitmap = bitmap;
-             } else {
diff --git a/debian/patches/pve/0042-PVE-Add-sequential-job-transaction-support.patch b/debian/patches/pve/0042-PVE-Add-sequential-job-transaction-support.patch
new file mode 100644 (file)
index 0000000..6be76d8
--- /dev/null
@@ -0,0 +1,97 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Stefan Reiter <s.reiter@proxmox.com>
+Date: Thu, 20 Aug 2020 14:31:59 +0200
+Subject: [PATCH] PVE: Add sequential job transaction support
+
+Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
+---
+ include/qemu/job.h | 12 ++++++++++++
+ job.c              | 31 +++++++++++++++++++++++++++++++
+ 2 files changed, 43 insertions(+)
+
+diff --git a/include/qemu/job.h b/include/qemu/job.h
+index 32aabb1c60..f7a6a0926a 100644
+--- a/include/qemu/job.h
++++ b/include/qemu/job.h
+@@ -280,6 +280,18 @@ typedef enum JobCreateFlags {
+  */
+ JobTxn *job_txn_new(void);
++/**
++ * Create a new transaction and set it to sequential mode, i.e. run all jobs
++ * one after the other instead of at the same time.
++ */
++JobTxn *job_txn_new_seq(void);
++
++/**
++ * Helper method to start the first job in a sequential transaction to kick it
++ * off. Other jobs will be run after this one completes.
++ */
++void job_txn_start_seq(JobTxn *txn);
++
+ /**
+  * Release a reference that was previously acquired with job_txn_add_job or
+  * job_txn_new. If it's the last reference to the object, it will be freed.
+diff --git a/job.c b/job.c
+index f9884e7d9d..05b7797e82 100644
+--- a/job.c
++++ b/job.c
+@@ -72,6 +72,8 @@ struct JobTxn {
+     /* Reference count */
+     int refcnt;
++
++    bool sequential;
+ };
+ /* Right now, this mutex is only needed to synchronize accesses to job->busy
+@@ -102,6 +104,25 @@ JobTxn *job_txn_new(void)
+     return txn;
+ }
++JobTxn *job_txn_new_seq(void)
++{
++    JobTxn *txn = job_txn_new();
++    txn->sequential = true;
++    return txn;
++}
++
++void job_txn_start_seq(JobTxn *txn)
++{
++    assert(txn->sequential);
++    assert(!txn->aborting);
++
++    Job *first = QLIST_FIRST(&txn->jobs);
++    assert(first);
++    assert(first->status == JOB_STATUS_CREATED);
++
++    job_start(first);
++}
++
+ static void job_txn_ref(JobTxn *txn)
+ {
+     txn->refcnt++;
+@@ -841,6 +862,9 @@ static void job_completed_txn_success(Job *job)
+      */
+     QLIST_FOREACH(other_job, &txn->jobs, txn_list) {
+         if (!job_is_completed(other_job)) {
++            if (txn->sequential) {
++                job_start(other_job);
++            }
+             return;
+         }
+         assert(other_job->ret == 0);
+@@ -1011,6 +1035,13 @@ int job_finish_sync(Job *job, void (*finish)(Job *, Error **errp), Error **errp)
+         return -EBUSY;
+     }
++    /* in a sequential transaction jobs with status CREATED can appear at time
++     * of cancelling, these have not begun work so job_enter won't do anything,
++     * let's ensure they are marked as ABORTING if required */
++    if (job->status == JOB_STATUS_CREATED && job->txn->sequential) {
++        job_update_rc(job);
++    }
++
+     AIO_WAIT_WHILE(job->aio_context,
+                    (job_enter(job), !job_is_completed(job)));
diff --git a/debian/patches/pve/0042-PVE-fixup-pbs-backup-add-compress-and-encrypt-option.patch b/debian/patches/pve/0042-PVE-fixup-pbs-backup-add-compress-and-encrypt-option.patch
deleted file mode 100644 (file)
index 601df5c..0000000
+++ /dev/null
@@ -1,103 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: Dietmar Maurer <dietmar@proxmox.com>
-Date: Thu, 9 Jul 2020 12:53:08 +0200
-Subject: [PATCH] PVE: fixup pbs backup, add compress and encrypt options
-
----
- block/monitor/block-hmp-cmds.c |  4 +++-
- pve-backup.c                   | 13 ++++++++++++-
- qapi/block-core.json           |  6 ++++++
- 3 files changed, 21 insertions(+), 2 deletions(-)
-
-diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c
-index 056d14deee..46c63b1cf9 100644
---- a/block/monitor/block-hmp-cmds.c
-+++ b/block/monitor/block-hmp-cmds.c
-@@ -1039,7 +1039,9 @@ void hmp_backup(Monitor *mon, const QDict *qdict)
-         false, NULL, // PBS fingerprint
-         false, NULL, // PBS backup-id
-         false, 0, // PBS backup-time
--        false, false, // PBS incremental
-+        false, false, // PBS use-dirty-bitmap
-+        false, false, // PBS compress
-+        false, false, // PBS encrypt
-         true, dir ? BACKUP_FORMAT_DIR : BACKUP_FORMAT_VMA,
-         false, NULL, false, NULL, !!devlist,
-         devlist, qdict_haskey(qdict, "speed"), speed, &error);
-diff --git a/pve-backup.c b/pve-backup.c
-index 1cd9d31d7c..bfb648d6b5 100644
---- a/pve-backup.c
-+++ b/pve-backup.c
-@@ -567,6 +567,10 @@ typedef struct QmpBackupTask {
-     const char *firewall_file;
-     bool has_devlist;
-     const char *devlist;
-+    bool has_compress;
-+    bool compress;
-+    bool has_encrypt;
-+    bool encrypt;
-     bool has_speed;
-     int64_t speed;
-     Error **errp;
-@@ -690,6 +694,7 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-         bool use_dirty_bitmap = task->has_use_dirty_bitmap && task->use_dirty_bitmap;
-+
-         char *pbs_err = NULL;
-         pbs = proxmox_backup_new(
-             task->backup_file,
-@@ -699,8 +704,10 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-             task->has_password ? task->password : NULL,
-             task->has_keyfile ? task->keyfile : NULL,
-             task->has_key_password ? task->key_password : NULL,
-+            task->has_compress ? task->compress : true,
-+            task->has_encrypt ? task->encrypt : task->has_keyfile,
-             task->has_fingerprint ? task->fingerprint : NULL,
--            &pbs_err);
-+             &pbs_err);
-         if (!pbs) {
-             error_set(task->errp, ERROR_CLASS_GENERIC_ERROR,
-@@ -939,6 +946,8 @@ UuidInfo *qmp_backup(
-     bool has_backup_id, const char *backup_id,
-     bool has_backup_time, int64_t backup_time,
-     bool has_use_dirty_bitmap, bool use_dirty_bitmap,
-+    bool has_compress, bool compress,
-+    bool has_encrypt, bool encrypt,
-     bool has_format, BackupFormat format,
-     bool has_config_file, const char *config_file,
-     bool has_firewall_file, const char *firewall_file,
-@@ -967,6 +976,8 @@ UuidInfo *qmp_backup(
-         .firewall_file = firewall_file,
-         .has_devlist = has_devlist,
-         .devlist = devlist,
-+        .has_compress = has_compress,
-+        .has_encrypt = has_encrypt,
-         .has_speed = has_speed,
-         .speed = speed,
-         .errp = errp,
-diff --git a/qapi/block-core.json b/qapi/block-core.json
-index d4e1c98c50..0fda1e3fd3 100644
---- a/qapi/block-core.json
-+++ b/qapi/block-core.json
-@@ -823,6 +823,10 @@
- #
- # @use-dirty-bitmap: use dirty bitmap to detect incremental changes since last job (optional for format 'pbs')
- #
-+# @compress: use compression (optional for format 'pbs', defaults to true)
-+#
-+# @encrypt: use encryption ((optional for format 'pbs', defaults to true if there is a keyfile)
-+#
- # Returns: the uuid of the backup job
- #
- ##
-@@ -834,6 +838,8 @@
-                                     '*backup-id': 'str',
-                                     '*backup-time': 'int',
-                                     '*use-dirty-bitmap': 'bool',
-+                                    '*compress': 'bool',
-+                                    '*encrypt': 'bool',
-                                     '*format': 'BackupFormat',
-                                     '*config-file': 'str',
-                                     '*firewall-file': 'str',
diff --git a/debian/patches/pve/0043-PVE-Add-PBS-block-driver-to-map-backup-archives-into.patch b/debian/patches/pve/0043-PVE-Add-PBS-block-driver-to-map-backup-archives-into.patch
deleted file mode 100644 (file)
index 4c31eaa..0000000
+++ /dev/null
@@ -1,400 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: Stefan Reiter <s.reiter@proxmox.com>
-Date: Wed, 8 Jul 2020 09:50:54 +0200
-Subject: [PATCH] PVE: Add PBS block driver to map backup archives into VMs
-
-Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
-[error cleanups, file_open implementation]
-Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
----
- block/meson.build    |   3 +
- block/pbs.c          | 271 +++++++++++++++++++++++++++++++++++++++++++
- configure            |   9 ++
- meson.build          |   1 +
- qapi/block-core.json |  14 ++-
- 5 files changed, 297 insertions(+), 1 deletion(-)
- create mode 100644 block/pbs.c
-
-diff --git a/block/meson.build b/block/meson.build
-index dfae565db3..a070060e53 100644
---- a/block/meson.build
-+++ b/block/meson.build
-@@ -49,6 +49,9 @@ block_ss.add(files(
-   '../pve-backup.c',
- ), libproxmox_backup_qemu)
-+block_ss.add(when: 'CONFIG_PBS_BDRV', if_true: files('pbs.c'))
-+block_ss.add(when: 'CONFIG_PBS_BDRV', if_true: libproxmox_backup_qemu)
-+
- softmmu_ss.add(when: 'CONFIG_TCG', if_true: files('blkreplay.c'))
-diff --git a/block/pbs.c b/block/pbs.c
-new file mode 100644
-index 0000000000..1481a2bfd1
---- /dev/null
-+++ b/block/pbs.c
-@@ -0,0 +1,271 @@
-+/*
-+ * Proxmox Backup Server read-only block driver
-+ */
-+
-+#include "qemu/osdep.h"
-+#include "qapi/error.h"
-+#include "qapi/qmp/qdict.h"
-+#include "qapi/qmp/qstring.h"
-+#include "qemu/module.h"
-+#include "qemu/option.h"
-+#include "qemu/cutils.h"
-+#include "block/block_int.h"
-+
-+#include <proxmox-backup-qemu.h>
-+
-+#define PBS_OPT_REPOSITORY "repository"
-+#define PBS_OPT_SNAPSHOT "snapshot"
-+#define PBS_OPT_ARCHIVE "archive"
-+#define PBS_OPT_KEYFILE "keyfile"
-+#define PBS_OPT_PASSWORD "password"
-+#define PBS_OPT_FINGERPRINT "fingerprint"
-+#define PBS_OPT_ENCRYPTION_PASSWORD "key_password"
-+
-+typedef struct {
-+    ProxmoxRestoreHandle *conn;
-+    char aid;
-+    int64_t length;
-+
-+    char *repository;
-+    char *snapshot;
-+    char *archive;
-+} BDRVPBSState;
-+
-+static QemuOptsList runtime_opts = {
-+    .name = "pbs",
-+    .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head),
-+    .desc = {
-+        {
-+            .name = PBS_OPT_REPOSITORY,
-+            .type = QEMU_OPT_STRING,
-+            .help = "The server address and repository to connect to.",
-+        },
-+        {
-+            .name = PBS_OPT_SNAPSHOT,
-+            .type = QEMU_OPT_STRING,
-+            .help = "The snapshot to read.",
-+        },
-+        {
-+            .name = PBS_OPT_ARCHIVE,
-+            .type = QEMU_OPT_STRING,
-+            .help = "Which archive within the snapshot should be accessed.",
-+        },
-+        {
-+            .name = PBS_OPT_PASSWORD,
-+            .type = QEMU_OPT_STRING,
-+            .help = "Server password. Can be passed as env var 'PBS_PASSWORD'.",
-+        },
-+        {
-+            .name = PBS_OPT_FINGERPRINT,
-+            .type = QEMU_OPT_STRING,
-+            .help = "Server fingerprint. Can be passed as env var 'PBS_FINGERPRINT'.",
-+        },
-+        {
-+            .name = PBS_OPT_ENCRYPTION_PASSWORD,
-+            .type = QEMU_OPT_STRING,
-+            .help = "Optional: Key password. Can be passed as env var 'PBS_ENCRYPTION_PASSWORD'.",
-+        },
-+        {
-+            .name = PBS_OPT_KEYFILE,
-+            .type = QEMU_OPT_STRING,
-+            .help = "Optional: The path to the keyfile to use.",
-+        },
-+        { /* end of list */ }
-+    },
-+};
-+
-+
-+// filename format:
-+// pbs:repository=<repo>,snapshot=<snap>,password=<pw>,key_password=<kpw>,fingerprint=<fp>,archive=<archive>
-+static void pbs_parse_filename(const char *filename, QDict *options,
-+                                     Error **errp)
-+{
-+
-+    if (!strstart(filename, "pbs:", &filename)) {
-+        if (errp) error_setg(errp, "pbs_parse_filename failed - missing 'pbs:' prefix");
-+    }
-+
-+
-+    QemuOpts *opts = qemu_opts_parse_noisily(&runtime_opts, filename, false);
-+    if (!opts) {
-+        if (errp) error_setg(errp, "pbs_parse_filename failed");
-+        return;
-+    }
-+
-+    qemu_opts_to_qdict(opts, options);
-+
-+    qemu_opts_del(opts);
-+}
-+
-+static int pbs_open(BlockDriverState *bs, QDict *options, int flags,
-+                    Error **errp)
-+{
-+    QemuOpts *opts;
-+    BDRVPBSState *s = bs->opaque;
-+    char *pbs_error = NULL;
-+
-+    opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
-+    qemu_opts_absorb_qdict(opts, options, &error_abort);
-+
-+    s->repository = g_strdup(qemu_opt_get(opts, PBS_OPT_REPOSITORY));
-+    s->snapshot = g_strdup(qemu_opt_get(opts, PBS_OPT_SNAPSHOT));
-+    s->archive = g_strdup(qemu_opt_get(opts, PBS_OPT_ARCHIVE));
-+    const char *keyfile = qemu_opt_get(opts, PBS_OPT_KEYFILE);
-+    const char *password = qemu_opt_get(opts, PBS_OPT_PASSWORD);
-+    const char *fingerprint = qemu_opt_get(opts, PBS_OPT_FINGERPRINT);
-+    const char *key_password = qemu_opt_get(opts, PBS_OPT_ENCRYPTION_PASSWORD);
-+
-+    if (!password) {
-+        password = getenv("PBS_PASSWORD");
-+    }
-+    if (!fingerprint) {
-+        fingerprint = getenv("PBS_FINGERPRINT");
-+    }
-+    if (!key_password) {
-+        key_password = getenv("PBS_ENCRYPTION_PASSWORD");
-+    }
-+
-+    /* connect to PBS server in read mode */
-+    s->conn = proxmox_restore_new(s->repository, s->snapshot, password,
-+        keyfile, key_password, fingerprint, &pbs_error);
-+
-+    /* invalidates qemu_opt_get char pointers from above */
-+    qemu_opts_del(opts);
-+
-+    if (!s->conn) {
-+        if (pbs_error && errp) error_setg(errp, "PBS restore_new failed: %s", pbs_error);
-+        if (pbs_error) proxmox_backup_free_error(pbs_error);
-+        return -ENOMEM;
-+    }
-+
-+    int ret = proxmox_restore_connect(s->conn, &pbs_error);
-+    if (ret < 0) {
-+        if (pbs_error && errp) error_setg(errp, "PBS connect failed: %s", pbs_error);
-+        if (pbs_error) proxmox_backup_free_error(pbs_error);
-+        return -ECONNREFUSED;
-+    }
-+
-+    /* acquire handle and length */
-+    s->aid = proxmox_restore_open_image(s->conn, s->archive, &pbs_error);
-+    if (s->aid < 0) {
-+        if (pbs_error && errp) error_setg(errp, "PBS open_image failed: %s", pbs_error);
-+        if (pbs_error) proxmox_backup_free_error(pbs_error);
-+        return -ENODEV;
-+    }
-+    s->length = proxmox_restore_get_image_length(s->conn, s->aid, &pbs_error);
-+    if (s->length < 0) {
-+        if (pbs_error && errp) error_setg(errp, "PBS get_image_length failed: %s", pbs_error);
-+        if (pbs_error) proxmox_backup_free_error(pbs_error);
-+        return -EINVAL;
-+    }
-+
-+    return 0;
-+}
-+
-+static int pbs_file_open(BlockDriverState *bs, QDict *options, int flags,
-+                         Error **errp)
-+{
-+    return pbs_open(bs, options, flags, errp);
-+}
-+
-+static void pbs_close(BlockDriverState *bs) {
-+    BDRVPBSState *s = bs->opaque;
-+    g_free(s->repository);
-+    g_free(s->snapshot);
-+    g_free(s->archive);
-+    proxmox_restore_disconnect(s->conn);
-+}
-+
-+static int64_t pbs_getlength(BlockDriverState *bs)
-+{
-+    BDRVPBSState *s = bs->opaque;
-+    return s->length;
-+}
-+
-+typedef struct ReadCallbackData {
-+    Coroutine *co;
-+    AioContext *ctx;
-+} ReadCallbackData;
-+
-+static void read_callback(void *callback_data)
-+{
-+    ReadCallbackData *rcb = callback_data;
-+    aio_co_schedule(rcb->ctx, rcb->co);
-+}
-+
-+static coroutine_fn int pbs_co_preadv(BlockDriverState *bs,
-+                                      uint64_t offset, uint64_t bytes,
-+                                      QEMUIOVector *qiov, int flags)
-+{
-+    BDRVPBSState *s = bs->opaque;
-+    int ret;
-+    char *pbs_error = NULL;
-+    uint8_t *buf = malloc(bytes);
-+
-+    ReadCallbackData rcb = {
-+        .co = qemu_coroutine_self(),
-+        .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);
-+
-+    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);
-+        return -EIO;
-+    }
-+
-+    qemu_iovec_from_buf(qiov, 0, buf, bytes);
-+    free(buf);
-+
-+    return ret;
-+}
-+
-+static coroutine_fn int pbs_co_pwritev(BlockDriverState *bs,
-+                                       uint64_t offset, uint64_t bytes,
-+                                       QEMUIOVector *qiov, int flags)
-+{
-+    fprintf(stderr, "pbs-bdrv: cannot write to backup file, make sure "
-+           "any attached disk devices are set to read-only!\n");
-+    return -EPERM;
-+}
-+
-+static void pbs_refresh_filename(BlockDriverState *bs)
-+{
-+    BDRVPBSState *s = bs->opaque;
-+    snprintf(bs->exact_filename, sizeof(bs->exact_filename), "%s/%s(%s)",
-+             s->repository, s->snapshot, s->archive);
-+}
-+
-+static const char *const pbs_strong_runtime_opts[] = {
-+    NULL
-+};
-+
-+static BlockDriver bdrv_pbs_co = {
-+    .format_name            = "pbs",
-+    .protocol_name          = "pbs",
-+    .instance_size          = sizeof(BDRVPBSState),
-+
-+    .bdrv_parse_filename    = pbs_parse_filename,
-+
-+    .bdrv_file_open         = pbs_file_open,
-+    .bdrv_open              = pbs_open,
-+    .bdrv_close             = pbs_close,
-+    .bdrv_getlength         = pbs_getlength,
-+
-+    .bdrv_co_preadv         = pbs_co_preadv,
-+    .bdrv_co_pwritev        = pbs_co_pwritev,
-+
-+    .bdrv_refresh_filename  = pbs_refresh_filename,
-+    .strong_runtime_opts    = pbs_strong_runtime_opts,
-+};
-+
-+static void bdrv_pbs_init(void)
-+{
-+    bdrv_register(&bdrv_pbs_co);
-+}
-+
-+block_init(bdrv_pbs_init);
-diff --git a/configure b/configure
-index 18c26e0389..33d9933871 100755
---- a/configure
-+++ b/configure
-@@ -436,6 +436,7 @@ vvfat="yes"
- qed="yes"
- parallels="yes"
- sheepdog="no"
-+pbs_bdrv="yes"
- libxml2=""
- debug_mutex="no"
- libpmem=""
-@@ -1461,6 +1462,10 @@ for opt do
-   ;;
-   --enable-sheepdog) sheepdog="yes"
-   ;;
-+  --disable-pbs-bdrv) pbs_bdrv="no"
-+  ;;
-+  --enable-pbs-bdrv) pbs_bdrv="yes"
-+  ;;
-   --disable-vhost-user) vhost_user="no"
-   ;;
-   --enable-vhost-user) vhost_user="yes"
-@@ -1843,6 +1848,7 @@ disabled with --disable-FEATURE, default is enabled if available:
-   qed             qed image format support
-   parallels       parallels image format support
-   sheepdog        sheepdog block driver support (deprecated)
-+  pbs-bdrv        Proxmox backup server read-only block driver support
-   crypto-afalg    Linux AF_ALG crypto backend driver
-   capstone        capstone disassembler support
-   debug-mutex     mutex debugging support
-@@ -6682,6 +6688,9 @@ if test "$sheepdog" = "yes" ; then
-   add_to deprecated_features "sheepdog"
-   echo "CONFIG_SHEEPDOG=y" >> $config_host_mak
- fi
-+if test "$pbs_bdrv" = "yes" ; then
-+  echo "CONFIG_PBS_BDRV=y" >> $config_host_mak
-+fi
- if test "$pty_h" = "yes" ; then
-   echo "HAVE_PTY_H=y" >> $config_host_mak
- fi
-diff --git a/meson.build b/meson.build
-index 6f1fafee14..4d156d35ce 100644
---- a/meson.build
-+++ b/meson.build
-@@ -2199,6 +2199,7 @@ summary_info += {'vvfat support':     config_host.has_key('CONFIG_VVFAT')}
- summary_info += {'qed support':       config_host.has_key('CONFIG_QED')}
- summary_info += {'parallels support': config_host.has_key('CONFIG_PARALLELS')}
- summary_info += {'sheepdog support':  config_host.has_key('CONFIG_SHEEPDOG')}
-+summary_info += {'PBS bdrv support':  config_host.has_key('CONFIG_PBS_BDRV')}
- summary_info += {'capstone':          capstone_opt == 'disabled' ? false : capstone_opt}
- summary_info += {'libpmem support':   config_host.has_key('CONFIG_LIBPMEM')}
- summary_info += {'libdaxctl support': config_host.has_key('CONFIG_LIBDAXCTL')}
-diff --git a/qapi/block-core.json b/qapi/block-core.json
-index 0fda1e3fd3..553112d998 100644
---- a/qapi/block-core.json
-+++ b/qapi/block-core.json
-@@ -2975,7 +2975,7 @@
-             'luks', 'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallels',
-             'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'rbd',
-             { 'name': 'replication', 'if': 'defined(CONFIG_REPLICATION)' },
--            'sheepdog',
-+            'sheepdog', 'pbs',
-             'ssh', 'throttle', 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat' ] }
- ##
-@@ -3039,6 +3039,17 @@
- { 'struct': 'BlockdevOptionsNull',
-   'data': { '*size': 'int', '*latency-ns': 'uint64', '*read-zeroes': 'bool' } }
-+##
-+# @BlockdevOptionsPbs:
-+#
-+# Driver specific block device options for the PBS backend.
-+#
-+##
-+{ 'struct': 'BlockdevOptionsPbs',
-+  'data': { 'repository': 'str', 'snapshot': 'str', 'archive': 'str',
-+            '*keyfile': 'str', '*password': 'str', '*fingerprint': 'str',
-+            '*key_password': 'str' } }
-+
- ##
- # @BlockdevOptionsNVMe:
- #
-@@ -4148,6 +4159,7 @@
-       'nfs':        'BlockdevOptionsNfs',
-       'null-aio':   'BlockdevOptionsNull',
-       'null-co':    'BlockdevOptionsNull',
-+      'pbs':        'BlockdevOptionsPbs',
-       'nvme':       'BlockdevOptionsNVMe',
-       'parallels':  'BlockdevOptionsGenericFormat',
-       'qcow2':      'BlockdevOptionsQcow2',
diff --git a/debian/patches/pve/0043-PVE-Backup-Use-a-transaction-to-synchronize-job-stat.patch b/debian/patches/pve/0043-PVE-Backup-Use-a-transaction-to-synchronize-job-stat.patch
new file mode 100644 (file)
index 0000000..bb3b026
--- /dev/null
@@ -0,0 +1,292 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Stefan Reiter <s.reiter@proxmox.com>
+Date: Thu, 20 Aug 2020 14:25:00 +0200
+Subject: [PATCH] PVE-Backup: Use a transaction to synchronize job states
+
+By using a JobTxn, we can sync dirty bitmaps only when *all* jobs were
+successful - meaning we don't need to remove them when the backup fails,
+since QEMU's BITMAP_SYNC_MODE_ON_SUCCESS will now handle that for us.
+
+To keep the rate-limiting and IO impact from before, we use a sequential
+transaction, so drives will still be backed up one after the other.
+
+Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
+---
+ pve-backup.c | 167 +++++++++++++++------------------------------------
+ 1 file changed, 49 insertions(+), 118 deletions(-)
+
+diff --git a/pve-backup.c b/pve-backup.c
+index 1e7b92a950..f3df43eb8c 100644
+--- a/pve-backup.c
++++ b/pve-backup.c
+@@ -52,6 +52,7 @@ static struct PVEBackupState {
+     VmaWriter *vmaw;
+     ProxmoxBackupHandle *pbs;
+     GList *di_list;
++    JobTxn *txn;
+     QemuMutex backup_mutex;
+     CoMutex dump_callback_mutex;
+ } backup_state;
+@@ -71,32 +72,12 @@ typedef struct PVEBackupDevInfo {
+     size_t size;
+     uint64_t block_size;
+     uint8_t dev_id;
+-    bool completed;
+     char targetfile[PATH_MAX];
+     BdrvDirtyBitmap *bitmap;
+     BlockDriverState *target;
++    BlockJob *job;
+ } PVEBackupDevInfo;
+-static void pvebackup_run_next_job(void);
+-
+-static BlockJob *
+-lookup_active_block_job(PVEBackupDevInfo *di)
+-{
+-    if (!di->completed && di->bs) {
+-        for (BlockJob *job = block_job_next(NULL); job; job = block_job_next(job)) {
+-            if (job->job.driver->job_type != JOB_TYPE_BACKUP) {
+-                continue;
+-            }
+-
+-            BackupBlockJob *bjob = container_of(job, BackupBlockJob, common);
+-            if (bjob && bjob->source_bs == di->bs) {
+-                return job;
+-            }
+-        }
+-    }
+-    return NULL;
+-}
+-
+ static void pvebackup_propagate_error(Error *err)
+ {
+     qemu_mutex_lock(&backup_state.stat.lock);
+@@ -272,18 +253,6 @@ static void coroutine_fn pvebackup_co_cleanup(void *unused)
+             if (local_err != NULL) {
+                 pvebackup_propagate_error(local_err);
+             }
+-        } else {
+-            // on error or cancel we cannot ensure synchronization of dirty
+-            // bitmaps with backup server, so remove all and do full backup next
+-            GList *l = backup_state.di_list;
+-            while (l) {
+-                PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
+-                l = g_list_next(l);
+-
+-                if (di->bitmap) {
+-                    bdrv_release_dirty_bitmap(di->bitmap);
+-                }
+-            }
+         }
+         proxmox_backup_disconnect(backup_state.pbs);
+@@ -322,8 +291,6 @@ static void pvebackup_complete_cb(void *opaque, int ret)
+     qemu_mutex_lock(&backup_state.backup_mutex);
+-    di->completed = true;
+-
+     if (ret < 0) {
+         Error *local_err = NULL;
+         error_setg(&local_err, "job failed with err %d - %s", ret, strerror(-ret));
+@@ -336,20 +303,17 @@ static void pvebackup_complete_cb(void *opaque, int ret)
+     block_on_coroutine_fn(pvebackup_complete_stream, di);
+-    // remove self from job queue
++    // remove self from job list
+     backup_state.di_list = g_list_remove(backup_state.di_list, di);
+-    if (di->bitmap && ret < 0) {
+-        // on error or cancel we cannot ensure synchronization of dirty
+-        // bitmaps with backup server, so remove all and do full backup next
+-        bdrv_release_dirty_bitmap(di->bitmap);
+-    }
+-
+     g_free(di);
+-    qemu_mutex_unlock(&backup_state.backup_mutex);
++    /* call cleanup if we're the last job */
++    if (!g_list_first(backup_state.di_list)) {
++        block_on_coroutine_fn(pvebackup_co_cleanup, NULL);
++    }
+-    pvebackup_run_next_job();
++    qemu_mutex_unlock(&backup_state.backup_mutex);
+ }
+ static void pvebackup_cancel(void)
+@@ -371,36 +335,28 @@ static void pvebackup_cancel(void)
+         proxmox_backup_abort(backup_state.pbs, "backup canceled");
+     }
+-    qemu_mutex_unlock(&backup_state.backup_mutex);
+-
+-    for(;;) {
+-
+-        BlockJob *next_job = NULL;
+-
+-        qemu_mutex_lock(&backup_state.backup_mutex);
+-
+-        GList *l = backup_state.di_list;
+-        while (l) {
+-            PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
+-            l = g_list_next(l);
++    /* it's enough to cancel one job in the transaction, the rest will follow
++     * automatically */
++    GList *bdi = g_list_first(backup_state.di_list);
++    BlockJob *cancel_job = bdi && bdi->data ?
++        ((PVEBackupDevInfo *)bdi->data)->job :
++        NULL;
+-            BlockJob *job = lookup_active_block_job(di);
+-            if (job != NULL) {
+-                next_job = job;
+-                break;
+-            }
+-        }
++    /* ref the job before releasing the mutex, just to be safe */
++    if (cancel_job) {
++        job_ref(&cancel_job->job);
++    }
+-        qemu_mutex_unlock(&backup_state.backup_mutex);
++    /* job_cancel_sync may enter the job, so we need to release the
++     * backup_mutex to avoid deadlock */
++    qemu_mutex_unlock(&backup_state.backup_mutex);
+-        if (next_job) {
+-            AioContext *aio_context = next_job->job.aio_context;
+-            aio_context_acquire(aio_context);
+-            job_cancel_sync(&next_job->job);
+-            aio_context_release(aio_context);
+-        } else {
+-            break;
+-        }
++    if (cancel_job) {
++        AioContext *aio_context = cancel_job->job.aio_context;
++        aio_context_acquire(aio_context);
++        job_cancel_sync(&cancel_job->job);
++        job_unref(&cancel_job->job);
++        aio_context_release(aio_context);
+     }
+ }
+@@ -459,51 +415,19 @@ static int coroutine_fn pvebackup_co_add_config(
+     goto out;
+ }
+-bool job_should_pause(Job *job);
+-
+-static void pvebackup_run_next_job(void)
+-{
+-    assert(!qemu_in_coroutine());
+-
+-    qemu_mutex_lock(&backup_state.backup_mutex);
+-
+-    GList *l = backup_state.di_list;
+-    while (l) {
+-        PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
+-        l = g_list_next(l);
+-
+-        BlockJob *job = lookup_active_block_job(di);
+-
+-        if (job) {
+-            qemu_mutex_unlock(&backup_state.backup_mutex);
+-
+-            AioContext *aio_context = job->job.aio_context;
+-            aio_context_acquire(aio_context);
+-
+-            if (job_should_pause(&job->job)) {
+-                bool error_or_canceled = pvebackup_error_or_canceled();
+-                if (error_or_canceled) {
+-                    job_cancel_sync(&job->job);
+-                } else {
+-                    job_resume(&job->job);
+-                }
+-            }
+-            aio_context_release(aio_context);
+-            return;
+-        }
+-    }
+-
+-    block_on_coroutine_fn(pvebackup_co_cleanup, NULL); // no more jobs, run cleanup
+-
+-    qemu_mutex_unlock(&backup_state.backup_mutex);
+-}
+-
+ static bool create_backup_jobs(void) {
+     assert(!qemu_in_coroutine());
+     Error *local_err = NULL;
++    /* create job transaction to synchronize bitmap commit and cancel all
++     * jobs in case one errors */
++    if (backup_state.txn) {
++        job_txn_unref(backup_state.txn);
++    }
++    backup_state.txn = job_txn_new_seq();
++
+     /* create and start all jobs (paused state) */
+     GList *l =  backup_state.di_list;
+     while (l) {
+@@ -524,7 +448,7 @@ static bool create_backup_jobs(void) {
+         BlockJob *job = backup_job_create(
+             NULL, di->bs, di->target, backup_state.speed, sync_mode, di->bitmap,
+             bitmap_mode, false, NULL, BLOCKDEV_ON_ERROR_REPORT, BLOCKDEV_ON_ERROR_REPORT,
+-            JOB_DEFAULT, pvebackup_complete_cb, di, 1, NULL, &local_err);
++            JOB_DEFAULT, pvebackup_complete_cb, di, backup_state.txn, &local_err);
+         aio_context_release(aio_context);
+@@ -536,7 +460,8 @@ static bool create_backup_jobs(void) {
+             pvebackup_propagate_error(create_job_err);
+             break;
+         }
+-        job_start(&job->job);
++
++        di->job = job;
+         bdrv_unref(di->target);
+         di->target = NULL;
+@@ -554,6 +479,10 @@ static bool create_backup_jobs(void) {
+                 bdrv_unref(di->target);
+                 di->target = NULL;
+             }
++
++            if (di->job) {
++                job_unref(&di->job->job);
++            }
+         }
+     }
+@@ -944,10 +873,6 @@ err:
+         PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
+         l = g_list_next(l);
+-        if (di->bitmap) {
+-            bdrv_release_dirty_bitmap(di->bitmap);
+-        }
+-
+         if (di->target) {
+             bdrv_unref(di->target);
+         }
+@@ -1036,9 +961,15 @@ UuidInfo *qmp_backup(
+     block_on_coroutine_fn(pvebackup_co_prepare, &task);
+     if (*errp == NULL) {
+-        create_backup_jobs();
++        bool errors = create_backup_jobs();
+         qemu_mutex_unlock(&backup_state.backup_mutex);
+-        pvebackup_run_next_job();
++
++        if (!errors) {
++            /* start the first job in the transaction
++             * note: this might directly enter the job, so we need to do this
++             * after unlocking the backup_mutex */
++            job_txn_start_seq(backup_state.txn);
++        }
+     } else {
+         qemu_mutex_unlock(&backup_state.backup_mutex);
+     }
diff --git a/debian/patches/pve/0044-PVE-Backup-Don-t-block-on-finishing-and-cleanup-crea.patch b/debian/patches/pve/0044-PVE-Backup-Don-t-block-on-finishing-and-cleanup-crea.patch
new file mode 100644 (file)
index 0000000..d15dda1
--- /dev/null
@@ -0,0 +1,500 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Stefan Reiter <s.reiter@proxmox.com>
+Date: Mon, 28 Sep 2020 13:40:51 +0200
+Subject: [PATCH] PVE-Backup: Don't block on finishing and cleanup
+ create_backup_jobs
+
+proxmox_backup_co_finish is already async, but previously we would wait
+for the coroutine using block_on_coroutine_fn(). Avoid this by
+scheduling pvebackup_co_complete_stream (and thus pvebackup_co_cleanup)
+as a real coroutine when calling from pvebackup_complete_cb. This is ok,
+since complete_stream uses the backup_mutex internally to synchronize,
+and other streams can happily continue writing in the meantime anyway.
+
+To accomodate, backup_mutex is converted to a CoMutex. This means
+converting every user to a coroutine. This is not just useful here, but
+will come in handy once this series[0] is merged, and QMP calls can be
+yield-able coroutines too. Then we can also finally get rid of
+block_on_coroutine_fn.
+
+Cases of aio_context_acquire/release from within what is now a coroutine
+are changed to aio_co_reschedule_self, which works since a running
+coroutine always holds the aio lock for the context it is running in.
+
+job_cancel_sync is called from a BH since it can't be run from a
+coroutine (uses AIO_WAIT_WHILE internally).
+
+Same thing for create_backup_jobs, which is converted to a BH too.
+
+To communicate the finishing state, a new property is introduced to
+query-backup: 'finishing'. A new state is explicitly not used, since
+that would break compatibility with older qemu-server versions.
+
+Also fix create_backup_jobs:
+
+No more weird bool returns, just the standard "errp" format used
+everywhere else too. With this, if backup_job_create fails, the error
+message is actually returned over QMP and can be shown to the user.
+
+To facilitate correct cleanup on such an error, we call
+create_backup_jobs as a bottom half directly from pvebackup_co_prepare.
+This additionally allows us to actually hold the backup_mutex during
+operation.
+
+Also add a job_cancel_sync before job_unref, since a job must be in
+STATUS_NULL to be deleted by unref, which could trigger an assert
+before.
+
+[0] https://lists.gnu.org/archive/html/qemu-devel/2020-09/msg03515.html
+
+Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
+---
+ pve-backup.c         | 217 ++++++++++++++++++++++++++++---------------
+ qapi/block-core.json |   5 +-
+ 2 files changed, 144 insertions(+), 78 deletions(-)
+
+diff --git a/pve-backup.c b/pve-backup.c
+index f3df43eb8c..ded90cb822 100644
+--- a/pve-backup.c
++++ b/pve-backup.c
+@@ -33,7 +33,9 @@ const char *PBS_BITMAP_NAME = "pbs-incremental-dirty-bitmap";
+ static struct PVEBackupState {
+     struct {
+-        // Everithing accessed from qmp_backup_query command is protected using lock
++        // Everything accessed from qmp_backup_query command is protected using
++        // this lock. Do NOT hold this lock for long times, as it is sometimes
++        // acquired from coroutines, and thus any wait time may block the guest.
+         QemuMutex lock;
+         Error *error;
+         time_t start_time;
+@@ -47,20 +49,22 @@ static struct PVEBackupState {
+         size_t reused;
+         size_t zero_bytes;
+         GList *bitmap_list;
++        bool finishing;
++        bool starting;
+     } stat;
+     int64_t speed;
+     VmaWriter *vmaw;
+     ProxmoxBackupHandle *pbs;
+     GList *di_list;
+     JobTxn *txn;
+-    QemuMutex backup_mutex;
++    CoMutex backup_mutex;
+     CoMutex dump_callback_mutex;
+ } backup_state;
+ static void pvebackup_init(void)
+ {
+     qemu_mutex_init(&backup_state.stat.lock);
+-    qemu_mutex_init(&backup_state.backup_mutex);
++    qemu_co_mutex_init(&backup_state.backup_mutex);
+     qemu_co_mutex_init(&backup_state.dump_callback_mutex);
+ }
+@@ -72,6 +76,7 @@ typedef struct PVEBackupDevInfo {
+     size_t size;
+     uint64_t block_size;
+     uint8_t dev_id;
++    int completed_ret; // INT_MAX if not completed
+     char targetfile[PATH_MAX];
+     BdrvDirtyBitmap *bitmap;
+     BlockDriverState *target;
+@@ -227,12 +232,12 @@ pvebackup_co_dump_vma_cb(
+ }
+ // assumes the caller holds backup_mutex
+-static void coroutine_fn pvebackup_co_cleanup(void *unused)
++static void coroutine_fn pvebackup_co_cleanup(void)
+ {
+     assert(qemu_in_coroutine());
+     qemu_mutex_lock(&backup_state.stat.lock);
+-    backup_state.stat.end_time = time(NULL);
++    backup_state.stat.finishing = true;
+     qemu_mutex_unlock(&backup_state.stat.lock);
+     if (backup_state.vmaw) {
+@@ -261,35 +266,29 @@ static void coroutine_fn pvebackup_co_cleanup(void *unused)
+     g_list_free(backup_state.di_list);
+     backup_state.di_list = NULL;
++
++    qemu_mutex_lock(&backup_state.stat.lock);
++    backup_state.stat.end_time = time(NULL);
++    backup_state.stat.finishing = false;
++    qemu_mutex_unlock(&backup_state.stat.lock);
+ }
+-// assumes the caller holds backup_mutex
+-static void coroutine_fn pvebackup_complete_stream(void *opaque)
++static void coroutine_fn pvebackup_co_complete_stream(void *opaque)
+ {
+     PVEBackupDevInfo *di = opaque;
++    int ret = di->completed_ret;
+-    bool error_or_canceled = pvebackup_error_or_canceled();
+-
+-    if (backup_state.vmaw) {
+-        vma_writer_close_stream(backup_state.vmaw, di->dev_id);
++    qemu_mutex_lock(&backup_state.stat.lock);
++    bool starting = backup_state.stat.starting;
++    qemu_mutex_unlock(&backup_state.stat.lock);
++    if (starting) {
++        /* in 'starting' state, no tasks have been run yet, meaning we can (and
++         * must) skip all cleanup, as we don't know what has and hasn't been
++         * initialized yet. */
++        return;
+     }
+-    if (backup_state.pbs && !error_or_canceled) {
+-        Error *local_err = NULL;
+-        proxmox_backup_co_close_image(backup_state.pbs, di->dev_id, &local_err);
+-        if (local_err != NULL) {
+-            pvebackup_propagate_error(local_err);
+-        }
+-    }
+-}
+-
+-static void pvebackup_complete_cb(void *opaque, int ret)
+-{
+-    assert(!qemu_in_coroutine());
+-
+-    PVEBackupDevInfo *di = opaque;
+-
+-    qemu_mutex_lock(&backup_state.backup_mutex);
++    qemu_co_mutex_lock(&backup_state.backup_mutex);
+     if (ret < 0) {
+         Error *local_err = NULL;
+@@ -301,7 +300,19 @@ static void pvebackup_complete_cb(void *opaque, int ret)
+     assert(di->target == NULL);
+-    block_on_coroutine_fn(pvebackup_complete_stream, di);
++    bool error_or_canceled = pvebackup_error_or_canceled();
++
++    if (backup_state.vmaw) {
++        vma_writer_close_stream(backup_state.vmaw, di->dev_id);
++    }
++
++    if (backup_state.pbs && !error_or_canceled) {
++        Error *local_err = NULL;
++        proxmox_backup_co_close_image(backup_state.pbs, di->dev_id, &local_err);
++        if (local_err != NULL) {
++            pvebackup_propagate_error(local_err);
++        }
++    }
+     // remove self from job list
+     backup_state.di_list = g_list_remove(backup_state.di_list, di);
+@@ -310,21 +321,49 @@ static void pvebackup_complete_cb(void *opaque, int ret)
+     /* call cleanup if we're the last job */
+     if (!g_list_first(backup_state.di_list)) {
+-        block_on_coroutine_fn(pvebackup_co_cleanup, NULL);
++        pvebackup_co_cleanup();
+     }
+-    qemu_mutex_unlock(&backup_state.backup_mutex);
++    qemu_co_mutex_unlock(&backup_state.backup_mutex);
+ }
+-static void pvebackup_cancel(void)
++static void pvebackup_complete_cb(void *opaque, int ret)
+ {
+-    assert(!qemu_in_coroutine());
++    PVEBackupDevInfo *di = opaque;
++    di->completed_ret = ret;
++
++    /*
++     * Schedule stream cleanup in async coroutine. close_image and finish might
++     * take a while, so we can't block on them here. This way it also doesn't
++     * matter if we're already running in a coroutine or not.
++     * Note: di is a pointer to an entry in the global backup_state struct, so
++     * it stays valid.
++     */
++    Coroutine *co = qemu_coroutine_create(pvebackup_co_complete_stream, di);
++    aio_co_enter(qemu_get_aio_context(), co);
++}
++
++/*
++ * job_cancel(_sync) does not like to be called from coroutines, so defer to
++ * main loop processing via a bottom half.
++ */
++static void job_cancel_bh(void *opaque) {
++    CoCtxData *data = (CoCtxData*)opaque;
++    Job *job = (Job*)data->data;
++    AioContext *job_ctx = job->aio_context;
++    aio_context_acquire(job_ctx);
++    job_cancel_sync(job);
++    aio_context_release(job_ctx);
++    aio_co_enter(data->ctx, data->co);
++}
++static void coroutine_fn pvebackup_co_cancel(void *opaque)
++{
+     Error *cancel_err = NULL;
+     error_setg(&cancel_err, "backup canceled");
+     pvebackup_propagate_error(cancel_err);
+-    qemu_mutex_lock(&backup_state.backup_mutex);
++    qemu_co_mutex_lock(&backup_state.backup_mutex);
+     if (backup_state.vmaw) {
+         /* make sure vma writer does not block anymore */
+@@ -342,27 +381,22 @@ static void pvebackup_cancel(void)
+         ((PVEBackupDevInfo *)bdi->data)->job :
+         NULL;
+-    /* ref the job before releasing the mutex, just to be safe */
+     if (cancel_job) {
+-        job_ref(&cancel_job->job);
++        CoCtxData data = {
++            .ctx = qemu_get_current_aio_context(),
++            .co = qemu_coroutine_self(),
++            .data = &cancel_job->job,
++        };
++        aio_bh_schedule_oneshot(data.ctx, job_cancel_bh, &data);
++        qemu_coroutine_yield();
+     }
+-    /* job_cancel_sync may enter the job, so we need to release the
+-     * backup_mutex to avoid deadlock */
+-    qemu_mutex_unlock(&backup_state.backup_mutex);
+-
+-    if (cancel_job) {
+-        AioContext *aio_context = cancel_job->job.aio_context;
+-        aio_context_acquire(aio_context);
+-        job_cancel_sync(&cancel_job->job);
+-        job_unref(&cancel_job->job);
+-        aio_context_release(aio_context);
+-    }
++    qemu_co_mutex_unlock(&backup_state.backup_mutex);
+ }
+ void qmp_backup_cancel(Error **errp)
+ {
+-    pvebackup_cancel();
++    block_on_coroutine_fn(pvebackup_co_cancel, NULL);
+ }
+ // assumes the caller holds backup_mutex
+@@ -415,10 +449,18 @@ static int coroutine_fn pvebackup_co_add_config(
+     goto out;
+ }
+-static bool create_backup_jobs(void) {
++/*
++ * backup_job_create can *not* be run from a coroutine (and requires an
++ * acquired AioContext), so this can't either.
++ * The caller is responsible that backup_mutex is held nonetheless.
++ */
++static void create_backup_jobs_bh(void *opaque) {
+     assert(!qemu_in_coroutine());
++    CoCtxData *data = (CoCtxData*)opaque;
++    Error **errp = (Error**)data->data;
++
+     Error *local_err = NULL;
+     /* create job transaction to synchronize bitmap commit and cancel all
+@@ -452,24 +494,19 @@ static bool create_backup_jobs(void) {
+         aio_context_release(aio_context);
+-        if (!job || local_err != NULL) {
+-            Error *create_job_err = NULL;
+-            error_setg(&create_job_err, "backup_job_create failed: %s",
+-                       local_err ? error_get_pretty(local_err) : "null");
++        di->job = job;
+-            pvebackup_propagate_error(create_job_err);
++        if (!job || local_err) {
++            error_setg(errp, "backup_job_create failed: %s",
++                       local_err ? error_get_pretty(local_err) : "null");
+             break;
+         }
+-        di->job = job;
+-
+         bdrv_unref(di->target);
+         di->target = NULL;
+     }
+-    bool errors = pvebackup_error_or_canceled();
+-
+-    if (errors) {
++    if (*errp) {
+         l = backup_state.di_list;
+         while (l) {
+             PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
+@@ -481,12 +518,17 @@ static bool create_backup_jobs(void) {
+             }
+             if (di->job) {
++                AioContext *ctx = di->job->job.aio_context;
++                aio_context_acquire(ctx);
++                job_cancel_sync(&di->job->job);
+                 job_unref(&di->job->job);
++                aio_context_release(ctx);
+             }
+         }
+     }
+-    return errors;
++    /* return */
++    aio_co_enter(data->ctx, data->co);
+ }
+ typedef struct QmpBackupTask {
+@@ -523,11 +565,12 @@ typedef struct QmpBackupTask {
+     UuidInfo *result;
+ } QmpBackupTask;
+-// assumes the caller holds backup_mutex
+ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+ {
+     assert(qemu_in_coroutine());
++    qemu_co_mutex_lock(&backup_state.backup_mutex);
++
+     QmpBackupTask *task = opaque;
+     task->result = NULL; // just to be sure
+@@ -548,8 +591,9 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+     const char *firewall_name = "qemu-server.fw";
+     if (backup_state.di_list) {
+-         error_set(task->errp, ERROR_CLASS_GENERIC_ERROR,
++        error_set(task->errp, ERROR_CLASS_GENERIC_ERROR,
+                   "previous backup not finished");
++        qemu_co_mutex_unlock(&backup_state.backup_mutex);
+         return;
+     }
+@@ -616,6 +660,8 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+         }
+         di->size = size;
+         total += size;
++
++        di->completed_ret = INT_MAX;
+     }
+     uuid_generate(uuid);
+@@ -847,6 +893,8 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+     backup_state.stat.dirty = total - backup_state.stat.reused;
+     backup_state.stat.transferred = 0;
+     backup_state.stat.zero_bytes = 0;
++    backup_state.stat.finishing = false;
++    backup_state.stat.starting = true;
+     qemu_mutex_unlock(&backup_state.stat.lock);
+@@ -861,6 +909,33 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+     uuid_info->UUID = uuid_str;
+     task->result = uuid_info;
++
++    /* Run create_backup_jobs_bh outside of coroutine (in BH) but keep
++    * backup_mutex locked. This is fine, a CoMutex can be held across yield
++    * points, and we'll release it as soon as the BH reschedules us.
++    */
++    CoCtxData waker = {
++        .co = qemu_coroutine_self(),
++        .ctx = qemu_get_current_aio_context(),
++        .data = &local_err,
++    };
++    aio_bh_schedule_oneshot(waker.ctx, create_backup_jobs_bh, &waker);
++    qemu_coroutine_yield();
++
++    if (local_err) {
++        error_propagate(task->errp, local_err);
++        goto err;
++    }
++
++    qemu_co_mutex_unlock(&backup_state.backup_mutex);
++
++    qemu_mutex_lock(&backup_state.stat.lock);
++    backup_state.stat.starting = false;
++    qemu_mutex_unlock(&backup_state.stat.lock);
++
++    /* start the first job in the transaction */
++    job_txn_start_seq(backup_state.txn);
++
+     return;
+ err_mutex:
+@@ -883,6 +958,7 @@ err:
+         g_free(di);
+     }
+     g_list_free(di_list);
++    backup_state.di_list = NULL;
+     if (devs) {
+         g_strfreev(devs);
+@@ -903,6 +979,8 @@ err:
+     }
+     task->result = NULL;
++
++    qemu_co_mutex_unlock(&backup_state.backup_mutex);
+     return;
+ }
+@@ -956,24 +1034,8 @@ UuidInfo *qmp_backup(
+         .errp = errp,
+     };
+-    qemu_mutex_lock(&backup_state.backup_mutex);
+-
+     block_on_coroutine_fn(pvebackup_co_prepare, &task);
+-    if (*errp == NULL) {
+-        bool errors = create_backup_jobs();
+-        qemu_mutex_unlock(&backup_state.backup_mutex);
+-
+-        if (!errors) {
+-            /* start the first job in the transaction
+-             * note: this might directly enter the job, so we need to do this
+-             * after unlocking the backup_mutex */
+-            job_txn_start_seq(backup_state.txn);
+-        }
+-    } else {
+-        qemu_mutex_unlock(&backup_state.backup_mutex);
+-    }
+-
+     return task.result;
+ }
+@@ -1025,6 +1087,7 @@ BackupStatus *qmp_query_backup(Error **errp)
+     info->transferred = backup_state.stat.transferred;
+     info->has_reused = true;
+     info->reused = backup_state.stat.reused;
++    info->finishing = backup_state.stat.finishing;
+     qemu_mutex_unlock(&backup_state.stat.lock);
+diff --git a/qapi/block-core.json b/qapi/block-core.json
+index b368371e8e..b90d6abe64 100644
+--- a/qapi/block-core.json
++++ b/qapi/block-core.json
+@@ -775,12 +775,15 @@
+ #
+ # @uuid: uuid for this backup job
+ #
++# @finishing: if status='active' and finishing=true, then the backup process is
++#             waiting for the target to finish.
++#
+ ##
+ { 'struct': 'BackupStatus',
+   'data': {'*status': 'str', '*errmsg': 'str', '*total': 'int', '*dirty': 'int',
+            '*transferred': 'int', '*zero-bytes': 'int', '*reused': 'int',
+            '*start-time': 'int', '*end-time': 'int',
+-           '*backup-file': 'str', '*uuid': 'str' } }
++           '*backup-file': 'str', '*uuid': 'str', 'finishing': 'bool' } }
+ ##
+ # @BackupFormat:
diff --git a/debian/patches/pve/0044-PVE-add-query_proxmox_support-QMP-command.patch b/debian/patches/pve/0044-PVE-add-query_proxmox_support-QMP-command.patch
deleted file mode 100644 (file)
index a9cbe84..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: Stefan Reiter <s.reiter@proxmox.com>
-Date: Wed, 8 Jul 2020 11:57:53 +0200
-Subject: [PATCH] PVE: add query_proxmox_support QMP command
-
-Generic interface for future use, currently used for PBS dirty-bitmap
-backup support.
-
-Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
-Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
-[PVE: query-proxmox-support: include library version]
-Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
----
- pve-backup.c         |  8 ++++++++
- qapi/block-core.json | 25 +++++++++++++++++++++++++
- 2 files changed, 33 insertions(+)
-
-diff --git a/pve-backup.c b/pve-backup.c
-index bfb648d6b5..ba9d0d8a86 100644
---- a/pve-backup.c
-+++ b/pve-backup.c
-@@ -1051,3 +1051,11 @@ BackupStatus *qmp_query_backup(Error **errp)
-     return info;
- }
-+
-+ProxmoxSupportStatus *qmp_query_proxmox_support(Error **errp)
-+{
-+    ProxmoxSupportStatus *ret = g_malloc0(sizeof(*ret));
-+    ret->pbs_library_version = g_strdup(proxmox_backup_qemu_version());
-+    ret->pbs_dirty_bitmap = true;
-+    return ret;
-+}
-diff --git a/qapi/block-core.json b/qapi/block-core.json
-index 553112d998..e0a0a60354 100644
---- a/qapi/block-core.json
-+++ b/qapi/block-core.json
-@@ -868,6 +868,31 @@
- ##
- { 'command': 'backup-cancel' }
-+##
-+# @ProxmoxSupportStatus:
-+#
-+# Contains info about supported features added by Proxmox.
-+#
-+# @pbs-dirty-bitmap: True if dirty-bitmap-incremental backups to PBS are
-+#                    supported.
-+#
-+# @pbs-library-version: Running version of libproxmox-backup-qemu0 library.
-+#
-+##
-+{ 'struct': 'ProxmoxSupportStatus',
-+  'data': { 'pbs-dirty-bitmap': 'bool',
-+            'pbs-library-version': 'str' } }
-+
-+##
-+# @query-proxmox-support:
-+#
-+# Returns information about supported features added by Proxmox.
-+#
-+# Returns: @ProxmoxSupportStatus
-+#
-+##
-+{ 'command': 'query-proxmox-support', 'returns': 'ProxmoxSupportStatus' }
-+
- ##
- # @BlockDeviceTimedStats:
- #
diff --git a/debian/patches/pve/0045-PVE-Migrate-dirty-bitmap-state-via-savevm.patch b/debian/patches/pve/0045-PVE-Migrate-dirty-bitmap-state-via-savevm.patch
new file mode 100644 (file)
index 0000000..a4ee6bc
--- /dev/null
@@ -0,0 +1,209 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Stefan Reiter <s.reiter@proxmox.com>
+Date: Thu, 22 Oct 2020 17:34:18 +0200
+Subject: [PATCH] PVE: Migrate dirty bitmap state via savevm
+
+QEMU provides 'savevm' registrations as a mechanism for arbitrary state
+to be migrated along with a VM. Use this to send a serialized version of
+dirty bitmap state data from proxmox-backup-qemu, and restore it on the
+target node.
+
+Also add a flag to query-proxmox-support so qemu-server can determine if
+safe migration is possible and makes sense.
+
+Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
+---
+ include/migration/misc.h |   3 ++
+ migration/meson.build    |   2 +
+ migration/pbs-state.c    | 106 +++++++++++++++++++++++++++++++++++++++
+ pve-backup.c             |   1 +
+ qapi/block-core.json     |   6 +++
+ softmmu/vl.c             |   1 +
+ 6 files changed, 119 insertions(+)
+ create mode 100644 migration/pbs-state.c
+
+diff --git a/include/migration/misc.h b/include/migration/misc.h
+index 34e7d75713..f83816dd3c 100644
+--- a/include/migration/misc.h
++++ b/include/migration/misc.h
+@@ -75,4 +75,7 @@ bool migration_in_incoming_postcopy(void);
+ /* migration/block-dirty-bitmap.c */
+ void dirty_bitmap_mig_init(void);
++/* migration/pbs-state.c */
++void pbs_state_mig_init(void);
++
+ #endif
+diff --git a/migration/meson.build b/migration/meson.build
+index e62b79b60f..b90a04aa75 100644
+--- a/migration/meson.build
++++ b/migration/meson.build
+@@ -7,8 +7,10 @@ migration_files = files(
+   'qemu-file-channel.c',
+   'qemu-file.c',
+   'qjson.c',
++  'pbs-state.c',
+ )
+ softmmu_ss.add(migration_files)
++softmmu_ss.add(libproxmox_backup_qemu)
+ softmmu_ss.add(files(
+   'block-dirty-bitmap.c',
+diff --git a/migration/pbs-state.c b/migration/pbs-state.c
+new file mode 100644
+index 0000000000..29f2b3860d
+--- /dev/null
++++ b/migration/pbs-state.c
+@@ -0,0 +1,106 @@
++/*
++ * PBS (dirty-bitmap) state migration
++ */
++
++#include "qemu/osdep.h"
++#include "migration/misc.h"
++#include "qemu-file.h"
++#include "migration/vmstate.h"
++#include "migration/register.h"
++#include "proxmox-backup-qemu.h"
++
++typedef struct PBSState {
++    bool active;
++} PBSState;
++
++/* state is accessed via this static variable directly, 'opaque' is NULL */
++static PBSState pbs_state;
++
++static void pbs_state_save_pending(QEMUFile *f, void *opaque,
++                                      uint64_t max_size,
++                                      uint64_t *res_precopy_only,
++                                      uint64_t *res_compatible,
++                                      uint64_t *res_postcopy_only)
++{
++    /* we send everything in save_setup, so nothing is ever pending */
++}
++
++/* receive PBS state via f and deserialize, called on target */
++static int pbs_state_load(QEMUFile *f, void *opaque, int version_id)
++{
++    /* safe cast, we cannot migrate to target with less bits than source */
++    size_t buf_size = (size_t)qemu_get_be64(f);
++
++    uint8_t *buf = (uint8_t *)malloc(buf_size);
++    size_t read = qemu_get_buffer(f, buf, buf_size);
++
++    if (read < buf_size) {
++        fprintf(stderr, "error receiving PBS state: not enough data\n");
++        return -EIO;
++    }
++
++    proxmox_import_state(buf, buf_size);
++
++    free(buf);
++    return 0;
++}
++
++/* serialize PBS state and send to target via f, called on source */
++static int pbs_state_save_setup(QEMUFile *f, void *opaque)
++{
++    size_t buf_size;
++    uint8_t *buf = proxmox_export_state(&buf_size);
++
++    /* LV encoding */
++    qemu_put_be64(f, buf_size);
++    qemu_put_buffer(f, buf, buf_size);
++
++    proxmox_free_state_buf(buf);
++    pbs_state.active = false;
++    return 0;
++}
++
++static bool pbs_state_is_active(void *opaque)
++{
++    /* we need to return active exactly once, else .save_setup is never called,
++     * but if we'd just return true the migration doesn't make progress since
++     * it'd be waiting for us */
++    return pbs_state.active;
++}
++
++static bool pbs_state_is_active_iterate(void *opaque)
++{
++    /* we don't iterate, everything is sent in save_setup */
++    return pbs_state_is_active(opaque);
++}
++
++static bool pbs_state_has_postcopy(void *opaque)
++{
++    /* PBS state can't change during a migration (since that's blocking any
++     * potential backups), so we can copy everything before the VM is stopped */
++    return false;
++}
++
++static void pbs_state_save_cleanup(void *opaque)
++{
++    /* reset active after migration succeeds or fails */
++    pbs_state.active = false;
++}
++
++static SaveVMHandlers savevm_pbs_state_handlers = {
++    .save_setup = pbs_state_save_setup,
++    .has_postcopy = pbs_state_has_postcopy,
++    .save_live_pending = pbs_state_save_pending,
++    .is_active_iterate = pbs_state_is_active_iterate,
++    .load_state = pbs_state_load,
++    .is_active = pbs_state_is_active,
++    .save_cleanup = pbs_state_save_cleanup,
++};
++
++void pbs_state_mig_init(void)
++{
++    pbs_state.active = true;
++    register_savevm_live("pbs-state", 0, 1,
++                         &savevm_pbs_state_handlers,
++                         NULL);
++}
+diff --git a/pve-backup.c b/pve-backup.c
+index ded90cb822..6b25292ba1 100644
+--- a/pve-backup.c
++++ b/pve-backup.c
+@@ -1130,5 +1130,6 @@ ProxmoxSupportStatus *qmp_query_proxmox_support(Error **errp)
+     ret->pbs_library_version = g_strdup(proxmox_backup_qemu_version());
+     ret->pbs_dirty_bitmap = true;
+     ret->query_bitmap_info = true;
++    ret->pbs_dirty_bitmap_migration = true;
+     return ret;
+ }
+diff --git a/qapi/block-core.json b/qapi/block-core.json
+index b90d6abe64..dee3d87efe 100644
+--- a/qapi/block-core.json
++++ b/qapi/block-core.json
+@@ -881,12 +881,18 @@
+ #
+ # @query-bitmap-info: True if the 'query-pbs-bitmap-info' QMP call is supported.
+ #
++# @pbs-dirty-bitmap-migration: True if safe migration of dirty-bitmaps including
++#                              PBS state is supported. Enabling 'dirty-bitmaps'
++#                              migration cap if this is false/unset may lead
++#                              to crashes on migration!
++#
+ # @pbs-library-version: Running version of libproxmox-backup-qemu0 library.
+ #
+ ##
+ { 'struct': 'ProxmoxSupportStatus',
+   'data': { 'pbs-dirty-bitmap': 'bool',
+             'query-bitmap-info': 'bool',
++            'pbs-dirty-bitmap-migration': 'bool',
+             'pbs-library-version': 'str' } }
+ ##
+diff --git a/softmmu/vl.c b/softmmu/vl.c
+index 5b5512128e..6721889fee 100644
+--- a/softmmu/vl.c
++++ b/softmmu/vl.c
+@@ -4304,6 +4304,7 @@ void qemu_init(int argc, char **argv, char **envp)
+     blk_mig_init();
+     ram_mig_init();
+     dirty_bitmap_mig_init();
++    pbs_state_mig_init();
+     qemu_opts_foreach(qemu_find_opts("mon"),
+                       mon_init_func, NULL, &error_fatal);
diff --git a/debian/patches/pve/0045-pbs-fix-missing-crypt-and-compress-parameters.patch b/debian/patches/pve/0045-pbs-fix-missing-crypt-and-compress-parameters.patch
deleted file mode 100644 (file)
index d4a03be..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: Wolfgang Bumiller <w.bumiller@proxmox.com>
-Date: Fri, 10 Jul 2020 13:22:35 +0200
-Subject: [PATCH] pbs: fix missing crypt and compress parameters
-
-Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
----
- pve-backup.c | 8 ++++++--
- 1 file changed, 6 insertions(+), 2 deletions(-)
-
-diff --git a/pve-backup.c b/pve-backup.c
-index ba9d0d8a86..e1dcf10a45 100644
---- a/pve-backup.c
-+++ b/pve-backup.c
-@@ -958,6 +958,8 @@ UuidInfo *qmp_backup(
-         .backup_file = backup_file,
-         .has_password = has_password,
-         .password = password,
-+        .has_keyfile = has_keyfile,
-+        .keyfile = keyfile,
-         .has_key_password = has_key_password,
-         .key_password = key_password,
-         .has_fingerprint = has_fingerprint,
-@@ -968,6 +970,10 @@ UuidInfo *qmp_backup(
-         .backup_time = backup_time,
-         .has_use_dirty_bitmap = has_use_dirty_bitmap,
-         .use_dirty_bitmap = use_dirty_bitmap,
-+        .has_compress = has_compress,
-+        .compress = compress,
-+        .has_encrypt = has_encrypt,
-+        .encrypt = encrypt,
-         .has_format = has_format,
-         .format = format,
-         .has_config_file = has_config_file,
-@@ -976,8 +982,6 @@ UuidInfo *qmp_backup(
-         .firewall_file = firewall_file,
-         .has_devlist = has_devlist,
-         .devlist = devlist,
--        .has_compress = has_compress,
--        .has_encrypt = has_encrypt,
-         .has_speed = has_speed,
-         .speed = speed,
-         .errp = errp,
diff --git a/debian/patches/pve/0046-PVE-handle-PBS-write-callback-with-big-blocks-correc.patch b/debian/patches/pve/0046-PVE-handle-PBS-write-callback-with-big-blocks-correc.patch
deleted file mode 100644 (file)
index 7457eb6..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: Stefan Reiter <s.reiter@proxmox.com>
-Date: Wed, 19 Aug 2020 12:33:17 +0200
-Subject: [PATCH] PVE: handle PBS write callback with big blocks correctly
-
-Under certain conditions QEMU will push more than the given blocksize
-into the callback at once. Handle it like VMA does, by iterating the
-data until all is written.
-
-The block size is stored per backup device to be used in the callback.
-This avoids relying on PROXMOX_BACKUP_DEFAULT_CHUNK_SIZE, in case it is
-made configurable in the future.
-
-Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
----
- pve-backup.c | 30 ++++++++++++++++++++++--------
- 1 file changed, 22 insertions(+), 8 deletions(-)
-
-diff --git a/pve-backup.c b/pve-backup.c
-index e1dcf10a45..3eba85506a 100644
---- a/pve-backup.c
-+++ b/pve-backup.c
-@@ -67,6 +67,7 @@ opts_init(pvebackup_init);
- typedef struct PVEBackupDevInfo {
-     BlockDriverState *bs;
-     size_t size;
-+    uint64_t block_size;
-     uint8_t dev_id;
-     bool completed;
-     char targetfile[PATH_MAX];
-@@ -147,17 +148,28 @@ pvebackup_co_dump_pbs_cb(
-         return -1;
-     }
--    pbs_res = proxmox_backup_co_write_data(backup_state.pbs, di->dev_id, buf, start, size, &local_err);
--    qemu_co_mutex_unlock(&backup_state.dump_callback_mutex);
-+    uint64_t transferred = 0;
-+    uint64_t reused = 0;
-+    while (transferred < size) {
-+        uint64_t left = size - transferred;
-+        uint64_t to_transfer = left < di->block_size ? left : di->block_size;
--    if (pbs_res < 0) {
--        pvebackup_propagate_error(local_err);
--        return pbs_res;
--    } else {
--        size_t reused = (pbs_res == 0) ? size : 0;
--        pvebackup_add_transfered_bytes(size, !buf ? size : 0, reused);
-+        pbs_res = proxmox_backup_co_write_data(backup_state.pbs, di->dev_id,
-+            buf ? buf + transferred : NULL, start + transferred, to_transfer, &local_err);
-+        transferred += to_transfer;
-+
-+        if (pbs_res < 0) {
-+            pvebackup_propagate_error(local_err);
-+            qemu_co_mutex_unlock(&backup_state.dump_callback_mutex);
-+            return pbs_res;
-+        }
-+
-+        reused += pbs_res == 0 ? to_transfer : 0;
-     }
-+    qemu_co_mutex_unlock(&backup_state.dump_callback_mutex);
-+    pvebackup_add_transfered_bytes(size, !buf ? size : 0, reused);
-+
-     return size;
- }
-@@ -726,6 +738,8 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-             PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
-             l = g_list_next(l);
-+            di->block_size = dump_cb_block_size;
-+
-             const char *devname = bdrv_get_device_name(di->bs);
-             BdrvDirtyBitmap *bitmap = bdrv_find_dirty_bitmap(di->bs, PBS_BITMAP_NAME);
diff --git a/debian/patches/pve/0046-migration-block-dirty-bitmap-migrate-other-bitmaps-e.patch b/debian/patches/pve/0046-migration-block-dirty-bitmap-migrate-other-bitmaps-e.patch
new file mode 100644 (file)
index 0000000..775f992
--- /dev/null
@@ -0,0 +1,32 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Stefan Reiter <s.reiter@proxmox.com>
+Date: Tue, 3 Nov 2020 14:57:32 +0100
+Subject: [PATCH] migration/block-dirty-bitmap: migrate other bitmaps even if
+ one fails
+
+If the checks in bdrv_dirty_bitmap_check fail, that only means that this
+one specific bitmap cannot be migrated. That is not an error condition
+for any other bitmaps on the same block device.
+
+Fixes dirty-bitmap migration with sync=bitmap, as the bitmaps used for
+that are obviously marked as "busy", which would cause none at all to be
+transferred.
+
+Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
+---
+ migration/block-dirty-bitmap.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/migration/block-dirty-bitmap.c b/migration/block-dirty-bitmap.c
+index c61d382be8..26e4e5c99c 100644
+--- a/migration/block-dirty-bitmap.c
++++ b/migration/block-dirty-bitmap.c
+@@ -534,7 +534,7 @@ static int add_bitmaps_to_list(DBMSaveState *s, BlockDriverState *bs,
+         if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_DEFAULT, &local_err)) {
+             error_report_err(local_err);
+-            return -1;
++            continue;
+         }
+         if (bitmap_aliases) {
diff --git a/debian/patches/pve/0047-PVE-add-zero-block-handling-to-PBS-dump-callback.patch b/debian/patches/pve/0047-PVE-add-zero-block-handling-to-PBS-dump-callback.patch
deleted file mode 100644 (file)
index 3bb6b35..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: Stefan Reiter <s.reiter@proxmox.com>
-Date: Thu, 13 Aug 2020 13:50:27 +0200
-Subject: [PATCH] PVE: add zero block handling to PBS dump callback
-
-Both the PBS and VMA dump callbacks assume that a NULL pointer can be
-passed as *pbuf, but that never happens, as backup-dump.c calls this
-function with contents of an iovec.
-
-So first, remove that assumption and add an 'assert' to verify.
-
-Secondly, while the vma-writer already does the buffer_is_zero check
-internally, for PBS we relied on that non-existant behaviour for zero
-chunks, so do the buffer_is_zero check manually and pass NULL to the
-rust lib in case it is true.
-
-Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
----
- pve-backup.c | 14 +++++++++-----
- 1 file changed, 9 insertions(+), 5 deletions(-)
-
-diff --git a/pve-backup.c b/pve-backup.c
-index 3eba85506a..40c2697b37 100644
---- a/pve-backup.c
-+++ b/pve-backup.c
-@@ -8,6 +8,7 @@
- #include "block/blockjob.h"
- #include "qapi/qapi-commands-block.h"
- #include "qapi/qmp/qerror.h"
-+#include "qemu/cutils.h"
- /* PVE backup state and related function */
-@@ -136,10 +137,13 @@ pvebackup_co_dump_pbs_cb(
-     PVEBackupDevInfo *di = opaque;
-     assert(backup_state.pbs);
-+    assert(buf);
-     Error *local_err = NULL;
-     int pbs_res = -1;
-+    bool is_zero_block = size == di->block_size && buffer_is_zero(buf, size);
-+
-     qemu_co_mutex_lock(&backup_state.dump_callback_mutex);
-     // avoid deadlock if job is cancelled
-@@ -155,7 +159,8 @@ pvebackup_co_dump_pbs_cb(
-         uint64_t to_transfer = left < di->block_size ? left : di->block_size;
-         pbs_res = proxmox_backup_co_write_data(backup_state.pbs, di->dev_id,
--            buf ? buf + transferred : NULL, start + transferred, to_transfer, &local_err);
-+            is_zero_block ? NULL : buf + transferred, start + transferred,
-+            to_transfer, &local_err);
-         transferred += to_transfer;
-         if (pbs_res < 0) {
-@@ -168,7 +173,7 @@ pvebackup_co_dump_pbs_cb(
-     }
-     qemu_co_mutex_unlock(&backup_state.dump_callback_mutex);
--    pvebackup_add_transfered_bytes(size, !buf ? size : 0, reused);
-+    pvebackup_add_transfered_bytes(size, is_zero_block ? size : 0, reused);
-     return size;
- }
-@@ -190,6 +195,7 @@ pvebackup_co_dump_vma_cb(
-     int ret = -1;
-     assert(backup_state.vmaw);
-+    assert(buf);
-     uint64_t remaining = size;
-@@ -216,9 +222,7 @@ pvebackup_co_dump_vma_cb(
-         qemu_co_mutex_unlock(&backup_state.dump_callback_mutex);
-         ++cluster_num;
--        if (buf) {
--            buf += VMA_CLUSTER_SIZE;
--        }
-+        buf += VMA_CLUSTER_SIZE;
-         if (ret < 0) {
-             Error *local_err = NULL;
-             vma_writer_error_propagate(backup_state.vmaw, &local_err);
diff --git a/debian/patches/pve/0047-PVE-fall-back-to-open-iscsi-initiatorname.patch b/debian/patches/pve/0047-PVE-fall-back-to-open-iscsi-initiatorname.patch
new file mode 100644 (file)
index 0000000..f4c4652
--- /dev/null
@@ -0,0 +1,68 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Fabian Ebner <f.ebner@proxmox.com>
+Date: Tue, 17 Nov 2020 10:51:05 +0100
+Subject: [PATCH] PVE: fall back to open-iscsi initiatorname
+
+When no explicit option is given, try reading the initiator name from
+/etc/iscsi/initiatorname.iscsi and only use the generic fallback, i.e.
+iqn.2008-11.org.linux-kvmXXX, as a third alternative.
+
+This avoids the need to add an explicit option for vma and to explicitly set it
+for each call to qemu that deals with iSCSI disks, while still allowing to set
+the option if a different name is needed.
+
+According to RFC 3720, an initiator name is at most 223 bytes long, so the
+4 KiB buffer is big enough, even if many whitespaces are used.
+
+Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
+---
+ block/iscsi.c | 30 ++++++++++++++++++++++++++++++
+ 1 file changed, 30 insertions(+)
+
+diff --git a/block/iscsi.c b/block/iscsi.c
+index e30a7e3606..6c70bbe351 100644
+--- a/block/iscsi.c
++++ b/block/iscsi.c
+@@ -1374,12 +1374,42 @@ static char *get_initiator_name(QemuOpts *opts)
+     const char *name;
+     char *iscsi_name;
+     UuidInfo *uuid_info;
++    FILE *name_fh;
+     name = qemu_opt_get(opts, "initiator-name");
+     if (name) {
+         return g_strdup(name);
+     }
++    name_fh = fopen("/etc/iscsi/initiatorname.iscsi", "r");
++    if (name_fh) {
++        const char *key = "InitiatorName";
++        char buffer[4096];
++        char *line;
++
++        while ((line = fgets(buffer, sizeof(buffer), name_fh))) {
++            line = g_strstrip(line);
++            if (!strncmp(line, key, strlen(key))) {
++                line = strchr(line, '=');
++                if (!line || strlen(line) == 1) {
++                    continue;
++                }
++                line++;
++                g_strstrip(line);
++                if (!strlen(line)) {
++                    continue;
++                }
++                name = line;
++                break;
++            }
++        }
++        fclose(name_fh);
++
++        if (name) {
++            return g_strdup(name);
++        }
++    }
++
+     uuid_info = qmp_query_uuid(NULL);
+     if (strcmp(uuid_info->UUID, UUID_NONE) == 0) {
+         name = qemu_get_vm_name();
diff --git a/debian/patches/pve/0048-PVE-Use-coroutine-QMP-for-backup-cancel_backup.patch b/debian/patches/pve/0048-PVE-Use-coroutine-QMP-for-backup-cancel_backup.patch
new file mode 100644 (file)
index 0000000..a18d478
--- /dev/null
@@ -0,0 +1,597 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Stefan Reiter <s.reiter@proxmox.com>
+Date: Tue, 26 Jan 2021 15:45:30 +0100
+Subject: [PATCH] PVE: Use coroutine QMP for backup/cancel_backup
+
+Finally turn backup QMP calls into coroutines, now that it's possible.
+This has the benefit that calls are asynchronous to the main loop, i.e.
+long running operations like connecting to a PBS server will no longer
+hang the VM.
+
+Additionally, it allows us to get rid of block_on_coroutine_fn, which
+was always a hacky workaround.
+
+While we're already spring cleaning, also remove the QmpBackupTask
+struct, since we can now put the 'prepare' function directly into
+qmp_backup and thus no longer need those giant walls of text.
+
+(Note that for our patches to work with 5.2.0 this change is actually
+required, otherwise monitor_get_fd() fails as we're not in a QMP
+coroutine, but one we start ourselves - we could of course set the
+monitor for that coroutine ourselves, but let's just fix it the right
+way instead)
+
+Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
+---
+ block/monitor/block-hmp-cmds.c |   4 +-
+ hmp-commands.hx                |   2 +
+ proxmox-backup-client.c        |  31 -----
+ pve-backup.c                   | 232 ++++++++++-----------------------
+ qapi/block-core.json           |   4 +-
+ 5 files changed, 77 insertions(+), 196 deletions(-)
+
+diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c
+index 46c63b1cf9..11c84d5508 100644
+--- a/block/monitor/block-hmp-cmds.c
++++ b/block/monitor/block-hmp-cmds.c
+@@ -1013,7 +1013,7 @@ void hmp_info_snapshots(Monitor *mon, const QDict *qdict)
+     g_free(global_snapshots);
+ }
+-void hmp_backup_cancel(Monitor *mon, const QDict *qdict)
++void coroutine_fn hmp_backup_cancel(Monitor *mon, const QDict *qdict)
+ {
+     Error *error = NULL;
+@@ -1022,7 +1022,7 @@ void hmp_backup_cancel(Monitor *mon, const QDict *qdict)
+     hmp_handle_error(mon, error);
+ }
+-void hmp_backup(Monitor *mon, const QDict *qdict)
++void coroutine_fn hmp_backup(Monitor *mon, const QDict *qdict)
+ {
+     Error *error = NULL;
+diff --git a/hmp-commands.hx b/hmp-commands.hx
+index 0c6b944850..54de3f80e6 100644
+--- a/hmp-commands.hx
++++ b/hmp-commands.hx
+@@ -108,6 +108,7 @@ ERST
+                   "\n\t\t\t Use -d to dump data into a directory instead"
+                   "\n\t\t\t of using VMA format.",
+         .cmd = hmp_backup,
++        .coroutine  = true,
+     },
+ SRST
+@@ -121,6 +122,7 @@ ERST
+         .params     = "",
+         .help       = "cancel the current VM backup",
+         .cmd        = hmp_backup_cancel,
++        .coroutine  = true,
+     },
+ SRST
+diff --git a/proxmox-backup-client.c b/proxmox-backup-client.c
+index 4ce7bc0b5e..0923037dec 100644
+--- a/proxmox-backup-client.c
++++ b/proxmox-backup-client.c
+@@ -5,37 +5,6 @@
+ /* Proxmox Backup Server client bindings using coroutines */
+-typedef struct BlockOnCoroutineWrapper {
+-    AioContext *ctx;
+-    CoroutineEntry *entry;
+-    void *entry_arg;
+-    bool finished;
+-} BlockOnCoroutineWrapper;
+-
+-static void coroutine_fn block_on_coroutine_wrapper(void *opaque)
+-{
+-    BlockOnCoroutineWrapper *wrapper = opaque;
+-    wrapper->entry(wrapper->entry_arg);
+-    wrapper->finished = true;
+-    aio_wait_kick();
+-}
+-
+-void block_on_coroutine_fn(CoroutineEntry *entry, void *entry_arg)
+-{
+-    assert(!qemu_in_coroutine());
+-
+-    AioContext *ctx = qemu_get_current_aio_context();
+-    BlockOnCoroutineWrapper wrapper = {
+-        .finished = false,
+-        .entry = entry,
+-        .entry_arg = entry_arg,
+-        .ctx = ctx,
+-    };
+-    Coroutine *wrapper_co = qemu_coroutine_create(block_on_coroutine_wrapper, &wrapper);
+-    aio_co_enter(ctx, wrapper_co);
+-    AIO_WAIT_WHILE(ctx, !wrapper.finished);
+-}
+-
+ // This is called from another thread, so we use aio_co_schedule()
+ static void proxmox_backup_schedule_wake(void *data) {
+     CoCtxData *waker = (CoCtxData *)data;
+diff --git a/pve-backup.c b/pve-backup.c
+index 6b25292ba1..f7597ae55c 100644
+--- a/pve-backup.c
++++ b/pve-backup.c
+@@ -357,7 +357,7 @@ static void job_cancel_bh(void *opaque) {
+     aio_co_enter(data->ctx, data->co);
+ }
+-static void coroutine_fn pvebackup_co_cancel(void *opaque)
++void coroutine_fn qmp_backup_cancel(Error **errp)
+ {
+     Error *cancel_err = NULL;
+     error_setg(&cancel_err, "backup canceled");
+@@ -394,11 +394,6 @@ static void coroutine_fn pvebackup_co_cancel(void *opaque)
+     qemu_co_mutex_unlock(&backup_state.backup_mutex);
+ }
+-void qmp_backup_cancel(Error **errp)
+-{
+-    block_on_coroutine_fn(pvebackup_co_cancel, NULL);
+-}
+-
+ // assumes the caller holds backup_mutex
+ static int coroutine_fn pvebackup_co_add_config(
+     const char *file,
+@@ -531,50 +526,27 @@ static void create_backup_jobs_bh(void *opaque) {
+     aio_co_enter(data->ctx, data->co);
+ }
+-typedef struct QmpBackupTask {
+-    const char *backup_file;
+-    bool has_password;
+-    const char *password;
+-    bool has_keyfile;
+-    const char *keyfile;
+-    bool has_key_password;
+-    const char *key_password;
+-    bool has_backup_id;
+-    const char *backup_id;
+-    bool has_backup_time;
+-    const char *fingerprint;
+-    bool has_fingerprint;
+-    int64_t backup_time;
+-    bool has_use_dirty_bitmap;
+-    bool use_dirty_bitmap;
+-    bool has_format;
+-    BackupFormat format;
+-    bool has_config_file;
+-    const char *config_file;
+-    bool has_firewall_file;
+-    const char *firewall_file;
+-    bool has_devlist;
+-    const char *devlist;
+-    bool has_compress;
+-    bool compress;
+-    bool has_encrypt;
+-    bool encrypt;
+-    bool has_speed;
+-    int64_t speed;
+-    Error **errp;
+-    UuidInfo *result;
+-} QmpBackupTask;
+-
+-static void coroutine_fn pvebackup_co_prepare(void *opaque)
++UuidInfo coroutine_fn *qmp_backup(
++    const char *backup_file,
++    bool has_password, const char *password,
++    bool has_keyfile, const char *keyfile,
++    bool has_key_password, const char *key_password,
++    bool has_fingerprint, const char *fingerprint,
++    bool has_backup_id, const char *backup_id,
++    bool has_backup_time, int64_t backup_time,
++    bool has_use_dirty_bitmap, bool use_dirty_bitmap,
++    bool has_compress, bool compress,
++    bool has_encrypt, bool encrypt,
++    bool has_format, BackupFormat format,
++    bool has_config_file, const char *config_file,
++    bool has_firewall_file, const char *firewall_file,
++    bool has_devlist, const char *devlist,
++    bool has_speed, int64_t speed, Error **errp)
+ {
+     assert(qemu_in_coroutine());
+     qemu_co_mutex_lock(&backup_state.backup_mutex);
+-    QmpBackupTask *task = opaque;
+-
+-    task->result = NULL; // just to be sure
+-
+     BlockBackend *blk;
+     BlockDriverState *bs = NULL;
+     const char *backup_dir = NULL;
+@@ -591,17 +563,17 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+     const char *firewall_name = "qemu-server.fw";
+     if (backup_state.di_list) {
+-        error_set(task->errp, ERROR_CLASS_GENERIC_ERROR,
++        error_set(errp, ERROR_CLASS_GENERIC_ERROR,
+                   "previous backup not finished");
+         qemu_co_mutex_unlock(&backup_state.backup_mutex);
+-        return;
++        return NULL;
+     }
+     /* Todo: try to auto-detect format based on file name */
+-    BackupFormat format = task->has_format ? task->format : BACKUP_FORMAT_VMA;
++    format = has_format ? format : BACKUP_FORMAT_VMA;
+-    if (task->has_devlist) {
+-        devs = g_strsplit_set(task->devlist, ",;:", -1);
++    if (has_devlist) {
++        devs = g_strsplit_set(devlist, ",;:", -1);
+         gchar **d = devs;
+         while (d && *d) {
+@@ -609,14 +581,14 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+             if (blk) {
+                 bs = blk_bs(blk);
+                 if (!bdrv_is_inserted(bs)) {
+-                    error_setg(task->errp, QERR_DEVICE_HAS_NO_MEDIUM, *d);
++                    error_setg(errp, QERR_DEVICE_HAS_NO_MEDIUM, *d);
+                     goto err;
+                 }
+                 PVEBackupDevInfo *di = g_new0(PVEBackupDevInfo, 1);
+                 di->bs = bs;
+                 di_list = g_list_append(di_list, di);
+             } else {
+-                error_set(task->errp, ERROR_CLASS_DEVICE_NOT_FOUND,
++                error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
+                           "Device '%s' not found", *d);
+                 goto err;
+             }
+@@ -639,7 +611,7 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+     }
+     if (!di_list) {
+-        error_set(task->errp, ERROR_CLASS_GENERIC_ERROR, "empty device list");
++        error_set(errp, ERROR_CLASS_GENERIC_ERROR, "empty device list");
+         goto err;
+     }
+@@ -649,13 +621,13 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+     while (l) {
+         PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
+         l = g_list_next(l);
+-        if (bdrv_op_is_blocked(di->bs, BLOCK_OP_TYPE_BACKUP_SOURCE, task->errp)) {
++        if (bdrv_op_is_blocked(di->bs, BLOCK_OP_TYPE_BACKUP_SOURCE, errp)) {
+             goto err;
+         }
+         ssize_t size = bdrv_getlength(di->bs);
+         if (size < 0) {
+-            error_setg_errno(task->errp, -di->size, "bdrv_getlength failed");
++            error_setg_errno(errp, -di->size, "bdrv_getlength failed");
+             goto err;
+         }
+         di->size = size;
+@@ -682,47 +654,44 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+     }
+     if (format == BACKUP_FORMAT_PBS) {
+-        if (!task->has_password) {
+-            error_set(task->errp, ERROR_CLASS_GENERIC_ERROR, "missing parameter 'password'");
++        if (!has_password) {
++            error_set(errp, ERROR_CLASS_GENERIC_ERROR, "missing parameter 'password'");
+             goto err_mutex;
+         }
+-        if (!task->has_backup_id) {
+-            error_set(task->errp, ERROR_CLASS_GENERIC_ERROR, "missing parameter 'backup-id'");
++        if (!has_backup_id) {
++            error_set(errp, ERROR_CLASS_GENERIC_ERROR, "missing parameter 'backup-id'");
+             goto err_mutex;
+         }
+-        if (!task->has_backup_time) {
+-            error_set(task->errp, ERROR_CLASS_GENERIC_ERROR, "missing parameter 'backup-time'");
++        if (!has_backup_time) {
++            error_set(errp, ERROR_CLASS_GENERIC_ERROR, "missing parameter 'backup-time'");
+             goto err_mutex;
+         }
+         int dump_cb_block_size = PROXMOX_BACKUP_DEFAULT_CHUNK_SIZE; // Hardcoded (4M)
+         firewall_name = "fw.conf";
+-        bool use_dirty_bitmap = task->has_use_dirty_bitmap && task->use_dirty_bitmap;
+-
+-
+         char *pbs_err = NULL;
+         pbs = proxmox_backup_new(
+-            task->backup_file,
+-            task->backup_id,
+-            task->backup_time,
++            backup_file,
++            backup_id,
++            backup_time,
+             dump_cb_block_size,
+-            task->has_password ? task->password : NULL,
+-            task->has_keyfile ? task->keyfile : NULL,
+-            task->has_key_password ? task->key_password : NULL,
+-            task->has_compress ? task->compress : true,
+-            task->has_encrypt ? task->encrypt : task->has_keyfile,
+-            task->has_fingerprint ? task->fingerprint : NULL,
++            has_password ? password : NULL,
++            has_keyfile ? keyfile : NULL,
++            has_key_password ? key_password : NULL,
++            has_compress ? compress : true,
++            has_encrypt ? encrypt : has_keyfile,
++            has_fingerprint ? fingerprint : NULL,
+              &pbs_err);
+         if (!pbs) {
+-            error_set(task->errp, ERROR_CLASS_GENERIC_ERROR,
++            error_set(errp, ERROR_CLASS_GENERIC_ERROR,
+                       "proxmox_backup_new failed: %s", pbs_err);
+             proxmox_backup_free_error(pbs_err);
+             goto err_mutex;
+         }
+-        int connect_result = proxmox_backup_co_connect(pbs, task->errp);
++        int connect_result = proxmox_backup_co_connect(pbs, errp);
+         if (connect_result < 0)
+             goto err_mutex;
+@@ -741,9 +710,9 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+             BdrvDirtyBitmap *bitmap = bdrv_find_dirty_bitmap(di->bs, PBS_BITMAP_NAME);
+             bool expect_only_dirty = false;
+-            if (use_dirty_bitmap) {
++            if (has_use_dirty_bitmap && use_dirty_bitmap) {
+                 if (bitmap == NULL) {
+-                    bitmap = bdrv_create_dirty_bitmap(di->bs, dump_cb_block_size, PBS_BITMAP_NAME, task->errp);
++                    bitmap = bdrv_create_dirty_bitmap(di->bs, dump_cb_block_size, PBS_BITMAP_NAME, errp);
+                     if (!bitmap) {
+                         goto err_mutex;
+                     }
+@@ -773,12 +742,12 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+                 }
+             }
+-            int dev_id = proxmox_backup_co_register_image(pbs, devname, di->size, expect_only_dirty, task->errp);
++            int dev_id = proxmox_backup_co_register_image(pbs, devname, di->size, expect_only_dirty, errp);
+             if (dev_id < 0) {
+                 goto err_mutex;
+             }
+-            if (!(di->target = bdrv_backup_dump_create(dump_cb_block_size, di->size, pvebackup_co_dump_pbs_cb, di, task->errp))) {
++            if (!(di->target = bdrv_backup_dump_create(dump_cb_block_size, di->size, pvebackup_co_dump_pbs_cb, di, errp))) {
+                 goto err_mutex;
+             }
+@@ -792,10 +761,10 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+             backup_state.stat.bitmap_list = g_list_append(backup_state.stat.bitmap_list, info);
+         }
+     } else if (format == BACKUP_FORMAT_VMA) {
+-        vmaw = vma_writer_create(task->backup_file, uuid, &local_err);
++        vmaw = vma_writer_create(backup_file, uuid, &local_err);
+         if (!vmaw) {
+             if (local_err) {
+-                error_propagate(task->errp, local_err);
++                error_propagate(errp, local_err);
+             }
+             goto err_mutex;
+         }
+@@ -806,25 +775,25 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+             PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
+             l = g_list_next(l);
+-            if (!(di->target = bdrv_backup_dump_create(VMA_CLUSTER_SIZE, di->size, pvebackup_co_dump_vma_cb, di, task->errp))) {
++            if (!(di->target = bdrv_backup_dump_create(VMA_CLUSTER_SIZE, di->size, pvebackup_co_dump_vma_cb, di, errp))) {
+                 goto err_mutex;
+             }
+             const char *devname = bdrv_get_device_name(di->bs);
+             di->dev_id = vma_writer_register_stream(vmaw, devname, di->size);
+             if (di->dev_id <= 0) {
+-                error_set(task->errp, ERROR_CLASS_GENERIC_ERROR,
++                error_set(errp, ERROR_CLASS_GENERIC_ERROR,
+                           "register_stream failed");
+                 goto err_mutex;
+             }
+         }
+     } else if (format == BACKUP_FORMAT_DIR) {
+-        if (mkdir(task->backup_file, 0640) != 0) {
+-            error_setg_errno(task->errp, errno, "can't create directory '%s'\n",
+-                             task->backup_file);
++        if (mkdir(backup_file, 0640) != 0) {
++            error_setg_errno(errp, errno, "can't create directory '%s'\n",
++                             backup_file);
+             goto err_mutex;
+         }
+-        backup_dir = task->backup_file;
++        backup_dir = backup_file;
+         l = di_list;
+         while (l) {
+@@ -838,34 +807,34 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+             bdrv_img_create(di->targetfile, "raw", NULL, NULL, NULL,
+                             di->size, flags, false, &local_err);
+             if (local_err) {
+-                error_propagate(task->errp, local_err);
++                error_propagate(errp, local_err);
+                 goto err_mutex;
+             }
+             di->target = bdrv_open(di->targetfile, NULL, NULL, flags, &local_err);
+             if (!di->target) {
+-                error_propagate(task->errp, local_err);
++                error_propagate(errp, local_err);
+                 goto err_mutex;
+             }
+         }
+     } else {
+-        error_set(task->errp, ERROR_CLASS_GENERIC_ERROR, "unknown backup format");
++        error_set(errp, ERROR_CLASS_GENERIC_ERROR, "unknown backup format");
+         goto err_mutex;
+     }
+     /* add configuration file to archive */
+-    if (task->has_config_file) {
+-        if (pvebackup_co_add_config(task->config_file, config_name, format, backup_dir,
+-                                    vmaw, pbs, task->errp) != 0) {
++    if (has_config_file) {
++        if (pvebackup_co_add_config(config_file, config_name, format, backup_dir,
++                                    vmaw, pbs, errp) != 0) {
+             goto err_mutex;
+         }
+     }
+     /* add firewall file to archive */
+-    if (task->has_firewall_file) {
+-        if (pvebackup_co_add_config(task->firewall_file, firewall_name, format, backup_dir,
+-                                    vmaw, pbs, task->errp) != 0) {
++    if (has_firewall_file) {
++        if (pvebackup_co_add_config(firewall_file, firewall_name, format, backup_dir,
++                                    vmaw, pbs, errp) != 0) {
+             goto err_mutex;
+         }
+     }
+@@ -883,7 +852,7 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+     if (backup_state.stat.backup_file) {
+         g_free(backup_state.stat.backup_file);
+     }
+-    backup_state.stat.backup_file = g_strdup(task->backup_file);
++    backup_state.stat.backup_file = g_strdup(backup_file);
+     uuid_copy(backup_state.stat.uuid, uuid);
+     uuid_unparse_lower(uuid, backup_state.stat.uuid_str);
+@@ -898,7 +867,7 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+     qemu_mutex_unlock(&backup_state.stat.lock);
+-    backup_state.speed = (task->has_speed && task->speed > 0) ? task->speed : 0;
++    backup_state.speed = (has_speed && speed > 0) ? speed : 0;
+     backup_state.vmaw = vmaw;
+     backup_state.pbs = pbs;
+@@ -908,8 +877,6 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+     uuid_info = g_malloc0(sizeof(*uuid_info));
+     uuid_info->UUID = uuid_str;
+-    task->result = uuid_info;
+-
+     /* Run create_backup_jobs_bh outside of coroutine (in BH) but keep
+     * backup_mutex locked. This is fine, a CoMutex can be held across yield
+     * points, and we'll release it as soon as the BH reschedules us.
+@@ -923,7 +890,7 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+     qemu_coroutine_yield();
+     if (local_err) {
+-        error_propagate(task->errp, local_err);
++        error_propagate(errp, local_err);
+         goto err;
+     }
+@@ -936,7 +903,7 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
+     /* start the first job in the transaction */
+     job_txn_start_seq(backup_state.txn);
+-    return;
++    return uuid_info;
+ err_mutex:
+     qemu_mutex_unlock(&backup_state.stat.lock);
+@@ -967,7 +934,7 @@ err:
+     if (vmaw) {
+         Error *err = NULL;
+         vma_writer_close(vmaw, &err);
+-        unlink(task->backup_file);
++        unlink(backup_file);
+     }
+     if (pbs) {
+@@ -978,65 +945,8 @@ err:
+         rmdir(backup_dir);
+     }
+-    task->result = NULL;
+-
+     qemu_co_mutex_unlock(&backup_state.backup_mutex);
+-    return;
+-}
+-
+-UuidInfo *qmp_backup(
+-    const char *backup_file,
+-    bool has_password, const char *password,
+-    bool has_keyfile, const char *keyfile,
+-    bool has_key_password, const char *key_password,
+-    bool has_fingerprint, const char *fingerprint,
+-    bool has_backup_id, const char *backup_id,
+-    bool has_backup_time, int64_t backup_time,
+-    bool has_use_dirty_bitmap, bool use_dirty_bitmap,
+-    bool has_compress, bool compress,
+-    bool has_encrypt, bool encrypt,
+-    bool has_format, BackupFormat format,
+-    bool has_config_file, const char *config_file,
+-    bool has_firewall_file, const char *firewall_file,
+-    bool has_devlist, const char *devlist,
+-    bool has_speed, int64_t speed, Error **errp)
+-{
+-    QmpBackupTask task = {
+-        .backup_file = backup_file,
+-        .has_password = has_password,
+-        .password = password,
+-        .has_keyfile = has_keyfile,
+-        .keyfile = keyfile,
+-        .has_key_password = has_key_password,
+-        .key_password = key_password,
+-        .has_fingerprint = has_fingerprint,
+-        .fingerprint = fingerprint,
+-        .has_backup_id = has_backup_id,
+-        .backup_id = backup_id,
+-        .has_backup_time = has_backup_time,
+-        .backup_time = backup_time,
+-        .has_use_dirty_bitmap = has_use_dirty_bitmap,
+-        .use_dirty_bitmap = use_dirty_bitmap,
+-        .has_compress = has_compress,
+-        .compress = compress,
+-        .has_encrypt = has_encrypt,
+-        .encrypt = encrypt,
+-        .has_format = has_format,
+-        .format = format,
+-        .has_config_file = has_config_file,
+-        .config_file = config_file,
+-        .has_firewall_file = has_firewall_file,
+-        .firewall_file = firewall_file,
+-        .has_devlist = has_devlist,
+-        .devlist = devlist,
+-        .has_speed = has_speed,
+-        .speed = speed,
+-        .errp = errp,
+-    };
+-
+-    block_on_coroutine_fn(pvebackup_co_prepare, &task);
+-
+-    return task.result;
++    return NULL;
+ }
+ BackupStatus *qmp_query_backup(Error **errp)
+diff --git a/qapi/block-core.json b/qapi/block-core.json
+index dee3d87efe..82133e2bee 100644
+--- a/qapi/block-core.json
++++ b/qapi/block-core.json
+@@ -847,7 +847,7 @@
+                                     '*config-file': 'str',
+                                     '*firewall-file': 'str',
+                                     '*devlist': 'str', '*speed': 'int' },
+-  'returns': 'UuidInfo' }
++  'returns': 'UuidInfo', 'coroutine': true }
+ ##
+ # @query-backup:
+@@ -869,7 +869,7 @@
+ # Notes: This command succeeds even if there is no backup process running.
+ #
+ ##
+-{ 'command': 'backup-cancel' }
++{ 'command': 'backup-cancel', 'coroutine': true }
+ ##
+ # @ProxmoxSupportStatus:
diff --git a/debian/patches/pve/0048-PVE-add-query-pbs-bitmap-info-QMP-call.patch b/debian/patches/pve/0048-PVE-add-query-pbs-bitmap-info-QMP-call.patch
deleted file mode 100644 (file)
index 828bf4e..0000000
+++ /dev/null
@@ -1,437 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: Stefan Reiter <s.reiter@proxmox.com>
-Date: Wed, 19 Aug 2020 17:02:00 +0200
-Subject: [PATCH] PVE: add query-pbs-bitmap-info QMP call
-
-Returns advanced information about dirty bitmaps used (or not used) for
-the latest PBS backup.
-
-Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
----
- monitor/hmp-cmds.c   |  28 ++++++-----
- pve-backup.c         | 117 ++++++++++++++++++++++++++++++++-----------
- qapi/block-core.json |  56 +++++++++++++++++++++
- 3 files changed, 159 insertions(+), 42 deletions(-)
-
-diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
-index 604026bb37..95f4e7f5c1 100644
---- a/monitor/hmp-cmds.c
-+++ b/monitor/hmp-cmds.c
-@@ -198,6 +198,7 @@ void hmp_info_mice(Monitor *mon, const QDict *qdict)
- void hmp_info_backup(Monitor *mon, const QDict *qdict)
- {
-     BackupStatus *info;
-+    PBSBitmapInfoList *bitmap_info;
-     info = qmp_query_backup(NULL);
-@@ -228,26 +229,29 @@ void hmp_info_backup(Monitor *mon, const QDict *qdict)
-             // this should not happen normally
-             monitor_printf(mon, "Total size: %d\n", 0);
-         } else {
--            bool incremental = false;
-             size_t total_or_dirty = info->total;
--            if (info->has_transferred) {
--                if (info->has_dirty && info->dirty) {
--                     if (info->dirty < info->total) {
--                        total_or_dirty = info->dirty;
--                        incremental = true;
--                    }
--                }
-+            bitmap_info = qmp_query_pbs_bitmap_info(NULL);
-+
-+            while (bitmap_info) {
-+                monitor_printf(mon, "Drive %s:\n",
-+                        bitmap_info->value->drive);
-+                monitor_printf(mon, "  bitmap action: %s\n",
-+                        PBSBitmapAction_str(bitmap_info->value->action));
-+                monitor_printf(mon, "  size: %zd\n",
-+                        bitmap_info->value->size);
-+                monitor_printf(mon, "  dirty: %zd\n",
-+                        bitmap_info->value->dirty);
-+                bitmap_info = bitmap_info->next;
-             }
--            int per = (info->transferred * 100)/total_or_dirty;
--
--            monitor_printf(mon, "Backup mode: %s\n", incremental ? "incremental" : "full");
-+            qapi_free_PBSBitmapInfoList(bitmap_info);
-             int zero_per = (info->has_zero_bytes && info->zero_bytes) ?
-                 (info->zero_bytes * 100)/info->total : 0;
-             monitor_printf(mon, "Total size: %zd\n", info->total);
-+            int trans_per = (info->transferred * 100)/total_or_dirty;
-             monitor_printf(mon, "Transferred bytes: %zd (%d%%)\n",
--                           info->transferred, per);
-+                           info->transferred, trans_per);
-             monitor_printf(mon, "Zero bytes: %zd (%d%%)\n",
-                            info->zero_bytes, zero_per);
-diff --git a/pve-backup.c b/pve-backup.c
-index 40c2697b37..1e7b92a950 100644
---- a/pve-backup.c
-+++ b/pve-backup.c
-@@ -46,6 +46,7 @@ static struct PVEBackupState {
-         size_t transferred;
-         size_t reused;
-         size_t zero_bytes;
-+        GList *bitmap_list;
-     } stat;
-     int64_t speed;
-     VmaWriter *vmaw;
-@@ -670,7 +671,6 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-     }
-     size_t total = 0;
--    size_t dirty = 0;
-     l = di_list;
-     while (l) {
-@@ -691,18 +691,33 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-     uuid_generate(uuid);
-+    qemu_mutex_lock(&backup_state.stat.lock);
-+    backup_state.stat.reused = 0;
-+
-+    /* clear previous backup's bitmap_list */
-+    if (backup_state.stat.bitmap_list) {
-+        GList *bl = backup_state.stat.bitmap_list;
-+        while (bl) {
-+            g_free(((PBSBitmapInfo *)bl->data)->drive);
-+            g_free(bl->data);
-+            bl = g_list_next(bl);
-+        }
-+        g_list_free(backup_state.stat.bitmap_list);
-+        backup_state.stat.bitmap_list = NULL;
-+    }
-+
-     if (format == BACKUP_FORMAT_PBS) {
-         if (!task->has_password) {
-             error_set(task->errp, ERROR_CLASS_GENERIC_ERROR, "missing parameter 'password'");
--            goto err;
-+            goto err_mutex;
-         }
-         if (!task->has_backup_id) {
-             error_set(task->errp, ERROR_CLASS_GENERIC_ERROR, "missing parameter 'backup-id'");
--            goto err;
-+            goto err_mutex;
-         }
-         if (!task->has_backup_time) {
-             error_set(task->errp, ERROR_CLASS_GENERIC_ERROR, "missing parameter 'backup-time'");
--            goto err;
-+            goto err_mutex;
-         }
-         int dump_cb_block_size = PROXMOX_BACKUP_DEFAULT_CHUNK_SIZE; // Hardcoded (4M)
-@@ -729,12 +744,12 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-             error_set(task->errp, ERROR_CLASS_GENERIC_ERROR,
-                       "proxmox_backup_new failed: %s", pbs_err);
-             proxmox_backup_free_error(pbs_err);
--            goto err;
-+            goto err_mutex;
-         }
-         int connect_result = proxmox_backup_co_connect(pbs, task->errp);
-         if (connect_result < 0)
--            goto err;
-+            goto err_mutex;
-         /* register all devices */
-         l = di_list;
-@@ -745,6 +760,8 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-             di->block_size = dump_cb_block_size;
-             const char *devname = bdrv_get_device_name(di->bs);
-+            PBSBitmapAction action = PBS_BITMAP_ACTION_NOT_USED;
-+            size_t dirty = di->size;
-             BdrvDirtyBitmap *bitmap = bdrv_find_dirty_bitmap(di->bs, PBS_BITMAP_NAME);
-             bool expect_only_dirty = false;
-@@ -753,49 +770,59 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-                 if (bitmap == NULL) {
-                     bitmap = bdrv_create_dirty_bitmap(di->bs, dump_cb_block_size, PBS_BITMAP_NAME, task->errp);
-                     if (!bitmap) {
--                        goto err;
-+                        goto err_mutex;
-                     }
-+                    action = PBS_BITMAP_ACTION_NEW;
-                 } else {
-                     expect_only_dirty = proxmox_backup_check_incremental(pbs, devname, di->size) != 0;
-                 }
-                 if (expect_only_dirty) {
--                    dirty += bdrv_get_dirty_count(bitmap);
-+                    /* track clean chunks as reused */
-+                    dirty = MIN(bdrv_get_dirty_count(bitmap), di->size);
-+                    backup_state.stat.reused += di->size - dirty;
-+                    action = PBS_BITMAP_ACTION_USED;
-                 } else {
-                     /* mark entire bitmap as dirty to make full backup */
-                     bdrv_set_dirty_bitmap(bitmap, 0, di->size);
--                    dirty += di->size;
-+                    if (action != PBS_BITMAP_ACTION_NEW) {
-+                        action = PBS_BITMAP_ACTION_INVALID;
-+                    }
-                 }
-                 di->bitmap = bitmap;
-             } else {
--                dirty += di->size;
--
-                 /* after a full backup the old dirty bitmap is invalid anyway */
-                 if (bitmap != NULL) {
-                     bdrv_release_dirty_bitmap(bitmap);
-+                    action = PBS_BITMAP_ACTION_NOT_USED_REMOVED;
-                 }
-             }
-             int dev_id = proxmox_backup_co_register_image(pbs, devname, di->size, expect_only_dirty, task->errp);
-             if (dev_id < 0) {
--                goto err;
-+                goto err_mutex;
-             }
-             if (!(di->target = bdrv_backup_dump_create(dump_cb_block_size, di->size, pvebackup_co_dump_pbs_cb, di, task->errp))) {
--                goto err;
-+                goto err_mutex;
-             }
-             di->dev_id = dev_id;
-+
-+            PBSBitmapInfo *info = g_malloc(sizeof(*info));
-+            info->drive = g_strdup(devname);
-+            info->action = action;
-+            info->size = di->size;
-+            info->dirty = dirty;
-+            backup_state.stat.bitmap_list = g_list_append(backup_state.stat.bitmap_list, info);
-         }
-     } else if (format == BACKUP_FORMAT_VMA) {
--        dirty = total;
--
-         vmaw = vma_writer_create(task->backup_file, uuid, &local_err);
-         if (!vmaw) {
-             if (local_err) {
-                 error_propagate(task->errp, local_err);
-             }
--            goto err;
-+            goto err_mutex;
-         }
-         /* register all devices for vma writer */
-@@ -805,7 +832,7 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-             l = g_list_next(l);
-             if (!(di->target = bdrv_backup_dump_create(VMA_CLUSTER_SIZE, di->size, pvebackup_co_dump_vma_cb, di, task->errp))) {
--                goto err;
-+                goto err_mutex;
-             }
-             const char *devname = bdrv_get_device_name(di->bs);
-@@ -813,16 +840,14 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-             if (di->dev_id <= 0) {
-                 error_set(task->errp, ERROR_CLASS_GENERIC_ERROR,
-                           "register_stream failed");
--                goto err;
-+                goto err_mutex;
-             }
-         }
-     } else if (format == BACKUP_FORMAT_DIR) {
--        dirty = total;
--
-         if (mkdir(task->backup_file, 0640) != 0) {
-             error_setg_errno(task->errp, errno, "can't create directory '%s'\n",
-                              task->backup_file);
--            goto err;
-+            goto err_mutex;
-         }
-         backup_dir = task->backup_file;
-@@ -839,18 +864,18 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-                             di->size, flags, false, &local_err);
-             if (local_err) {
-                 error_propagate(task->errp, local_err);
--                goto err;
-+                goto err_mutex;
-             }
-             di->target = bdrv_open(di->targetfile, NULL, NULL, flags, &local_err);
-             if (!di->target) {
-                 error_propagate(task->errp, local_err);
--                goto err;
-+                goto err_mutex;
-             }
-         }
-     } else {
-         error_set(task->errp, ERROR_CLASS_GENERIC_ERROR, "unknown backup format");
--        goto err;
-+        goto err_mutex;
-     }
-@@ -858,7 +883,7 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-     if (task->has_config_file) {
-         if (pvebackup_co_add_config(task->config_file, config_name, format, backup_dir,
-                                     vmaw, pbs, task->errp) != 0) {
--            goto err;
-+            goto err_mutex;
-         }
-     }
-@@ -866,12 +891,11 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-     if (task->has_firewall_file) {
-         if (pvebackup_co_add_config(task->firewall_file, firewall_name, format, backup_dir,
-                                     vmaw, pbs, task->errp) != 0) {
--            goto err;
-+            goto err_mutex;
-         }
-     }
-     /* initialize global backup_state now */
--
--    qemu_mutex_lock(&backup_state.stat.lock);
-+    /* note: 'reused' and 'bitmap_list' are initialized earlier */
-     if (backup_state.stat.error) {
-         error_free(backup_state.stat.error);
-@@ -891,10 +915,9 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-     char *uuid_str = g_strdup(backup_state.stat.uuid_str);
-     backup_state.stat.total = total;
--    backup_state.stat.dirty = dirty;
-+    backup_state.stat.dirty = total - backup_state.stat.reused;
-     backup_state.stat.transferred = 0;
-     backup_state.stat.zero_bytes = 0;
--    backup_state.stat.reused = format == BACKUP_FORMAT_PBS && dirty >= total ? 0 : total - dirty;
-     qemu_mutex_unlock(&backup_state.stat.lock);
-@@ -911,6 +934,9 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-     task->result = uuid_info;
-     return;
-+err_mutex:
-+    qemu_mutex_unlock(&backup_state.stat.lock);
-+
- err:
-     l = di_list;
-@@ -1074,10 +1100,41 @@ BackupStatus *qmp_query_backup(Error **errp)
-     return info;
- }
-+PBSBitmapInfoList *qmp_query_pbs_bitmap_info(Error **errp)
-+{
-+    PBSBitmapInfoList *head = NULL, **p_next = &head;
-+
-+    qemu_mutex_lock(&backup_state.stat.lock);
-+
-+    GList *l = backup_state.stat.bitmap_list;
-+    while (l) {
-+        PBSBitmapInfo *info = (PBSBitmapInfo *)l->data;
-+        l = g_list_next(l);
-+
-+        /* clone bitmap info to avoid auto free after QMP marshalling */
-+        PBSBitmapInfo *info_ret = g_malloc0(sizeof(*info_ret));
-+        info_ret->drive = g_strdup(info->drive);
-+        info_ret->action = info->action;
-+        info_ret->size = info->size;
-+        info_ret->dirty = info->dirty;
-+
-+        PBSBitmapInfoList *info_list = g_malloc0(sizeof(*info_list));
-+        info_list->value = info_ret;
-+
-+        *p_next = info_list;
-+        p_next = &info_list->next;
-+    }
-+
-+    qemu_mutex_unlock(&backup_state.stat.lock);
-+
-+    return head;
-+}
-+
- ProxmoxSupportStatus *qmp_query_proxmox_support(Error **errp)
- {
-     ProxmoxSupportStatus *ret = g_malloc0(sizeof(*ret));
-     ret->pbs_library_version = g_strdup(proxmox_backup_qemu_version());
-     ret->pbs_dirty_bitmap = true;
-+    ret->query_bitmap_info = true;
-     return ret;
- }
-diff --git a/qapi/block-core.json b/qapi/block-core.json
-index e0a0a60354..b368371e8e 100644
---- a/qapi/block-core.json
-+++ b/qapi/block-core.json
-@@ -876,11 +876,14 @@
- # @pbs-dirty-bitmap: True if dirty-bitmap-incremental backups to PBS are
- #                    supported.
- #
-+# @query-bitmap-info: True if the 'query-pbs-bitmap-info' QMP call is supported.
-+#
- # @pbs-library-version: Running version of libproxmox-backup-qemu0 library.
- #
- ##
- { 'struct': 'ProxmoxSupportStatus',
-   'data': { 'pbs-dirty-bitmap': 'bool',
-+            'query-bitmap-info': 'bool',
-             'pbs-library-version': 'str' } }
- ##
-@@ -893,6 +896,59 @@
- ##
- { 'command': 'query-proxmox-support', 'returns': 'ProxmoxSupportStatus' }
-+##
-+# @PBSBitmapAction:
-+#
-+# An action taken on a dirty-bitmap when a backup job was started.
-+#
-+# @not-used: Bitmap mode was not enabled.
-+#
-+# @not-used-removed: Bitmap mode was not enabled, but a bitmap from a
-+#                    previous backup still existed and was removed.
-+#
-+# @new: A new bitmap was attached to the drive for this backup.
-+#
-+# @used: An existing bitmap will be used to only backup changed data.
-+#
-+# @invalid: A bitmap existed, but had to be cleared since it's associated
-+#           base snapshot did not match the base given for the current job or
-+#           the crypt mode has changed.
-+#
-+##
-+{ 'enum': 'PBSBitmapAction',
-+  'data': ['not-used', 'not-used-removed', 'new', 'used', 'invalid'] }
-+
-+##
-+# @PBSBitmapInfo:
-+#
-+# Contains information about dirty bitmaps used for each drive in a PBS backup.
-+#
-+# @drive: The underlying drive.
-+#
-+# @action: The action that was taken when the backup started.
-+#
-+# @size: The total size of the drive.
-+#
-+# @dirty: How much of the drive is considered dirty and will be backed up,
-+#         or 'size' if everything will be.
-+#
-+##
-+{ 'struct': 'PBSBitmapInfo',
-+  'data': { 'drive': 'str', 'action': 'PBSBitmapAction', 'size': 'int',
-+            'dirty': 'int' } }
-+
-+##
-+# @query-pbs-bitmap-info:
-+#
-+# Returns information about dirty bitmaps used on the most recently started
-+# backup. Returns nothing when the last backup was not using PBS or if no
-+# backup occured in this session.
-+#
-+# Returns: @PBSBitmapInfo
-+#
-+##
-+{ 'command': 'query-pbs-bitmap-info', 'returns': ['PBSBitmapInfo'] }
-+
- ##
- # @BlockDeviceTimedStats:
- #
diff --git a/debian/patches/pve/0049-PBS-add-master-key-support.patch b/debian/patches/pve/0049-PBS-add-master-key-support.patch
new file mode 100644 (file)
index 0000000..52e600c
--- /dev/null
@@ -0,0 +1,97 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Stefan Reiter <s.reiter@proxmox.com>
+Date: Wed, 10 Feb 2021 11:07:06 +0100
+Subject: [PATCH] PBS: add master key support
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+this requires a new enough libproxmox-backup-qemu0, and allows querying
+from the PVE side to avoid QMP calls with unsupported parameters.
+
+Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
+Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
+---
+ block/monitor/block-hmp-cmds.c | 1 +
+ pve-backup.c                   | 3 +++
+ qapi/block-core.json           | 7 +++++++
+ 3 files changed, 11 insertions(+)
+
+diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c
+index 11c84d5508..0932deb28c 100644
+--- a/block/monitor/block-hmp-cmds.c
++++ b/block/monitor/block-hmp-cmds.c
+@@ -1036,6 +1036,7 @@ void coroutine_fn hmp_backup(Monitor *mon, const QDict *qdict)
+         false, NULL, // PBS password
+         false, NULL, // PBS keyfile
+         false, NULL, // PBS key_password
++        false, NULL, // PBS master_keyfile
+         false, NULL, // PBS fingerprint
+         false, NULL, // PBS backup-id
+         false, 0, // PBS backup-time
+diff --git a/pve-backup.c b/pve-backup.c
+index f7597ae55c..0ecadf6ce6 100644
+--- a/pve-backup.c
++++ b/pve-backup.c
+@@ -531,6 +531,7 @@ UuidInfo coroutine_fn *qmp_backup(
+     bool has_password, const char *password,
+     bool has_keyfile, const char *keyfile,
+     bool has_key_password, const char *key_password,
++    bool has_master_keyfile, const char *master_keyfile,
+     bool has_fingerprint, const char *fingerprint,
+     bool has_backup_id, const char *backup_id,
+     bool has_backup_time, int64_t backup_time,
+@@ -679,6 +680,7 @@ UuidInfo coroutine_fn *qmp_backup(
+             has_password ? password : NULL,
+             has_keyfile ? keyfile : NULL,
+             has_key_password ? key_password : NULL,
++            has_master_keyfile ? master_keyfile : NULL,
+             has_compress ? compress : true,
+             has_encrypt ? encrypt : has_keyfile,
+             has_fingerprint ? fingerprint : NULL,
+@@ -1041,5 +1043,6 @@ ProxmoxSupportStatus *qmp_query_proxmox_support(Error **errp)
+     ret->pbs_dirty_bitmap = true;
+     ret->query_bitmap_info = true;
+     ret->pbs_dirty_bitmap_migration = true;
++    ret->pbs_masterkey = true;
+     return ret;
+ }
+diff --git a/qapi/block-core.json b/qapi/block-core.json
+index 82133e2bee..be3d6a0d37 100644
+--- a/qapi/block-core.json
++++ b/qapi/block-core.json
+@@ -818,6 +818,8 @@
+ #
+ # @key-password: password for keyfile (optional for format 'pbs')
+ #
++# @master-keyfile: PEM-formatted master public keyfile (optional for format 'pbs')
++#
+ # @fingerprint: server cert fingerprint (optional for format 'pbs')
+ #
+ # @backup-id: backup ID (required for format 'pbs')
+@@ -837,6 +839,7 @@
+                                     '*password': 'str',
+                                     '*keyfile': 'str',
+                                     '*key-password': 'str',
++                                    '*master-keyfile': 'str',
+                                     '*fingerprint': 'str',
+                                     '*backup-id': 'str',
+                                     '*backup-time': 'int',
+@@ -886,6 +889,9 @@
+ #                              migration cap if this is false/unset may lead
+ #                              to crashes on migration!
+ #
++# @pbs-masterkey: True if the QMP backup call supports the 'master_keyfile'
++#                 parameter.
++#
+ # @pbs-library-version: Running version of libproxmox-backup-qemu0 library.
+ #
+ ##
+@@ -893,6 +899,7 @@
+   'data': { 'pbs-dirty-bitmap': 'bool',
+             'query-bitmap-info': 'bool',
+             'pbs-dirty-bitmap-migration': 'bool',
++            'pbs-masterkey': 'bool',
+             'pbs-library-version': 'str' } }
+ ##
diff --git a/debian/patches/pve/0049-PVE-redirect-stderr-to-journal-when-daemonized.patch b/debian/patches/pve/0049-PVE-redirect-stderr-to-journal-when-daemonized.patch
deleted file mode 100644 (file)
index 7fb3c4f..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: Stefan Reiter <s.reiter@proxmox.com>
-Date: Tue, 12 Jan 2021 14:12:20 +0100
-Subject: [PATCH] PVE: redirect stderr to journal when daemonized
-
-QEMU uses the logging for error messages usually, so LOG_ERR is most
-fitting.
-
-Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
----
- meson.build | 2 ++
- os-posix.c  | 7 +++++--
- 2 files changed, 7 insertions(+), 2 deletions(-)
-
-diff --git a/meson.build b/meson.build
-index 4d156d35ce..737ea9e5d7 100644
---- a/meson.build
-+++ b/meson.build
-@@ -726,6 +726,7 @@ keyutils = dependency('libkeyutils', required: false,
- has_gettid = cc.has_function('gettid')
- libuuid = cc.find_library('uuid', required: true)
-+libsystemd = cc.find_library('systemd', required: true)
- libproxmox_backup_qemu = cc.find_library('proxmox_backup_qemu', required: true)
- # Malloc tests
-@@ -1539,6 +1540,7 @@ blockdev_ss.add(files(
- # os-posix.c contains POSIX-specific functions used by qemu-storage-daemon,
- # os-win32.c does not
- blockdev_ss.add(when: 'CONFIG_POSIX', if_true: files('os-posix.c'))
-+blockdev_ss.add(when: 'CONFIG_POSIX', if_true: libsystemd)
- softmmu_ss.add(when: 'CONFIG_WIN32', if_true: [files('os-win32.c')])
- common_ss.add(files('cpus-common.c'))
-diff --git a/os-posix.c b/os-posix.c
-index 1de2839554..ac4f652923 100644
---- a/os-posix.c
-+++ b/os-posix.c
-@@ -28,6 +28,8 @@
- #include <pwd.h>
- #include <grp.h>
- #include <libgen.h>
-+#include <systemd/sd-journal.h>
-+#include <syslog.h>
- #include "qemu-common.h"
- /* Needed early for CONFIG_BSD etc. */
-@@ -288,9 +290,10 @@ void os_setup_post(void)
-         dup2(fd, 0);
-         dup2(fd, 1);
--        /* In case -D is given do not redirect stderr to /dev/null */
-+        /* In case -D is given do not redirect stderr to journal */
-         if (!qemu_logfile) {
--            dup2(fd, 2);
-+            int journal_fd = sd_journal_stream_fd("QEMU", LOG_ERR, 0);
-+            dup2(journal_fd, 2);
-         }
-         close(fd);
diff --git a/debian/patches/pve/0050-PVE-Add-sequential-job-transaction-support.patch b/debian/patches/pve/0050-PVE-Add-sequential-job-transaction-support.patch
deleted file mode 100644 (file)
index 24f8bfb..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: Stefan Reiter <s.reiter@proxmox.com>
-Date: Thu, 20 Aug 2020 14:31:59 +0200
-Subject: [PATCH] PVE: Add sequential job transaction support
-
-Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
----
- include/qemu/job.h | 12 ++++++++++++
- job.c              | 24 ++++++++++++++++++++++++
- 2 files changed, 36 insertions(+)
-
-diff --git a/include/qemu/job.h b/include/qemu/job.h
-index 32aabb1c60..f7a6a0926a 100644
---- a/include/qemu/job.h
-+++ b/include/qemu/job.h
-@@ -280,6 +280,18 @@ typedef enum JobCreateFlags {
-  */
- JobTxn *job_txn_new(void);
-+/**
-+ * Create a new transaction and set it to sequential mode, i.e. run all jobs
-+ * one after the other instead of at the same time.
-+ */
-+JobTxn *job_txn_new_seq(void);
-+
-+/**
-+ * Helper method to start the first job in a sequential transaction to kick it
-+ * off. Other jobs will be run after this one completes.
-+ */
-+void job_txn_start_seq(JobTxn *txn);
-+
- /**
-  * Release a reference that was previously acquired with job_txn_add_job or
-  * job_txn_new. If it's the last reference to the object, it will be freed.
-diff --git a/job.c b/job.c
-index f9884e7d9d..8f06e05fbf 100644
---- a/job.c
-+++ b/job.c
-@@ -72,6 +72,8 @@ struct JobTxn {
-     /* Reference count */
-     int refcnt;
-+
-+    bool sequential;
- };
- /* Right now, this mutex is only needed to synchronize accesses to job->busy
-@@ -102,6 +104,25 @@ JobTxn *job_txn_new(void)
-     return txn;
- }
-+JobTxn *job_txn_new_seq(void)
-+{
-+    JobTxn *txn = job_txn_new();
-+    txn->sequential = true;
-+    return txn;
-+}
-+
-+void job_txn_start_seq(JobTxn *txn)
-+{
-+    assert(txn->sequential);
-+    assert(!txn->aborting);
-+
-+    Job *first = QLIST_FIRST(&txn->jobs);
-+    assert(first);
-+    assert(first->status == JOB_STATUS_CREATED);
-+
-+    job_start(first);
-+}
-+
- static void job_txn_ref(JobTxn *txn)
- {
-     txn->refcnt++;
-@@ -841,6 +862,9 @@ static void job_completed_txn_success(Job *job)
-      */
-     QLIST_FOREACH(other_job, &txn->jobs, txn_list) {
-         if (!job_is_completed(other_job)) {
-+            if (txn->sequential) {
-+                job_start(other_job);
-+            }
-             return;
-         }
-         assert(other_job->ret == 0);
diff --git a/debian/patches/pve/0051-PVE-Backup-Use-a-transaction-to-synchronize-job-stat.patch b/debian/patches/pve/0051-PVE-Backup-Use-a-transaction-to-synchronize-job-stat.patch
deleted file mode 100644 (file)
index bb3b026..0000000
+++ /dev/null
@@ -1,292 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: Stefan Reiter <s.reiter@proxmox.com>
-Date: Thu, 20 Aug 2020 14:25:00 +0200
-Subject: [PATCH] PVE-Backup: Use a transaction to synchronize job states
-
-By using a JobTxn, we can sync dirty bitmaps only when *all* jobs were
-successful - meaning we don't need to remove them when the backup fails,
-since QEMU's BITMAP_SYNC_MODE_ON_SUCCESS will now handle that for us.
-
-To keep the rate-limiting and IO impact from before, we use a sequential
-transaction, so drives will still be backed up one after the other.
-
-Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
----
- pve-backup.c | 167 +++++++++++++++------------------------------------
- 1 file changed, 49 insertions(+), 118 deletions(-)
-
-diff --git a/pve-backup.c b/pve-backup.c
-index 1e7b92a950..f3df43eb8c 100644
---- a/pve-backup.c
-+++ b/pve-backup.c
-@@ -52,6 +52,7 @@ static struct PVEBackupState {
-     VmaWriter *vmaw;
-     ProxmoxBackupHandle *pbs;
-     GList *di_list;
-+    JobTxn *txn;
-     QemuMutex backup_mutex;
-     CoMutex dump_callback_mutex;
- } backup_state;
-@@ -71,32 +72,12 @@ typedef struct PVEBackupDevInfo {
-     size_t size;
-     uint64_t block_size;
-     uint8_t dev_id;
--    bool completed;
-     char targetfile[PATH_MAX];
-     BdrvDirtyBitmap *bitmap;
-     BlockDriverState *target;
-+    BlockJob *job;
- } PVEBackupDevInfo;
--static void pvebackup_run_next_job(void);
--
--static BlockJob *
--lookup_active_block_job(PVEBackupDevInfo *di)
--{
--    if (!di->completed && di->bs) {
--        for (BlockJob *job = block_job_next(NULL); job; job = block_job_next(job)) {
--            if (job->job.driver->job_type != JOB_TYPE_BACKUP) {
--                continue;
--            }
--
--            BackupBlockJob *bjob = container_of(job, BackupBlockJob, common);
--            if (bjob && bjob->source_bs == di->bs) {
--                return job;
--            }
--        }
--    }
--    return NULL;
--}
--
- static void pvebackup_propagate_error(Error *err)
- {
-     qemu_mutex_lock(&backup_state.stat.lock);
-@@ -272,18 +253,6 @@ static void coroutine_fn pvebackup_co_cleanup(void *unused)
-             if (local_err != NULL) {
-                 pvebackup_propagate_error(local_err);
-             }
--        } else {
--            // on error or cancel we cannot ensure synchronization of dirty
--            // bitmaps with backup server, so remove all and do full backup next
--            GList *l = backup_state.di_list;
--            while (l) {
--                PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
--                l = g_list_next(l);
--
--                if (di->bitmap) {
--                    bdrv_release_dirty_bitmap(di->bitmap);
--                }
--            }
-         }
-         proxmox_backup_disconnect(backup_state.pbs);
-@@ -322,8 +291,6 @@ static void pvebackup_complete_cb(void *opaque, int ret)
-     qemu_mutex_lock(&backup_state.backup_mutex);
--    di->completed = true;
--
-     if (ret < 0) {
-         Error *local_err = NULL;
-         error_setg(&local_err, "job failed with err %d - %s", ret, strerror(-ret));
-@@ -336,20 +303,17 @@ static void pvebackup_complete_cb(void *opaque, int ret)
-     block_on_coroutine_fn(pvebackup_complete_stream, di);
--    // remove self from job queue
-+    // remove self from job list
-     backup_state.di_list = g_list_remove(backup_state.di_list, di);
--    if (di->bitmap && ret < 0) {
--        // on error or cancel we cannot ensure synchronization of dirty
--        // bitmaps with backup server, so remove all and do full backup next
--        bdrv_release_dirty_bitmap(di->bitmap);
--    }
--
-     g_free(di);
--    qemu_mutex_unlock(&backup_state.backup_mutex);
-+    /* call cleanup if we're the last job */
-+    if (!g_list_first(backup_state.di_list)) {
-+        block_on_coroutine_fn(pvebackup_co_cleanup, NULL);
-+    }
--    pvebackup_run_next_job();
-+    qemu_mutex_unlock(&backup_state.backup_mutex);
- }
- static void pvebackup_cancel(void)
-@@ -371,36 +335,28 @@ static void pvebackup_cancel(void)
-         proxmox_backup_abort(backup_state.pbs, "backup canceled");
-     }
--    qemu_mutex_unlock(&backup_state.backup_mutex);
--
--    for(;;) {
--
--        BlockJob *next_job = NULL;
--
--        qemu_mutex_lock(&backup_state.backup_mutex);
--
--        GList *l = backup_state.di_list;
--        while (l) {
--            PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
--            l = g_list_next(l);
-+    /* it's enough to cancel one job in the transaction, the rest will follow
-+     * automatically */
-+    GList *bdi = g_list_first(backup_state.di_list);
-+    BlockJob *cancel_job = bdi && bdi->data ?
-+        ((PVEBackupDevInfo *)bdi->data)->job :
-+        NULL;
--            BlockJob *job = lookup_active_block_job(di);
--            if (job != NULL) {
--                next_job = job;
--                break;
--            }
--        }
-+    /* ref the job before releasing the mutex, just to be safe */
-+    if (cancel_job) {
-+        job_ref(&cancel_job->job);
-+    }
--        qemu_mutex_unlock(&backup_state.backup_mutex);
-+    /* job_cancel_sync may enter the job, so we need to release the
-+     * backup_mutex to avoid deadlock */
-+    qemu_mutex_unlock(&backup_state.backup_mutex);
--        if (next_job) {
--            AioContext *aio_context = next_job->job.aio_context;
--            aio_context_acquire(aio_context);
--            job_cancel_sync(&next_job->job);
--            aio_context_release(aio_context);
--        } else {
--            break;
--        }
-+    if (cancel_job) {
-+        AioContext *aio_context = cancel_job->job.aio_context;
-+        aio_context_acquire(aio_context);
-+        job_cancel_sync(&cancel_job->job);
-+        job_unref(&cancel_job->job);
-+        aio_context_release(aio_context);
-     }
- }
-@@ -459,51 +415,19 @@ static int coroutine_fn pvebackup_co_add_config(
-     goto out;
- }
--bool job_should_pause(Job *job);
--
--static void pvebackup_run_next_job(void)
--{
--    assert(!qemu_in_coroutine());
--
--    qemu_mutex_lock(&backup_state.backup_mutex);
--
--    GList *l = backup_state.di_list;
--    while (l) {
--        PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
--        l = g_list_next(l);
--
--        BlockJob *job = lookup_active_block_job(di);
--
--        if (job) {
--            qemu_mutex_unlock(&backup_state.backup_mutex);
--
--            AioContext *aio_context = job->job.aio_context;
--            aio_context_acquire(aio_context);
--
--            if (job_should_pause(&job->job)) {
--                bool error_or_canceled = pvebackup_error_or_canceled();
--                if (error_or_canceled) {
--                    job_cancel_sync(&job->job);
--                } else {
--                    job_resume(&job->job);
--                }
--            }
--            aio_context_release(aio_context);
--            return;
--        }
--    }
--
--    block_on_coroutine_fn(pvebackup_co_cleanup, NULL); // no more jobs, run cleanup
--
--    qemu_mutex_unlock(&backup_state.backup_mutex);
--}
--
- static bool create_backup_jobs(void) {
-     assert(!qemu_in_coroutine());
-     Error *local_err = NULL;
-+    /* create job transaction to synchronize bitmap commit and cancel all
-+     * jobs in case one errors */
-+    if (backup_state.txn) {
-+        job_txn_unref(backup_state.txn);
-+    }
-+    backup_state.txn = job_txn_new_seq();
-+
-     /* create and start all jobs (paused state) */
-     GList *l =  backup_state.di_list;
-     while (l) {
-@@ -524,7 +448,7 @@ static bool create_backup_jobs(void) {
-         BlockJob *job = backup_job_create(
-             NULL, di->bs, di->target, backup_state.speed, sync_mode, di->bitmap,
-             bitmap_mode, false, NULL, BLOCKDEV_ON_ERROR_REPORT, BLOCKDEV_ON_ERROR_REPORT,
--            JOB_DEFAULT, pvebackup_complete_cb, di, 1, NULL, &local_err);
-+            JOB_DEFAULT, pvebackup_complete_cb, di, backup_state.txn, &local_err);
-         aio_context_release(aio_context);
-@@ -536,7 +460,8 @@ static bool create_backup_jobs(void) {
-             pvebackup_propagate_error(create_job_err);
-             break;
-         }
--        job_start(&job->job);
-+
-+        di->job = job;
-         bdrv_unref(di->target);
-         di->target = NULL;
-@@ -554,6 +479,10 @@ static bool create_backup_jobs(void) {
-                 bdrv_unref(di->target);
-                 di->target = NULL;
-             }
-+
-+            if (di->job) {
-+                job_unref(&di->job->job);
-+            }
-         }
-     }
-@@ -944,10 +873,6 @@ err:
-         PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
-         l = g_list_next(l);
--        if (di->bitmap) {
--            bdrv_release_dirty_bitmap(di->bitmap);
--        }
--
-         if (di->target) {
-             bdrv_unref(di->target);
-         }
-@@ -1036,9 +961,15 @@ UuidInfo *qmp_backup(
-     block_on_coroutine_fn(pvebackup_co_prepare, &task);
-     if (*errp == NULL) {
--        create_backup_jobs();
-+        bool errors = create_backup_jobs();
-         qemu_mutex_unlock(&backup_state.backup_mutex);
--        pvebackup_run_next_job();
-+
-+        if (!errors) {
-+            /* start the first job in the transaction
-+             * note: this might directly enter the job, so we need to do this
-+             * after unlocking the backup_mutex */
-+            job_txn_start_seq(backup_state.txn);
-+        }
-     } else {
-         qemu_mutex_unlock(&backup_state.backup_mutex);
-     }
diff --git a/debian/patches/pve/0052-PVE-Backup-Use-more-coroutines-and-don-t-block-on-fi.patch b/debian/patches/pve/0052-PVE-Backup-Use-more-coroutines-and-don-t-block-on-fi.patch
deleted file mode 100644 (file)
index b215d3d..0000000
+++ /dev/null
@@ -1,381 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: Stefan Reiter <s.reiter@proxmox.com>
-Date: Mon, 28 Sep 2020 13:40:51 +0200
-Subject: [PATCH] PVE-Backup: Use more coroutines and don't block on finishing
-
-proxmox_backup_co_finish is already async, but previously we would wait
-for the coroutine using block_on_coroutine_fn(). Avoid this by
-scheduling pvebackup_co_complete_stream (and thus pvebackup_co_cleanup)
-as a real coroutine when calling from pvebackup_complete_cb. This is ok,
-since complete_stream uses the backup_mutex internally to synchronize,
-and other streams can happily continue writing in the meantime anyway.
-
-To accomodate, backup_mutex is converted to a CoMutex. This means
-converting every user to a coroutine. This is not just useful here, but
-will come in handy once this series[0] is merged, and QMP calls can be
-yield-able coroutines too. Then we can also finally get rid of
-block_on_coroutine_fn.
-
-Cases of aio_context_acquire/release from within what is now a coroutine
-are changed to aio_co_reschedule_self, which works since a running
-coroutine always holds the aio lock for the context it is running in.
-
-job_cancel_sync is called from a BH since it can't be run from a
-coroutine (uses AIO_WAIT_WHILE internally).
-
-Same thing for create_backup_jobs, which is converted to a BH too.
-
-To communicate the finishing state, a new property is introduced to
-query-backup: 'finishing'. A new state is explicitly not used, since
-that would break compatibility with older qemu-server versions.
-
-[0] https://lists.gnu.org/archive/html/qemu-devel/2020-09/msg03515.html
-
-Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
----
- pve-backup.c         | 148 ++++++++++++++++++++++++++-----------------
- qapi/block-core.json |   5 +-
- 2 files changed, 95 insertions(+), 58 deletions(-)
-
-diff --git a/pve-backup.c b/pve-backup.c
-index f3df43eb8c..f3b8ce1f3a 100644
---- a/pve-backup.c
-+++ b/pve-backup.c
-@@ -33,7 +33,9 @@ const char *PBS_BITMAP_NAME = "pbs-incremental-dirty-bitmap";
- static struct PVEBackupState {
-     struct {
--        // Everithing accessed from qmp_backup_query command is protected using lock
-+        // Everything accessed from qmp_backup_query command is protected using
-+        // this lock. Do NOT hold this lock for long times, as it is sometimes
-+        // acquired from coroutines, and thus any wait time may block the guest.
-         QemuMutex lock;
-         Error *error;
-         time_t start_time;
-@@ -47,20 +49,21 @@ static struct PVEBackupState {
-         size_t reused;
-         size_t zero_bytes;
-         GList *bitmap_list;
-+        bool finishing;
-     } stat;
-     int64_t speed;
-     VmaWriter *vmaw;
-     ProxmoxBackupHandle *pbs;
-     GList *di_list;
-     JobTxn *txn;
--    QemuMutex backup_mutex;
-+    CoMutex backup_mutex;
-     CoMutex dump_callback_mutex;
- } backup_state;
- static void pvebackup_init(void)
- {
-     qemu_mutex_init(&backup_state.stat.lock);
--    qemu_mutex_init(&backup_state.backup_mutex);
-+    qemu_co_mutex_init(&backup_state.backup_mutex);
-     qemu_co_mutex_init(&backup_state.dump_callback_mutex);
- }
-@@ -72,6 +75,7 @@ typedef struct PVEBackupDevInfo {
-     size_t size;
-     uint64_t block_size;
-     uint8_t dev_id;
-+    int completed_ret; // INT_MAX if not completed
-     char targetfile[PATH_MAX];
-     BdrvDirtyBitmap *bitmap;
-     BlockDriverState *target;
-@@ -227,12 +231,12 @@ pvebackup_co_dump_vma_cb(
- }
- // assumes the caller holds backup_mutex
--static void coroutine_fn pvebackup_co_cleanup(void *unused)
-+static void coroutine_fn pvebackup_co_cleanup(void)
- {
-     assert(qemu_in_coroutine());
-     qemu_mutex_lock(&backup_state.stat.lock);
--    backup_state.stat.end_time = time(NULL);
-+    backup_state.stat.finishing = true;
-     qemu_mutex_unlock(&backup_state.stat.lock);
-     if (backup_state.vmaw) {
-@@ -261,12 +265,29 @@ static void coroutine_fn pvebackup_co_cleanup(void *unused)
-     g_list_free(backup_state.di_list);
-     backup_state.di_list = NULL;
-+
-+    qemu_mutex_lock(&backup_state.stat.lock);
-+    backup_state.stat.end_time = time(NULL);
-+    backup_state.stat.finishing = false;
-+    qemu_mutex_unlock(&backup_state.stat.lock);
- }
--// assumes the caller holds backup_mutex
--static void coroutine_fn pvebackup_complete_stream(void *opaque)
-+static void coroutine_fn pvebackup_co_complete_stream(void *opaque)
- {
-     PVEBackupDevInfo *di = opaque;
-+    int ret = di->completed_ret;
-+
-+    qemu_co_mutex_lock(&backup_state.backup_mutex);
-+
-+    if (ret < 0) {
-+        Error *local_err = NULL;
-+        error_setg(&local_err, "job failed with err %d - %s", ret, strerror(-ret));
-+        pvebackup_propagate_error(local_err);
-+    }
-+
-+    di->bs = NULL;
-+
-+    assert(di->target == NULL);
-     bool error_or_canceled = pvebackup_error_or_canceled();
-@@ -281,27 +302,6 @@ static void coroutine_fn pvebackup_complete_stream(void *opaque)
-             pvebackup_propagate_error(local_err);
-         }
-     }
--}
--
--static void pvebackup_complete_cb(void *opaque, int ret)
--{
--    assert(!qemu_in_coroutine());
--
--    PVEBackupDevInfo *di = opaque;
--
--    qemu_mutex_lock(&backup_state.backup_mutex);
--
--    if (ret < 0) {
--        Error *local_err = NULL;
--        error_setg(&local_err, "job failed with err %d - %s", ret, strerror(-ret));
--        pvebackup_propagate_error(local_err);
--    }
--
--    di->bs = NULL;
--
--    assert(di->target == NULL);
--
--    block_on_coroutine_fn(pvebackup_complete_stream, di);
-     // remove self from job list
-     backup_state.di_list = g_list_remove(backup_state.di_list, di);
-@@ -310,21 +310,49 @@ static void pvebackup_complete_cb(void *opaque, int ret)
-     /* call cleanup if we're the last job */
-     if (!g_list_first(backup_state.di_list)) {
--        block_on_coroutine_fn(pvebackup_co_cleanup, NULL);
-+        pvebackup_co_cleanup();
-     }
--    qemu_mutex_unlock(&backup_state.backup_mutex);
-+    qemu_co_mutex_unlock(&backup_state.backup_mutex);
- }
--static void pvebackup_cancel(void)
-+static void pvebackup_complete_cb(void *opaque, int ret)
- {
--    assert(!qemu_in_coroutine());
-+    PVEBackupDevInfo *di = opaque;
-+    di->completed_ret = ret;
-+
-+    /*
-+     * Schedule stream cleanup in async coroutine. close_image and finish might
-+     * take a while, so we can't block on them here. This way it also doesn't
-+     * matter if we're already running in a coroutine or not.
-+     * Note: di is a pointer to an entry in the global backup_state struct, so
-+     * it stays valid.
-+     */
-+    Coroutine *co = qemu_coroutine_create(pvebackup_co_complete_stream, di);
-+    aio_co_enter(qemu_get_aio_context(), co);
-+}
-+/*
-+ * job_cancel(_sync) does not like to be called from coroutines, so defer to
-+ * main loop processing via a bottom half.
-+ */
-+static void job_cancel_bh(void *opaque) {
-+    CoCtxData *data = (CoCtxData*)opaque;
-+    Job *job = (Job*)data->data;
-+    AioContext *job_ctx = job->aio_context;
-+    aio_context_acquire(job_ctx);
-+    job_cancel_sync(job);
-+    aio_context_release(job_ctx);
-+    aio_co_enter(data->ctx, data->co);
-+}
-+
-+static void coroutine_fn pvebackup_co_cancel(void *opaque)
-+{
-     Error *cancel_err = NULL;
-     error_setg(&cancel_err, "backup canceled");
-     pvebackup_propagate_error(cancel_err);
--    qemu_mutex_lock(&backup_state.backup_mutex);
-+    qemu_co_mutex_lock(&backup_state.backup_mutex);
-     if (backup_state.vmaw) {
-         /* make sure vma writer does not block anymore */
-@@ -342,27 +370,22 @@ static void pvebackup_cancel(void)
-         ((PVEBackupDevInfo *)bdi->data)->job :
-         NULL;
--    /* ref the job before releasing the mutex, just to be safe */
-     if (cancel_job) {
--        job_ref(&cancel_job->job);
-+        CoCtxData data = {
-+            .ctx = qemu_get_current_aio_context(),
-+            .co = qemu_coroutine_self(),
-+            .data = &cancel_job->job,
-+        };
-+        aio_bh_schedule_oneshot(data.ctx, job_cancel_bh, &data);
-+        qemu_coroutine_yield();
-     }
--    /* job_cancel_sync may enter the job, so we need to release the
--     * backup_mutex to avoid deadlock */
--    qemu_mutex_unlock(&backup_state.backup_mutex);
--
--    if (cancel_job) {
--        AioContext *aio_context = cancel_job->job.aio_context;
--        aio_context_acquire(aio_context);
--        job_cancel_sync(&cancel_job->job);
--        job_unref(&cancel_job->job);
--        aio_context_release(aio_context);
--    }
-+    qemu_co_mutex_unlock(&backup_state.backup_mutex);
- }
- void qmp_backup_cancel(Error **errp)
- {
--    pvebackup_cancel();
-+    block_on_coroutine_fn(pvebackup_co_cancel, NULL);
- }
- // assumes the caller holds backup_mutex
-@@ -415,6 +438,14 @@ static int coroutine_fn pvebackup_co_add_config(
-     goto out;
- }
-+/*
-+ * backup_job_create can *not* be run from a coroutine (and requires an
-+ * acquired AioContext), so this can't either.
-+ * This does imply that this function cannot run with backup_mutex acquired.
-+ * That is ok because it is only ever called between setting up the backup_state
-+ * struct and starting the jobs, and from within a QMP call. This means that no
-+ * other QMP call can interrupt, and no background job is running yet.
-+ */
- static bool create_backup_jobs(void) {
-     assert(!qemu_in_coroutine());
-@@ -523,11 +554,12 @@ typedef struct QmpBackupTask {
-     UuidInfo *result;
- } QmpBackupTask;
--// assumes the caller holds backup_mutex
- static void coroutine_fn pvebackup_co_prepare(void *opaque)
- {
-     assert(qemu_in_coroutine());
-+    qemu_co_mutex_lock(&backup_state.backup_mutex);
-+
-     QmpBackupTask *task = opaque;
-     task->result = NULL; // just to be sure
-@@ -548,8 +580,9 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-     const char *firewall_name = "qemu-server.fw";
-     if (backup_state.di_list) {
--         error_set(task->errp, ERROR_CLASS_GENERIC_ERROR,
-+        error_set(task->errp, ERROR_CLASS_GENERIC_ERROR,
-                   "previous backup not finished");
-+        qemu_co_mutex_unlock(&backup_state.backup_mutex);
-         return;
-     }
-@@ -616,6 +649,8 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-         }
-         di->size = size;
-         total += size;
-+
-+        di->completed_ret = INT_MAX;
-     }
-     uuid_generate(uuid);
-@@ -847,6 +882,7 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-     backup_state.stat.dirty = total - backup_state.stat.reused;
-     backup_state.stat.transferred = 0;
-     backup_state.stat.zero_bytes = 0;
-+    backup_state.stat.finishing = false;
-     qemu_mutex_unlock(&backup_state.stat.lock);
-@@ -861,6 +897,8 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-     uuid_info->UUID = uuid_str;
-     task->result = uuid_info;
-+
-+    qemu_co_mutex_unlock(&backup_state.backup_mutex);
-     return;
- err_mutex:
-@@ -903,6 +941,8 @@ err:
-     }
-     task->result = NULL;
-+
-+    qemu_co_mutex_unlock(&backup_state.backup_mutex);
-     return;
- }
-@@ -956,22 +996,15 @@ UuidInfo *qmp_backup(
-         .errp = errp,
-     };
--    qemu_mutex_lock(&backup_state.backup_mutex);
--
-     block_on_coroutine_fn(pvebackup_co_prepare, &task);
-     if (*errp == NULL) {
-         bool errors = create_backup_jobs();
--        qemu_mutex_unlock(&backup_state.backup_mutex);
-         if (!errors) {
--            /* start the first job in the transaction
--             * note: this might directly enter the job, so we need to do this
--             * after unlocking the backup_mutex */
-+            // start the first job in the transaction
-             job_txn_start_seq(backup_state.txn);
-         }
--    } else {
--        qemu_mutex_unlock(&backup_state.backup_mutex);
-     }
-     return task.result;
-@@ -1025,6 +1058,7 @@ BackupStatus *qmp_query_backup(Error **errp)
-     info->transferred = backup_state.stat.transferred;
-     info->has_reused = true;
-     info->reused = backup_state.stat.reused;
-+    info->finishing = backup_state.stat.finishing;
-     qemu_mutex_unlock(&backup_state.stat.lock);
-diff --git a/qapi/block-core.json b/qapi/block-core.json
-index b368371e8e..b90d6abe64 100644
---- a/qapi/block-core.json
-+++ b/qapi/block-core.json
-@@ -775,12 +775,15 @@
- #
- # @uuid: uuid for this backup job
- #
-+# @finishing: if status='active' and finishing=true, then the backup process is
-+#             waiting for the target to finish.
-+#
- ##
- { 'struct': 'BackupStatus',
-   'data': {'*status': 'str', '*errmsg': 'str', '*total': 'int', '*dirty': 'int',
-            '*transferred': 'int', '*zero-bytes': 'int', '*reused': 'int',
-            '*start-time': 'int', '*end-time': 'int',
--           '*backup-file': 'str', '*uuid': 'str' } }
-+           '*backup-file': 'str', '*uuid': 'str', 'finishing': 'bool' } }
- ##
- # @BackupFormat:
diff --git a/debian/patches/pve/0053-PVE-fix-and-clean-up-error-handling-for-create_backu.patch b/debian/patches/pve/0053-PVE-fix-and-clean-up-error-handling-for-create_backu.patch
deleted file mode 100644 (file)
index 92dc3e0..0000000
+++ /dev/null
@@ -1,187 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: Stefan Reiter <s.reiter@proxmox.com>
-Date: Thu, 22 Oct 2020 17:01:07 +0200
-Subject: [PATCH] PVE: fix and clean up error handling for create_backup_jobs
-
-No more weird bool returns, just the standard "errp" format used
-everywhere else too. With this, if backup_job_create fails, the error
-message is actually returned over QMP and can be shown to the user.
-
-To facilitate correct cleanup on such an error, we call
-create_backup_jobs as a bottom half directly from pvebackup_co_prepare.
-This additionally allows us to actually hold the backup_mutex during
-operation.
-
-Also add a job_cancel_sync before job_unref, since a job must be in
-STATUS_NULL to be deleted by unref, which could trigger an assert
-before.
-
-Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
----
- pve-backup.c | 79 +++++++++++++++++++++++++++++++++++-----------------
- 1 file changed, 54 insertions(+), 25 deletions(-)
-
-diff --git a/pve-backup.c b/pve-backup.c
-index f3b8ce1f3a..ded90cb822 100644
---- a/pve-backup.c
-+++ b/pve-backup.c
-@@ -50,6 +50,7 @@ static struct PVEBackupState {
-         size_t zero_bytes;
-         GList *bitmap_list;
-         bool finishing;
-+        bool starting;
-     } stat;
-     int64_t speed;
-     VmaWriter *vmaw;
-@@ -277,6 +278,16 @@ static void coroutine_fn pvebackup_co_complete_stream(void *opaque)
-     PVEBackupDevInfo *di = opaque;
-     int ret = di->completed_ret;
-+    qemu_mutex_lock(&backup_state.stat.lock);
-+    bool starting = backup_state.stat.starting;
-+    qemu_mutex_unlock(&backup_state.stat.lock);
-+    if (starting) {
-+        /* in 'starting' state, no tasks have been run yet, meaning we can (and
-+         * must) skip all cleanup, as we don't know what has and hasn't been
-+         * initialized yet. */
-+        return;
-+    }
-+
-     qemu_co_mutex_lock(&backup_state.backup_mutex);
-     if (ret < 0) {
-@@ -441,15 +452,15 @@ static int coroutine_fn pvebackup_co_add_config(
- /*
-  * backup_job_create can *not* be run from a coroutine (and requires an
-  * acquired AioContext), so this can't either.
-- * This does imply that this function cannot run with backup_mutex acquired.
-- * That is ok because it is only ever called between setting up the backup_state
-- * struct and starting the jobs, and from within a QMP call. This means that no
-- * other QMP call can interrupt, and no background job is running yet.
-+ * The caller is responsible that backup_mutex is held nonetheless.
-  */
--static bool create_backup_jobs(void) {
-+static void create_backup_jobs_bh(void *opaque) {
-     assert(!qemu_in_coroutine());
-+    CoCtxData *data = (CoCtxData*)opaque;
-+    Error **errp = (Error**)data->data;
-+
-     Error *local_err = NULL;
-     /* create job transaction to synchronize bitmap commit and cancel all
-@@ -483,24 +494,19 @@ static bool create_backup_jobs(void) {
-         aio_context_release(aio_context);
--        if (!job || local_err != NULL) {
--            Error *create_job_err = NULL;
--            error_setg(&create_job_err, "backup_job_create failed: %s",
--                       local_err ? error_get_pretty(local_err) : "null");
-+        di->job = job;
--            pvebackup_propagate_error(create_job_err);
-+        if (!job || local_err) {
-+            error_setg(errp, "backup_job_create failed: %s",
-+                       local_err ? error_get_pretty(local_err) : "null");
-             break;
-         }
--        di->job = job;
--
-         bdrv_unref(di->target);
-         di->target = NULL;
-     }
--    bool errors = pvebackup_error_or_canceled();
--
--    if (errors) {
-+    if (*errp) {
-         l = backup_state.di_list;
-         while (l) {
-             PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
-@@ -512,12 +518,17 @@ static bool create_backup_jobs(void) {
-             }
-             if (di->job) {
-+                AioContext *ctx = di->job->job.aio_context;
-+                aio_context_acquire(ctx);
-+                job_cancel_sync(&di->job->job);
-                 job_unref(&di->job->job);
-+                aio_context_release(ctx);
-             }
-         }
-     }
--    return errors;
-+    /* return */
-+    aio_co_enter(data->ctx, data->co);
- }
- typedef struct QmpBackupTask {
-@@ -883,6 +894,7 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-     backup_state.stat.transferred = 0;
-     backup_state.stat.zero_bytes = 0;
-     backup_state.stat.finishing = false;
-+    backup_state.stat.starting = true;
-     qemu_mutex_unlock(&backup_state.stat.lock);
-@@ -898,7 +910,32 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-     task->result = uuid_info;
-+    /* Run create_backup_jobs_bh outside of coroutine (in BH) but keep
-+    * backup_mutex locked. This is fine, a CoMutex can be held across yield
-+    * points, and we'll release it as soon as the BH reschedules us.
-+    */
-+    CoCtxData waker = {
-+        .co = qemu_coroutine_self(),
-+        .ctx = qemu_get_current_aio_context(),
-+        .data = &local_err,
-+    };
-+    aio_bh_schedule_oneshot(waker.ctx, create_backup_jobs_bh, &waker);
-+    qemu_coroutine_yield();
-+
-+    if (local_err) {
-+        error_propagate(task->errp, local_err);
-+        goto err;
-+    }
-+
-     qemu_co_mutex_unlock(&backup_state.backup_mutex);
-+
-+    qemu_mutex_lock(&backup_state.stat.lock);
-+    backup_state.stat.starting = false;
-+    qemu_mutex_unlock(&backup_state.stat.lock);
-+
-+    /* start the first job in the transaction */
-+    job_txn_start_seq(backup_state.txn);
-+
-     return;
- err_mutex:
-@@ -921,6 +958,7 @@ err:
-         g_free(di);
-     }
-     g_list_free(di_list);
-+    backup_state.di_list = NULL;
-     if (devs) {
-         g_strfreev(devs);
-@@ -998,15 +1036,6 @@ UuidInfo *qmp_backup(
-     block_on_coroutine_fn(pvebackup_co_prepare, &task);
--    if (*errp == NULL) {
--        bool errors = create_backup_jobs();
--
--        if (!errors) {
--            // start the first job in the transaction
--            job_txn_start_seq(backup_state.txn);
--        }
--    }
--
-     return task.result;
- }
diff --git a/debian/patches/pve/0054-PVE-Migrate-dirty-bitmap-state-via-savevm.patch b/debian/patches/pve/0054-PVE-Migrate-dirty-bitmap-state-via-savevm.patch
deleted file mode 100644 (file)
index a4ee6bc..0000000
+++ /dev/null
@@ -1,209 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: Stefan Reiter <s.reiter@proxmox.com>
-Date: Thu, 22 Oct 2020 17:34:18 +0200
-Subject: [PATCH] PVE: Migrate dirty bitmap state via savevm
-
-QEMU provides 'savevm' registrations as a mechanism for arbitrary state
-to be migrated along with a VM. Use this to send a serialized version of
-dirty bitmap state data from proxmox-backup-qemu, and restore it on the
-target node.
-
-Also add a flag to query-proxmox-support so qemu-server can determine if
-safe migration is possible and makes sense.
-
-Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
----
- include/migration/misc.h |   3 ++
- migration/meson.build    |   2 +
- migration/pbs-state.c    | 106 +++++++++++++++++++++++++++++++++++++++
- pve-backup.c             |   1 +
- qapi/block-core.json     |   6 +++
- softmmu/vl.c             |   1 +
- 6 files changed, 119 insertions(+)
- create mode 100644 migration/pbs-state.c
-
-diff --git a/include/migration/misc.h b/include/migration/misc.h
-index 34e7d75713..f83816dd3c 100644
---- a/include/migration/misc.h
-+++ b/include/migration/misc.h
-@@ -75,4 +75,7 @@ bool migration_in_incoming_postcopy(void);
- /* migration/block-dirty-bitmap.c */
- void dirty_bitmap_mig_init(void);
-+/* migration/pbs-state.c */
-+void pbs_state_mig_init(void);
-+
- #endif
-diff --git a/migration/meson.build b/migration/meson.build
-index e62b79b60f..b90a04aa75 100644
---- a/migration/meson.build
-+++ b/migration/meson.build
-@@ -7,8 +7,10 @@ migration_files = files(
-   'qemu-file-channel.c',
-   'qemu-file.c',
-   'qjson.c',
-+  'pbs-state.c',
- )
- softmmu_ss.add(migration_files)
-+softmmu_ss.add(libproxmox_backup_qemu)
- softmmu_ss.add(files(
-   'block-dirty-bitmap.c',
-diff --git a/migration/pbs-state.c b/migration/pbs-state.c
-new file mode 100644
-index 0000000000..29f2b3860d
---- /dev/null
-+++ b/migration/pbs-state.c
-@@ -0,0 +1,106 @@
-+/*
-+ * PBS (dirty-bitmap) state migration
-+ */
-+
-+#include "qemu/osdep.h"
-+#include "migration/misc.h"
-+#include "qemu-file.h"
-+#include "migration/vmstate.h"
-+#include "migration/register.h"
-+#include "proxmox-backup-qemu.h"
-+
-+typedef struct PBSState {
-+    bool active;
-+} PBSState;
-+
-+/* state is accessed via this static variable directly, 'opaque' is NULL */
-+static PBSState pbs_state;
-+
-+static void pbs_state_save_pending(QEMUFile *f, void *opaque,
-+                                      uint64_t max_size,
-+                                      uint64_t *res_precopy_only,
-+                                      uint64_t *res_compatible,
-+                                      uint64_t *res_postcopy_only)
-+{
-+    /* we send everything in save_setup, so nothing is ever pending */
-+}
-+
-+/* receive PBS state via f and deserialize, called on target */
-+static int pbs_state_load(QEMUFile *f, void *opaque, int version_id)
-+{
-+    /* safe cast, we cannot migrate to target with less bits than source */
-+    size_t buf_size = (size_t)qemu_get_be64(f);
-+
-+    uint8_t *buf = (uint8_t *)malloc(buf_size);
-+    size_t read = qemu_get_buffer(f, buf, buf_size);
-+
-+    if (read < buf_size) {
-+        fprintf(stderr, "error receiving PBS state: not enough data\n");
-+        return -EIO;
-+    }
-+
-+    proxmox_import_state(buf, buf_size);
-+
-+    free(buf);
-+    return 0;
-+}
-+
-+/* serialize PBS state and send to target via f, called on source */
-+static int pbs_state_save_setup(QEMUFile *f, void *opaque)
-+{
-+    size_t buf_size;
-+    uint8_t *buf = proxmox_export_state(&buf_size);
-+
-+    /* LV encoding */
-+    qemu_put_be64(f, buf_size);
-+    qemu_put_buffer(f, buf, buf_size);
-+
-+    proxmox_free_state_buf(buf);
-+    pbs_state.active = false;
-+    return 0;
-+}
-+
-+static bool pbs_state_is_active(void *opaque)
-+{
-+    /* we need to return active exactly once, else .save_setup is never called,
-+     * but if we'd just return true the migration doesn't make progress since
-+     * it'd be waiting for us */
-+    return pbs_state.active;
-+}
-+
-+static bool pbs_state_is_active_iterate(void *opaque)
-+{
-+    /* we don't iterate, everything is sent in save_setup */
-+    return pbs_state_is_active(opaque);
-+}
-+
-+static bool pbs_state_has_postcopy(void *opaque)
-+{
-+    /* PBS state can't change during a migration (since that's blocking any
-+     * potential backups), so we can copy everything before the VM is stopped */
-+    return false;
-+}
-+
-+static void pbs_state_save_cleanup(void *opaque)
-+{
-+    /* reset active after migration succeeds or fails */
-+    pbs_state.active = false;
-+}
-+
-+static SaveVMHandlers savevm_pbs_state_handlers = {
-+    .save_setup = pbs_state_save_setup,
-+    .has_postcopy = pbs_state_has_postcopy,
-+    .save_live_pending = pbs_state_save_pending,
-+    .is_active_iterate = pbs_state_is_active_iterate,
-+    .load_state = pbs_state_load,
-+    .is_active = pbs_state_is_active,
-+    .save_cleanup = pbs_state_save_cleanup,
-+};
-+
-+void pbs_state_mig_init(void)
-+{
-+    pbs_state.active = true;
-+    register_savevm_live("pbs-state", 0, 1,
-+                         &savevm_pbs_state_handlers,
-+                         NULL);
-+}
-diff --git a/pve-backup.c b/pve-backup.c
-index ded90cb822..6b25292ba1 100644
---- a/pve-backup.c
-+++ b/pve-backup.c
-@@ -1130,5 +1130,6 @@ ProxmoxSupportStatus *qmp_query_proxmox_support(Error **errp)
-     ret->pbs_library_version = g_strdup(proxmox_backup_qemu_version());
-     ret->pbs_dirty_bitmap = true;
-     ret->query_bitmap_info = true;
-+    ret->pbs_dirty_bitmap_migration = true;
-     return ret;
- }
-diff --git a/qapi/block-core.json b/qapi/block-core.json
-index b90d6abe64..dee3d87efe 100644
---- a/qapi/block-core.json
-+++ b/qapi/block-core.json
-@@ -881,12 +881,18 @@
- #
- # @query-bitmap-info: True if the 'query-pbs-bitmap-info' QMP call is supported.
- #
-+# @pbs-dirty-bitmap-migration: True if safe migration of dirty-bitmaps including
-+#                              PBS state is supported. Enabling 'dirty-bitmaps'
-+#                              migration cap if this is false/unset may lead
-+#                              to crashes on migration!
-+#
- # @pbs-library-version: Running version of libproxmox-backup-qemu0 library.
- #
- ##
- { 'struct': 'ProxmoxSupportStatus',
-   'data': { 'pbs-dirty-bitmap': 'bool',
-             'query-bitmap-info': 'bool',
-+            'pbs-dirty-bitmap-migration': 'bool',
-             'pbs-library-version': 'str' } }
- ##
-diff --git a/softmmu/vl.c b/softmmu/vl.c
-index 5b5512128e..6721889fee 100644
---- a/softmmu/vl.c
-+++ b/softmmu/vl.c
-@@ -4304,6 +4304,7 @@ void qemu_init(int argc, char **argv, char **envp)
-     blk_mig_init();
-     ram_mig_init();
-     dirty_bitmap_mig_init();
-+    pbs_state_mig_init();
-     qemu_opts_foreach(qemu_find_opts("mon"),
-                       mon_init_func, NULL, &error_fatal);
diff --git a/debian/patches/pve/0055-migration-block-dirty-bitmap-migrate-other-bitmaps-e.patch b/debian/patches/pve/0055-migration-block-dirty-bitmap-migrate-other-bitmaps-e.patch
deleted file mode 100644 (file)
index 775f992..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: Stefan Reiter <s.reiter@proxmox.com>
-Date: Tue, 3 Nov 2020 14:57:32 +0100
-Subject: [PATCH] migration/block-dirty-bitmap: migrate other bitmaps even if
- one fails
-
-If the checks in bdrv_dirty_bitmap_check fail, that only means that this
-one specific bitmap cannot be migrated. That is not an error condition
-for any other bitmaps on the same block device.
-
-Fixes dirty-bitmap migration with sync=bitmap, as the bitmaps used for
-that are obviously marked as "busy", which would cause none at all to be
-transferred.
-
-Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
----
- migration/block-dirty-bitmap.c | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/migration/block-dirty-bitmap.c b/migration/block-dirty-bitmap.c
-index c61d382be8..26e4e5c99c 100644
---- a/migration/block-dirty-bitmap.c
-+++ b/migration/block-dirty-bitmap.c
-@@ -534,7 +534,7 @@ static int add_bitmaps_to_list(DBMSaveState *s, BlockDriverState *bs,
-         if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_DEFAULT, &local_err)) {
-             error_report_err(local_err);
--            return -1;
-+            continue;
-         }
-         if (bitmap_aliases) {
diff --git a/debian/patches/pve/0056-PVE-fix-aborting-multiple-CREATED-jobs-in-sequential.patch b/debian/patches/pve/0056-PVE-fix-aborting-multiple-CREATED-jobs-in-sequential.patch
deleted file mode 100644 (file)
index 0e30326..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: Stefan Reiter <s.reiter@proxmox.com>
-Date: Mon, 4 Jan 2021 14:49:14 +0100
-Subject: [PATCH] PVE: fix aborting multiple 'CREATED' jobs in sequential
- transaction
-
-Deadlocks could occur in the AIO_WAIT_WHILE loop in job_finish_sync,
-which would wait for CREATED but not running jobs to complete, even
-though job_enter is a no-op in that scenario. Mark offending jobs as
-ABORTING immediately via job_update_rc if required.
-
-Manifested itself in cancelling or failing backups with more than 2
-drives.
-
-Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
-Tested-by: Mira Limbeck <m.limbeck@proxmox.com>
-Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
----
- job.c | 7 +++++++
- 1 file changed, 7 insertions(+)
-
-diff --git a/job.c b/job.c
-index 8f06e05fbf..05b7797e82 100644
---- a/job.c
-+++ b/job.c
-@@ -1035,6 +1035,13 @@ int job_finish_sync(Job *job, void (*finish)(Job *, Error **errp), Error **errp)
-         return -EBUSY;
-     }
-+    /* in a sequential transaction jobs with status CREATED can appear at time
-+     * of cancelling, these have not begun work so job_enter won't do anything,
-+     * let's ensure they are marked as ABORTING if required */
-+    if (job->status == JOB_STATUS_CREATED && job->txn->sequential) {
-+        job_update_rc(job);
-+    }
-+
-     AIO_WAIT_WHILE(job->aio_context,
-                    (job_enter(job), !job_is_completed(job)));
diff --git a/debian/patches/pve/0057-PVE-fall-back-to-open-iscsi-initiatorname.patch b/debian/patches/pve/0057-PVE-fall-back-to-open-iscsi-initiatorname.patch
deleted file mode 100644 (file)
index f4c4652..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: Fabian Ebner <f.ebner@proxmox.com>
-Date: Tue, 17 Nov 2020 10:51:05 +0100
-Subject: [PATCH] PVE: fall back to open-iscsi initiatorname
-
-When no explicit option is given, try reading the initiator name from
-/etc/iscsi/initiatorname.iscsi and only use the generic fallback, i.e.
-iqn.2008-11.org.linux-kvmXXX, as a third alternative.
-
-This avoids the need to add an explicit option for vma and to explicitly set it
-for each call to qemu that deals with iSCSI disks, while still allowing to set
-the option if a different name is needed.
-
-According to RFC 3720, an initiator name is at most 223 bytes long, so the
-4 KiB buffer is big enough, even if many whitespaces are used.
-
-Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
----
- block/iscsi.c | 30 ++++++++++++++++++++++++++++++
- 1 file changed, 30 insertions(+)
-
-diff --git a/block/iscsi.c b/block/iscsi.c
-index e30a7e3606..6c70bbe351 100644
---- a/block/iscsi.c
-+++ b/block/iscsi.c
-@@ -1374,12 +1374,42 @@ static char *get_initiator_name(QemuOpts *opts)
-     const char *name;
-     char *iscsi_name;
-     UuidInfo *uuid_info;
-+    FILE *name_fh;
-     name = qemu_opt_get(opts, "initiator-name");
-     if (name) {
-         return g_strdup(name);
-     }
-+    name_fh = fopen("/etc/iscsi/initiatorname.iscsi", "r");
-+    if (name_fh) {
-+        const char *key = "InitiatorName";
-+        char buffer[4096];
-+        char *line;
-+
-+        while ((line = fgets(buffer, sizeof(buffer), name_fh))) {
-+            line = g_strstrip(line);
-+            if (!strncmp(line, key, strlen(key))) {
-+                line = strchr(line, '=');
-+                if (!line || strlen(line) == 1) {
-+                    continue;
-+                }
-+                line++;
-+                g_strstrip(line);
-+                if (!strlen(line)) {
-+                    continue;
-+                }
-+                name = line;
-+                break;
-+            }
-+        }
-+        fclose(name_fh);
-+
-+        if (name) {
-+            return g_strdup(name);
-+        }
-+    }
-+
-     uuid_info = qmp_query_uuid(NULL);
-     if (strcmp(uuid_info->UUID, UUID_NONE) == 0) {
-         name = qemu_get_vm_name();
diff --git a/debian/patches/pve/0058-PVE-Use-coroutine-QMP-for-backup-cancel_backup.patch b/debian/patches/pve/0058-PVE-Use-coroutine-QMP-for-backup-cancel_backup.patch
deleted file mode 100644 (file)
index a18d478..0000000
+++ /dev/null
@@ -1,597 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: Stefan Reiter <s.reiter@proxmox.com>
-Date: Tue, 26 Jan 2021 15:45:30 +0100
-Subject: [PATCH] PVE: Use coroutine QMP for backup/cancel_backup
-
-Finally turn backup QMP calls into coroutines, now that it's possible.
-This has the benefit that calls are asynchronous to the main loop, i.e.
-long running operations like connecting to a PBS server will no longer
-hang the VM.
-
-Additionally, it allows us to get rid of block_on_coroutine_fn, which
-was always a hacky workaround.
-
-While we're already spring cleaning, also remove the QmpBackupTask
-struct, since we can now put the 'prepare' function directly into
-qmp_backup and thus no longer need those giant walls of text.
-
-(Note that for our patches to work with 5.2.0 this change is actually
-required, otherwise monitor_get_fd() fails as we're not in a QMP
-coroutine, but one we start ourselves - we could of course set the
-monitor for that coroutine ourselves, but let's just fix it the right
-way instead)
-
-Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
----
- block/monitor/block-hmp-cmds.c |   4 +-
- hmp-commands.hx                |   2 +
- proxmox-backup-client.c        |  31 -----
- pve-backup.c                   | 232 ++++++++++-----------------------
- qapi/block-core.json           |   4 +-
- 5 files changed, 77 insertions(+), 196 deletions(-)
-
-diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c
-index 46c63b1cf9..11c84d5508 100644
---- a/block/monitor/block-hmp-cmds.c
-+++ b/block/monitor/block-hmp-cmds.c
-@@ -1013,7 +1013,7 @@ void hmp_info_snapshots(Monitor *mon, const QDict *qdict)
-     g_free(global_snapshots);
- }
--void hmp_backup_cancel(Monitor *mon, const QDict *qdict)
-+void coroutine_fn hmp_backup_cancel(Monitor *mon, const QDict *qdict)
- {
-     Error *error = NULL;
-@@ -1022,7 +1022,7 @@ void hmp_backup_cancel(Monitor *mon, const QDict *qdict)
-     hmp_handle_error(mon, error);
- }
--void hmp_backup(Monitor *mon, const QDict *qdict)
-+void coroutine_fn hmp_backup(Monitor *mon, const QDict *qdict)
- {
-     Error *error = NULL;
-diff --git a/hmp-commands.hx b/hmp-commands.hx
-index 0c6b944850..54de3f80e6 100644
---- a/hmp-commands.hx
-+++ b/hmp-commands.hx
-@@ -108,6 +108,7 @@ ERST
-                   "\n\t\t\t Use -d to dump data into a directory instead"
-                   "\n\t\t\t of using VMA format.",
-         .cmd = hmp_backup,
-+        .coroutine  = true,
-     },
- SRST
-@@ -121,6 +122,7 @@ ERST
-         .params     = "",
-         .help       = "cancel the current VM backup",
-         .cmd        = hmp_backup_cancel,
-+        .coroutine  = true,
-     },
- SRST
-diff --git a/proxmox-backup-client.c b/proxmox-backup-client.c
-index 4ce7bc0b5e..0923037dec 100644
---- a/proxmox-backup-client.c
-+++ b/proxmox-backup-client.c
-@@ -5,37 +5,6 @@
- /* Proxmox Backup Server client bindings using coroutines */
--typedef struct BlockOnCoroutineWrapper {
--    AioContext *ctx;
--    CoroutineEntry *entry;
--    void *entry_arg;
--    bool finished;
--} BlockOnCoroutineWrapper;
--
--static void coroutine_fn block_on_coroutine_wrapper(void *opaque)
--{
--    BlockOnCoroutineWrapper *wrapper = opaque;
--    wrapper->entry(wrapper->entry_arg);
--    wrapper->finished = true;
--    aio_wait_kick();
--}
--
--void block_on_coroutine_fn(CoroutineEntry *entry, void *entry_arg)
--{
--    assert(!qemu_in_coroutine());
--
--    AioContext *ctx = qemu_get_current_aio_context();
--    BlockOnCoroutineWrapper wrapper = {
--        .finished = false,
--        .entry = entry,
--        .entry_arg = entry_arg,
--        .ctx = ctx,
--    };
--    Coroutine *wrapper_co = qemu_coroutine_create(block_on_coroutine_wrapper, &wrapper);
--    aio_co_enter(ctx, wrapper_co);
--    AIO_WAIT_WHILE(ctx, !wrapper.finished);
--}
--
- // This is called from another thread, so we use aio_co_schedule()
- static void proxmox_backup_schedule_wake(void *data) {
-     CoCtxData *waker = (CoCtxData *)data;
-diff --git a/pve-backup.c b/pve-backup.c
-index 6b25292ba1..f7597ae55c 100644
---- a/pve-backup.c
-+++ b/pve-backup.c
-@@ -357,7 +357,7 @@ static void job_cancel_bh(void *opaque) {
-     aio_co_enter(data->ctx, data->co);
- }
--static void coroutine_fn pvebackup_co_cancel(void *opaque)
-+void coroutine_fn qmp_backup_cancel(Error **errp)
- {
-     Error *cancel_err = NULL;
-     error_setg(&cancel_err, "backup canceled");
-@@ -394,11 +394,6 @@ static void coroutine_fn pvebackup_co_cancel(void *opaque)
-     qemu_co_mutex_unlock(&backup_state.backup_mutex);
- }
--void qmp_backup_cancel(Error **errp)
--{
--    block_on_coroutine_fn(pvebackup_co_cancel, NULL);
--}
--
- // assumes the caller holds backup_mutex
- static int coroutine_fn pvebackup_co_add_config(
-     const char *file,
-@@ -531,50 +526,27 @@ static void create_backup_jobs_bh(void *opaque) {
-     aio_co_enter(data->ctx, data->co);
- }
--typedef struct QmpBackupTask {
--    const char *backup_file;
--    bool has_password;
--    const char *password;
--    bool has_keyfile;
--    const char *keyfile;
--    bool has_key_password;
--    const char *key_password;
--    bool has_backup_id;
--    const char *backup_id;
--    bool has_backup_time;
--    const char *fingerprint;
--    bool has_fingerprint;
--    int64_t backup_time;
--    bool has_use_dirty_bitmap;
--    bool use_dirty_bitmap;
--    bool has_format;
--    BackupFormat format;
--    bool has_config_file;
--    const char *config_file;
--    bool has_firewall_file;
--    const char *firewall_file;
--    bool has_devlist;
--    const char *devlist;
--    bool has_compress;
--    bool compress;
--    bool has_encrypt;
--    bool encrypt;
--    bool has_speed;
--    int64_t speed;
--    Error **errp;
--    UuidInfo *result;
--} QmpBackupTask;
--
--static void coroutine_fn pvebackup_co_prepare(void *opaque)
-+UuidInfo coroutine_fn *qmp_backup(
-+    const char *backup_file,
-+    bool has_password, const char *password,
-+    bool has_keyfile, const char *keyfile,
-+    bool has_key_password, const char *key_password,
-+    bool has_fingerprint, const char *fingerprint,
-+    bool has_backup_id, const char *backup_id,
-+    bool has_backup_time, int64_t backup_time,
-+    bool has_use_dirty_bitmap, bool use_dirty_bitmap,
-+    bool has_compress, bool compress,
-+    bool has_encrypt, bool encrypt,
-+    bool has_format, BackupFormat format,
-+    bool has_config_file, const char *config_file,
-+    bool has_firewall_file, const char *firewall_file,
-+    bool has_devlist, const char *devlist,
-+    bool has_speed, int64_t speed, Error **errp)
- {
-     assert(qemu_in_coroutine());
-     qemu_co_mutex_lock(&backup_state.backup_mutex);
--    QmpBackupTask *task = opaque;
--
--    task->result = NULL; // just to be sure
--
-     BlockBackend *blk;
-     BlockDriverState *bs = NULL;
-     const char *backup_dir = NULL;
-@@ -591,17 +563,17 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-     const char *firewall_name = "qemu-server.fw";
-     if (backup_state.di_list) {
--        error_set(task->errp, ERROR_CLASS_GENERIC_ERROR,
-+        error_set(errp, ERROR_CLASS_GENERIC_ERROR,
-                   "previous backup not finished");
-         qemu_co_mutex_unlock(&backup_state.backup_mutex);
--        return;
-+        return NULL;
-     }
-     /* Todo: try to auto-detect format based on file name */
--    BackupFormat format = task->has_format ? task->format : BACKUP_FORMAT_VMA;
-+    format = has_format ? format : BACKUP_FORMAT_VMA;
--    if (task->has_devlist) {
--        devs = g_strsplit_set(task->devlist, ",;:", -1);
-+    if (has_devlist) {
-+        devs = g_strsplit_set(devlist, ",;:", -1);
-         gchar **d = devs;
-         while (d && *d) {
-@@ -609,14 +581,14 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-             if (blk) {
-                 bs = blk_bs(blk);
-                 if (!bdrv_is_inserted(bs)) {
--                    error_setg(task->errp, QERR_DEVICE_HAS_NO_MEDIUM, *d);
-+                    error_setg(errp, QERR_DEVICE_HAS_NO_MEDIUM, *d);
-                     goto err;
-                 }
-                 PVEBackupDevInfo *di = g_new0(PVEBackupDevInfo, 1);
-                 di->bs = bs;
-                 di_list = g_list_append(di_list, di);
-             } else {
--                error_set(task->errp, ERROR_CLASS_DEVICE_NOT_FOUND,
-+                error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
-                           "Device '%s' not found", *d);
-                 goto err;
-             }
-@@ -639,7 +611,7 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-     }
-     if (!di_list) {
--        error_set(task->errp, ERROR_CLASS_GENERIC_ERROR, "empty device list");
-+        error_set(errp, ERROR_CLASS_GENERIC_ERROR, "empty device list");
-         goto err;
-     }
-@@ -649,13 +621,13 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-     while (l) {
-         PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
-         l = g_list_next(l);
--        if (bdrv_op_is_blocked(di->bs, BLOCK_OP_TYPE_BACKUP_SOURCE, task->errp)) {
-+        if (bdrv_op_is_blocked(di->bs, BLOCK_OP_TYPE_BACKUP_SOURCE, errp)) {
-             goto err;
-         }
-         ssize_t size = bdrv_getlength(di->bs);
-         if (size < 0) {
--            error_setg_errno(task->errp, -di->size, "bdrv_getlength failed");
-+            error_setg_errno(errp, -di->size, "bdrv_getlength failed");
-             goto err;
-         }
-         di->size = size;
-@@ -682,47 +654,44 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-     }
-     if (format == BACKUP_FORMAT_PBS) {
--        if (!task->has_password) {
--            error_set(task->errp, ERROR_CLASS_GENERIC_ERROR, "missing parameter 'password'");
-+        if (!has_password) {
-+            error_set(errp, ERROR_CLASS_GENERIC_ERROR, "missing parameter 'password'");
-             goto err_mutex;
-         }
--        if (!task->has_backup_id) {
--            error_set(task->errp, ERROR_CLASS_GENERIC_ERROR, "missing parameter 'backup-id'");
-+        if (!has_backup_id) {
-+            error_set(errp, ERROR_CLASS_GENERIC_ERROR, "missing parameter 'backup-id'");
-             goto err_mutex;
-         }
--        if (!task->has_backup_time) {
--            error_set(task->errp, ERROR_CLASS_GENERIC_ERROR, "missing parameter 'backup-time'");
-+        if (!has_backup_time) {
-+            error_set(errp, ERROR_CLASS_GENERIC_ERROR, "missing parameter 'backup-time'");
-             goto err_mutex;
-         }
-         int dump_cb_block_size = PROXMOX_BACKUP_DEFAULT_CHUNK_SIZE; // Hardcoded (4M)
-         firewall_name = "fw.conf";
--        bool use_dirty_bitmap = task->has_use_dirty_bitmap && task->use_dirty_bitmap;
--
--
-         char *pbs_err = NULL;
-         pbs = proxmox_backup_new(
--            task->backup_file,
--            task->backup_id,
--            task->backup_time,
-+            backup_file,
-+            backup_id,
-+            backup_time,
-             dump_cb_block_size,
--            task->has_password ? task->password : NULL,
--            task->has_keyfile ? task->keyfile : NULL,
--            task->has_key_password ? task->key_password : NULL,
--            task->has_compress ? task->compress : true,
--            task->has_encrypt ? task->encrypt : task->has_keyfile,
--            task->has_fingerprint ? task->fingerprint : NULL,
-+            has_password ? password : NULL,
-+            has_keyfile ? keyfile : NULL,
-+            has_key_password ? key_password : NULL,
-+            has_compress ? compress : true,
-+            has_encrypt ? encrypt : has_keyfile,
-+            has_fingerprint ? fingerprint : NULL,
-              &pbs_err);
-         if (!pbs) {
--            error_set(task->errp, ERROR_CLASS_GENERIC_ERROR,
-+            error_set(errp, ERROR_CLASS_GENERIC_ERROR,
-                       "proxmox_backup_new failed: %s", pbs_err);
-             proxmox_backup_free_error(pbs_err);
-             goto err_mutex;
-         }
--        int connect_result = proxmox_backup_co_connect(pbs, task->errp);
-+        int connect_result = proxmox_backup_co_connect(pbs, errp);
-         if (connect_result < 0)
-             goto err_mutex;
-@@ -741,9 +710,9 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-             BdrvDirtyBitmap *bitmap = bdrv_find_dirty_bitmap(di->bs, PBS_BITMAP_NAME);
-             bool expect_only_dirty = false;
--            if (use_dirty_bitmap) {
-+            if (has_use_dirty_bitmap && use_dirty_bitmap) {
-                 if (bitmap == NULL) {
--                    bitmap = bdrv_create_dirty_bitmap(di->bs, dump_cb_block_size, PBS_BITMAP_NAME, task->errp);
-+                    bitmap = bdrv_create_dirty_bitmap(di->bs, dump_cb_block_size, PBS_BITMAP_NAME, errp);
-                     if (!bitmap) {
-                         goto err_mutex;
-                     }
-@@ -773,12 +742,12 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-                 }
-             }
--            int dev_id = proxmox_backup_co_register_image(pbs, devname, di->size, expect_only_dirty, task->errp);
-+            int dev_id = proxmox_backup_co_register_image(pbs, devname, di->size, expect_only_dirty, errp);
-             if (dev_id < 0) {
-                 goto err_mutex;
-             }
--            if (!(di->target = bdrv_backup_dump_create(dump_cb_block_size, di->size, pvebackup_co_dump_pbs_cb, di, task->errp))) {
-+            if (!(di->target = bdrv_backup_dump_create(dump_cb_block_size, di->size, pvebackup_co_dump_pbs_cb, di, errp))) {
-                 goto err_mutex;
-             }
-@@ -792,10 +761,10 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-             backup_state.stat.bitmap_list = g_list_append(backup_state.stat.bitmap_list, info);
-         }
-     } else if (format == BACKUP_FORMAT_VMA) {
--        vmaw = vma_writer_create(task->backup_file, uuid, &local_err);
-+        vmaw = vma_writer_create(backup_file, uuid, &local_err);
-         if (!vmaw) {
-             if (local_err) {
--                error_propagate(task->errp, local_err);
-+                error_propagate(errp, local_err);
-             }
-             goto err_mutex;
-         }
-@@ -806,25 +775,25 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-             PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
-             l = g_list_next(l);
--            if (!(di->target = bdrv_backup_dump_create(VMA_CLUSTER_SIZE, di->size, pvebackup_co_dump_vma_cb, di, task->errp))) {
-+            if (!(di->target = bdrv_backup_dump_create(VMA_CLUSTER_SIZE, di->size, pvebackup_co_dump_vma_cb, di, errp))) {
-                 goto err_mutex;
-             }
-             const char *devname = bdrv_get_device_name(di->bs);
-             di->dev_id = vma_writer_register_stream(vmaw, devname, di->size);
-             if (di->dev_id <= 0) {
--                error_set(task->errp, ERROR_CLASS_GENERIC_ERROR,
-+                error_set(errp, ERROR_CLASS_GENERIC_ERROR,
-                           "register_stream failed");
-                 goto err_mutex;
-             }
-         }
-     } else if (format == BACKUP_FORMAT_DIR) {
--        if (mkdir(task->backup_file, 0640) != 0) {
--            error_setg_errno(task->errp, errno, "can't create directory '%s'\n",
--                             task->backup_file);
-+        if (mkdir(backup_file, 0640) != 0) {
-+            error_setg_errno(errp, errno, "can't create directory '%s'\n",
-+                             backup_file);
-             goto err_mutex;
-         }
--        backup_dir = task->backup_file;
-+        backup_dir = backup_file;
-         l = di_list;
-         while (l) {
-@@ -838,34 +807,34 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-             bdrv_img_create(di->targetfile, "raw", NULL, NULL, NULL,
-                             di->size, flags, false, &local_err);
-             if (local_err) {
--                error_propagate(task->errp, local_err);
-+                error_propagate(errp, local_err);
-                 goto err_mutex;
-             }
-             di->target = bdrv_open(di->targetfile, NULL, NULL, flags, &local_err);
-             if (!di->target) {
--                error_propagate(task->errp, local_err);
-+                error_propagate(errp, local_err);
-                 goto err_mutex;
-             }
-         }
-     } else {
--        error_set(task->errp, ERROR_CLASS_GENERIC_ERROR, "unknown backup format");
-+        error_set(errp, ERROR_CLASS_GENERIC_ERROR, "unknown backup format");
-         goto err_mutex;
-     }
-     /* add configuration file to archive */
--    if (task->has_config_file) {
--        if (pvebackup_co_add_config(task->config_file, config_name, format, backup_dir,
--                                    vmaw, pbs, task->errp) != 0) {
-+    if (has_config_file) {
-+        if (pvebackup_co_add_config(config_file, config_name, format, backup_dir,
-+                                    vmaw, pbs, errp) != 0) {
-             goto err_mutex;
-         }
-     }
-     /* add firewall file to archive */
--    if (task->has_firewall_file) {
--        if (pvebackup_co_add_config(task->firewall_file, firewall_name, format, backup_dir,
--                                    vmaw, pbs, task->errp) != 0) {
-+    if (has_firewall_file) {
-+        if (pvebackup_co_add_config(firewall_file, firewall_name, format, backup_dir,
-+                                    vmaw, pbs, errp) != 0) {
-             goto err_mutex;
-         }
-     }
-@@ -883,7 +852,7 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-     if (backup_state.stat.backup_file) {
-         g_free(backup_state.stat.backup_file);
-     }
--    backup_state.stat.backup_file = g_strdup(task->backup_file);
-+    backup_state.stat.backup_file = g_strdup(backup_file);
-     uuid_copy(backup_state.stat.uuid, uuid);
-     uuid_unparse_lower(uuid, backup_state.stat.uuid_str);
-@@ -898,7 +867,7 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-     qemu_mutex_unlock(&backup_state.stat.lock);
--    backup_state.speed = (task->has_speed && task->speed > 0) ? task->speed : 0;
-+    backup_state.speed = (has_speed && speed > 0) ? speed : 0;
-     backup_state.vmaw = vmaw;
-     backup_state.pbs = pbs;
-@@ -908,8 +877,6 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-     uuid_info = g_malloc0(sizeof(*uuid_info));
-     uuid_info->UUID = uuid_str;
--    task->result = uuid_info;
--
-     /* Run create_backup_jobs_bh outside of coroutine (in BH) but keep
-     * backup_mutex locked. This is fine, a CoMutex can be held across yield
-     * points, and we'll release it as soon as the BH reschedules us.
-@@ -923,7 +890,7 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-     qemu_coroutine_yield();
-     if (local_err) {
--        error_propagate(task->errp, local_err);
-+        error_propagate(errp, local_err);
-         goto err;
-     }
-@@ -936,7 +903,7 @@ static void coroutine_fn pvebackup_co_prepare(void *opaque)
-     /* start the first job in the transaction */
-     job_txn_start_seq(backup_state.txn);
--    return;
-+    return uuid_info;
- err_mutex:
-     qemu_mutex_unlock(&backup_state.stat.lock);
-@@ -967,7 +934,7 @@ err:
-     if (vmaw) {
-         Error *err = NULL;
-         vma_writer_close(vmaw, &err);
--        unlink(task->backup_file);
-+        unlink(backup_file);
-     }
-     if (pbs) {
-@@ -978,65 +945,8 @@ err:
-         rmdir(backup_dir);
-     }
--    task->result = NULL;
--
-     qemu_co_mutex_unlock(&backup_state.backup_mutex);
--    return;
--}
--
--UuidInfo *qmp_backup(
--    const char *backup_file,
--    bool has_password, const char *password,
--    bool has_keyfile, const char *keyfile,
--    bool has_key_password, const char *key_password,
--    bool has_fingerprint, const char *fingerprint,
--    bool has_backup_id, const char *backup_id,
--    bool has_backup_time, int64_t backup_time,
--    bool has_use_dirty_bitmap, bool use_dirty_bitmap,
--    bool has_compress, bool compress,
--    bool has_encrypt, bool encrypt,
--    bool has_format, BackupFormat format,
--    bool has_config_file, const char *config_file,
--    bool has_firewall_file, const char *firewall_file,
--    bool has_devlist, const char *devlist,
--    bool has_speed, int64_t speed, Error **errp)
--{
--    QmpBackupTask task = {
--        .backup_file = backup_file,
--        .has_password = has_password,
--        .password = password,
--        .has_keyfile = has_keyfile,
--        .keyfile = keyfile,
--        .has_key_password = has_key_password,
--        .key_password = key_password,
--        .has_fingerprint = has_fingerprint,
--        .fingerprint = fingerprint,
--        .has_backup_id = has_backup_id,
--        .backup_id = backup_id,
--        .has_backup_time = has_backup_time,
--        .backup_time = backup_time,
--        .has_use_dirty_bitmap = has_use_dirty_bitmap,
--        .use_dirty_bitmap = use_dirty_bitmap,
--        .has_compress = has_compress,
--        .compress = compress,
--        .has_encrypt = has_encrypt,
--        .encrypt = encrypt,
--        .has_format = has_format,
--        .format = format,
--        .has_config_file = has_config_file,
--        .config_file = config_file,
--        .has_firewall_file = has_firewall_file,
--        .firewall_file = firewall_file,
--        .has_devlist = has_devlist,
--        .devlist = devlist,
--        .has_speed = has_speed,
--        .speed = speed,
--        .errp = errp,
--    };
--
--    block_on_coroutine_fn(pvebackup_co_prepare, &task);
--
--    return task.result;
-+    return NULL;
- }
- BackupStatus *qmp_query_backup(Error **errp)
-diff --git a/qapi/block-core.json b/qapi/block-core.json
-index dee3d87efe..82133e2bee 100644
---- a/qapi/block-core.json
-+++ b/qapi/block-core.json
-@@ -847,7 +847,7 @@
-                                     '*config-file': 'str',
-                                     '*firewall-file': 'str',
-                                     '*devlist': 'str', '*speed': 'int' },
--  'returns': 'UuidInfo' }
-+  'returns': 'UuidInfo', 'coroutine': true }
- ##
- # @query-backup:
-@@ -869,7 +869,7 @@
- # Notes: This command succeeds even if there is no backup process running.
- #
- ##
--{ 'command': 'backup-cancel' }
-+{ 'command': 'backup-cancel', 'coroutine': true }
- ##
- # @ProxmoxSupportStatus:
diff --git a/debian/patches/pve/0059-PBS-add-master-key-support.patch b/debian/patches/pve/0059-PBS-add-master-key-support.patch
deleted file mode 100644 (file)
index 52e600c..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: Stefan Reiter <s.reiter@proxmox.com>
-Date: Wed, 10 Feb 2021 11:07:06 +0100
-Subject: [PATCH] PBS: add master key support
-MIME-Version: 1.0
-Content-Type: text/plain; charset=UTF-8
-Content-Transfer-Encoding: 8bit
-
-this requires a new enough libproxmox-backup-qemu0, and allows querying
-from the PVE side to avoid QMP calls with unsupported parameters.
-
-Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
-Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
----
- block/monitor/block-hmp-cmds.c | 1 +
- pve-backup.c                   | 3 +++
- qapi/block-core.json           | 7 +++++++
- 3 files changed, 11 insertions(+)
-
-diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c
-index 11c84d5508..0932deb28c 100644
---- a/block/monitor/block-hmp-cmds.c
-+++ b/block/monitor/block-hmp-cmds.c
-@@ -1036,6 +1036,7 @@ void coroutine_fn hmp_backup(Monitor *mon, const QDict *qdict)
-         false, NULL, // PBS password
-         false, NULL, // PBS keyfile
-         false, NULL, // PBS key_password
-+        false, NULL, // PBS master_keyfile
-         false, NULL, // PBS fingerprint
-         false, NULL, // PBS backup-id
-         false, 0, // PBS backup-time
-diff --git a/pve-backup.c b/pve-backup.c
-index f7597ae55c..0ecadf6ce6 100644
---- a/pve-backup.c
-+++ b/pve-backup.c
-@@ -531,6 +531,7 @@ UuidInfo coroutine_fn *qmp_backup(
-     bool has_password, const char *password,
-     bool has_keyfile, const char *keyfile,
-     bool has_key_password, const char *key_password,
-+    bool has_master_keyfile, const char *master_keyfile,
-     bool has_fingerprint, const char *fingerprint,
-     bool has_backup_id, const char *backup_id,
-     bool has_backup_time, int64_t backup_time,
-@@ -679,6 +680,7 @@ UuidInfo coroutine_fn *qmp_backup(
-             has_password ? password : NULL,
-             has_keyfile ? keyfile : NULL,
-             has_key_password ? key_password : NULL,
-+            has_master_keyfile ? master_keyfile : NULL,
-             has_compress ? compress : true,
-             has_encrypt ? encrypt : has_keyfile,
-             has_fingerprint ? fingerprint : NULL,
-@@ -1041,5 +1043,6 @@ ProxmoxSupportStatus *qmp_query_proxmox_support(Error **errp)
-     ret->pbs_dirty_bitmap = true;
-     ret->query_bitmap_info = true;
-     ret->pbs_dirty_bitmap_migration = true;
-+    ret->pbs_masterkey = true;
-     return ret;
- }
-diff --git a/qapi/block-core.json b/qapi/block-core.json
-index 82133e2bee..be3d6a0d37 100644
---- a/qapi/block-core.json
-+++ b/qapi/block-core.json
-@@ -818,6 +818,8 @@
- #
- # @key-password: password for keyfile (optional for format 'pbs')
- #
-+# @master-keyfile: PEM-formatted master public keyfile (optional for format 'pbs')
-+#
- # @fingerprint: server cert fingerprint (optional for format 'pbs')
- #
- # @backup-id: backup ID (required for format 'pbs')
-@@ -837,6 +839,7 @@
-                                     '*password': 'str',
-                                     '*keyfile': 'str',
-                                     '*key-password': 'str',
-+                                    '*master-keyfile': 'str',
-                                     '*fingerprint': 'str',
-                                     '*backup-id': 'str',
-                                     '*backup-time': 'int',
-@@ -886,6 +889,9 @@
- #                              migration cap if this is false/unset may lead
- #                              to crashes on migration!
- #
-+# @pbs-masterkey: True if the QMP backup call supports the 'master_keyfile'
-+#                 parameter.
-+#
- # @pbs-library-version: Running version of libproxmox-backup-qemu0 library.
- #
- ##
-@@ -893,6 +899,7 @@
-   'data': { 'pbs-dirty-bitmap': 'bool',
-             'query-bitmap-info': 'bool',
-             'pbs-dirty-bitmap-migration': 'bool',
-+            'pbs-masterkey': 'bool',
-             'pbs-library-version': 'str' } }
- ##
index 6539603e4212e3ee5c5b5a58b937ff219e6b9c68..61ecf5dae533c4d0dac4a57d9a32082693510d10 100644 (file)
@@ -35,33 +35,23 @@ pve/0026-PVE-Backup-add-vma-backup-format-code.patch
 pve/0027-PVE-Backup-add-backup-dump-block-driver.patch
 pve/0028-PVE-Backup-proxmox-backup-patches-for-qemu.patch
 pve/0029-PVE-Backup-pbs-restore-new-command-to-restore-from-p.patch
-pve/0030-PVE-Backup-avoid-coroutines-to-fix-AIO-freeze-cleanu.patch
-pve/0031-drive-mirror-add-support-for-sync-bitmap-mode-never.patch
-pve/0032-drive-mirror-add-support-for-conditional-and-always-.patch
-pve/0033-mirror-add-check-for-bitmap-mode-without-bitmap.patch
-pve/0034-mirror-switch-to-bdrv_dirty_bitmap_merge_internal.patch
-pve/0035-iotests-add-test-for-bitmap-mirror.patch
-pve/0036-mirror-move-some-checks-to-qmp.patch
-pve/0037-PVE-Backup-Add-dirty-bitmap-tracking-for-incremental.patch
-pve/0038-PVE-backup-rename-incremental-to-use-dirty-bitmap.patch
-pve/0039-PVE-fixup-pbs-restore-API.patch
-pve/0040-PVE-always-set-dirty-counter-for-non-incremental-bac.patch
-pve/0041-PVE-use-proxmox_backup_check_incremental.patch
-pve/0042-PVE-fixup-pbs-backup-add-compress-and-encrypt-option.patch
-pve/0043-PVE-Add-PBS-block-driver-to-map-backup-archives-into.patch
-pve/0044-PVE-add-query_proxmox_support-QMP-command.patch
-pve/0045-pbs-fix-missing-crypt-and-compress-parameters.patch
-pve/0046-PVE-handle-PBS-write-callback-with-big-blocks-correc.patch
-pve/0047-PVE-add-zero-block-handling-to-PBS-dump-callback.patch
-pve/0048-PVE-add-query-pbs-bitmap-info-QMP-call.patch
-pve/0049-PVE-redirect-stderr-to-journal-when-daemonized.patch
-pve/0050-PVE-Add-sequential-job-transaction-support.patch
-pve/0051-PVE-Backup-Use-a-transaction-to-synchronize-job-stat.patch
-pve/0052-PVE-Backup-Use-more-coroutines-and-don-t-block-on-fi.patch
-pve/0053-PVE-fix-and-clean-up-error-handling-for-create_backu.patch
-pve/0054-PVE-Migrate-dirty-bitmap-state-via-savevm.patch
-pve/0055-migration-block-dirty-bitmap-migrate-other-bitmaps-e.patch
-pve/0056-PVE-fix-aborting-multiple-CREATED-jobs-in-sequential.patch
-pve/0057-PVE-fall-back-to-open-iscsi-initiatorname.patch
-pve/0058-PVE-Use-coroutine-QMP-for-backup-cancel_backup.patch
-pve/0059-PBS-add-master-key-support.patch
+pve/0030-drive-mirror-add-support-for-sync-bitmap-mode-never.patch
+pve/0031-drive-mirror-add-support-for-conditional-and-always-.patch
+pve/0032-mirror-add-check-for-bitmap-mode-without-bitmap.patch
+pve/0033-mirror-switch-to-bdrv_dirty_bitmap_merge_internal.patch
+pve/0034-iotests-add-test-for-bitmap-mirror.patch
+pve/0035-mirror-move-some-checks-to-qmp.patch
+pve/0036-PVE-Backup-Add-dirty-bitmap-tracking-for-incremental.patch
+pve/0037-PVE-various-PBS-fixes.patch
+pve/0038-PVE-Add-PBS-block-driver-to-map-backup-archives-into.patch
+pve/0039-PVE-add-query_proxmox_support-QMP-command.patch
+pve/0040-PVE-add-query-pbs-bitmap-info-QMP-call.patch
+pve/0041-PVE-redirect-stderr-to-journal-when-daemonized.patch
+pve/0042-PVE-Add-sequential-job-transaction-support.patch
+pve/0043-PVE-Backup-Use-a-transaction-to-synchronize-job-stat.patch
+pve/0044-PVE-Backup-Don-t-block-on-finishing-and-cleanup-crea.patch
+pve/0045-PVE-Migrate-dirty-bitmap-state-via-savevm.patch
+pve/0046-migration-block-dirty-bitmap-migrate-other-bitmaps-e.patch
+pve/0047-PVE-fall-back-to-open-iscsi-initiatorname.patch
+pve/0048-PVE-Use-coroutine-QMP-for-backup-cancel_backup.patch
+pve/0049-PBS-add-master-key-support.patch