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