[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 5/7] virtio-md-pci: Support unplug requests for compatible dev
From: |
David Hildenbrand |
Subject: |
[PATCH v2 5/7] virtio-md-pci: Support unplug requests for compatible devices |
Date: |
Fri, 23 Jun 2023 14:20:54 +0200 |
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.
Signed-off-by: David Hildenbrand <david@redhat.com>
---
hw/virtio/virtio-md-pci.c | 38 +++++++++++++++++++++++++++++--
include/hw/virtio/virtio-md-pci.h | 3 +++
2 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/hw/virtio/virtio-md-pci.c b/hw/virtio/virtio-md-pci.c
index a22a259e2d..62bfb7920b 100644
--- a/hw/virtio/virtio-md-pci.c
+++ b/hw/virtio/virtio-md-pci.c
@@ -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,
Error **errp)
{
- /* We don't support hot unplug of virtio based memory devices */
- error_setg(errp, "virtio based memory devices cannot be unplugged.");
+ VirtIOMDPCIClass *vmdc = VIRTIO_MD_PCI_GET_CLASS(vmd);
+ 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)
diff --git a/include/hw/virtio/virtio-md-pci.h
b/include/hw/virtio/virtio-md-pci.h
index f9fa857aec..5912e16674 100644
--- a/include/hw/virtio/virtio-md-pci.h
+++ b/include/hw/virtio/virtio-md-pci.h
@@ -26,6 +26,9 @@ OBJECT_DECLARE_TYPE(VirtIOMDPCI, VirtIOMDPCIClass,
VIRTIO_MD_PCI)
struct VirtIOMDPCIClass {
/* private */
VirtioPCIClass parent;
+
+ /* public */
+ void (*unplug_request_check)(VirtIOMDPCI *vmd, Error **errp);
};
struct VirtIOMDPCI {
--
2.40.1
- [PATCH v2 0/7] virtio-mem: Device unplug support, David Hildenbrand, 2023/06/23
- [PATCH v2 2/7] pc: Factor out (un)plug handling of virtio-md-pci devices, David Hildenbrand, 2023/06/23
- [PATCH v2 3/7] arm/virt: Use virtio-md-pci (un)plug functions, David Hildenbrand, 2023/06/23
- [PATCH v2 7/7] virtio-mem-pci: Device unplug support, David Hildenbrand, 2023/06/23
- [PATCH v2 4/7] virtio-md-pci: Handle unplug of virtio based memory devices, David Hildenbrand, 2023/06/23
- [PATCH v2 6/7] virtio-mem: Prepare for device unplug support, David Hildenbrand, 2023/06/23
- [PATCH v2 1/7] virtio-md-pci: New parent type for virtio-mem-pci and virtio-pmem-pci, David Hildenbrand, 2023/06/23
- [PATCH v2 5/7] virtio-md-pci: Support unplug requests for compatible devices,
David Hildenbrand <=