| 295 | } |
| 296 | |
| 297 | static int test_rdonly(struct io_uring *ring, int op) |
| 298 | { |
| 299 | int ret, fd; |
| 300 | int ro; |
| 301 | |
| 302 | if (!opcodes[op].test) |
| 303 | return T_EXIT_SKIP; |
| 304 | |
| 305 | fd = open(filename, O_DIRECT | O_RDONLY | O_EXCL); |
| 306 | if (fd < 0) { |
| 307 | if (errno == EINVAL || errno == EBUSY) |
| 308 | return T_EXIT_SKIP; |
| 309 | fprintf(stderr, "open failed %i\n", errno); |
| 310 | return T_EXIT_FAIL; |
| 311 | } |
| 312 | |
| 313 | ret = queue_discard_lba(ring, fd, 0, 1); |
| 314 | if (ret >= 0) { |
| 315 | fprintf(stderr, "discarded with O_RDONLY %i\n", ret); |
| 316 | return 1; |
| 317 | } |
| 318 | close(fd); |
| 319 | |
| 320 | fd = open(filename, O_DIRECT | O_RDWR | O_EXCL); |
| 321 | if (fd < 0) { |
| 322 | if (errno == EINVAL || errno == EBUSY) |
| 323 | return T_EXIT_SKIP; |
| 324 | fprintf(stderr, "open failed %i\n", errno); |
| 325 | return T_EXIT_FAIL; |
| 326 | } |
| 327 | |
| 328 | ro = 1; |
| 329 | ret = ioctl(fd, BLKROSET, &ro); |
| 330 | if (ret) { |
| 331 | fprintf(stderr, "BLKROSET 1 failed %i\n", errno); |
| 332 | return T_EXIT_FAIL; |
| 333 | } |
| 334 | |
| 335 | ret = queue_discard_lba(ring, fd, 0, 1); |
| 336 | if (ret >= 0) { |
| 337 | fprintf(stderr, "discarded with O_RDONLY %i\n", ret); |
| 338 | return 1; |
| 339 | } |
| 340 | |
| 341 | ro = 0; |
| 342 | ret = ioctl(fd, BLKROSET, &ro); |
| 343 | if (ret) { |
| 344 | fprintf(stderr, "BLKROSET 0 failed %i\n", errno); |
| 345 | return T_EXIT_FAIL; |
| 346 | } |
| 347 | close(fd); |
| 348 | return 0; |
| 349 | } |
| 350 | |
| 351 | int main(int argc, char *argv[]) |
| 352 | { |
no test coverage detected