• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Description: Test that out-of-order file updates with inflight requests
4  *		work as expected.
5  *
6  */
7 #include <stdio.h>
8 #include <fcntl.h>
9 #include <sys/socket.h>
10 #include <unistd.h>
11 #include <stdlib.h>
12 #include <poll.h>
13 
14 #include "liburing.h"
15 #include "helpers.h"
16 
main(int argc,char * argv[])17 int main(int argc, char *argv[])
18 {
19 	struct io_uring_sqe *sqe;
20 	int res, fds[2], sockid;
21 	struct io_uring ring;
22 
23 	if (argc > 1)
24 		return T_EXIT_SKIP;
25 
26 	res = io_uring_queue_init(1, &ring, 0);
27 	if (res) {
28 		fprintf(stderr, "queue_init: %d\n", res);
29 		return T_EXIT_FAIL;
30 	}
31 
32 	res = io_uring_register_files_sparse(&ring, 2);
33 	if (res) {
34 		if (res == -EINVAL)
35 			return T_EXIT_SKIP;
36 		fprintf(stderr, "sparse reg: %d\n", res);
37 		return T_EXIT_FAIL;
38 	}
39 
40 	fds[0] = socket(AF_INET, SOCK_DGRAM, 0);
41 	if (fds[0] < 0) {
42 		perror("socket");
43 		return T_EXIT_FAIL;
44 	}
45 	fds[1] = socket(AF_INET, SOCK_DGRAM, 0);
46 	if (fds[1] < 0) {
47 		perror("socket");
48 		return T_EXIT_FAIL;
49 	}
50 
51 	res = io_uring_register_files_update(&ring, 0, fds, 2);
52 	if (res != 2) {
53 		fprintf(stderr, "files updates; %d\n", res);
54 		return T_EXIT_FAIL;
55 	}
56 
57 	sqe = io_uring_get_sqe(&ring);
58 	io_uring_prep_poll_add(sqe, 0, POLLIN);
59 	sqe->flags = IOSQE_FIXED_FILE;
60 	io_uring_submit(&ring);
61 
62 	close(fds[0]);
63 	close(fds[1]);
64 
65 	sockid = -1;
66 	res = io_uring_register_files_update(&ring, 1, &sockid, 1);
67 	if (res != 1) {
68 		fprintf(stderr, "files updates; %d\n", res);
69 		return T_EXIT_FAIL;
70 	}
71 
72 	sockid = -1;
73 	res = io_uring_register_files_update(&ring, 0, &sockid, 1);
74 	if (res != 1) {
75 		fprintf(stderr, "files updates; %d\n", res);
76 		return T_EXIT_FAIL;
77 	}
78 
79 	sleep(1);
80 	io_uring_queue_exit(&ring);
81 	return T_EXIT_PASS;
82 }
83