mirror of https://github.com/proxmox/mirror_qemu
virtio-md-pci: Support unplug requests for compatible devices
Let's support unplug requests for virtio-md-pci devices that provide a unplug_request_check() callback. We'll wire that up for virtio-mem-pci next. Message-ID: <20230711153445.514112-6-david@redhat.com> Tested-by: Mario Casquero <mcasquer@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: David Hildenbrand <david@redhat.com>master
parent
c29dd73f74
commit
aac44204bc
|
@ -69,8 +69,42 @@ void virtio_md_pci_plug(VirtIOMDPCI *vmd, MachineState *ms, Error **errp)
|
||||||
void virtio_md_pci_unplug_request(VirtIOMDPCI *vmd, MachineState *ms,
|
void virtio_md_pci_unplug_request(VirtIOMDPCI *vmd, MachineState *ms,
|
||||||
Error **errp)
|
Error **errp)
|
||||||
{
|
{
|
||||||
/* We don't support hot unplug of virtio based memory devices */
|
VirtIOMDPCIClass *vmdc = VIRTIO_MD_PCI_GET_CLASS(vmd);
|
||||||
error_setg(errp, "virtio based memory devices cannot be unplugged.");
|
DeviceState *dev = DEVICE(vmd);
|
||||||
|
HotplugHandler *bus_handler = qdev_get_bus_hotplug_handler(dev);
|
||||||
|
HotplugHandlerClass *hdc;
|
||||||
|
Error *local_err = NULL;
|
||||||
|
|
||||||
|
if (!vmdc->unplug_request_check) {
|
||||||
|
error_setg(errp, "this virtio based memory devices cannot be unplugged");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!bus_handler) {
|
||||||
|
error_setg(errp, "hotunplug of virtio based memory devices not"
|
||||||
|
"supported on this bus");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
vmdc->unplug_request_check(vmd, &local_err);
|
||||||
|
if (local_err) {
|
||||||
|
error_propagate(errp, local_err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Forward the async request or turn it into a sync request (handling it
|
||||||
|
* like qdev_unplug()).
|
||||||
|
*/
|
||||||
|
hdc = HOTPLUG_HANDLER_GET_CLASS(bus_handler);
|
||||||
|
if (hdc->unplug_request) {
|
||||||
|
hotplug_handler_unplug_request(bus_handler, dev, &local_err);
|
||||||
|
} else {
|
||||||
|
virtio_md_pci_unplug(vmd, ms, &local_err);
|
||||||
|
if (!local_err) {
|
||||||
|
object_unparent(OBJECT(dev));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void virtio_md_pci_unplug(VirtIOMDPCI *vmd, MachineState *ms, Error **errp)
|
void virtio_md_pci_unplug(VirtIOMDPCI *vmd, MachineState *ms, Error **errp)
|
||||||
|
|
|
@ -26,6 +26,9 @@ OBJECT_DECLARE_TYPE(VirtIOMDPCI, VirtIOMDPCIClass, VIRTIO_MD_PCI)
|
||||||
struct VirtIOMDPCIClass {
|
struct VirtIOMDPCIClass {
|
||||||
/* private */
|
/* private */
|
||||||
VirtioPCIClass parent;
|
VirtioPCIClass parent;
|
||||||
|
|
||||||
|
/* public */
|
||||||
|
void (*unplug_request_check)(VirtIOMDPCI *vmd, Error **errp);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VirtIOMDPCI {
|
struct VirtIOMDPCI {
|
||||||
|
|
Loading…
Reference in New Issue