qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Jason Wang <jasowang@redhat.com>
Subject: [Qemu-devel] [PATCH 1/3] virtio: interface to enable/disable host notifiers
Date: Tue, 7 Apr 2015 12:45:56 +0200	[thread overview]
Message-ID: <1428403546-31914-2-git-send-email-mst@redhat.com> (raw)
In-Reply-To: <1428403546-31914-1-git-send-email-mst@redhat.com>

generalize and move these from vhost to virtio.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/virtio/virtio.h |  3 +++
 hw/virtio/vhost.c          | 45 ++--------------------------------------
 hw/virtio/virtio.c         | 51 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 56 insertions(+), 43 deletions(-)

diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index d95f8b6..e1cff22 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -219,6 +219,9 @@ void virtio_queue_set_host_notifier_fd_handler(VirtQueue *vq, bool assign,
 void virtio_queue_notify_vq(VirtQueue *vq);
 void virtio_irq(VirtQueue *vq);
 
+int virtio_enable_host_notifiers(VirtIODevice *vdev, int startvq, int nvqs);
+void virtio_disable_host_notifiers(VirtIODevice *vdev, int startvq, int nvqs);
+
 static inline void virtio_add_feature(uint32_t *features, unsigned int fbit)
 {
     assert(fbit < 32);
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 5a12861..8dd2f59 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -918,36 +918,7 @@ bool vhost_dev_query(struct vhost_dev *hdev, VirtIODevice *vdev)
  */
 int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev)
 {
-    BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
-    VirtioBusState *vbus = VIRTIO_BUS(qbus);
-    VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
-    int i, r;
-    if (!k->set_host_notifier) {
-        fprintf(stderr, "binding does not support host notifiers\n");
-        r = -ENOSYS;
-        goto fail;
-    }
-
-    for (i = 0; i < hdev->nvqs; ++i) {
-        r = k->set_host_notifier(qbus->parent, hdev->vq_index + i, true);
-        if (r < 0) {
-            fprintf(stderr, "vhost VQ %d notifier binding failed: %d\n", i, -r);
-            goto fail_vq;
-        }
-    }
-
-    return 0;
-fail_vq:
-    while (--i >= 0) {
-        r = k->set_host_notifier(qbus->parent, hdev->vq_index + i, false);
-        if (r < 0) {
-            fprintf(stderr, "vhost VQ %d notifier cleanup error: %d\n", i, -r);
-            fflush(stderr);
-        }
-        assert (r >= 0);
-    }
-fail:
-    return r;
+    return virtio_enable_host_notifiers(vdev, hdev->vq_index, hdev->nvqs);
 }
 
 /* Stop processing guest IO notifications in vhost.
@@ -957,19 +928,7 @@ fail:
  */
 void vhost_dev_disable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev)
 {
-    BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
-    VirtioBusState *vbus = VIRTIO_BUS(qbus);
-    VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
-    int i, r;
-
-    for (i = 0; i < hdev->nvqs; ++i) {
-        r = k->set_host_notifier(qbus->parent, hdev->vq_index + i, false);
-        if (r < 0) {
-            fprintf(stderr, "vhost VQ %d notifier cleanup failed: %d\n", i, -r);
-            fflush(stderr);
-        }
-        assert (r >= 0);
-    }
+    virtio_disable_host_notifiers(vdev, hdev->vq_index, hdev->nvqs);
 }
 
 /* Test and clear event pending status.
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 17c1260..e7ee069 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -1283,6 +1283,57 @@ void virtio_device_set_child_bus_name(VirtIODevice *vdev, char *bus_name)
     vdev->bus_name = g_strdup(bus_name);
 }
 
+int virtio_enable_host_notifiers(VirtIODevice *vdev, int startvq, int nvqs)
+{
+    BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
+    VirtioBusState *vbus = VIRTIO_BUS(qbus);
+    VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
+    int i, r;
+    if (!k->set_host_notifier) {
+        fprintf(stderr, "binding does not support host notifiers\n");
+        r = -ENOSYS;
+        goto fail;
+    }
+
+    for (i = 0; i < nvqs; ++i) {
+        r = k->set_host_notifier(qbus->parent, startvq + i, true);
+        if (r < 0) {
+            fprintf(stderr, "vhost VQ %d notifier binding failed: %d\n", i, -r);
+            goto fail_vq;
+        }
+    }
+
+    return 0;
+fail_vq:
+    while (--i >= 0) {
+        r = k->set_host_notifier(qbus->parent, startvq + i, false);
+        if (r < 0) {
+            fprintf(stderr, "vhost VQ %d notifier cleanup error: %d\n", i, -r);
+            fflush(stderr);
+        }
+        assert (r >= 0);
+    }
+fail:
+    return r;
+}
+
+void virtio_disable_host_notifiers(VirtIODevice *vdev, int startvq, int nvqs)
+{
+    BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
+    VirtioBusState *vbus = VIRTIO_BUS(qbus);
+    VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
+    int i, r;
+
+    for (i = 0; i < nvqs; ++i) {
+        r = k->set_host_notifier(qbus->parent, startvq + i, false);
+        if (r < 0) {
+            fprintf(stderr, "vhost VQ %d notifier cleanup failed: %d\n", i, -r);
+            fflush(stderr);
+        }
+        assert (r >= 0);
+    }
+}
+
 static void virtio_device_realize(DeviceState *dev, Error **errp)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
-- 
MST

  reply	other threads:[~2015-04-07 10:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-07 10:45 [Qemu-devel] [PATCH 0/3] virtio: host notifier API cleanup Michael S. Tsirkin
2015-04-07 10:45 ` Michael S. Tsirkin [this message]
2015-04-07 11:32   ` [Qemu-devel] [PATCH 1/3] virtio: interface to enable/disable host notifiers Cornelia Huck
2015-04-07 10:45 ` [Qemu-devel] [PATCH 2/3] dataplane/virtio-blk.c: new API to enable notifiers Michael S. Tsirkin
2015-04-07 11:35   ` Cornelia Huck
2015-04-07 10:46 ` [Qemu-devel] [PATCH 3/3] dataplane/virtio-scsi: new API to enable host notifiers Michael S. Tsirkin
2015-04-07 11:41   ` Cornelia Huck

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=1428403546-31914-2-git-send-email-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=jasowang@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).