diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 0ee10dd770..710ddfd2cf 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -1537,13 +1537,8 @@ static int qemuBlockStorageSourceAttachApplyStorage(qemuMonitorPtr mon, qemuBlockStorageSourceAttachDataPtr data) { - int rv; - if (data->storageProps) { - rv = qemuMonitorBlockdevAdd(mon, data->storageProps); - data->storageProps = NULL; - - if (rv < 0) + if (qemuMonitorBlockdevAdd(mon, &data->storageProps) < 0) return -1; data->storageAttached = true; @@ -1570,13 +1565,8 @@ static int qemuBlockStorageSourceAttachApplyFormat(qemuMonitorPtr mon, qemuBlockStorageSourceAttachDataPtr data) { - int rv; - if (data->formatProps) { - rv = qemuMonitorBlockdevAdd(mon, data->formatProps); - data->formatProps = NULL; - - if (rv < 0) + if (qemuMonitorBlockdevAdd(mon, &data->formatProps) < 0) return -1; data->formatAttached = true; diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index ba70d01d47..802ad20aa1 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -4400,23 +4400,19 @@ qemuMonitorBlockdevCreate(qemuMonitorPtr mon, * @mon: monitor object * @props: JSON object describing the blockdev to add * - * Adds a new block device (BDS) to qemu. Note that @props is always consumed - * by this function and should not be accessed after calling this function. + * Adds a new block device (BDS) to qemu. Note that *@props is consumed + * and set to NULL on success. */ int qemuMonitorBlockdevAdd(qemuMonitorPtr mon, - virJSONValuePtr props) + virJSONValuePtr *props) { - VIR_DEBUG("props=%p (node-name=%s)", props, - NULLSTR(virJSONValueObjectGetString(props, "node-name"))); + VIR_DEBUG("props=%p (node-name=%s)", *props, + NULLSTR(virJSONValueObjectGetString(*props, "node-name"))); - QEMU_CHECK_MONITOR_GOTO(mon, error); + QEMU_CHECK_MONITOR(mon); return qemuMonitorJSONBlockdevAdd(mon, props); - - error: - virJSONValueFree(props); - return -1; } diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 89197cfe0d..8cf9e11899 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1330,7 +1330,7 @@ int qemuMonitorBlockdevCreate(qemuMonitorPtr mon, virJSONValuePtr props); int qemuMonitorBlockdevAdd(qemuMonitorPtr mon, - virJSONValuePtr props); + virJSONValuePtr *props); int qemuMonitorBlockdevDel(qemuMonitorPtr mon, const char *nodename); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index bbcb67ddb7..50d93c0c7e 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -8821,12 +8821,13 @@ qemuMonitorJSONBlockdevCreate(qemuMonitorPtr mon, int qemuMonitorJSONBlockdevAdd(qemuMonitorPtr mon, - virJSONValuePtr props) + virJSONValuePtr *props) { g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; + virJSONValuePtr pr = g_steal_pointer(props); - if (!(cmd = qemuMonitorJSONMakeCommandInternal("blockdev-add", props))) + if (!(cmd = qemuMonitorJSONMakeCommandInternal("blockdev-add", pr))) return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index 61f5b0061d..fd2e09025e 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -597,7 +597,7 @@ int qemuMonitorJSONBlockdevCreate(qemuMonitorPtr mon, ATTRIBUTE_NONNULL(1); int qemuMonitorJSONBlockdevAdd(qemuMonitorPtr mon, - virJSONValuePtr props) + virJSONValuePtr *props) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); int qemuMonitorJSONBlockdevDel(qemuMonitorPtr mon,