From patchwork Tue Oct 30 09:54:45 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lei Li X-Patchwork-Id: 195363 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 E8C552C00AC for ; Tue, 30 Oct 2012 20:56:30 +1100 (EST) Received: from localhost ([::1]:47452 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TT8Yf-00076H-0a for incoming@patchwork.ozlabs.org; Tue, 30 Oct 2012 05:56:29 -0400 Received: from eggs.gnu.org ([208.118.235.92]:59922) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TT8YB-0006Xp-7q for qemu-devel@nongnu.org; Tue, 30 Oct 2012 05:56:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TT8Y5-0006P1-5k for qemu-devel@nongnu.org; Tue, 30 Oct 2012 05:55:59 -0400 Received: from e28smtp05.in.ibm.com ([122.248.162.5]:52126) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TT8Y3-0006On-HR for qemu-devel@nongnu.org; Tue, 30 Oct 2012 05:55:52 -0400 Received: from /spool/local by e28smtp05.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 30 Oct 2012 15:25:49 +0530 Received: from d28relay01.in.ibm.com (9.184.220.58) by e28smtp05.in.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 30 Oct 2012 15:25:48 +0530 Received: from d28av03.in.ibm.com (d28av03.in.ibm.com [9.184.220.65]) by d28relay01.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q9U9tlnA40960254 for ; Tue, 30 Oct 2012 15:25:47 +0530 Received: from d28av03.in.ibm.com (loopback [127.0.0.1]) by d28av03.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q9U9tkEr022301 for ; Tue, 30 Oct 2012 20:55:46 +1100 Received: from localhost.localdomain.cn.ibm.com ([9.115.122.89]) by d28av03.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q9U9tY32021734; Tue, 30 Oct 2012 20:55:45 +1100 From: Lei Li To: aliguori@us.ibm.com Date: Tue, 30 Oct 2012 17:54:45 +0800 Message-Id: <1351590885-31252-5-git-send-email-lilei@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1351590885-31252-1-git-send-email-lilei@linux.vnet.ibm.com> References: <1351590885-31252-1-git-send-email-lilei@linux.vnet.ibm.com> x-cbid: 12103009-8256-0000-0000-000004C90FAF X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 122.248.162.5 Cc: blauwirbel@gmail.com, Lei Li , qemu-devel@nongnu.org, 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 | 21 +++++++++++++++++++++ hmp.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ hmp.h | 1 + monitor.c | 15 +++++++++++++++ monitor.h | 3 +++ 5 files changed, 91 insertions(+), 0 deletions(-) diff --git a/hmp-commands.hx b/hmp-commands.hx index c79c9d3..35e0646 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 0465c42..ec08377 100644 --- a/hmp.c +++ b/hmp.c @@ -1289,3 +1289,54 @@ 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 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)); + 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 6289037..0d384b5 100644 --- a/hmp.h +++ b/hmp.h @@ -79,5 +79,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 eeef32e..5ef9cbe 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);