diff options
author | Greg Kurz <groug@kaod.org> | 2018-02-01 21:21:28 +0100 |
---|---|---|
committer | Greg Kurz <groug@kaod.org> | 2018-02-02 11:11:55 +0100 |
commit | be3a6781605803b2c48a48135002869ed2c73cf1 (patch) | |
tree | 1836053f31ca3c79b0901fb08dff53ab12ede27a /tests/libqos | |
parent | 354b86f85f516fecb60185f9c2b8e5933177b300 (diff) |
libqos/virtio: return length written into used descriptor
When a 9p request is flushed (ie, cancelled) by the guest, the device
is expected to simply mark the request as used, without sending a 9p
reply (ie, without writing anything into the used buffer).
To be able to test this, we need access to the length written by the
device into the used descriptor. This patch adds a uint32_t * argument
to qvirtqueue_get_buf() and qvirtio_wait_used_elem() for this purpose.
All existing users are updated accordingly.
Signed-off-by: Greg Kurz <groug@kaod.org>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'tests/libqos')
-rw-r--r-- | tests/libqos/virtio.c | 25 | ||||
-rw-r--r-- | tests/libqos/virtio.h | 3 |
2 files changed, 19 insertions, 9 deletions
diff --git a/tests/libqos/virtio.c b/tests/libqos/virtio.c index 0879a621c8..0dad5c19ac 100644 --- a/tests/libqos/virtio.c +++ b/tests/libqos/virtio.c @@ -119,6 +119,8 @@ uint8_t qvirtio_wait_status_byte_no_isr(QVirtioDevice *d, /* * qvirtio_wait_used_elem: * @desc_idx: The next expected vq->desc[] index in the used ring + * @len: A pointer that is filled with the length written into the buffer, may + * be NULL * @timeout_us: How many microseconds to wait before failing * * This function waits for the next completed request on the used ring. @@ -126,6 +128,7 @@ uint8_t qvirtio_wait_status_byte_no_isr(QVirtioDevice *d, void qvirtio_wait_used_elem(QVirtioDevice *d, QVirtQueue *vq, uint32_t desc_idx, + uint32_t *len, gint64 timeout_us) { gint64 start_time = g_get_monotonic_time(); @@ -136,7 +139,7 @@ void qvirtio_wait_used_elem(QVirtioDevice *d, clock_step(100); if (d->bus->get_queue_isr_status(d, vq) && - qvirtqueue_get_buf(vq, &got_desc_idx)) { + qvirtqueue_get_buf(vq, &got_desc_idx, len)) { g_assert_cmpint(got_desc_idx, ==, desc_idx); return; } @@ -304,30 +307,36 @@ void qvirtqueue_kick(QVirtioDevice *d, QVirtQueue *vq, uint32_t free_head) /* * qvirtqueue_get_buf: * @desc_idx: A pointer that is filled with the vq->desc[] index, may be NULL + * @len: A pointer that is filled with the length written into the buffer, may + * be NULL * * This function gets the next used element if there is one ready. * * Returns: true if an element was ready, false otherwise */ -bool qvirtqueue_get_buf(QVirtQueue *vq, uint32_t *desc_idx) +bool qvirtqueue_get_buf(QVirtQueue *vq, uint32_t *desc_idx, uint32_t *len) { uint16_t idx; + uint64_t elem_addr; idx = readw(vq->used + offsetof(struct vring_used, idx)); if (idx == vq->last_used_idx) { return false; } - if (desc_idx) { - uint64_t elem_addr; + elem_addr = vq->used + + offsetof(struct vring_used, ring) + + (vq->last_used_idx % vq->size) * + sizeof(struct vring_used_elem); - elem_addr = vq->used + - offsetof(struct vring_used, ring) + - (vq->last_used_idx % vq->size) * - sizeof(struct vring_used_elem); + if (desc_idx) { *desc_idx = readl(elem_addr + offsetof(struct vring_used_elem, id)); } + if (len) { + *len = readw(elem_addr + offsetof(struct vring_used_elem, len)); + } + vq->last_used_idx++; return true; } diff --git a/tests/libqos/virtio.h b/tests/libqos/virtio.h index 0a04740adf..69b5b13840 100644 --- a/tests/libqos/virtio.h +++ b/tests/libqos/virtio.h @@ -124,6 +124,7 @@ uint8_t qvirtio_wait_status_byte_no_isr(QVirtioDevice *d, void qvirtio_wait_used_elem(QVirtioDevice *d, QVirtQueue *vq, uint32_t desc_idx, + uint32_t *len, gint64 timeout_us); void qvirtio_wait_config_isr(QVirtioDevice *d, gint64 timeout_us); QVirtQueue *qvirtqueue_setup(QVirtioDevice *d, @@ -140,7 +141,7 @@ uint32_t qvirtqueue_add(QVirtQueue *vq, uint64_t data, uint32_t len, bool write, bool next); uint32_t qvirtqueue_add_indirect(QVirtQueue *vq, QVRingIndirectDesc *indirect); void qvirtqueue_kick(QVirtioDevice *d, QVirtQueue *vq, uint32_t free_head); -bool qvirtqueue_get_buf(QVirtQueue *vq, uint32_t *desc_idx); +bool qvirtqueue_get_buf(QVirtQueue *vq, uint32_t *desc_idx, uint32_t *len); void qvirtqueue_set_used_event(QVirtQueue *vq, uint16_t idx); |