[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC v4 PATCH 37/49] multi-process/mon: Refactor monitor/chardev functio
From: |
Jagannathan Raman |
Subject: |
[RFC v4 PATCH 37/49] multi-process/mon: Refactor monitor/chardev functions out of vl.c |
Date: |
Thu, 24 Oct 2019 05:09:18 -0400 |
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>
---
New patch in v3
v3 -> v4
- Moved monitor related functions to monitor.c and chardev functions
to char.c
chardev/char.c | 14 ++++++++
include/chardev/char.h | 1 +
include/monitor/monitor.h | 2 ++
monitor/monitor.c | 83 +++++++++++++++++++++++++++++++++++++++++-
remote/remote-main.c | 1 +
remote/remote-opts.c | 1 +
vl-parse.c | 35 +++++++++---------
vl.c | 91 -----------------------------------------------
8 files changed, 119 insertions(+), 109 deletions(-)
diff --git a/chardev/char.c b/chardev/char.c
index 7b6b2cb..9f339ec 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -1168,4 +1168,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 087b202..bad076c 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 a81eeff..ed1963a 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -42,5 +42,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 12898b6..18bcb57 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,84 @@ void monitor_init_globals_core(void)
NULL);
}
+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 mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
+{
+ Chardev *chr;
+ bool qmp;
+ bool pretty = false;
+ const char *chardev;
+ const char *mode;
+
+ mode = qemu_opt_get(opts, "mode");
+ if (mode == NULL) {
+ mode = "readline";
+ }
+ if (strcmp(mode, "readline") == 0) {
+ qmp = false;
+ } else if (strcmp(mode, "control") == 0) {
+ qmp = true;
+ } else {
+ error_setg(errp, "unknown monitor mode \"%s\"", mode);
+ return -1;
+ }
+
+ if (!qmp && qemu_opt_get(opts, "pretty")) {
+ warn_report("'pretty' is deprecated for HMP monitors, it has no effect
"
+ "and will be removed in future versions");
+ }
+ if (qemu_opt_get_bool(opts, "pretty", 0)) {
+ pretty = true;
+ }
+
+ chardev = qemu_opt_get(opts, "chardev");
+ if (!chardev) {
+ error_report("chardev is required");
+ exit(1);
+ }
+ chr = qemu_chr_find(chardev);
+ if (chr == NULL) {
+ error_setg(errp, "chardev \"%s\" not found", chardev);
+ return -1;
+ }
+
+ if (qmp) {
+ monitor_init_qmp(chr, pretty);
+ } else {
+ monitor_init_hmp(chr, true);
+ }
+ return 0;
+}
+
QemuOptsList qemu_mon_opts = {
.name = "mon",
.implied_opt_name = "chardev",
diff --git a/remote/remote-main.c b/remote/remote-main.c
index 4459d26..30182dc 100644
--- a/remote/remote-main.c
+++ b/remote/remote-main.c
@@ -67,6 +67,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 0ebe6b1..7de6195 100644
--- a/remote/remote-opts.c
+++ b/remote/remote-opts.c
@@ -55,6 +55,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/vl-parse.c b/vl-parse.c
index 4e2bd7c..011a9ef 100644
--- a/vl-parse.c
+++ b/vl-parse.c
@@ -110,49 +110,50 @@ int drive_init_func(void *opaque, QemuOpts *opts, Error
**errp)
return 0;
}
-#if defined(CONFIG_MPQEMU)
-int rdrive_init_func(void *opaque, QemuOpts *opts, Error **errp)
+int device_init_func(void *opaque, QemuOpts *opts, Error **errp)
{
DeviceState *dev;
+ const char *remote = NULL;
- dev = qdev_remote_add(opts, false /* this is drive */, errp);
+ remote = qemu_opt_get(opts, "rid");
+ if (remote) {
+ return 0;
+ }
+
+ dev = qdev_device_add(opts, errp);
if (!dev) {
- error_setg(errp, "qdev_remote_add failed for drive.");
return -1;
}
object_unref(OBJECT(dev));
return 0;
}
-#endif
#if defined(CONFIG_MPQEMU)
-int rdevice_init_func(void *opaque, QemuOpts *opts, Error **errp)
+int rdrive_init_func(void *opaque, QemuOpts *opts, Error **errp)
{
DeviceState *dev;
- dev = qdev_remote_add(opts, true /* this is device */, errp);
+ dev = qdev_remote_add(opts, false /* this is drive */, errp);
if (!dev) {
- error_setg(errp, "qdev_remote_add failed for device.");
+ error_setg(errp, "qdev_remote_add failed for drive.");
return -1;
}
+ object_unref(OBJECT(dev));
return 0;
}
#endif
-int device_init_func(void *opaque, QemuOpts *opts, Error **errp)
+#if defined(CONFIG_MPQEMU)
+int rdevice_init_func(void *opaque, QemuOpts *opts, Error **errp)
{
DeviceState *dev;
- const char *remote = NULL;
- remote = qemu_opt_get(opts, "rid");
- if (remote) {
- return 0;
- }
-
- dev = qdev_device_add(opts, errp);
+ dev = qdev_remote_add(opts, true /* this is device */, errp);
if (!dev) {
+ error_setg(errp, "qdev_remote_add failed for device.");
return -1;
}
- object_unref(OBJECT(dev));
return 0;
}
+#endif
+
diff --git a/vl.c b/vl.c
index 1417ff2..a6a0db8 100644
--- a/vl.c
+++ b/vl.c
@@ -2279,19 +2279,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)
@@ -2300,84 +2287,6 @@ static int fsdev_init_func(void *opaque, QemuOpts *opts,
Error **errp)
}
#endif
-static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
-{
- Chardev *chr;
- bool qmp;
- bool pretty = false;
- const char *chardev;
- const char *mode;
-
- mode = qemu_opt_get(opts, "mode");
- if (mode == NULL) {
- mode = "readline";
- }
- if (strcmp(mode, "readline") == 0) {
- qmp = false;
- } else if (strcmp(mode, "control") == 0) {
- qmp = true;
- } else {
- error_setg(errp, "unknown monitor mode \"%s\"", mode);
- return -1;
- }
-
- if (!qmp && qemu_opt_get(opts, "pretty")) {
- warn_report("'pretty' is deprecated for HMP monitors, it has no effect
"
- "and will be removed in future versions");
- }
- if (qemu_opt_get_bool(opts, "pretty", 0)) {
- pretty = true;
- }
-
- chardev = qemu_opt_get(opts, "chardev");
- if (!chardev) {
- error_report("chardev is required");
- exit(1);
- }
- chr = qemu_chr_find(chardev);
- if (chr == NULL) {
- error_setg(errp, "chardev \"%s\" not found", chardev);
- return -1;
- }
-
- if (qmp) {
- monitor_init_qmp(chr, pretty);
- } else {
- monitor_init_hmp(chr, true);
- }
- return 0;
-}
-
-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
- [RFC v4 PATCH 26/49] multi-process: refractor vl.c code to re-use in remote, (continued)
- [RFC v4 PATCH 26/49] multi-process: refractor vl.c code to re-use in remote, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 27/49] multi-process: add remote option, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 28/49] multi-process: add remote options parser, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 30/49] multi-process: send heartbeat messages to remote, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 31/49] multi-process: handle heartbeat messages in remote process, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 32/49] multi-process: Use separate MMIO communication channel, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 34/49] multi-process/mon: choose HMP commands based on target, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 35/49] multi-process/mon: stub functions to enable QMP module for remote process, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 36/49] multi-process/mon: enable QMP module support in the remote process, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 38/49] multi-process/mon: Initialize QMP module for remote processes, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 37/49] multi-process/mon: Refactor monitor/chardev functions out of vl.c,
Jagannathan Raman <=
- [RFC v4 PATCH 39/49] multi-process: prevent duplicate memory initialization in remote, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 40/49] multi-process/mig: build migration module in the remote process, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 41/49] multi-process/mig: Enable VMSD save in the Proxy object, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 42/49] multi-process/mig: Send VMSD of remote to the Proxy object, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 44/49] multi-process/mig: refactor runstate_check into common file, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 45/49] multi-process/mig: Synchronize runstate of remote process, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 47/49] multi-process: Enable support for multiple devices in remote, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 08/49] multi-process: add functions to synchronize proxy and remote endpoints, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 07/49] multi-process: define mpqemu-link object, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 49/49] multi-process: add configure and usage information, Jagannathan Raman, 2019/10/24