Add link SQE support

Just a basic test case that does various forms of linked nops, and
a sample bare bones copy program using linked reads and writes.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Jens Axboe
2019-05-13 16:16:07 -06:00
parent 40c6f8454b
commit 0ba9503f79
5 changed files with 381 additions and 4 deletions

View File

@@ -2,14 +2,14 @@ CFLAGS ?= -g -O2 -Wall -D_GNU_SOURCE -L../src/
all_targets += poll poll-cancel ring-leak fsync io_uring_setup io_uring_register \
io_uring_enter nop sq-full cq-full 35fa71a030ca-test \
917257daa0fe-test b19062a56726-test eeed8b54e0df-test
917257daa0fe-test b19062a56726-test eeed8b54e0df-test link
all: $(all_targets)
test_srcs := poll.c poll-cancel.c ring-leak.c fsync.c io_uring_setup.c \
io_uring_register.c io_uring_enter.c nop.c sq-full.c cq-full.c \
35fa71a030ca-test.c 917257daa0fe-test.c b19062a56726-test.c \
eeed8b54e0df-test
eeed8b54e0df-test link
test_objs := $(patsubst %.c,%.ol,$(test_srcs))
@@ -41,6 +41,8 @@ b19062a56726-test: b19062a56726-test.c
$(CC) $(CFLAGS) -o $@ b19062a56726-test.c
eeed8b54e0df-test: eeed8b54e0df-test.c
$(CC) $(CFLAGS) -o $@ eeed8b54e0df-test.c -luring
link: link.c
$(CC) $(CFLAGS) -o $@ link.c -luring
clean:
rm -f $(all_targets) $(test_objs)

209
test/link.c Normal file
View File

@@ -0,0 +1,209 @@
/*
* Description: run various linked sqe tests
*
*/
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include "../src/liburing.h"
/*
* Test two independent chains
*/
static int test_double_chain(struct io_uring *ring)
{
struct io_uring_cqe *cqe;
struct io_uring_sqe *sqe;
int ret, i;
sqe = io_uring_get_sqe(ring);
if (!sqe) {
printf("get sqe failed\n");
goto err;
}
io_uring_prep_nop(sqe);
sqe->flags |= IOSQE_IO_LINK;
sqe = io_uring_get_sqe(ring);
if (!sqe) {
printf("get sqe failed\n");
goto err;
}
io_uring_prep_nop(sqe);
sqe = io_uring_get_sqe(ring);
if (!sqe) {
printf("get sqe failed\n");
goto err;
}
io_uring_prep_nop(sqe);
sqe->flags |= IOSQE_IO_LINK;
sqe = io_uring_get_sqe(ring);
if (!sqe) {
printf("get sqe failed\n");
goto err;
}
io_uring_prep_nop(sqe);
ret = io_uring_submit(ring);
if (ret <= 0) {
printf("sqe submit failed: %d\n", ret);
goto err;
}
for (i = 0; i < 4; i++) {
ret = io_uring_wait_cqe(ring, &cqe);
if (ret < 0) {
printf("wait completion %d\n", ret);
goto err;
}
io_uring_cqe_seen(ring, cqe);
}
return 0;
err:
return 1;
}
/*
* Test multiple dependents
*/
static int test_double_link(struct io_uring *ring)
{
struct io_uring_cqe *cqe;
struct io_uring_sqe *sqe;
int ret, i;
sqe = io_uring_get_sqe(ring);
if (!sqe) {
printf("get sqe failed\n");
goto err;
}
io_uring_prep_nop(sqe);
sqe->flags |= IOSQE_IO_LINK;
sqe = io_uring_get_sqe(ring);
if (!sqe) {
printf("get sqe failed\n");
goto err;
}
io_uring_prep_nop(sqe);
sqe->flags |= IOSQE_IO_LINK;
sqe = io_uring_get_sqe(ring);
if (!sqe) {
printf("get sqe failed\n");
goto err;
}
io_uring_prep_nop(sqe);
ret = io_uring_submit(ring);
if (ret <= 0) {
printf("sqe submit failed: %d\n", ret);
goto err;
}
for (i = 0; i < 3; i++) {
ret = io_uring_wait_cqe(ring, &cqe);
if (ret < 0) {
printf("wait completion %d\n", ret);
goto err;
}
io_uring_cqe_seen(ring, cqe);
}
return 0;
err:
return 1;
}
/*
* Test single dependency
*/
static int test_single_link(struct io_uring *ring)
{
struct io_uring_cqe *cqe;
struct io_uring_sqe *sqe;
int ret, i;
sqe = io_uring_get_sqe(ring);
if (!sqe) {
printf("get sqe failed\n");
goto err;
}
io_uring_prep_nop(sqe);
sqe->flags |= IOSQE_IO_LINK;
sqe = io_uring_get_sqe(ring);
if (!sqe) {
printf("get sqe failed\n");
goto err;
}
io_uring_prep_nop(sqe);
ret = io_uring_submit(ring);
if (ret <= 0) {
printf("sqe submit failed: %d\n", ret);
goto err;
}
for (i = 0; i < 2; i++) {
ret = io_uring_wait_cqe(ring, &cqe);
if (ret < 0) {
printf("wait completion %d\n", ret);
goto err;
}
io_uring_cqe_seen(ring, cqe);
}
return 0;
err:
return 1;
}
int main(int argc, char *argv[])
{
struct io_uring ring;
int ret;
ret = io_uring_queue_init(8, &ring, 0);
if (ret) {
printf("ring setup failed\n");
return 1;
}
ret = test_single_link(&ring);
if (ret) {
printf("test_single_link failed\n");
return ret;
}
ret = test_double_link(&ring);
if (ret) {
printf("test_double_link failed\n");
return ret;
}
ret = test_double_chain(&ring);
if (ret) {
printf("test_double_chain failed\n");
return ret;
}
return 0;
}