From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>, agraf@suse.de, lcapitulino@redhat.com
Subject: [Qemu-devel] [FOR 0.12 PATCH v3 17/21] rework -monitor handling, switch to QemuOpts
Date: Mon, 7 Dec 2009 13:42:49 +0100 [thread overview]
Message-ID: <1260189773-20728-18-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1260189773-20728-1-git-send-email-kraxel@redhat.com>
This patch reworks the -monitor handling:
- It adds a new "mon" QemuOpts list for the monitor(s).
- It adds a monitor_parse() function to parse the -monitor switch.
- It adds a mon_init function to initialize the monitor(s) from the
"mon" QemuOpts list.
- It winds up everything and removes the old bits.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
qemu-config.c | 19 +++++++++
qemu-config.h | 1 +
vl.c | 121 ++++++++++++++++++++++++++++++++++++--------------------
3 files changed, 98 insertions(+), 43 deletions(-)
diff --git a/qemu-config.c b/qemu-config.c
index a23b125..c3203c8 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -224,6 +224,24 @@ QemuOptsList qemu_global_opts = {
},
};
+QemuOptsList qemu_mon_opts = {
+ .name = "mon",
+ .head = QTAILQ_HEAD_INITIALIZER(qemu_mon_opts.head),
+ .desc = {
+ {
+ .name = "mode",
+ .type = QEMU_OPT_STRING,
+ },{
+ .name = "chardev",
+ .type = QEMU_OPT_STRING,
+ },{
+ .name = "default",
+ .type = QEMU_OPT_BOOL,
+ },
+ { /* end if list */ }
+ },
+};
+
static QemuOptsList *lists[] = {
&qemu_drive_opts,
&qemu_chardev_opts,
@@ -232,6 +250,7 @@ static QemuOptsList *lists[] = {
&qemu_net_opts,
&qemu_rtc_opts,
&qemu_global_opts,
+ &qemu_mon_opts,
NULL,
};
diff --git a/qemu-config.h b/qemu-config.h
index 6246e76..34dfadc 100644
--- a/qemu-config.h
+++ b/qemu-config.h
@@ -7,6 +7,7 @@ extern QemuOptsList qemu_device_opts;
extern QemuOptsList qemu_netdev_opts;
extern QemuOptsList qemu_net_opts;
extern QemuOptsList qemu_rtc_opts;
+extern QemuOptsList qemu_mon_opts;
int qemu_set_option(const char *str);
int qemu_global_option(const char *str);
diff --git a/vl.c b/vl.c
index 701b687..11910ac 100644
--- a/vl.c
+++ b/vl.c
@@ -172,9 +172,6 @@ int main(int argc, char **argv)
#define DEFAULT_RAM_SIZE 128
-/* Maximum number of monitor devices */
-#define MAX_MONITOR_DEVICES 10
-
static const char *data_dir;
const char *bios_name = NULL;
/* Note: drives_table[MAX_DRIVES] is a dummy block driver if none available
@@ -211,7 +208,6 @@ int no_quit = 0;
CharDriverState *serial_hds[MAX_SERIAL_PORTS];
CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
-CharDriverState *monitor_hds[MAX_MONITOR_DEVICES];
#ifdef TARGET_I386
int win2k_install_hack = 0;
int rtc_td_hack = 0;
@@ -4630,13 +4626,85 @@ static int chardev_init_func(QemuOpts *opts, void *opaque)
return 0;
}
+static int mon_init_func(QemuOpts *opts, void *opaque)
+{
+ CharDriverState *chr;
+ const char *chardev;
+ const char *mode;
+ int flags;
+
+ qemu_opts_print(opts, NULL);
+
+ mode = qemu_opt_get(opts, "mode");
+ if (mode == NULL) {
+ mode = "readline";
+ }
+ if (strcmp(mode, "readline") == 0) {
+ flags = MONITOR_USE_READLINE;
+ } else if (strcmp(mode, "control") == 0) {
+ flags = MONITOR_USE_CONTROL;
+ } else {
+ fprintf(stderr, "unknown monitor mode \"%s\"\n", mode);
+ exit(1);
+ }
+
+ if (qemu_opt_get_bool(opts, "default", 0))
+ flags |= MONITOR_IS_DEFAULT;
+
+ chardev = qemu_opt_get(opts, "chardev");
+ chr = qemu_chr_find(chardev);
+ if (chardev == NULL) {
+ fprintf(stderr, "chardev \"%s\" not found\n", chardev);
+ exit(1);
+ }
+
+ monitor_init(chr, flags);
+ return 0;
+}
+
+static void monitor_parse(const char *optarg)
+{
+ static int monitor_device_index = 0;
+ QemuOpts *opts;
+ const char *p;
+ char label[32];
+ int def = 0;
+
+ if (strstart(optarg, "chardev:", &p)) {
+ snprintf(label, sizeof(label), "%s", p);
+ } else {
+ if (monitor_device_index) {
+ snprintf(label, sizeof(label), "monitor%d",
+ monitor_device_index);
+ } else {
+ snprintf(label, sizeof(label), "monitor");
+ def = 1;
+ }
+ opts = qemu_chr_parse_compat(label, optarg);
+ if (!opts) {
+ fprintf(stderr, "fixme #1\n");
+ exit(1);
+ }
+ }
+
+ opts = qemu_opts_create(&qemu_mon_opts, label, 1);
+ if (!opts) {
+ fprintf(stderr, "fixme #2\n");
+ exit(1);
+ }
+ qemu_opt_set(opts, "mode", "readline");
+ qemu_opt_set(opts, "chardev", label);
+ if (def)
+ qemu_opt_set(opts, "default", "on");
+ monitor_device_index++;
+}
+
struct device_config {
enum {
DEV_USB, /* -usbdevice */
DEV_BT, /* -bt */
DEV_SERIAL, /* -serial */
DEV_PARALLEL, /* -parallel */
- DEV_MONITOR, /* -monitor */
} type;
const char *cmdline;
QTAILQ_ENTRY(device_config) next;
@@ -4712,32 +4780,6 @@ static int parallel_parse(const char *devname)
return 0;
}
-static int monitor_parse(const char *devname)
-{
- static int index = 0;
- char label[32];
-
- if (strcmp(devname, "none") == 0)
- return 0;
- if (index == MAX_MONITOR_DEVICES) {
- fprintf(stderr, "qemu: too many monitor devices\n");
- exit(1);
- }
- if (index == 0) {
- snprintf(label, sizeof(label), "monitor");
- } else {
- snprintf(label, sizeof(label), "monitor%d", index);
- }
- monitor_hds[index] = qemu_chr_open(label, devname, NULL);
- if (!monitor_hds[index]) {
- fprintf(stderr, "qemu: could not open monitor device '%s'\n",
- devname);
- return -1;
- }
- index++;
- return 0;
-}
-
int main(int argc, char **argv, char **envp)
{
const char *gdbstub_dev = NULL;
@@ -5241,7 +5283,7 @@ int main(int argc, char **argv, char **envp)
break;
}
case QEMU_OPTION_monitor:
- add_device_config(DEV_MONITOR, optarg);
+ monitor_parse(optarg);
default_monitor = 0;
break;
case QEMU_OPTION_chardev:
@@ -5572,7 +5614,7 @@ int main(int argc, char **argv, char **envp)
if (default_serial)
add_device_config(DEV_SERIAL, "stdio");
if (default_monitor)
- add_device_config(DEV_MONITOR, "stdio");
+ monitor_parse("stdio");
}
} else {
if (default_serial)
@@ -5580,7 +5622,7 @@ int main(int argc, char **argv, char **envp)
if (default_parallel)
add_device_config(DEV_PARALLEL, "vc:80Cx24C");
if (default_monitor)
- add_device_config(DEV_MONITOR, "vc:80Cx24C");
+ monitor_parse("vc:80Cx24C");
}
if (default_vga)
vga_interface_type = VGA_CIRRUS;
@@ -5774,8 +5816,6 @@ int main(int argc, char **argv, char **envp)
}
}
- if (foreach_device_config(DEV_MONITOR, monitor_parse) < 0)
- exit(1);
if (foreach_device_config(DEV_SERIAL, serial_parse) < 0)
exit(1);
if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0)
@@ -5900,13 +5940,8 @@ int main(int argc, char **argv, char **envp)
text_consoles_set_display(display_state);
- for (i = 0; i < MAX_MONITOR_DEVICES; i++) {
- if (monitor_hds[i]) {
- monitor_init(monitor_hds[i],
- MONITOR_USE_READLINE |
- ((i == 0) ? MONITOR_IS_DEFAULT : 0));
- }
- }
+ if (qemu_opts_foreach(&qemu_mon_opts, mon_init_func, NULL, 1) != 0)
+ exit(1);
if (gdbstub_dev && gdbserver_start(gdbstub_dev) < 0) {
fprintf(stderr, "qemu: could not open gdbserver on device '%s'\n",
--
1.6.5.2
next prev parent reply other threads:[~2009-12-07 12:44 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-07 12:42 [Qemu-devel] [FOR 0.12 PATCH v3 00/21] default devices: qdev integration Gerd Hoffmann
2009-12-07 12:42 ` [Qemu-devel] [FOR 0.12 PATCH v3 01/21] Revert "monitor: Command-line flag to enable control mode" Gerd Hoffmann
2009-12-07 12:42 ` [Qemu-devel] [FOR 0.12 PATCH v3 02/21] Revert "Set default console to virtio on S390x" Gerd Hoffmann
2009-12-07 12:42 ` [Qemu-devel] [FOR 0.12 PATCH v3 03/21] chardev: move greeting into vc backend Gerd Hoffmann
2009-12-07 12:42 ` [Qemu-devel] [FOR 0.12 PATCH v3 04/21] vc: colorize chardev title line with blue background Gerd Hoffmann
2009-12-07 12:42 ` [Qemu-devel] [FOR 0.12 PATCH v3 05/21] default devices: core code & serial lines Gerd Hoffmann
2009-12-07 12:52 ` [Qemu-devel] " Alexander Graf
2009-12-07 13:27 ` Gerd Hoffmann
2009-12-07 14:07 ` Alexander Graf
2009-12-07 14:39 ` Gerd Hoffmann
2009-12-07 15:12 ` Alexander Graf
2009-12-07 16:05 ` Gerd Hoffmann
2009-12-07 16:10 ` Alexander Graf
2009-12-08 9:23 ` Gerd Hoffmann
2009-12-07 12:54 ` Alexander Graf
2009-12-07 13:30 ` Gerd Hoffmann
2009-12-07 12:42 ` [Qemu-devel] [FOR 0.12 PATCH v3 06/21] default devices: parallel port Gerd Hoffmann
2009-12-07 12:42 ` [Qemu-devel] [FOR 0.12 PATCH v3 07/21] default devices: qemu monitor Gerd Hoffmann
2009-12-07 12:42 ` [Qemu-devel] [FOR 0.12 PATCH v3 08/21] zap serial_monitor_mux Gerd Hoffmann
2009-12-07 12:42 ` [Qemu-devel] [FOR 0.12 PATCH v3 09/21] default devices: vga adapter Gerd Hoffmann
2009-12-07 12:42 ` [Qemu-devel] [FOR 0.12 PATCH v3 10/21] default devices: add global cmd line option Gerd Hoffmann
2009-12-08 12:46 ` [Qemu-devel] " Paolo Bonzini
2009-12-08 15:58 ` Gerd Hoffmann
2009-12-07 12:42 ` [Qemu-devel] [FOR 0.12 PATCH v3 11/21] default devices: network Gerd Hoffmann
2009-12-07 12:42 ` [Qemu-devel] [FOR 0.12 PATCH v3 12/21] default devices: drives Gerd Hoffmann
2009-12-07 12:42 ` [Qemu-devel] [FOR 0.12 PATCH v3 13/21] qdev: make compat stuff more generic Gerd Hoffmann
2009-12-07 12:42 ` [Qemu-devel] [FOR 0.12 PATCH v3 14/21] qdev: add command line option to set global defaults for properties Gerd Hoffmann
2009-12-07 12:42 ` [Qemu-devel] [FOR 0.12 PATCH v3 15/21] chardev: make chardevs specified in config file work Gerd Hoffmann
2009-12-07 12:42 ` [Qemu-devel] [FOR 0.12 PATCH v3 16/21] un-static qemu_chr_parse_compat() Gerd Hoffmann
2009-12-07 12:42 ` Gerd Hoffmann [this message]
2009-12-07 14:59 ` [Qemu-devel] Re: [FOR 0.12 PATCH v3 17/21] rework -monitor handling, switch to QemuOpts Luiz Capitulino
2009-12-07 15:18 ` Gerd Hoffmann
2009-12-07 19:11 ` [Qemu-devel] " Anthony Liguori
2009-12-07 12:42 ` [Qemu-devel] [FOR 0.12 PATCH v3 18/21] add new -mon switch Gerd Hoffmann
2009-12-07 12:42 ` [Qemu-devel] [FOR 0.12 PATCH v3 19/21] add -qmp convinience switch Gerd Hoffmann
2009-12-07 12:42 ` [Qemu-devel] [FOR 0.12 PATCH v3 20/21] default devices: virtio consoles Gerd Hoffmann
2009-12-07 13:07 ` [Qemu-devel] " Alexander Graf
2009-12-07 13:34 ` Gerd Hoffmann
2009-12-07 12:42 ` [Qemu-devel] [FOR 0.12 PATCH v3 21/21] Set default console to virtio on S390x Gerd Hoffmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1260189773-20728-18-git-send-email-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=agraf@suse.de \
--cc=lcapitulino@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).