[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-ppc] [PATCH v4 23/24] virtio-pmem: hotplug support functions
From: |
David Hildenbrand |
Subject: |
[Qemu-ppc] [PATCH v4 23/24] virtio-pmem: hotplug support functions |
Date: |
Wed, 26 Sep 2018 11:42:18 +0200 |
virtio-pmem devices will have to be hotplugged using the machine hotplug
handler just like other memory devices. Therefore, all machines that
want to support virtio-pmem will have to modify their machine hotplug
handler.
virtio-pmem devices are realized when their parent proxy device
(virtio-pmem-pci) is realized. Therefore, they are attached to a bus
without a hotplug handler. This makes things a lot easier, because
without a hotplug handler, we can directly get control over the device
in the machine hotplug handler (otherwise we would have to overwrite
control and pass control to the bus hotplug handler from the machine
hotplug handler).
As we have to implement support for each machine we want to support,
add a safety net ("pre_plugged") that catches if the pre_plug handler
was not called - if trying to realize it with a machine that does not
support it.
Otherwise creating and realizing virtio-pmem-pci along with virtio-pmem
would work, however the memory-device part would not properly get
hotplugged.
Signed-off-by: David Hildenbrand <address@hidden>
---
hw/virtio/virtio-pmem.c | 34 +++++++++++++++++++++++++++++++++
include/hw/virtio/virtio-pmem.h | 11 +++++++++++
2 files changed, 45 insertions(+)
diff --git a/hw/virtio/virtio-pmem.c b/hw/virtio/virtio-pmem.c
index 0f8b509f0f..893e92237b 100644
--- a/hw/virtio/virtio-pmem.c
+++ b/hw/virtio/virtio-pmem.c
@@ -112,6 +112,12 @@ static void virtio_pmem_realize(DeviceState *dev, Error
**errp)
return;
}
+ /* pre_plug handler wasn't executed (e.g. from machine hotplug handler) */
+ if (!pmem->pre_plugged) {
+ error_setg(errp, "virtio-pmem is not compatible with the machine");
+ return;
+ }
+
host_memory_backend_set_mapped(pmem->memdev, true);
virtio_init(vdev, TYPE_VIRTIO_PMEM, VIRTIO_ID_PMEM,
sizeof(struct virtio_pmem_config));
@@ -205,6 +211,34 @@ static void virtio_pmem_class_init(ObjectClass *klass,
void *data)
mdc->get_device_id = virtio_pmem_md_get_device_id;
}
+void virtio_pmem_pre_plug(VirtIOPMEM *pmem, MachineState *ms, Error **errp)
+{
+ /*
+ * The proxy device (e.g. virtio-pmem-pci) has an hotplug handler and
+ * will attach the virtio-pmem device to its bus (parent_bus). This
+ * device will realize the virtio-mem device from its realize function,
+ * therefore when it is hotplugged itself. The proxy device bus
+ * therefore has no hotplug handler and we don't have to forward any
+ * calls.
+ */
+ if (!DEVICE(pmem)->parent_bus ||
+ DEVICE(pmem)->parent_bus->hotplug_handler) {
+ error_setg(errp, "virtio-pmem is not compatible with the proxy.");
+ }
+ memory_device_pre_plug(MEMORY_DEVICE(pmem), ms, NULL, errp);
+ pmem->pre_plugged = true;
+}
+
+void virtio_pmem_plug(VirtIOPMEM *pmem, MachineState *ms, Error **errp)
+{
+ memory_device_plug(MEMORY_DEVICE(pmem), ms);
+}
+
+void virtio_pmem_do_unplug(VirtIOPMEM *pmem, MachineState *ms)
+{
+ memory_device_unplug(MEMORY_DEVICE(pmem), ms);
+}
+
static TypeInfo virtio_pmem_info = {
.name = TYPE_VIRTIO_PMEM,
.parent = TYPE_VIRTIO_DEVICE,
diff --git a/include/hw/virtio/virtio-pmem.h b/include/hw/virtio/virtio-pmem.h
index 11e549e0f1..9cc70e391d 100644
--- a/include/hw/virtio/virtio-pmem.h
+++ b/include/hw/virtio/virtio-pmem.h
@@ -31,10 +31,21 @@ typedef struct VirtIOPMEM {
VirtQueue *rq_vq;
uint64_t start;
HostMemoryBackend *memdev;
+
+ /*
+ * Safety net to make sure we can catch trying to be realized on a
+ * machine that is not prepared to properly hotplug virtio-pmem from
+ * its machine hotplug handler.
+ */
+ bool pre_plugged;
} VirtIOPMEM;
struct virtio_pmem_config {
uint64_t start;
uint64_t size;
};
+
+void virtio_pmem_pre_plug(VirtIOPMEM *pmem, MachineState *ms, Error **errp);
+void virtio_pmem_plug(VirtIOPMEM *pmem, MachineState *ms, Error **errp);
+void virtio_pmem_do_unplug(VirtIOPMEM *pmem, MachineState *ms);
#endif
--
2.17.1
- [Qemu-ppc] [PATCH v4 17/24] memory-device: add class function get_device_id(), (continued)
- [Qemu-ppc] [PATCH v4 17/24] memory-device: add class function get_device_id(), David Hildenbrand, 2018/09/26
- [Qemu-ppc] [PATCH v4 18/24] qdev: hotplug: provide do_unplug handler, David Hildenbrand, 2018/09/26
- [Qemu-ppc] [PATCH v4 19/24] virtio-pmem: prototype, David Hildenbrand, 2018/09/26
- [Qemu-ppc] [PATCH v4 20/24] virtio-pci: proxy for virtio-pmem, David Hildenbrand, 2018/09/26
- [Qemu-ppc] [PATCH v4 21/24] hmp: handle virtio-pmem when printing memory device infos, David Hildenbrand, 2018/09/26
- [Qemu-ppc] [PATCH v4 22/24] numa: handle virtio-pmem in NUMA stats, David Hildenbrand, 2018/09/26
- [Qemu-ppc] [PATCH v4 23/24] virtio-pmem: hotplug support functions,
David Hildenbrand <=
- [Qemu-ppc] [PATCH v4 24/24] pc: support for virtio-pmem, David Hildenbrand, 2018/09/26