[PATCH v3 07/20] mcdstub: quitting QEMU via mcd command added

Nicolas Eder posted 20 patches 1 year ago
Maintainers: Nicolas Eder <nicolas.eder@lauterbach.com>, "Alex Bennée" <alex.bennee@linaro.org>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, Peter Xu <peterx@redhat.com>, David Hildenbrand <david@redhat.com>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Yanan Wang <wangyanan55@huawei.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Thomas Huth <thuth@redhat.com>, Peter Maydell <peter.maydell@linaro.org>
There is a newer version of this series
[PATCH v3 07/20] mcdstub: quitting QEMU via mcd command added
Posted by Nicolas Eder 1 year ago
---
 include/mcdstub/mcdstub.h |  9 +++++++++
 mcdstub/mcdstub.c         | 15 +++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/include/mcdstub/mcdstub.h b/include/mcdstub/mcdstub.h
index c7e34673a6..c3e9c7e9dc 100644
--- a/include/mcdstub/mcdstub.h
+++ b/include/mcdstub/mcdstub.h
@@ -356,6 +356,15 @@ int mcd_handle_packet(const char *line_buf);
  */
 void mcd_put_strbuf(void);
 
+/**
+ * mcd_exit() - Terminates QEMU.
+ *
+ * If the mcdserver_state has not been initialized the function exits before
+ * terminating QEMU. Terminting is done with the qemu_chr_fe_deinit function.
+ * @code: An exitcode, which can be used in the future.
+ */
+void mcd_exit(int code);
+
 /**
  * run_cmd_parser() - Prepares the mcdserver_state before executing TCP packet
  * functions.
diff --git a/mcdstub/mcdstub.c b/mcdstub/mcdstub.c
index d2f6df04c0..858e79632b 100644
--- a/mcdstub/mcdstub.c
+++ b/mcdstub/mcdstub.c
@@ -340,6 +340,11 @@ int mcd_handle_packet(const char *line_buf)
             cmd_parser = &open_server_cmd_desc;
         }
         break;
+    case TCP_CHAR_KILLQEMU:
+        /* kill qemu completely */
+        error_report("QEMU: Terminated via MCDstub");
+        mcd_exit(0);
+        exit(0);
     case TCP_CHAR_CLOSE_SERVER:
         {
             static MCDCmdParseEntry close_server_cmd_desc = {
@@ -492,6 +497,16 @@ int process_string_cmd(void *user_ctx, const char *data,
     return -1;
 }
 
+void mcd_exit(int code)
+{
+    /* terminate qemu */
+    if (!mcdserver_state.init) {
+        return;
+    }
+
+    qemu_chr_fe_deinit(&mcdserver_system_state.chr, true);
+}
+
 void mcd_chr_event(void *opaque, QEMUChrEvent event)
 {
     int i;
-- 
2.34.1