forked from axboe/liburing
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test case for 5.4 io merge regression logic
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
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters