From 45a1e7de82dc416bf65486836285c15c4701f34b Mon Sep 17 00:00:00 2001
From: Michael S. Tsirkin <mst@redhat.com>
Date: Wed, 7 Apr 2010 14:25:24 -0300
Subject: [PATCH 09/12] vhost: detect lack of support earlier+style

RH-Author: Michael S. Tsirkin <mst@redhat.com>
Message-id: <21c9d7892da422443b437c107b6dac00008445db.1270649651.git.mst@redhat.com>
Patchwork-id: 8428
O-Subject: [PATCH RHEL6.0 6/9] vhost: detect lack of support earlier+style
Bugzilla: 580109
RH-Acked-by: Gerd Hoffmann <kraxel@redhat.com>
RH-Acked-by: Juan Quintela <quintela@redhat.com>
RH-Acked-by: Amit Shah <amit.shah@redhat.com>

Address Amit Shah's comments: detect lack of vhost support
earlier, better name for local variable.

Cherry-picked from commit d59700553ecbf052cce1e099e8f4dae2704fe424.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/vhost.c |   21 +++++++++++++--------
 1 files changed, 13 insertions(+), 8 deletions(-)

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/vhost.c |   21 +++++++++++++--------
 1 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/hw/vhost.c b/hw/vhost.c
index 531e48b..ad2f98a 100644
--- a/hw/vhost.c
+++ b/hw/vhost.c
@@ -454,7 +454,17 @@ static int vhost_virtqueue_init(struct vhost_dev *dev,
     struct vhost_vring_state state = {
         .index = idx,
     };
-    struct VirtQueue *q = virtio_get_queue(vdev, idx);
+    struct VirtQueue *vvq = virtio_get_queue(vdev, idx);
+
+    if (!vdev->binding->set_guest_notifier) {
+        fprintf(stderr, "binding does not support guest notifiers\n");
+        return -ENOSYS;
+    }
+
+    if (!vdev->binding->set_host_notifier) {
+        fprintf(stderr, "binding does not support host notifiers\n");
+        return -ENOSYS;
+    }
 
     vq->num = state.num = virtio_queue_get_num(vdev, idx);
     r = ioctl(dev->control, VHOST_SET_VRING_NUM, &state);
@@ -503,11 +513,6 @@ static int vhost_virtqueue_init(struct vhost_dev *dev,
         r = -errno;
         goto fail_alloc;
     }
-    if (!vdev->binding->set_guest_notifier || !vdev->binding->set_host_notifier) {
-        fprintf(stderr, "binding does not support irqfd/queuefd\n");
-        r = -ENOSYS;
-        goto fail_alloc;
-    }
     r = vdev->binding->set_guest_notifier(vdev->binding_opaque, idx, true);
     if (r < 0) {
         fprintf(stderr, "Error binding guest notifier: %d\n", -r);
@@ -520,13 +525,13 @@ static int vhost_virtqueue_init(struct vhost_dev *dev,
         goto fail_host_notifier;
     }
 
-    file.fd = event_notifier_get_fd(virtio_queue_get_host_notifier(q));
+    file.fd = event_notifier_get_fd(virtio_queue_get_host_notifier(vvq));
     r = ioctl(dev->control, VHOST_SET_VRING_KICK, &file);
     if (r) {
         goto fail_kick;
     }
 
-    file.fd = event_notifier_get_fd(virtio_queue_get_guest_notifier(q));
+    file.fd = event_notifier_get_fd(virtio_queue_get_guest_notifier(vvq));
     r = ioctl(dev->control, VHOST_SET_VRING_CALL, &file);
     if (r) {
         goto fail_call;
-- 
1.7.0.3

