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(a)redhat.com>
---
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