[pve-devel] [PATCH qemu 01/13] backup: factor out gathering device info into helper
Fiona Ebner
f.ebner at proxmox.com
Thu Jan 25 15:41:37 CET 2024
no functional change intended. Should make it easier to read and add
more logic on top (for backup fleecing).
Signed-off-by: Fiona Ebner <f.ebner at proxmox.com>
---
git diff --patience to produce a better diff
Can be squashed into "PVE-Backup: Proxmox backup patches for QEMU".
pve-backup.c | 112 ++++++++++++++++++++++++++++++---------------------
1 file changed, 67 insertions(+), 45 deletions(-)
diff --git a/pve-backup.c b/pve-backup.c
index 9c8b88d075..75af865437 100644
--- a/pve-backup.c
+++ b/pve-backup.c
@@ -576,54 +576,19 @@ static void create_backup_jobs_bh(void *opaque) {
aio_co_enter(data->ctx, data->co);
}
-UuidInfo coroutine_fn *qmp_backup(
- const char *backup_file,
- const char *password,
- const char *keyfile,
- const char *key_password,
- const char *master_keyfile,
- const char *fingerprint,
- const char *backup_ns,
- 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,
- const char *config_file,
- const char *firewall_file,
+/*
+ * 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,
- bool has_speed, int64_t speed,
- bool has_max_workers, int64_t max_workers,
Error **errp)
{
- assert(qemu_in_coroutine());
-
- 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;
-
- const char *config_name = "qemu-server.conf";
- const char *firewall_name = "qemu-server.fw";
-
- if (backup_state.di_list) {
- error_set(errp, ERROR_CLASS_GENERIC_ERROR,
- "previous backup not finished");
- qemu_co_mutex_unlock(&backup_state.backup_mutex);
- return NULL;
- }
-
- /* 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);
@@ -668,6 +633,67 @@ UuidInfo coroutine_fn *qmp_backup(
goto err;
}
+err:
+ if (devs) {
+ g_strfreev(devs);
+ }
+
+ return di_list;
+}
+
+UuidInfo coroutine_fn *qmp_backup(
+ const char *backup_file,
+ const char *password,
+ const char *keyfile,
+ const char *key_password,
+ const char *master_keyfile,
+ const char *fingerprint,
+ const char *backup_ns,
+ 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,
+ const char *config_file,
+ const char *firewall_file,
+ const char *devlist,
+ bool has_speed, int64_t speed,
+ bool has_max_workers, int64_t max_workers,
+ Error **errp)
+{
+ assert(qemu_in_coroutine());
+
+ qemu_co_mutex_lock(&backup_state.backup_mutex);
+
+ Error *local_err = NULL;
+ uuid_t uuid;
+ VmaWriter *vmaw = NULL;
+ ProxmoxBackupHandle *pbs = NULL;
+ GList *di_list = NULL;
+ GList *l;
+ UuidInfo *uuid_info;
+
+ const char *config_name = "qemu-server.conf";
+ const char *firewall_name = "qemu-server.fw";
+
+ if (backup_state.di_list) {
+ error_set(errp, ERROR_CLASS_GENERIC_ERROR,
+ "previous backup not finished");
+ qemu_co_mutex_unlock(&backup_state.backup_mutex);
+ return NULL;
+ }
+
+ /* Todo: try to auto-detect format based on file name */
+ format = has_format ? format : BACKUP_FORMAT_VMA;
+
+ 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;
l = di_list;
@@ -954,10 +980,6 @@ err:
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);
--
2.39.2
More information about the pve-devel
mailing list