From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:59277) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tgct4-0007LE-0j for qemu-devel@nongnu.org; Thu, 06 Dec 2012 09:57:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tgcsz-0001lD-Ic for qemu-devel@nongnu.org; Thu, 06 Dec 2012 09:57:17 -0500 Received: from e28smtp06.in.ibm.com ([122.248.162.6]:59030) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tgcsz-0001jm-1K for qemu-devel@nongnu.org; Thu, 06 Dec 2012 09:57:13 -0500 Received: from /spool/local by e28smtp06.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 6 Dec 2012 20:26:54 +0530 Received: from d28relay04.in.ibm.com (d28relay04.in.ibm.com [9.184.220.61]) by d28dlp03.in.ibm.com (Postfix) with ESMTP id 26161125804D for ; Thu, 6 Dec 2012 20:26:50 +0530 (IST) Received: from d28av04.in.ibm.com (d28av04.in.ibm.com [9.184.220.66]) by d28relay04.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id qB6Ev3vM4391184 for ; Thu, 6 Dec 2012 20:27:03 +0530 Received: from d28av04.in.ibm.com (loopback [127.0.0.1]) by d28av04.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id qB6Ev3NX010108 for ; Fri, 7 Dec 2012 01:57:03 +1100 From: Lei Li Date: Thu, 6 Dec 2012 22:56:40 +0800 Message-Id: <1354805800-29653-5-git-send-email-lilei@linux.vnet.ibm.com> In-Reply-To: <1354805800-29653-1-git-send-email-lilei@linux.vnet.ibm.com> References: <1354805800-29653-1-git-send-email-lilei@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 4/4] HMP: Introduce console command List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: aliguori@us.ibm.com Cc: qemu-devel@nongnu.org, anthony@codemonkey.ws, Lei Li Signed-off-by: Lei Li --- hmp-commands.hx | 21 +++++++++++++++++++++ hmp.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ hmp.h | 1 + monitor.c | 15 +++++++++++++++ monitor.h | 3 +++ 5 files changed, 92 insertions(+), 0 deletions(-) diff --git a/hmp-commands.hx b/hmp-commands.hx index 3975e22..9ec5ed7 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -874,6 +874,27 @@ if the requested size is larger than it. ETEXI { + .name = "console", + .args_type = "chardev:s", + .params = "chardev", + .mhandler.cmd = hmp_console, + }, + +STEXI +@item console @var{device} +@findex console +Connect to the serial console from within the monitor, allow to write data +to memchardev @var{chardev}. Exit from the console and return back to +monitor by 'ctrl-]' or enter. + +@example +(qemu) console foo +foo: data string... +@end example + +ETEXI + + { .name = "migrate", .args_type = "detach:-d,blk:-b,inc:-i,uri:s", .params = "[-d] [-b] [-i] uri", diff --git a/hmp.c b/hmp.c index 413012f..a6c053c 100644 --- a/hmp.c +++ b/hmp.c @@ -1365,3 +1365,55 @@ void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict) qmp_nbd_server_stop(&errp); hmp_handle_error(mon, &errp); } + +enum escape_char +{ + ESCAPE_CHAR_CTRL_GS = 0x1d /* ctrl-] used for escape */ +}; + +static void hmp_read_console(Monitor *mon, const char *data, + void *opaque) +{ + CharDriverState *chr = opaque; + uint32_t size = strlen(data); + enum escape_char console_escape = ESCAPE_CHAR_CTRL_GS; + + Error *err = NULL; + + if (*data == console_escape) { + monitor_resume(mon); + return; + } + + qmp_memchar_write(chr->label, size, data, 0, 0, &err); + + if (err) { + monitor_printf(mon, "%s\n", error_get_pretty(err)); + monitor_read_command(mon,1); + error_free(err); + return; + } + + monitor_read_command(mon, 1); +} + +void hmp_console(Monitor *mon, const QDict *qdict) +{ + const char *device = qdict_get_str(qdict, "chardev"); + CharDriverState *chr; + Error *err = NULL; + + chr = qemu_chr_find(device); + + if (!chr) { + error_set(&err, QERR_DEVICE_NOT_FOUND, device); + goto out; + } + + if (monitor_read_console(mon, device, hmp_read_console, chr) < 0) { + monitor_printf(mon, "Connect to console %s failed\n", device); + } + +out: + hmp_handle_error(mon, &err); +} diff --git a/hmp.h b/hmp.h index 22a6646..9082324 100644 --- a/hmp.h +++ b/hmp.h @@ -82,5 +82,6 @@ void hmp_screen_dump(Monitor *mon, const QDict *qdict); void hmp_nbd_server_start(Monitor *mon, const QDict *qdict); void hmp_nbd_server_add(Monitor *mon, const QDict *qdict); void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict); +void hmp_console(Monitor *mon, const QDict *qdict); #endif diff --git a/monitor.c b/monitor.c index c0e32d6..695a19a 100644 --- a/monitor.c +++ b/monitor.c @@ -256,6 +256,21 @@ int monitor_read_password(Monitor *mon, ReadLineFunc *readline_func, } } +int monitor_read_console(Monitor *mon, const char *device, + ReadLineFunc *readline_func, void *opaque) +{ + char prompt[60]; + + if (!mon->rs) { + return -1; + } + + snprintf(prompt, sizeof(prompt), "%s: ", device); + readline_start(mon->rs, prompt, 0, readline_func, opaque); + + return 0; +} + void monitor_flush(Monitor *mon) { if (mon && mon->outbuf_index != 0 && !mon->mux_out) { diff --git a/monitor.h b/monitor.h index b4ef955..5f584b9 100644 --- a/monitor.h +++ b/monitor.h @@ -87,6 +87,9 @@ ReadLineState *monitor_get_rs(Monitor *mon); int monitor_read_password(Monitor *mon, ReadLineFunc *readline_func, void *opaque); +int monitor_read_console(Monitor *mon, const char *device, + ReadLineFunc *readline_func, void *opaque); + int qmp_qom_set(Monitor *mon, const QDict *qdict, QObject **ret); int qmp_qom_get(Monitor *mon, const QDict *qdict, QObject **ret); -- 1.7.7.6