| 56 | } |
| 57 | |
| 58 | static int test_barrier_fsync(struct io_uring *ring) |
| 59 | { |
| 60 | struct io_uring_cqe *cqe; |
| 61 | struct io_uring_sqe *sqe; |
| 62 | struct iovec iovecs[4]; |
| 63 | int i, fd, ret; |
| 64 | off_t off; |
| 65 | |
| 66 | fd = open("fsync-testfile", O_WRONLY | O_CREAT, 0644); |
| 67 | if (fd < 0) { |
| 68 | perror("open"); |
| 69 | return 1; |
| 70 | } |
| 71 | unlink("fsync-testfile"); |
| 72 | |
| 73 | for (i = 0; i < ARRAY_SIZE(iovecs); i++) { |
| 74 | iovecs[i].iov_base = t_malloc(4096); |
| 75 | iovecs[i].iov_len = 4096; |
| 76 | } |
| 77 | |
| 78 | off = 0; |
| 79 | for (i = 0; i < 4; i++) { |
| 80 | sqe = io_uring_get_sqe(ring); |
| 81 | if (!sqe) { |
| 82 | fprintf(stderr, "get sqe failed\n"); |
| 83 | goto err; |
| 84 | } |
| 85 | |
| 86 | io_uring_prep_writev(sqe, fd, &iovecs[i], 1, off); |
| 87 | sqe->user_data = 0; |
| 88 | off += 4096; |
| 89 | } |
| 90 | |
| 91 | sqe = io_uring_get_sqe(ring); |
| 92 | if (!sqe) { |
| 93 | fprintf(stderr, "get sqe failed\n"); |
| 94 | goto err; |
| 95 | } |
| 96 | |
| 97 | io_uring_prep_fsync(sqe, fd, IORING_FSYNC_DATASYNC); |
| 98 | sqe->user_data = 1; |
| 99 | io_uring_sqe_set_flags(sqe, IOSQE_IO_DRAIN); |
| 100 | |
| 101 | ret = io_uring_submit(ring); |
| 102 | if (ret < 0) { |
| 103 | fprintf(stderr, "sqe submit failed: %d\n", ret); |
| 104 | goto err; |
| 105 | } else if (ret < 5) { |
| 106 | fprintf(stderr, "Submitted only %d\n", ret); |
| 107 | goto err; |
| 108 | } |
| 109 | |
| 110 | for (i = 0; i < 5; i++) { |
| 111 | ret = io_uring_wait_cqe(ring, &cqe); |
| 112 | if (ret < 0) { |
| 113 | fprintf(stderr, "wait completion %d\n", ret); |
| 114 | goto err; |
| 115 | } |
no test coverage detected