Skip to content

Commit

Permalink
add test case for 5.4 io merge regression logic
Browse files Browse the repository at this point in the history
Prior to switching io-wq we try to merge adjacent read/write requests.
But because of bug in merge logic io may stuck
  • Loading branch information
Dmitry Monakhov committed Mar 19, 2021
1 parent a9f23f0 commit 16d171b
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
90 changes: 90 additions & 0 deletions test/462ef1f514d3-test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/* SPDX-License-Identifier: MIT */
/*
* Regression test for incorrect async_list io_should_merge() logic
* Bug was fixed in 5.5 by (commit: 561fb04 io_uring: replace workqueue usage with io-wq")
* Affects 5.4 lts branch, at least 5.4.106 is affected.
*/
#include <stdio.h>
#include <errno.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <assert.h>
#include <fcntl.h>
#include <unistd.h>

#include "liburing.h"
#include "liburing.h"


int main(int argc, char *argv[])
{
struct io_uring_sqe *sqe;
struct io_uring_cqe *cqe;
struct io_uring ring;
int ret, fd, pipe1[2];
char buf[4096];
struct iovec vec = {
.iov_base = buf,
.iov_len = sizeof(buf)
};
struct __kernel_timespec ts = {.tv_sec = 3, .tv_nsec = 0};

ret = pipe(pipe1);
assert(!ret);

fd = open("testfile", O_RDWR | O_CREAT, 0644);
assert(ret>=0);
ret = ftruncate(fd, 4096);
assert(!ret);

ret = io_uring_queue_init(4, &ring, 0);
assert(!ret);

sqe = io_uring_get_sqe(&ring);
io_uring_prep_readv(sqe, pipe1[0], &vec, 1, 0);
sqe->user_data = 1;

sqe = io_uring_get_sqe(&ring);
io_uring_prep_readv(sqe, fd, &vec, 1, 4096);
sqe->user_data = 2;

ret = io_uring_submit(&ring);
assert(ret == 2);

ret = io_uring_wait_cqe(&ring, &cqe);
assert(!ret);
assert(cqe->res == 0);
assert(cqe->user_data == 2);
io_uring_cqe_seen(&ring, cqe);

/*
* Prepare request adjusent to previous one, so merge logic may want to
* link it previous request, but because of a bug in merge logic
* it may be merged with pipe-read request
*/
sqe = io_uring_get_sqe(&ring);
io_uring_prep_readv(sqe, fd, &vec, 1, 2048);
sqe->user_data = 3;

ret = io_uring_submit(&ring);
assert(ret == 1);

/*
* Read may stuck because of because a bug there request was incorrecly
* merged with pipe-read request
*/
ret = io_uring_wait_cqe_timeout(&ring, &cqe, &ts);
if (ret == -ETIME) {
printf("TEST_FAIL: readv request stuck\n");
return 1;
}
assert(!ret);

assert(cqe->res == 2048);
assert(cqe->user_data == 3);

io_uring_cqe_seen(&ring, cqe);
io_uring_queue_exit(&ring);

return 0;
}
2 changes: 2 additions & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ test_targets += \
232c93d07b74-test \
35fa71a030ca-test \
500f9fbadef8-test \
462ef1f514d3-test \
7ad0e4b2f83c-test \
8a9973408177-test \
917257daa0fe-test \
Expand Down Expand Up @@ -150,6 +151,7 @@ test_srcs := \
helpers.c \
232c93d07b74-test.c \
35fa71a030ca-test.c \
462ef1f514d3-test.c \
500f9fbadef8-test.c \
7ad0e4b2f83c-test.c \
8a9973408177-test.c \
Expand Down

0 comments on commit 16d171b

Please sign in to comment.