From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38586) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YFxOw-0000Uh-Ka for qemu-devel@nongnu.org; Mon, 26 Jan 2015 23:05:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YFxOq-0004w5-8N for qemu-devel@nongnu.org; Mon, 26 Jan 2015 23:05:18 -0500 Received: from e28smtp02.in.ibm.com ([122.248.162.2]:40354) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YFxOp-0004vg-K0 for qemu-devel@nongnu.org; Mon, 26 Jan 2015 23:05:12 -0500 Received: from /spool/local by e28smtp02.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 27 Jan 2015 09:35:07 +0530 Received: from d28relay03.in.ibm.com (d28relay03.in.ibm.com [9.184.220.60]) by d28dlp01.in.ibm.com (Postfix) with ESMTP id 15738E0057 for ; Tue, 27 Jan 2015 09:36:25 +0530 (IST) Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay03.in.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t0R454uA1835386 for ; Tue, 27 Jan 2015 09:35:05 +0530 Received: from d28av02.in.ibm.com (localhost [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t0R454xU024348 for ; Tue, 27 Jan 2015 09:35:04 +0530 From: Bharata B Rao Date: Tue, 27 Jan 2015 09:35:00 +0530 Message-Id: <1422331502-24636-2-git-send-email-bharata@linux.vnet.ibm.com> In-Reply-To: <1422331502-24636-1-git-send-email-bharata@linux.vnet.ibm.com> References: <1422331502-24636-1-git-send-email-bharata@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH v2 1/3] pc: Fix DIMMs capacity calculation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: imammedo@redhat.com, Bharata B Rao pc_existing_dimms_capacity() is returning DIMMs count rather than capacity. Fix this to return the capacity. Also consider only realized devices for capacity calculation. Signed-off-by: Bharata B Rao Reviewed-by: Igor Mammedov --- hw/i386/pc.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index e07f1fa..125cf0a 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1552,25 +1552,18 @@ void qemu_register_pc_machine(QEMUMachine *m) g_free(name); } -static int pc_dimm_count(Object *obj, void *opaque) -{ - int *count = opaque; - - if (object_dynamic_cast(obj, TYPE_PC_DIMM)) { - (*count)++; - } - - object_child_foreach(obj, pc_dimm_count, opaque); - return 0; -} - static int pc_existing_dimms_capacity(Object *obj, void *opaque) { Error *local_err = NULL; uint64_t *size = opaque; if (object_dynamic_cast(obj, TYPE_PC_DIMM)) { - (*size) += object_property_get_int(obj, PC_DIMM_SIZE_PROP, &local_err); + DeviceState *dev = DEVICE(obj); + + if (dev->realized) { + (*size) += object_property_get_int(obj, PC_DIMM_SIZE_PROP, + &local_err); + } if (local_err) { qerror_report_err(local_err); @@ -1579,7 +1572,7 @@ static int pc_existing_dimms_capacity(Object *obj, void *opaque) } } - object_child_foreach(obj, pc_dimm_count, opaque); + object_child_foreach(obj, pc_existing_dimms_capacity, opaque); return 0; } @@ -1623,8 +1616,9 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev, if (existing_dimms_capacity + memory_region_size(mr) > machine->maxram_size - machine->ram_size) { error_setg(&local_err, "not enough space, currently 0x%" PRIx64 - " in use of total 0x" RAM_ADDR_FMT, - existing_dimms_capacity, machine->maxram_size); + " in use of total hot pluggable 0x" RAM_ADDR_FMT, + existing_dimms_capacity, + machine->maxram_size - machine->ram_size); goto out; } -- 2.1.0