[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH RFC 2/2] vhost-scsi: implement DeviceEvent
From: |
Dongli Zhang |
Subject: |
[PATCH RFC 2/2] vhost-scsi: implement DeviceEvent |
Date: |
Thu, 14 Jan 2021 16:27:30 -0800 |
This patch implements DeviceEvent for vhost-scsi. As RFC, this patch only
considers the case of eventfd and only for vhost-scsi.
Below are example for HMP and QAPI.
(qemu) device_event /machine/peripheral/vscsi0 kick 1
{ "execute": "x-debug-device-event",
"arguments": { "dev": "/machine/peripheral/vscsi0",
"event": "kick",
"queue": 1 } }
Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
---
hw/virtio/vhost-scsi-pci.c | 10 ++++++++++
hw/virtio/virtio.c | 19 +++++++++++++++++++
include/hw/virtio/virtio.h | 3 +++
3 files changed, 32 insertions(+)
diff --git a/hw/virtio/vhost-scsi-pci.c b/hw/virtio/vhost-scsi-pci.c
index cb71a294fa..0236720868 100644
--- a/hw/virtio/vhost-scsi-pci.c
+++ b/hw/virtio/vhost-scsi-pci.c
@@ -62,12 +62,22 @@ static void vhost_scsi_pci_realize(VirtIOPCIProxy
*vpci_dev, Error **errp)
qdev_realize(vdev, BUS(&vpci_dev->bus), errp);
}
+static void vhost_scsi_pci_event(DeviceState *dev, int event, int queue,
+ Error **errp)
+{
+ VHostSCSIPCI *vscsi = VHOST_SCSI_PCI(dev);
+ DeviceState *vdev = DEVICE(&vscsi->vdev);
+
+ virtio_device_event_eventfd(vdev, event, queue, errp);
+}
+
static void vhost_scsi_pci_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
k->realize = vhost_scsi_pci_realize;
+ dc->event = vhost_scsi_pci_event;
set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
device_class_set_props(dc, vhost_scsi_pci_properties);
pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index b308026596..d9168c4ac8 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -3690,6 +3690,25 @@ static void virtio_device_unrealize(DeviceState *dev)
vdev->bus_name = NULL;
}
+void virtio_device_event_eventfd(DeviceState *dev, int event, int queue,
+ Error **errp)
+{
+ struct VirtIODevice *vdev = VIRTIO_DEVICE(dev);
+ int num = virtio_get_num_queues(vdev);
+
+ if (queue < 0 || queue >= num) {
+ error_setg(errp, "Invalid queue %d", queue);
+ return;
+ }
+
+ VirtQueue *vq = &vdev->vq[queue];
+
+ if (event == DEVICE_EVENT_CALL)
+ event_notifier_set(&vq->guest_notifier);
+ else if (event == DEVICE_EVENT_KICK)
+ event_notifier_set(&vq->host_notifier);
+}
+
static void virtio_device_free_virtqueues(VirtIODevice *vdev)
{
int i;
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index b7ece7a6a8..606ebdfb85 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -397,4 +397,7 @@ static inline bool virtio_device_disabled(VirtIODevice
*vdev)
bool virtio_legacy_allowed(VirtIODevice *vdev);
bool virtio_legacy_check_disabled(VirtIODevice *vdev);
+void virtio_device_event_eventfd(DeviceState *dev, int event, int queue,
+ Error **errp);
+
#endif
--
2.17.1