@@ -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;
@@ -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;
@@ -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
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(+)