]> git.proxmox.com Git - pve-qemu.git/commitdiff
backup: factor out & clean up gathering device info into helper
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 12 Mar 2024 12:54:59 +0000 (13:54 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 12 Mar 2024 12:55:00 +0000 (13:55 +0100)
Squash the two original patches [0][1] from Fiona, which got send
separate to be easier to review, into the big patch that adds the
Proxmox backup integration.

[0]: https://lists.proxmox.com/pipermail/pve-devel/2024-January/061479.html
[1]: https://lists.proxmox.com/pipermail/pve-devel/2024-January/061478.html

Originally-by: Fiona Ebner <f.ebner@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
debian/patches/pve/0016-PVE-add-IOChannel-implementation-for-savevm-async.patch
debian/patches/pve/0030-PVE-Backup-Proxmox-backup-patches-for-QEMU.patch
debian/patches/pve/0034-PVE-Migrate-dirty-bitmap-state-via-savevm.patch
debian/patches/pve/0040-Revert-block-rbd-workaround-for-ceph-issue-53784.patch
debian/patches/pve/0041-Revert-block-rbd-fix-handling-of-holes-in-.bdrv_co_b.patch
debian/patches/pve/0042-Revert-block-rbd-implement-bdrv_co_block_status.patch
debian/patches/pve/0043-alloc-track-fix-deadlock-during-drop.patch
debian/patches/pve/0044-migration-for-snapshots-hold-the-BQL-during-setup-ca.patch
debian/patches/pve/0045-savevm-async-don-t-hold-BQL-during-setup.patch

index 40c9b3284d327c8c69dee68dc56dfcefb2411602..df086e3140d436148680f867ee38e27e1e6d796c 100644 (file)
@@ -14,6 +14,7 @@ Additionally, allows tracking the current position from the outside
 (intended to be used for progress tracking).
 
 Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
+Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
 ---
  migration/channel-savevm-async.c | 183 +++++++++++++++++++++++++++++++
  migration/channel-savevm-async.h |  51 +++++++++
index 054e31c494eae373e00fee984ddd80cc92ee494e..8bc528e33760fae9a29cf50bf863b0668f779cac 100644 (file)
@@ -94,11 +94,11 @@ Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
  monitor/hmp-cmds.c             |   72 +++
  proxmox-backup-client.c        |  146 +++++
  proxmox-backup-client.h        |   60 ++
- pve-backup.c                   | 1072 ++++++++++++++++++++++++++++++++
+ pve-backup.c                   | 1089 ++++++++++++++++++++++++++++++++
  qapi/block-core.json           |  229 +++++++
  qapi/common.json               |   14 +
  qapi/machine.json              |   16 +-
- 14 files changed, 1687 insertions(+), 14 deletions(-)
+ 14 files changed, 1704 insertions(+), 14 deletions(-)
  create mode 100644 proxmox-backup-client.c
  create mode 100644 proxmox-backup-client.h
  create mode 100644 pve-backup.c
@@ -586,10 +586,10 @@ index 0000000000..8cbf645b2c
 +#endif /* PROXMOX_BACKUP_CLIENT_H */
 diff --git a/pve-backup.c b/pve-backup.c
 new file mode 100644
-index 0000000000..5ed3c6a310
+index 0000000000..ae3d137e12
 --- /dev/null
 +++ b/pve-backup.c
-@@ -0,0 +1,1072 @@
+@@ -0,0 +1,1089 @@
 +#include "proxmox-backup-client.h"
 +#include "vma.h"
 +
@@ -1173,6 +1173,66 @@ index 0000000000..5ed3c6a310
 +    aio_co_enter(data->ctx, data->co);
 +}
 +
