qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Dongli Zhang <dongli.zhang@oracle.com>
To: qemu-devel@nongnu.org
Cc: berrange@redhat.com, ehabkost@redhat.com, mst@redhat.com,
	joe.jin@oracle.com, armbru@redhat.com, dgilbert@redhat.com,
	pbonzini@redhat.com, joao.m.martins@oracle.com
Subject: [PATCH RFC 2/2] vhost-scsi: implement DeviceEvent
Date: Thu, 14 Jan 2021 16:27:30 -0800	[thread overview]
Message-ID: <20210115002730.1279-3-dongli.zhang@oracle.com> (raw)
In-Reply-To: <20210115002730.1279-1-dongli.zhang@oracle.com>

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



  parent reply	other threads:[~2021-01-15  0:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-15  0:27 [PATCH RFC 0/2] Add debug interface to kick/call on purpose Dongli Zhang
2021-01-15  0:27 ` [PATCH RFC 1/2] qdev: add debug interface to kick/call eventfd Dongli Zhang
2021-01-19 22:20   ` Eric Blake
2021-01-15  0:27 ` Dongli Zhang [this message]
2021-01-15 10:27 ` [PATCH RFC 0/2] Add debug interface to kick/call on purpose Daniel P. Berrangé
2021-01-18 16:59   ` Dr. David Alan Gilbert
2021-01-19 22:11     ` Dongli Zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210115002730.1279-3-dongli.zhang@oracle.com \
    --to=dongli.zhang@oracle.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=joao.m.martins@oracle.com \
    --cc=joe.jin@oracle.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).