From patchwork Mon Jan 21 09:13:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lei Li X-Patchwork-Id: 214052 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 530C32C0089 for ; Mon, 21 Jan 2013 20:14:46 +1100 (EST) Received: from localhost ([::1]:53319 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TxDSm-0001d5-CA for incoming@patchwork.ozlabs.org; Mon, 21 Jan 2013 04:14:44 -0500 Received: from eggs.gnu.org ([208.118.235.92]:57334) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TxDSE-0000RX-AV for qemu-devel@nongnu.org; Mon, 21 Jan 2013 04:14:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TxDSC-0003An-N3 for qemu-devel@nongnu.org; Mon, 21 Jan 2013 04:14:10 -0500 Received: from e28smtp05.in.ibm.com ([122.248.162.5]:49642) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TxDSB-00039G-W3 for qemu-devel@nongnu.org; Mon, 21 Jan 2013 04:14:08 -0500 Received: from /spool/local by e28smtp05.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 21 Jan 2013 14:42:49 +0530 Received: from d28dlp02.in.ibm.com (9.184.220.127) by e28smtp05.in.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 21 Jan 2013 14:42:47 +0530 Received: from d28relay02.in.ibm.com (d28relay02.in.ibm.com [9.184.220.59]) by d28dlp02.in.ibm.com (Postfix) with ESMTP id 995343940050 for ; Mon, 21 Jan 2013 14:44:02 +0530 (IST) Received: from d28av05.in.ibm.com (d28av05.in.ibm.com [9.184.220.67]) by d28relay02.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r0L9E0Ji50331688 for ; Mon, 21 Jan 2013 14:44:01 +0530 Received: from d28av05.in.ibm.com (loopback [127.0.0.1]) by d28av05.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r0L9E0R0011761 for ; Mon, 21 Jan 2013 20:14:01 +1100 Received: from localhost.cn.ibm.com ([9.115.122.36]) by d28av05.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r0L9Do2S010998; Mon, 21 Jan 2013 20:13:59 +1100 From: Lei Li To: qemu-devel@nongnu.org Date: Mon, 21 Jan 2013 17:13:48 +0800 Message-Id: <1358759628-18278-5-git-send-email-lilei@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1358759628-18278-1-git-send-email-lilei@linux.vnet.ibm.com> References: <1358759628-18278-1-git-send-email-lilei@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13012109-8256-0000-0000-000005E88580 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.5 Cc: aliguori@us.ibm.com, Lei Li 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 | 52 +++++++++++++++++++++++++++++++++++++++++++++ hmp.h | 1 + include/monitor/monitor.h | 3 ++ monitor.c | 15 +++++++++++++ 5 files changed, 92 insertions(+), 0 deletions(-) diff --git a/hmp-commands.hx b/hmp-commands.hx index 52ead10..7f7a54a 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -875,6 +875,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 7e86c24..fab5090 100644 --- a/hmp.c +++ b/hmp.c @@ -1389,3 +1389,55 @@ void hmp_chardev_remove(Monitor *mon, const QDict *qdict) qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err); hmp_handle_error(mon, &local_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)); + 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 076d8cf..a01268e 100644 --- a/hmp.h +++ b/hmp.h @@ -84,5 +84,6 @@ void hmp_nbd_server_add(Monitor *mon, const QDict *qdict); void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict); void hmp_chardev_add(Monitor *mon, const QDict *qdict); void hmp_chardev_remove(Monitor *mon, const QDict *qdict); +void hmp_console(Monitor *mon, const QDict *qdict); #endif diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index 87fb49c..a14e965 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/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); diff --git a/monitor.c b/monitor.c index 20bd19b..6f6155d 100644 --- a/monitor.c +++ b/monitor.c @@ -260,6 +260,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) {