From patchwork Thu Oct 25 19:54:35 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lei Li X-Patchwork-Id: 194299 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E5FE42C0093 for ; Fri, 26 Oct 2012 06:57:02 +1100 (EST) Received: from localhost ([::1]:45331 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TRTY5-0006W9-4i for incoming@patchwork.ozlabs.org; Thu, 25 Oct 2012 15:57:01 -0400 Received: from eggs.gnu.org ([208.118.235.92]:33351) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TRTXQ-0004px-NX for qemu-devel@nongnu.org; Thu, 25 Oct 2012 15:56:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TRTXO-0007jo-0Z for qemu-devel@nongnu.org; Thu, 25 Oct 2012 15:56:20 -0400 Received: from e23smtp06.au.ibm.com ([202.81.31.148]:58844) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TRTXN-0007jQ-GU for qemu-devel@nongnu.org; Thu, 25 Oct 2012 15:56:17 -0400 Received: from /spool/local by e23smtp06.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 26 Oct 2012 05:54:09 +1000 Received: from d23relay05.au.ibm.com (202.81.31.247) by e23smtp06.au.ibm.com (202.81.31.212) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 26 Oct 2012 05:54:08 +1000 Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q9PJk5Cb11862082 for ; Fri, 26 Oct 2012 06:46:05 +1100 Received: from d23av03.au.ibm.com (loopback [127.0.0.1]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q9PJuDbG027513 for ; Fri, 26 Oct 2012 06:56:14 +1100 Received: from localhost.localdomain ([9.77.176.231]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q9PJts7b027299; Fri, 26 Oct 2012 06:56:11 +1100 From: Lei Li To: qemu-devel@nongnu.org Date: Fri, 26 Oct 2012 03:54:35 +0800 Message-Id: <1351194875-10983-5-git-send-email-lilei@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1351194875-10983-1-git-send-email-lilei@linux.vnet.ibm.com> References: <1351194875-10983-1-git-send-email-lilei@linux.vnet.ibm.com> x-cbid: 12102519-7014-0000-0000-000002147103 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 202.81.31.148 Cc: blauwirbel@gmail.com, aliguori@us.ibm.com, Lei Li , lcapitulino@redhat.com Subject: [Qemu-devel] [PATCH 4/4] HMP: Introduce console command X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Lei Li --- hmp-commands.hx | 25 +++++++++++++++++++++++++ hmp.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ hmp.h | 1 + monitor.c | 15 +++++++++++++++ monitor.h | 3 +++ 5 files changed, 96 insertions(+), 0 deletions(-) diff --git a/hmp-commands.hx b/hmp-commands.hx index df294eb..7cba42c 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -861,6 +861,31 @@ if the requested size is larger than it. ETEXI { + .name = "console", + .args_type = "chardev:s", + .params = "chardev", + .help = "Connect to the serial console from within the" + "monitor, allow to write data to memchardev" + "'chardev'. Exit from the console and return back" + "to monitor by typing 'ctrl-]'", + .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 typing 'ctrl-]'. +@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 ef85736..d716410 100644 --- a/hmp.c +++ b/hmp.c @@ -1255,3 +1255,55 @@ void hmp_screen_dump(Monitor *mon, const QDict *qdict) qmp_screendump(filename, &err); hmp_handle_error(mon, &err); } + +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 DataFormat format = DATA_FORMAT_UTF8; + 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, format, &err); + + if (err) { + monitor_printf(mon, "%s\n", error_get_pretty(err)); + 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 a5a0cfe..5b54a79 100644 --- a/hmp.h +++ b/hmp.h @@ -77,5 +77,6 @@ void hmp_getfd(Monitor *mon, const QDict *qdict); void hmp_closefd(Monitor *mon, const QDict *qdict); void hmp_send_key(Monitor *mon, const QDict *qdict); void hmp_screen_dump(Monitor *mon, const QDict *qdict); +void hmp_console(Monitor *mon, const QDict *qdict); #endif diff --git a/monitor.c b/monitor.c index d17ae2d..7e90115 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 b6e7d95..735bd1b 100644 --- a/monitor.h +++ b/monitor.h @@ -86,6 +86,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);