[PATCH v2] qemu_block: Refactor qemuBlockExportAddNBD()

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@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

On 10/26/21 5:19 PM, Kristina Hanicova wrote:
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@redhat.com> --- src/qemu/qemu_block.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-)
The patch is correct, but I think the commit message can be made cleaner. We don't need a reference to older versions, but what I'd appreciate is a short description (be it one sentence long) what's happening in the commit. Can you please reply with something like that? I'll update to commit message and push. Michal
participants (2)
-
Kristina Hanicova
-
Michal Prívozník