]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemuMonitorBlockdevCreate: Use double pointer instead of always consuming '@props'
authorPeter Krempa <pkrempa@redhat.com>
Wed, 1 Dec 2021 08:10:40 +0000 (09:10 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 7 Dec 2021 08:00:39 +0000 (09:00 +0100)
We use this approach for other APIs which take a virJSONValue as
argument and the logic is also simpler.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_block.c
src/qemu/qemu_monitor.c
src/qemu/qemu_monitor.h
src/qemu/qemu_monitor_json.c
src/qemu/qemu_monitor_json.h

index 8a10d2aa0cdde5e937b59e2f624f7464e9adfb1e..f6a7f2b750708846f5054aa390b4b9987e0345aa 100644 (file)
@@ -2710,8 +2710,7 @@ qemuBlockStorageSourceCreateGeneric(virDomainObj *vm,
     if (qemuDomainObjEnterMonitorAsync(priv->driver, vm, asyncJob) < 0)
         goto cleanup;
 
-    rc = qemuMonitorBlockdevCreate(priv->mon, job->name, props);
-    props = NULL;
+    rc = qemuMonitorBlockdevCreate(priv->mon, job->name, &props);
 
     qemuDomainObjExitMonitor(priv->driver, vm);
     if (rc < 0)
index 26b59801b88b48164f4d41c816d409af9f4a12de..d752b299abfe0ad858fc7b1cff6413df49a2c93f 100644 (file)
@@ -4242,30 +4242,23 @@ qemuMonitorSetWatchdogAction(qemuMonitor *mon,
  * qemuMonitorBlockdevCreate:
  * @mon: monitor object
  * @jobname: name of the job
- * @props: JSON object describing the blockdev to add
+ * @props: JSON object describing the blockdev to add (consumed on success)
  *
  * Instructs qemu to create/format a new storage or format layer. Note that
  * the job does not add the created/formatted image into qemu and
  * qemuMonitorBlockdevAdd needs to be called separately with corresponding
  * arguments. Note that the arguments for creating and adding are different.
- *
- * Note that @props is always consumed by this function and should not be
- * accessed after calling this function.
  */
 int
 qemuMonitorBlockdevCreate(qemuMonitor *mon,
                           const char *jobname,
-                          virJSONValue *props)
+                          virJSONValue **props)
 {
     VIR_DEBUG("jobname=%s props=%p", jobname, props);
 
-    QEMU_CHECK_MONITOR_GOTO(mon, error);
+    QEMU_CHECK_MONITOR(mon);
 
     return qemuMonitorJSONBlockdevCreate(mon, jobname, props);
-
- error:
-    virJSONValueFree(props);
-    return -1;
 }
 
 /**
index 99ecebc64878bf4a97b03b1de1d78d8181ae5c25..8b0c8a99ab6aafe115f47e7877613406219f966d 100644 (file)
@@ -1416,7 +1416,7 @@ int qemuMonitorSetWatchdogAction(qemuMonitor *mon,
 
 int qemuMonitorBlockdevCreate(qemuMonitor *mon,
                               const char *jobname,
-                              virJSONValue *props);
+                              virJSONValue **props);
 
 int qemuMonitorBlockdevAdd(qemuMonitor *mon,
                            virJSONValue **props);
index c10ea583fd788dfe9dcd75f7f59e6fe49b82f570..c05a2f3cffab20411ce73d99cac04cca38e65db2 100644 (file)
@@ -7964,16 +7964,15 @@ qemuMonitorJSONSetWatchdogAction(qemuMonitor *mon,
 int
 qemuMonitorJSONBlockdevCreate(qemuMonitor *mon,
                               const char *jobname,
-                              virJSONValue *props)
+                              virJSONValue **props)
 {
     g_autoptr(virJSONValue) cmd = NULL;
     g_autoptr(virJSONValue) reply = NULL;
 
     cmd = qemuMonitorJSONMakeCommand("blockdev-create",
                                      "s:job-id", jobname,
-                                     "a:options", &props,
+                                     "a:options", props,
                                      NULL);
-    virJSONValueFree(props);
     if (!cmd)
         return -1;
 
index f7fb13f56ca2c99b9e926d92967c71d7c2925997..3b88ae73638a2181fc4053e03f6c025c33e846fe 100644 (file)
@@ -586,7 +586,7 @@ int qemuMonitorJSONSetWatchdogAction(qemuMonitor *mon,
 
 int qemuMonitorJSONBlockdevCreate(qemuMonitor *mon,
                                   const char *jobname,
-                                  virJSONValue *props)
+                                  virJSONValue **props)
     ATTRIBUTE_NONNULL(1);
 
 int qemuMonitorJSONBlockdevAdd(qemuMonitor *mon,