From patchwork Wed Sep 9 18:05:45 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Blue Swirl X-Patchwork-Id: 33217 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by bilbo.ozlabs.org (Postfix) with ESMTPS id 08CE1B6F1F for ; Thu, 10 Sep 2009 04:12:45 +1000 (EST) Received: from localhost ([127.0.0.1]:60396 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MlReq-0001D1-Of for incoming@patchwork.ozlabs.org; Wed, 09 Sep 2009 14:12:40 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MlRYY-0006nR-Sv for qemu-devel@nongnu.org; Wed, 09 Sep 2009 14:06:11 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MlRYU-0006lJ-7U for qemu-devel@nongnu.org; Wed, 09 Sep 2009 14:06:10 -0400 Received: from [199.232.76.173] (port=53575 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MlRYU-0006l8-2V for qemu-devel@nongnu.org; Wed, 09 Sep 2009 14:06:06 -0400 Received: from mail-ew0-f221.google.com ([209.85.219.221]:63947) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MlRYT-0007qh-Ey for qemu-devel@nongnu.org; Wed, 09 Sep 2009 14:06:05 -0400 Received: by mail-ew0-f221.google.com with SMTP id 21so624776ewy.8 for ; Wed, 09 Sep 2009 11:06:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:from:date:message-id :subject:to:content-type; bh=AJoWoz4LHwwzs0ucTyWeGPirxH1Fo0R5X+45g5eY2UM=; b=JWwK5pd8VTGSY2r3/jzBg8BVtQMZgOBk37EZBx0RxCroP0A1hV7PQlRWyUrJCCwSjK CBFOblbi318DrJunm04vZrKccfg8/8Pfwb9dCL/98JItyrFCSr53r/1gNbZlwiNW6RMj /dGw5DVCbBY6Hgmqpid5gnie/Gd6LHow3jQtE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; b=WYcdn8Ka1+tviTPtGSuN0KyuZ4jTPlGXBScemCMWZKzyesczeCnXc/XUqAoQchIhYi tI4d2QdrQSIDCG9861Ke3Fw20DavLYrL7u+S2zTjJC/LAgpQkLklLZRXrmRNbhyIYm3t /4yA2J9VLyxHxLX9LmtnMAwNAa3n49pl9kCws= MIME-Version: 1.0 Received: by 10.210.2.17 with SMTP id 17mr542291ebb.46.1252519565105; Wed, 09 Sep 2009 11:06:05 -0700 (PDT) From: Blue Swirl Date: Wed, 9 Sep 2009 21:05:45 +0300 Message-ID: To: qemu-devel X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: [Qemu-devel] [PATCH 1/5] monitor: add device info infrastructure X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Blue Swirl --- monitor.c | 39 +++++++++++++++++++++++++++++++++++++++ monitor.h | 10 ++++++++++ qemu-monitor.hx | 7 +++++++ vl.c | 18 +++++++++--------- 4 files changed, 65 insertions(+), 9 deletions(-) diff --git a/monitor.c b/monitor.c index f5f4d0e..0c891cc 100644 --- a/monitor.c +++ b/monitor.c @@ -83,6 +83,13 @@ struct mon_fd_t { LIST_ENTRY(mon_fd_t) next; }; +/* Callback for device info command */ +struct MonDevInfoEntry { + const struct MonDevInfo *dev_info; + void *dev_opaque; + LIST_ENTRY(MonDevInfoEntry) next; +}; + struct Monitor { CharDriverState *chr; int flags; @@ -94,6 +101,7 @@ struct Monitor { BlockDriverCompletionFunc *password_completion_cb; void *password_opaque; LIST_HEAD(,mon_fd_t) fds; + LIST_HEAD(,MonDevInfoEntry) dev_infos; LIST_ENTRY(Monitor) entry; }; @@ -1800,6 +1808,19 @@ int monitor_get_fd(Monitor *mon, const char *fdname) return -1; } +static void do_info_device(Monitor *mon, const QDict *qdict) +{ + struct MonDevInfoEntry *entry; + const char *name = qdict_get_str(qdict, "devname"); + + LIST_FOREACH(entry, &mon->dev_infos, next) { + if (strcmp(entry->dev_info->dev_name, name) != 0) { + continue; + } + entry->dev_info->dev_info_cb(mon, entry->dev_opaque); + } +} + static const mon_cmd_t mon_cmds[] = { #include "qemu-monitor.h" { NULL, NULL, }, @@ -3045,6 +3066,13 @@ static void monitor_find_completion(const char *cmdline) for (cmd = mon_cmds; cmd->name != NULL; cmd++) { cmd_completion(str, cmd->name); } + } else if (!strcmp(cmd->name, "dev_info")) { + struct MonDevInfoEntry *entry; + + readline_set_completion_index(cur_mon->rs, strlen(str)); + LIST_FOREACH(entry, &cur_mon->dev_infos, next) { + cmd_completion(str, entry->dev_info->dev_name); + } } break; default: @@ -3209,6 +3237,17 @@ void monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs, completion_cb(opaque, err); } +void monitor_register_device_info(const struct MonDevInfo *dev_info, + void *dev_opaque) +{ + struct MonDevInfoEntry *entry; + + entry = qemu_malloc(sizeof(*entry)); + entry->dev_info = dev_info; + entry->dev_opaque = dev_opaque; + LIST_INSERT_HEAD(&cur_mon->dev_infos, entry, next); +} + typedef struct QemuErrorSink QemuErrorSink; struct QemuErrorSink { enum { diff --git a/monitor.h b/monitor.h index c7d2d0b..3bcb494 100644 --- a/monitor.h +++ b/monitor.h @@ -21,6 +21,16 @@ void monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs, BlockDriverCompletionFunc *completion_cb, void *opaque); +typedef void DeviceInfoFunc(Monitor *mon, void *opaque); + +struct MonDevInfo { + const char *dev_name; + DeviceInfoFunc *dev_info_cb; +}; + +void monitor_register_device_info(const struct MonDevInfo *dev_info, + void *dev_opaque); + int monitor_get_fd(Monitor *mon, const char *fdname); void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap); diff --git a/qemu-monitor.hx b/qemu-monitor.hx index 9f91873..af01245 100644 --- a/qemu-monitor.hx +++ b/qemu-monitor.hx @@ -645,6 +645,13 @@ Close the file descriptor previously assigned to @var{fdname} using the used by another monitor command. ETEXI + { "dev_info", "devname:s", do_info_device, + "device name", "show device information" }, +STEXI +@item device @var{devicename} +Show information about a device. +ETEXI + STEXI @end table ETEXI diff --git a/vl.c b/vl.c index 098daaa..6bb4084 100644 --- a/vl.c +++ b/vl.c @@ -5908,6 +5908,15 @@ int main(int argc, char **argv, char **envp) } } } + qemu_chr_initial_reset(); + + for (i = 0; i < MAX_MONITOR_DEVICES; i++) { + if (monitor_devices[i] && monitor_hds[i]) { + monitor_init(monitor_hds[i], + MONITOR_USE_READLINE | + ((i == 0) ? MONITOR_IS_DEFAULT : 0)); + } + } for(i = 0; i < MAX_SERIAL_PORTS; i++) { const char *devname = serial_devices[i]; @@ -6052,15 +6061,6 @@ int main(int argc, char **argv, char **envp) } text_consoles_set_display(display_state); - qemu_chr_initial_reset(); - - for (i = 0; i < MAX_MONITOR_DEVICES; i++) { - if (monitor_devices[i] && monitor_hds[i]) { - monitor_init(monitor_hds[i], - MONITOR_USE_READLINE | - ((i == 0) ? MONITOR_IS_DEFAULT : 0)); - } - } for(i = 0; i < MAX_SERIAL_PORTS; i++) { const char *devname = serial_devices[i];