From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <f.ebner@proxmox.com>
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 9605190DE5
 for <pve-devel@lists.proxmox.com>; 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 75D7E1B99D
 for <pve-devel@lists.proxmox.com>; 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) server-digest SHA256)
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS
 for <pve-devel@lists.proxmox.com>; 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 2C11E492A7
 for <pve-devel@lists.proxmox.com>; Thu, 25 Jan 2024 15:41:53 +0100 (CET)
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Thu, 25 Jan 2024 15:41:38 +0100
Message-Id: <20240125144149.216064-3-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 02/13] backup: get device info: code cleanup
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>
X-List-Received-Date: Thu, 25 Jan 2024 14:42:24 -0000

Make variables more local. Put failure case for !blk first to avoid
an additional else block with indentation.

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

Can be squashed into "PVE-Backup: Proxmox backup patches for QEMU".

 pve-backup.c | 27 +++++++++++----------------
 1 file changed, 11 insertions(+), 16 deletions(-)

diff --git a/pve-backup.c b/pve-backup.c
index 75af865437..4b0dcca246 100644
--- a/pve-backup.c
+++ b/pve-backup.c
@@ -585,8 +585,6 @@ static GList coroutine_fn *get_device_info(
     const char *devlist,
     Error **errp)
 {
-    BlockBackend *blk;
-    BlockDriverState *bs = NULL;
     gchar **devs = NULL;
     GList *di_list = NULL;
 
@@ -595,29 +593,26 @@ static GList coroutine_fn *get_device_info(
 
         gchar **d = devs;
         while (d && *d) {
-            blk = blk_by_name(*d);
-            if (blk) {
-                bs = blk_bs(blk);
-                if (!bdrv_co_is_inserted(bs)) {
-                    error_setg(errp, QERR_DEVICE_HAS_NO_MEDIUM, *d);
-                    goto err;
-                }
-                PVEBackupDevInfo *di = g_new0(PVEBackupDevInfo, 1);
-                di->bs = bs;
-                di_list = g_list_append(di_list, di);
-            } else {
+            BlockBackend *blk = blk_by_name(*d);
+            if (!blk) {
                 error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
                           "Device '%s' not found", *d);
                 goto err;
             }
+            BlockDriverState *bs = blk_bs(blk);
+            if (!bdrv_co_is_inserted(bs)) {
+                error_setg(errp, QERR_DEVICE_HAS_NO_MEDIUM, *d);
+                goto err;
+            }
+            PVEBackupDevInfo *di = g_new0(PVEBackupDevInfo, 1);
+            di->bs = bs;
+            di_list = g_list_append(di_list, di);
             d++;
         }
-
     } else {
         BdrvNextIterator it;
 
-        bs = NULL;
-        for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
+        for (BlockDriverState *bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
             if (!bdrv_co_is_inserted(bs) || bdrv_is_read_only(bs)) {
                 continue;
             }
-- 
2.39.2