blob: ac5a93c8309b7bd275461cc599ff18f8389947a0 [file] [log] [blame]
Jens Axboeed92ac02007-02-06 14:43:52 +01001/*
Jens Axboeda751ca2007-03-14 10:59:33 +01002 * net engine
3 *
4 * IO engine that reads/writes to/from sockets.
5 *
Jens Axboeed92ac02007-02-06 14:43:52 +01006 */
7#include <stdio.h>
8#include <stdlib.h>
9#include <unistd.h>
Steven Noonan842805f2012-12-01 08:16:55 +000010#include <signal.h>
Jens Axboeed92ac02007-02-06 14:43:52 +010011#include <errno.h>
12#include <assert.h>
13#include <netinet/in.h>
Steven Noonan70a78782012-11-28 14:52:36 -080014#include <netinet/tcp.h>
Jens Axboeed92ac02007-02-06 14:43:52 +010015#include <arpa/inet.h>
16#include <netdb.h>
Jens Axboe5fdd1242007-02-11 04:00:37 +010017#include <sys/poll.h>
Jens Axboe72920562008-06-02 12:30:06 +020018#include <sys/types.h>
Jens Axboe0fd666b2011-10-06 20:08:53 +020019#include <sys/stat.h>
Jens Axboe72920562008-06-02 12:30:06 +020020#include <sys/socket.h>
Jens Axboe0fd666b2011-10-06 20:08:53 +020021#include <sys/un.h>
Jens Axboeed92ac02007-02-06 14:43:52 +010022
23#include "../fio.h"
Jens Axboeed92ac02007-02-06 14:43:52 +010024
Jens Axboeb5af8292007-03-08 12:43:13 +010025struct netio_data {
26 int listenfd;
Jens Axboe9cce02e2007-06-22 15:42:21 +020027 int use_splice;
28 int pipes[2];
Jens Axboeb5af8292007-03-08 12:43:13 +010029 struct sockaddr_in addr;
Jens Axboe49ccb8c2014-01-23 16:49:37 -080030 struct sockaddr_in6 addr6;
Jens Axboe0fd666b2011-10-06 20:08:53 +020031 struct sockaddr_un addr_un;
Jens Axboeb5af8292007-03-08 12:43:13 +010032};
Jens Axboeed92ac02007-02-06 14:43:52 +010033
Steven Langde890a12011-11-09 14:03:34 +010034struct netio_options {
35 struct thread_data *td;
36 unsigned int port;
37 unsigned int proto;
38 unsigned int listen;
Jens Axboe6f73a7f2012-11-30 09:59:20 +010039 unsigned int pingpong;
Steven Noonan70a78782012-11-28 14:52:36 -080040 unsigned int nodelay;
Shawn Bohrerd3a623d2013-07-19 13:24:08 -050041 unsigned int ttl;
Jens Axboe531e67a2014-10-09 11:55:16 -060042 unsigned int window_size;
Bruce Cranf16b7402013-10-08 15:05:27 +010043 char *intfc;
Steven Langde890a12011-11-09 14:03:34 +010044};
45
Jens Axboe664fb3b2009-01-19 13:26:36 +010046struct udp_close_msg {
47 uint32_t magic;
48 uint32_t cmd;
49};
50
51enum {
52 FIO_LINK_CLOSE = 0x89,
Jens Axboeb96d2432012-11-30 08:27:46 +010053 FIO_LINK_OPEN_CLOSE_MAGIC = 0x6c696e6b,
54 FIO_LINK_OPEN = 0x98,
Jens Axboe0fd666b2011-10-06 20:08:53 +020055
56 FIO_TYPE_TCP = 1,
57 FIO_TYPE_UDP = 2,
58 FIO_TYPE_UNIX = 3,
Jens Axboe49ccb8c2014-01-23 16:49:37 -080059 FIO_TYPE_TCP_V6 = 4,
60 FIO_TYPE_UDP_V6 = 5,
Jens Axboe664fb3b2009-01-19 13:26:36 +010061};
62
Steven Langde890a12011-11-09 14:03:34 +010063static int str_hostname_cb(void *data, const char *input);
64static struct fio_option options[] = {
65 {
66 .name = "hostname",
Jens Axboee8b0e952012-03-19 14:37:08 +010067 .lname = "net engine hostname",
Steven Langde890a12011-11-09 14:03:34 +010068 .type = FIO_OPT_STR_STORE,
69 .cb = str_hostname_cb,
70 .help = "Hostname for net IO engine",
Jens Axboee90a0ad2013-04-10 19:43:59 +020071 .category = FIO_OPT_C_ENGINE,
72 .group = FIO_OPT_G_NETIO,
Steven Langde890a12011-11-09 14:03:34 +010073 },
74 {
75 .name = "port",
Jens Axboee8b0e952012-03-19 14:37:08 +010076 .lname = "net engine port",
Steven Langde890a12011-11-09 14:03:34 +010077 .type = FIO_OPT_INT,
78 .off1 = offsetof(struct netio_options, port),
79 .minval = 1,
80 .maxval = 65535,
81 .help = "Port to use for TCP or UDP net connections",
Jens Axboee90a0ad2013-04-10 19:43:59 +020082 .category = FIO_OPT_C_ENGINE,
83 .group = FIO_OPT_G_NETIO,
Steven Langde890a12011-11-09 14:03:34 +010084 },
85 {
86 .name = "protocol",
Jens Axboee8b0e952012-03-19 14:37:08 +010087 .lname = "net engine protocol",
Steven Langde890a12011-11-09 14:03:34 +010088 .alias = "proto",
89 .type = FIO_OPT_STR,
90 .off1 = offsetof(struct netio_options, proto),
91 .help = "Network protocol to use",
92 .def = "tcp",
93 .posval = {
94 { .ival = "tcp",
95 .oval = FIO_TYPE_TCP,
96 .help = "Transmission Control Protocol",
97 },
Jens Axboeeb232312014-01-24 18:59:15 -080098#ifdef CONFIG_IPV6
Jens Axboe49ccb8c2014-01-23 16:49:37 -080099 { .ival = "tcpv6",
100 .oval = FIO_TYPE_TCP_V6,
101 .help = "Transmission Control Protocol V6",
102 },
Jens Axboeeb232312014-01-24 18:59:15 -0800103#endif
Steven Langde890a12011-11-09 14:03:34 +0100104 { .ival = "udp",
105 .oval = FIO_TYPE_UDP,
Bruce Cranf5cc3d02012-10-10 08:17:44 -0600106 .help = "User Datagram Protocol",
Steven Langde890a12011-11-09 14:03:34 +0100107 },
Jens Axboeeb232312014-01-24 18:59:15 -0800108#ifdef CONFIG_IPV6
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800109 { .ival = "udpv6",
110 .oval = FIO_TYPE_UDP_V6,
111 .help = "User Datagram Protocol V6",
112 },
Jens Axboeeb232312014-01-24 18:59:15 -0800113#endif
Steven Langde890a12011-11-09 14:03:34 +0100114 { .ival = "unix",
115 .oval = FIO_TYPE_UNIX,
116 .help = "UNIX domain socket",
117 },
118 },
Jens Axboee90a0ad2013-04-10 19:43:59 +0200119 .category = FIO_OPT_C_ENGINE,
120 .group = FIO_OPT_G_NETIO,
Steven Langde890a12011-11-09 14:03:34 +0100121 },
Jens Axboe1eafa372013-01-31 10:19:51 +0100122#ifdef CONFIG_TCP_NODELAY
Steven Langde890a12011-11-09 14:03:34 +0100123 {
Steven Noonan70a78782012-11-28 14:52:36 -0800124 .name = "nodelay",
125 .type = FIO_OPT_BOOL,
126 .off1 = offsetof(struct netio_options, nodelay),
127 .help = "Use TCP_NODELAY on TCP connections",
Jens Axboee90a0ad2013-04-10 19:43:59 +0200128 .category = FIO_OPT_C_ENGINE,
129 .group = FIO_OPT_G_NETIO,
Steven Noonan70a78782012-11-28 14:52:36 -0800130 },
Jens Axboe1eafa372013-01-31 10:19:51 +0100131#endif
Steven Langde890a12011-11-09 14:03:34 +0100132 {
133 .name = "listen",
Jens Axboee8b0e952012-03-19 14:37:08 +0100134 .lname = "net engine listen",
Steven Langde890a12011-11-09 14:03:34 +0100135 .type = FIO_OPT_STR_SET,
136 .off1 = offsetof(struct netio_options, listen),
137 .help = "Listen for incoming TCP connections",
Jens Axboee90a0ad2013-04-10 19:43:59 +0200138 .category = FIO_OPT_C_ENGINE,
139 .group = FIO_OPT_G_NETIO,
Steven Langde890a12011-11-09 14:03:34 +0100140 },
141 {
Jens Axboe6f73a7f2012-11-30 09:59:20 +0100142 .name = "pingpong",
143 .type = FIO_OPT_STR_SET,
144 .off1 = offsetof(struct netio_options, pingpong),
145 .help = "Ping-pong IO requests",
Jens Axboee90a0ad2013-04-10 19:43:59 +0200146 .category = FIO_OPT_C_ENGINE,
147 .group = FIO_OPT_G_NETIO,
Jens Axboe6f73a7f2012-11-30 09:59:20 +0100148 },
149 {
Shawn Bohrerb93b6a22013-07-19 13:24:07 -0500150 .name = "interface",
151 .lname = "net engine interface",
152 .type = FIO_OPT_STR_STORE,
Bruce Cranf16b7402013-10-08 15:05:27 +0100153 .off1 = offsetof(struct netio_options, intfc),
Shawn Bohrerb93b6a22013-07-19 13:24:07 -0500154 .help = "Network interface to use",
155 .category = FIO_OPT_C_ENGINE,
156 .group = FIO_OPT_G_NETIO,
157 },
158 {
Shawn Bohrerd3a623d2013-07-19 13:24:08 -0500159 .name = "ttl",
160 .lname = "net engine multicast ttl",
161 .type = FIO_OPT_INT,
162 .off1 = offsetof(struct netio_options, ttl),
163 .def = "1",
164 .minval = 0,
165 .help = "Time-to-live value for outgoing UDP multicast packets",
166 .category = FIO_OPT_C_ENGINE,
167 .group = FIO_OPT_G_NETIO,
168 },
Jens Axboe531e67a2014-10-09 11:55:16 -0600169#ifdef CONFIG_NET_WINDOWSIZE
170 {
171 .name = "window_size",
172 .lname = "Window Size",
173 .type = FIO_OPT_INT,
174 .off1 = offsetof(struct netio_options, window_size),
175 .minval = 0,
176 .help = "Set socket buffer window size",
177 .category = FIO_OPT_C_ENGINE,
178 .group = FIO_OPT_G_NETIO,
179 },
180#endif
Shawn Bohrerd3a623d2013-07-19 13:24:08 -0500181 {
Steven Langde890a12011-11-09 14:03:34 +0100182 .name = NULL,
183 },
184};
185
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800186static inline int is_udp(struct netio_options *o)
187{
188 return o->proto == FIO_TYPE_UDP || o->proto == FIO_TYPE_UDP_V6;
189}
190
191static inline int is_tcp(struct netio_options *o)
192{
193 return o->proto == FIO_TYPE_TCP || o->proto == FIO_TYPE_TCP_V6;
194}
195
196static inline int is_ipv6(struct netio_options *o)
197{
198 return o->proto == FIO_TYPE_UDP_V6 || o->proto == FIO_TYPE_TCP_V6;
199}
200
Jens Axboe531e67a2014-10-09 11:55:16 -0600201static int set_window_size(struct thread_data *td, int fd)
202{
203#ifdef CONFIG_NET_WINDOWSIZE
204 struct netio_options *o = td->eo;
205 unsigned int wss;
206 int snd, rcv, ret;
207
208 if (!o->window_size)
209 return 0;
210
211 rcv = o->listen || o->pingpong;
212 snd = !o->listen || o->pingpong;
213 wss = o->window_size;
214 ret = 0;
215
216 if (rcv) {
217 ret = setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (void *) &wss,
218 sizeof(wss));
219 if (ret < 0)
220 td_verror(td, errno, "rcvbuf window size");
221 }
222 if (snd && !ret) {
223 ret = setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (void *) &wss,
224 sizeof(wss));
225 if (ret < 0)
226 td_verror(td, errno, "sndbuf window size");
227 }
228
229 return ret;
230#else
231 td_verror(td, -EINVAL, "setsockopt window size");
232 return -1;
233#endif
234}
235
Jens Axboe371d4562009-01-19 10:17:06 +0100236/*
237 * Return -1 for error and 'nr events' for a positive number
238 * of events
239 */
240static int poll_wait(struct thread_data *td, int fd, short events)
241{
242 struct pollfd pfd;
243 int ret;
244
245 while (!td->terminate) {
246 pfd.fd = fd;
247 pfd.events = events;
248 ret = poll(&pfd, 1, -1);
249 if (ret < 0) {
250 if (errno == EINTR)
Jens Axboed5b388a2009-01-19 12:38:27 +0100251 break;
Jens Axboe371d4562009-01-19 10:17:06 +0100252
253 td_verror(td, errno, "poll");
254 return -1;
255 } else if (!ret)
256 continue;
257
258 break;
259 }
260
261 if (pfd.revents & events)
262 return 1;
Jens Axboe371d4562009-01-19 10:17:06 +0100263
264 return -1;
265}
266
Shawn Bohrerb511c9a2013-07-19 13:24:06 -0500267static int fio_netio_is_multicast(const char *mcaddr)
268{
269 in_addr_t addr = inet_network(mcaddr);
270 if (addr == -1)
271 return 0;
272
273 if (inet_network("224.0.0.0") <= addr &&
274 inet_network("239.255.255.255") >= addr)
275 return 1;
276
277 return 0;
278}
279
280
Jens Axboeed92ac02007-02-06 14:43:52 +0100281static int fio_netio_prep(struct thread_data *td, struct io_u *io_u)
282{
Steven Langde890a12011-11-09 14:03:34 +0100283 struct netio_options *o = td->eo;
Jens Axboeed92ac02007-02-06 14:43:52 +0100284
Jens Axboe7a6499d2007-02-07 09:35:29 +0100285 /*
286 * Make sure we don't see spurious reads to a receiver, and vice versa
287 */
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800288 if (is_tcp(o))
Steven Langde890a12011-11-09 14:03:34 +0100289 return 0;
290
291 if ((o->listen && io_u->ddir == DDIR_WRITE) ||
292 (!o->listen && io_u->ddir == DDIR_READ)) {
Jens Axboee1161c32007-02-22 19:36:48 +0100293 td_verror(td, EINVAL, "bad direction");
Jens Axboe7a6499d2007-02-07 09:35:29 +0100294 return 1;
Jens Axboeed92ac02007-02-06 14:43:52 +0100295 }
Bruce Cran3f457be2012-10-10 13:37:41 +0100296
Jens Axboef85ac252008-03-01 18:09:49 +0100297 return 0;
Jens Axboeed92ac02007-02-06 14:43:52 +0100298}
299
Jens Axboe67bf9822013-01-10 11:23:19 +0100300#ifdef CONFIG_LINUX_SPLICE
Jens Axboecd963e12007-06-24 21:41:46 +0200301static int splice_io_u(int fdin, int fdout, unsigned int len)
Jens Axboe9cce02e2007-06-22 15:42:21 +0200302{
Jens Axboe9cce02e2007-06-22 15:42:21 +0200303 int bytes = 0;
304
305 while (len) {
Jens Axboecd963e12007-06-24 21:41:46 +0200306 int ret = splice(fdin, NULL, fdout, NULL, len, 0);
Jens Axboe9cce02e2007-06-22 15:42:21 +0200307
308 if (ret < 0) {
309 if (!bytes)
310 bytes = ret;
311
312 break;
313 } else if (!ret)
314 break;
315
316 bytes += ret;
Jens Axboef657a2f2007-06-22 20:40:10 +0200317 len -= ret;
Jens Axboe9cce02e2007-06-22 15:42:21 +0200318 }
319
320 return bytes;
321}
322
323/*
Jens Axboecd963e12007-06-24 21:41:46 +0200324 * Receive bytes from a socket and fill them into the internal pipe
325 */
326static int splice_in(struct thread_data *td, struct io_u *io_u)
327{
328 struct netio_data *nd = td->io_ops->data;
329
330 return splice_io_u(io_u->file->fd, nd->pipes[1], io_u->xfer_buflen);
331}
332
333/*
Jens Axboe9cce02e2007-06-22 15:42:21 +0200334 * Transmit 'len' bytes from the internal pipe
335 */
336static int splice_out(struct thread_data *td, struct io_u *io_u,
337 unsigned int len)
338{
339 struct netio_data *nd = td->io_ops->data;
Jens Axboecd963e12007-06-24 21:41:46 +0200340
341 return splice_io_u(nd->pipes[0], io_u->file->fd, len);
342}
343
344static int vmsplice_io_u(struct io_u *io_u, int fd, unsigned int len)
345{
346 struct iovec iov = {
347 .iov_base = io_u->xfer_buf,
348 .iov_len = len,
349 };
Jens Axboe9cce02e2007-06-22 15:42:21 +0200350 int bytes = 0;
351
Jens Axboecd963e12007-06-24 21:41:46 +0200352 while (iov.iov_len) {
353 int ret = vmsplice(fd, &iov, 1, SPLICE_F_MOVE);
Jens Axboe9cce02e2007-06-22 15:42:21 +0200354
355 if (ret < 0) {
356 if (!bytes)
357 bytes = ret;
Jens Axboe9cce02e2007-06-22 15:42:21 +0200358 break;
359 } else if (!ret)
360 break;
361
Jens Axboecd963e12007-06-24 21:41:46 +0200362 iov.iov_len -= ret;
363 iov.iov_base += ret;
Jens Axboe9cce02e2007-06-22 15:42:21 +0200364 bytes += ret;
Jens Axboe9cce02e2007-06-22 15:42:21 +0200365 }
366
367 return bytes;
Jens Axboecd963e12007-06-24 21:41:46 +0200368
Jens Axboe9cce02e2007-06-22 15:42:21 +0200369}
370
371/*
372 * vmsplice() pipe to io_u buffer
373 */
374static int vmsplice_io_u_out(struct thread_data *td, struct io_u *io_u,
375 unsigned int len)
376{
377 struct netio_data *nd = td->io_ops->data;
Jens Axboe9cce02e2007-06-22 15:42:21 +0200378
Jens Axboecd963e12007-06-24 21:41:46 +0200379 return vmsplice_io_u(io_u, nd->pipes[0], len);
Jens Axboe9cce02e2007-06-22 15:42:21 +0200380}
381
382/*
383 * vmsplice() io_u to pipe
384 */
385static int vmsplice_io_u_in(struct thread_data *td, struct io_u *io_u)
386{
387 struct netio_data *nd = td->io_ops->data;
Jens Axboe9cce02e2007-06-22 15:42:21 +0200388
Jens Axboecd963e12007-06-24 21:41:46 +0200389 return vmsplice_io_u(io_u, nd->pipes[1], io_u->xfer_buflen);
Jens Axboe9cce02e2007-06-22 15:42:21 +0200390}
391
Jens Axboecd963e12007-06-24 21:41:46 +0200392/*
393 * splice receive - transfer socket data into a pipe using splice, then map
394 * that pipe data into the io_u using vmsplice.
395 */
Jens Axboe9cce02e2007-06-22 15:42:21 +0200396static int fio_netio_splice_in(struct thread_data *td, struct io_u *io_u)
397{
398 int ret;
399
400 ret = splice_in(td, io_u);
Jens Axboecd963e12007-06-24 21:41:46 +0200401 if (ret > 0)
402 return vmsplice_io_u_out(td, io_u, ret);
Jens Axboe9cce02e2007-06-22 15:42:21 +0200403
Jens Axboecd963e12007-06-24 21:41:46 +0200404 return ret;
Jens Axboe9cce02e2007-06-22 15:42:21 +0200405}
406
Jens Axboecd963e12007-06-24 21:41:46 +0200407/*
408 * splice transmit - map data from the io_u into a pipe by using vmsplice,
409 * then transfer that pipe to a socket using splice.
410 */
Jens Axboe9cce02e2007-06-22 15:42:21 +0200411static int fio_netio_splice_out(struct thread_data *td, struct io_u *io_u)
412{
413 int ret;
414
415 ret = vmsplice_io_u_in(td, io_u);
Jens Axboecd963e12007-06-24 21:41:46 +0200416 if (ret > 0)
417 return splice_out(td, io_u, ret);
Jens Axboe9cce02e2007-06-22 15:42:21 +0200418
Jens Axboecd963e12007-06-24 21:41:46 +0200419 return ret;
Jens Axboe9cce02e2007-06-22 15:42:21 +0200420}
Jens Axboe5921e802008-05-30 15:02:38 +0200421#else
422static int fio_netio_splice_in(struct thread_data *td, struct io_u *io_u)
423{
Jens Axboeaf8771b2008-05-30 22:58:28 +0200424 errno = EOPNOTSUPP;
Jens Axboe5921e802008-05-30 15:02:38 +0200425 return -1;
426}
427
428static int fio_netio_splice_out(struct thread_data *td, struct io_u *io_u)
429{
Jens Axboeaf8771b2008-05-30 22:58:28 +0200430 errno = EOPNOTSUPP;
Jens Axboe5921e802008-05-30 15:02:38 +0200431 return -1;
432}
433#endif
Jens Axboe9cce02e2007-06-22 15:42:21 +0200434
435static int fio_netio_send(struct thread_data *td, struct io_u *io_u)
436{
Jens Axboe414c2a32009-01-16 13:21:15 +0100437 struct netio_data *nd = td->io_ops->data;
Steven Langde890a12011-11-09 14:03:34 +0100438 struct netio_options *o = td->eo;
Jens Axboe6f73a7f2012-11-30 09:59:20 +0100439 int ret, flags = 0;
Jens Axboe371d4562009-01-19 10:17:06 +0100440
Jens Axboe664fb3b2009-01-19 13:26:36 +0100441 do {
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800442 if (is_udp(o)) {
Jens Axboe10aa1362014-04-01 21:10:36 -0600443 const struct sockaddr *to;
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800444 socklen_t len;
445
446 if (is_ipv6(o)) {
447 to = (struct sockaddr *) &nd->addr6;
448 len = sizeof(nd->addr6);
449 } else {
450 to = (struct sockaddr *) &nd->addr;
451 len = sizeof(nd->addr);
452 }
Jens Axboe62b38922009-05-11 10:37:33 +0200453
Jens Axboe664fb3b2009-01-19 13:26:36 +0100454 ret = sendto(io_u->file->fd, io_u->xfer_buf,
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800455 io_u->xfer_buflen, flags, to, len);
Jens Axboe664fb3b2009-01-19 13:26:36 +0100456 } else {
457 /*
458 * if we are going to write more, set MSG_MORE
459 */
Jens Axboe5921e802008-05-30 15:02:38 +0200460#ifdef MSG_MORE
Jens Axboe6f73a7f2012-11-30 09:59:20 +0100461 if ((td->this_io_bytes[DDIR_WRITE] + io_u->xfer_buflen <
462 td->o.size) && !o->pingpong)
Jens Axboe664fb3b2009-01-19 13:26:36 +0100463 flags |= MSG_MORE;
Jens Axboe5921e802008-05-30 15:02:38 +0200464#endif
Jens Axboe664fb3b2009-01-19 13:26:36 +0100465 ret = send(io_u->file->fd, io_u->xfer_buf,
466 io_u->xfer_buflen, flags);
467 }
468 if (ret > 0)
469 break;
Jens Axboe9cce02e2007-06-22 15:42:21 +0200470
Jens Axboe664fb3b2009-01-19 13:26:36 +0100471 ret = poll_wait(td, io_u->file->fd, POLLOUT);
472 if (ret <= 0)
473 break;
Jens Axboe664fb3b2009-01-19 13:26:36 +0100474 } while (1);
475
476 return ret;
477}
478
479static int is_udp_close(struct io_u *io_u, int len)
480{
481 struct udp_close_msg *msg;
482
483 if (len != sizeof(struct udp_close_msg))
484 return 0;
485
486 msg = io_u->xfer_buf;
Jens Axboeb96d2432012-11-30 08:27:46 +0100487 if (ntohl(msg->magic) != FIO_LINK_OPEN_CLOSE_MAGIC)
Jens Axboe664fb3b2009-01-19 13:26:36 +0100488 return 0;
489 if (ntohl(msg->cmd) != FIO_LINK_CLOSE)
490 return 0;
491
492 return 1;
Jens Axboe9cce02e2007-06-22 15:42:21 +0200493}
494
Jens Axboe414c2a32009-01-16 13:21:15 +0100495static int fio_netio_recv(struct thread_data *td, struct io_u *io_u)
Jens Axboe9cce02e2007-06-22 15:42:21 +0200496{
Jens Axboe414c2a32009-01-16 13:21:15 +0100497 struct netio_data *nd = td->io_ops->data;
Steven Langde890a12011-11-09 14:03:34 +0100498 struct netio_options *o = td->eo;
Jens Axboe6f73a7f2012-11-30 09:59:20 +0100499 int ret, flags = 0;
Jens Axboe371d4562009-01-19 10:17:06 +0100500
Jens Axboe664fb3b2009-01-19 13:26:36 +0100501 do {
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800502 if (is_udp(o)) {
Shawn Bohrerb511c9a2013-07-19 13:24:06 -0500503 struct sockaddr *from;
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800504 socklen_t l, *len = &l;
Shawn Bohrerb511c9a2013-07-19 13:24:06 -0500505
506 if (o->listen) {
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800507 if (!is_ipv6(o)) {
508 from = (struct sockaddr *) &nd->addr;
509 *len = sizeof(nd->addr);
510 } else {
511 from = (struct sockaddr *) &nd->addr6;
512 *len = sizeof(nd->addr6);
513 }
Shawn Bohrerb511c9a2013-07-19 13:24:06 -0500514 } else {
515 from = NULL;
516 len = NULL;
517 }
Jens Axboe9cce02e2007-06-22 15:42:21 +0200518
Jens Axboe664fb3b2009-01-19 13:26:36 +0100519 ret = recvfrom(io_u->file->fd, io_u->xfer_buf,
Shawn Bohrerb511c9a2013-07-19 13:24:06 -0500520 io_u->xfer_buflen, flags, from, len);
Jens Axboe664fb3b2009-01-19 13:26:36 +0100521 if (is_udp_close(io_u, ret)) {
522 td->done = 1;
523 return 0;
524 }
525 } else {
526 ret = recv(io_u->file->fd, io_u->xfer_buf,
527 io_u->xfer_buflen, flags);
528 }
529 if (ret > 0)
530 break;
Jens Axboe7d988f62012-11-29 19:57:35 +0100531 else if (!ret && (flags & MSG_WAITALL))
532 break;
Jens Axboe414c2a32009-01-16 13:21:15 +0100533
Jens Axboe664fb3b2009-01-19 13:26:36 +0100534 ret = poll_wait(td, io_u->file->fd, POLLIN);
535 if (ret <= 0)
536 break;
Jens Axboe664fb3b2009-01-19 13:26:36 +0100537 flags |= MSG_WAITALL;
538 } while (1);
539
540 return ret;
Jens Axboe9cce02e2007-06-22 15:42:21 +0200541}
542
Jens Axboe6f73a7f2012-11-30 09:59:20 +0100543static int __fio_netio_queue(struct thread_data *td, struct io_u *io_u,
544 enum fio_ddir ddir)
Jens Axboeed92ac02007-02-06 14:43:52 +0100545{
Jens Axboe9cce02e2007-06-22 15:42:21 +0200546 struct netio_data *nd = td->io_ops->data;
Steven Langde890a12011-11-09 14:03:34 +0100547 struct netio_options *o = td->eo;
Jens Axboe9cce02e2007-06-22 15:42:21 +0200548 int ret;
Jens Axboeed92ac02007-02-06 14:43:52 +0100549
Jens Axboe6f73a7f2012-11-30 09:59:20 +0100550 if (ddir == DDIR_WRITE) {
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800551 if (!nd->use_splice || is_udp(o) ||
Steven Langde890a12011-11-09 14:03:34 +0100552 o->proto == FIO_TYPE_UNIX)
Jens Axboe9cce02e2007-06-22 15:42:21 +0200553 ret = fio_netio_send(td, io_u);
Jens Axboe9cce02e2007-06-22 15:42:21 +0200554 else
Jens Axboe414c2a32009-01-16 13:21:15 +0100555 ret = fio_netio_splice_out(td, io_u);
Jens Axboe6f73a7f2012-11-30 09:59:20 +0100556 } else if (ddir == DDIR_READ) {
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800557 if (!nd->use_splice || is_udp(o) ||
Steven Langde890a12011-11-09 14:03:34 +0100558 o->proto == FIO_TYPE_UNIX)
Jens Axboe414c2a32009-01-16 13:21:15 +0100559 ret = fio_netio_recv(td, io_u);
560 else
561 ret = fio_netio_splice_in(td, io_u);
Jens Axboed4f12dd2007-02-08 12:59:02 +0100562 } else
Jens Axboe7a6499d2007-02-07 09:35:29 +0100563 ret = 0; /* must be a SYNC */
Jens Axboeed92ac02007-02-06 14:43:52 +0100564
Jens Axboecec6b552007-02-06 20:15:38 +0100565 if (ret != (int) io_u->xfer_buflen) {
Jens Axboe0ecdd7f2014-10-08 17:04:29 -0600566 if (ret > 0) {
Jens Axboecec6b552007-02-06 20:15:38 +0100567 io_u->resid = io_u->xfer_buflen - ret;
568 io_u->error = 0;
Jens Axboe36167d82007-02-18 05:41:31 +0100569 return FIO_Q_COMPLETED;
Jens Axboe0ecdd7f2014-10-08 17:04:29 -0600570 } else if (!ret)
571 return FIO_Q_BUSY;
572 else {
Jens Axboe414c2a32009-01-16 13:21:15 +0100573 int err = errno;
574
Jens Axboe6f73a7f2012-11-30 09:59:20 +0100575 if (ddir == DDIR_WRITE && err == EMSGSIZE)
Jens Axboe414c2a32009-01-16 13:21:15 +0100576 return FIO_Q_BUSY;
577
578 io_u->error = err;
579 }
Jens Axboeed92ac02007-02-06 14:43:52 +0100580 }
581
Jens Axboe36167d82007-02-18 05:41:31 +0100582 if (io_u->error)
Jens Axboee1161c32007-02-22 19:36:48 +0100583 td_verror(td, io_u->error, "xfer");
Jens Axboeed92ac02007-02-06 14:43:52 +0100584
Jens Axboe36167d82007-02-18 05:41:31 +0100585 return FIO_Q_COMPLETED;
Jens Axboeed92ac02007-02-06 14:43:52 +0100586}
587
Jens Axboe6f73a7f2012-11-30 09:59:20 +0100588static int fio_netio_queue(struct thread_data *td, struct io_u *io_u)
589{
590 struct netio_options *o = td->eo;
591 int ret;
592
593 fio_ro_check(td, io_u);
594
595 ret = __fio_netio_queue(td, io_u, io_u->ddir);
596 if (!o->pingpong || ret != FIO_Q_COMPLETED)
597 return ret;
598
599 /*
600 * For ping-pong mode, receive or send reply as needed
601 */
602 if (td_read(td) && io_u->ddir == DDIR_READ)
603 ret = __fio_netio_queue(td, io_u, DDIR_WRITE);
604 else if (td_write(td) && io_u->ddir == DDIR_WRITE)
605 ret = __fio_netio_queue(td, io_u, DDIR_READ);
606
607 return ret;
608}
609
Jens Axboeb5af8292007-03-08 12:43:13 +0100610static int fio_netio_connect(struct thread_data *td, struct fio_file *f)
Jens Axboeed92ac02007-02-06 14:43:52 +0100611{
Jens Axboeb5af8292007-03-08 12:43:13 +0100612 struct netio_data *nd = td->io_ops->data;
Steven Langde890a12011-11-09 14:03:34 +0100613 struct netio_options *o = td->eo;
Jens Axboe6264c7a2013-02-28 08:24:23 +0100614 int type, domain;
Jens Axboeed92ac02007-02-06 14:43:52 +0100615
Steven Langde890a12011-11-09 14:03:34 +0100616 if (o->proto == FIO_TYPE_TCP) {
Jens Axboe0fd666b2011-10-06 20:08:53 +0200617 domain = AF_INET;
Jens Axboe414c2a32009-01-16 13:21:15 +0100618 type = SOCK_STREAM;
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800619 } else if (o->proto == FIO_TYPE_TCP_V6) {
620 domain = AF_INET6;
621 type = SOCK_STREAM;
Steven Langde890a12011-11-09 14:03:34 +0100622 } else if (o->proto == FIO_TYPE_UDP) {
Jens Axboe0fd666b2011-10-06 20:08:53 +0200623 domain = AF_INET;
Jens Axboe414c2a32009-01-16 13:21:15 +0100624 type = SOCK_DGRAM;
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800625 } else if (o->proto == FIO_TYPE_UDP_V6) {
626 domain = AF_INET6;
627 type = SOCK_DGRAM;
Steven Langde890a12011-11-09 14:03:34 +0100628 } else if (o->proto == FIO_TYPE_UNIX) {
Jens Axboe0fd666b2011-10-06 20:08:53 +0200629 domain = AF_UNIX;
630 type = SOCK_STREAM;
631 } else {
Steven Langde890a12011-11-09 14:03:34 +0100632 log_err("fio: bad network type %d\n", o->proto);
Jens Axboe0fd666b2011-10-06 20:08:53 +0200633 f->fd = -1;
634 return 1;
635 }
Jens Axboe414c2a32009-01-16 13:21:15 +0100636
Jens Axboe0fd666b2011-10-06 20:08:53 +0200637 f->fd = socket(domain, type, 0);
Jens Axboeb5af8292007-03-08 12:43:13 +0100638 if (f->fd < 0) {
639 td_verror(td, errno, "socket");
640 return 1;
Jens Axboeed92ac02007-02-06 14:43:52 +0100641 }
642
Jens Axboe1eafa372013-01-31 10:19:51 +0100643#ifdef CONFIG_TCP_NODELAY
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800644 if (o->nodelay && is_tcp(o)) {
Jens Axboe6264c7a2013-02-28 08:24:23 +0100645 int optval = 1;
646
Jens Axboe26e594a2013-01-30 21:52:37 +0100647 if (setsockopt(f->fd, IPPROTO_TCP, TCP_NODELAY, (void *) &optval, sizeof(int)) < 0) {
Steven Noonan70a78782012-11-28 14:52:36 -0800648 log_err("fio: cannot set TCP_NODELAY option on socket (%s), disable with 'nodelay=0'\n", strerror(errno));
649 return 1;
650 }
651 }
Jens Axboe1eafa372013-01-31 10:19:51 +0100652#endif
Steven Noonan70a78782012-11-28 14:52:36 -0800653
Jens Axboe531e67a2014-10-09 11:55:16 -0600654 if (set_window_size(td, f->fd)) {
655 close(f->fd);
656 return 1;
657 }
658
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800659 if (is_udp(o)) {
Shawn Bohrerd3a623d2013-07-19 13:24:08 -0500660 if (!fio_netio_is_multicast(td->o.filename))
661 return 0;
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800662 if (is_ipv6(o)) {
663 log_err("fio: multicast not supported on IPv6\n");
664 close(f->fd);
665 return 1;
666 }
Shawn Bohrerd3a623d2013-07-19 13:24:08 -0500667
Bruce Cranf16b7402013-10-08 15:05:27 +0100668 if (o->intfc) {
Shawn Bohrerb93b6a22013-07-19 13:24:07 -0500669 struct in_addr interface_addr;
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800670
Bruce Cranf16b7402013-10-08 15:05:27 +0100671 if (inet_aton(o->intfc, &interface_addr) == 0) {
Shawn Bohrerb93b6a22013-07-19 13:24:07 -0500672 log_err("fio: interface not valid interface IP\n");
673 close(f->fd);
674 return 1;
675 }
Bruce Cranf16b7402013-10-08 15:05:27 +0100676 if (setsockopt(f->fd, IPPROTO_IP, IP_MULTICAST_IF, (const char*)&interface_addr, sizeof(interface_addr)) < 0) {
Shawn Bohrerb93b6a22013-07-19 13:24:07 -0500677 td_verror(td, errno, "setsockopt IP_MULTICAST_IF");
678 close(f->fd);
679 return 1;
680 }
681 }
Bruce Cranf16b7402013-10-08 15:05:27 +0100682 if (setsockopt(f->fd, IPPROTO_IP, IP_MULTICAST_TTL, (const char*)&o->ttl, sizeof(o->ttl)) < 0) {
Shawn Bohrerd3a623d2013-07-19 13:24:08 -0500683 td_verror(td, errno, "setsockopt IP_MULTICAST_TTL");
684 close(f->fd);
685 return 1;
686 }
Jens Axboe414c2a32009-01-16 13:21:15 +0100687 return 0;
Shawn Bohrerb93b6a22013-07-19 13:24:07 -0500688 } else if (o->proto == FIO_TYPE_TCP) {
Jens Axboe67bf9822013-01-10 11:23:19 +0100689 socklen_t len = sizeof(nd->addr);
Jens Axboe414c2a32009-01-16 13:21:15 +0100690
Jens Axboe0fd666b2011-10-06 20:08:53 +0200691 if (connect(f->fd, (struct sockaddr *) &nd->addr, len) < 0) {
692 td_verror(td, errno, "connect");
Jens Axboeb94cba42011-10-06 21:27:10 +0200693 close(f->fd);
Jens Axboe0fd666b2011-10-06 20:08:53 +0200694 return 1;
695 }
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800696 } else if (o->proto == FIO_TYPE_TCP_V6) {
697 socklen_t len = sizeof(nd->addr6);
698
699 if (connect(f->fd, (struct sockaddr *) &nd->addr6, len) < 0) {
700 td_verror(td, errno, "connect");
701 close(f->fd);
702 return 1;
703 }
704
Jens Axboe0fd666b2011-10-06 20:08:53 +0200705 } else {
706 struct sockaddr_un *addr = &nd->addr_un;
Jens Axboe67bf9822013-01-10 11:23:19 +0100707 socklen_t len;
Jens Axboe0fd666b2011-10-06 20:08:53 +0200708
709 len = sizeof(addr->sun_family) + strlen(addr->sun_path) + 1;
710
711 if (connect(f->fd, (struct sockaddr *) addr, len) < 0) {
712 td_verror(td, errno, "connect");
Jens Axboeb94cba42011-10-06 21:27:10 +0200713 close(f->fd);
Jens Axboe0fd666b2011-10-06 20:08:53 +0200714 return 1;
715 }
Jens Axboeed92ac02007-02-06 14:43:52 +0100716 }
717
718 return 0;
Jens Axboeed92ac02007-02-06 14:43:52 +0100719}
720
Jens Axboeb5af8292007-03-08 12:43:13 +0100721static int fio_netio_accept(struct thread_data *td, struct fio_file *f)
Jens Axboe5fdd1242007-02-11 04:00:37 +0100722{
Jens Axboeb5af8292007-03-08 12:43:13 +0100723 struct netio_data *nd = td->io_ops->data;
Steven Langde890a12011-11-09 14:03:34 +0100724 struct netio_options *o = td->eo;
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800725 socklen_t socklen;
Jens Axboe6264c7a2013-02-28 08:24:23 +0100726 int state;
Jens Axboe5fdd1242007-02-11 04:00:37 +0100727
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800728 if (is_udp(o)) {
Jens Axboe414c2a32009-01-16 13:21:15 +0100729 f->fd = nd->listenfd;
730 return 0;
731 }
732
Jens Axboe859088d2012-11-29 20:02:50 +0100733 state = td->runstate;
734 td_set_runstate(td, TD_SETTING_UP);
735
Jens Axboe6d861442007-03-15 09:22:23 +0100736 log_info("fio: waiting for connection\n");
Jens Axboe5fdd1242007-02-11 04:00:37 +0100737
Jens Axboe371d4562009-01-19 10:17:06 +0100738 if (poll_wait(td, nd->listenfd, POLLIN) < 0)
Jens Axboe859088d2012-11-29 20:02:50 +0100739 goto err;
Jens Axboe5fdd1242007-02-11 04:00:37 +0100740
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800741 if (o->proto == FIO_TYPE_TCP) {
742 socklen = sizeof(nd->addr);
743 f->fd = accept(nd->listenfd, (struct sockaddr *) &nd->addr, &socklen);
744 } else {
745 socklen = sizeof(nd->addr6);
746 f->fd = accept(nd->listenfd, (struct sockaddr *) &nd->addr6, &socklen);
747 }
748
Jens Axboe371d4562009-01-19 10:17:06 +0100749 if (f->fd < 0) {
750 td_verror(td, errno, "accept");
Jens Axboe859088d2012-11-29 20:02:50 +0100751 goto err;
Jens Axboe5fdd1242007-02-11 04:00:37 +0100752 }
753
Jens Axboe1eafa372013-01-31 10:19:51 +0100754#ifdef CONFIG_TCP_NODELAY
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800755 if (o->nodelay && is_tcp(o)) {
Jens Axboe6264c7a2013-02-28 08:24:23 +0100756 int optval = 1;
757
Jens Axboe26e594a2013-01-30 21:52:37 +0100758 if (setsockopt(f->fd, IPPROTO_TCP, TCP_NODELAY, (void *) &optval, sizeof(int)) < 0) {
Steven Noonan70a78782012-11-28 14:52:36 -0800759 log_err("fio: cannot set TCP_NODELAY option on socket (%s), disable with 'nodelay=0'\n", strerror(errno));
760 return 1;
761 }
762 }
Jens Axboe1eafa372013-01-31 10:19:51 +0100763#endif
Steven Noonan70a78782012-11-28 14:52:36 -0800764
Jens Axboe0cae16f2012-11-30 16:22:31 +0100765 reset_all_stats(td);
Jens Axboe859088d2012-11-29 20:02:50 +0100766 td_set_runstate(td, state);
Jens Axboe5fdd1242007-02-11 04:00:37 +0100767 return 0;
Jens Axboe859088d2012-11-29 20:02:50 +0100768err:
769 td_set_runstate(td, state);
770 return 1;
Jens Axboeb5af8292007-03-08 12:43:13 +0100771}
772
Jens Axboe664fb3b2009-01-19 13:26:36 +0100773static void fio_netio_udp_close(struct thread_data *td, struct fio_file *f)
774{
775 struct netio_data *nd = td->io_ops->data;
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800776 struct netio_options *o = td->eo;
Jens Axboe664fb3b2009-01-19 13:26:36 +0100777 struct udp_close_msg msg;
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800778 struct sockaddr *to;
779 socklen_t len;
Jens Axboe664fb3b2009-01-19 13:26:36 +0100780 int ret;
781
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800782 if (is_ipv6(o)) {
783 to = (struct sockaddr *) &nd->addr6;
784 len = sizeof(nd->addr6);
785 } else {
786 to = (struct sockaddr *) &nd->addr;
787 len = sizeof(nd->addr);
788 }
789
Jens Axboeb96d2432012-11-30 08:27:46 +0100790 msg.magic = htonl(FIO_LINK_OPEN_CLOSE_MAGIC);
Jens Axboe664fb3b2009-01-19 13:26:36 +0100791 msg.cmd = htonl(FIO_LINK_CLOSE);
792
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800793 ret = sendto(f->fd, (void *) &msg, sizeof(msg), MSG_WAITALL, to, len);
Jens Axboe664fb3b2009-01-19 13:26:36 +0100794 if (ret < 0)
795 td_verror(td, errno, "sendto udp link close");
796}
797
798static int fio_netio_close_file(struct thread_data *td, struct fio_file *f)
799{
Steven Langde890a12011-11-09 14:03:34 +0100800 struct netio_options *o = td->eo;
Jens Axboe664fb3b2009-01-19 13:26:36 +0100801
802 /*
803 * If this is an UDP connection, notify the receiver that we are
804 * closing down the link
805 */
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800806 if (is_udp(o))
Jens Axboe664fb3b2009-01-19 13:26:36 +0100807 fio_netio_udp_close(td, f);
808
809 return generic_close_file(td, f);
810}
811
Jens Axboeb96d2432012-11-30 08:27:46 +0100812static int fio_netio_udp_recv_open(struct thread_data *td, struct fio_file *f)
813{
814 struct netio_data *nd = td->io_ops->data;
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800815 struct netio_options *o = td->eo;
Jens Axboeb96d2432012-11-30 08:27:46 +0100816 struct udp_close_msg msg;
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800817 struct sockaddr *to;
818 socklen_t len;
Jens Axboeb96d2432012-11-30 08:27:46 +0100819 int ret;
820
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800821 if (is_ipv6(o)) {
822 len = sizeof(nd->addr6);
823 to = (struct sockaddr *) &nd->addr6;
824 } else {
825 len = sizeof(nd->addr);
826 to = (struct sockaddr *) &nd->addr;
827 }
828
Jens Axboe1f819912013-01-23 17:21:41 -0700829 ret = recvfrom(f->fd, (void *) &msg, sizeof(msg), MSG_WAITALL, to, &len);
Jens Axboeb96d2432012-11-30 08:27:46 +0100830 if (ret < 0) {
Shawn Bohreree7062f2013-07-19 13:24:09 -0500831 td_verror(td, errno, "recvfrom udp link open");
Jens Axboeb96d2432012-11-30 08:27:46 +0100832 return ret;
833 }
834
835 if (ntohl(msg.magic) != FIO_LINK_OPEN_CLOSE_MAGIC ||
836 ntohl(msg.cmd) != FIO_LINK_OPEN) {
837 log_err("fio: bad udp open magic %x/%x\n", ntohl(msg.magic),
838 ntohl(msg.cmd));
839 return -1;
840 }
841
842 return 0;
843}
844
845static int fio_netio_udp_send_open(struct thread_data *td, struct fio_file *f)
846{
847 struct netio_data *nd = td->io_ops->data;
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800848 struct netio_options *o = td->eo;
Jens Axboeb96d2432012-11-30 08:27:46 +0100849 struct udp_close_msg msg;
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800850 struct sockaddr *to;
851 socklen_t len;
Jens Axboeb96d2432012-11-30 08:27:46 +0100852 int ret;
853
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800854 if (is_ipv6(o)) {
855 len = sizeof(nd->addr6);
856 to = (struct sockaddr *) &nd->addr6;
857 } else {
858 len = sizeof(nd->addr);
859 to = (struct sockaddr *) &nd->addr;
860 }
861
Jens Axboeb96d2432012-11-30 08:27:46 +0100862 msg.magic = htonl(FIO_LINK_OPEN_CLOSE_MAGIC);
863 msg.cmd = htonl(FIO_LINK_OPEN);
864
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800865 ret = sendto(f->fd, (void *) &msg, sizeof(msg), MSG_WAITALL, to, len);
Jens Axboeb96d2432012-11-30 08:27:46 +0100866 if (ret < 0) {
867 td_verror(td, errno, "sendto udp link open");
868 return ret;
869 }
870
871 return 0;
872}
873
874static int fio_netio_open_file(struct thread_data *td, struct fio_file *f)
875{
876 int ret;
877 struct netio_options *o = td->eo;
878
879 if (o->listen)
880 ret = fio_netio_accept(td, f);
881 else
882 ret = fio_netio_connect(td, f);
883
884 if (ret) {
885 f->fd = -1;
886 return ret;
887 }
888
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800889 if (is_udp(o)) {
Jens Axboeb96d2432012-11-30 08:27:46 +0100890 if (td_write(td))
891 ret = fio_netio_udp_send_open(td, f);
892 else {
893 int state;
894
895 state = td->runstate;
896 td_set_runstate(td, TD_SETTING_UP);
897 ret = fio_netio_udp_recv_open(td, f);
898 td_set_runstate(td, state);
899 }
900 }
901
902 if (ret)
903 fio_netio_close_file(td, f);
904
905 return ret;
906}
907
Jens Axboe0b783342014-01-23 20:19:17 -0800908static int fio_fill_addr(struct thread_data *td, const char *host, int af,
909 void *dst, struct addrinfo **res)
910{
911 struct netio_options *o = td->eo;
912 struct addrinfo hints;
913 int ret;
914
915 if (inet_pton(af, host, dst))
916 return 0;
917
918 memset(&hints, 0, sizeof(hints));
Jens Axboe0b783342014-01-23 20:19:17 -0800919
920 if (is_tcp(o))
921 hints.ai_socktype = SOCK_STREAM;
922 else
923 hints.ai_socktype = SOCK_DGRAM;
924
Jens Axboeb1b1be22014-01-23 20:41:33 -0800925 if (is_ipv6(o))
926 hints.ai_family = AF_INET6;
927 else
928 hints.ai_family = AF_INET;
929
Jens Axboe0b783342014-01-23 20:19:17 -0800930 ret = getaddrinfo(host, NULL, &hints, res);
931 if (ret) {
932 int e = EINVAL;
933 char str[128];
934
935 if (ret == EAI_SYSTEM)
936 e = errno;
937
938 snprintf(str, sizeof(str), "getaddrinfo: %s", gai_strerror(ret));
939 td_verror(td, e, str);
940 return 1;
941 }
942
943 return 0;
944}
945
Jens Axboe0fd666b2011-10-06 20:08:53 +0200946static int fio_netio_setup_connect_inet(struct thread_data *td,
947 const char *host, unsigned short port)
Jens Axboeb5af8292007-03-08 12:43:13 +0100948{
949 struct netio_data *nd = td->io_ops->data;
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800950 struct netio_options *o = td->eo;
Jens Axboe0b783342014-01-23 20:19:17 -0800951 struct addrinfo *res = NULL;
952 void *dst, *src;
953 int af, len;
Jens Axboeb5af8292007-03-08 12:43:13 +0100954
Jens Axboe166dce42012-11-29 14:35:33 +0100955 if (!host) {
956 log_err("fio: connect with no host to connect to.\n");
957 if (td_read(td))
958 log_err("fio: did you forget to set 'listen'?\n");
959
960 td_verror(td, EINVAL, "no hostname= set");
961 return 1;
962 }
963
Jens Axboe0b783342014-01-23 20:19:17 -0800964 nd->addr.sin_family = AF_INET;
965 nd->addr.sin_port = htons(port);
966 nd->addr6.sin6_family = AF_INET6;
967 nd->addr6.sin6_port = htons(port);
968
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800969 if (is_ipv6(o)) {
Jens Axboe0b783342014-01-23 20:19:17 -0800970 af = AF_INET6;
Jens Axboe68631b32014-02-25 13:43:38 -0800971 dst = &nd->addr6.sin6_addr;
Jens Axboe49ccb8c2014-01-23 16:49:37 -0800972 } else {
Jens Axboe0b783342014-01-23 20:19:17 -0800973 af = AF_INET;
Jens Axboe68631b32014-02-25 13:43:38 -0800974 dst = &nd->addr.sin_addr;
Jens Axboeb5af8292007-03-08 12:43:13 +0100975 }
976
Jens Axboe0b783342014-01-23 20:19:17 -0800977 if (fio_fill_addr(td, host, af, dst, &res))
978 return 1;
979
980 if (!res)
981 return 0;
982
983 if (is_ipv6(o)) {
984 len = sizeof(nd->addr6.sin6_addr);
985 src = &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr;
986 } else {
987 len = sizeof(nd->addr.sin_addr);
988 src = &((struct sockaddr_in *) res->ai_addr)->sin_addr;
989 }
990
991 memcpy(dst, src, len);
992 freeaddrinfo(res);
Jens Axboeb5af8292007-03-08 12:43:13 +0100993 return 0;
994}
995
Jens Axboe0fd666b2011-10-06 20:08:53 +0200996static int fio_netio_setup_connect_unix(struct thread_data *td,
997 const char *path)
998{
999 struct netio_data *nd = td->io_ops->data;
1000 struct sockaddr_un *soun = &nd->addr_un;
1001
1002 soun->sun_family = AF_UNIX;
Jens Axboe4b159fa2014-04-14 08:49:04 -06001003 memset(soun->sun_path, 0, sizeof(soun->sun_path));
1004 strncpy(soun->sun_path, path, sizeof(soun->sun_path) - 1);
Jens Axboe0fd666b2011-10-06 20:08:53 +02001005 return 0;
1006}
1007
Steven Langde890a12011-11-09 14:03:34 +01001008static int fio_netio_setup_connect(struct thread_data *td)
Jens Axboe0fd666b2011-10-06 20:08:53 +02001009{
Steven Langde890a12011-11-09 14:03:34 +01001010 struct netio_options *o = td->eo;
Jens Axboe0fd666b2011-10-06 20:08:53 +02001011
Jens Axboe49ccb8c2014-01-23 16:49:37 -08001012 if (is_udp(o) || is_tcp(o))
Steven Langde890a12011-11-09 14:03:34 +01001013 return fio_netio_setup_connect_inet(td, td->o.filename,o->port);
Jens Axboe0fd666b2011-10-06 20:08:53 +02001014 else
Steven Langde890a12011-11-09 14:03:34 +01001015 return fio_netio_setup_connect_unix(td, td->o.filename);
Jens Axboe0fd666b2011-10-06 20:08:53 +02001016}
1017
1018static int fio_netio_setup_listen_unix(struct thread_data *td, const char *path)
1019{
1020 struct netio_data *nd = td->io_ops->data;
1021 struct sockaddr_un *addr = &nd->addr_un;
1022 mode_t mode;
1023 int len, fd;
1024
1025 fd = socket(AF_UNIX, SOCK_STREAM, 0);
1026 if (fd < 0) {
1027 log_err("fio: socket: %s\n", strerror(errno));
1028 return -1;
1029 }
1030
1031 mode = umask(000);
1032
1033 memset(addr, 0, sizeof(*addr));
1034 addr->sun_family = AF_UNIX;
Jens Axboe4b159fa2014-04-14 08:49:04 -06001035 strncpy(addr->sun_path, path, sizeof(addr->sun_path) - 1);
Jens Axboe0fd666b2011-10-06 20:08:53 +02001036 unlink(path);
1037
1038 len = sizeof(addr->sun_family) + strlen(path) + 1;
1039
1040 if (bind(fd, (struct sockaddr *) addr, len) < 0) {
1041 log_err("fio: bind: %s\n", strerror(errno));
Jens Axboeb94cba42011-10-06 21:27:10 +02001042 close(fd);
Jens Axboe0fd666b2011-10-06 20:08:53 +02001043 return -1;
1044 }
1045
1046 umask(mode);
1047 nd->listenfd = fd;
1048 return 0;
1049}
1050
1051static int fio_netio_setup_listen_inet(struct thread_data *td, short port)
Jens Axboeb5af8292007-03-08 12:43:13 +01001052{
1053 struct netio_data *nd = td->io_ops->data;
Steven Langde890a12011-11-09 14:03:34 +01001054 struct netio_options *o = td->eo;
Shawn Bohrerb511c9a2013-07-19 13:24:06 -05001055 struct ip_mreq mr;
1056 struct sockaddr_in sin;
Jens Axboe49ccb8c2014-01-23 16:49:37 -08001057 struct sockaddr *saddr;
1058 int fd, opt, type, domain;
1059 socklen_t len;
Jens Axboeed92ac02007-02-06 14:43:52 +01001060
Shawn Bohrerb511c9a2013-07-19 13:24:06 -05001061 memset(&sin, 0, sizeof(sin));
Jens Axboe414c2a32009-01-16 13:21:15 +01001062
Jens Axboe49ccb8c2014-01-23 16:49:37 -08001063 if (o->proto == FIO_TYPE_TCP) {
1064 type = SOCK_STREAM;
1065 domain = AF_INET;
1066 } else if (o->proto == FIO_TYPE_TCP_V6) {
1067 type = SOCK_STREAM;
1068 domain = AF_INET6;
1069 } else if (o->proto == FIO_TYPE_UDP) {
1070 type = SOCK_DGRAM;
1071 domain = AF_INET;
1072 } else if (o->proto == FIO_TYPE_UDP_V6) {
1073 type = SOCK_DGRAM;
1074 domain = AF_INET6;
1075 } else {
1076 log_err("fio: unknown proto %d\n", o->proto);
1077 return 1;
1078 }
1079
1080 fd = socket(domain, type, 0);
Jens Axboeed92ac02007-02-06 14:43:52 +01001081 if (fd < 0) {
Jens Axboee1161c32007-02-22 19:36:48 +01001082 td_verror(td, errno, "socket");
Jens Axboeed92ac02007-02-06 14:43:52 +01001083 return 1;
1084 }
1085
1086 opt = 1;
Jens Axboe26e594a2013-01-30 21:52:37 +01001087 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *) &opt, sizeof(opt)) < 0) {
Jens Axboee1161c32007-02-22 19:36:48 +01001088 td_verror(td, errno, "setsockopt");
Shawn Bohrer4a93dec2013-07-19 13:24:10 -05001089 close(fd);
Jens Axboeed92ac02007-02-06 14:43:52 +01001090 return 1;
1091 }
Jens Axboe6bedbfa2007-02-07 09:54:40 +01001092#ifdef SO_REUSEPORT
Jens Axboe26e594a2013-01-30 21:52:37 +01001093 if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, (void *) &opt, sizeof(opt)) < 0) {
Jens Axboee1161c32007-02-22 19:36:48 +01001094 td_verror(td, errno, "setsockopt");
Shawn Bohrer4a93dec2013-07-19 13:24:10 -05001095 close(fd);
Jens Axboe6bedbfa2007-02-07 09:54:40 +01001096 return 1;
1097 }
1098#endif
Jens Axboeed92ac02007-02-06 14:43:52 +01001099
Jens Axboe531e67a2014-10-09 11:55:16 -06001100 if (set_window_size(td, fd)) {
1101 close(fd);
1102 return 1;
1103 }
1104
Jens Axboe6611e9c2014-01-24 07:36:43 -08001105 if (td->o.filename) {
Jens Axboe49ccb8c2014-01-23 16:49:37 -08001106 if (!is_udp(o) || !fio_netio_is_multicast(td->o.filename)) {
Shawn Bohrerb511c9a2013-07-19 13:24:06 -05001107 log_err("fio: hostname not valid for non-multicast inbound network IO\n");
1108 close(fd);
1109 return 1;
1110 }
Jens Axboe6611e9c2014-01-24 07:36:43 -08001111 if (is_ipv6(o)) {
1112 log_err("fio: IPv6 not supported for multicast network IO");
1113 close(fd);
1114 return 1;
1115 }
Shawn Bohrerb511c9a2013-07-19 13:24:06 -05001116
1117 inet_aton(td->o.filename, &sin.sin_addr);
1118
1119 mr.imr_multiaddr = sin.sin_addr;
Bruce Cranf16b7402013-10-08 15:05:27 +01001120 if (o->intfc) {
1121 if (inet_aton(o->intfc, &mr.imr_interface) == 0) {
Shawn Bohrerb93b6a22013-07-19 13:24:07 -05001122 log_err("fio: interface not valid interface IP\n");
1123 close(fd);
1124 return 1;
1125 }
1126 } else {
1127 mr.imr_interface.s_addr = htonl(INADDR_ANY);
1128 }
Jens Axboe6611e9c2014-01-24 07:36:43 -08001129
Bruce Cranf16b7402013-10-08 15:05:27 +01001130 if (setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const char*)&mr, sizeof(mr)) < 0) {
Shawn Bohrerb511c9a2013-07-19 13:24:06 -05001131 td_verror(td, errno, "setsockopt IP_ADD_MEMBERSHIP");
1132 close(fd);
1133 return 1;
1134 }
1135 }
1136
Jens Axboe49ccb8c2014-01-23 16:49:37 -08001137 if (!is_ipv6(o)) {
1138 saddr = (struct sockaddr *) &nd->addr;
1139 len = sizeof(nd->addr);
Jens Axboeed92ac02007-02-06 14:43:52 +01001140
Jens Axboe49ccb8c2014-01-23 16:49:37 -08001141 nd->addr.sin_family = AF_INET;
1142 nd->addr.sin_addr.s_addr = sin.sin_addr.s_addr ? sin.sin_addr.s_addr : htonl(INADDR_ANY);
1143 nd->addr.sin_port = htons(port);
1144 } else {
1145 saddr = (struct sockaddr *) &nd->addr6;
1146 len = sizeof(nd->addr6);
1147
1148 nd->addr6.sin6_family = AF_INET6;
Jens Axboe66f7a562014-04-14 11:57:05 -06001149 nd->addr6.sin6_addr = in6addr_any;
Jens Axboe49ccb8c2014-01-23 16:49:37 -08001150 nd->addr6.sin6_port = htons(port);
1151 }
1152
1153 if (bind(fd, saddr, len) < 0) {
Jens Axboed19cedd2014-04-11 11:29:50 -06001154 close(fd);
Jens Axboee1161c32007-02-22 19:36:48 +01001155 td_verror(td, errno, "bind");
Jens Axboeed92ac02007-02-06 14:43:52 +01001156 return 1;
1157 }
Jens Axboe0fd666b2011-10-06 20:08:53 +02001158
1159 nd->listenfd = fd;
1160 return 0;
1161}
1162
Steven Langde890a12011-11-09 14:03:34 +01001163static int fio_netio_setup_listen(struct thread_data *td)
Jens Axboe0fd666b2011-10-06 20:08:53 +02001164{
1165 struct netio_data *nd = td->io_ops->data;
Steven Langde890a12011-11-09 14:03:34 +01001166 struct netio_options *o = td->eo;
Jens Axboe0fd666b2011-10-06 20:08:53 +02001167 int ret;
1168
Jens Axboe49ccb8c2014-01-23 16:49:37 -08001169 if (is_udp(o) || is_tcp(o))
Steven Langde890a12011-11-09 14:03:34 +01001170 ret = fio_netio_setup_listen_inet(td, o->port);
Jens Axboe0fd666b2011-10-06 20:08:53 +02001171 else
Steven Langde890a12011-11-09 14:03:34 +01001172 ret = fio_netio_setup_listen_unix(td, td->o.filename);
Jens Axboe0fd666b2011-10-06 20:08:53 +02001173
1174 if (ret)
1175 return ret;
Jens Axboe49ccb8c2014-01-23 16:49:37 -08001176 if (is_udp(o))
Jens Axboe0fd666b2011-10-06 20:08:53 +02001177 return 0;
1178
1179 if (listen(nd->listenfd, 10) < 0) {
Jens Axboee1161c32007-02-22 19:36:48 +01001180 td_verror(td, errno, "listen");
Jens Axboe0fd666b2011-10-06 20:08:53 +02001181 nd->listenfd = -1;
Jens Axboeed92ac02007-02-06 14:43:52 +01001182 return 1;
1183 }
1184
Jens Axboeb5af8292007-03-08 12:43:13 +01001185 return 0;
Jens Axboeed92ac02007-02-06 14:43:52 +01001186}
1187
Jens Axboe9bec88e2007-03-02 08:55:48 +01001188static int fio_netio_init(struct thread_data *td)
Jens Axboeed92ac02007-02-06 14:43:52 +01001189{
Steven Langde890a12011-11-09 14:03:34 +01001190 struct netio_options *o = td->eo;
Jens Axboeaf52b342007-03-13 10:07:47 +01001191 int ret;
Jens Axboeed92ac02007-02-06 14:43:52 +01001192
Bruce Cran3f457be2012-10-10 13:37:41 +01001193#ifdef WIN32
1194 WSADATA wsd;
1195 WSAStartup(MAKEWORD(2,2), &wsd);
1196#endif
1197
Jens Axboe16d55aa2007-05-22 09:21:37 +02001198 if (td_random(td)) {
1199 log_err("fio: network IO can't be random\n");
1200 return 1;
1201 }
Jens Axboeed92ac02007-02-06 14:43:52 +01001202
Steven Langde890a12011-11-09 14:03:34 +01001203 if (o->proto == FIO_TYPE_UNIX && o->port) {
1204 log_err("fio: network IO port not valid with unix socket\n");
1205 return 1;
1206 } else if (o->proto != FIO_TYPE_UNIX && !o->port) {
1207 log_err("fio: network IO requires port for tcp or udp\n");
1208 return 1;
Jens Axboe414c2a32009-01-16 13:21:15 +01001209 }
Jens Axboe0fd666b2011-10-06 20:08:53 +02001210
Jens Axboe49ccb8c2014-01-23 16:49:37 -08001211 if (!is_tcp(o)) {
Steven Langde890a12011-11-09 14:03:34 +01001212 if (o->listen) {
Jens Axboe9b986062011-12-19 08:57:18 +01001213 log_err("fio: listen only valid for TCP proto IO\n");
1214 return 1;
Steven Langde890a12011-11-09 14:03:34 +01001215 }
1216 if (td_rw(td)) {
Jens Axboe9b986062011-12-19 08:57:18 +01001217 log_err("fio: datagram network connections must be"
Steven Langde890a12011-11-09 14:03:34 +01001218 " read OR write\n");
Jens Axboe9b986062011-12-19 08:57:18 +01001219 return 1;
1220 }
1221 if (o->proto == FIO_TYPE_UNIX && !td->o.filename) {
1222 log_err("fio: UNIX sockets need host/filename\n");
1223 return 1;
Steven Langde890a12011-11-09 14:03:34 +01001224 }
1225 o->listen = td_read(td);
1226 }
1227
Steven Langde890a12011-11-09 14:03:34 +01001228 if (o->listen)
1229 ret = fio_netio_setup_listen(td);
Jens Axboe0fd666b2011-10-06 20:08:53 +02001230 else
Steven Langde890a12011-11-09 14:03:34 +01001231 ret = fio_netio_setup_connect(td);
Jens Axboeed92ac02007-02-06 14:43:52 +01001232
Jens Axboe7bb48f82007-03-27 15:30:28 +02001233 return ret;
Jens Axboeed92ac02007-02-06 14:43:52 +01001234}
1235
Jens Axboeb5af8292007-03-08 12:43:13 +01001236static void fio_netio_cleanup(struct thread_data *td)
Jens Axboe9bec88e2007-03-02 08:55:48 +01001237{
Jens Axboeb5af8292007-03-08 12:43:13 +01001238 struct netio_data *nd = td->io_ops->data;
1239
1240 if (nd) {
Jens Axboe64b24cd2007-06-24 21:28:39 +02001241 if (nd->listenfd != -1)
1242 close(nd->listenfd);
1243 if (nd->pipes[0] != -1)
1244 close(nd->pipes[0]);
1245 if (nd->pipes[1] != -1)
1246 close(nd->pipes[1]);
1247
Jens Axboeb5af8292007-03-08 12:43:13 +01001248 free(nd);
Jens Axboeb5af8292007-03-08 12:43:13 +01001249 }
1250}
1251
1252static int fio_netio_setup(struct thread_data *td)
1253{
Jens Axboe7bb48f82007-03-27 15:30:28 +02001254 struct netio_data *nd;
Jens Axboeb5af8292007-03-08 12:43:13 +01001255
Steven Langde890a12011-11-09 14:03:34 +01001256 if (!td->files_index) {
Jens Axboe5903e7b2014-02-26 13:42:13 -08001257 add_file(td, td->o.filename ?: "net", 0, 0);
Steven Langde890a12011-11-09 14:03:34 +01001258 td->o.nr_files = td->o.nr_files ?: 1;
Jens Axboeb53f2c52014-04-08 21:07:12 -06001259 td->o.open_files++;
Steven Langde890a12011-11-09 14:03:34 +01001260 }
1261
Jens Axboe7bb48f82007-03-27 15:30:28 +02001262 if (!td->io_ops->data) {
1263 nd = malloc(sizeof(*nd));;
1264
1265 memset(nd, 0, sizeof(*nd));
1266 nd->listenfd = -1;
Jens Axboe64b24cd2007-06-24 21:28:39 +02001267 nd->pipes[0] = nd->pipes[1] = -1;
Jens Axboe7bb48f82007-03-27 15:30:28 +02001268 td->io_ops->data = nd;
Jens Axboe7bb48f82007-03-27 15:30:28 +02001269 }
1270
Jens Axboe9bec88e2007-03-02 08:55:48 +01001271 return 0;
1272}
1273
Jens Axboe36d80bc2012-11-30 21:46:06 +01001274static void fio_netio_terminate(struct thread_data *td)
1275{
Jens Axboee5f7caa2014-10-08 14:14:05 -06001276 kill(td->pid, SIGTERM);
Jens Axboe36d80bc2012-11-30 21:46:06 +01001277}
1278
Jens Axboe67bf9822013-01-10 11:23:19 +01001279#ifdef CONFIG_LINUX_SPLICE
Jens Axboe9cce02e2007-06-22 15:42:21 +02001280static int fio_netio_setup_splice(struct thread_data *td)
1281{
1282 struct netio_data *nd;
1283
1284 fio_netio_setup(td);
1285
1286 nd = td->io_ops->data;
1287 if (nd) {
1288 if (pipe(nd->pipes) < 0)
1289 return 1;
1290
1291 nd->use_splice = 1;
1292 return 0;
1293 }
1294
1295 return 1;
1296}
1297
Jens Axboe5921e802008-05-30 15:02:38 +02001298static struct ioengine_ops ioengine_splice = {
Steven Langde890a12011-11-09 14:03:34 +01001299 .name = "netsplice",
1300 .version = FIO_IOOPS_VERSION,
1301 .prep = fio_netio_prep,
1302 .queue = fio_netio_queue,
1303 .setup = fio_netio_setup_splice,
1304 .init = fio_netio_init,
1305 .cleanup = fio_netio_cleanup,
1306 .open_file = fio_netio_open_file,
Jens Axboe36d80bc2012-11-30 21:46:06 +01001307 .close_file = fio_netio_close_file,
1308 .terminate = fio_netio_terminate,
Steven Langde890a12011-11-09 14:03:34 +01001309 .options = options,
1310 .option_struct_size = sizeof(struct netio_options),
1311 .flags = FIO_SYNCIO | FIO_DISKLESSIO | FIO_UNIDIR |
Jens Axboe36d80bc2012-11-30 21:46:06 +01001312 FIO_PIPEIO,
Jens Axboe5921e802008-05-30 15:02:38 +02001313};
1314#endif
1315
Jens Axboe9cce02e2007-06-22 15:42:21 +02001316static struct ioengine_ops ioengine_rw = {
Steven Langde890a12011-11-09 14:03:34 +01001317 .name = "net",
1318 .version = FIO_IOOPS_VERSION,
1319 .prep = fio_netio_prep,
1320 .queue = fio_netio_queue,
1321 .setup = fio_netio_setup,
1322 .init = fio_netio_init,
1323 .cleanup = fio_netio_cleanup,
1324 .open_file = fio_netio_open_file,
1325 .close_file = fio_netio_close_file,
Jens Axboe36d80bc2012-11-30 21:46:06 +01001326 .terminate = fio_netio_terminate,
Steven Langde890a12011-11-09 14:03:34 +01001327 .options = options,
1328 .option_struct_size = sizeof(struct netio_options),
1329 .flags = FIO_SYNCIO | FIO_DISKLESSIO | FIO_UNIDIR |
Steven Noonanad705bc2013-04-08 15:05:25 -07001330 FIO_PIPEIO | FIO_BIT_BASED,
Jens Axboeed92ac02007-02-06 14:43:52 +01001331};
1332
Steven Langde890a12011-11-09 14:03:34 +01001333static int str_hostname_cb(void *data, const char *input)
1334{
1335 struct netio_options *o = data;
1336
1337 if (o->td->o.filename)
1338 free(o->td->o.filename);
1339 o->td->o.filename = strdup(input);
1340 return 0;
1341}
1342
Jens Axboeed92ac02007-02-06 14:43:52 +01001343static void fio_init fio_netio_register(void)
1344{
Jens Axboe9cce02e2007-06-22 15:42:21 +02001345 register_ioengine(&ioengine_rw);
Jens Axboe67bf9822013-01-10 11:23:19 +01001346#ifdef CONFIG_LINUX_SPLICE
Jens Axboe9cce02e2007-06-22 15:42:21 +02001347 register_ioengine(&ioengine_splice);
Jens Axboe5921e802008-05-30 15:02:38 +02001348#endif
Jens Axboeed92ac02007-02-06 14:43:52 +01001349}
1350
1351static void fio_exit fio_netio_unregister(void)
1352{
Jens Axboe9cce02e2007-06-22 15:42:21 +02001353 unregister_ioengine(&ioengine_rw);
Jens Axboe67bf9822013-01-10 11:23:19 +01001354#ifdef CONFIG_LINUX_SPLICE
Jens Axboe9cce02e2007-06-22 15:42:21 +02001355 unregister_ioengine(&ioengine_splice);
Jens Axboe5921e802008-05-30 15:02:38 +02001356#endif
Jens Axboeed92ac02007-02-06 14:43:52 +01001357}