Skip to contentSkip to conversation

vhost: Use vbus var instead of VIRTIO_BUS() macro

PATCH In review Felipe Franciosi 3 participants 5 messages Nov 9, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vhost: Use vbus var instead of VIRTIO_BUS() macro

Recent changes on vhost_dev_enable/disable_notifiers() produced a VirtioBusState vbus variable which can be used instead of the VIRTIO_BUS() macro. This commit just makes the code a little bit cleaner and more consistent.

---
 hw/virtio/vhost.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
hw/virtio/vhost.c +6 -8
index 1290963..7d29dad 100644
@@ -1198,20 +1198,18 @@ int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev)
 
     virtio_device_stop_ioeventfd(vdev);
     for (i = 0; i < hdev->nvqs; ++i) {
-        r = virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), hdev->vq_index + i,
-                                         true);
+        r = virtio_bus_set_host_notifier(vbus, hdev->vq_index + i, true);
         if (r < 0) {
             error_report("vhost VQ %d notifier binding failed: %d", i, -r);
             goto fail_vq;
         }
     }
-    VIRTIO_BUS(qbus)->ioeventfd_started = true;
+    vbus->ioeventfd_started = true;
 
     return 0;
 fail_vq:
     while (--i >= 0) {
-        e = virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), hdev->vq_index + i,
-                                         false);
+        e = virtio_bus_set_host_notifier(vbus, hdev->vq_index + i, false);
         if (e < 0) {
             error_report("vhost VQ %d notifier cleanup error: %d", i, -r);
         }
@@ -1230,17 +1228,17 @@ 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);
     int i, r;
 
     for (i = 0; i < hdev->nvqs; ++i) {
-        r = virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), hdev->vq_index + i,
-                                         false);
+        r = virtio_bus_set_host_notifier(vbus, hdev->vq_index + i, false);
         if (r < 0) {
             error_report("vhost VQ %d notifier cleanup failed: %d", i, -r);
         }
         assert (r >= 0);
     }
-    VIRTIO_BUS(qbus)->ioeventfd_started = false;
+    vbus->ioeventfd_started = false;
     virtio_device_start_ioeventfd(vdev);
 }
 
Signature · 1 line
1.9.4
#1 lore raw
Quoted 6 lines · Felipe Franciosi

Recent changes on vhost_dev_enable/disable_notifiers() produced a VirtioBusState vbus variable which can be used instead of the VIRTIO_BUS() macro. This commit just makes the code a little bit cleaner and more consistent.

Michael, what do you think? Perhaps it's simplest to just squash the two patches (v2 of "vhost: Update 'ioeventfd_started' with host notifiers" and this one).

Paolo

Quoted 54 lines
---
 hw/virtio/vhost.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
hw/virtio/vhost.c +6 -8
index 1290963..7d29dad 100644
@@ -1198,20 +1198,18 @@ int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev)
 
     virtio_device_stop_ioeventfd(vdev);
     for (i = 0; i < hdev->nvqs; ++i) {
-        r = virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), hdev->vq_index + i,
-                                         true);
+        r = virtio_bus_set_host_notifier(vbus, hdev->vq_index + i, true);
         if (r < 0) {
             error_report("vhost VQ %d notifier binding failed: %d", i, -r);
             goto fail_vq;
         }
     }
-    VIRTIO_BUS(qbus)->ioeventfd_started = true;
+    vbus->ioeventfd_started = true;
 
     return 0;
 fail_vq:
     while (--i >= 0) {
-        e = virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), hdev->vq_index + i,
-                                         false);
+        e = virtio_bus_set_host_notifier(vbus, hdev->vq_index + i, false);
         if (e < 0) {
             error_report("vhost VQ %d notifier cleanup error: %d", i, -r);
         }
