With blockdev we can use the full range of commands to manipulate the
tray and the medium separately. Implement monitor code for this.
Schema testing done in the qemumonitorjsontest allows us to verify that
we generate the commands correctly.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_monitor.c | 51 +++++++++++++++++++
src/qemu/qemu_monitor.h | 14 ++++++
src/qemu/qemu_monitor_json.c | 114 +++++++++++++++++++++++++++++++++++++++++++
src/qemu/qemu_monitor_json.h | 18 +++++++
tests/qemumonitorjsontest.c | 8 +++
5 files changed, 205 insertions(+)
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 4dcbd69dce..d665f33d81 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -4334,6 +4334,57 @@ qemuMonitorBlockdevDel(qemuMonitorPtr mon,
return qemuMonitorJSONBlockdevDel(mon, nodename);
}
+int
+qemuMonitorBlockdevTrayOpen(qemuMonitorPtr mon,
+ const char *id,
+ bool force)
+{
+ VIR_DEBUG("id=%s force=%d", id, force);
+
+ QEMU_CHECK_MONITOR(mon);
+
+ return qemuMonitorJSONBlockdevTrayOpen(mon, id, force);
+}
+
+
+int
+qemuMonitorBlockdevTrayClose(qemuMonitorPtr mon,
+ const char *id)
+{
+ VIR_DEBUG("id=%s", id);
+
+ QEMU_CHECK_MONITOR(mon);
+
+ return qemuMonitorJSONBlockdevTrayClose(mon, id);
+}
+
+
+int
+qemuMonitorBlockdevMediumRemove(qemuMonitorPtr mon,
+ const char *id)
+{
+ VIR_DEBUG("id=%s", id);
+
+ QEMU_CHECK_MONITOR(mon);
+
+ return qemuMonitorJSONBlockdevMediumRemove(mon, id);
+}
+
+
+
+int
+qemuMonitorBlockdevMediumInsert(qemuMonitorPtr mon,
+ const char *id,
+ const char *nodename)
+{
+ VIR_DEBUG("id=%s nodename=%s", id, nodename);
+
+ QEMU_CHECK_MONITOR(mon);
+
+ return qemuMonitorJSONBlockdevMediumInsert(mon, id, nodename);
+}
+
+
char *
qemuMonitorGetSEVMeasurement(qemuMonitorPtr mon)
{
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index f8f6969ddb..0734588f66 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1151,6 +1151,20 @@ int qemuMonitorBlockdevAdd(qemuMonitorPtr mon,
int qemuMonitorBlockdevDel(qemuMonitorPtr mon,
const char *nodename);
+int qemuMonitorBlockdevTrayOpen(qemuMonitorPtr mon,
+ const char *id,
+ bool force);
+
+int qemuMonitorBlockdevTrayClose(qemuMonitorPtr mon,
+ const char *id);
+
+int qemuMonitorBlockdevMediumRemove(qemuMonitorPtr mon,
+ const char *id);
+
+int qemuMonitorBlockdevMediumInsert(qemuMonitorPtr mon,
+ const char *id,
+ const char *nodename);
+
char *
qemuMonitorGetSEVMeasurement(qemuMonitorPtr mon);
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index de3fcd83d8..105f6f78ac 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -8004,6 +8004,120 @@ qemuMonitorJSONBlockdevDel(qemuMonitorPtr mon,
return ret;
}
+
+int
+qemuMonitorJSONBlockdevTrayOpen(qemuMonitorPtr mon,
+ const char *id,
+ bool force)
+{
+ virJSONValuePtr cmd;
+ virJSONValuePtr reply = NULL;
+ int ret = -1;
+
+ if (!(cmd = qemuMonitorJSONMakeCommand("blockdev-open-tray",
+ "s:id", id,
+ "b:force", force, 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;
+}
+
+
+int
+qemuMonitorJSONBlockdevTrayClose(qemuMonitorPtr mon,
+ const char *id)
+{
+ virJSONValuePtr cmd;
+ virJSONValuePtr reply = NULL;
+ int ret = -1;
+
+ if (!(cmd = qemuMonitorJSONMakeCommand("blockdev-close-tray",
+ "s:id", id, 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;
+}
+
+
+int
+qemuMonitorJSONBlockdevMediumRemove(qemuMonitorPtr mon,
+ const char *id)
+{
+ virJSONValuePtr cmd;
+ virJSONValuePtr reply = NULL;
+ int ret = -1;
+
+ if (!(cmd = qemuMonitorJSONMakeCommand("blockdev-remove-medium",
+ "s:id", id, 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;
+}
+
+
+int
+qemuMonitorJSONBlockdevMediumInsert(qemuMonitorPtr mon,
+ const char *id,
+ const char *nodename)
+{
+ virJSONValuePtr cmd;
+ virJSONValuePtr reply = NULL;
+ int ret = -1;
+
+ if (!(cmd = qemuMonitorJSONMakeCommand("blockdev-insert-medium",
+ "s:id", id,
+ "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;
+}
+
+
/**
* The function is used to retrieve the measurement of a SEV guest.
* The measurement is signature of the memory contents that was encrypted
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 19aebef5fb..3c5839db38 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -549,6 +549,24 @@ int qemuMonitorJSONBlockdevDel(qemuMonitorPtr mon,
const char *nodename)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+int qemuMonitorJSONBlockdevTrayOpen(qemuMonitorPtr mon,
+ const char *id,
+ bool force)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+
+int qemuMonitorJSONBlockdevTrayClose(qemuMonitorPtr mon,
+ const char *id)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+
+int qemuMonitorJSONBlockdevMediumRemove(qemuMonitorPtr mon,
+ const char *id)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+
+int qemuMonitorJSONBlockdevMediumInsert(qemuMonitorPtr mon,
+ const char *id,
+ const char *nodename)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
+
int qemuMonitorJSONGetPRManagerInfo(qemuMonitorPtr mon,
virHashTablePtr info)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index b048c40d7d..7c4947374f 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -1352,6 +1352,10 @@ GEN_TEST_FUNC(qemuMonitorJSONOpenGraphics, "spice",
"spicefd", false)
GEN_TEST_FUNC(qemuMonitorJSONNBDServerStart, "localhost", 12345,
"test-alias")
GEN_TEST_FUNC(qemuMonitorJSONNBDServerAdd, "vda", true)
GEN_TEST_FUNC(qemuMonitorJSONDetachCharDev, "serial1")
+GEN_TEST_FUNC(qemuMonitorJSONBlockdevTrayOpen, "foodev", true)
+GEN_TEST_FUNC(qemuMonitorJSONBlockdevTrayClose, "foodev")
+GEN_TEST_FUNC(qemuMonitorJSONBlockdevMediumRemove, "foodev")
+GEN_TEST_FUNC(qemuMonitorJSONBlockdevMediumInsert, "foodev",
"newnode")
static bool
testQemuMonitorJSONqemuMonitorJSONQueryCPUsEqual(struct qemuMonitorQueryCpusEntry *a,
@@ -2997,6 +3001,10 @@ mymain(void)
DO_TEST_GEN(qemuMonitorJSONNBDServerStart);
DO_TEST_GEN(qemuMonitorJSONNBDServerAdd);
DO_TEST_GEN(qemuMonitorJSONDetachCharDev);
+ DO_TEST_GEN(qemuMonitorJSONBlockdevTrayOpen);
+ DO_TEST_GEN(qemuMonitorJSONBlockdevTrayClose);
+ DO_TEST_GEN(qemuMonitorJSONBlockdevMediumRemove);
+ DO_TEST_GEN(qemuMonitorJSONBlockdevMediumInsert);
DO_TEST(qemuMonitorJSONGetBalloonInfo);
DO_TEST(qemuMonitorJSONGetBlockInfo);
DO_TEST(qemuMonitorJSONGetAllBlockStatsInfo);
--
2.16.2