[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCHv2 44/62] qemu: monitor: Add APIs for cdrom tray handling for -blockdev



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 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 49dc478f5b..0a29ad7502 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -4336,6 +4336,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 70854497b2..649a925829 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1155,6 +1155,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 2b168d96c2..3351d405f3 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -8012,6 +8012,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 3da4d3076a..2859d3e82f 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,
@@ -2992,6 +2996,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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]