qemu-devel
[Top][All Lists]
Advanced

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

Re: [PATCH v5 37/50] multi-process/mon: Refactor monitor/chardev functio


From: Jag Raman
Subject: Re: [PATCH v5 37/50] multi-process/mon: Refactor monitor/chardev functions out of vl.c
Date: Thu, 5 Mar 2020 10:41:08 -0500
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0



On 3/5/2020 5:51 AM, Dr. David Alan Gilbert wrote:
* Jagannathan Raman (address@hidden) wrote:
Some of the initialization helper functions w.r.t monitor & chardev
in vl.c are also used by the remote process. Therefore, these functions
are refactored into shared files that both QEMU & remote process
could use.

Signed-off-by: Elena Ufimtseva <address@hidden>
Signed-off-by: John G Johnson <address@hidden>
Signed-off-by: Jagannathan Raman <address@hidden>

Reviewed-by: Dr. David Alan Gilbert <address@hidden>

This looks like another good candidate to go in a separate post that
doesn't need to wait for the rest of multi-process; you are probably
best splitting it into separate chardev and monitor chunks so they can
go via their respective maintainers.

Sure, thanks!

--
Jag


Dave


---
  chardev/char.c            | 14 ++++++++++++++
  include/chardev/char.h    |  1 +
  include/monitor/monitor.h |  2 ++
  monitor/monitor.c         | 40 ++++++++++++++++++++++++++++++++++++++-
  remote/remote-main.c      |  1 +
  remote/remote-opts.c      |  1 +
  softmmu/vl.c              | 48 -----------------------------------------------
  7 files changed, 58 insertions(+), 49 deletions(-)

diff --git a/chardev/char.c b/chardev/char.c
index 8723756..1d03ea0 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -1189,4 +1189,18 @@ static void register_types(void)
      qemu_add_machine_init_done_notifier(&chardev_machine_done_notify);
  }
+int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp)
+{
+    Error *local_err = NULL;
+
+    if (!qemu_chr_new_from_opts(opts, NULL, &local_err)) {
+        if (local_err) {
+            error_propagate(errp, local_err);
+            return -1;
+        }
+        exit(0);
+    }
+    return 0;
+}
+
  type_init(register_types);
diff --git a/include/chardev/char.h b/include/chardev/char.h
index 00589a6..e370320 100644
--- a/include/chardev/char.h
+++ b/include/chardev/char.h
@@ -290,4 +290,5 @@ GSource *qemu_chr_timeout_add_ms(Chardev *chr, guint ms,
  /* console.c */
  void qemu_chr_parse_vc(QemuOpts *opts, ChardevBackend *backend, Error **errp);
+int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp);
  #endif
diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index b7bdd2b..d92bf1c 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -45,5 +45,7 @@ int monitor_fdset_get_fd(int64_t fdset_id, int flags);
  int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd);
  void monitor_fdset_dup_fd_remove(int dup_fd);
  int64_t monitor_fdset_dup_fd_find(int dup_fd);
+void monitor_parse(const char *optarg, const char *mode, bool pretty);
+int mon_init_func(void *opaque, QemuOpts *opts, Error **errp);
#endif /* MONITOR_H */
diff --git a/monitor/monitor.c b/monitor/monitor.c
index c1a6c44..5759b84 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -33,7 +33,10 @@
  #include "sysemu/qtest.h"
  #include "sysemu/sysemu.h"
  #include "trace.h"