++/*
++ * Returns a list of device infos, which needs to be freed by the caller. In
++ * case of an error, errp will be set, but the returned value might still be a
++ * list.
++ */
++static GList coroutine_fn *get_device_info(
++    const char *devlist,
++    Error **errp)
++{
++    gchar **devs = NULL;
++    GList *di_list = NULL;
++
++    if (devlist) {
++        devs = g_strsplit_set(devlist, ",;:", -1);
++
++        gchar **d = devs;
++        while (d && *d) {
++            BlockBackend *blk = blk_by_name(*d);
++            if (!blk) {
++                error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
++                          "Device '%s' not found", *d);
++                goto err;
++            }
++            BlockDriverState *bs = blk_bs(blk);
++            if (!bdrv_co_is_inserted(bs)) {
++                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);
++            d++;
++        }
++    } else {
++        BdrvNextIterator it;
++
++        for (BlockDriverState *bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
++            if (!bdrv_co_is_inserted(bs) || bdrv_is_read_only(bs)) {
++                continue;
++            }
++
++            PVEBackupDevInfo *di = g_new0(PVEBackupDevInfo, 1);
++            di->bs = bs;
++            di_list = g_list_append(di_list, di);
++        }
++    }
++
++    if (!di_list) {
++        error_set(errp, ERROR_CLASS_GENERIC_ERROR, "empty device list");
++        goto err;
++    }
++
++err:
++    if (devs) {
++        g_strfreev(devs);
++    }
++
++    return di_list;
++}
++
 +UuidInfo coroutine_fn *qmp_backup(
 +    const char *backup_file,
 +    const char *password,
@@ -1198,13 +1258,10 @@ index 0000000000..5ed3c6a310
 +
 +    qemu_co_mutex_lock(&backup_state.backup_mutex);
 +
-+    BlockBackend *blk;
-+    BlockDriverState *bs = NULL;
 +    Error *local_err = NULL;
 +    uuid_t uuid;
 +    VmaWriter *vmaw = NULL;
 +    ProxmoxBackupHandle *pbs = NULL;
-+    gchar **devs = NULL;
 +    GList *di_list = NULL;
 +    GList *l;
 +    UuidInfo *uuid_info;
@@ -1222,48 +1279,12 @@ index 0000000000..5ed3c6a310
 +    /* Todo: try to auto-detect format based on file name */
 +    format = has_format ? format : BACKUP_FORMAT_VMA;
 +
-+    if (devlist) {
-+        devs = g_strsplit_set(devlist, ",;:", -1);
-+
-+        gchar **d = devs;
-+        while (d && *d) {
-+            blk = blk_by_name(*d);
-+            if (blk) {
-+                bs = blk_bs(blk);
-+                if (!bdrv_co_is_inserted(bs)) {
-+                    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(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
-+                          "Device '%s' not found", *d);
-+                goto err;
-+            }
-+            d++;
-+        }
-+
-+    } else {
-+        BdrvNextIterator it;
-+
-+        bs = NULL;
-+        for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
-+            if (!bdrv_co_is_inserted(bs) || bdrv_is_read_only(bs)) {
-+                continue;
-+            }
-+
-+            PVEBackupDevInfo *di = g_new0(PVEBackupDevInfo, 1);
-+            di->bs = bs;
-+            di_list = g_list_append(di_list, di);
-+        }
-+    }
-+
-+    if (!di_list) {
-+        error_set(errp, ERROR_CLASS_GENERIC_ERROR, "empty device list");
++    di_list = get_device_info(devlist, &local_err);
++    if (local_err) {
++        error_propagate(errp, local_err);
 +        goto err;
 +    }
++    assert(di_list);
 +
 +    size_t total = 0;
 +
@@ -1551,10 +1572,6 @@ index 0000000000..5ed3c6a310
 +    g_list_free(di_list);
 +    backup_state.di_list = NULL;
 +
-+    if (devs) {
-+        g_strfreev(devs);
-+    }
-+
 +    if (vmaw) {
 +        Error *err = NULL;
 +        vma_writer_close(vmaw, &err);
index dffe12ccaf4270ed675280c0c89502a89012eca6..1015db38575b6359f49e5e396b9f246437e7331f 100644 (file)
@@ -174,10 +174,10 @@ index 0000000000..887e998b9e
 +                         NULL);
 +}
 diff --git a/pve-backup.c b/pve-backup.c
-index 5ed3c6a310..6720e985bc 100644
+index ae3d137e12..e6b17b797e 100644
 --- a/pve-backup.c
 +++ b/pve-backup.c
-@@ -1065,6 +1065,7 @@ ProxmoxSupportStatus *qmp_query_proxmox_support(Error **errp)
+@@ -1082,6 +1082,7 @@ ProxmoxSupportStatus *qmp_query_proxmox_support(Error **errp)
      ret->pbs_library_version = g_strdup(proxmox_backup_qemu_version());
      ret->pbs_dirty_bitmap = true;
      ret->pbs_dirty_bitmap_savevm = true;
index e60e74f26a479704b5770cd7f870b830149f424c..094f353e74b960162a9c7e9d667ed8863ad029f7 100644 (file)
@@ -7,6 +7,7 @@ This reverts commit fc176116cdea816ceb8dd969080b2b95f58edbc0 in
 preparation to revert 0347a8fd4c3faaedf119be04c197804be40a384b.
 
 Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
+Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
 ---
  block/rbd.c | 42 ++----------------------------------------
  1 file changed, 2 insertions(+), 40 deletions(-)
index e5fad0878ae86cf04321bfe2079916a82dfd39d1..e4aca7355f6b37bab7433c3b0afbaad4411bf760 100644 (file)
@@ -8,6 +8,7 @@ This reverts commit 9e302f64bb407a9bb097b626da97228c2654cfee in
 preparation to revert 0347a8fd4c3faaedf119be04c197804be40a384b.
 
 Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
+Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
 ---
  block/rbd.c | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)
index 7e1ee52bce40cb658b9ff8bda6f26ae517d67e47..9e9a385610919b5c381eb792625f1b27e850fd27 100644 (file)
@@ -18,6 +18,7 @@ Upstream bug report:
 https://gitlab.com/qemu-project/qemu/-/issues/1026
 
 Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
+Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
 ---
  block/rbd.c | 112 ----------------------------------------------------
  1 file changed, 112 deletions(-)
index 81694455458f17d1f8203e312eb68f9105b99ae8..153b8efd0c014e5cdde28d0a29243765ecb49aaa 100644 (file)
@@ -67,6 +67,7 @@ general to not leave unnecessary block nodes lying around.
 
 Suggested-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
 Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
+Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
 ---
  block/alloc-track.c | 54 ++++++++++++++-------------------------------
  1 file changed, 16 insertions(+), 38 deletions(-)
index 3fa7ef79b78577e6a190ae44e9dc32a60367bab5..635f64a883bc84da09d06acedebf1d64a8a37f3a 100644 (file)
@@ -43,6 +43,7 @@ callbacks that need the BQL and only take the lock if it's not already
 held.
 
 Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
+Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
 ---
  include/migration/register.h   |  2 +-
  migration/block-dirty-bitmap.c | 15 ++++++++++++---
index 3ff0bf7e8184d4be0118e4c39ba9a30fb9b35104..ac00f1ac21a2656bd77c585872743a04283092ba 100644 (file)
@@ -8,6 +8,7 @@ callbacks" for why. This is separate, because a version of that one
 will hopefully land upstream.
 
 Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
+Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
 ---
  migration/savevm-async.c | 2 --
  1 file changed, 2 deletions(-)