[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v1 4/5] pc: Support unplug of virtio-mem-pci devices
From: |
David Hildenbrand |
Subject: |
[PATCH v1 4/5] pc: Support unplug of virtio-mem-pci devices |
Date: |
Tue, 13 Jun 2023 17:02:09 +0200 |
Let's support unplug of virtio-mem-pci devices by granting (forwarding)
unplug requests if it's safe to unplug a virtio-mem device.
Signed-off-by: David Hildenbrand <david@redhat.com>
---
hw/i386/pc.c | 48 +++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 41 insertions(+), 7 deletions(-)
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index fdd7062929..996757794e 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1549,13 +1549,6 @@ static void pc_virtio_md_pci_plug(HotplugHandler
*hotplug_dev,
error_propagate(errp, local_err);
}
-static void pc_virtio_md_pci_unplug_request(HotplugHandler *hotplug_dev,
- DeviceState *dev, Error **errp)
-{
- /* We don't support hot unplug of virtio based memory devices */
- error_setg(errp, "virtio based memory devices cannot be unplugged.");
-}
-
static void pc_virtio_md_pci_unplug(HotplugHandler *hotplug_dev,
DeviceState *dev, Error **errp)
{
@@ -1580,6 +1573,47 @@ static void pc_virtio_md_pci_unplug(HotplugHandler
*hotplug_dev,
}
}
+static void pc_virtio_md_pci_unplug_request(HotplugHandler *hotplug_dev,
+ DeviceState *dev, Error **errp)
+{
+ HotplugHandler *hotplug_dev2 = qdev_get_bus_hotplug_handler(dev);
+ HotplugHandlerClass *hdc;
+ Error *local_err = NULL;
+
+ if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM_PCI)) {
+ error_setg(errp, "virtio-pmem devices cannot be unplugged.");
+ return;
+ }
+
+ if (!hotplug_dev2) {
+ error_setg(errp, "hotunplug of virtio based memory devices not"
+ "supported on this bus");
+ return;
+ }
+
+ /* Verify whether it is *currently* safe to unplug the virtio-mem device.
*/
+ g_assert(object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MEM_PCI));
+ virtio_mem_pci_unplug_request_check(VIRTIO_MEM_PCI(dev), &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(hotplug_dev2);
+ if (hdc->unplug_request) {
+ hotplug_handler_unplug_request(hotplug_dev2, dev, &local_err);
+ } else {
+ pc_virtio_md_pci_unplug(hotplug_dev, dev, &local_err);
+ if (!local_err) {
+ object_unparent(OBJECT(dev));
+ }
+ }
+}
+
static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev,
DeviceState *dev, Error **errp)
{
--
2.40.1
- [PATCH v1 0/5] virtio-mem: Device unplug support, David Hildenbrand, 2023/06/13
- [PATCH v1 5/5] arm/virt: Support unplug of virtio-mem-pci devices, David Hildenbrand, 2023/06/13
- [PATCH v1 1/5] pc: Properly handle unplug of virtio based memory devices, David Hildenbrand, 2023/06/13
- [PATCH v1 2/5] arm/virt: Properly handle unplug of virtio based memory devices, David Hildenbrand, 2023/06/13
- [PATCH v1 4/5] pc: Support unplug of virtio-mem-pci devices,
David Hildenbrand <=
- [PATCH v1 3/5] virtio-mem: Prepare for unplug support of virtio-mem-pci devices, David Hildenbrand, 2023/06/13
- Re: [PATCH v1 0/5] virtio-mem: Device unplug support, Michael S. Tsirkin, 2023/06/23