From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <pve-devel-bounces@lists.proxmox.com> Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 03F2E1FF16E for <inbox@lore.proxmox.com>; Mon, 31 Mar 2025 15:20:54 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 3BAF44B64; Mon, 31 Mar 2025 15:20:30 +0200 (CEST) From: Fiona Ebner <f.ebner@proxmox.com> To: pve-devel@lists.proxmox.com Date: Mon, 31 Mar 2025 15:19:46 +0200 Message-Id: <20250331132020.105324-4-f.ebner@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250331132020.105324-1-f.ebner@proxmox.com> References: <20250331132020.105324-1-f.ebner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.040 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 Subject: [pve-devel] [PATCH qemu v6 03/37] PVE backup: factor out helper to initialize backup state stat struct X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/> List-Post: <mailto:pve-devel@lists.proxmox.com> List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com> Suggested-by: Wolfgang Bumiller <w.bumiller@proxmox.com> Signed-off-by: Fiona Ebner <f.ebner@proxmox.com> --- New in v6. pve-backup.c | 62 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/pve-backup.c b/pve-backup.c index 915649b5f9..88a981f81c 100644 --- a/pve-backup.c +++ b/pve-backup.c @@ -828,6 +828,43 @@ static void clear_backup_state_bitmap_list(void) { } } +/* + * Initializes most of the backup state 'stat' struct. Note that 'reused' and + * 'bitmap_list' are not changed by this function and need to be handled by + * the caller. In particular, 'reused' needs to be set before calling this + * function. + * + * To be called with the backup_state.stat mutex held. + */ +static void initialize_backup_state_stat( + const char *backup_file, + uuid_t uuid, + size_t total) +{ + if (backup_state.stat.error) { + error_free(backup_state.stat.error); + backup_state.stat.error = NULL; + } + + backup_state.stat.start_time = time(NULL); + backup_state.stat.end_time = 0; + + if (backup_state.stat.backup_file) { + g_free(backup_state.stat.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); + + backup_state.stat.total = total; + 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; +} + UuidInfo coroutine_fn *qmp_backup( const char *backup_file, const char *password, @@ -1070,32 +1107,9 @@ UuidInfo coroutine_fn *qmp_backup( } } /* initialize global backup_state now */ - /* note: 'reused' and 'bitmap_list' are initialized earlier */ - - if (backup_state.stat.error) { - error_free(backup_state.stat.error); - backup_state.stat.error = NULL; - } - - backup_state.stat.start_time = time(NULL); - backup_state.stat.end_time = 0; - - if (backup_state.stat.backup_file) { - g_free(backup_state.stat.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); + initialize_backup_state_stat(backup_file, uuid, total); char *uuid_str = g_strdup(backup_state.stat.uuid_str); - backup_state.stat.total = total; - 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); backup_state.speed = (has_speed && speed > 0) ? speed : 0; -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel