[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 2/5] Expose CirMemCharDriver via command line
From: |
Lei Li |
Subject: |
[Qemu-devel] [PATCH 2/5] Expose CirMemCharDriver via command line |
Date: |
Wed, 12 Sep 2012 19:57:23 +0800 |
Signed-off-by: Lei Li <address@hidden>
---
qemu-char.c | 31 +++++++++++++++++++++++++++++++
qemu-config.c | 3 +++
qemu-options.hx | 10 ++++++++++
3 files changed, 44 insertions(+), 0 deletions(-)
diff --git a/qemu-char.c b/qemu-char.c
index 0470085..6e84acc 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -2675,6 +2675,31 @@ static void cirmem_chr_read(CharDriverState *chr,
uint8_t *buf, int len)
d->cbuf_count -= len;
}
+static CharDriverState *qemu_chr_open_cirmemchr(QemuOpts *opts)
+{
+ CharDriverState *chr;
+ CircMemCharDriver *d;
+
+ chr = g_malloc0(sizeof(CharDriverState));
+ d = g_malloc(sizeof(*d));
+
+ d->cbuf_capacity = qemu_opt_get_number(opts, "maxcapacity", 0);
+ if (d->cbuf_capacity == 0) {
+ d->cbuf_capacity = CBUFF_SIZE;
+ }
+
+ d->cbuf_in = 0;
+ d->cbuf_out = 0;
+ d->cbuf_count = 0;
+ d->cbuf = g_malloc0(d->cbuf_capacity);
+
+ memset(chr, 0, sizeof(*chr));
+ chr->opaque = d;
+ chr->chr_write = mem_chr_write;
+
+ return chr;
+}
+
QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename)
{
char host[65], port[33], width[8], height[8];
@@ -2739,6 +2764,11 @@ QemuOpts *qemu_chr_parse_compat(const char *label, const
char *filename)
qemu_opt_set(opts, "path", p);
return opts;
}
+ if (strstart(filename, "memchr", &p)) {
+ qemu_opt_set(opts, "backend", "memchr");
+ qemu_opt_set(opts, "maxcapacity", p);
+ return opts;
+ }
if (strstart(filename, "tcp:", &p) ||
strstart(filename, "telnet:", &p)) {
if (sscanf(p, "%64[^:]:%32[^,]%n", host, port, &pos) < 2) {
@@ -2812,6 +2842,7 @@ static const struct {
{ .name = "udp", .open = qemu_chr_open_udp },
{ .name = "msmouse", .open = qemu_chr_open_msmouse },
{ .name = "vc", .open = text_console_init },
+ { .name = "memchr", .open = qemu_chr_open_cirmemchr },
#ifdef _WIN32
{ .name = "file", .open = qemu_chr_open_win_file_out },
{ .name = "pipe", .open = qemu_chr_open_win_pipe },
diff --git a/qemu-config.c b/qemu-config.c
index eba977e..5cb6dcb 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -213,6 +213,9 @@ static QemuOptsList qemu_chardev_opts = {
},{
.name = "debug",
.type = QEMU_OPT_NUMBER,
+ },{
+ .name = "maxcapacity",
+ .type = QEMU_OPT_NUMBER,
},
{ /* end of list */ }
},
diff --git a/qemu-options.hx b/qemu-options.hx
index 804a2d1..3a7384d 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1666,6 +1666,7 @@ DEF("chardev", HAS_ARG, QEMU_OPTION_chardev,
"-chardev msmouse,id=id[,mux=on|off]\n"
"-chardev
vc,id=id[[,width=width][,height=height]][[,cols=cols][,rows=rows]]\n"
" [,mux=on|off]\n"
+ "-chardev memchr,id=id,maxcapacity=maxcapacity\n"
"-chardev file,id=id,path=path[,mux=on|off]\n"
"-chardev pipe,id=id,path=path[,mux=on|off]\n"
#ifdef _WIN32
@@ -1704,6 +1705,7 @@ Backend is one of:
@option{udp},
@option{msmouse},
@option{vc},
address@hidden,
@option{file},
@option{pipe},
@option{console},
@@ -1810,6 +1812,14 @@ the console, in pixels.
@option{cols} and @option{rows} specify that the console be sized to fit a text
console with the given dimensions.
address@hidden -chardev memchr ,address@hidden ,address@hidden
+
+Create a circular buffer with fixed size indicated by optionally
@option{maxcapacity}
+which will be default 64K if it is not given.
+
address@hidden specify the max capacity of the size of circular buffer
+want to create.
+
@item -chardev file ,address@hidden ,address@hidden
Log all traffic received from the guest to a file.
--
1.7.7.6