Received: from eggs.gnu.org ([2001:4830:134:3::10]:46015) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayEiM-00073M-UY for qemu-devel@nongnu.org; Thu, 05 May 2016 04:33:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ayEiB-00017q-9X for qemu-devel@nongnu.org; Thu, 05 May 2016 04:32:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41338) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayEiB-00013J-4p for qemu-devel@nongnu.org; Thu, 05 May 2016 04:32:43 -0400 From: Stefan Hajnoczi Date: Thu, 5 May 2016 09:32:17 +0100 Message-Id: <1462437137-19824-6-git-send-email-stefanha@redhat.com> In-Reply-To: <1462437137-19824-1-git-send-email-stefanha@redhat.com> References: <1462437137-19824-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PATCH 5/5] libqos: add qvirtio_wait_queue_buf() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?UTF-8?q?Marc=20Mar=C3=AD?= , Stefan Hajnoczi 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 --- 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