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(a)redhat.com>
---
src/qemu/qemu_block.c | 3 +--
src/qemu/qemu_monitor.c | 13 +++----------
src/qemu/qemu_monitor.h | 2 +-
src/qemu/qemu_monitor_json.c | 5 ++---
src/qemu/qemu_monitor_json.h | 2 +-
5 files changed, 8 insertions(+), 17 deletions(-)
diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index 8a10d2aa0c..f6a7f2b750 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -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)
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 26b59801b8..d752b299ab 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -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;
}
/**
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 99ecebc648..8b0c8a99ab 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -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);
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index c10ea583fd..c05a2f3cff 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -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;
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index f7fb13f56c..3b88ae7363 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -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,
--
2.31.1