]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu_monitor: Introduce qemuMonitorDetachCharDev
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 12 Mar 2013 18:57:48 +0000 (19:57 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 12 Jul 2013 09:00:04 +0000 (11:00 +0200)
This function wraps 'chardev-remove' qemu monitor command around.
It takes chardev alias as its single argument besides qemu monitor
pointer.

src/qemu/qemu_monitor.c
src/qemu/qemu_monitor.h
src/qemu/qemu_monitor_json.c
src/qemu/qemu_monitor_json.h
tests/qemumonitorjsontest.c

index de0079eb18d4120ed2823e99aeabda43a80f6429..c1ac49324edfd15dfa7090fb54b407e26735c6fe 100644 (file)
@@ -3643,3 +3643,23 @@ int qemuMonitorAttachCharDev(qemuMonitorPtr mon,
 
     return qemuMonitorJSONAttachCharDev(mon, chrID, chr);
 }
+
+int qemuMonitorDetachCharDev(qemuMonitorPtr mon,
+                             const char *chrID)
+{
+    VIR_DEBUG("mon=%p chrID=%s", mon, chrID);
+
+    if (!mon) {
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
+                       _("monitor must not be NULL"));
+        return -1;
+    }
+
+    if (!mon->json) {
+        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
+                       _("JSON monitor is required"));
+        return -1;
+    }
+
+    return qemuMonitorJSONDetachCharDev(mon, chrID);
+}
index 734e09bc6db94bfdb5d66fe22cb71314c3156d87..4d83bef815e5b706274a3c92ee1c935b5befbbf4 100644 (file)
@@ -704,6 +704,8 @@ int qemuMonitorGetTPMTypes(qemuMonitorPtr mon,
 int qemuMonitorAttachCharDev(qemuMonitorPtr mon,
                              const char *chrID,
                              virDomainChrSourceDefPtr chr);
+int qemuMonitorDetachCharDev(qemuMonitorPtr mon,
+                             const char *chrID);
 /**
  * When running two dd process and using <> redirection, we need a
  * shell that will not truncate files.  These two strings serve that
index b06429e20013af056f9e2cd1d15aab627af7a9d7..cf2b20aee1c57cc7de49b578b9a32c919a52338f 100644 (file)
@@ -5123,3 +5123,26 @@ cleanup:
     virJSONValueFree(reply);
     return ret;
 }
+
+int
+qemuMonitorJSONDetachCharDev(qemuMonitorPtr mon,
+                             const char *chrID)
+{
+    int ret = -1;
+    virJSONValuePtr cmd;
+    virJSONValuePtr reply = NULL;
+
+    if (!(cmd = qemuMonitorJSONMakeCommand("chardev-remove",
+                                           "s:id", chrID,
+                                           NULL)))
+        return ret;
+
+    ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+
+    if (ret == 0)
+        ret = qemuMonitorJSONCheckError(cmd, reply);
+
+    virJSONValueFree(cmd);
+    virJSONValueFree(reply);
+    return ret;
+}
index e0a48835e18ccd02c9aaf44410265395ab68defe..266077395c13826b37e377fea2dfd32aef96f9b1 100644 (file)
@@ -356,4 +356,6 @@ int qemuMonitorJSONGetTPMTypes(qemuMonitorPtr mon,
 int qemuMonitorJSONAttachCharDev(qemuMonitorPtr mon,
                                  const char *chrID,
                                  virDomainChrSourceDefPtr chr);
+int qemuMonitorJSONDetachCharDev(qemuMonitorPtr mon,
+                                 const char *chrID);
 #endif /* QEMU_MONITOR_JSON_H */
index 1b3b9f83c876ccfbe40ab430e8dfb8a0c31cdd89..7edaf395d114b1ef1d811d47b1350b680d913aaf 100644 (file)
@@ -675,6 +675,30 @@ cleanup:
     return ret;
 }
 
+static int
+testQemuMonitorJSONDetachChardev(const void *data)
+{
+    const virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
+    qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlopt);
+    int ret = -1;
+
+    if (!test)
+        return ret;
+
+    if (qemuMonitorTestAddItem(test, "chardev-remove", "{\"return\": {}}") < 0)
+        goto cleanup;
+
+    if (qemuMonitorDetachCharDev(qemuMonitorTestGetMonitor(test),
+                                 "dummy_chrID") < 0)
+        goto cleanup;
+
+    ret = 0;
+
+cleanup:
+    qemuMonitorTestFree(test);
+    return ret;
+}
+
 static int
 mymain(void)
 {
@@ -704,6 +728,7 @@ mymain(void)
     DO_TEST(GetTPMModels);
     DO_TEST(GetCommandLineOptionParameters);
     DO_TEST(AttachChardev);
+    DO_TEST(DetachChardev);
 
     virObjectUnref(xmlopt);