From patchwork Tue Jun 17 17:41:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 360811 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1F7FF140091 for ; Wed, 18 Jun 2014 06:13:41 +1000 (EST) Received: from localhost ([::1]:53191 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WwzlD-0005L5-2A for incoming@patchwork.ozlabs.org; Tue, 17 Jun 2014 16:13:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58217) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WwxOa-0000ZS-BL for qemu-devel@nongnu.org; Tue, 17 Jun 2014 13:42:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WwxOV-0005Jt-NE for qemu-devel@nongnu.org; Tue, 17 Jun 2014 13:42:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:20523) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WwxOV-0005JZ-Ft for qemu-devel@nongnu.org; Tue, 17 Jun 2014 13:42:03 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s5HHfIwF031912 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Jun 2014 13:41:18 -0400 Received: from redhat.com (ovpn-116-78.ams2.redhat.com [10.36.116.78]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s5HHfEU0027193; Tue, 17 Jun 2014 13:41:15 -0400 Date: Tue, 17 Jun 2014 20:41:43 +0300 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <1403021756-15960-89-git-send-email-mst@redhat.com> References: <1403021756-15960-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1403021756-15960-1-git-send-email-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id s5HHfIwF031912 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Peter Maydell , Eduardo Habkost , Hu Tao , Markus Armbruster , Luiz Capitulino , Anthony Liguori , Paolo Bonzini , Wanlong Gao Subject: [Qemu-devel] [PULL 088/103] qmp: add query-memdev 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 From: Hu Tao Add qmp command query-memdev to query for information of memory devices Signed-off-by: Hu Tao Acked-by: Michael S. Tsirkin --- qapi-schema.json | 40 +++++++++++++++++++++++++++ numa.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 38 +++++++++++++++++++++++++ 3 files changed, 162 insertions(+) diff --git a/qapi-schema.json b/qapi-schema.json index fa1b876..4c367d0 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4796,3 +4796,43 @@ ## { 'enum': 'HostMemPolicy', 'data': [ 'default', 'preferred', 'bind', 'interleave' ] } + +## +# @Memdev: +# +# Information of memory device +# +# @size: memory device size +# +# @merge: enables or disables memory merge support +# +# @dump: includes memory device's memory in a core dump or not +# +# @prealloc: enables or disables memory preallocation +# +# @host-nodes: host nodes for its memory policy +# +# @policy: memory policy of memory device +# +# Since: 2.1 +## + +{ 'type': 'Memdev', + 'data': { + 'size': 'size', + 'merge': 'bool', + 'dump': 'bool', + 'prealloc': 'bool', + 'host-nodes': ['uint16'], + 'policy': 'HostMemPolicy' }} + +## +# @query-memdev: +# +# Returns information for all memory devices. +# +# Returns: a list of @Memdev. +# +# Since: 2.1 +## +{ 'command': 'query-memdev', 'returns': ['Memdev'] } diff --git a/numa.c b/numa.c index 711f682..eef0717 100644 --- a/numa.c +++ b/numa.c @@ -34,6 +34,7 @@ #include "qapi/qmp/qerror.h" #include "hw/boards.h" #include "sysemu/hostmem.h" +#include "qmp-commands.h" QemuOptsList qemu_numa_opts = { .name = "numa", @@ -283,3 +284,86 @@ void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner, addr += size; } } + +static int query_memdev(Object *obj, void *opaque) +{ + MemdevList **list = opaque; + Error *err = NULL; + + if (object_dynamic_cast(obj, TYPE_MEMORY_BACKEND)) { + MemdevList *m = g_malloc0(sizeof(*m)); + + m->value = g_malloc0(sizeof(*m->value)); + + m->value->size = object_property_get_int(obj, "size", + &err); + if (err) { + goto error; + } + + m->value->merge = object_property_get_bool(obj, "merge", + &err); + if (err) { + goto error; + } + + m->value->dump = object_property_get_bool(obj, "dump", + &err); + if (err) { + goto error; + } + + m->value->prealloc = object_property_get_bool(obj, + "prealloc", &err); + if (err) { + goto error; + } + + m->value->policy = object_property_get_enum(obj, + "policy", + HostMemPolicy_lookup, + &err); + if (err) { + goto error; + } + + object_property_get_uint16List(obj, "host-nodes", + &m->value->host_nodes, &err); + if (err) { + goto error; + } + + m->next = *list; + *list = m; + } + + return 0; +error: + return -1; +} + +MemdevList *qmp_query_memdev(Error **errp) +{ + Object *obj; + MemdevList *list = NULL, *m; + + obj = object_resolve_path("/objects", NULL); + if (obj == NULL) { + return NULL; + } + + if (object_child_foreach(obj, query_memdev, &list) != 0) { + goto error; + } + + return list; + +error: + while (list) { + m = list; + list = list->next; + g_free(m->value); + g_free(m); + } + return NULL; +} diff --git a/qmp-commands.hx b/qmp-commands.hx index d8aa4ed..bb34cd8 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -3572,3 +3572,41 @@ Example: } } ] } EQMP + + { + .name = "query-memdev", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_query_memdev, + }, + +SQMP +query-memdev +------------ + +Show memory devices information. + + +Example (1): + +-> { "execute": "query-memdev" } +<- { "return": [ + { + "size": 536870912, + "merge": false, + "dump": true, + "prealloc": false, + "host-nodes": [0, 1], + "policy": "bind" + }, + { + "size": 536870912, + "merge": false, + "dump": true, + "prealloc": true, + "host-nodes": [2, 3], + "policy": "preferred" + } + ] + } + +EQMP