From patchwork Mon Mar 5 06:57:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 10258255 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 A873460134 for ; Mon, 5 Mar 2018 07:03:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 968002883B for ; Mon, 5 Mar 2018 07:03:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B1532891E; Mon, 5 Mar 2018 07:03:45 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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 mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A91442883B for ; Mon, 5 Mar 2018 07:03:44 +0000 (UTC) Received: from localhost ([::1]:47515 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esk9w-0001mb-0P for patchwork-qemu-devel@patchwork.kernel.org; Mon, 05 Mar 2018 02:03:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47746) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esk46-0004v3-3o for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:57:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1esk42-0004h7-6C for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:57:42 -0500 Received: from mga03.intel.com ([134.134.136.65]:48550) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1esk41-0004gN-PI; Mon, 05 Mar 2018 01:57:38 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Mar 2018 22:57:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,426,1515484800"; d="scan'208";a="34645599" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.13.35]) by fmsmga004.fm.intel.com with ESMTP; 04 Mar 2018 22:57:33 -0800 From: Haozhong Zhang To: qemu-devel@nongnu.org Date: Mon, 5 Mar 2018 14:57:06 +0800 Message-Id: <20180305065710.25876-2-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180305065710.25876-1-haozhong.zhang@intel.com> References: <20180305065710.25876-1-haozhong.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.65 Subject: [Qemu-devel] [PATCH v3 1/5] pc-dimm: refactor qmp_pc_dimm_device_list X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Haozhong Zhang , Xiao Guangrong , mst@redhat.com, Bharata B Rao , Alexander Graf , Eduardo Habkost , Markus Armbruster , qemu-ppc@nongnu.org, Stefan Hajnoczi , Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , Dan Williams , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Use pc_dimm_built_list to hide recursive callbacks from callers. Signed-off-by: Haozhong Zhang --- hw/mem/pc-dimm.c | 83 +++++++++++++++++++++++++----------------------- hw/ppc/spapr.c | 3 +- include/hw/mem/pc-dimm.h | 2 +- numa.c | 4 +-- qmp.c | 7 +--- stubs/qmp_pc_dimm.c | 4 +-- 6 files changed, 50 insertions(+), 53 deletions(-) diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 6e74b61cb6..4d050fe2cd 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -162,45 +162,6 @@ uint64_t get_plugged_memory_size(void) return pc_existing_dimms_capacity(&error_abort); } -int qmp_pc_dimm_device_list(Object *obj, void *opaque) -{ - MemoryDeviceInfoList ***prev = opaque; - - 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_uint(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; - } - } - - object_child_foreach(obj, qmp_pc_dimm_device_list, opaque); - return 0; -} - static int pc_dimm_slot2bitmap(Object *obj, void *opaque) { unsigned long *bitmap = opaque; @@ -276,6 +237,50 @@ static int pc_dimm_built_list(Object *obj, void *opaque) return 0; } +MemoryDeviceInfoList *qmp_pc_dimm_device_list(void) +{ + GSList *dimms = NULL, *item; + MemoryDeviceInfoList *list = NULL, *prev = NULL; + + object_child_foreach(qdev_get_machine(), pc_dimm_built_list, &dimms); + + for (item = dimms; item; item = g_slist_next(item)) { + PCDIMMDevice *dimm = PC_DIMM(item->data); + Object *obj = OBJECT(dimm); + MemoryDeviceInfoList *elem = g_new0(MemoryDeviceInfoList, 1); + MemoryDeviceInfo *info = g_new0(MemoryDeviceInfo, 1); + PCDIMMDeviceInfo *di = g_new0(PCDIMMDeviceInfo, 1); + DeviceClass *dc = DEVICE_GET_CLASS(obj); + DeviceState *dev = DEVICE(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_uint(obj, 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; + if (prev) { + prev->next = elem; + } else { + list = elem; + } + prev = elem; + } + + g_slist_free(dimms); + + return list; +} + uint64_t pc_dimm_get_free_addr(uint64_t address_space_start, uint64_t address_space_size, uint64_t *hint, uint64_t align, uint64_t size, diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 83c9d66dd5..68a81e47d2 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -731,8 +731,7 @@ static int spapr_populate_drconf_memory(sPAPRMachineState *spapr, void *fdt) } if (hotplug_lmb_start) { - MemoryDeviceInfoList **prev = &dimms; - qmp_pc_dimm_device_list(qdev_get_machine(), &prev); + dimms = qmp_pc_dimm_device_list(); } /* ibm,dynamic-memory */ diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h index d83b957829..1fc479281c 100644 --- a/include/hw/mem/pc-dimm.h +++ b/include/hw/mem/pc-dimm.h @@ -93,7 +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_list(Object *obj, void *opaque); +MemoryDeviceInfoList *qmp_pc_dimm_device_list(void); uint64_t pc_existing_dimms_capacity(Error **errp); uint64_t get_plugged_memory_size(void); void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugState *hpms, diff --git a/numa.c b/numa.c index 7e0e789b02..c6734ceb8c 100644 --- a/numa.c +++ b/numa.c @@ -520,12 +520,10 @@ void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner, static void numa_stat_memory_devices(NumaNodeMem node_mem[]) { - MemoryDeviceInfoList *info_list = NULL; - MemoryDeviceInfoList **prev = &info_list; + MemoryDeviceInfoList *info_list = qmp_pc_dimm_device_list(); MemoryDeviceInfoList *info; PCDIMMDeviceInfo *pcdimm_info; - qmp_pc_dimm_device_list(qdev_get_machine(), &prev); for (info = info_list; info; info = info->next) { MemoryDeviceInfo *value = info->value; diff --git a/qmp.c b/qmp.c index 793f6f3323..c6ac7b05b4 100644 --- a/qmp.c +++ b/qmp.c @@ -680,12 +680,7 @@ void qmp_object_del(const char *id, Error **errp) MemoryDeviceInfoList *qmp_query_memory_devices(Error **errp) { - MemoryDeviceInfoList *head = NULL; - MemoryDeviceInfoList **prev = &head; - - qmp_pc_dimm_device_list(qdev_get_machine(), &prev); - - return head; + return qmp_pc_dimm_device_list(); } ACPIOSTInfoList *qmp_query_acpi_ospm_status(Error **errp) diff --git a/stubs/qmp_pc_dimm.c b/stubs/qmp_pc_dimm.c index 9ddc4f619a..b6b2cca89e 100644 --- a/stubs/qmp_pc_dimm.c +++ b/stubs/qmp_pc_dimm.c @@ -2,9 +2,9 @@ #include "qom/object.h" #include "hw/mem/pc-dimm.h" -int qmp_pc_dimm_device_list(Object *obj, void *opaque) +MemoryDeviceInfoList *qmp_pc_dimm_device_list(void) { - return 0; + return NULL; } uint64_t get_plugged_memory_size(void)