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 C959E1FF16B for <inbox@lore.proxmox.com>; Thu, 3 Apr 2025 14:32:01 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id AF2053F8F4; Thu, 3 Apr 2025 14:31:25 +0200 (CEST) From: Wolfgang Bumiller <w.bumiller@proxmox.com> To: pve-devel@lists.proxmox.com Date: Thu, 3 Apr 2025 14:30:47 +0200 Message-Id: <20250403123118.264974-8-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.079 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 07/10] PVE backup: factor out get_single_device_info() helper 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> Signed-off-by: Fiona Ebner <f.ebner@proxmox.com> [WB: free di and di->device_name on error] Sigend-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com> --- Changes in v8: described in the trailers above ^ pve-backup.c | 90 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 37 deletions(-) diff --git a/pve-backup.c b/pve-backup.c index 091b5bd231..8b7414f057 100644 --- a/pve-backup.c +++ b/pve-backup.c @@ -760,6 +760,57 @@ static bool fleecing_all(const char *device_id) return true; } +static PVEBackupDevInfo coroutine_fn GRAPH_RDLOCK *get_single_device_info( + const char *device, + bool (*device_uses_fleecing)(const char*), + Error **errp) +{ + BlockBackend *blk = blk_by_name(device); + if (!blk) { + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", device); + return NULL; + } + BlockDriverState *bs = blk_bs(blk); + if (!bdrv_co_is_inserted(bs)) { + error_setg(errp, "Device '%s' has no medium", device); + return NULL; + } + PVEBackupDevInfo *di = g_new0(PVEBackupDevInfo, 1); + di->bs = bs; + di->device_name = g_strdup(bdrv_get_device_name(bs)); + + if (device_uses_fleecing && device_uses_fleecing(device)) { + g_autofree gchar *fleecing_devid = g_strconcat(device, "-fleecing", NULL); + BlockBackend *fleecing_blk = blk_by_name(fleecing_devid); + if (!fleecing_blk) { + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", fleecing_devid); + goto fail; + } + BlockDriverState *fleecing_bs = blk_bs(fleecing_blk); + if (!bdrv_co_is_inserted(fleecing_bs)) { + error_setg(errp, "Device '%s' has no medium", fleecing_devid); + goto fail; + } + /* + * Fleecing image needs to be the same size to act as a cbw target. + */ + if (bs->total_sectors != fleecing_bs->total_sectors) { + error_setg(errp, "Size mismatch for '%s' - sector count %ld != %ld", + fleecing_devid, fleecing_bs->total_sectors, bs->total_sectors); + goto fail; + } + di->fleecing.bs = fleecing_bs; + } + + return di; +fail: + g_free(di->device_name); + g_free(di); + return NULL; +} + /* * 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 @@ -778,45 +829,10 @@ static GList coroutine_fn GRAPH_RDLOCK *get_device_info( 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); + PVEBackupDevInfo *di = get_single_device_info(*d, device_uses_fleecing, errp); + if (!di) { goto err; } - BlockDriverState *bs = blk_bs(blk); - if (!bdrv_co_is_inserted(bs)) { - error_setg(errp, "Device '%s' has no medium", *d); - goto err; - } - PVEBackupDevInfo *di = g_new0(PVEBackupDevInfo, 1); - di->bs = bs; - di->device_name = g_strdup(bdrv_get_device_name(bs)); - - if (device_uses_fleecing && device_uses_fleecing(*d)) { - g_autofree gchar *fleecing_devid = g_strconcat(*d, "-fleecing", NULL); - BlockBackend *fleecing_blk = blk_by_name(fleecing_devid); - if (!fleecing_blk) { - error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, - "Device '%s' not found", fleecing_devid); - goto err; - } - BlockDriverState *fleecing_bs = blk_bs(fleecing_blk); - if (!bdrv_co_is_inserted(fleecing_bs)) { - error_setg(errp, "Device '%s' has no medium", fleecing_devid); - goto err; - } - /* - * Fleecing image needs to be the same size to act as a cbw target. - */ - if (bs->total_sectors != fleecing_bs->total_sectors) { - error_setg(errp, "Size mismatch for '%s' - sector count %ld != %ld", - fleecing_devid, fleecing_bs->total_sectors, bs->total_sectors); - goto err; - } - di->fleecing.bs = fleecing_bs; - } - di_list = g_list_append(di_list, di); d++; } -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel