d76c62
From f5fe33504d90bf47d3f766470a04b16eca56bfd8 Mon Sep 17 00:00:00 2001
d76c62
Message-Id: <f5fe33504d90bf47d3f766470a04b16eca56bfd8@dist-git>
d76c62
From: Peter Krempa <pkrempa@redhat.com>
d76c62
Date: Wed, 19 Feb 2020 15:10:04 +0100
d76c62
Subject: [PATCH] qemuMonitorBlockdevAdd: Take double pointer argument
d76c62
MIME-Version: 1.0
d76c62
Content-Type: text/plain; charset=UTF-8
d76c62
Content-Transfer-Encoding: 8bit
d76c62
d76c62
Modify qemuMonitorBlockdevAdd so that it takes a double pointer for the
d76c62
@props argument so that it's cleared inside the call. This allows
d76c62
writing cleaner callers.
d76c62
d76c62
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
d76c62
Reviewed-by: Ján Tomko <jtomko@redhat.com>
d76c62
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
d76c62
(cherry picked from commit db57e9daf5ab25bd7a1f377c4dde160b0896ad64)
d76c62
d76c62
https://bugzilla.redhat.com/show_bug.cgi?id=1798366
d76c62
Message-Id: <1b4429b82826f69f18b506b8fbd648ff0ac70c38.1582120424.git.pkrempa@redhat.com>
d76c62
Reviewed-by: Ján Tomko <jtomko@redhat.com>
d76c62
---
d76c62
 src/qemu/qemu_block.c        | 14 ++------------
d76c62
 src/qemu/qemu_monitor.c      | 16 ++++++----------
d76c62
 src/qemu/qemu_monitor.h      |  2 +-
d76c62
 src/qemu/qemu_monitor_json.c |  5 +++--
d76c62
 src/qemu/qemu_monitor_json.h |  2 +-
d76c62
 5 files changed, 13 insertions(+), 26 deletions(-)
d76c62
d76c62
diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
d76c62
index 0ee10dd770..710ddfd2cf 100644
d76c62
--- a/src/qemu/qemu_block.c
d76c62
+++ b/src/qemu/qemu_block.c
d76c62
@@ -1537,13 +1537,8 @@ static int
d76c62
 qemuBlockStorageSourceAttachApplyStorage(qemuMonitorPtr mon,
d76c62
                                          qemuBlockStorageSourceAttachDataPtr data)
