| 97 | } |
| 98 | |
| 99 | int main(int argc, char *argv[]) |
| 100 | { |
| 101 | struct io_uring ring; |
| 102 | const char *fname; |
| 103 | char buf[256]; |
| 104 | int fd, rnd_fd, ret, bs = 512; |
| 105 | |
| 106 | if (argc > 1) { |
| 107 | fname = argv[1]; |
| 108 | } else { |
| 109 | srand((unsigned)time(NULL)); |
| 110 | snprintf(buf, sizeof(buf), ".fixed-seg-%u-%u", (unsigned) rand(), |
| 111 | (unsigned)getpid()); |
| 112 | fname = buf; |
| 113 | t_create_file(fname, 128*1024); |
| 114 | } |
| 115 | |
| 116 | fd = open(fname, O_RDWR | O_DIRECT | O_EXCL); |
| 117 | if (fd < 0) { |
| 118 | perror("open"); |
| 119 | return 1; |
| 120 | } |
| 121 | ret = is_bdev(fd); |
| 122 | if (fd < 0) |
| 123 | return 1; |
| 124 | if (ret && ioctl(fd, BLKSSZGET, &bs) < 0) { |
| 125 | perror("ioctl BLKSSZGET,"); |
| 126 | return 1; |
| 127 | } |
| 128 | |
| 129 | rnd_fd = open("/dev/urandom", O_RDONLY); |
| 130 | if (fd < 0) { |
| 131 | perror("urandom: open"); |
| 132 | goto err; |
| 133 | } |
| 134 | |
| 135 | if (posix_memalign(&wvec.iov_base, 4096, 512*1024)) |
| 136 | goto err; |
| 137 | wvec.iov_len = 512*1024; |
| 138 | |
| 139 | ret = read(rnd_fd, wvec.iov_base, wvec.iov_len); |
| 140 | if (ret != wvec.iov_len) { |
| 141 | fprintf(stderr, "Precondition, urandom read failed, ret: %d\n", ret); |
| 142 | goto err; |
| 143 | } |
| 144 | |
| 145 | ret = write(fd, wvec.iov_base, wvec.iov_len); |
| 146 | if (ret != wvec.iov_len) { |
| 147 | fprintf(stderr, "Precondition, write failed, ret: %d\n", ret); |
| 148 | goto err; |
| 149 | } |
| 150 | |
| 151 | if (posix_memalign(&rvec.iov_base, 4096, 512*1024)) |
| 152 | goto err; |
| 153 | rvec.iov_len = 512*1024; |
| 154 | |
| 155 | ret = io_uring_queue_init(8, &ring, 0); |
| 156 | if (ret) { |
nothing calls this directly
no test coverage detected