• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Description: test wq sharing
4  */
5 #include <errno.h>
6 #include <stdio.h>
7 #include <unistd.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <fcntl.h>
11 
12 #include "liburing.h"
13 
test_attach_invalid(int ringfd)14 static int test_attach_invalid(int ringfd)
15 {
16 	struct io_uring_params p;
17 	struct io_uring ring;
18 	int ret;
19 
20 	memset(&p, 0, sizeof(p));
21 	p.flags = IORING_SETUP_ATTACH_WQ;
22 	p.wq_fd = ringfd;
23 	ret = io_uring_queue_init_params(1, &ring, &p);
24 	if (ret != -EINVAL) {
25 		fprintf(stderr, "Attach to zero: %d\n", ret);
26 		goto err;
27 	}
28 	return 0;
29 err:
30 	return 1;
31 }
32 
test_attach(int ringfd)33 static int test_attach(int ringfd)
34 {
35 	struct io_uring_params p;
36 	struct io_uring ring2;
37 	int ret;
38 
39 	memset(&p, 0, sizeof(p));
40 	p.flags = IORING_SETUP_ATTACH_WQ;
41 	p.wq_fd = ringfd;
42 	ret = io_uring_queue_init_params(1, &ring2, &p);
43 	if (ret == -EINVAL) {
44 		fprintf(stdout, "Sharing not supported, skipping\n");
45 		return 0;
46 	} else if (ret) {
47 		fprintf(stderr, "Attach to id: %d\n", ret);
48 		goto err;
49 	}
50 	io_uring_queue_exit(&ring2);
51 	return 0;
52 err:
53 	return 1;
54 }
55 
main(int argc,char * argv[])56 int main(int argc, char *argv[])
57 {
58 	struct io_uring ring;
59 	int ret;
60 
61 	if (argc > 1)
62 		return 0;
63 
64 	ret = io_uring_queue_init(8, &ring, 0);
65 	if (ret) {
66 		fprintf(stderr, "ring setup failed\n");
67 		return 1;
68 	}
69 
70 	/* stdout is definitely not an io_uring descriptor */
71 	ret = test_attach_invalid(2);
72 	if (ret) {
73 		fprintf(stderr, "test_attach_invalid failed\n");
74 		return ret;
75 	}
76 
77 	ret = test_attach(ring.ring_fd);
78 	if (ret) {
79 		fprintf(stderr, "test_attach failed\n");
80 		return ret;
81 	}
82 
83 	return 0;
84 }
85