On Mon, 16 Mar 2015 16:58:17 +0800 Zhu Guihua <zhugh.f...@cn.fujitsu.com> wrote:
> From: Tang Chen <tangc...@cn.fujitsu.com> > > Implement unplug cb for pc-dimm. It calls memory unplug cb to reset > some memory status, removes the corresponding memory region, and > unregisters vmstate. > > Signed-off-by: Tang Chen <tangc...@cn.fujitsu.com> > Signed-off-by: Zhu Guihua <zhugh.f...@cn.fujitsu.com> Please, squash this patch into previous. > --- > hw/i386/pc.c | 26 ++++++++++++++++++++++++-- > 1 file changed, 24 insertions(+), 2 deletions(-) > > diff --git a/hw/i386/pc.c b/hw/i386/pc.c > index 9c7c318..141fa6a 100644 > --- a/hw/i386/pc.c > +++ b/hw/i386/pc.c > @@ -1689,6 +1689,23 @@ out: > error_propagate(errp, local_err); > } > > +static void pc_dimm_unplug(HotplugHandler *hotplug_dev, > + DeviceState *dev, Error **errp) > +{ > + PCMachineState *pcms = PC_MACHINE(hotplug_dev); > + PCDIMMDevice *dimm = PC_DIMM(dev); > + PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm); > + MemoryRegion *mr = ddc->get_memory_region(dimm); > + HotplugHandlerClass *hhc; > + Error *local_err = NULL; > + > + hhc = HOTPLUG_HANDLER_GET_CLASS(pcms->acpi_dev); > + hhc->unplug(HOTPLUG_HANDLER(pcms->acpi_dev), dev, &local_err); potentially leaking local_err, should be propagated to errp and maybe in case of error here we shouldn't proceed with removal. > + > + memory_region_del_subregion(&pcms->hotplug_memory, mr); > + vmstate_unregister_ram(mr, dev); > +} > + > static void pc_cpu_plug(HotplugHandler *hotplug_dev, > DeviceState *dev, Error **errp) > { > @@ -1742,8 +1759,13 @@ static void > pc_machine_device_unplug_request_cb(HotplugHandler *hotplug_dev, > static void pc_machine_device_unplug_cb(HotplugHandler *hotplug_dev, > DeviceState *dev, Error **errp) > { > - error_setg(errp, "acpi: device unplug for not supported device" > - " type: %s", object_get_typename(OBJECT(dev))); > + if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { > + pc_dimm_unplug(hotplug_dev, dev, errp); > + object_unparent(OBJECT(dev)); Pls, do unparenting in pc_dimm_unplug() > + } else { > + error_setg(errp, "acpi: device unplug for not supported device" > + " type: %s", object_get_typename(OBJECT(dev))); > + } > } > > static HotplugHandler *pc_get_hotpug_handler(MachineState *machine,