@@ -1230,17 +1228,17 @@ 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);
     int i, r;
 
     for (i = 0; i < hdev->nvqs; ++i) {
-        r = virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), hdev->vq_index + i,
-                                         false);
+        r = virtio_bus_set_host_notifier(vbus, hdev->vq_index + i, false);
         if (r < 0) {
             error_report("vhost VQ %d notifier cleanup failed: %d", i, -r);
         }
         assert (r >= 0);
     }
-    VIRTIO_BUS(qbus)->ioeventfd_started = false;
+    vbus->ioeventfd_started = false;
     virtio_device_start_ioeventfd(vdev);
 }
 
#2 lore raw
Quoted 11 lines · Paolo Bonzini
Quoted 5 lines · Felipe Franciosi

Recent changes on vhost_dev_enable/disable_notifiers() produced a VirtioBusState vbus variable which can be used instead of the VIRTIO_BUS() macro. This commit just makes the code a little bit cleaner and more consistent.

Quoted 7 lines
Quoted 1 line

Michael, what do you think? Perhaps it's simplest to just squash the two patches (v2 of "vhost: Update 'ioeventfd_started' with host notifiers" and this one).

Paolo

Please, do. I just realised the repeated use of VIRTIO_BUS() after sending the first patch (Update 'ioeventfd_started' with host notifiers) and decided to ship this one too to get them both in if possible.

Thanks,
Felipe

Quoted 55 lines
Quoted 55 lines

---
hw/virtio/vhost.c | 14 ++++++--------

1 file changed, 6 insertions(+), 8 deletions(-)
hw/virtio/vhost.c +2 -3
index 1290963..7d29dad 100644
@@ -1198,20 +1198,18 @@ int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev)
 
    virtio_device_stop_ioeventfd(vdev);
    for (i = 0; i < hdev->nvqs; ++i) {
-        r = virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), hdev->vq_index + i,
-                                         true);
+        r = virtio_bus_set_host_notifier(vbus, hdev->vq_index + i, true);
        if (r < 0) {
            error_report("vhost VQ %d notifier binding failed: %d", i, -r);
            goto fail_vq;
        }
    }
-    VIRTIO_BUS(qbus)->ioeventfd_started = true;
+    vbus->ioeventfd_started = true;
 
    return 0;

fail_vq:

    while (--i >= 0) {
hw/virtio/vhost.c +4 -5
-        e = virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), hdev->vq_index + i,
-                                         false);
+        e = virtio_bus_set_host_notifier(vbus, hdev->vq_index + i, false);
        if (e < 0) {
            error_report("vhost VQ %d notifier cleanup error: %d", i, -r);
        }
@@ -1230,17 +1228,17 @@ 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);
    int i, r;
 
    for (i = 0; i < hdev->nvqs; ++i) {
-        r = virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), hdev->vq_index + i,
-                                         false);
+        r = virtio_bus_set_host_notifier(vbus, hdev->vq_index + i, false);
        if (r < 0) {
            error_report("vhost VQ %d notifier cleanup failed: %d", i, -r);
        }
        assert (r >= 0);
    }
-    VIRTIO_BUS(qbus)->ioeventfd_started = false;
+    vbus->ioeventfd_started = false;
    virtio_device_start_ioeventfd(vdev);
 }
 
#3 lore raw
In reply to Paolo Bonzini
Quoted 8 lines · Paolo Bonzini
Quoted 5 lines · Felipe Franciosi

Recent changes on vhost_dev_enable/disable_notifiers() produced a VirtioBusState vbus variable which can be used instead of the VIRTIO_BUS() macro. This commit just makes the code a little bit cleaner and more consistent.

Quoted 7 lines
Quoted 1 line

Michael, what do you think? Perhaps it's simplest to just squash the two patches (v2 of "vhost: Update 'ioeventfd_started' with host notifiers" and this one).

Paolo

I think I'll apply both but why bother squashing?

Quoted 54 lines
Quoted 54 lines
---
 hw/virtio/vhost.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
