Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_monitor.c | 37 +++++++++++++++++++++++++++++
src/qemu/qemu_monitor.h | 7 ++++++
src/qemu/qemu_monitor_json.c | 55 ++++++++++++++++++++++++++++++++++++++++++++
src/qemu/qemu_monitor_json.h | 9 ++++++++
4 files changed, 108 insertions(+)
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index f21bf7000d..fb9583e405 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -4412,3 +4412,40 @@ qemuMonitorSetWatchdogAction(qemuMonitorPtr mon,
return qemuMonitorJSONSetWatchdogAction(mon, action);
}
+
+
+/**
+ * qemuMonitorBlockdevAdd:
+ * @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.
+ */
+int
+qemuMonitorBlockdevAdd(qemuMonitorPtr mon,
+ virJSONValuePtr props)
+{
+ VIR_DEBUG("props=%p (node-name=%s)", props,
+ NULLSTR(virJSONValueObjectGetString(props, "node-name")));
+
+ QEMU_CHECK_MONITOR_JSON_GOTO(mon, error);
+
+ return qemuMonitorJSONBlockdevAdd(mon, props);
+
+ error:
+ virJSONValueFree(props);
+ return -1;
+}
+
+
+int
+qemuMonitorBlockdevDel(qemuMonitorPtr mon,
+ const char *nodename)
+{
+ VIR_DEBUG("nodename=%s", nodename);
+
+ QEMU_CHECK_MONITOR_JSON(mon);
+
+ return qemuMonitorJSONBlockdevDel(mon, nodename);
+}
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 6cba37c281..52ad843029 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1142,4 +1142,11 @@ virJSONValuePtr qemuMonitorQueryNamedBlockNodes(qemuMonitorPtr
mon);
int qemuMonitorSetWatchdogAction(qemuMonitorPtr mon,
const char *action);
+
+int qemuMonitorBlockdevAdd(qemuMonitorPtr mon,
+ virJSONValuePtr props);
+
+int qemuMonitorBlockdevDel(qemuMonitorPtr mon,
+ const char *nodename);
+
#endif /* QEMU_MONITOR_H */
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 0b0fb7feba..61554a7ebc 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -7889,3 +7889,58 @@ qemuMonitorJSONSetWatchdogAction(qemuMonitorPtr mon,
virJSONValueFree(reply);
return ret;
}
+
+
+int
+qemuMonitorJSONBlockdevAdd(qemuMonitorPtr mon,
+ virJSONValuePtr props)
+{
+ virJSONValuePtr cmd;
+ virJSONValuePtr reply = NULL;
+ int ret = -1;
+
+ if (!(cmd = qemuMonitorJSONMakeCommandInternal("blockdev-add",
+ props, false)))
+ return -1;
+
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
+
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+
+ ret = 0;
+
+ cleanup:
+ virJSONValueFree(cmd);
+ virJSONValueFree(reply);
+ return ret;
+}
+
+
+int
+qemuMonitorJSONBlockdevDel(qemuMonitorPtr mon,
+ const char *nodename)
+{
+ virJSONValuePtr cmd;
+ virJSONValuePtr reply = NULL;
+ int ret = -1;
+
+ if (!(cmd = qemuMonitorJSONMakeCommand("blockdev-del",
+ "s:node-name", nodename,
+ NULL)))
+ return -1;
+
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
+
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+
+ ret = 0;
+
+ cleanup:
+ virJSONValueFree(cmd);
+ virJSONValueFree(reply);
+ return ret;
+}
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 8461932cac..22bcc1e8ef 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -537,4 +537,13 @@ virJSONValuePtr qemuMonitorJSONQueryNamedBlockNodes(qemuMonitorPtr
mon)
int qemuMonitorJSONSetWatchdogAction(qemuMonitorPtr mon,
const char *action)
ATTRIBUTE_NONNULL(1);
+
+int qemuMonitorJSONBlockdevAdd(qemuMonitorPtr mon,
+ virJSONValuePtr props)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+
+int qemuMonitorJSONBlockdevDel(qemuMonitorPtr mon,
+ const char *nodename)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+
#endif /* QEMU_MONITOR_JSON_H */
--
2.16.2