500f9fbadef8.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #include "../config-host.h"
  2. /* SPDX-License-Identifier: MIT */
  3. /*
  4. * Description: Single depth submit+wait poll hang test
  5. *
  6. */
  7. #include <errno.h>
  8. #include <stdio.h>
  9. #include <unistd.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <fcntl.h>
  13. #include "helpers.h"
  14. #include "liburing.h"
  15. #define BLOCKS 4096
  16. int main(int argc, char *argv[])
  17. {
  18. struct io_uring ring;
  19. struct io_uring_sqe *sqe;
  20. struct io_uring_cqe *cqe;
  21. struct iovec iov;
  22. char buf[32];
  23. off_t offset;
  24. unsigned blocks;
  25. int ret, fd;
  26. if (argc > 1)
  27. return T_EXIT_SKIP;
  28. t_posix_memalign(&iov.iov_base, 4096, 4096);
  29. iov.iov_len = 4096;
  30. ret = io_uring_queue_init(1, &ring, IORING_SETUP_IOPOLL);
  31. if (ret) {
  32. fprintf(stderr, "ring setup failed\n");
  33. return T_EXIT_FAIL;
  34. }
  35. sprintf(buf, "./XXXXXX");
  36. fd = mkostemp(buf, O_WRONLY | O_DIRECT | O_CREAT);
  37. if (fd < 0) {
  38. if (errno == EINVAL)
  39. return T_EXIT_SKIP;
  40. perror("mkostemp");
  41. return T_EXIT_FAIL;
  42. }
  43. offset = 0;
  44. blocks = BLOCKS;
  45. do {
  46. sqe = io_uring_get_sqe(&ring);
  47. if (!sqe) {
  48. fprintf(stderr, "get sqe failed\n");
  49. goto err;
  50. }
  51. io_uring_prep_writev(sqe, fd, &iov, 1, offset);
  52. ret = io_uring_submit_and_wait(&ring, 1);
  53. if (ret < 0) {
  54. fprintf(stderr, "submit_and_wait: %d\n", ret);
  55. goto err;
  56. }
  57. ret = io_uring_wait_cqe(&ring, &cqe);
  58. if (ret < 0) {
  59. fprintf(stderr, "wait completion: %d\n", ret);
  60. goto err;
  61. }
  62. if (cqe->res != 4096) {
  63. if (cqe->res == -EOPNOTSUPP)
  64. goto skipped;
  65. goto err;
  66. }
  67. io_uring_cqe_seen(&ring, cqe);
  68. offset += 4096;
  69. } while (--blocks);
  70. close(fd);
  71. unlink(buf);
  72. return T_EXIT_PASS;
  73. err:
  74. close(fd);
  75. unlink(buf);
  76. return T_EXIT_FAIL;
  77. skipped:
  78. fprintf(stderr, "Polling not supported in current dir, test skipped\n");
  79. close(fd);
  80. unlink(buf);
  81. return T_EXIT_SKIP;
  82. }