summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2021-09-16 10:02:17 -0600
committerJens Axboe <axboe@kernel.dk>2021-09-16 10:02:17 -0600
commitd06c81aa3c170b586b09a88ebcd2c04f3106bd44 (patch)
tree8aab68976500ba022b55661dd9c0d74ad1a08bf4
parentd68917b4207bd9a6d39a5b87109e9cfdde574878 (diff)
downloadliburing-d06c81aa3c170b586b09a88ebcd2c04f3106bd44.tar.gz
liburing-d06c81aa3c170b586b09a88ebcd2c04f3106bd44.tar.bz2
test/file-verify: add provide buffers test case
This is another invariant where we provide buffers to the ring, and then have the read operation auto-select the buffer based on the buffer index specified. Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--test/file-verify.c49
1 files changed, 43 insertions, 6 deletions
diff --git a/test/file-verify.c b/test/file-verify.c
index 0a0b5e9..201306b 100644
--- a/test/file-verify.c
+++ b/test/file-verify.c
@@ -56,7 +56,7 @@ static int verify_buf(void *buf, size_t size, off_t off)
}
static int test_truncate(struct io_uring *ring, const char *fname, int buffered,
- int vectored)
+ int vectored, int provide_buf)
{
struct io_uring_cqe *cqe;
struct io_uring_sqe *sqe;
@@ -135,6 +135,27 @@ again:
goto err;
}
+ if (provide_buf) {
+ sqe = io_uring_get_sqe(ring);
+ io_uring_prep_provide_buffers(sqe, buf, CHUNK_SIZE, 1, 0, 0);
+ ret = io_uring_submit(ring);
+ if (ret != 1) {
+ fprintf(stderr, "submit failed %d\n", ret);
+ goto err;
+ }
+ ret = io_uring_wait_cqe(ring, &cqe);
+ if (ret < 0) {
+ fprintf(stderr, "wait completion %d\n", ret);
+ goto err;
+ }
+ ret = cqe->res;
+ io_uring_cqe_seen(ring, cqe);
+ if (ret) {
+ fprintf(stderr, "Provide buffer failed %d\n", ret);
+ goto err;
+ }
+ }
+
sqe = io_uring_get_sqe(ring);
if (!sqe) {
fprintf(stderr, "get sqe failed\n");
@@ -142,11 +163,17 @@ again:
}
if (vectored) {
+ assert(!provide_buf);
vec.iov_base = buf;
vec.iov_len = CHUNK_SIZE;
io_uring_prep_readv(sqe, fd, &vec, 1, off);
} else {
- io_uring_prep_read(sqe, fd, buf, CHUNK_SIZE, off);
+ if (provide_buf) {
+ io_uring_prep_read(sqe, fd, NULL, CHUNK_SIZE, off);
+ sqe->flags |= IOSQE_BUFFER_SELECT;
+ } else {
+ io_uring_prep_read(sqe, fd, buf, CHUNK_SIZE, off);
+ }
}
memset(buf, 0, CHUNK_SIZE);
@@ -499,27 +526,37 @@ int main(int argc, char *argv[])
goto err;
}
- ret = test_truncate(&ring, fname, 1, 0);
+ ret = test_truncate(&ring, fname, 1, 0, 0);
if (ret) {
fprintf(stderr, "Buffered end truncate read failed\n");
goto err;
}
- ret = test_truncate(&ring, fname, 1, 1);
+ ret = test_truncate(&ring, fname, 1, 1, 0);
if (ret) {
fprintf(stderr, "Buffered end truncate vec read failed\n");
goto err;
}
+ ret = test_truncate(&ring, fname, 1, 0, 1);
+ if (ret) {
+ fprintf(stderr, "Buffered end truncate pbuf read failed\n");
+ goto err;
+ }
- ret = test_truncate(&ring, fname, 0, 0);
+ ret = test_truncate(&ring, fname, 0, 0, 0);
if (ret) {
fprintf(stderr, "O_DIRECT end truncate read failed\n");
goto err;
}
- ret = test_truncate(&ring, fname, 0, 1);
+ ret = test_truncate(&ring, fname, 0, 1, 0);
if (ret) {
fprintf(stderr, "O_DIRECT end truncate vec read failed\n");
goto err;
}
+ ret = test_truncate(&ring, fname, 0, 0, 1);
+ if (ret) {
+ fprintf(stderr, "O_DIRECT end truncate pbuf read failed\n");
+ goto err;
+ }
if (buf == fname)
unlink(fname);