From patchwork Mon Mar 20 00:12:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9632893 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 710A460327 for ; Mon, 20 Mar 2017 00:16:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 648FE27F60 for ; Mon, 20 Mar 2017 00:16:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5937A27F9F; Mon, 20 Mar 2017 00:16:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 46C122810E for ; Mon, 20 Mar 2017 00:15:57 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cpkwx-0006pb-A2; Mon, 20 Mar 2017 00:13:27 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cpkww-0006n3-IX for xen-devel@lists.xen.org; Mon, 20 Mar 2017 00:13:26 +0000 Received: from [85.158.143.35] by server-10.bemta-6.messagelabs.com id 18/D2-13192-5AE1FC85; Mon, 20 Mar 2017 00:13:25 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrNLMWRWlGSWpSXmKPExsVywNykWHep3Pk Ig9NdrBZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8a7zU/ZChp9Kjb93s7cwHjSuouRi4NF4BaT xOQNH1lAHCGB6YwSq39sZOti5OSQEOCVOLJsBiuE7Sexf997qKJeRokH0xvAitgE9CVWPD4IV MTBISJgLNF20xmkhlngL5PEy/dvmUBqhAUyJL5+egs2iEVAVWLPpaNgvbwCdhJdj74xQSyQl7 hw9RQLyBxOoHjHbDeQsJCArcSPVZNZJjDyLWBkWMWoUZxaVJZapGtooJdUlJmeUZKbmJkD5Jn p5aYWFyemp+YkJhXrJefnbmIEBgoDEOxgvLcs4BCjJAeTkijvP/VzEUJ8SfkplRmJxRnxRaU5 qcWHGGU4OJQkeLdLnY8QEixKTU+tSMvMAYYsTFqCg0dJhNddGijNW1yQmFucmQ6ROsWoKCXOa wWSEABJZJTmwbXB4uQSo6yUMC8j0CFCPAWpRbmZJajyrxjFORiVhHk/gWznycwrgZv+CmgxE9 DiZTfOgCwuSURISTUwSuU+qZm0KZGx6q5NweK66b4Zn3mZDDVOLDEXCJHu1w4775yUfM+C4ee PRq/VkYFeaTPXfTG8f6xn/7EizpsrH8+2lO9c0VnTXMm8s+Hkiu1fP15NWiPgvCRdPFKn2KJT 8Bv/osBLkx2kX54/PuW09vE5Uquzjq/MfHjsvkOPgGnf65kybQeSlFiKMxINtZiLihMBdKs+Y Y4CAAA= X-Env-Sender: haozhong.zhang@intel.com X-Msg-Ref: server-15.tower-21.messagelabs.com!1489968802!62980042!1 X-Originating-IP: [192.55.52.115] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 62505 invoked from network); 20 Mar 2017 00:13:24 -0000 Received: from mga14.intel.com (HELO mga14.intel.com) (192.55.52.115) by server-15.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 20 Mar 2017 00:13:24 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1489968804; x=1521504804; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=UEnBaZ7eVpL7JP2HQO1BNemU2PC0rjpVI9oxoH8tOkQ=; b=e7AloZuw4C6XH4cJ887ZFX0VlUO7EegB/1d3I8apOVLp8WmoJNVbaVAg GCYeh+pg5aqohPs/hKmrXcb5iRPdLA==; Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Mar 2017 17:13:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,191,1486454400"; d="scan'208";a="78799216" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.153]) by fmsmga006.fm.intel.com with ESMTP; 19 Mar 2017 17:13:20 -0700 From: Haozhong Zhang To: qemu-devel@nongnu.org, xen-devel@lists.xen.org Date: Mon, 20 Mar 2017 08:12:49 +0800 Message-Id: <20170320001249.25521-11-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20170320001249.25521-1-haozhong.zhang@intel.com> References: <20170320001249.25521-1-haozhong.zhang@intel.com> Cc: Haozhong Zhang , Xiao Guangrong , "Michael S. Tsirkin" , "Dr. David Alan Gilbert" , Markus Armbruster , Igor Mammedov , Konrad Rzeszutek Wilk , Dan Williams , Eric Blake Subject: [Xen-devel] [RFC QEMU PATCH v2 10/10] qapi: extend 'query-memory-devices' to list devices of specified type X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add an optional argument 'devtype' to 'query-memory-devices', which is either 'dimm' or 'nvdimm'. If 'devtype' is missed or 'dimm', all memory devices will be listed. If 'devtype' is 'nvdimm', only nvdimm devices will be listed. Signed-off-by: Haozhong Zhang --- Cc: "Dr. David Alan Gilbert" Cc: Xiao Guangrong Cc: "Michael S. Tsirkin" Cc: Igor Mammedov Cc: Eric Blake Cc: Markus Armbruster --- hmp.c | 3 +- hw/mem/nvdimm.c | 38 ++++++++++++++++++++++++++ hw/mem/pc-dimm.c | 71 ++++++++++++++++++++++++++++-------------------- include/hw/mem/nvdimm.h | 2 ++ include/hw/mem/pc-dimm.h | 1 + qapi-schema.json | 48 +++++++++++++++++++++++++++++--- qmp.c | 13 +++++++-- 7 files changed, 140 insertions(+), 36 deletions(-) diff --git a/hmp.c b/hmp.c index 261843f7a2..35ad8c9716 100644 --- a/hmp.c +++ b/hmp.c @@ -2144,7 +2144,8 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict) void hmp_info_memory_devices(Monitor *mon, const QDict *qdict) { Error *err = NULL; - MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err); + MemoryDeviceInfoList *info_list = + qmp_query_memory_devices(true, MEMORY_DEVICE_TYPE_DIMM, &err); MemoryDeviceInfoList *info; MemoryDeviceInfo *value; PCDIMMDeviceInfo *di; diff --git a/hw/mem/nvdimm.c b/hw/mem/nvdimm.c index 0d3e17e94c..811efda869 100644 --- a/hw/mem/nvdimm.c +++ b/hw/mem/nvdimm.c @@ -178,3 +178,41 @@ static void nvdimm_register_types(void) } type_init(nvdimm_register_types) + +static int qmp_nvdimm_device_info(Object *obj, NVDIMMDeviceInfo *di) +{ + if (!object_dynamic_cast(obj, TYPE_NVDIMM)) { + return 1; + } + + if (qmp_pc_dimm_device_info(obj, (PCDIMMDeviceInfo *)di)) { + return 1; + } + + di->label_size = object_property_get_int(obj, "label-size", NULL); + + return 0; +} + +int qmp_nvdimm_device_list(Object *obj, void *opaque) +{ + MemoryDeviceInfoList ***prev = opaque; + NVDIMMDeviceInfo *di = g_new0(NVDIMMDeviceInfo, 1); + + if (qmp_nvdimm_device_info(obj, di)) { + g_free(di); + } else { + MemoryDeviceInfoList *elem = g_new0(MemoryDeviceInfoList, 1); + MemoryDeviceInfo *info = g_new0(MemoryDeviceInfo, 1); + + info->type = MEMORY_DEVICE_TYPE_NVDIMM; + info->u.nvdimm.data = di; + elem->value = info; + elem->next = NULL; + **prev = elem; + *prev = &elem->next; + } + + object_child_foreach(obj, qmp_nvdimm_device_list, opaque); + return 0; +} diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 69c5784252..40a9c31cc5 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -161,39 +161,52 @@ uint64_t pc_existing_dimms_capacity(Error **errp) return cap.size; } +int qmp_pc_dimm_device_info(Object *obj, PCDIMMDeviceInfo *di) +{ + DeviceState *dev; + DeviceClass *dc; + PCDIMMDevice *dimm; + + if (!object_dynamic_cast(obj, TYPE_PC_DIMM)) { + return 1; + } + + dev = DEVICE(obj); + dc = DEVICE_GET_CLASS(obj); + dimm = PC_DIMM(obj); + + if (dev->id) { + di->has_id = true; + di->id = g_strdup(dev->id); + } + di->hotplugged = dev->hotplugged; + di->hotpluggable = dc->hotpluggable; + di->addr = dimm->addr; + di->slot = dimm->slot; + di->node = dimm->node; + di->size = object_property_get_int(OBJECT(dimm), PC_DIMM_SIZE_PROP, NULL); + di->memdev = object_get_canonical_path(OBJECT(dimm->hostmem)); + + return 0; +} + int qmp_pc_dimm_device_list(Object *obj, void *opaque) { MemoryDeviceInfoList ***prev = opaque; + PCDIMMDeviceInfo *di = g_new0(PCDIMMDeviceInfo, 1); - if (object_dynamic_cast(obj, TYPE_PC_DIMM)) { - DeviceState *dev = DEVICE(obj); - - if (dev->realized) { - MemoryDeviceInfoList *elem = g_new0(MemoryDeviceInfoList, 1); - MemoryDeviceInfo *info = g_new0(MemoryDeviceInfo, 1); - PCDIMMDeviceInfo *di = g_new0(PCDIMMDeviceInfo, 1); - DeviceClass *dc = DEVICE_GET_CLASS(obj); - PCDIMMDevice *dimm = PC_DIMM(obj); - - if (dev->id) { - di->has_id = true; - di->id = g_strdup(dev->id); - } - di->hotplugged = dev->hotplugged; - di->hotpluggable = dc->hotpluggable; - di->addr = dimm->addr; - di->slot = dimm->slot; - di->node = dimm->node; - di->size = object_property_get_int(OBJECT(dimm), PC_DIMM_SIZE_PROP, - NULL); - di->memdev = object_get_canonical_path(OBJECT(dimm->hostmem)); - - info->u.dimm.data = di; - elem->value = info; - elem->next = NULL; - **prev = elem; - *prev = &elem->next; - } + if (qmp_pc_dimm_device_info(obj, di)) { + g_free(di); + } else { + MemoryDeviceInfoList *elem = g_new0(MemoryDeviceInfoList, 1); + MemoryDeviceInfo *info = g_new0(MemoryDeviceInfo, 1); + + info->type = MEMORY_DEVICE_TYPE_DIMM; + info->u.dimm.data = di; + elem->value = info; + elem->next = NULL; + **prev = elem; + *prev = &elem->next; } object_child_foreach(obj, qmp_pc_dimm_device_list, opaque); diff --git a/include/hw/mem/nvdimm.h b/include/hw/mem/nvdimm.h index 03e1ff9558..89c79564c8 100644 --- a/include/hw/mem/nvdimm.h +++ b/include/hw/mem/nvdimm.h @@ -132,4 +132,6 @@ void nvdimm_build_acpi(GArray *table_offsets, GArray *table_data, uint32_t ram_slots); void nvdimm_plug(AcpiNVDIMMState *state); void nvdimm_acpi_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev); + +int qmp_nvdimm_device_list(Object *obj, void *opaque); #endif diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h index 1e483f2670..5f74febeaa 100644 --- a/include/hw/mem/pc-dimm.h +++ b/include/hw/mem/pc-dimm.h @@ -93,6 +93,7 @@ uint64_t pc_dimm_get_free_addr(uint64_t address_space_start, int pc_dimm_get_free_slot(const int *hint, int max_slots, Error **errp); +int qmp_pc_dimm_device_info(Object *obj, PCDIMMDeviceInfo *di); int qmp_pc_dimm_device_list(Object *obj, void *opaque); uint64_t pc_existing_dimms_capacity(Error **errp); void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugState *hpms, diff --git a/qapi-schema.json b/qapi-schema.json index 32b4a4b782..5280de2405 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -5811,24 +5811,62 @@ } ## +# @NVDIMMDeviceInfo: +# +# NVDIMMDevice state information +# +# @label-size: size the label storage area +# +# Since 2.9 +## +{ 'struct': 'NVDIMMDeviceInfo', + 'base': 'PCDIMMDeviceInfo', + 'data': { 'label-size': 'int' } +} + +## # @MemoryDeviceInfo: # # Union containing information about a memory device # +# - @dimm: since 2.1 +# - @nvdimm: since 2.9 +# # Since: 2.1 ## -{ 'union': 'MemoryDeviceInfo', 'data': {'dimm': 'PCDIMMDeviceInfo'} } +{ 'union': 'MemoryDeviceInfo', + 'data': {'dimm': 'PCDIMMDeviceInfo', 'nvdimm': 'NVDIMMDeviceInfo'} +} + +## +# @MemoryDeviceType: +# +# Type of memory devices. +# +# @dimm: pc-dimm memory device +# +# @nvdimm: nvdimm memory device +# +# Since 2.9 +## +{ 'enum': 'MemoryDeviceType', 'data': [ 'dimm', 'nvdimm' ] } ## # @query-memory-devices: # -# Lists available memory devices and their state +# Lists available memory devices and their state. If the optional argument +# @devtype is present, only memory devices of the specified type are included. +# +# @devtype: specify the type of memory devices to be listed. If 'dimm' is +# specified, all pc-dimm devices (including nvdimm devices which is +# a subtype of pc-dimm) will be listed. If 'nvdimm' is specified, +# only nvdimm devices will be listed. (Since 2.9) # # Since: 2.1 # # Example: # -# -> { "execute": "query-memory-devices" } +# -> { "execute": "query-memory-devices", "arguments": { "devtype": "dimm" } } # <- { "return": [ { "data": # { "addr": 5368709120, # "hotpluggable": true, @@ -5842,7 +5880,9 @@ # } ] } # ## -{ 'command': 'query-memory-devices', 'returns': ['MemoryDeviceInfo'] } +{ 'command': 'query-memory-devices', + 'data': { '*devtype': 'MemoryDeviceType' }, + 'returns': ['MemoryDeviceInfo'] } ## # @ACPISlotType: diff --git a/qmp.c b/qmp.c index fa82b598c6..179a10bced 100644 --- a/qmp.c +++ b/qmp.c @@ -36,6 +36,7 @@ #include "hw/boards.h" #include "qom/object_interfaces.h" #include "hw/mem/pc-dimm.h" +#include "hw/mem/nvdimm.h" #include "hw/acpi/acpi_dev_interface.h" NameInfo *qmp_query_name(Error **errp) @@ -689,12 +690,20 @@ void qmp_object_del(const char *id, Error **errp) user_creatable_del(id, errp); } -MemoryDeviceInfoList *qmp_query_memory_devices(Error **errp) +MemoryDeviceInfoList *qmp_query_memory_devices(bool has_devtype, + MemoryDeviceType devtype, + Error **errp) { MemoryDeviceInfoList *head = NULL; MemoryDeviceInfoList **prev = &head; - qmp_pc_dimm_device_list(qdev_get_machine(), &prev); + if (!has_devtype || devtype == MEMORY_DEVICE_TYPE_DIMM) { + qmp_pc_dimm_device_list(qdev_get_machine(), &prev); + } else if (devtype == MEMORY_DEVICE_TYPE_NVDIMM) { + qmp_nvdimm_device_list(qdev_get_machine(), &prev); + } else { + error_setg(errp, "unrecognized memory device type %d", devtype); + } return head; }