hw/virtio/vhost.c +6 -8
index 1290963..7d29dad 100644
@@ -1198,20 +1198,18 @@ int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev)
 
     virtio_device_stop_ioeventfd(vdev);
     for (i = 0; i < hdev->nvqs; ++i) {
-        r = virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), hdev->vq_index + i,
-                                         true);
+        r = virtio_bus_set_host_notifier(vbus, hdev->vq_index + i, true);
         if (r < 0) {
             error_report("vhost VQ %d notifier binding failed: %d", i, -r);
             goto fail_vq;
         }
     }
-    VIRTIO_BUS(qbus)->ioeventfd_started = true;
+    vbus->ioeventfd_started = true;
 
     return 0;
 fail_vq:
     while (--i >= 0) {
-        e = virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), hdev->vq_index + i,
-                                         false);
+        e = virtio_bus_set_host_notifier(vbus, hdev->vq_index + i, false);
         if (e < 0) {
             error_report("vhost VQ %d notifier cleanup error: %d", i, -r);
         }
@@ -1230,17 +1228,17 @@ 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);
     int i, r;
 
     for (i = 0; i < hdev->nvqs; ++i) {
-        r = virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), hdev->vq_index + i,
-                                         false);
+        r = virtio_bus_set_host_notifier(vbus, hdev->vq_index + i, false);
         if (r < 0) {
             error_report("vhost VQ %d notifier cleanup failed: %d", i, -r);
         }
         assert (r >= 0);
     }
-    VIRTIO_BUS(qbus)->ioeventfd_started = false;
+    vbus->ioeventfd_started = false;
     virtio_device_start_ioeventfd(vdev);
 }
 
#4 lore raw
Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · Paolo Bonzini
Quoted 6 lines · Felipe Franciosi

Recent changes on vhost_dev_enable/disable_notifiers() produced a VirtioBusState vbus variable which can be used instead of the VIRTIO_BUS() macro. This commit just makes the code a little bit cleaner and more consistent.

Quoted 7 lines
Quoted 5 lines

Michael, what do you think? Perhaps it's simplest to just squash the two patches (v2 of "vhost: Update 'ioeventfd_started' with host notifiers" and this one).

Paolo

I think I'll apply both but why bother squashing?

Just because

    VIRTIO_BUS(qbus)->ioeventfd_started = true;

from the first patch is ugly. :)

Paolo

Quoted 54 lines
Quoted 54 lines
Quoted 54 lines
---
 hw/virtio/vhost.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
hw/virtio/vhost.c +6 -8
index 1290963..7d29dad 100644
@@ -1198,20 +1198,18 @@ int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev)
 
     virtio_device_stop_ioeventfd(vdev);
     for (i = 0; i < hdev->nvqs; ++i) {
-        r = virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), hdev->vq_index + i,
-                                         true);
+        r = virtio_bus_set_host_notifier(vbus, hdev->vq_index + i, true);
         if (r < 0) {
             error_report("vhost VQ %d notifier binding failed: %d", i, -r);
             goto fail_vq;
         }
     }
-    VIRTIO_BUS(qbus)->ioeventfd_started = true;
+    vbus->ioeventfd_started = true;
 
     return 0;
 fail_vq:
     while (--i >= 0) {
-        e = virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), hdev->vq_index + i,
-                                         false);
+        e = virtio_bus_set_host_notifier(vbus, hdev->vq_index + i, false);
         if (e < 0) {
             error_report("vhost VQ %d notifier cleanup error: %d", i, -r);
         }
@@ -1230,17 +1228,17 @@ 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);
     int i, r;
 
     for (i = 0; i < hdev->nvqs; ++i) {
-        r = virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), hdev->vq_index + i,
-                                         false);
+        r = virtio_bus_set_host_notifier(vbus, hdev->vq_index + i, false);
         if (r < 0) {
             error_report("vhost VQ %d notifier cleanup failed: %d", i, -r);
         }
         assert (r >= 0);
     }
-    VIRTIO_BUS(qbus)->ioeventfd_started = false;
+    vbus->ioeventfd_started = false;
     virtio_device_start_ioeventfd(vdev);
 }