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 9F4D41FF172
	for <inbox@lore.proxmox.com>; Tue,  1 Apr 2025 19:37:46 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id C78C1190C;
	Tue,  1 Apr 2025 19:35:13 +0200 (CEST)
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Tue,  1 Apr 2025 19:34:05 +0200
Message-Id: <20250401173435.221892-8-f.ebner@proxmox.com>
X-Mailer: git-send-email 2.39.5
In-Reply-To: <20250401173435.221892-1-f.ebner@proxmox.com>
References: <20250401173435.221892-1-f.ebner@proxmox.com>
MIME-Version: 1.0
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.038 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 v7 07/37] 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>

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---

New in v7.

 pve-backup.c | 86 ++++++++++++++++++++++++++++++----------------------
 1 file changed, 49 insertions(+), 37 deletions(-)

diff --git a/pve-backup.c b/pve-backup.c
index 091b5bd231..04583f2b89 100644
--- a/pve-backup.c
+++ b/pve-backup.c
@@ -760,6 +760,53 @@ 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);
+            return NULL;
+        }
+        BlockDriverState *fleecing_bs = blk_bs(fleecing_blk);
+        if (!bdrv_co_is_inserted(fleecing_bs)) {
+            error_setg(errp, "Device '%s' has no medium", fleecing_devid);
+            return NULL;
+        }
+        /*
+         * 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);
+            return NULL;
+        }
+        di->fleecing.bs = fleecing_bs;
+    }
+
+    return di;
+}
+
 /*
  * 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 +825,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