pc: Fix DIMMs capacity calculation
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 <bharata@linux.vnet.ibm.com> Reviewed-by: Igor Mammedov <imammedo@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
		
							parent
							
								
									07d01c9c19
								
							
						
					
					
						commit
						759048ac20
					
				
							
								
								
									
										26
									
								
								hw/i386/pc.c
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								hw/i386/pc.c
									
									
									
									
									
								
							@ -1552,25 +1552,18 @@ void qemu_register_pc_machine(QEMUMachine *m)
 | 
				
			|||||||
    g_free(name);
 | 
					    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)
 | 
					static int pc_existing_dimms_capacity(Object *obj, void *opaque)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    Error *local_err = NULL;
 | 
					    Error *local_err = NULL;
 | 
				
			||||||
    uint64_t *size = opaque;
 | 
					    uint64_t *size = opaque;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (object_dynamic_cast(obj, TYPE_PC_DIMM)) {
 | 
					    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) {
 | 
					        if (local_err) {
 | 
				
			||||||
            qerror_report_err(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;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -1623,8 +1616,9 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev,
 | 
				
			|||||||
    if (existing_dimms_capacity + memory_region_size(mr) >
 | 
					    if (existing_dimms_capacity + memory_region_size(mr) >
 | 
				
			||||||
        machine->maxram_size - machine->ram_size) {
 | 
					        machine->maxram_size - machine->ram_size) {
 | 
				
			||||||
        error_setg(&local_err, "not enough space, currently 0x%" PRIx64
 | 
					        error_setg(&local_err, "not enough space, currently 0x%" PRIx64
 | 
				
			||||||
                   " in use of total 0x" RAM_ADDR_FMT,
 | 
					                   " in use of total hot pluggable 0x" RAM_ADDR_FMT,
 | 
				
			||||||
                   existing_dimms_capacity, machine->maxram_size);
 | 
					                   existing_dimms_capacity,
 | 
				
			||||||
 | 
					                   machine->maxram_size - machine->ram_size);
 | 
				
			||||||
        goto out;
 | 
					        goto out;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user