From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:48453) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TPyhu-0007lA-Ua for qemu-devel@nongnu.org; Sun, 21 Oct 2012 12:49:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TPyhs-0006Ux-El for qemu-devel@nongnu.org; Sun, 21 Oct 2012 12:48:58 -0400 Received: from e23smtp05.au.ibm.com ([202.81.31.147]:60890) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TPyhr-0006S0-TH for qemu-devel@nongnu.org; Sun, 21 Oct 2012 12:48:56 -0400 Received: from /spool/local by e23smtp05.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 22 Oct 2012 02:47:09 +1000 Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q9LGmowc40304840 for ; Mon, 22 Oct 2012 03:48:50 +1100 Received: from d23av01.au.ibm.com (loopback [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q9LGmnLP006819 for ; Mon, 22 Oct 2012 03:48:50 +1100 From: Lei Li Date: Mon, 22 Oct 2012 00:47:58 +0800 Message-Id: <1350838081-6351-3-git-send-email-lilei@linux.vnet.ibm.com> In-Reply-To: <1350838081-6351-1-git-send-email-lilei@linux.vnet.ibm.com> References: <1350838081-6351-1-git-send-email-lilei@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 2/5] Expose CirMemCharDriver via command line List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: blauwirbel@gmail.com, aliguori@us.ibm.com, Lei Li , lcapitulino@redhat.com Signed-off-by: Lei Li --- qemu-char.c | 36 ++++++++++++++++++++++++++++++++++++ qemu-config.c | 3 +++ qemu-options.hx | 10 ++++++++++ 3 files changed, 49 insertions(+), 0 deletions(-) diff --git a/qemu-char.c b/qemu-char.c index b174da1..381bf60 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -99,6 +99,7 @@ #include "ui/qemu-spice.h" #define READ_BUF_LEN 4096 +#define CBUFF_SIZE 65536 /***********************************************************/ /* character device */ @@ -2660,6 +2661,35 @@ static void cirmem_chr_close(struct CharDriverState *chr) chr->opaque = NULL; } +static CharDriverState *qemu_chr_open_cirmemchr(QemuOpts *opts) +{ + CharDriverState *chr; + CirMemCharDriver *d; + + chr = g_malloc0(sizeof(CharDriverState)); + d = g_malloc(sizeof(*d)); + + d->size = qemu_opt_get_number(opts, "maxcapacity", 0); + if (d->size == 0) { + d->size = CBUFF_SIZE; + } + + if (d->size & (d->size -1)) { + return NULL; + } + + d->producer = 0; + d->consumer = 0; + d->cbuf = g_malloc0(d->size); + + memset(chr, 0, sizeof(*chr)); + chr->opaque = d; + chr->chr_write = cirmem_chr_write; + chr->chr_close = cirmem_chr_close; + + return chr; +} + QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename) { char host[65], port[33], width[8], height[8]; @@ -2724,6 +2754,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) { @@ -2797,6 +2832,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 cd1ec21..5553bb6 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 7d97f96..4f90f20 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -1684,6 +1684,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 @@ -1722,6 +1723,7 @@ Backend is one of: @option{udp}, @option{msmouse}, @option{vc}, +@option{memchr}, @option{file}, @option{pipe}, @option{console}, @@ -1828,6 +1830,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. +@item -chardev memchr ,id=@var{id} ,maxcapacity=@var{maxcapacity} + +Create a circular buffer with fixed size indicated by optionally @option{maxcapacity} +which will be default 64K if it is not given. + +@option{maxcapacity} specify the max capacity of the size of circular buffer +want to create. Should be power of 2. + @item -chardev file ,id=@var{id} ,path=@var{path} Log all traffic received from the guest to a file. -- 1.7.7.6