On Tue, Oct 26, 2021 at 16:58:22 +0200, Kristina Hanicova wrote:
I think this patch improves readability of the function by
removing unnecessary 'else' branches after 'return' and reworking
the code a bit.
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..4e532d29c0 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);
These two are okay, they invoke a different code path when features are
not supported ...
It will indeed help as we can simply delete them when the caps become
obsolete ...
- 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 qemuMonitorBlockExportAdd(priv->mon, &nbdprops);
but this is weird and doesn't conform to what we usually do. Write it
as:
if (!(nbdprops = qemuBlockExportGetNBDProps(src->nodeformat, exportname,
writable, bitmaps)))
return -1;
return qemuMonitorBlockExportAdd(priv->mon, &nbdprops);
- return 0;
+ return -1;
And get rid of the above.
}
--
2.31.1