[PATCH kvmtool 03/16] virtio/vhost: Factor notify_vq_eventfd()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



All vhost devices perform the same operation when setting up the
ioeventfd. Move it to virtio/vhost.c

Signed-off-by: Jean-Philippe Brucker <jean-philippe@xxxxxxxxxx>
---
 include/kvm/virtio.h |  2 ++
 virtio/net.c         |  9 +--------
 virtio/scsi.c        |  9 +--------
 virtio/vhost.c       | 14 ++++++++++++++
 virtio/vsock.c       | 14 ++------------
 5 files changed, 20 insertions(+), 28 deletions(-)

diff --git a/include/kvm/virtio.h b/include/kvm/virtio.h
index c8fd69e0..4a364a02 100644
--- a/include/kvm/virtio.h
+++ b/include/kvm/virtio.h
@@ -250,6 +250,8 @@ void virtio_notify_status(struct kvm *kvm, struct virtio_device *vdev,
 void virtio_vhost_init(struct kvm *kvm, int vhost_fd);
 void virtio_vhost_set_vring(struct kvm *kvm, int vhost_fd, u32 index,
 			    struct virt_queue *queue);
+void virtio_vhost_set_vring_kick(struct kvm *kvm, int vhost_fd,
+				 u32 index, int event_fd);
 
 int virtio_transport_parser(const struct option *opt, const char *arg, int unset);
 
diff --git a/virtio/net.c b/virtio/net.c
index 021c81d3..b935d24f 100644
--- a/virtio/net.c
+++ b/virtio/net.c
@@ -701,18 +701,11 @@ static void notify_vq_gsi(struct kvm *kvm, void *dev, u32 vq, u32 gsi)
 static void notify_vq_eventfd(struct kvm *kvm, void *dev, u32 vq, u32 efd)
 {
 	struct net_dev *ndev = dev;
-	struct vhost_vring_file file = {
-		.index	= vq,
-		.fd	= efd,
-	};
-	int r;
 
 	if (ndev->vhost_fd == 0 || is_ctrl_vq(ndev, vq))
 		return;
 
-	r = ioctl(ndev->vhost_fd, VHOST_SET_VRING_KICK, &file);
-	if (r < 0)
-		die_perror("VHOST_SET_VRING_KICK failed");
+	virtio_vhost_set_vring_kick(kvm, ndev->vhost_fd, vq, efd);
 }
 
 static int notify_vq(struct kvm *kvm, void *dev, u32 vq)
diff --git a/virtio/scsi.c b/virtio/scsi.c
index 674aad34..1f757404 100644
--- a/virtio/scsi.c
+++ b/virtio/scsi.c
@@ -123,18 +123,11 @@ static void notify_vq_gsi(struct kvm *kvm, void *dev, u32 vq, u32 gsi)
 static void notify_vq_eventfd(struct kvm *kvm, void *dev, u32 vq, u32 efd)
 {
 	struct scsi_dev *sdev = dev;
-	struct vhost_vring_file file = {
-		.index	= vq,
-		.fd	= efd,
-	};
-	int r;
 
 	if (sdev->vhost_fd == 0)
 		return;
 
-	r = ioctl(sdev->vhost_fd, VHOST_SET_VRING_KICK, &file);
-	if (r < 0)
-		die_perror("VHOST_SET_VRING_KICK failed");
+	virtio_vhost_set_vring_kick(kvm, sdev->vhost_fd, vq, efd);
 }
 
 static int notify_vq(struct kvm *kvm, void *dev, u32 vq)
diff --git a/virtio/vhost.c b/virtio/vhost.c
index afe37465..3acfd30a 100644
--- a/virtio/vhost.c
+++ b/virtio/vhost.c
@@ -65,3 +65,17 @@ void virtio_vhost_set_vring(struct kvm *kvm, int vhost_fd, u32 index,
 	if (r < 0)
 		die_perror("VHOST_SET_VRING_ADDR failed");
 }
+
+void virtio_vhost_set_vring_kick(struct kvm *kvm, int vhost_fd,
+				 u32 index, int event_fd)
+{
+	int r;
+	struct vhost_vring_file file = {
+		.index	= index,
+		.fd	= event_fd,
+	};
+
+	r = ioctl(vhost_fd, VHOST_SET_VRING_KICK, &file);
+	if (r < 0)
+		die_perror("VHOST_SET_VRING_KICK failed");
+}
diff --git a/virtio/vsock.c b/virtio/vsock.c
index 2f7906f2..0ada9e09 100644
--- a/virtio/vsock.c
+++ b/virtio/vsock.c
@@ -80,21 +80,11 @@ static int init_vq(struct kvm *kvm, void *dev, u32 vq)
 static void notify_vq_eventfd(struct kvm *kvm, void *dev, u32 vq, u32 efd)
 {
 	struct vsock_dev *vdev = dev;
-	struct vhost_vring_file file = {
-		.index	= vq,
-		.fd	= efd,
-	};
-	int r;
 
-	if (is_event_vq(vq))
-		return;
-
-	if (vdev->vhost_fd == -1)
+	if (vdev->vhost_fd == -1 || is_event_vq(vq))
 		return;
 
-	r = ioctl(vdev->vhost_fd, VHOST_SET_VRING_KICK, &file);
-	if (r < 0)
-		die_perror("VHOST_SET_VRING_KICK failed");
+	virtio_vhost_set_vring_kick(kvm, vdev->vhost_fd, vq, efd);
 }
 
 static void notify_status(struct kvm *kvm, void *dev, u32 status)
-- 
2.40.0




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux