render / rpms / libvirt

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