From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id C2E3A90E44 for ; Thu, 25 Jan 2024 15:42:24 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 97DB71B9A0 for ; Thu, 25 Jan 2024 15:41:54 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Thu, 25 Jan 2024 15:41:53 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 58B5F492AB for ; Thu, 25 Jan 2024 15:41:53 +0100 (CET) From: Fiona Ebner To: pve-devel@lists.proxmox.com Date: Thu, 25 Jan 2024 15:41:37 +0100 Message-Id: <20240125144149.216064-2-f.ebner@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240125144149.216064-1-f.ebner@proxmox.com> References: <20240125144149.216064-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.075 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pve-devel] [PATCH qemu 01/13] backup: factor out gathering device info into helper X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Jan 2024 14:42:24 -0000 no functional change intended. Should make it easier to read and add more logic on top (for backup fleecing). Signed-off-by: Fiona Ebner --- 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