From patchwork Sun Apr 27 10:29:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hani Benhabiles X-Patchwork-Id: 343136 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D38A91400A6 for ; Sun, 27 Apr 2014 20:30:11 +1000 (EST) Received: from localhost ([::1]:38725 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WeMLZ-0003b6-0g for incoming@patchwork.ozlabs.org; Sun, 27 Apr 2014 06:30:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33907) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WeMLD-0002Wo-G2 for qemu-devel@nongnu.org; Sun, 27 Apr 2014 06:29:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WeML7-0000gM-GW for qemu-devel@nongnu.org; Sun, 27 Apr 2014 06:29:47 -0400 Received: from mail-we0-x234.google.com ([2a00:1450:400c:c03::234]:49207) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WeML7-0000gB-6i for qemu-devel@nongnu.org; Sun, 27 Apr 2014 06:29:41 -0400 Received: by mail-we0-f180.google.com with SMTP id t61so441433wes.11 for ; Sun, 27 Apr 2014 03:29:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=Dg5RpERLwSjFVEVy+QK/c0iD5rwsyuEomvzQfXCaV4g=; b=LFyP6fRdYXi59/lrJT9QQY0v5kLKqsy0w/FEWw603BtV7j7nzWKsDMk5hx9DU3zIFM GpmAdUz/DdxaCCOx90ZmoA/QBIEE8LFMPwiTyI8/WE4zhs78szcGszze7L6jQ/W7nglC +JCkaxGdhywwp8gY7klZgoX3+mowvKazWteLZ3PTWGL8qNTBdCw6a6MRNUZ2OrdjDNy3 /t+IO76FnjWfrofVKI2QDqu+lg0T4thAUVVXYcJlbkj5nC9EBzgvlvgL/yTFSXpBmmCN CbAgIOCc3eZkiue4JU17xu9Bgmgzhj8VadW3RNS6mt5r94NjetwygYKRHX8MKkKexgqV LDyg== X-Received: by 10.180.80.3 with SMTP id n3mr10644702wix.36.1398594579766; Sun, 27 Apr 2014 03:29:39 -0700 (PDT) Received: from localhost.localdomain ([41.104.79.200]) by mx.google.com with ESMTPSA id xm20sm9923467wib.19.2014.04.27.03.29.37 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 27 Apr 2014 03:29:38 -0700 (PDT) From: Hani Benhabiles To: qemu-devel@nongnu.org Date: Sun, 27 Apr 2014 11:29:30 +0100 Message-Id: <1398594570-14015-1-git-send-email-kroosec@gmail.com> X-Mailer: git-send-email 1.8.3.2 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c03::234 Cc: pbonzini@redhat.com, stefanha@redhat.com, afaerber@suse.de, armbru@redhat.com, lcapitulino@redhat.com Subject: [Qemu-devel] [PATCH] monitor: Add info qom-tree subcommand. 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: Hani Benhabiles --- Not sure whether the qobject stringifying functions could fit or be of some use elsewhere. Thus, I kept them as static near the only place where they are used at the moment. hmp-commands.hx | 2 + hmp.c | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ hmp.h | 1 + monitor.c | 7 +++ 4 files changed, 153 insertions(+) diff --git a/hmp-commands.hx b/hmp-commands.hx index f3fc514..65b5e33 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1754,6 +1754,8 @@ show qdev device model list show roms @item info tpm show the TPM device +@item info qom-tree +show the QOM tree @end table ETEXI diff --git a/hmp.c b/hmp.c index 2f279c4..891a34e 100644 --- a/hmp.c +++ b/hmp.c @@ -22,9 +22,11 @@ #include "qemu/sockets.h" #include "monitor/monitor.h" #include "qapi/opts-visitor.h" +#include "qapi/qmp/types.h" #include "ui/console.h" #include "block/qapi.h" #include "qemu-io.h" +#include "qom/qom-qobject.h" static void hmp_handle_error(Monitor *mon, Error **errp) { @@ -712,6 +714,147 @@ void hmp_info_tpm(Monitor *mon, const QDict *qdict) qapi_free_TPMInfoList(info_list); } +static char *qobject_to_str(const QObject *, int); + +static char *qlist_to_str(const QObject *obj, int indent) +{ + char *buf = NULL; + const QListEntry *entry; + int i = 0; + + assert(qobject_type(obj) == QTYPE_QLIST); + + entry = qlist_first(qobject_to_qlist(obj)); + while (entry) { + char *new, *str; + int type = qobject_type(entry->value); + str = qobject_to_str(entry->value, indent); + if (type == QTYPE_QLIST || type == QTYPE_QDICT) { + new = g_strdup_printf("%s%*sElement #%d:\n%s", buf ?: "", + indent, "", i++, str); + } else { + new = g_strdup_printf("%s%*sElement #%d: %s\n", buf ?: "", + indent, "", i++, str); + } + g_free(buf); + g_free(str); + buf = new; + entry = qlist_next(entry); + } + return buf; +} + +static char *qdict_to_str(const QObject *obj, int indent) +{ + QDict *dict = qobject_to_qdict(obj); + const QDictEntry *entry; + char *buf = NULL; + + assert(qobject_type(obj) == QTYPE_QDICT); + + for (entry = qdict_first(dict); entry; entry = qdict_next(dict, entry)) { + char *str, *new; + int type = qobject_type(entry->value); + str = qobject_to_str(entry->value, indent); + if (type == QTYPE_QLIST || type == QTYPE_QDICT) { + new = g_strdup_printf("%s%*s%s:\n%s", buf ?: "", indent, "", + entry->key, str); + } else { + new = g_strdup_printf("%s%*s%s: %s\n", buf ?: "", indent, "", + entry->key, str); + } + g_free(buf); + g_free(str); + buf = new; + } + return buf; +} + +static char *qobject_to_str(const QObject *obj, int indent) +{ + switch (qobject_type(obj)) { + case QTYPE_QSTRING: { + QString *value = qobject_to_qstring(obj); + return g_strdup(qstring_get_str(value)); + } + case QTYPE_QINT: { + QInt *value = qobject_to_qint(obj); + return g_strdup_printf("%" PRId64, qint_get_int(value)); + } + case QTYPE_QBOOL: { + QBool *value = qobject_to_qbool(obj); + return g_strdup(qbool_get_int(value) ? "True" : "False"); + } + case QTYPE_QERROR: { + QString *value = qerror_human((QError *)obj); + return g_strdup(qstring_get_str(value)); + } + case QTYPE_QFLOAT: { + QFloat *value = qobject_to_qfloat(obj); + return g_strdup_printf("%g", qfloat_get_double(value)); + } + case QTYPE_QLIST: + return qlist_to_str(obj, indent + 2); + case QTYPE_QDICT: + return qdict_to_str(obj, indent + 2); + case QTYPE_NONE: + break; + case QTYPE_MAX: + default: + abort(); + } + return NULL; +} + +static void hmp_print_qom_tree(Monitor *mon, const char *path, int indent) +{ + ObjectPropertyInfoList *list, *start; + + monitor_printf(mon, "%*s%s:\n", indent, "", path); + start = list = qmp_qom_list(path, NULL); + indent += 2; + while (list) { + ObjectPropertyInfo *info = list->value; + + if (!strncmp(info->type, "child<", 5)) { + char *name = g_strdup_printf("%s/%s", path, info->name); + hmp_print_qom_tree(mon, name, indent); + g_free(name); + } else { + Object *obj = NULL; + QObject *data = NULL; + char *str; + + obj = object_resolve_path(path, NULL); + if (!obj) { + list = list->next; + continue; + } + data = object_property_get_qobject(obj, info->name, NULL); + if (!data) { + list = list->next; + continue; + } + str = qobject_to_str(data, indent); + if (qobject_type(data) == QTYPE_QDICT + || qobject_type(data) == QTYPE_QLIST) { + monitor_printf(mon, "%*s%s:\n%s", indent, "", info->name, str); + } else { + monitor_printf(mon, "%*s%s: %s\n", indent, "", info->name, str); + } + g_free(str); + qobject_decref(data); + } + list = list->next; + } + qapi_free_ObjectPropertyInfoList(start); +} + +void hmp_info_qom_tree(Monitor *mon, const QDict *qdict) +{ + hmp_print_qom_tree(mon, "/machine", 0); +} + void hmp_quit(Monitor *mon, const QDict *qdict) { monitor_suspend(mon); diff --git a/hmp.h b/hmp.h index ed58f0e..1733242 100644 --- a/hmp.h +++ b/hmp.h @@ -37,6 +37,7 @@ void hmp_info_balloon(Monitor *mon, const QDict *qdict); void hmp_info_pci(Monitor *mon, const QDict *qdict); void hmp_info_block_jobs(Monitor *mon, const QDict *qdict); void hmp_info_tpm(Monitor *mon, const QDict *qdict); +void hmp_info_qom_tree(Monitor *mon, const QDict *qdict); void hmp_quit(Monitor *mon, const QDict *qdict); void hmp_stop(Monitor *mon, const QDict *qdict); void hmp_system_reset(Monitor *mon, const QDict *qdict); diff --git a/monitor.c b/monitor.c index 342e83b..fcb1d0c 100644 --- a/monitor.c +++ b/monitor.c @@ -2966,6 +2966,13 @@ static mon_cmd_t info_cmds[] = { .mhandler.cmd = hmp_info_tpm, }, { + .name = "qom-tree", + .args_type = "", + .params = "", + .help = "show the QOM tree", + .mhandler.cmd = hmp_info_qom_tree, + }, + { .name = NULL, }, };