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 [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id D3DEE1FF16B for <inbox@lore.proxmox.com>; Thu, 3 Apr 2025 14:31:40 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D46EA3F7BF; Thu, 3 Apr 2025 14:31:23 +0200 (CEST) From: Wolfgang Bumiller <w.bumiller@proxmox.com> To: pve-devel@lists.proxmox.com Date: Thu, 3 Apr 2025 14:30:43 +0200 Message-Id: <20250403123118.264974-4-w.bumiller@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250403123118.264974-1-w.bumiller@proxmox.com> References: <20250403123118.264974-1-w.bumiller@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.080 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 v8 qemu 03/10] 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> From: Fiona Ebner <f.ebner@proxmox.com> Suggested-by: Wolfgang Bumiller <w.bumiller@proxmox.com> Signed-off-by: Fiona Ebner <f.ebner@proxmox.com> Reviewed-by: Wolfgang Bumiller <w.bumiller@proxmox.com> --- No changes to v7. 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