reg-hint.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "../config-host.h"
  2. /* SPDX-License-Identifier: MIT */
  3. /*
  4. * Test alloc hint sanity after unregistering the file table
  5. */
  6. #include <stdio.h>
  7. #include <unistd.h>
  8. #include <sys/socket.h>
  9. #include "liburing.h"
  10. #include "helpers.h"
  11. int main(int argc, char *argv[])
  12. {
  13. struct io_uring_sqe *sqe;
  14. struct io_uring_cqe *cqe;
  15. struct io_uring ring;
  16. int ret;
  17. if (argc > 1)
  18. return T_EXIT_SKIP;
  19. io_uring_queue_init(1, &ring, 0);
  20. ret = io_uring_register_files_sparse(&ring, 16);
  21. if (ret) {
  22. if (ret == -EINVAL)
  23. return T_EXIT_SKIP;
  24. fprintf(stderr, "Failed to register file table: %d\n", ret);
  25. return T_EXIT_FAIL;
  26. }
  27. io_uring_unregister_files(&ring);
  28. sqe = io_uring_get_sqe(&ring);
  29. io_uring_prep_socket_direct_alloc(sqe, AF_UNIX, SOCK_DGRAM, 0, 0);
  30. ret = io_uring_submit(&ring);
  31. if (ret != 1) {
  32. fprintf(stderr, "submit %d\n", ret);
  33. return T_EXIT_FAIL;
  34. }
  35. ret = io_uring_wait_cqe(&ring, &cqe);
  36. if (ret) {
  37. fprintf(stderr, "wait cqe: %d\n", ret);
  38. return T_EXIT_FAIL;
  39. }
  40. if (cqe->res != -ENFILE) {
  41. fprintf(stderr, "Bad CQE res: %d\n", cqe->res);
  42. return T_EXIT_FAIL;
  43. }
  44. io_uring_cqe_seen(&ring, cqe);
  45. return T_EXIT_PASS;
  46. }