[RFC PATCH 3/9] tools/virtio: convert to new vringh user APIs

From: Shunsuke Mie
Date: Mon Dec 26 2022 - 21:26:01 EST


struct vringh_iov is being remove, so convert vringh_test to use the
vringh user APIs. This has it change to use struct vringh_kiov instead of
the struct vringh_iov.

Signed-off-by: Shunsuke Mie <mie@xxxxxxxxxx>
---
tools/virtio/vringh_test.c | 34 +++++++++++++++++-----------------
1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/tools/virtio/vringh_test.c b/tools/virtio/vringh_test.c
index 98ff808d6f0c..6c9533b8a2ca 100644
--- a/tools/virtio/vringh_test.c
+++ b/tools/virtio/vringh_test.c
@@ -193,8 +193,8 @@ static int parallel_test(u64 features,
errx(1, "Could not set affinity to cpu %u", first_cpu);

while (xfers < NUM_XFERS) {
- struct iovec host_riov[2], host_wiov[2];
- struct vringh_iov riov, wiov;
+ struct kvec host_riov[2], host_wiov[2];
+ struct vringh_kiov riov, wiov;
u16 head, written;

if (fast_vringh) {
@@ -216,10 +216,10 @@ static int parallel_test(u64 features,
written = 0;
goto complete;
} else {
- vringh_iov_init(&riov,
+ vringh_kiov_init(&riov,
host_riov,
ARRAY_SIZE(host_riov));
- vringh_iov_init(&wiov,
+ vringh_kiov_init(&wiov,
host_wiov,
ARRAY_SIZE(host_wiov));

@@ -442,8 +442,8 @@ int main(int argc, char *argv[])
struct virtqueue *vq;
struct vringh vrh;
struct scatterlist guest_sg[RINGSIZE], *sgs[2];
- struct iovec host_riov[2], host_wiov[2];
- struct vringh_iov riov, wiov;
+ struct kvec host_riov[2], host_wiov[2];
+ struct vringh_kiov riov, wiov;
struct vring_used_elem used[RINGSIZE];
char buf[28];
u16 head;
@@ -517,8 +517,8 @@ int main(int argc, char *argv[])
__kmalloc_fake = NULL;

/* Host retreives it. */
- vringh_iov_init(&riov, host_riov, ARRAY_SIZE(host_riov));
- vringh_iov_init(&wiov, host_wiov, ARRAY_SIZE(host_wiov));
+ vringh_kiov_init(&riov, host_riov, ARRAY_SIZE(host_riov));
+ vringh_kiov_init(&wiov, host_wiov, ARRAY_SIZE(host_wiov));

err = vringh_getdesc_user(&vrh, &riov, &wiov, getrange, &head);
if (err != 1)
@@ -586,8 +586,8 @@ int main(int argc, char *argv[])
__kmalloc_fake = NULL;

/* Host picks it up (allocates new iov). */
- vringh_iov_init(&riov, host_riov, ARRAY_SIZE(host_riov));
- vringh_iov_init(&wiov, host_wiov, ARRAY_SIZE(host_wiov));
+ vringh_kiov_init(&riov, host_riov, ARRAY_SIZE(host_riov));
+ vringh_kiov_init(&wiov, host_wiov, ARRAY_SIZE(host_wiov));

err = vringh_getdesc_user(&vrh, &riov, &wiov, getrange, &head);
if (err != 1)
@@ -613,8 +613,8 @@ int main(int argc, char *argv[])
assert(err < 3 || buf[2] == (char)(i + 2));
}
assert(riov.i == riov.used);
- vringh_iov_cleanup(&riov);
- vringh_iov_cleanup(&wiov);
+ vringh_kiov_cleanup(&riov);
+ vringh_kiov_cleanup(&wiov);

/* Complete using multi interface, just because we can. */
used[0].id = head;
@@ -638,8 +638,8 @@ int main(int argc, char *argv[])
}

/* Now get many, and consume them all at once. */
- vringh_iov_init(&riov, host_riov, ARRAY_SIZE(host_riov));
- vringh_iov_init(&wiov, host_wiov, ARRAY_SIZE(host_wiov));
+ vringh_kiov_init(&riov, host_riov, ARRAY_SIZE(host_riov));
+ vringh_kiov_init(&wiov, host_wiov, ARRAY_SIZE(host_wiov));

for (i = 0; i < RINGSIZE; i++) {
err = vringh_getdesc_user(&vrh, &riov, &wiov, getrange, &head);
@@ -723,8 +723,8 @@ int main(int argc, char *argv[])
d[5].flags = 0;

/* Host picks it up (allocates new iov). */
- vringh_iov_init(&riov, host_riov, ARRAY_SIZE(host_riov));
- vringh_iov_init(&wiov, host_wiov, ARRAY_SIZE(host_wiov));
+ vringh_kiov_init(&riov, host_riov, ARRAY_SIZE(host_riov));
+ vringh_kiov_init(&wiov, host_wiov, ARRAY_SIZE(host_wiov));

err = vringh_getdesc_user(&vrh, &riov, &wiov, getrange, &head);
if (err != 1)
@@ -744,7 +744,7 @@ int main(int argc, char *argv[])
/* Data should be linear. */
for (i = 0; i < err; i++)
assert(buf[i] == i);
- vringh_iov_cleanup(&riov);
+ vringh_kiov_cleanup(&riov);
}

/* Don't leak memory... */
--
2.25.1