summaryrefslogtreecommitdiff
path: root/test/poll-cancel-all.c
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2022-04-16 14:45:50 -0600
committerJens Axboe <axboe@kernel.dk>2022-04-16 14:45:50 -0600
commitc091b912bc9c6fb64c68c7b0056c4923b327cd9e (patch)
treef84e652a991517692f09a8d37e8d4a3ac7cf0940 /test/poll-cancel-all.c
parentd02460d876daec91293aa025f0cfb3af59dcccd4 (diff)
downloadliburing-c091b912bc9c6fb64c68c7b0056c4923b327cd9e.tar.gz
liburing-c091b912bc9c6fb64c68c7b0056c4923b327cd9e.tar.bz2
test/poll-cancel-all: test IORING_ASYNC_CANCEL_ANY
_ANY will match any request, no keys needed. Allows canceling any request on the ring. Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'test/poll-cancel-all.c')
-rw-r--r--test/poll-cancel-all.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/test/poll-cancel-all.c b/test/poll-cancel-all.c
index 754ec4f..c724823 100644
--- a/test/poll-cancel-all.c
+++ b/test/poll-cancel-all.c
@@ -247,6 +247,100 @@ err:
return 1;
}
+static int test3(struct io_uring *ring, int *fd)
+{
+ struct io_uring_sqe *sqe;
+ struct io_uring_cqe *cqe;
+ int ret, i, fd2[2];
+
+ if (pipe(fd2) < 0) {
+ perror("pipe");
+ return 1;
+ }
+
+ for (i = 0; i < 8; i++) {
+ sqe = io_uring_get_sqe(ring);
+ if (!sqe) {
+ fprintf(stderr, "get sqe failed\n");
+ goto err;
+ }
+
+ if (!(i & 1)) {
+ io_uring_prep_poll_add(sqe, fd[0], POLLIN);
+ sqe->flags |= IOSQE_ASYNC;
+ } else
+ io_uring_prep_poll_add(sqe, fd2[0], POLLIN);
+ sqe->user_data = i & 1;
+ }
+
+ ret = io_uring_submit(ring);
+ if (ret < 8) {
+ fprintf(stderr, "child: sqe submit failed: %d\n", ret);
+ goto err;
+ }
+
+ usleep(10000);
+
+ sqe = io_uring_get_sqe(ring);
+ if (!sqe) {
+ fprintf(stderr, "get sqe failed\n");
+ goto err;
+ }
+
+ /*
+ * Mark CANCEL_ALL to cancel all matching the key, and use
+ * CANCEL_FD to cancel requests matching the specified fd.
+ * This should cancel all the pending poll requests on the pipe
+ * input.
+ */
+ io_uring_prep_cancel(sqe, 0, IORING_ASYNC_CANCEL_ALL);
+ sqe->cancel_flags |= IORING_ASYNC_CANCEL_ANY;
+ sqe->fd = 0;
+ sqe->user_data = 100;
+
+ ret = io_uring_submit(ring);
+ if (ret < 1) {
+ fprintf(stderr, "child: sqe submit failed: %d\n", ret);
+ goto err;
+ }
+
+ for (i = 0; i < 9; i++) {
+ ret = io_uring_wait_cqe(ring, &cqe);
+ if (ret) {
+ fprintf(stderr, "wait=%d\n", ret);
+ goto err;
+ }
+ switch (cqe->user_data) {
+ case 100:
+ if (cqe->res != 8) {
+ fprintf(stderr, "canceled %d\n", cqe->res);
+ goto err;
+ }
+ break;
+ case 0:
+ case 1:
+ if (cqe->res != -ECANCELED) {
+ fprintf(stderr, "poll res %d\n", cqe->res);
+ goto err;
+ }
+ break;
+ default:
+ fprintf(stderr, "invalid user_data %lu\n",
+ (unsigned long) cqe->user_data);
+ goto err;
+ }
+ io_uring_cqe_seen(ring, cqe);
+ }
+
+ close(fd2[0]);
+ close(fd2[1]);
+ return 0;
+err:
+ close(fd2[0]);
+ close(fd2[1]);
+ return 1;
+}
+
int main(int argc, char *argv[])
{
struct io_uring ring;
@@ -280,5 +374,11 @@ int main(int argc, char *argv[])
return ret;
}
+ ret = test3(&ring, fd);
+ if (ret) {
+ fprintf(stderr, "test3 failed\n");
+ return ret;
+ }
+
return 0;
}