[PATCH 04/17] qemuMonitorJSONMigrate: Extract flags prior to constructing command

Peter Krempa posted 17 patches 4 years, 2 months ago
[PATCH 04/17] qemuMonitorJSONMigrate: Extract flags prior to constructing command
Posted by Peter Krempa 4 years, 2 months ago
The migration API takes specific flags which are then converted to
boolean parameters for the command. Extract the flag into helper
variables rather than using ternary operatirs while constructing the
command itself.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 src/qemu/qemu_monitor_json.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index da14eee964..82631e30e0 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -3440,13 +3440,15 @@ int qemuMonitorJSONMigrate(qemuMonitor *mon,
                            unsigned int flags,
                            const char *uri)
 {
-    g_autoptr(virJSONValue) cmd =
-      qemuMonitorJSONMakeCommand("migrate",
-                                 "b:detach", flags & QEMU_MONITOR_MIGRATE_BACKGROUND ? 1 : 0,
-                                 "b:blk", flags & QEMU_MONITOR_MIGRATE_NON_SHARED_DISK ? 1 : 0,
-                                 "b:inc", flags & QEMU_MONITOR_MIGRATE_NON_SHARED_INC ? 1 : 0,
-                                 "s:uri", uri,
-                                 NULL);
+    bool detach = !!(flags & QEMU_MONITOR_MIGRATE_BACKGROUND);
+    bool blk = !!(flags & QEMU_MONITOR_MIGRATE_NON_SHARED_DISK);
+    bool inc = !!(flags & QEMU_MONITOR_MIGRATE_NON_SHARED_INC);
+    g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("migrate",
+                                                             "b:detach", detach,
+                                                             "b:blk", blk,
+                                                             "b:inc", inc,
+                                                             "s:uri", uri,
+                                                             NULL);
     g_autoptr(virJSONValue) reply = NULL;

     if (!cmd)
-- 
2.31.1

Re: [PATCH 04/17] qemuMonitorJSONMigrate: Extract flags prior to constructing command
Posted by Ján Tomko 4 years, 2 months ago
On a Friday in 2021, Peter Krempa wrote:
>The migration API takes specific flags which are then converted to
>boolean parameters for the command. Extract the flag into helper
>variables rather than using ternary operatirs while constructing the

operators

>command itself.
>
>Signed-off-by: Peter Krempa <pkrempa@redhat.com>
>---
> src/qemu/qemu_monitor_json.c | 16 +++++++++-------
> 1 file changed, 9 insertions(+), 7 deletions(-)
>

Jano