Message ID | 1420679180-14883-12-git-send-email-tangchen@cn.fujitsu.com |
---|---|
State | New |
Headers | show |
On Thu, 8 Jan 2015 09:06:18 +0800 Tang Chen <tangchen@cn.fujitsu.com> wrote: > Implement unplug cb for pc-dimm. It remove the corresponding > memory region, and unregister vmstat. At last, it calls memory > unplug cb to reset memory status and do unparenting. > --- > hw/i386/pc.c | 25 +++++++++++++++++++++++-- > 1 file changed, 23 insertions(+), 2 deletions(-) > > diff --git a/hw/i386/pc.c b/hw/i386/pc.c > index f501f1f..3732f67 100644 > --- a/hw/i386/pc.c > +++ b/hw/i386/pc.c > @@ -1691,6 +1691,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; > + > + memory_region_del_subregion(&pcms->hotplug_memory, mr); > + vmstate_unregister_ram(mr, dev); I'd first cleanup external state by calling acpi unplug handler and only the do above. > + > + hhc = HOTPLUG_HANDLER_GET_CLASS(pcms->acpi_dev); > + hhc->unplug(HOTPLUG_HANDLER(pcms->acpi_dev), dev, &local_err); > +} > + > static void pc_cpu_plug(HotplugHandler *hotplug_dev, > DeviceState *dev, Error **errp) > { > @@ -1744,8 +1761,12 @@ 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); > + } 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,
On 01/29/2015 09:34 PM, Igor Mammedov wrote: > On Thu, 8 Jan 2015 09:06:18 +0800 > Tang Chen <tangchen@cn.fujitsu.com> wrote: > >> Implement unplug cb for pc-dimm. It remove the corresponding >> memory region, and unregister vmstat. At last, it calls memory >> unplug cb to reset memory status and do unparenting. >> --- >> hw/i386/pc.c | 25 +++++++++++++++++++++++-- >> 1 file changed, 23 insertions(+), 2 deletions(-) >> >> diff --git a/hw/i386/pc.c b/hw/i386/pc.c >> index f501f1f..3732f67 100644 >> --- a/hw/i386/pc.c >> +++ b/hw/i386/pc.c >> @@ -1691,6 +1691,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; >> + >> + memory_region_del_subregion(&pcms->hotplug_memory, mr); >> + vmstate_unregister_ram(mr, dev); > I'd first cleanup external state by calling acpi unplug handler > and only the do above. your meaning is to put the above behind hhc->unplug ? Regards, Zhu >> + >> + hhc = HOTPLUG_HANDLER_GET_CLASS(pcms->acpi_dev); >> + hhc->unplug(HOTPLUG_HANDLER(pcms->acpi_dev), dev, &local_err); >> +} >> + >> static void pc_cpu_plug(HotplugHandler *hotplug_dev, >> DeviceState *dev, Error **errp) >> { >> @@ -1744,8 +1761,12 @@ 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); >> + } 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, > . >
On Wed, 25 Feb 2015 19:21:43 +0800 Zhu Guihua <zhugh.fnst@cn.fujitsu.com> wrote: > > On 01/29/2015 09:34 PM, Igor Mammedov wrote: > > On Thu, 8 Jan 2015 09:06:18 +0800 > > Tang Chen <tangchen@cn.fujitsu.com> wrote: > > > >> Implement unplug cb for pc-dimm. It remove the corresponding > >> memory region, and unregister vmstat. At last, it calls memory > >> unplug cb to reset memory status and do unparenting. > >> --- > >> hw/i386/pc.c | 25 +++++++++++++++++++++++-- > >> 1 file changed, 23 insertions(+), 2 deletions(-) > >> > >> diff --git a/hw/i386/pc.c b/hw/i386/pc.c > >> index f501f1f..3732f67 100644 > >> --- a/hw/i386/pc.c > >> +++ b/hw/i386/pc.c > >> @@ -1691,6 +1691,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; > >> + > >> + memory_region_del_subregion(&pcms->hotplug_memory, mr); > >> + vmstate_unregister_ram(mr, dev); > > I'd first cleanup external state by calling acpi unplug handler > > and only the do above. > > your meaning is to put the above behind hhc->unplug ? yes > > Regards, > Zhu > > >> + > >> + hhc = HOTPLUG_HANDLER_GET_CLASS(pcms->acpi_dev); > >> + hhc->unplug(HOTPLUG_HANDLER(pcms->acpi_dev), dev, &local_err); > >> +} > >> + > >> static void pc_cpu_plug(HotplugHandler *hotplug_dev, > >> DeviceState *dev, Error **errp) > >> { > >> @@ -1744,8 +1761,12 @@ 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); > >> + } 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, > > . > > >
diff --git a/hw/i386/pc.c b/hw/i386/pc.c index f501f1f..3732f67 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1691,6 +1691,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; + + memory_region_del_subregion(&pcms->hotplug_memory, mr); + vmstate_unregister_ram(mr, dev); + + hhc = HOTPLUG_HANDLER_GET_CLASS(pcms->acpi_dev); + hhc->unplug(HOTPLUG_HANDLER(pcms->acpi_dev), dev, &local_err); +} + static void pc_cpu_plug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { @@ -1744,8 +1761,12 @@ 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); + } 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,