[PATCH v2] qemu_block: Refactor qemuBlockExportAddNBD()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is v2 of: https://listman.redhat.com/archives/libvir-list/2021-October/msg01035.html

Diff to v1:
* negation of 'if' with switched body (proposed by Peter)

Signed-off-by: Kristina Hanicova <khanicov@xxxxxxxxxx>
---
 src/qemu/qemu_block.c | 33 +++++++++++++--------------------
 1 file changed, 13 insertions(+), 20 deletions(-)

diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index 34fdec2c4b..b8e70f6a83 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -3592,28 +3592,21 @@ qemuBlockExportAddNBD(virDomainObj *vm,
                       const char *bitmap)
 {
     qemuDomainObjPrivate *priv = vm->privateData;
+    g_autoptr(virJSONValue) nbdprops = NULL;
+    const char *bitmaps[2] = { bitmap, NULL };
 
-    if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) {
-        if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCK_EXPORT_ADD)) {
-            g_autoptr(virJSONValue) nbdprops = NULL;
-            const char *bitmaps[2] = { bitmap, NULL };
+    /* older qemu versions didn't support configuring the exportname and
+     * took the 'drivealias' as the export name */
+    if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV))
+        return qemuMonitorNBDServerAdd(priv->mon, drivealias, NULL, writable, NULL);
 
-            if (!(nbdprops = qemuBlockExportGetNBDProps(src->nodeformat,
-                                                        exportname,
-                                                        writable,
-                                                        bitmaps)))
-                return -1;
+    if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCK_EXPORT_ADD))
+        return qemuMonitorNBDServerAdd(priv->mon, src->nodeformat,
+                                       exportname, writable, bitmap);
 
-            return qemuMonitorBlockExportAdd(priv->mon, &nbdprops);
-        } else {
-            return qemuMonitorNBDServerAdd(priv->mon, src->nodeformat,
-                                           exportname, writable, bitmap);
-        }
-    } else {
-        /* older qemu versions didn't support configuring the exportname and
-         * took the 'drivealias' as the export name */
-        return qemuMonitorNBDServerAdd(priv->mon, drivealias, NULL, writable, NULL);
-    }
+    if (!(nbdprops = qemuBlockExportGetNBDProps(src->nodeformat, exportname,
+                                                writable, bitmaps)))
+        return -1;
 
-    return 0;
+    return qemuMonitorBlockExportAdd(priv->mon, &nbdprops);
 }
-- 
2.31.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux