qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH 5/5] libqos: add qvirtio_wait_queue_buf()


From: Stefan Hajnoczi
Subject: [Qemu-devel] [PATCH 5/5] libqos: add qvirtio_wait_queue_buf()
Date: Thu, 5 May 2016 09:32:17 +0100

Like qvirtqueue_get_buf() but blocking and checks for the expected
buffer token.  New virtio device tests are expected to use this function
as a convenient way to pop buffers off the used ring.

Signed-off-by: Stefan Hajnoczi <address@hidden>
---
 tests/libqos/virtio.c | 28 ++++++++++++++++++++++++++++
 tests/libqos/virtio.h |  3 +++
 2 files changed, 31 insertions(+)

diff --git a/tests/libqos/virtio.c b/tests/libqos/virtio.c
index 948d722..b1591db 100644
--- a/tests/libqos/virtio.c
+++ b/tests/libqos/virtio.c
@@ -131,6 +131,34 @@ void qvirtio_wait_config_isr(const QVirtioBus *bus, 
QVirtioDevice *d,
     }
 }
 
+/**
+ * qvirtio_wait_queue_buf:
+ * @bus: the virtio bus
+ * @d: the virtio device
+ * @vq: the virtqueue
+ *
+ * Wait for the next buffer and check that it has the given token.
+ *
+ * Returns: the number of bytes written by the device.
+ */
+unsigned int qvirtio_wait_queue_buf(const QVirtioBus *bus, QVirtioDevice *d,
+                                    QVirtQueue *vq, void *token,
+                                    gint64 timeout_us)
+{
+    unsigned int len;
+    void *actual_token;
+
+    actual_token = qvirtqueue_get_buf(vq, &len);
+    if (!actual_token) {
+        qvirtio_wait_queue_isr(bus, d, vq, timeout_us);
+        actual_token = qvirtqueue_get_buf(vq, &len);
+    }
+    g_assert(actual_token != NULL);
+    g_assert(actual_token == token);
+
+    return len;
+}
+
 void qvring_init(const QGuestAllocator *alloc, QVirtQueue *vq, uint64_t addr)
 {
     int i;
diff --git a/tests/libqos/virtio.h b/tests/libqos/virtio.h
index 4fea8ef..5d40b23 100644
--- a/tests/libqos/virtio.h
+++ b/tests/libqos/virtio.h
@@ -120,6 +120,9 @@ uint8_t qvirtio_wait_status_byte_no_isr(const QVirtioBus 
*bus,
                                         gint64 timeout_us);
 void qvirtio_wait_config_isr(const QVirtioBus *bus, QVirtioDevice *d,
                              gint64 timeout_us);
+unsigned int qvirtio_wait_queue_buf(const QVirtioBus *bus, QVirtioDevice *d,
+                                    QVirtQueue *vq, void *token,
+                                    gint64 timeout_us);
 QVirtQueue *qvirtqueue_setup(const QVirtioBus *bus, QVirtioDevice *d,
                                         QGuestAllocator *alloc, uint16_t 
index);
 
-- 
2.5.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]