d76c62
 {
d76c62
-    int rv;
d76c62
-
d76c62
     if (data->storageProps) {
d76c62
-        rv = qemuMonitorBlockdevAdd(mon, data->storageProps);
d76c62
-        data->storageProps = NULL;
d76c62
-
d76c62
-        if (rv < 0)
d76c62
+        if (qemuMonitorBlockdevAdd(mon, &data->storageProps) < 0)
d76c62
             return -1;
d76c62
 
d76c62
         data->storageAttached = true;
d76c62
@@ -1570,13 +1565,8 @@ static int
d76c62
 qemuBlockStorageSourceAttachApplyFormat(qemuMonitorPtr mon,
d76c62
                                         qemuBlockStorageSourceAttachDataPtr data)
d76c62
 {
d76c62
-    int rv;
d76c62
-
d76c62
     if (data->formatProps) {
d76c62
-        rv = qemuMonitorBlockdevAdd(mon, data->formatProps);
d76c62
-        data->formatProps = NULL;
d76c62
-
d76c62
-        if (rv < 0)
d76c62
+        if (qemuMonitorBlockdevAdd(mon, &data->formatProps) < 0)
d76c62
             return -1;
d76c62
 
d76c62
         data->formatAttached = true;
d76c62
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
d76c62
index 0e67851690..e3ee48613a 100644
d76c62
--- a/src/qemu/qemu_monitor.c
d76c62
+++ b/src/qemu/qemu_monitor.c
d76c62
@@ -4391,23 +4391,19 @@ qemuMonitorBlockdevCreate(qemuMonitorPtr mon,
d76c62
  * @mon: monitor object
d76c62
  * @props: JSON object describing the blockdev to add
d76c62
  *
d76c62
- * Adds a new block device (BDS) to qemu. Note that @props is always consumed
d76c62
- * by this function and should not be accessed after calling this function.
d76c62
+ * Adds a new block device (BDS) to qemu. Note that *@props is consumed
d76c62
+ * and set to NULL on success.
d76c62
  */
d76c62
 int
d76c62
 qemuMonitorBlockdevAdd(qemuMonitorPtr mon,
d76c62
-                       virJSONValuePtr props)
d76c62
+                       virJSONValuePtr *props)
d76c62
 {
d76c62
-    VIR_DEBUG("props=%p (node-name=%s)", props,
d76c62
-              NULLSTR(virJSONValueObjectGetString(props, "node-name")));
d76c62
+    VIR_DEBUG("props=%p (node-name=%s)", *props,
d76c62
+              NULLSTR(virJSONValueObjectGetString(*props, "node-name")));
d76c62
 
d76c62
-    QEMU_CHECK_MONITOR_GOTO(mon, error);
d76c62
+    QEMU_CHECK_MONITOR(mon);
d76c62
 
d76c62
     return qemuMonitorJSONBlockdevAdd(mon, props);
d76c62
-
d76c62
- error:
d76c62
-    virJSONValueFree(props);
d76c62
-    return -1;
d76c62
 }
d76c62
 
d76c62
 
d76c62
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
d76c62
index cca2cdcb27..6a6b8efaee 100644
d76c62
--- a/src/qemu/qemu_monitor.h
d76c62
+++ b/src/qemu/qemu_monitor.h
d76c62
@@ -1323,7 +1323,7 @@ int qemuMonitorBlockdevCreate(qemuMonitorPtr mon,
d76c62
                               virJSONValuePtr props);
d76c62
 
d76c62
 int qemuMonitorBlockdevAdd(qemuMonitorPtr mon,
d76c62
-                           virJSONValuePtr props);
d76c62
+                           virJSONValuePtr *props);
d76c62
 
d76c62
 int qemuMonitorBlockdevDel(qemuMonitorPtr mon,
d76c62
                            const char *nodename);
d76c62
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
d76c62
index 05a44882f0..3827574ef6 100644
d76c62
--- a/src/qemu/qemu_monitor_json.c
d76c62
+++ b/src/qemu/qemu_monitor_json.c
d76c62
@@ -8811,12 +8811,13 @@ qemuMonitorJSONBlockdevCreate(qemuMonitorPtr mon,
d76c62
 
d76c62
 int
d76c62
 qemuMonitorJSONBlockdevAdd(qemuMonitorPtr mon,
d76c62
-                           virJSONValuePtr props)
d76c62
+                           virJSONValuePtr *props)
d76c62
 {
d76c62
     g_autoptr(virJSONValue) cmd = NULL;
d76c62
     g_autoptr(virJSONValue) reply = NULL;
d76c62
+    virJSONValuePtr pr = g_steal_pointer(props);
d76c62
 
d76c62
-    if (!(cmd = qemuMonitorJSONMakeCommandInternal("blockdev-add", props)))
d76c62
+    if (!(cmd = qemuMonitorJSONMakeCommandInternal("blockdev-add", pr)))
d76c62
         return -1;
d76c62
 
d76c62
     if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
d76c62
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
d76c62
index 61f5b0061d..fd2e09025e 100644
d76c62
--- a/src/qemu/qemu_monitor_json.h
d76c62
+++ b/src/qemu/qemu_monitor_json.h
d76c62
@@ -597,7 +597,7 @@ int qemuMonitorJSONBlockdevCreate(qemuMonitorPtr mon,
d76c62
     ATTRIBUTE_NONNULL(1);
d76c62
 
d76c62
 int qemuMonitorJSONBlockdevAdd(qemuMonitorPtr mon,
d76c62
-                               virJSONValuePtr props)
d76c62
+                               virJSONValuePtr *props)
d76c62
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
d76c62
 
d76c62
 int qemuMonitorJSONBlockdevDel(qemuMonitorPtr mon,
d76c62
-- 
d76c62
2.25.0
d76c62