summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Begunkov <asml.silence@gmail.com>2021-03-12 16:28:33 +0000
committerJens Axboe <axboe@kernel.dk>2021-03-18 09:17:35 -0600
commit2b89fce100ee1e6859fedc0768029dc9019faef1 (patch)
treec825ef110e58631f1cc0363f986c2bcc7e970935
parent14d63ea2d9a5e709c5e099270a7e4ba95e73af08 (diff)
downloadliburing-2b89fce100ee1e6859fedc0768029dc9019faef1.tar.gz
liburing-2b89fce100ee1e6859fedc0768029dc9019faef1.tar.bz2
tests: test that ring exit cancels io-wq
Test that io_uring_queue_exit() does proper cancellation of io-wq. Note that there are worse cases with multiple tasks that can hang in the kernel due to failing to do io-wq cancellations properly. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/r/2eee395a2cf1bea49036aa82b056ff7bfd2cda14.1615566409.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--test/ring-leak.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/test/ring-leak.c b/test/ring-leak.c
index 4ddc8ff..7ff1d87 100644
--- a/test/ring-leak.c
+++ b/test/ring-leak.c
@@ -73,6 +73,65 @@ static void send_fd(int socket, int fd)
perror("sendmsg");
}
+static int test_iowq_request_cancel(void)
+{
+ char buffer[128];
+ struct io_uring ring;
+ struct io_uring_sqe *sqe;
+ int ret, fds[2];
+
+ ret = io_uring_queue_init(8, &ring, 0);
+ if (ret < 0) {
+ fprintf(stderr, "failed to init io_uring: %s\n", strerror(-ret));
+ return ret;
+ }
+ if (pipe(fds)) {
+ perror("pipe");
+ return -1;
+ }
+ ret = io_uring_register_files(&ring, fds, 2);
+ if (ret) {
+ fprintf(stderr, "file_register: %d\n", ret);
+ return ret;
+ }
+ close(fds[1]);
+
+ sqe = io_uring_get_sqe(&ring);
+ if (!sqe) {
+ fprintf(stderr, "%s: failed to get sqe\n", __FUNCTION__);
+ return 1;
+ }
+ /* potentially sitting in internal polling */
+ io_uring_prep_read(sqe, 0, buffer, 10, 0);
+ sqe->flags |= IOSQE_FIXED_FILE;
+
+ sqe = io_uring_get_sqe(&ring);
+ if (!sqe) {
+ fprintf(stderr, "%s: failed to get sqe\n", __FUNCTION__);
+ return 1;
+ }
+ /* staying in io-wq */
+ io_uring_prep_read(sqe, 0, buffer, 10, 0);
+ sqe->flags |= IOSQE_FIXED_FILE | IOSQE_ASYNC;
+
+ ret = io_uring_submit(&ring);
+ if (ret != 2) {
+ fprintf(stderr, "%s: got %d, wanted 1\n", __FUNCTION__, ret);
+ return 1;
+ }
+
+ /* should unregister files and close the write fd */
+ io_uring_queue_exit(&ring);
+
+ /*
+ * We're trying to wait for the ring to "really" exit, that will be
+ * done async. For that rely on the registered write end to be closed
+ * after ring quiesce, so failing read from the other pipe end.
+ */
+ read(fds[0], buffer, 10);
+ return 0;
+}
+
int main(int argc, char *argv[])
{
int sp[2], pid, ring_fd, ret;
@@ -80,6 +139,12 @@ int main(int argc, char *argv[])
if (argc > 1)
return 0;
+ ret = test_iowq_request_cancel();
+ if (ret) {
+ fprintf(stderr, "test_iowq_request_cancel() failed\n");
+ return 1;
+ }
+
if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sp) != 0) {
perror("Failed to create Unix-domain socket pair\n");
return 1;