| 311 | } |
| 312 | |
| 313 | static int read_poll_link(const char *file) |
| 314 | { |
| 315 | struct __kernel_timespec ts; |
| 316 | struct io_uring_sqe *sqe; |
| 317 | struct io_uring_cqe *cqe; |
| 318 | struct io_uring ring; |
| 319 | int i, fd, ret, fds[2]; |
| 320 | |
| 321 | ret = io_uring_queue_init(8, &ring, 0); |
| 322 | if (ret) |
| 323 | return ret; |
| 324 | |
| 325 | fd = open(file, O_WRONLY); |
| 326 | if (fd < 0) { |
| 327 | if (errno == EACCES || errno == EPERM) |
| 328 | return T_EXIT_SKIP; |
| 329 | perror("open"); |
| 330 | return 1; |
| 331 | } |
| 332 | |
| 333 | if (pipe(fds)) { |
| 334 | perror("pipe"); |
| 335 | return 1; |
| 336 | } |
| 337 | |
| 338 | sqe = io_uring_get_sqe(&ring); |
| 339 | io_uring_prep_writev(sqe, fd, &vecs[0], 1, 0); |
| 340 | sqe->flags |= IOSQE_IO_LINK; |
| 341 | sqe->user_data = 1; |
| 342 | |
| 343 | sqe = io_uring_get_sqe(&ring); |
| 344 | io_uring_prep_poll_add(sqe, fds[0], POLLIN); |
| 345 | sqe->flags |= IOSQE_IO_LINK; |
| 346 | sqe->user_data = 2; |
| 347 | |
| 348 | ts.tv_sec = 1; |
| 349 | ts.tv_nsec = 0; |
| 350 | sqe = io_uring_get_sqe(&ring); |
| 351 | io_uring_prep_link_timeout(sqe, &ts, 0); |
| 352 | sqe->user_data = 3; |
| 353 | |
| 354 | ret = io_uring_submit(&ring); |
| 355 | if (ret != 3) { |
| 356 | fprintf(stderr, "submitted %d\n", ret); |
| 357 | return 1; |
| 358 | } |
| 359 | |
| 360 | for (i = 0; i < 3; i++) { |
| 361 | ret = io_uring_wait_cqe(&ring, &cqe); |
| 362 | if (ret) { |
| 363 | fprintf(stderr, "wait_cqe=%d\n", ret); |
| 364 | return 1; |
| 365 | } |
| 366 | io_uring_cqe_seen(&ring, cqe); |
| 367 | } |
| 368 | |
| 369 | return 0; |
| 370 | } |
no test coverage detected