Make sure we don't fail links on ETIME when IORING_TIMEOUT_ETIME_SUCCESS is set. Signed-off-by: Pavel Begunkov <asml.silence@xxxxxxxxx> --- src/include/liburing/io_uring.h | 1 + test/timeout.c | 67 +++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/src/include/liburing/io_uring.h b/src/include/liburing/io_uring.h index 7aa43fc..61683bd 100644 --- a/src/include/liburing/io_uring.h +++ b/src/include/liburing/io_uring.h @@ -162,6 +162,7 @@ enum { #define IORING_TIMEOUT_BOOTTIME (1U << 2) #define IORING_TIMEOUT_REALTIME (1U << 3) #define IORING_LINK_TIMEOUT_UPDATE (1U << 4) +#define IORING_TIMEOUT_ETIME_SUCCESS (1U << 5) #define IORING_TIMEOUT_CLOCK_MASK (IORING_TIMEOUT_BOOTTIME | IORING_TIMEOUT_REALTIME) #define IORING_TIMEOUT_UPDATE_MASK (IORING_TIMEOUT_UPDATE | IORING_LINK_TIMEOUT_UPDATE) /* diff --git a/test/timeout.c b/test/timeout.c index 775063f..f8ba973 100644 --- a/test/timeout.c +++ b/test/timeout.c @@ -1267,6 +1267,67 @@ static int test_timeout_link_cancel(void) return 0; } + +static int test_not_failing_links(void) +{ + struct io_uring ring; + struct io_uring_sqe *sqe; + struct io_uring_cqe *cqe; + struct __kernel_timespec ts; + int ret; + + ret = io_uring_queue_init(8, &ring, 0); + if (ret) { + fprintf(stderr, "ring create failed: %d\n", ret); + return 1; + } + + msec_to_ts(&ts, 1); + sqe = io_uring_get_sqe(&ring); + io_uring_prep_timeout(sqe, &ts, 0, IORING_TIMEOUT_ETIME_SUCCESS); + sqe->user_data = 1; + sqe->flags |= IOSQE_IO_LINK; + + sqe = io_uring_get_sqe(&ring); + io_uring_prep_nop(sqe); + sqe->user_data = 2; + + ret = io_uring_submit(&ring); + if (ret != 2) { + fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret); + return 1; + } + + ret = io_uring_wait_cqe(&ring, &cqe); + if (ret < 0) { + fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret); + return 1; + } else if (cqe->user_data == 1 && cqe->res == -EINVAL) { + fprintf(stderr, "ETIME_SUCCESS is not supported, skip\n"); + goto done; + } else if (cqe->res != -ETIME || cqe->user_data != 1) { + fprintf(stderr, "timeout failed %i %i\n", cqe->res, + (int)cqe->user_data); + return 1; + } + io_uring_cqe_seen(&ring, cqe); + + ret = io_uring_wait_cqe(&ring, &cqe); + if (ret < 0) { + fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret); + return 1; + } else if (cqe->res || cqe->user_data != 2) { + fprintf(stderr, "nop failed %i %i\n", cqe->res, + (int)cqe->user_data); + return 1; + } +done: + io_uring_cqe_seen(&ring, cqe); + io_uring_queue_exit(&ring); + return 0; +} + + int main(int argc, char *argv[]) { struct io_uring ring, sqpoll_ring; @@ -1450,6 +1511,12 @@ int main(int argc, char *argv[]) return ret; } + ret = test_not_failing_links(); + if (ret) { + fprintf(stderr, "test_not_failing_links failed\n"); + return ret; + } + if (sqpoll) io_uring_queue_exit(&sqpoll_ring); return 0; -- 2.33.0