render / rpms / libvirt

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