-
+#include "qemu/cutils.h"
+#include "qemu/option.h"
+#include "qemu-options.h"
+#include "qemu/config-file.h"
  /*
   * To prevent flooding clients, events can be throttled. The
   * throttling is calculated globally, rather than per-Monitor
@@ -609,6 +612,41 @@ void monitor_init_globals_core(void)
                                     NULL);
  }
+int mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
+{
+    return monitor_init_opts(opts, errp);
+}
+
+void monitor_parse(const char *optarg, const char *mode, bool pretty)
+{
+    static int monitor_device_index;
+    QemuOpts *opts;
+    const char *p;
+    char label[32];
+
+    if (strstart(optarg, "chardev:", &p)) {
+        snprintf(label, sizeof(label), "%s", p);
+    } else {
+        snprintf(label, sizeof(label), "compat_monitor%d",
+                 monitor_device_index);
+        opts = qemu_chr_parse_compat(label, optarg, true);
+        if (!opts) {
+            error_report("parse error: %s", optarg);
+            exit(1);
+        }
+    }
+
+    opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal);
+    qemu_opt_set(opts, "mode", mode, &error_abort);
+    qemu_opt_set(opts, "chardev", label, &error_abort);
+    if (!strcmp(mode, "control")) {
+        qemu_opt_set_bool(opts, "pretty", pretty, &error_abort);
+    } else {
+        assert(pretty == false);
+    }
+    monitor_device_index++;
+}
+
  int monitor_init_opts(QemuOpts *opts, Error **errp)
  {
      Chardev *chr;
diff --git a/remote/remote-main.c b/remote/remote-main.c
index 5284ee9..23fc0df 100644
--- a/remote/remote-main.c
+++ b/remote/remote-main.c
@@ -54,6 +54,7 @@
  #include "qemu/cutils.h"
  #include "remote-opts.h"
  #include "monitor/monitor.h"
+#include "chardev/char.h"
  #include "sysemu/reset.h"
static MPQemuLinkState *mpqemu_link;
diff --git a/remote/remote-opts.c b/remote/remote-opts.c
index 7e12700..565e641 100644
--- a/remote/remote-opts.c
+++ b/remote/remote-opts.c
@@ -39,6 +39,7 @@
  #include "block/block.h"
  #include "remote/remote-opts.h"
  #include "include/qemu-common.h"
+#include "monitor/monitor.h"
#include "vl.h"
  /*
diff --git a/softmmu/vl.c b/softmmu/vl.c
index a8a6f35..4a4f52c 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -2133,19 +2133,6 @@ static int device_help_func(void *opaque, QemuOpts 
*opts, Error **errp)
      return qdev_device_help(opts);
  }
-static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp)
-{
-    Error *local_err = NULL;
-
-    if (!qemu_chr_new_from_opts(opts, NULL, &local_err)) {
-        if (local_err) {
-            error_propagate(errp, local_err);
-            return -1;
-        }
-        exit(0);
-    }
-    return 0;
-}
#ifdef CONFIG_VIRTFS
  static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp)
@@ -2154,41 +2141,6 @@ static int fsdev_init_func(void *opaque, QemuOpts *opts, 
Error **errp)
  }
  #endif
-static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
-{
-    return monitor_init_opts(opts, errp);
-}
-
-static void monitor_parse(const char *optarg, const char *mode, bool pretty)
-{
-    static int monitor_device_index = 0;
-    QemuOpts *opts;
-    const char *p;
-    char label[32];
-
-    if (strstart(optarg, "chardev:", &p)) {
-        snprintf(label, sizeof(label), "%s", p);
-    } else {
-        snprintf(label, sizeof(label), "compat_monitor%d",
-                 monitor_device_index);
-        opts = qemu_chr_parse_compat(label, optarg, true);
-        if (!opts) {
-            error_report("parse error: %s", optarg);
-            exit(1);
-        }
-    }
-
-    opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal);
-    qemu_opt_set(opts, "mode", mode, &error_abort);
-    qemu_opt_set(opts, "chardev", label, &error_abort);
-    if (!strcmp(mode, "control")) {
-        qemu_opt_set_bool(opts, "pretty", pretty, &error_abort);
-    } else {
-        assert(pretty == false);
-    }
-    monitor_device_index++;
-}
-
  struct device_config {
      enum {
          DEV_USB,       /* -usbdevice     */
--
1.8.3.1

--
Dr. David Alan Gilbert / address@hidden / Manchester, UK




reply via email to

[Prev in Thread] Current Thread [Next in Thread]