Commit | Line | Data |
---|---|---|
ed92ac0c | 1 | /* |
da751ca9 JA |
2 | * net engine |
3 | * | |
4 | * IO engine that reads/writes to/from sockets. | |
5 | * | |
ed92ac0c JA |
6 | */ |
7 | #include <stdio.h> | |
8 | #include <stdlib.h> | |
9 | #include <unistd.h> | |
842805f5 | 10 | #include <signal.h> |
ed92ac0c | 11 | #include <errno.h> |
ed92ac0c | 12 | #include <netinet/in.h> |
70a7878c | 13 | #include <netinet/tcp.h> |
ed92ac0c JA |
14 | #include <arpa/inet.h> |
15 | #include <netdb.h> | |
8393ca93 | 16 | #include <poll.h> |
0fd666bf | 17 | #include <sys/stat.h> |
7292056a | 18 | #include <sys/socket.h> |
0fd666bf | 19 | #include <sys/un.h> |
ed92ac0c | 20 | |
80cc242a MP |
21 | #ifdef CONFIG_VSOCK |
22 | #include <linux/vm_sockets.h> | |
23 | #else | |
24 | struct sockaddr_vm { | |
25 | }; | |
26 | #ifndef AF_VSOCK | |
27 | #define AF_VSOCK -1 | |
28 | #endif | |
29 | #endif | |
30 | ||
ed92ac0c | 31 | #include "../fio.h" |
e9ad9637 | 32 | #include "../verify.h" |
d220c761 | 33 | #include "../optgroup.h" |
ed92ac0c | 34 | |
b5af8293 JA |
35 | struct netio_data { |
36 | int listenfd; | |
9cce02e8 | 37 | int use_splice; |
71f9b933 | 38 | int seq_off; |
9cce02e8 | 39 | int pipes[2]; |
b5af8293 | 40 | struct sockaddr_in addr; |
49ccb8c1 | 41 | struct sockaddr_in6 addr6; |
0fd666bf | 42 | struct sockaddr_un addr_un; |
80cc242a | 43 | struct sockaddr_vm addr_vm; |
e9ad9637 JA |
44 | uint64_t udp_send_seq; |
45 | uint64_t udp_recv_seq; | |
b5af8293 | 46 | }; |
ed92ac0c | 47 | |
de890a1e SL |
48 | struct netio_options { |
49 | struct thread_data *td; | |
50 | unsigned int port; | |
51 | unsigned int proto; | |
52 | unsigned int listen; | |
6f73a7f8 | 53 | unsigned int pingpong; |
70a7878c | 54 | unsigned int nodelay; |
d3a623de | 55 | unsigned int ttl; |
1008602c | 56 | unsigned int window_size; |
e5f34d95 | 57 | unsigned int mss; |
f16b7405 | 58 | char *intfc; |
de890a1e SL |
59 | }; |
60 | ||
664fb3bd JA |
61 | struct udp_close_msg { |
62 | uint32_t magic; | |
63 | uint32_t cmd; | |
64 | }; | |
65 | ||
e9ad9637 JA |
66 | struct udp_seq { |
67 | uint64_t magic; | |
68 | uint64_t seq; | |
71f9b933 | 69 | uint64_t bs; |
e9ad9637 JA |
70 | }; |
71 | ||
664fb3bd JA |
72 | enum { |
73 | FIO_LINK_CLOSE = 0x89, | |
b96d2430 JA |
74 | FIO_LINK_OPEN_CLOSE_MAGIC = 0x6c696e6b, |
75 | FIO_LINK_OPEN = 0x98, | |
e9ad9637 | 76 | FIO_UDP_SEQ_MAGIC = 0x657375716e556563ULL, |
0fd666bf JA |
77 | |
78 | FIO_TYPE_TCP = 1, | |
79 | FIO_TYPE_UDP = 2, | |
80 | FIO_TYPE_UNIX = 3, | |
49ccb8c1 JA |
81 | FIO_TYPE_TCP_V6 = 4, |
82 | FIO_TYPE_UDP_V6 = 5, | |
80cc242a | 83 | FIO_TYPE_VSOCK_STREAM = 6, |
664fb3bd JA |
84 | }; |
85 | ||
de890a1e SL |
86 | static int str_hostname_cb(void *data, const char *input); |
87 | static struct fio_option options[] = { | |
88 | { | |
89 | .name = "hostname", | |
e8b0e958 | 90 | .lname = "net engine hostname", |
de890a1e SL |
91 | .type = FIO_OPT_STR_STORE, |
92 | .cb = str_hostname_cb, | |
93 | .help = "Hostname for net IO engine", | |
e90a0adf JA |
94 | .category = FIO_OPT_C_ENGINE, |
95 | .group = FIO_OPT_G_NETIO, | |
de890a1e SL |
96 | }, |
97 | { | |
98 | .name = "port", | |
e8b0e958 | 99 | .lname = "net engine port", |
de890a1e SL |
100 | .type = FIO_OPT_INT, |
101 | .off1 = offsetof(struct netio_options, port), | |
102 | .minval = 1, | |
103 | .maxval = 65535, | |
104 | .help = "Port to use for TCP or UDP net connections", | |
e90a0adf JA |
105 | .category = FIO_OPT_C_ENGINE, |
106 | .group = FIO_OPT_G_NETIO, | |
de890a1e SL |
107 | }, |
108 | { | |
109 | .name = "protocol", | |
e8b0e958 | 110 | .lname = "net engine protocol", |
de890a1e SL |
111 | .alias = "proto", |
112 | .type = FIO_OPT_STR, | |
113 | .off1 = offsetof(struct netio_options, proto), | |
114 | .help = "Network protocol to use", | |
115 | .def = "tcp", | |
116 | .posval = { | |
117 | { .ival = "tcp", | |
118 | .oval = FIO_TYPE_TCP, | |
119 | .help = "Transmission Control Protocol", | |
120 | }, | |
eb232310 | 121 | #ifdef CONFIG_IPV6 |
49ccb8c1 JA |
122 | { .ival = "tcpv6", |
123 | .oval = FIO_TYPE_TCP_V6, | |
124 | .help = "Transmission Control Protocol V6", | |
125 | }, | |
eb232310 | 126 | #endif |
de890a1e SL |
127 | { .ival = "udp", |
128 | .oval = FIO_TYPE_UDP, | |
f5cc3d0e | 129 | .help = "User Datagram Protocol", |
de890a1e | 130 | }, |
eb232310 | 131 | #ifdef CONFIG_IPV6 |
49ccb8c1 JA |
132 | { .ival = "udpv6", |
133 | .oval = FIO_TYPE_UDP_V6, | |
134 | .help = "User Datagram Protocol V6", | |
135 | }, | |
eb232310 | 136 | #endif |
de890a1e SL |
137 | { .ival = "unix", |
138 | .oval = FIO_TYPE_UNIX, | |
139 | .help = "UNIX domain socket", | |
140 | }, | |
80cc242a MP |
141 | { .ival = "vsock", |
142 | .oval = FIO_TYPE_VSOCK_STREAM, | |
143 | .help = "Virtual socket", | |
144 | }, | |
de890a1e | 145 | }, |
e90a0adf JA |
146 | .category = FIO_OPT_C_ENGINE, |
147 | .group = FIO_OPT_G_NETIO, | |
de890a1e | 148 | }, |
1eafa37a | 149 | #ifdef CONFIG_TCP_NODELAY |
70a7878c SN |
150 | { |
151 | .name = "nodelay", | |
dda13f44 | 152 | .lname = "No Delay", |
70a7878c SN |
153 | .type = FIO_OPT_BOOL, |
154 | .off1 = offsetof(struct netio_options, nodelay), | |
155 | .help = "Use TCP_NODELAY on TCP connections", | |
e90a0adf JA |
156 | .category = FIO_OPT_C_ENGINE, |
157 | .group = FIO_OPT_G_NETIO, | |
70a7878c | 158 | }, |
1eafa37a | 159 | #endif |
de890a1e SL |
160 | { |
161 | .name = "listen", | |
e8b0e958 | 162 | .lname = "net engine listen", |
de890a1e SL |
163 | .type = FIO_OPT_STR_SET, |
164 | .off1 = offsetof(struct netio_options, listen), | |
165 | .help = "Listen for incoming TCP connections", | |
e90a0adf JA |
166 | .category = FIO_OPT_C_ENGINE, |
167 | .group = FIO_OPT_G_NETIO, | |
de890a1e | 168 | }, |
6f73a7f8 JA |
169 | { |
170 | .name = "pingpong", | |
dda13f44 | 171 | .lname = "Ping Pong", |
6f73a7f8 JA |
172 | .type = FIO_OPT_STR_SET, |
173 | .off1 = offsetof(struct netio_options, pingpong), | |
174 | .help = "Ping-pong IO requests", | |
e90a0adf JA |
175 | .category = FIO_OPT_C_ENGINE, |
176 | .group = FIO_OPT_G_NETIO, | |
6f73a7f8 | 177 | }, |
b93b6a2e SB |
178 | { |
179 | .name = "interface", | |
180 | .lname = "net engine interface", | |
181 | .type = FIO_OPT_STR_STORE, | |
f16b7405 | 182 | .off1 = offsetof(struct netio_options, intfc), |
b93b6a2e SB |
183 | .help = "Network interface to use", |
184 | .category = FIO_OPT_C_ENGINE, | |
185 | .group = FIO_OPT_G_NETIO, | |
186 | }, | |
d3a623de SB |
187 | { |
188 | .name = "ttl", | |
189 | .lname = "net engine multicast ttl", | |
190 | .type = FIO_OPT_INT, | |
191 | .off1 = offsetof(struct netio_options, ttl), | |
192 | .def = "1", | |
193 | .minval = 0, | |
194 | .help = "Time-to-live value for outgoing UDP multicast packets", | |
195 | .category = FIO_OPT_C_ENGINE, | |
196 | .group = FIO_OPT_G_NETIO, | |
197 | }, | |
1008602c JA |
198 | #ifdef CONFIG_NET_WINDOWSIZE |
199 | { | |
200 | .name = "window_size", | |
201 | .lname = "Window Size", | |
202 | .type = FIO_OPT_INT, | |
203 | .off1 = offsetof(struct netio_options, window_size), | |
204 | .minval = 0, | |
205 | .help = "Set socket buffer window size", | |
206 | .category = FIO_OPT_C_ENGINE, | |
207 | .group = FIO_OPT_G_NETIO, | |
208 | }, | |
e5f34d95 JA |
209 | #endif |
210 | #ifdef CONFIG_NET_MSS | |
211 | { | |
212 | .name = "mss", | |
213 | .lname = "Maximum segment size", | |
214 | .type = FIO_OPT_INT, | |
215 | .off1 = offsetof(struct netio_options, mss), | |
216 | .minval = 0, | |
217 | .help = "Set TCP maximum segment size", | |
218 | .category = FIO_OPT_C_ENGINE, | |
219 | .group = FIO_OPT_G_NETIO, | |
220 | }, | |
1008602c | 221 | #endif |
de890a1e SL |
222 | { |
223 | .name = NULL, | |
224 | }, | |
225 | }; | |
226 | ||
49ccb8c1 JA |
227 | static inline int is_udp(struct netio_options *o) |
228 | { | |
229 | return o->proto == FIO_TYPE_UDP || o->proto == FIO_TYPE_UDP_V6; | |
230 | } | |
231 | ||
232 | static inline int is_tcp(struct netio_options *o) | |
233 | { | |
234 | return o->proto == FIO_TYPE_TCP || o->proto == FIO_TYPE_TCP_V6; | |
235 | } | |
236 | ||
237 | static inline int is_ipv6(struct netio_options *o) | |
238 | { | |
239 | return o->proto == FIO_TYPE_UDP_V6 || o->proto == FIO_TYPE_TCP_V6; | |
240 | } | |
241 | ||
80cc242a MP |
242 | static inline int is_vsock(struct netio_options *o) |
243 | { | |
244 | return o->proto == FIO_TYPE_VSOCK_STREAM; | |
245 | } | |
246 | ||
1008602c JA |
247 | static int set_window_size(struct thread_data *td, int fd) |
248 | { | |
249 | #ifdef CONFIG_NET_WINDOWSIZE | |
250 | struct netio_options *o = td->eo; | |
251 | unsigned int wss; | |
252 | int snd, rcv, ret; | |
253 | ||
254 | if (!o->window_size) | |
255 | return 0; | |
256 | ||
257 | rcv = o->listen || o->pingpong; | |
258 | snd = !o->listen || o->pingpong; | |
259 | wss = o->window_size; | |
260 | ret = 0; | |
261 | ||
262 | if (rcv) { | |
263 | ret = setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (void *) &wss, | |
264 | sizeof(wss)); | |
265 | if (ret < 0) | |
266 | td_verror(td, errno, "rcvbuf window size"); | |
267 | } | |
268 | if (snd && !ret) { | |
269 | ret = setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (void *) &wss, | |
270 | sizeof(wss)); | |
271 | if (ret < 0) | |
272 | td_verror(td, errno, "sndbuf window size"); | |
273 | } | |
274 | ||
275 | return ret; | |
276 | #else | |
277 | td_verror(td, -EINVAL, "setsockopt window size"); | |
278 | return -1; | |
279 | #endif | |
280 | } | |
281 | ||
e5f34d95 JA |
282 | static int set_mss(struct thread_data *td, int fd) |
283 | { | |
284 | #ifdef CONFIG_NET_MSS | |
285 | struct netio_options *o = td->eo; | |
286 | unsigned int mss; | |
287 | int ret; | |
288 | ||
289 | if (!o->mss || !is_tcp(o)) | |
290 | return 0; | |
291 | ||
292 | mss = o->mss; | |
293 | ret = setsockopt(fd, IPPROTO_TCP, TCP_MAXSEG, (void *) &mss, | |
294 | sizeof(mss)); | |
295 | if (ret < 0) | |
296 | td_verror(td, errno, "setsockopt TCP_MAXSEG"); | |
297 | ||
298 | return ret; | |
299 | #else | |
300 | td_verror(td, -EINVAL, "setsockopt TCP_MAXSEG"); | |
301 | return -1; | |
302 | #endif | |
303 | } | |
304 | ||
305 | ||
371d456c JA |
306 | /* |
307 | * Return -1 for error and 'nr events' for a positive number | |
308 | * of events | |
309 | */ | |
310 | static int poll_wait(struct thread_data *td, int fd, short events) | |
311 | { | |
312 | struct pollfd pfd; | |
313 | int ret; | |
314 | ||
315 | while (!td->terminate) { | |
316 | pfd.fd = fd; | |
317 | pfd.events = events; | |
318 | ret = poll(&pfd, 1, -1); | |
319 | if (ret < 0) { | |
320 | if (errno == EINTR) | |
d5b388a5 | 321 | break; |
371d456c JA |
322 | |
323 | td_verror(td, errno, "poll"); | |
324 | return -1; | |
325 | } else if (!ret) | |
326 | continue; | |
327 | ||
328 | break; | |
329 | } | |
330 | ||
331 | if (pfd.revents & events) | |
332 | return 1; | |
371d456c JA |
333 | |
334 | return -1; | |
335 | } | |
336 | ||
b511c9aa SB |
337 | static int fio_netio_is_multicast(const char *mcaddr) |
338 | { | |
339 | in_addr_t addr = inet_network(mcaddr); | |
340 | if (addr == -1) | |
341 | return 0; | |
342 | ||
343 | if (inet_network("224.0.0.0") <= addr && | |
344 | inet_network("239.255.255.255") >= addr) | |
345 | return 1; | |
346 | ||
347 | return 0; | |
348 | } | |
349 | ||
350 | ||
ed92ac0c JA |
351 | static int fio_netio_prep(struct thread_data *td, struct io_u *io_u) |
352 | { | |
de890a1e | 353 | struct netio_options *o = td->eo; |
ed92ac0c | 354 | |
7a6499da JA |
355 | /* |
356 | * Make sure we don't see spurious reads to a receiver, and vice versa | |
357 | */ | |
49ccb8c1 | 358 | if (is_tcp(o)) |
de890a1e SL |
359 | return 0; |
360 | ||
361 | if ((o->listen && io_u->ddir == DDIR_WRITE) || | |
362 | (!o->listen && io_u->ddir == DDIR_READ)) { | |
e1161c32 | 363 | td_verror(td, EINVAL, "bad direction"); |
7a6499da | 364 | return 1; |
ed92ac0c | 365 | } |
3f457bea | 366 | |
f85ac25a | 367 | return 0; |
ed92ac0c JA |
368 | } |
369 | ||
67bf9823 | 370 | #ifdef CONFIG_LINUX_SPLICE |
cd963e18 | 371 | static int splice_io_u(int fdin, int fdout, unsigned int len) |
ed92ac0c | 372 | { |
9cce02e8 | 373 | int bytes = 0; |
7a6499da | 374 | |
9cce02e8 | 375 | while (len) { |
cd963e18 | 376 | int ret = splice(fdin, NULL, fdout, NULL, len, 0); |
9cce02e8 JA |
377 | |
378 | if (ret < 0) { | |
379 | if (!bytes) | |
380 | bytes = ret; | |
381 | ||
382 | break; | |
383 | } else if (!ret) | |
384 | break; | |
385 | ||
386 | bytes += ret; | |
f657a2fb | 387 | len -= ret; |
9cce02e8 JA |
388 | } |
389 | ||
390 | return bytes; | |
391 | } | |
392 | ||
393 | /* | |
cd963e18 | 394 | * Receive bytes from a socket and fill them into the internal pipe |
9cce02e8 | 395 | */ |
cd963e18 | 396 | static int splice_in(struct thread_data *td, struct io_u *io_u) |
9cce02e8 | 397 | { |
565e784d | 398 | struct netio_data *nd = td->io_ops_data; |
9cce02e8 | 399 | |
cd963e18 | 400 | return splice_io_u(io_u->file->fd, nd->pipes[1], io_u->xfer_buflen); |
9cce02e8 JA |
401 | } |
402 | ||
403 | /* | |
cd963e18 | 404 | * Transmit 'len' bytes from the internal pipe |
9cce02e8 | 405 | */ |
cd963e18 JA |
406 | static int splice_out(struct thread_data *td, struct io_u *io_u, |
407 | unsigned int len) | |
9cce02e8 | 408 | { |
565e784d | 409 | struct netio_data *nd = td->io_ops_data; |
cd963e18 JA |
410 | |
411 | return splice_io_u(nd->pipes[0], io_u->file->fd, len); | |
412 | } | |
413 | ||
414 | static int vmsplice_io_u(struct io_u *io_u, int fd, unsigned int len) | |
415 | { | |
9cce02e8 JA |
416 | struct iovec iov = { |
417 | .iov_base = io_u->xfer_buf, | |
418 | .iov_len = len, | |
419 | }; | |
420 | int bytes = 0; | |
421 | ||
422 | while (iov.iov_len) { | |
cd963e18 | 423 | int ret = vmsplice(fd, &iov, 1, SPLICE_F_MOVE); |
9cce02e8 JA |
424 | |
425 | if (ret < 0) { | |
426 | if (!bytes) | |
427 | bytes = ret; | |
428 | break; | |
429 | } else if (!ret) | |
430 | break; | |
431 | ||
432 | iov.iov_len -= ret; | |
cd963e18 | 433 | iov.iov_base += ret; |
f657a2fb | 434 | bytes += ret; |
9cce02e8 JA |
435 | } |
436 | ||
437 | return bytes; | |
cd963e18 | 438 | |
9cce02e8 JA |
439 | } |
440 | ||
441 | /* | |
cd963e18 | 442 | * vmsplice() pipe to io_u buffer |
9cce02e8 | 443 | */ |
cd963e18 JA |
444 | static int vmsplice_io_u_out(struct thread_data *td, struct io_u *io_u, |
445 | unsigned int len) | |
9cce02e8 | 446 | { |
565e784d | 447 | struct netio_data *nd = td->io_ops_data; |
9cce02e8 | 448 | |
cd963e18 JA |
449 | return vmsplice_io_u(io_u, nd->pipes[0], len); |
450 | } | |
9cce02e8 | 451 | |
cd963e18 JA |
452 | /* |
453 | * vmsplice() io_u to pipe | |
454 | */ | |
455 | static int vmsplice_io_u_in(struct thread_data *td, struct io_u *io_u) | |
456 | { | |
565e784d | 457 | struct netio_data *nd = td->io_ops_data; |
ed92ac0c | 458 | |
cd963e18 | 459 | return vmsplice_io_u(io_u, nd->pipes[1], io_u->xfer_buflen); |
9cce02e8 JA |
460 | } |
461 | ||
cd963e18 JA |
462 | /* |
463 | * splice receive - transfer socket data into a pipe using splice, then map | |
464 | * that pipe data into the io_u using vmsplice. | |
465 | */ | |
9cce02e8 JA |
466 | static int fio_netio_splice_in(struct thread_data *td, struct io_u *io_u) |
467 | { | |
468 | int ret; | |
469 | ||
470 | ret = splice_in(td, io_u); | |
cd963e18 JA |
471 | if (ret > 0) |
472 | return vmsplice_io_u_out(td, io_u, ret); | |
9cce02e8 | 473 | |
cd963e18 | 474 | return ret; |
9cce02e8 JA |
475 | } |
476 | ||
cd963e18 JA |
477 | /* |
478 | * splice transmit - map data from the io_u into a pipe by using vmsplice, | |
479 | * then transfer that pipe to a socket using splice. | |
480 | */ | |
9cce02e8 JA |
481 | static int fio_netio_splice_out(struct thread_data *td, struct io_u *io_u) |
482 | { | |
483 | int ret; | |
484 | ||
485 | ret = vmsplice_io_u_in(td, io_u); | |
cd963e18 JA |
486 | if (ret > 0) |
487 | return splice_out(td, io_u, ret); | |
9cce02e8 | 488 | |
cd963e18 | 489 | return ret; |
9cce02e8 | 490 | } |
5921e80c JA |
491 | #else |
492 | static int fio_netio_splice_in(struct thread_data *td, struct io_u *io_u) | |
493 | { | |
af8771b9 | 494 | errno = EOPNOTSUPP; |
5921e80c JA |
495 | return -1; |
496 | } | |
497 | ||
498 | static int fio_netio_splice_out(struct thread_data *td, struct io_u *io_u) | |
499 | { | |
af8771b9 | 500 | errno = EOPNOTSUPP; |
5921e80c JA |
501 | return -1; |
502 | } | |
503 | #endif | |
9cce02e8 | 504 | |
e9ad9637 JA |
505 | static void store_udp_seq(struct netio_data *nd, struct io_u *io_u) |
506 | { | |
507 | struct udp_seq *us; | |
508 | ||
ae703cdf SN |
509 | if (io_u->xfer_buflen < sizeof(*us)) |
510 | return; | |
511 | ||
e9ad9637 | 512 | us = io_u->xfer_buf + io_u->xfer_buflen - sizeof(*us); |
e341a7f0 | 513 | us->magic = cpu_to_le64((uint64_t) FIO_UDP_SEQ_MAGIC); |
71f9b933 | 514 | us->bs = cpu_to_le64((uint64_t) io_u->xfer_buflen); |
e9ad9637 JA |
515 | us->seq = cpu_to_le64(nd->udp_send_seq++); |
516 | } | |
517 | ||
3bcb9d94 JA |
518 | static void verify_udp_seq(struct thread_data *td, struct netio_data *nd, |
519 | struct io_u *io_u) | |
e9ad9637 JA |
520 | { |
521 | struct udp_seq *us; | |
522 | uint64_t seq; | |
523 | ||
ae703cdf SN |
524 | if (io_u->xfer_buflen < sizeof(*us)) |
525 | return; | |
526 | ||
71f9b933 JA |
527 | if (nd->seq_off) |
528 | return; | |
529 | ||
e9ad9637 JA |
530 | us = io_u->xfer_buf + io_u->xfer_buflen - sizeof(*us); |
531 | if (le64_to_cpu(us->magic) != FIO_UDP_SEQ_MAGIC) | |
532 | return; | |
71f9b933 JA |
533 | if (le64_to_cpu(us->bs) != io_u->xfer_buflen) { |
534 | nd->seq_off = 1; | |
535 | return; | |
536 | } | |
e9ad9637 JA |
537 | |
538 | seq = le64_to_cpu(us->seq); | |
539 | ||
540 | if (seq != nd->udp_recv_seq) | |
3bcb9d94 | 541 | td->ts.drop_io_u[io_u->ddir] += seq - nd->udp_recv_seq; |
e9ad9637 JA |
542 | |
543 | nd->udp_recv_seq = seq + 1; | |
544 | } | |
545 | ||
9cce02e8 JA |
546 | static int fio_netio_send(struct thread_data *td, struct io_u *io_u) |
547 | { | |
565e784d | 548 | struct netio_data *nd = td->io_ops_data; |
de890a1e | 549 | struct netio_options *o = td->eo; |
6f73a7f8 | 550 | int ret, flags = 0; |
371d456c | 551 | |
664fb3bd | 552 | do { |
49ccb8c1 | 553 | if (is_udp(o)) { |
10aa136b | 554 | const struct sockaddr *to; |
49ccb8c1 JA |
555 | socklen_t len; |
556 | ||
557 | if (is_ipv6(o)) { | |
558 | to = (struct sockaddr *) &nd->addr6; | |
559 | len = sizeof(nd->addr6); | |
560 | } else { | |
561 | to = (struct sockaddr *) &nd->addr; | |
562 | len = sizeof(nd->addr); | |
563 | } | |
62b38926 | 564 | |
e9ad9637 JA |
565 | if (td->o.verify == VERIFY_NONE) |
566 | store_udp_seq(nd, io_u); | |
567 | ||
664fb3bd | 568 | ret = sendto(io_u->file->fd, io_u->xfer_buf, |
49ccb8c1 | 569 | io_u->xfer_buflen, flags, to, len); |
664fb3bd JA |
570 | } else { |
571 | /* | |
572 | * if we are going to write more, set MSG_MORE | |
573 | */ | |
5921e80c | 574 | #ifdef MSG_MORE |
6f73a7f8 JA |
575 | if ((td->this_io_bytes[DDIR_WRITE] + io_u->xfer_buflen < |
576 | td->o.size) && !o->pingpong) | |
664fb3bd | 577 | flags |= MSG_MORE; |
5921e80c | 578 | #endif |
664fb3bd JA |
579 | ret = send(io_u->file->fd, io_u->xfer_buf, |
580 | io_u->xfer_buflen, flags); | |
581 | } | |
582 | if (ret > 0) | |
583 | break; | |
9cce02e8 | 584 | |
664fb3bd JA |
585 | ret = poll_wait(td, io_u->file->fd, POLLOUT); |
586 | if (ret <= 0) | |
587 | break; | |
664fb3bd JA |
588 | } while (1); |
589 | ||
590 | return ret; | |
591 | } | |
592 | ||
6b37db5b | 593 | static int is_close_msg(struct io_u *io_u, int len) |
664fb3bd JA |
594 | { |
595 | struct udp_close_msg *msg; | |
596 | ||
597 | if (len != sizeof(struct udp_close_msg)) | |
598 | return 0; | |
599 | ||
600 | msg = io_u->xfer_buf; | |
6b37db5b | 601 | if (le32_to_cpu(msg->magic) != FIO_LINK_OPEN_CLOSE_MAGIC) |
664fb3bd | 602 | return 0; |
6b37db5b | 603 | if (le32_to_cpu(msg->cmd) != FIO_LINK_CLOSE) |
664fb3bd JA |
604 | return 0; |
605 | ||
606 | return 1; | |
9cce02e8 JA |
607 | } |
608 | ||
414c2a3e | 609 | static int fio_netio_recv(struct thread_data *td, struct io_u *io_u) |
9cce02e8 | 610 | { |
565e784d | 611 | struct netio_data *nd = td->io_ops_data; |
de890a1e | 612 | struct netio_options *o = td->eo; |
6f73a7f8 | 613 | int ret, flags = 0; |
664fb3bd JA |
614 | |
615 | do { | |
49ccb8c1 | 616 | if (is_udp(o)) { |
b511c9aa | 617 | struct sockaddr *from; |
49ccb8c1 | 618 | socklen_t l, *len = &l; |
b511c9aa SB |
619 | |
620 | if (o->listen) { | |
49ccb8c1 JA |
621 | if (!is_ipv6(o)) { |
622 | from = (struct sockaddr *) &nd->addr; | |
623 | *len = sizeof(nd->addr); | |
624 | } else { | |
625 | from = (struct sockaddr *) &nd->addr6; | |
626 | *len = sizeof(nd->addr6); | |
627 | } | |
b511c9aa SB |
628 | } else { |
629 | from = NULL; | |
630 | len = NULL; | |
631 | } | |
664fb3bd JA |
632 | |
633 | ret = recvfrom(io_u->file->fd, io_u->xfer_buf, | |
b511c9aa | 634 | io_u->xfer_buflen, flags, from, len); |
e9ad9637 | 635 | |
6b37db5b | 636 | if (is_close_msg(io_u, ret)) { |
664fb3bd JA |
637 | td->done = 1; |
638 | return 0; | |
639 | } | |
640 | } else { | |
641 | ret = recv(io_u->file->fd, io_u->xfer_buf, | |
642 | io_u->xfer_buflen, flags); | |
6b37db5b JA |
643 | |
644 | if (is_close_msg(io_u, ret)) { | |
645 | td->done = 1; | |
646 | return 0; | |
647 | } | |
664fb3bd JA |
648 | } |
649 | if (ret > 0) | |
650 | break; | |
7d988f68 JA |
651 | else if (!ret && (flags & MSG_WAITALL)) |
652 | break; | |
9cce02e8 | 653 | |
664fb3bd JA |
654 | ret = poll_wait(td, io_u->file->fd, POLLIN); |
655 | if (ret <= 0) | |
656 | break; | |
664fb3bd JA |
657 | flags |= MSG_WAITALL; |
658 | } while (1); | |
414c2a3e | 659 | |
e9ad9637 | 660 | if (is_udp(o) && td->o.verify == VERIFY_NONE) |
3bcb9d94 | 661 | verify_udp_seq(td, nd, io_u); |
e9ad9637 | 662 | |
664fb3bd | 663 | return ret; |
9cce02e8 JA |
664 | } |
665 | ||
2e4ef4fb JA |
666 | static enum fio_q_status __fio_netio_queue(struct thread_data *td, |
667 | struct io_u *io_u, | |
668 | enum fio_ddir ddir) | |
9cce02e8 | 669 | { |
565e784d | 670 | struct netio_data *nd = td->io_ops_data; |
de890a1e | 671 | struct netio_options *o = td->eo; |
9cce02e8 JA |
672 | int ret; |
673 | ||
6f73a7f8 | 674 | if (ddir == DDIR_WRITE) { |
49ccb8c1 | 675 | if (!nd->use_splice || is_udp(o) || |
de890a1e | 676 | o->proto == FIO_TYPE_UNIX) |
9cce02e8 | 677 | ret = fio_netio_send(td, io_u); |
414c2a3e JA |
678 | else |
679 | ret = fio_netio_splice_out(td, io_u); | |
6f73a7f8 | 680 | } else if (ddir == DDIR_READ) { |
49ccb8c1 | 681 | if (!nd->use_splice || is_udp(o) || |
de890a1e | 682 | o->proto == FIO_TYPE_UNIX) |
414c2a3e | 683 | ret = fio_netio_recv(td, io_u); |
9cce02e8 | 684 | else |
414c2a3e | 685 | ret = fio_netio_splice_in(td, io_u); |
d4f12dd0 | 686 | } else |
7a6499da | 687 | ret = 0; /* must be a SYNC */ |
ed92ac0c | 688 | |
cec6b55d | 689 | if (ret != (int) io_u->xfer_buflen) { |
f6846c65 | 690 | if (ret > 0) { |
cec6b55d JA |
691 | io_u->resid = io_u->xfer_buflen - ret; |
692 | io_u->error = 0; | |
36167d82 | 693 | return FIO_Q_COMPLETED; |
f6846c65 JA |
694 | } else if (!ret) |
695 | return FIO_Q_BUSY; | |
696 | else { | |
414c2a3e JA |
697 | int err = errno; |
698 | ||
6f73a7f8 | 699 | if (ddir == DDIR_WRITE && err == EMSGSIZE) |
414c2a3e JA |
700 | return FIO_Q_BUSY; |
701 | ||
702 | io_u->error = err; | |
703 | } | |
ed92ac0c JA |
704 | } |
705 | ||
36167d82 | 706 | if (io_u->error) |
e1161c32 | 707 | td_verror(td, io_u->error, "xfer"); |
ed92ac0c | 708 | |
36167d82 | 709 | return FIO_Q_COMPLETED; |
ed92ac0c JA |
710 | } |
711 | ||
2e4ef4fb JA |
712 | static enum fio_q_status fio_netio_queue(struct thread_data *td, |
713 | struct io_u *io_u) | |
6f73a7f8 JA |
714 | { |
715 | struct netio_options *o = td->eo; | |
716 | int ret; | |
717 | ||
718 | fio_ro_check(td, io_u); | |
719 | ||
720 | ret = __fio_netio_queue(td, io_u, io_u->ddir); | |
721 | if (!o->pingpong || ret != FIO_Q_COMPLETED) | |
722 | return ret; | |
723 | ||
724 | /* | |
725 | * For ping-pong mode, receive or send reply as needed | |
726 | */ | |
727 | if (td_read(td) && io_u->ddir == DDIR_READ) | |
728 | ret = __fio_netio_queue(td, io_u, DDIR_WRITE); | |
729 | else if (td_write(td) && io_u->ddir == DDIR_WRITE) | |
730 | ret = __fio_netio_queue(td, io_u, DDIR_READ); | |
731 | ||
732 | return ret; | |
733 | } | |
734 | ||
b5af8293 | 735 | static int fio_netio_connect(struct thread_data *td, struct fio_file *f) |
ed92ac0c | 736 | { |
565e784d | 737 | struct netio_data *nd = td->io_ops_data; |
de890a1e | 738 | struct netio_options *o = td->eo; |
6264c7a8 | 739 | int type, domain; |
414c2a3e | 740 | |
de890a1e | 741 | if (o->proto == FIO_TYPE_TCP) { |
0fd666bf | 742 | domain = AF_INET; |
414c2a3e | 743 | type = SOCK_STREAM; |
49ccb8c1 JA |
744 | } else if (o->proto == FIO_TYPE_TCP_V6) { |
745 | domain = AF_INET6; | |
746 | type = SOCK_STREAM; | |
de890a1e | 747 | } else if (o->proto == FIO_TYPE_UDP) { |
0fd666bf | 748 | domain = AF_INET; |
414c2a3e | 749 | type = SOCK_DGRAM; |
49ccb8c1 JA |
750 | } else if (o->proto == FIO_TYPE_UDP_V6) { |
751 | domain = AF_INET6; | |
752 | type = SOCK_DGRAM; | |
de890a1e | 753 | } else if (o->proto == FIO_TYPE_UNIX) { |
0fd666bf JA |
754 | domain = AF_UNIX; |
755 | type = SOCK_STREAM; | |
80cc242a MP |
756 | } else if (is_vsock(o)) { |
757 | domain = AF_VSOCK; | |
758 | type = SOCK_STREAM; | |
0fd666bf | 759 | } else { |
de890a1e | 760 | log_err("fio: bad network type %d\n", o->proto); |
0fd666bf JA |
761 | f->fd = -1; |
762 | return 1; | |
763 | } | |
ed92ac0c | 764 | |
0fd666bf | 765 | f->fd = socket(domain, type, 0); |
b5af8293 JA |
766 | if (f->fd < 0) { |
767 | td_verror(td, errno, "socket"); | |
768 | return 1; | |
ed92ac0c JA |
769 | } |
770 | ||
1eafa37a | 771 | #ifdef CONFIG_TCP_NODELAY |
49ccb8c1 | 772 | if (o->nodelay && is_tcp(o)) { |
6264c7a8 JA |
773 | int optval = 1; |
774 | ||
26e594a5 | 775 | if (setsockopt(f->fd, IPPROTO_TCP, TCP_NODELAY, (void *) &optval, sizeof(int)) < 0) { |
70a7878c SN |
776 | log_err("fio: cannot set TCP_NODELAY option on socket (%s), disable with 'nodelay=0'\n", strerror(errno)); |
777 | return 1; | |
778 | } | |
779 | } | |
1eafa37a | 780 | #endif |
70a7878c | 781 | |
1008602c JA |
782 | if (set_window_size(td, f->fd)) { |
783 | close(f->fd); | |
784 | return 1; | |
785 | } | |
e5f34d95 JA |
786 | if (set_mss(td, f->fd)) { |
787 | close(f->fd); | |
788 | return 1; | |
789 | } | |
1008602c | 790 | |
49ccb8c1 | 791 | if (is_udp(o)) { |
d3a623de SB |
792 | if (!fio_netio_is_multicast(td->o.filename)) |
793 | return 0; | |
49ccb8c1 JA |
794 | if (is_ipv6(o)) { |
795 | log_err("fio: multicast not supported on IPv6\n"); | |
796 | close(f->fd); | |
797 | return 1; | |
798 | } | |
d3a623de | 799 | |
f16b7405 | 800 | if (o->intfc) { |
b93b6a2e | 801 | struct in_addr interface_addr; |
49ccb8c1 | 802 | |
f16b7405 | 803 | if (inet_aton(o->intfc, &interface_addr) == 0) { |
b93b6a2e SB |
804 | log_err("fio: interface not valid interface IP\n"); |
805 | close(f->fd); | |
806 | return 1; | |
807 | } | |
f16b7405 | 808 | if (setsockopt(f->fd, IPPROTO_IP, IP_MULTICAST_IF, (const char*)&interface_addr, sizeof(interface_addr)) < 0) { |
b93b6a2e SB |
809 | td_verror(td, errno, "setsockopt IP_MULTICAST_IF"); |
810 | close(f->fd); | |
811 | return 1; | |
812 | } | |
813 | } | |
f16b7405 | 814 | if (setsockopt(f->fd, IPPROTO_IP, IP_MULTICAST_TTL, (const char*)&o->ttl, sizeof(o->ttl)) < 0) { |
d3a623de SB |
815 | td_verror(td, errno, "setsockopt IP_MULTICAST_TTL"); |
816 | close(f->fd); | |
817 | return 1; | |
818 | } | |
414c2a3e | 819 | return 0; |
b93b6a2e | 820 | } else if (o->proto == FIO_TYPE_TCP) { |
67bf9823 | 821 | socklen_t len = sizeof(nd->addr); |
414c2a3e | 822 | |
0fd666bf JA |
823 | if (connect(f->fd, (struct sockaddr *) &nd->addr, len) < 0) { |
824 | td_verror(td, errno, "connect"); | |
b94cba47 | 825 | close(f->fd); |
0fd666bf JA |
826 | return 1; |
827 | } | |
49ccb8c1 JA |
828 | } else if (o->proto == FIO_TYPE_TCP_V6) { |
829 | socklen_t len = sizeof(nd->addr6); | |
830 | ||
831 | if (connect(f->fd, (struct sockaddr *) &nd->addr6, len) < 0) { | |
832 | td_verror(td, errno, "connect"); | |
833 | close(f->fd); | |
834 | return 1; | |
835 | } | |
80cc242a MP |
836 | } else if (is_vsock(o)) { |
837 | socklen_t len = sizeof(nd->addr_vm); | |
49ccb8c1 | 838 | |
80cc242a MP |
839 | if (connect(f->fd, (struct sockaddr *) &nd->addr_vm, len) < 0) { |
840 | td_verror(td, errno, "connect"); | |
841 | close(f->fd); | |
842 | return 1; | |
843 | } | |
0fd666bf JA |
844 | } else { |
845 | struct sockaddr_un *addr = &nd->addr_un; | |
67bf9823 | 846 | socklen_t len; |
0fd666bf JA |
847 | |
848 | len = sizeof(addr->sun_family) + strlen(addr->sun_path) + 1; | |
849 | ||
850 | if (connect(f->fd, (struct sockaddr *) addr, len) < 0) { | |
851 | td_verror(td, errno, "connect"); | |
b94cba47 | 852 | close(f->fd); |
0fd666bf JA |
853 | return 1; |
854 | } | |
ed92ac0c JA |
855 | } |
856 | ||
857 | return 0; | |
ed92ac0c JA |
858 | } |
859 | ||
b5af8293 | 860 | static int fio_netio_accept(struct thread_data *td, struct fio_file *f) |
5fdd124a | 861 | { |
565e784d | 862 | struct netio_data *nd = td->io_ops_data; |
de890a1e | 863 | struct netio_options *o = td->eo; |
49ccb8c1 | 864 | socklen_t socklen; |
6264c7a8 | 865 | int state; |
5fdd124a | 866 | |
49ccb8c1 | 867 | if (is_udp(o)) { |
414c2a3e JA |
868 | f->fd = nd->listenfd; |
869 | return 0; | |
870 | } | |
871 | ||
859088d3 JA |
872 | state = td->runstate; |
873 | td_set_runstate(td, TD_SETTING_UP); | |
874 | ||
6d86144d | 875 | log_info("fio: waiting for connection\n"); |
5fdd124a | 876 | |
371d456c | 877 | if (poll_wait(td, nd->listenfd, POLLIN) < 0) |
859088d3 | 878 | goto err; |
0c09442b | 879 | |
49ccb8c1 JA |
880 | if (o->proto == FIO_TYPE_TCP) { |
881 | socklen = sizeof(nd->addr); | |
882 | f->fd = accept(nd->listenfd, (struct sockaddr *) &nd->addr, &socklen); | |
80cc242a MP |
883 | } else if (is_vsock(o)) { |
884 | socklen = sizeof(nd->addr_vm); | |
885 | f->fd = accept(nd->listenfd, (struct sockaddr *) &nd->addr_vm, &socklen); | |
49ccb8c1 JA |
886 | } else { |
887 | socklen = sizeof(nd->addr6); | |
888 | f->fd = accept(nd->listenfd, (struct sockaddr *) &nd->addr6, &socklen); | |
889 | } | |
890 | ||
371d456c JA |
891 | if (f->fd < 0) { |
892 | td_verror(td, errno, "accept"); | |
859088d3 | 893 | goto err; |
b5af8293 | 894 | } |
5fdd124a | 895 | |
1eafa37a | 896 | #ifdef CONFIG_TCP_NODELAY |
49ccb8c1 | 897 | if (o->nodelay && is_tcp(o)) { |
6264c7a8 JA |
898 | int optval = 1; |
899 | ||
26e594a5 | 900 | if (setsockopt(f->fd, IPPROTO_TCP, TCP_NODELAY, (void *) &optval, sizeof(int)) < 0) { |
70a7878c SN |
901 | log_err("fio: cannot set TCP_NODELAY option on socket (%s), disable with 'nodelay=0'\n", strerror(errno)); |
902 | return 1; | |
903 | } | |
904 | } | |
1eafa37a | 905 | #endif |
70a7878c | 906 | |
0cae16ff | 907 | reset_all_stats(td); |
859088d3 | 908 | td_set_runstate(td, state); |
b5af8293 | 909 | return 0; |
859088d3 JA |
910 | err: |
911 | td_set_runstate(td, state); | |
912 | return 1; | |
b5af8293 JA |
913 | } |
914 | ||
6b37db5b | 915 | static void fio_netio_send_close(struct thread_data *td, struct fio_file *f) |
664fb3bd | 916 | { |
565e784d | 917 | struct netio_data *nd = td->io_ops_data; |
49ccb8c1 | 918 | struct netio_options *o = td->eo; |
664fb3bd | 919 | struct udp_close_msg msg; |
49ccb8c1 JA |
920 | struct sockaddr *to; |
921 | socklen_t len; | |
664fb3bd JA |
922 | int ret; |
923 | ||
49ccb8c1 JA |
924 | if (is_ipv6(o)) { |
925 | to = (struct sockaddr *) &nd->addr6; | |
926 | len = sizeof(nd->addr6); | |
80cc242a MP |
927 | } else if (is_vsock(o)) { |
928 | to = NULL; | |
929 | len = 0; | |
49ccb8c1 JA |
930 | } else { |
931 | to = (struct sockaddr *) &nd->addr; | |
932 | len = sizeof(nd->addr); | |
933 | } | |
934 | ||
6b37db5b JA |
935 | msg.magic = cpu_to_le32((uint32_t) FIO_LINK_OPEN_CLOSE_MAGIC); |
936 | msg.cmd = cpu_to_le32((uint32_t) FIO_LINK_CLOSE); | |
664fb3bd | 937 | |
49ccb8c1 | 938 | ret = sendto(f->fd, (void *) &msg, sizeof(msg), MSG_WAITALL, to, len); |
664fb3bd JA |
939 | if (ret < 0) |
940 | td_verror(td, errno, "sendto udp link close"); | |
941 | } | |
942 | ||
943 | static int fio_netio_close_file(struct thread_data *td, struct fio_file *f) | |
944 | { | |
664fb3bd | 945 | /* |
6b37db5b | 946 | * Notify the receiver that we are closing down the link |
664fb3bd | 947 | */ |
6b37db5b | 948 | fio_netio_send_close(td, f); |
664fb3bd JA |
949 | |
950 | return generic_close_file(td, f); | |
951 | } | |
952 | ||
b96d2430 JA |
953 | static int fio_netio_udp_recv_open(struct thread_data *td, struct fio_file *f) |
954 | { | |
565e784d | 955 | struct netio_data *nd = td->io_ops_data; |
49ccb8c1 | 956 | struct netio_options *o = td->eo; |
b96d2430 | 957 | struct udp_close_msg msg; |
49ccb8c1 JA |
958 | struct sockaddr *to; |
959 | socklen_t len; | |
b96d2430 JA |
960 | int ret; |
961 | ||
49ccb8c1 JA |
962 | if (is_ipv6(o)) { |
963 | len = sizeof(nd->addr6); | |
964 | to = (struct sockaddr *) &nd->addr6; | |
965 | } else { | |
966 | len = sizeof(nd->addr); | |
967 | to = (struct sockaddr *) &nd->addr; | |
968 | } | |
969 | ||
1f81991e | 970 | ret = recvfrom(f->fd, (void *) &msg, sizeof(msg), MSG_WAITALL, to, &len); |
b96d2430 | 971 | if (ret < 0) { |
ee7062fd | 972 | td_verror(td, errno, "recvfrom udp link open"); |
b96d2430 JA |
973 | return ret; |
974 | } | |
975 | ||
976 | if (ntohl(msg.magic) != FIO_LINK_OPEN_CLOSE_MAGIC || | |
977 | ntohl(msg.cmd) != FIO_LINK_OPEN) { | |
0cef322a SW |
978 | log_err("fio: bad udp open magic %x/%x\n", |
979 | (unsigned int) ntohl(msg.magic), | |
980 | (unsigned int) ntohl(msg.cmd)); | |
b96d2430 JA |
981 | return -1; |
982 | } | |
983 | ||
e9ad9637 | 984 | fio_gettime(&td->start, NULL); |
b96d2430 JA |
985 | return 0; |
986 | } | |
987 | ||
6b37db5b | 988 | static int fio_netio_send_open(struct thread_data *td, struct fio_file *f) |
b96d2430 | 989 | { |
565e784d | 990 | struct netio_data *nd = td->io_ops_data; |
49ccb8c1 | 991 | struct netio_options *o = td->eo; |
b96d2430 | 992 | struct udp_close_msg msg; |
49ccb8c1 JA |
993 | struct sockaddr *to; |
994 | socklen_t len; | |
b96d2430 JA |
995 | int ret; |
996 | ||
49ccb8c1 JA |
997 | if (is_ipv6(o)) { |
998 | len = sizeof(nd->addr6); | |
999 | to = (struct sockaddr *) &nd->addr6; | |
80cc242a MP |
1000 | } else if (is_vsock(o)) { |
1001 | len = sizeof(nd->addr_vm); | |
1002 | to = (struct sockaddr *) &nd->addr_vm; | |
49ccb8c1 JA |
1003 | } else { |
1004 | len = sizeof(nd->addr); | |
1005 | to = (struct sockaddr *) &nd->addr; | |
1006 | } | |
1007 | ||
b96d2430 JA |
1008 | msg.magic = htonl(FIO_LINK_OPEN_CLOSE_MAGIC); |
1009 | msg.cmd = htonl(FIO_LINK_OPEN); | |
1010 | ||
49ccb8c1 | 1011 | ret = sendto(f->fd, (void *) &msg, sizeof(msg), MSG_WAITALL, to, len); |
b96d2430 JA |
1012 | if (ret < 0) { |
1013 | td_verror(td, errno, "sendto udp link open"); | |
1014 | return ret; | |
1015 | } | |
1016 | ||
1017 | return 0; | |
1018 | } | |
1019 | ||
1020 | static int fio_netio_open_file(struct thread_data *td, struct fio_file *f) | |
1021 | { | |
1022 | int ret; | |
1023 | struct netio_options *o = td->eo; | |
1024 | ||
1025 | if (o->listen) | |
1026 | ret = fio_netio_accept(td, f); | |
1027 | else | |
1028 | ret = fio_netio_connect(td, f); | |
1029 | ||
1030 | if (ret) { | |
1031 | f->fd = -1; | |
1032 | return ret; | |
1033 | } | |
1034 | ||
49ccb8c1 | 1035 | if (is_udp(o)) { |
b96d2430 | 1036 | if (td_write(td)) |
6b37db5b | 1037 | ret = fio_netio_send_open(td, f); |
b96d2430 JA |
1038 | else { |
1039 | int state; | |
1040 | ||
1041 | state = td->runstate; | |
1042 | td_set_runstate(td, TD_SETTING_UP); | |
1043 | ret = fio_netio_udp_recv_open(td, f); | |
1044 | td_set_runstate(td, state); | |
1045 | } | |
1046 | } | |
1047 | ||
1048 | if (ret) | |
1049 | fio_netio_close_file(td, f); | |
1050 | ||
1051 | return ret; | |
1052 | } | |
1053 | ||
0b783341 JA |
1054 | static int fio_fill_addr(struct thread_data *td, const char *host, int af, |
1055 | void *dst, struct addrinfo **res) | |
1056 | { | |
1057 | struct netio_options *o = td->eo; | |
1058 | struct addrinfo hints; | |
1059 | int ret; | |
1060 | ||
1061 | if (inet_pton(af, host, dst)) | |
1062 | return 0; | |
1063 | ||
1064 | memset(&hints, 0, sizeof(hints)); | |
0b783341 | 1065 | |
80cc242a | 1066 | if (is_tcp(o) || is_vsock(o)) |
0b783341 JA |
1067 | hints.ai_socktype = SOCK_STREAM; |
1068 | else | |
1069 | hints.ai_socktype = SOCK_DGRAM; | |
1070 | ||
b1b1be2a JA |
1071 | if (is_ipv6(o)) |
1072 | hints.ai_family = AF_INET6; | |
80cc242a MP |
1073 | #ifdef CONFIG_VSOCK |
1074 | else if (is_vsock(o)) | |
1075 | hints.ai_family = AF_VSOCK; | |
1076 | #endif | |
b1b1be2a JA |
1077 | else |
1078 | hints.ai_family = AF_INET; | |
1079 | ||
0b783341 JA |
1080 | ret = getaddrinfo(host, NULL, &hints, res); |
1081 | if (ret) { | |
1082 | int e = EINVAL; | |
1083 | char str[128]; | |
1084 | ||
1085 | if (ret == EAI_SYSTEM) | |
1086 | e = errno; | |
1087 | ||
1088 | snprintf(str, sizeof(str), "getaddrinfo: %s", gai_strerror(ret)); | |
1089 | td_verror(td, e, str); | |
1090 | return 1; | |
1091 | } | |
1092 | ||
1093 | return 0; | |
1094 | } | |
1095 | ||
0fd666bf JA |
1096 | static int fio_netio_setup_connect_inet(struct thread_data *td, |
1097 | const char *host, unsigned short port) | |
b5af8293 | 1098 | { |
565e784d | 1099 | struct netio_data *nd = td->io_ops_data; |
49ccb8c1 | 1100 | struct netio_options *o = td->eo; |
0b783341 JA |
1101 | struct addrinfo *res = NULL; |
1102 | void *dst, *src; | |
1103 | int af, len; | |
b5af8293 | 1104 | |
166dce4b JA |
1105 | if (!host) { |
1106 | log_err("fio: connect with no host to connect to.\n"); | |
1107 | if (td_read(td)) | |
1108 | log_err("fio: did you forget to set 'listen'?\n"); | |
1109 | ||
1110 | td_verror(td, EINVAL, "no hostname= set"); | |
1111 | return 1; | |
1112 | } | |
1113 | ||
0b783341 JA |
1114 | nd->addr.sin_family = AF_INET; |
1115 | nd->addr.sin_port = htons(port); | |
1116 | nd->addr6.sin6_family = AF_INET6; | |
1117 | nd->addr6.sin6_port = htons(port); | |
b5af8293 | 1118 | |
0b783341 JA |
1119 | if (is_ipv6(o)) { |
1120 | af = AF_INET6; | |
68631b36 | 1121 | dst = &nd->addr6.sin6_addr; |
49ccb8c1 | 1122 | } else { |
0b783341 | 1123 | af = AF_INET; |
68631b36 | 1124 | dst = &nd->addr.sin_addr; |
0b783341 | 1125 | } |
49ccb8c1 | 1126 | |
0b783341 JA |
1127 | if (fio_fill_addr(td, host, af, dst, &res)) |
1128 | return 1; | |
49ccb8c1 | 1129 | |
0b783341 JA |
1130 | if (!res) |
1131 | return 0; | |
49ccb8c1 | 1132 | |
0b783341 JA |
1133 | if (is_ipv6(o)) { |
1134 | len = sizeof(nd->addr6.sin6_addr); | |
1135 | src = &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr; | |
1136 | } else { | |
1137 | len = sizeof(nd->addr.sin_addr); | |
1138 | src = &((struct sockaddr_in *) res->ai_addr)->sin_addr; | |
5fdd124a JA |
1139 | } |
1140 | ||
0b783341 JA |
1141 | memcpy(dst, src, len); |
1142 | freeaddrinfo(res); | |
5fdd124a JA |
1143 | return 0; |
1144 | } | |
1145 | ||
0fd666bf JA |
1146 | static int fio_netio_setup_connect_unix(struct thread_data *td, |
1147 | const char *path) | |
1148 | { | |
565e784d | 1149 | struct netio_data *nd = td->io_ops_data; |
0fd666bf JA |
1150 | struct sockaddr_un *soun = &nd->addr_un; |
1151 | ||
1152 | soun->sun_family = AF_UNIX; | |
36833fb0 | 1153 | snprintf(soun->sun_path, sizeof(soun->sun_path), "%s", path); |
0fd666bf JA |
1154 | return 0; |
1155 | } | |
1156 | ||
80cc242a MP |
1157 | static int fio_netio_setup_connect_vsock(struct thread_data *td, |
1158 | const char *host, unsigned short port) | |
1159 | { | |
1160 | #ifdef CONFIG_VSOCK | |
1161 | struct netio_data *nd = td->io_ops_data; | |
1162 | struct sockaddr_vm *addr = &nd->addr_vm; | |
1163 | int cid; | |
1164 | ||
1165 | if (!host) { | |
1166 | log_err("fio: connect with no host to connect to.\n"); | |
1167 | if (td_read(td)) | |
1168 | log_err("fio: did you forget to set 'listen'?\n"); | |
1169 | ||
1170 | td_verror(td, EINVAL, "no hostname= set"); | |
1171 | return 1; | |
1172 | } | |
1173 | ||
1174 | addr->svm_family = AF_VSOCK; | |
1175 | addr->svm_port = port; | |
1176 | ||
1177 | if (host) { | |
1178 | cid = atoi(host); | |
1179 | if (cid < 0 || cid > UINT32_MAX) { | |
1180 | log_err("fio: invalid CID %d\n", cid); | |
1181 | return 1; | |
1182 | } | |
1183 | addr->svm_cid = cid; | |
1184 | } | |
1185 | ||
1186 | return 0; | |
1187 | #else | |
1188 | td_verror(td, -EINVAL, "vsock not supported"); | |
1189 | return 1; | |
1190 | #endif | |
1191 | } | |
1192 | ||
de890a1e | 1193 | static int fio_netio_setup_connect(struct thread_data *td) |
0fd666bf | 1194 | { |
de890a1e | 1195 | struct netio_options *o = td->eo; |
0fd666bf | 1196 | |
49ccb8c1 | 1197 | if (is_udp(o) || is_tcp(o)) |
de890a1e | 1198 | return fio_netio_setup_connect_inet(td, td->o.filename,o->port); |
80cc242a MP |
1199 | else if (is_vsock(o)) |
1200 | return fio_netio_setup_connect_vsock(td, td->o.filename, o->port); | |
0fd666bf | 1201 | else |
de890a1e | 1202 | return fio_netio_setup_connect_unix(td, td->o.filename); |
0fd666bf JA |
1203 | } |
1204 | ||
1205 | static int fio_netio_setup_listen_unix(struct thread_data *td, const char *path) | |
1206 | { | |
565e784d | 1207 | struct netio_data *nd = td->io_ops_data; |
0fd666bf JA |
1208 | struct sockaddr_un *addr = &nd->addr_un; |
1209 | mode_t mode; | |
1210 | int len, fd; | |
1211 | ||
1212 | fd = socket(AF_UNIX, SOCK_STREAM, 0); | |
1213 | if (fd < 0) { | |
1214 | log_err("fio: socket: %s\n", strerror(errno)); | |
1215 | return -1; | |
1216 | } | |
1217 | ||
1218 | mode = umask(000); | |
1219 | ||
0fd666bf | 1220 | addr->sun_family = AF_UNIX; |
36833fb0 | 1221 | snprintf(addr->sun_path, sizeof(addr->sun_path), "%s", path); |
0fd666bf JA |
1222 | unlink(path); |
1223 | ||
1224 | len = sizeof(addr->sun_family) + strlen(path) + 1; | |
1225 | ||
1226 | if (bind(fd, (struct sockaddr *) addr, len) < 0) { | |
1227 | log_err("fio: bind: %s\n", strerror(errno)); | |
b94cba47 | 1228 | close(fd); |
0fd666bf JA |
1229 | return -1; |
1230 | } | |
1231 | ||
1232 | umask(mode); | |
1233 | nd->listenfd = fd; | |
1234 | return 0; | |
1235 | } | |
1236 | ||
1237 | static int fio_netio_setup_listen_inet(struct thread_data *td, short port) | |
ed92ac0c | 1238 | { |
565e784d | 1239 | struct netio_data *nd = td->io_ops_data; |
de890a1e | 1240 | struct netio_options *o = td->eo; |
b511c9aa SB |
1241 | struct ip_mreq mr; |
1242 | struct sockaddr_in sin; | |
49ccb8c1 JA |
1243 | struct sockaddr *saddr; |
1244 | int fd, opt, type, domain; | |
1245 | socklen_t len; | |
ed92ac0c | 1246 | |
b511c9aa | 1247 | memset(&sin, 0, sizeof(sin)); |
49ccb8c1 JA |
1248 | |
1249 | if (o->proto == FIO_TYPE_TCP) { | |
414c2a3e | 1250 | type = SOCK_STREAM; |
49ccb8c1 JA |
1251 | domain = AF_INET; |
1252 | } else if (o->proto == FIO_TYPE_TCP_V6) { | |
1253 | type = SOCK_STREAM; | |
1254 | domain = AF_INET6; | |
1255 | } else if (o->proto == FIO_TYPE_UDP) { | |
414c2a3e | 1256 | type = SOCK_DGRAM; |
49ccb8c1 JA |
1257 | domain = AF_INET; |
1258 | } else if (o->proto == FIO_TYPE_UDP_V6) { | |
1259 | type = SOCK_DGRAM; | |
1260 | domain = AF_INET6; | |
1261 | } else { | |
1262 | log_err("fio: unknown proto %d\n", o->proto); | |
1263 | return 1; | |
1264 | } | |
414c2a3e | 1265 | |
49ccb8c1 | 1266 | fd = socket(domain, type, 0); |
ed92ac0c | 1267 | if (fd < 0) { |
e1161c32 | 1268 | td_verror(td, errno, "socket"); |
ed92ac0c JA |
1269 | return 1; |
1270 | } | |
1271 | ||
1272 | opt = 1; | |
26e594a5 | 1273 | if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *) &opt, sizeof(opt)) < 0) { |
e1161c32 | 1274 | td_verror(td, errno, "setsockopt"); |
4a93dec2 | 1275 | close(fd); |
ed92ac0c JA |
1276 | return 1; |
1277 | } | |
6bedbfaf | 1278 | #ifdef SO_REUSEPORT |
26e594a5 | 1279 | if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, (void *) &opt, sizeof(opt)) < 0) { |
e1161c32 | 1280 | td_verror(td, errno, "setsockopt"); |
4a93dec2 | 1281 | close(fd); |
6bedbfaf JA |
1282 | return 1; |
1283 | } | |
1284 | #endif | |
ed92ac0c | 1285 | |
1008602c JA |
1286 | if (set_window_size(td, fd)) { |
1287 | close(fd); | |
1288 | return 1; | |
1289 | } | |
e5f34d95 JA |
1290 | if (set_mss(td, fd)) { |
1291 | close(fd); | |
1292 | return 1; | |
1293 | } | |
1008602c | 1294 | |
6611e9c7 | 1295 | if (td->o.filename) { |
49ccb8c1 | 1296 | if (!is_udp(o) || !fio_netio_is_multicast(td->o.filename)) { |
b511c9aa SB |
1297 | log_err("fio: hostname not valid for non-multicast inbound network IO\n"); |
1298 | close(fd); | |
1299 | return 1; | |
1300 | } | |
6611e9c7 | 1301 | if (is_ipv6(o)) { |
c5839011 | 1302 | log_err("fio: IPv6 not supported for multicast network IO\n"); |
6611e9c7 JA |
1303 | close(fd); |
1304 | return 1; | |
1305 | } | |
b511c9aa SB |
1306 | |
1307 | inet_aton(td->o.filename, &sin.sin_addr); | |
1308 | ||
1309 | mr.imr_multiaddr = sin.sin_addr; | |
f16b7405 BC |
1310 | if (o->intfc) { |
1311 | if (inet_aton(o->intfc, &mr.imr_interface) == 0) { | |
b93b6a2e SB |
1312 | log_err("fio: interface not valid interface IP\n"); |
1313 | close(fd); | |
1314 | return 1; | |
1315 | } | |
1316 | } else { | |
1317 | mr.imr_interface.s_addr = htonl(INADDR_ANY); | |
1318 | } | |
6611e9c7 | 1319 | |
f16b7405 | 1320 | if (setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const char*)&mr, sizeof(mr)) < 0) { |
b511c9aa SB |
1321 | td_verror(td, errno, "setsockopt IP_ADD_MEMBERSHIP"); |
1322 | close(fd); | |
1323 | return 1; | |
1324 | } | |
1325 | } | |
1326 | ||
49ccb8c1 JA |
1327 | if (!is_ipv6(o)) { |
1328 | saddr = (struct sockaddr *) &nd->addr; | |
1329 | len = sizeof(nd->addr); | |
1330 | ||
1331 | nd->addr.sin_family = AF_INET; | |
1332 | nd->addr.sin_addr.s_addr = sin.sin_addr.s_addr ? sin.sin_addr.s_addr : htonl(INADDR_ANY); | |
1333 | nd->addr.sin_port = htons(port); | |
1334 | } else { | |
1335 | saddr = (struct sockaddr *) &nd->addr6; | |
1336 | len = sizeof(nd->addr6); | |
1337 | ||
1338 | nd->addr6.sin6_family = AF_INET6; | |
66f7a56f | 1339 | nd->addr6.sin6_addr = in6addr_any; |
49ccb8c1 JA |
1340 | nd->addr6.sin6_port = htons(port); |
1341 | } | |
ed92ac0c | 1342 | |
49ccb8c1 | 1343 | if (bind(fd, saddr, len) < 0) { |
d19cedd6 | 1344 | close(fd); |
e1161c32 | 1345 | td_verror(td, errno, "bind"); |
ed92ac0c JA |
1346 | return 1; |
1347 | } | |
0fd666bf JA |
1348 | |
1349 | nd->listenfd = fd; | |
1350 | return 0; | |
1351 | } | |
1352 | ||
80cc242a MP |
1353 | static int fio_netio_setup_listen_vsock(struct thread_data *td, short port, int type) |
1354 | { | |
1355 | #ifdef CONFIG_VSOCK | |
1356 | struct netio_data *nd = td->io_ops_data; | |
1357 | struct sockaddr_vm *addr = &nd->addr_vm; | |
1358 | int fd, opt; | |
1359 | socklen_t len; | |
1360 | ||
1361 | fd = socket(AF_VSOCK, type, 0); | |
1362 | if (fd < 0) { | |
1363 | td_verror(td, errno, "socket"); | |
1364 | return 1; | |
1365 | } | |
1366 | ||
1367 | opt = 1; | |
1368 | if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *) &opt, sizeof(opt)) < 0) { | |
1369 | td_verror(td, errno, "setsockopt"); | |
1370 | close(fd); | |
1371 | return 1; | |
1372 | } | |
1373 | ||
1374 | len = sizeof(*addr); | |
1375 | ||
1376 | nd->addr_vm.svm_family = AF_VSOCK; | |
1377 | nd->addr_vm.svm_cid = VMADDR_CID_ANY; | |
1378 | nd->addr_vm.svm_port = port; | |
1379 | ||
1380 | if (bind(fd, (struct sockaddr *) addr, len) < 0) { | |
1381 | td_verror(td, errno, "bind"); | |
1382 | close(fd); | |
1383 | return 1; | |
1384 | } | |
1385 | ||
1386 | nd->listenfd = fd; | |
1387 | return 0; | |
1388 | #else | |
1389 | td_verror(td, -EINVAL, "vsock not supported"); | |
1390 | return -1; | |
1391 | #endif | |
1392 | } | |
1393 | ||
de890a1e | 1394 | static int fio_netio_setup_listen(struct thread_data *td) |
0fd666bf | 1395 | { |
565e784d | 1396 | struct netio_data *nd = td->io_ops_data; |
de890a1e | 1397 | struct netio_options *o = td->eo; |
0fd666bf JA |
1398 | int ret; |
1399 | ||
49ccb8c1 | 1400 | if (is_udp(o) || is_tcp(o)) |
de890a1e | 1401 | ret = fio_netio_setup_listen_inet(td, o->port); |
80cc242a MP |
1402 | else if (is_vsock(o)) |
1403 | ret = fio_netio_setup_listen_vsock(td, o->port, SOCK_STREAM); | |
0fd666bf | 1404 | else |
de890a1e | 1405 | ret = fio_netio_setup_listen_unix(td, td->o.filename); |
0fd666bf JA |
1406 | |
1407 | if (ret) | |
1408 | return ret; | |
49ccb8c1 | 1409 | if (is_udp(o)) |
0fd666bf JA |
1410 | return 0; |
1411 | ||
1412 | if (listen(nd->listenfd, 10) < 0) { | |
e1161c32 | 1413 | td_verror(td, errno, "listen"); |
0fd666bf | 1414 | nd->listenfd = -1; |
ed92ac0c JA |
1415 | return 1; |
1416 | } | |
1417 | ||
b5af8293 | 1418 | return 0; |
ed92ac0c JA |
1419 | } |
1420 | ||
9bec88e1 | 1421 | static int fio_netio_init(struct thread_data *td) |
ed92ac0c | 1422 | { |
de890a1e | 1423 | struct netio_options *o = td->eo; |
af52b345 | 1424 | int ret; |
ed92ac0c | 1425 | |
3f457bea BC |
1426 | #ifdef WIN32 |
1427 | WSADATA wsd; | |
1428 | WSAStartup(MAKEWORD(2,2), &wsd); | |
1429 | #endif | |
1430 | ||
16d55aae JA |
1431 | if (td_random(td)) { |
1432 | log_err("fio: network IO can't be random\n"); | |
1433 | return 1; | |
1434 | } | |
ed92ac0c | 1435 | |
de890a1e SL |
1436 | if (o->proto == FIO_TYPE_UNIX && o->port) { |
1437 | log_err("fio: network IO port not valid with unix socket\n"); | |
1438 | return 1; | |
80cc242a MP |
1439 | } else if (is_vsock(o) && !o->port) { |
1440 | log_err("fio: network IO requires port for vsock\n"); | |
1441 | return 1; | |
de890a1e SL |
1442 | } else if (o->proto != FIO_TYPE_UNIX && !o->port) { |
1443 | log_err("fio: network IO requires port for tcp or udp\n"); | |
1444 | return 1; | |
1445 | } | |
ed92ac0c | 1446 | |
9e6ca396 JA |
1447 | o->port += td->subjob_number; |
1448 | ||
80cc242a | 1449 | if (!is_tcp(o) && !is_vsock(o)) { |
de890a1e | 1450 | if (o->listen) { |
9b986065 JA |
1451 | log_err("fio: listen only valid for TCP proto IO\n"); |
1452 | return 1; | |
de890a1e SL |
1453 | } |
1454 | if (td_rw(td)) { | |
9b986065 | 1455 | log_err("fio: datagram network connections must be" |
de890a1e | 1456 | " read OR write\n"); |
9b986065 JA |
1457 | return 1; |
1458 | } | |
1459 | if (o->proto == FIO_TYPE_UNIX && !td->o.filename) { | |
1460 | log_err("fio: UNIX sockets need host/filename\n"); | |
1461 | return 1; | |
de890a1e SL |
1462 | } |
1463 | o->listen = td_read(td); | |
1464 | } | |
443662ef | 1465 | |
de890a1e SL |
1466 | if (o->listen) |
1467 | ret = fio_netio_setup_listen(td); | |
0fd666bf | 1468 | else |
de890a1e | 1469 | ret = fio_netio_setup_connect(td); |
ed92ac0c | 1470 | |
7bb48f84 | 1471 | return ret; |
ed92ac0c JA |
1472 | } |
1473 | ||
b5af8293 | 1474 | static void fio_netio_cleanup(struct thread_data *td) |
9bec88e1 | 1475 | { |
565e784d | 1476 | struct netio_data *nd = td->io_ops_data; |
b5af8293 JA |
1477 | |
1478 | if (nd) { | |
64b24cd8 JA |
1479 | if (nd->listenfd != -1) |
1480 | close(nd->listenfd); | |
1481 | if (nd->pipes[0] != -1) | |
1482 | close(nd->pipes[0]); | |
1483 | if (nd->pipes[1] != -1) | |
1484 | close(nd->pipes[1]); | |
1485 | ||
b5af8293 | 1486 | free(nd); |
b5af8293 JA |
1487 | } |
1488 | } | |
1489 | ||
1490 | static int fio_netio_setup(struct thread_data *td) | |
1491 | { | |
7bb48f84 | 1492 | struct netio_data *nd; |
7bb48f84 | 1493 | |
de890a1e | 1494 | if (!td->files_index) { |
5903e7b7 | 1495 | add_file(td, td->o.filename ?: "net", 0, 0); |
de890a1e | 1496 | td->o.nr_files = td->o.nr_files ?: 1; |
b53f2c54 | 1497 | td->o.open_files++; |
de890a1e SL |
1498 | } |
1499 | ||
565e784d | 1500 | if (!td->io_ops_data) { |
223decdd | 1501 | nd = calloc(1, sizeof(*nd)); |
7bb48f84 | 1502 | nd->listenfd = -1; |
64b24cd8 | 1503 | nd->pipes[0] = nd->pipes[1] = -1; |
565e784d | 1504 | td->io_ops_data = nd; |
7bb48f84 | 1505 | } |
b5af8293 | 1506 | |
9bec88e1 JA |
1507 | return 0; |
1508 | } | |
1509 | ||
36d80bc7 JA |
1510 | static void fio_netio_terminate(struct thread_data *td) |
1511 | { | |
c5dd6d89 | 1512 | kill(td->pid, SIGTERM); |
36d80bc7 JA |
1513 | } |
1514 | ||
67bf9823 | 1515 | #ifdef CONFIG_LINUX_SPLICE |
9cce02e8 JA |
1516 | static int fio_netio_setup_splice(struct thread_data *td) |
1517 | { | |
1518 | struct netio_data *nd; | |
1519 | ||
1520 | fio_netio_setup(td); | |
1521 | ||
565e784d | 1522 | nd = td->io_ops_data; |
9cce02e8 JA |
1523 | if (nd) { |
1524 | if (pipe(nd->pipes) < 0) | |
1525 | return 1; | |
1526 | ||
1527 | nd->use_splice = 1; | |
1528 | return 0; | |
1529 | } | |
1530 | ||
1531 | return 1; | |
1532 | } | |
1533 | ||
5921e80c | 1534 | static struct ioengine_ops ioengine_splice = { |
de890a1e SL |
1535 | .name = "netsplice", |
1536 | .version = FIO_IOOPS_VERSION, | |
1537 | .prep = fio_netio_prep, | |
1538 | .queue = fio_netio_queue, | |
1539 | .setup = fio_netio_setup_splice, | |
1540 | .init = fio_netio_init, | |
1541 | .cleanup = fio_netio_cleanup, | |
1542 | .open_file = fio_netio_open_file, | |
36d80bc7 JA |
1543 | .close_file = fio_netio_close_file, |
1544 | .terminate = fio_netio_terminate, | |
de890a1e SL |
1545 | .options = options, |
1546 | .option_struct_size = sizeof(struct netio_options), | |
1547 | .flags = FIO_SYNCIO | FIO_DISKLESSIO | FIO_UNIDIR | | |
36d80bc7 | 1548 | FIO_PIPEIO, |
ed92ac0c | 1549 | }; |
5921e80c | 1550 | #endif |
ed92ac0c | 1551 | |
5921e80c | 1552 | static struct ioengine_ops ioengine_rw = { |
de890a1e SL |
1553 | .name = "net", |
1554 | .version = FIO_IOOPS_VERSION, | |
1555 | .prep = fio_netio_prep, | |
1556 | .queue = fio_netio_queue, | |
1557 | .setup = fio_netio_setup, | |
1558 | .init = fio_netio_init, | |
1559 | .cleanup = fio_netio_cleanup, | |
1560 | .open_file = fio_netio_open_file, | |
1561 | .close_file = fio_netio_close_file, | |
36d80bc7 | 1562 | .terminate = fio_netio_terminate, |
de890a1e SL |
1563 | .options = options, |
1564 | .option_struct_size = sizeof(struct netio_options), | |
1565 | .flags = FIO_SYNCIO | FIO_DISKLESSIO | FIO_UNIDIR | | |
ad705bcb | 1566 | FIO_PIPEIO | FIO_BIT_BASED, |
9cce02e8 JA |
1567 | }; |
1568 | ||
de890a1e SL |
1569 | static int str_hostname_cb(void *data, const char *input) |
1570 | { | |
1571 | struct netio_options *o = data; | |
1572 | ||
1573 | if (o->td->o.filename) | |
1574 | free(o->td->o.filename); | |
1575 | o->td->o.filename = strdup(input); | |
1576 | return 0; | |
1577 | } | |
1578 | ||
ed92ac0c JA |
1579 | static void fio_init fio_netio_register(void) |
1580 | { | |
9cce02e8 | 1581 | register_ioengine(&ioengine_rw); |
67bf9823 | 1582 | #ifdef CONFIG_LINUX_SPLICE |
9cce02e8 | 1583 | register_ioengine(&ioengine_splice); |
5921e80c | 1584 | #endif |
ed92ac0c JA |
1585 | } |
1586 | ||
1587 | static void fio_exit fio_netio_unregister(void) | |
1588 | { | |
9cce02e8 | 1589 | unregister_ioengine(&ioengine_rw); |
67bf9823 | 1590 | #ifdef CONFIG_LINUX_SPLICE |
9cce02e8 | 1591 | unregister_ioengine(&ioengine_splice); |
5921e80c | 1592 | #endif |
ed92ac0c | 1593 | } |