From patchwork Fri Jul 23 16:47:39 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Di Ciurcio Filho X-Patchwork-Id: 59824 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 ozlabs.org (Postfix) with ESMTPS id 804901007D1 for ; Sat, 24 Jul 2010 02:58:26 +1000 (EST) Received: from localhost ([127.0.0.1]:44058 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OcLUJ-00007E-C9 for incoming@patchwork.ozlabs.org; Fri, 23 Jul 2010 12:52:43 -0400 Received: from [140.186.70.92] (port=45461 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OcLPg-0005Wh-4c for qemu-devel@nongnu.org; Fri, 23 Jul 2010 12:47:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OcLPe-0002qQ-Kd for qemu-devel@nongnu.org; Fri, 23 Jul 2010 12:47:55 -0400 Received: from mail-gx0-f173.google.com ([209.85.161.173]:46757) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OcLPe-0002q7-HU for qemu-devel@nongnu.org; Fri, 23 Jul 2010 12:47:54 -0400 Received: by gxk19 with SMTP id 19so207766gxk.4 for ; Fri, 23 Jul 2010 09:47:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:x-mailer:in-reply-to:references; bh=apXqcmkxcAQSfRdJHYvxowPg9+I1Wql+IMb3pWtlnLc=; b=RBwKQmLaVrk6oUPNpL/2cE5cEqwVL1kdqVNQZGTE0Tqf8JMkNE7iNG559m2T7vM2CZ /vjIrT+iPhOnzvM1N6S08VkdCAx9bZbAjwnu1APXT0LJfoGZl0Gr3gG/45X7/Qhf1+a2 Us4K40CUE1gMYnJrVCW9H4DnNDeh+VeBN9LoY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=eFCWo0oWbZnhYOZMoBmXaawOnIJTUctBtvslC5IruVFT0jOVWAjLIyAIk+/ctBWWk5 TMDwQid5m9tmFs5EVqhQLT8lXf90jVHek8mV8Xw5K+C7rvZVj1AS678rqZf3WHYo1rmM 66FyzPRPUkvG19mIaUJES3oLlM8jx5xI6kY+E= Received: by 10.150.181.3 with SMTP id d3mr5826815ybf.28.1279903673406; Fri, 23 Jul 2010 09:47:53 -0700 (PDT) Received: from localhost.localdomain (curitiba.ic.unicamp.br [143.106.7.130]) by mx.google.com with ESMTPS id e7sm767506ybe.16.2010.07.23.09.47.48 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 23 Jul 2010 09:47:50 -0700 (PDT) From: Miguel Di Ciurcio Filho To: qemu-devel@nongnu.org Date: Fri, 23 Jul 2010 13:47:39 -0300 Message-Id: <1279903660-9607-3-git-send-email-miguel.filho@gmail.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1279903660-9607-1-git-send-email-miguel.filho@gmail.com> References: <1279903660-9607-1-git-send-email-miguel.filho@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: armbru@redhat.com, lcapitulino@redhat.com, Miguel Di Ciurcio Filho , avi@redhat.com Subject: [Qemu-devel] [PATCH v4 2/3] QMP: Introduce query-available-devices 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 --- hw/qdev.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/qdev.h | 1 + monitor.c | 8 ++++++ 3 files changed, 93 insertions(+), 0 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index e99c73f..14985f5 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -29,6 +29,7 @@ #include "qdev.h" #include "sysemu.h" #include "monitor.h" +#include "qjson.h" static int qdev_hotplug = 0; @@ -788,6 +789,89 @@ void do_info_qdm(Monitor *mon) } } +static const char *qdev_property_type_to_string(int type) +{ + switch (type) { + case PROP_TYPE_UINT8: + case PROP_TYPE_UINT16: + case PROP_TYPE_UINT32: + case PROP_TYPE_INT32: + case PROP_TYPE_UINT64: + return "integer"; + case PROP_TYPE_TADDR: + case PROP_TYPE_MACADDR: + case PROP_TYPE_DRIVE: + case PROP_TYPE_CHR: + case PROP_TYPE_STRING: + case PROP_TYPE_NETDEV: + return "string"; + case PROP_TYPE_BIT: + return "boolean"; + } + + return NULL; +} + +void do_available_devices(Monitor *mon, QObject **ret_data) +{ + DeviceInfo *info; + QList *devs = qlist_new(); + + for (info = device_info_list; info != NULL; info = info->next) { + QObject *obj; + QDict *dev; + QList *props = qlist_new(); + Property *prop; + const char *type; + + for (prop = info->props; prop && prop->name; prop++) { + QObject *entry; + /* + * TODO: skip old and hackish stuff, they will be removed some day. + */ + if (!prop->info->parse || prop->info->type == PROP_TYPE_VLAN + || prop->info->type == PROP_TYPE_PTR + || prop->info->type == PROP_TYPE_UNSPEC) { + continue; + } + + type = qdev_property_type_to_string(prop->info->type); + + assert(type != NULL); + + entry = qobject_from_jsonf("{ 'name': %s, 'type': %s }", + prop->name, type); + + qlist_append_obj(props, entry); + } + + obj = qobject_from_jsonf("{ 'name': %s, 'bus': %s, 'creatable': %i }", + info->name, + info->bus_info->name, + info->no_user ? 0 : 1); + + dev = qobject_to_qdict(obj); + + if (!qlist_empty(props)) { + qdict_put(dev, "properties", props); + } else { + QDECREF(props); + } + + if (info->alias) { + qdict_put(dev, "alias", qstring_from_str(info->alias)); + } + + if (info->desc) { + qdict_put(dev, "description", qstring_from_str(info->desc)); + } + + qlist_append(devs, dev); + } + + *ret_data = QOBJECT(devs); +} + int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data) { QemuOpts *opts; diff --git a/hw/qdev.h b/hw/qdev.h index 678f8b7..8c6fa06 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -185,6 +185,7 @@ void qbus_free(BusState *bus); void do_info_qtree(Monitor *mon); void do_info_qdm(Monitor *mon); +void do_available_devices(Monitor *mon, QObject **ret_data); int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data); int do_device_del(Monitor *mon, const QDict *qdict, QObject **ret_data); diff --git a/monitor.c b/monitor.c index 45fd482..384d5fc 100644 --- a/monitor.c +++ b/monitor.c @@ -2561,6 +2561,14 @@ static const mon_cmd_t info_cmds[] = { .mhandler.info = do_info_qtree, }, { + .name = "available-devices", + .args_type = "", + .params = "", + .help = "describes the capabilities of all supported devices", + .user_print = monitor_user_noop, + .mhandler.info_new = do_available_devices, + }, + { .name = "qdm", .args_type = "", .params = "",