blob: edb5577660f032159f400a655c35eff426920d10 [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>
14#include <arpa/inet.h>
15#include <netdb.h>
Jens Axboe5fdd1242007-02-11 04:00:37 +010016#include <sys/poll.h>
Jens Axboe72920562008-06-02 12:30:06 +020017#include <sys/types.h>
Jens Axboe0fd666b2011-10-06 20:08:53 +020018#include <sys/stat.h>
Jens Axboe72920562008-06-02 12:30:06 +020019#include <sys/socket.h>
Jens Axboe0fd666b2011-10-06 20:08:53 +020020#include <sys/un.h>
Jens Axboeed92ac02007-02-06 14:43:52 +010021
22#include "../fio.h"
Jens Axboeed92ac02007-02-06 14:43:52 +010023
Jens Axboeb5af8292007-03-08 12:43:13 +010024struct netio_data {
25 int listenfd;
Jens Axboe9cce02e2007-06-22 15:42:21 +020026 int use_splice;
27 int pipes[2];
Jens Axboeb5af8292007-03-08 12:43:13 +010028 struct sockaddr_in addr;
Jens Axboe0fd666b2011-10-06 20:08:53 +020029 struct sockaddr_un addr_un;
Jens Axboeb5af8292007-03-08 12:43:13 +010030};
Jens Axboeed92ac02007-02-06 14:43:52 +010031
Steven Langde890a12011-11-09 14:03:34 +010032struct netio_options {
33 struct thread_data *td;
34 unsigned int port;
35 unsigned int proto;
36 unsigned int listen;
Jens Axboe6f73a7f2012-11-30 09:59:20 +010037 unsigned int pingpong;
Steven Langde890a12011-11-09 14:03:34 +010038};
39
Jens Axboe664fb3b2009-01-19 13:26:36 +010040struct udp_close_msg {
41 uint32_t magic;
42 uint32_t cmd;
43};
44
45enum {
46 FIO_LINK_CLOSE = 0x89,
Jens Axboeb96d2432012-11-30 08:27:46 +010047 FIO_LINK_OPEN_CLOSE_MAGIC = 0x6c696e6b,
48 FIO_LINK_OPEN = 0x98,
Jens Axboe0fd666b2011-10-06 20:08:53 +020049
50 FIO_TYPE_TCP = 1,
51 FIO_TYPE_UDP = 2,
52 FIO_TYPE_UNIX = 3,
Jens Axboe664fb3b2009-01-19 13:26:36 +010053};
54
Steven Langde890a12011-11-09 14:03:34 +010055static int str_hostname_cb(void *data, const char *input);
56static struct fio_option options[] = {
57 {
58 .name = "hostname",
59 .type = FIO_OPT_STR_STORE,
60 .cb = str_hostname_cb,
61 .help = "Hostname for net IO engine",
62 },
63 {
64 .name = "port",
65 .type = FIO_OPT_INT,
66 .off1 = offsetof(struct netio_options, port),
67 .minval = 1,
68 .maxval = 65535,
69 .help = "Port to use for TCP or UDP net connections",
70 },
71 {
72 .name = "protocol",
73 .alias = "proto",
74 .type = FIO_OPT_STR,
75 .off1 = offsetof(struct netio_options, proto),
76 .help = "Network protocol to use",
77 .def = "tcp",
78 .posval = {
79 { .ival = "tcp",
80 .oval = FIO_TYPE_TCP,
81 .help = "Transmission Control Protocol",
82 },
83 { .ival = "udp",
84 .oval = FIO_TYPE_UDP,
Bruce Cranf5cc3d02012-10-10 08:17:44 -060085 .help = "User Datagram Protocol",
Steven Langde890a12011-11-09 14:03:34 +010086 },
87 { .ival = "unix",
88 .oval = FIO_TYPE_UNIX,
89 .help = "UNIX domain socket",
90 },
91 },
92 },
93 {
94 .name = "listen",
95 .type = FIO_OPT_STR_SET,
96 .off1 = offsetof(struct netio_options, listen),
97 .help = "Listen for incoming TCP connections",
98 },
99 {
Jens Axboe6f73a7f2012-11-30 09:59:20 +0100100 .name = "pingpong",
101 .type = FIO_OPT_STR_SET,
102 .off1 = offsetof(struct netio_options, pingpong),
103 .help = "Ping-pong IO requests",
104 },
105 {
Steven Langde890a12011-11-09 14:03:34 +0100106 .name = NULL,
107 },
108};
109
Jens Axboe371d4562009-01-19 10:17:06 +0100110/*
111 * Return -1 for error and 'nr events' for a positive number
112 * of events
113 */
114static int poll_wait(struct thread_data *td, int fd, short events)
115{
116 struct pollfd pfd;
117 int ret;
118
119 while (!td->terminate) {
120 pfd.fd = fd;
121 pfd.events = events;
122 ret = poll(&pfd, 1, -1);
123 if (ret < 0) {
124 if (errno == EINTR)
Jens Axboed5b388a2009-01-19 12:38:27 +0100125 break;
Jens Axboe371d4562009-01-19 10:17:06 +0100126
127 td_verror(td, errno, "poll");
128 return -1;
129 } else if (!ret)
130 continue;
131
132 break;
133 }
134
135 if (pfd.revents & events)
136 return 1;
Jens Axboe371d4562009-01-19 10:17:06 +0100137
138 return -1;
139}
140
Jens Axboeed92ac02007-02-06 14:43:52 +0100141static int fio_netio_prep(struct thread_data *td, struct io_u *io_u)
142{
Steven Langde890a12011-11-09 14:03:34 +0100143 struct netio_options *o = td->eo;
Jens Axboeed92ac02007-02-06 14:43:52 +0100144
Jens Axboe7a6499d2007-02-07 09:35:29 +0100145 /*
146 * Make sure we don't see spurious reads to a receiver, and vice versa
147 */
Steven Langde890a12011-11-09 14:03:34 +0100148 if (o->proto == FIO_TYPE_TCP)
149 return 0;
150
151 if ((o->listen && io_u->ddir == DDIR_WRITE) ||
152 (!o->listen && io_u->ddir == DDIR_READ)) {
Jens Axboee1161c32007-02-22 19:36:48 +0100153 td_verror(td, EINVAL, "bad direction");
Jens Axboe7a6499d2007-02-07 09:35:29 +0100154 return 1;
Jens Axboeed92ac02007-02-06 14:43:52 +0100155 }
Bruce Cran3f457be2012-10-10 13:37:41 +0100156
Jens Axboef85ac252008-03-01 18:09:49 +0100157 return 0;
Jens Axboeed92ac02007-02-06 14:43:52 +0100158}
159
Jens Axboe5921e802008-05-30 15:02:38 +0200160#ifdef FIO_HAVE_SPLICE
Jens Axboecd963e12007-06-24 21:41:46 +0200161static int splice_io_u(int fdin, int fdout, unsigned int len)
Jens Axboe9cce02e2007-06-22 15:42:21 +0200162{
Jens Axboe9cce02e2007-06-22 15:42:21 +0200163 int bytes = 0;
164
165 while (len) {
Jens Axboecd963e12007-06-24 21:41:46 +0200166 int ret = splice(fdin, NULL, fdout, NULL, len, 0);
Jens Axboe9cce02e2007-06-22 15:42:21 +0200167
168 if (ret < 0) {
169 if (!bytes)
170 bytes = ret;
171
172 break;
173 } else if (!ret)
174 break;
175
176 bytes += ret;
Jens Axboef657a2f2007-06-22 20:40:10 +0200177 len -= ret;
Jens Axboe9cce02e2007-06-22 15:42:21 +0200178 }
179
180 return bytes;
181}
182
183/*
Jens Axboecd963e12007-06-24 21:41:46 +0200184 * Receive bytes from a socket and fill them into the internal pipe
185 */
186static int splice_in(struct thread_data *td, struct io_u *io_u)
187{
188 struct netio_data *nd = td->io_ops->data;
189
190 return splice_io_u(io_u->file->fd, nd->pipes[1], io_u->xfer_buflen);
191}
192
193/*
Jens Axboe9cce02e2007-06-22 15:42:21 +0200194 * Transmit 'len' bytes from the internal pipe
195 */
196static int splice_out(struct thread_data *td, struct io_u *io_u,
197 unsigned int len)
198{
199 struct netio_data *nd = td->io_ops->data;
Jens Axboecd963e12007-06-24 21:41:46 +0200200
201 return splice_io_u(nd->pipes[0], io_u->file->fd, len);
202}
203
204static int vmsplice_io_u(struct io_u *io_u, int fd, unsigned int len)
205{
206 struct iovec iov = {
207 .iov_base = io_u->xfer_buf,
208 .iov_len = len,
209 };
Jens Axboe9cce02e2007-06-22 15:42:21 +0200210 int bytes = 0;
211
Jens Axboecd963e12007-06-24 21:41:46 +0200212 while (iov.iov_len) {
213 int ret = vmsplice(fd, &iov, 1, SPLICE_F_MOVE);
Jens Axboe9cce02e2007-06-22 15:42:21 +0200214
215 if (ret < 0) {
216 if (!bytes)
217 bytes = ret;
Jens Axboe9cce02e2007-06-22 15:42:21 +0200218 break;
219 } else if (!ret)
220 break;
221
Jens Axboecd963e12007-06-24 21:41:46 +0200222 iov.iov_len -= ret;
223 iov.iov_base += ret;
Jens Axboe9cce02e2007-06-22 15:42:21 +0200224 bytes += ret;
Jens Axboe9cce02e2007-06-22 15:42:21 +0200225 }
226
227 return bytes;
Jens Axboecd963e12007-06-24 21:41:46 +0200228
Jens Axboe9cce02e2007-06-22 15:42:21 +0200229}
230
231/*
232 * vmsplice() pipe to io_u buffer
233 */
234static int vmsplice_io_u_out(struct thread_data *td, struct io_u *io_u,
235 unsigned int len)
236{
237 struct netio_data *nd = td->io_ops->data;
Jens Axboe9cce02e2007-06-22 15:42:21 +0200238
Jens Axboecd963e12007-06-24 21:41:46 +0200239 return vmsplice_io_u(io_u, nd->pipes[0], len);
Jens Axboe9cce02e2007-06-22 15:42:21 +0200240}
241
242/*
243 * vmsplice() io_u to pipe
244 */
245static int vmsplice_io_u_in(struct thread_data *td, struct io_u *io_u)
246{
247 struct netio_data *nd = td->io_ops->data;
Jens Axboe9cce02e2007-06-22 15:42:21 +0200248
Jens Axboecd963e12007-06-24 21:41:46 +0200249 return vmsplice_io_u(io_u, nd->pipes[1], io_u->xfer_buflen);
Jens Axboe9cce02e2007-06-22 15:42:21 +0200250}
251
Jens Axboecd963e12007-06-24 21:41:46 +0200252/*
253 * splice receive - transfer socket data into a pipe using splice, then map
254 * that pipe data into the io_u using vmsplice.
255 */
Jens Axboe9cce02e2007-06-22 15:42:21 +0200256static int fio_netio_splice_in(struct thread_data *td, struct io_u *io_u)
257{
258 int ret;
259
260 ret = splice_in(td, io_u);
Jens Axboecd963e12007-06-24 21:41:46 +0200261 if (ret > 0)
262 return vmsplice_io_u_out(td, io_u, ret);
Jens Axboe9cce02e2007-06-22 15:42:21 +0200263
Jens Axboecd963e12007-06-24 21:41:46 +0200264 return ret;
Jens Axboe9cce02e2007-06-22 15:42:21 +0200265}
266
Jens Axboecd963e12007-06-24 21:41:46 +0200267/*
268 * splice transmit - map data from the io_u into a pipe by using vmsplice,
269 * then transfer that pipe to a socket using splice.
270 */
Jens Axboe9cce02e2007-06-22 15:42:21 +0200271static int fio_netio_splice_out(struct thread_data *td, struct io_u *io_u)
272{
273 int ret;
274
275 ret = vmsplice_io_u_in(td, io_u);
Jens Axboecd963e12007-06-24 21:41:46 +0200276 if (ret > 0)
277 return splice_out(td, io_u, ret);
Jens Axboe9cce02e2007-06-22 15:42:21 +0200278
Jens Axboecd963e12007-06-24 21:41:46 +0200279 return ret;
Jens Axboe9cce02e2007-06-22 15:42:21 +0200280}
Jens Axboe5921e802008-05-30 15:02:38 +0200281#else
282static int fio_netio_splice_in(struct thread_data *td, struct io_u *io_u)
283{
Jens Axboeaf8771b2008-05-30 22:58:28 +0200284 errno = EOPNOTSUPP;
Jens Axboe5921e802008-05-30 15:02:38 +0200285 return -1;
286}
287
288static int fio_netio_splice_out(struct thread_data *td, struct io_u *io_u)
289{
Jens Axboeaf8771b2008-05-30 22:58:28 +0200290 errno = EOPNOTSUPP;
Jens Axboe5921e802008-05-30 15:02:38 +0200291 return -1;
292}
293#endif
Jens Axboe9cce02e2007-06-22 15:42:21 +0200294
295static int fio_netio_send(struct thread_data *td, struct io_u *io_u)
296{
Jens Axboe414c2a32009-01-16 13:21:15 +0100297 struct netio_data *nd = td->io_ops->data;
Steven Langde890a12011-11-09 14:03:34 +0100298 struct netio_options *o = td->eo;
Jens Axboe6f73a7f2012-11-30 09:59:20 +0100299 int ret, flags = 0;
Jens Axboe371d4562009-01-19 10:17:06 +0100300
Jens Axboe664fb3b2009-01-19 13:26:36 +0100301 do {
Steven Langde890a12011-11-09 14:03:34 +0100302 if (o->proto == FIO_TYPE_UDP) {
Jens Axboe62b38922009-05-11 10:37:33 +0200303 struct sockaddr *to = (struct sockaddr *) &nd->addr;
304
Jens Axboe664fb3b2009-01-19 13:26:36 +0100305 ret = sendto(io_u->file->fd, io_u->xfer_buf,
Jens Axboe62b38922009-05-11 10:37:33 +0200306 io_u->xfer_buflen, flags, to,
307 sizeof(*to));
Jens Axboe664fb3b2009-01-19 13:26:36 +0100308 } else {
309 /*
310 * if we are going to write more, set MSG_MORE
311 */
Jens Axboe5921e802008-05-30 15:02:38 +0200312#ifdef MSG_MORE
Jens Axboe6f73a7f2012-11-30 09:59:20 +0100313 if ((td->this_io_bytes[DDIR_WRITE] + io_u->xfer_buflen <
314 td->o.size) && !o->pingpong)
Jens Axboe664fb3b2009-01-19 13:26:36 +0100315 flags |= MSG_MORE;
Jens Axboe5921e802008-05-30 15:02:38 +0200316#endif
Jens Axboe664fb3b2009-01-19 13:26:36 +0100317 ret = send(io_u->file->fd, io_u->xfer_buf,
318 io_u->xfer_buflen, flags);
319 }
320 if (ret > 0)
321 break;
Jens Axboe9cce02e2007-06-22 15:42:21 +0200322
Jens Axboe664fb3b2009-01-19 13:26:36 +0100323 ret = poll_wait(td, io_u->file->fd, POLLOUT);
324 if (ret <= 0)
325 break;
Jens Axboe664fb3b2009-01-19 13:26:36 +0100326 } while (1);
327
328 return ret;
329}
330
331static int is_udp_close(struct io_u *io_u, int len)
332{
333 struct udp_close_msg *msg;
334
335 if (len != sizeof(struct udp_close_msg))
336 return 0;
337
338 msg = io_u->xfer_buf;
Jens Axboeb96d2432012-11-30 08:27:46 +0100339 if (ntohl(msg->magic) != FIO_LINK_OPEN_CLOSE_MAGIC)
Jens Axboe664fb3b2009-01-19 13:26:36 +0100340 return 0;
341 if (ntohl(msg->cmd) != FIO_LINK_CLOSE)
342 return 0;
343
344 return 1;
Jens Axboe9cce02e2007-06-22 15:42:21 +0200345}
346
Jens Axboe414c2a32009-01-16 13:21:15 +0100347static int fio_netio_recv(struct thread_data *td, struct io_u *io_u)
Jens Axboe9cce02e2007-06-22 15:42:21 +0200348{
Jens Axboe414c2a32009-01-16 13:21:15 +0100349 struct netio_data *nd = td->io_ops->data;
Steven Langde890a12011-11-09 14:03:34 +0100350 struct netio_options *o = td->eo;
Jens Axboe6f73a7f2012-11-30 09:59:20 +0100351 int ret, flags = 0;
Jens Axboe371d4562009-01-19 10:17:06 +0100352
Jens Axboe664fb3b2009-01-19 13:26:36 +0100353 do {
Steven Langde890a12011-11-09 14:03:34 +0100354 if (o->proto == FIO_TYPE_UDP) {
Jens Axboe5ba13ea2011-10-04 23:50:28 +0200355 fio_socklen_t len = sizeof(nd->addr);
Jens Axboe62b38922009-05-11 10:37:33 +0200356 struct sockaddr *from = (struct sockaddr *) &nd->addr;
Jens Axboe9cce02e2007-06-22 15:42:21 +0200357
Jens Axboe664fb3b2009-01-19 13:26:36 +0100358 ret = recvfrom(io_u->file->fd, io_u->xfer_buf,
Jens Axboe62b38922009-05-11 10:37:33 +0200359 io_u->xfer_buflen, flags, from, &len);
Jens Axboe664fb3b2009-01-19 13:26:36 +0100360 if (is_udp_close(io_u, ret)) {
361 td->done = 1;
362 return 0;
363 }
364 } else {
365 ret = recv(io_u->file->fd, io_u->xfer_buf,
366 io_u->xfer_buflen, flags);
367 }
368 if (ret > 0)
369 break;
Jens Axboe7d988f62012-11-29 19:57:35 +0100370 else if (!ret && (flags & MSG_WAITALL))
371 break;
Jens Axboe414c2a32009-01-16 13:21:15 +0100372
Jens Axboe664fb3b2009-01-19 13:26:36 +0100373 ret = poll_wait(td, io_u->file->fd, POLLIN);
374 if (ret <= 0)
375 break;
Jens Axboe664fb3b2009-01-19 13:26:36 +0100376 flags |= MSG_WAITALL;
377 } while (1);
378
379 return ret;
Jens Axboe9cce02e2007-06-22 15:42:21 +0200380}
381
Jens Axboe6f73a7f2012-11-30 09:59:20 +0100382static int __fio_netio_queue(struct thread_data *td, struct io_u *io_u,
383 enum fio_ddir ddir)
Jens Axboeed92ac02007-02-06 14:43:52 +0100384{
Jens Axboe9cce02e2007-06-22 15:42:21 +0200385 struct netio_data *nd = td->io_ops->data;
Steven Langde890a12011-11-09 14:03:34 +0100386 struct netio_options *o = td->eo;
Jens Axboe9cce02e2007-06-22 15:42:21 +0200387 int ret;
Jens Axboeed92ac02007-02-06 14:43:52 +0100388
Jens Axboe6f73a7f2012-11-30 09:59:20 +0100389 if (ddir == DDIR_WRITE) {
Steven Langde890a12011-11-09 14:03:34 +0100390 if (!nd->use_splice || o->proto == FIO_TYPE_UDP ||
391 o->proto == FIO_TYPE_UNIX)
Jens Axboe9cce02e2007-06-22 15:42:21 +0200392 ret = fio_netio_send(td, io_u);
Jens Axboe9cce02e2007-06-22 15:42:21 +0200393 else
Jens Axboe414c2a32009-01-16 13:21:15 +0100394 ret = fio_netio_splice_out(td, io_u);
Jens Axboe6f73a7f2012-11-30 09:59:20 +0100395 } else if (ddir == DDIR_READ) {
Steven Langde890a12011-11-09 14:03:34 +0100396 if (!nd->use_splice || o->proto == FIO_TYPE_UDP ||
397 o->proto == FIO_TYPE_UNIX)
Jens Axboe414c2a32009-01-16 13:21:15 +0100398 ret = fio_netio_recv(td, io_u);
399 else
400 ret = fio_netio_splice_in(td, io_u);
Jens Axboed4f12dd2007-02-08 12:59:02 +0100401 } else
Jens Axboe7a6499d2007-02-07 09:35:29 +0100402 ret = 0; /* must be a SYNC */
Jens Axboeed92ac02007-02-06 14:43:52 +0100403
Jens Axboecec6b552007-02-06 20:15:38 +0100404 if (ret != (int) io_u->xfer_buflen) {
Jens Axboe22819ec2007-02-18 07:47:14 +0100405 if (ret >= 0) {
Jens Axboecec6b552007-02-06 20:15:38 +0100406 io_u->resid = io_u->xfer_buflen - ret;
407 io_u->error = 0;
Jens Axboe36167d82007-02-18 05:41:31 +0100408 return FIO_Q_COMPLETED;
Jens Axboe414c2a32009-01-16 13:21:15 +0100409 } else {
410 int err = errno;
411
Jens Axboe6f73a7f2012-11-30 09:59:20 +0100412 if (ddir == DDIR_WRITE && err == EMSGSIZE)
Jens Axboe414c2a32009-01-16 13:21:15 +0100413 return FIO_Q_BUSY;
414
415 io_u->error = err;
416 }
Jens Axboeed92ac02007-02-06 14:43:52 +0100417 }
418
Jens Axboe36167d82007-02-18 05:41:31 +0100419 if (io_u->error)
Jens Axboee1161c32007-02-22 19:36:48 +0100420 td_verror(td, io_u->error, "xfer");
Jens Axboeed92ac02007-02-06 14:43:52 +0100421
Jens Axboe36167d82007-02-18 05:41:31 +0100422 return FIO_Q_COMPLETED;
Jens Axboeed92ac02007-02-06 14:43:52 +0100423}
424
Jens Axboe6f73a7f2012-11-30 09:59:20 +0100425static int fio_netio_queue(struct thread_data *td, struct io_u *io_u)
426{
427 struct netio_options *o = td->eo;
428 int ret;
429
430 fio_ro_check(td, io_u);
431
432 ret = __fio_netio_queue(td, io_u, io_u->ddir);
433 if (!o->pingpong || ret != FIO_Q_COMPLETED)
434 return ret;
435
436 /*
437 * For ping-pong mode, receive or send reply as needed
438 */
439 if (td_read(td) && io_u->ddir == DDIR_READ)
440 ret = __fio_netio_queue(td, io_u, DDIR_WRITE);
441 else if (td_write(td) && io_u->ddir == DDIR_WRITE)
442 ret = __fio_netio_queue(td, io_u, DDIR_READ);
443
444 return ret;
445}
446
Jens Axboeb5af8292007-03-08 12:43:13 +0100447static int fio_netio_connect(struct thread_data *td, struct fio_file *f)
Jens Axboeed92ac02007-02-06 14:43:52 +0100448{
Jens Axboeb5af8292007-03-08 12:43:13 +0100449 struct netio_data *nd = td->io_ops->data;
Steven Langde890a12011-11-09 14:03:34 +0100450 struct netio_options *o = td->eo;
Jens Axboe0fd666b2011-10-06 20:08:53 +0200451 int type, domain;
Jens Axboeed92ac02007-02-06 14:43:52 +0100452
Steven Langde890a12011-11-09 14:03:34 +0100453 if (o->proto == FIO_TYPE_TCP) {
Jens Axboe0fd666b2011-10-06 20:08:53 +0200454 domain = AF_INET;
Jens Axboe414c2a32009-01-16 13:21:15 +0100455 type = SOCK_STREAM;
Steven Langde890a12011-11-09 14:03:34 +0100456 } else if (o->proto == FIO_TYPE_UDP) {
Jens Axboe0fd666b2011-10-06 20:08:53 +0200457 domain = AF_INET;
Jens Axboe414c2a32009-01-16 13:21:15 +0100458 type = SOCK_DGRAM;
Steven Langde890a12011-11-09 14:03:34 +0100459 } else if (o->proto == FIO_TYPE_UNIX) {
Jens Axboe0fd666b2011-10-06 20:08:53 +0200460 domain = AF_UNIX;
461 type = SOCK_STREAM;
462 } else {
Steven Langde890a12011-11-09 14:03:34 +0100463 log_err("fio: bad network type %d\n", o->proto);
Jens Axboe0fd666b2011-10-06 20:08:53 +0200464 f->fd = -1;
465 return 1;
466 }
Jens Axboe414c2a32009-01-16 13:21:15 +0100467
Jens Axboe0fd666b2011-10-06 20:08:53 +0200468 f->fd = socket(domain, type, 0);
Jens Axboeb5af8292007-03-08 12:43:13 +0100469 if (f->fd < 0) {
470 td_verror(td, errno, "socket");
471 return 1;
Jens Axboeed92ac02007-02-06 14:43:52 +0100472 }
473
Steven Langde890a12011-11-09 14:03:34 +0100474 if (o->proto == FIO_TYPE_UDP)
Jens Axboe414c2a32009-01-16 13:21:15 +0100475 return 0;
Steven Langde890a12011-11-09 14:03:34 +0100476 else if (o->proto == FIO_TYPE_TCP) {
Jens Axboe0fd666b2011-10-06 20:08:53 +0200477 fio_socklen_t len = sizeof(nd->addr);
Jens Axboe414c2a32009-01-16 13:21:15 +0100478
Jens Axboe0fd666b2011-10-06 20:08:53 +0200479 if (connect(f->fd, (struct sockaddr *) &nd->addr, len) < 0) {
480 td_verror(td, errno, "connect");
Jens Axboeb94cba42011-10-06 21:27:10 +0200481 close(f->fd);
Jens Axboe0fd666b2011-10-06 20:08:53 +0200482 return 1;
483 }
484 } else {
485 struct sockaddr_un *addr = &nd->addr_un;
486 fio_socklen_t len;
487
488 len = sizeof(addr->sun_family) + strlen(addr->sun_path) + 1;
489
490 if (connect(f->fd, (struct sockaddr *) addr, len) < 0) {
491 td_verror(td, errno, "connect");
Jens Axboeb94cba42011-10-06 21:27:10 +0200492 close(f->fd);
Jens Axboe0fd666b2011-10-06 20:08:53 +0200493 return 1;
494 }
Jens Axboeed92ac02007-02-06 14:43:52 +0100495 }
496
497 return 0;
Jens Axboeed92ac02007-02-06 14:43:52 +0100498}
499
Jens Axboeb5af8292007-03-08 12:43:13 +0100500static int fio_netio_accept(struct thread_data *td, struct fio_file *f)
Jens Axboe5fdd1242007-02-11 04:00:37 +0100501{
Jens Axboeb5af8292007-03-08 12:43:13 +0100502 struct netio_data *nd = td->io_ops->data;
Steven Langde890a12011-11-09 14:03:34 +0100503 struct netio_options *o = td->eo;
Jens Axboe5ba13ea2011-10-04 23:50:28 +0200504 fio_socklen_t socklen = sizeof(nd->addr);
Jens Axboe859088d2012-11-29 20:02:50 +0100505 int state;
Jens Axboe5fdd1242007-02-11 04:00:37 +0100506
Steven Langde890a12011-11-09 14:03:34 +0100507 if (o->proto == FIO_TYPE_UDP) {
Jens Axboe414c2a32009-01-16 13:21:15 +0100508 f->fd = nd->listenfd;
509 return 0;
510 }
511
Jens Axboe859088d2012-11-29 20:02:50 +0100512 state = td->runstate;
513 td_set_runstate(td, TD_SETTING_UP);
514
Jens Axboe6d861442007-03-15 09:22:23 +0100515 log_info("fio: waiting for connection\n");
Jens Axboe5fdd1242007-02-11 04:00:37 +0100516
Jens Axboe371d4562009-01-19 10:17:06 +0100517 if (poll_wait(td, nd->listenfd, POLLIN) < 0)
Jens Axboe859088d2012-11-29 20:02:50 +0100518 goto err;
Jens Axboe5fdd1242007-02-11 04:00:37 +0100519
Jens Axboe371d4562009-01-19 10:17:06 +0100520 f->fd = accept(nd->listenfd, (struct sockaddr *) &nd->addr, &socklen);
521 if (f->fd < 0) {
522 td_verror(td, errno, "accept");
Jens Axboe859088d2012-11-29 20:02:50 +0100523 goto err;
Jens Axboe5fdd1242007-02-11 04:00:37 +0100524 }
525
Jens Axboe0cae16f2012-11-30 16:22:31 +0100526 reset_all_stats(td);
Jens Axboe859088d2012-11-29 20:02:50 +0100527 td_set_runstate(td, state);
Jens Axboe5fdd1242007-02-11 04:00:37 +0100528 return 0;
Jens Axboe859088d2012-11-29 20:02:50 +0100529err:
530 td_set_runstate(td, state);
531 return 1;
Jens Axboe5fdd1242007-02-11 04:00:37 +0100532}
533
Jens Axboe664fb3b2009-01-19 13:26:36 +0100534static void fio_netio_udp_close(struct thread_data *td, struct fio_file *f)
535{
536 struct netio_data *nd = td->io_ops->data;
537 struct udp_close_msg msg;
Jens Axboe62b38922009-05-11 10:37:33 +0200538 struct sockaddr *to = (struct sockaddr *) &nd->addr;
Jens Axboe664fb3b2009-01-19 13:26:36 +0100539 int ret;
540
Jens Axboeb96d2432012-11-30 08:27:46 +0100541 msg.magic = htonl(FIO_LINK_OPEN_CLOSE_MAGIC);
Jens Axboe664fb3b2009-01-19 13:26:36 +0100542 msg.cmd = htonl(FIO_LINK_CLOSE);
543
Jens Axboe62b38922009-05-11 10:37:33 +0200544 ret = sendto(f->fd, &msg, sizeof(msg), MSG_WAITALL, to,
Jens Axboe664fb3b2009-01-19 13:26:36 +0100545 sizeof(nd->addr));
546 if (ret < 0)
547 td_verror(td, errno, "sendto udp link close");
548}
549
550static int fio_netio_close_file(struct thread_data *td, struct fio_file *f)
551{
Steven Langde890a12011-11-09 14:03:34 +0100552 struct netio_options *o = td->eo;
Jens Axboe664fb3b2009-01-19 13:26:36 +0100553
554 /*
555 * If this is an UDP connection, notify the receiver that we are
556 * closing down the link
557 */
Steven Langde890a12011-11-09 14:03:34 +0100558 if (o->proto == FIO_TYPE_UDP)
Jens Axboe664fb3b2009-01-19 13:26:36 +0100559 fio_netio_udp_close(td, f);
560
561 return generic_close_file(td, f);
562}
563
Jens Axboeb96d2432012-11-30 08:27:46 +0100564static int fio_netio_udp_recv_open(struct thread_data *td, struct fio_file *f)
565{
566 struct netio_data *nd = td->io_ops->data;
567 struct udp_close_msg msg;
568 struct sockaddr *to = (struct sockaddr *) &nd->addr;
569 fio_socklen_t len = sizeof(nd->addr);
570 int ret;
571
572 ret = recvfrom(f->fd, &msg, sizeof(msg), MSG_WAITALL, to, &len);
573 if (ret < 0) {
574 td_verror(td, errno, "sendto udp link open");
575 return ret;
576 }
577
578 if (ntohl(msg.magic) != FIO_LINK_OPEN_CLOSE_MAGIC ||
579 ntohl(msg.cmd) != FIO_LINK_OPEN) {
580 log_err("fio: bad udp open magic %x/%x\n", ntohl(msg.magic),
581 ntohl(msg.cmd));
582 return -1;
583 }
584
585 return 0;
586}
587
588static int fio_netio_udp_send_open(struct thread_data *td, struct fio_file *f)
589{
590 struct netio_data *nd = td->io_ops->data;
591 struct udp_close_msg msg;
592 struct sockaddr *to = (struct sockaddr *) &nd->addr;
593 int ret;
594
595 msg.magic = htonl(FIO_LINK_OPEN_CLOSE_MAGIC);
596 msg.cmd = htonl(FIO_LINK_OPEN);
597
598 ret = sendto(f->fd, &msg, sizeof(msg), MSG_WAITALL, to,
599 sizeof(nd->addr));
600 if (ret < 0) {
601 td_verror(td, errno, "sendto udp link open");
602 return ret;
603 }
604
605 return 0;
606}
607
608static int fio_netio_open_file(struct thread_data *td, struct fio_file *f)
609{
610 int ret;
611 struct netio_options *o = td->eo;
612
613 if (o->listen)
614 ret = fio_netio_accept(td, f);
615 else
616 ret = fio_netio_connect(td, f);
617
618 if (ret) {
619 f->fd = -1;
620 return ret;
621 }
622
623 if (o->proto == FIO_TYPE_UDP) {
624 if (td_write(td))
625 ret = fio_netio_udp_send_open(td, f);
626 else {
627 int state;
628
629 state = td->runstate;
630 td_set_runstate(td, TD_SETTING_UP);
631 ret = fio_netio_udp_recv_open(td, f);
632 td_set_runstate(td, state);
633 }
634 }
635
636 if (ret)
637 fio_netio_close_file(td, f);
638
639 return ret;
640}
641
Jens Axboe0fd666b2011-10-06 20:08:53 +0200642static int fio_netio_setup_connect_inet(struct thread_data *td,
643 const char *host, unsigned short port)
Jens Axboeb5af8292007-03-08 12:43:13 +0100644{
645 struct netio_data *nd = td->io_ops->data;
646
Jens Axboe166dce42012-11-29 14:35:33 +0100647 if (!host) {
648 log_err("fio: connect with no host to connect to.\n");
649 if (td_read(td))
650 log_err("fio: did you forget to set 'listen'?\n");
651
652 td_verror(td, EINVAL, "no hostname= set");
653 return 1;
654 }
655
Jens Axboeb5af8292007-03-08 12:43:13 +0100656 nd->addr.sin_family = AF_INET;
657 nd->addr.sin_port = htons(port);
658
659 if (inet_aton(host, &nd->addr.sin_addr) != 1) {
660 struct hostent *hent;
661
662 hent = gethostbyname(host);
663 if (!hent) {
664 td_verror(td, errno, "gethostbyname");
665 return 1;
666 }
667
668 memcpy(&nd->addr.sin_addr, hent->h_addr, 4);
669 }
670
671 return 0;
672}
673
Jens Axboe0fd666b2011-10-06 20:08:53 +0200674static int fio_netio_setup_connect_unix(struct thread_data *td,
675 const char *path)
676{
677 struct netio_data *nd = td->io_ops->data;
678 struct sockaddr_un *soun = &nd->addr_un;
679
680 soun->sun_family = AF_UNIX;
681 strcpy(soun->sun_path, path);
682 return 0;
683}
684
Steven Langde890a12011-11-09 14:03:34 +0100685static int fio_netio_setup_connect(struct thread_data *td)
Jens Axboe0fd666b2011-10-06 20:08:53 +0200686{
Steven Langde890a12011-11-09 14:03:34 +0100687 struct netio_options *o = td->eo;
Jens Axboe0fd666b2011-10-06 20:08:53 +0200688
Steven Langde890a12011-11-09 14:03:34 +0100689 if (o->proto == FIO_TYPE_UDP || o->proto == FIO_TYPE_TCP)
690 return fio_netio_setup_connect_inet(td, td->o.filename,o->port);
Jens Axboe0fd666b2011-10-06 20:08:53 +0200691 else
Steven Langde890a12011-11-09 14:03:34 +0100692 return fio_netio_setup_connect_unix(td, td->o.filename);
Jens Axboe0fd666b2011-10-06 20:08:53 +0200693}
694
695static int fio_netio_setup_listen_unix(struct thread_data *td, const char *path)
696{
697 struct netio_data *nd = td->io_ops->data;
698 struct sockaddr_un *addr = &nd->addr_un;
699 mode_t mode;
700 int len, fd;
701
702 fd = socket(AF_UNIX, SOCK_STREAM, 0);
703 if (fd < 0) {
704 log_err("fio: socket: %s\n", strerror(errno));
705 return -1;
706 }
707
708 mode = umask(000);
709
710 memset(addr, 0, sizeof(*addr));
711 addr->sun_family = AF_UNIX;
712 strcpy(addr->sun_path, path);
713 unlink(path);
714
715 len = sizeof(addr->sun_family) + strlen(path) + 1;
716
717 if (bind(fd, (struct sockaddr *) addr, len) < 0) {
718 log_err("fio: bind: %s\n", strerror(errno));
Jens Axboeb94cba42011-10-06 21:27:10 +0200719 close(fd);
Jens Axboe0fd666b2011-10-06 20:08:53 +0200720 return -1;
721 }
722
723 umask(mode);
724 nd->listenfd = fd;
725 return 0;
726}
727
728static int fio_netio_setup_listen_inet(struct thread_data *td, short port)
Jens Axboeb5af8292007-03-08 12:43:13 +0100729{
730 struct netio_data *nd = td->io_ops->data;
Steven Langde890a12011-11-09 14:03:34 +0100731 struct netio_options *o = td->eo;
Jens Axboe414c2a32009-01-16 13:21:15 +0100732 int fd, opt, type;
Jens Axboeed92ac02007-02-06 14:43:52 +0100733
Steven Langde890a12011-11-09 14:03:34 +0100734 if (o->proto == FIO_TYPE_TCP)
Jens Axboe414c2a32009-01-16 13:21:15 +0100735 type = SOCK_STREAM;
736 else
737 type = SOCK_DGRAM;
738
Jens Axboe0fd666b2011-10-06 20:08:53 +0200739 fd = socket(AF_INET, type, 0);
Jens Axboeed92ac02007-02-06 14:43:52 +0100740 if (fd < 0) {
Jens Axboee1161c32007-02-22 19:36:48 +0100741 td_verror(td, errno, "socket");
Jens Axboeed92ac02007-02-06 14:43:52 +0100742 return 1;
743 }
744
745 opt = 1;
746 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) {
Jens Axboee1161c32007-02-22 19:36:48 +0100747 td_verror(td, errno, "setsockopt");
Jens Axboeed92ac02007-02-06 14:43:52 +0100748 return 1;
749 }
Jens Axboe6bedbfa2007-02-07 09:54:40 +0100750#ifdef SO_REUSEPORT
751 if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &opt, sizeof(opt)) < 0) {
Jens Axboee1161c32007-02-22 19:36:48 +0100752 td_verror(td, errno, "setsockopt");
Jens Axboe6bedbfa2007-02-07 09:54:40 +0100753 return 1;
754 }
755#endif
Jens Axboeed92ac02007-02-06 14:43:52 +0100756
Jens Axboeb5af8292007-03-08 12:43:13 +0100757 nd->addr.sin_family = AF_INET;
758 nd->addr.sin_addr.s_addr = htonl(INADDR_ANY);
759 nd->addr.sin_port = htons(port);
Jens Axboeed92ac02007-02-06 14:43:52 +0100760
Jens Axboeb5af8292007-03-08 12:43:13 +0100761 if (bind(fd, (struct sockaddr *) &nd->addr, sizeof(nd->addr)) < 0) {
Jens Axboee1161c32007-02-22 19:36:48 +0100762 td_verror(td, errno, "bind");
Jens Axboeed92ac02007-02-06 14:43:52 +0100763 return 1;
764 }
Jens Axboe0fd666b2011-10-06 20:08:53 +0200765
766 nd->listenfd = fd;
767 return 0;
768}
769
Steven Langde890a12011-11-09 14:03:34 +0100770static int fio_netio_setup_listen(struct thread_data *td)
Jens Axboe0fd666b2011-10-06 20:08:53 +0200771{
772 struct netio_data *nd = td->io_ops->data;
Steven Langde890a12011-11-09 14:03:34 +0100773 struct netio_options *o = td->eo;
Jens Axboe0fd666b2011-10-06 20:08:53 +0200774 int ret;
775
Steven Langde890a12011-11-09 14:03:34 +0100776 if (o->proto == FIO_TYPE_UDP || o->proto == FIO_TYPE_TCP)
777 ret = fio_netio_setup_listen_inet(td, o->port);
Jens Axboe0fd666b2011-10-06 20:08:53 +0200778 else
Steven Langde890a12011-11-09 14:03:34 +0100779 ret = fio_netio_setup_listen_unix(td, td->o.filename);
Jens Axboe0fd666b2011-10-06 20:08:53 +0200780
781 if (ret)
782 return ret;
Steven Langde890a12011-11-09 14:03:34 +0100783 if (o->proto == FIO_TYPE_UDP)
Jens Axboe0fd666b2011-10-06 20:08:53 +0200784 return 0;
785
786 if (listen(nd->listenfd, 10) < 0) {
Jens Axboee1161c32007-02-22 19:36:48 +0100787 td_verror(td, errno, "listen");
Jens Axboe0fd666b2011-10-06 20:08:53 +0200788 nd->listenfd = -1;
Jens Axboeed92ac02007-02-06 14:43:52 +0100789 return 1;
790 }
791
Jens Axboeb5af8292007-03-08 12:43:13 +0100792 return 0;
Jens Axboeed92ac02007-02-06 14:43:52 +0100793}
794
Jens Axboe9bec88e2007-03-02 08:55:48 +0100795static int fio_netio_init(struct thread_data *td)
Jens Axboeed92ac02007-02-06 14:43:52 +0100796{
Steven Langde890a12011-11-09 14:03:34 +0100797 struct netio_options *o = td->eo;
Jens Axboeaf52b342007-03-13 10:07:47 +0100798 int ret;
Jens Axboeed92ac02007-02-06 14:43:52 +0100799
Bruce Cran3f457be2012-10-10 13:37:41 +0100800#ifdef WIN32
801 WSADATA wsd;
802 WSAStartup(MAKEWORD(2,2), &wsd);
803#endif
804
Jens Axboe16d55aa2007-05-22 09:21:37 +0200805 if (td_random(td)) {
806 log_err("fio: network IO can't be random\n");
807 return 1;
808 }
Jens Axboeed92ac02007-02-06 14:43:52 +0100809
Steven Langde890a12011-11-09 14:03:34 +0100810 if (o->proto == FIO_TYPE_UNIX && o->port) {
811 log_err("fio: network IO port not valid with unix socket\n");
812 return 1;
813 } else if (o->proto != FIO_TYPE_UNIX && !o->port) {
814 log_err("fio: network IO requires port for tcp or udp\n");
815 return 1;
Jens Axboe414c2a32009-01-16 13:21:15 +0100816 }
Jens Axboe0fd666b2011-10-06 20:08:53 +0200817
Steven Langde890a12011-11-09 14:03:34 +0100818 if (o->proto != FIO_TYPE_TCP) {
819 if (o->listen) {
Jens Axboe9b986062011-12-19 08:57:18 +0100820 log_err("fio: listen only valid for TCP proto IO\n");
821 return 1;
Steven Langde890a12011-11-09 14:03:34 +0100822 }
823 if (td_rw(td)) {
Jens Axboe9b986062011-12-19 08:57:18 +0100824 log_err("fio: datagram network connections must be"
Steven Langde890a12011-11-09 14:03:34 +0100825 " read OR write\n");
Jens Axboe9b986062011-12-19 08:57:18 +0100826 return 1;
827 }
828 if (o->proto == FIO_TYPE_UNIX && !td->o.filename) {
829 log_err("fio: UNIX sockets need host/filename\n");
830 return 1;
Steven Langde890a12011-11-09 14:03:34 +0100831 }
832 o->listen = td_read(td);
833 }
834
835 if (o->proto != FIO_TYPE_UNIX && o->listen && td->o.filename) {
836 log_err("fio: hostname not valid for inbound network IO\n");
837 return 1;
838 }
839
840 if (o->listen)
841 ret = fio_netio_setup_listen(td);
Jens Axboe0fd666b2011-10-06 20:08:53 +0200842 else
Steven Langde890a12011-11-09 14:03:34 +0100843 ret = fio_netio_setup_connect(td);
Jens Axboeed92ac02007-02-06 14:43:52 +0100844
Jens Axboe7bb48f82007-03-27 15:30:28 +0200845 return ret;
Jens Axboeed92ac02007-02-06 14:43:52 +0100846}
847
Jens Axboeb5af8292007-03-08 12:43:13 +0100848static void fio_netio_cleanup(struct thread_data *td)
Jens Axboe9bec88e2007-03-02 08:55:48 +0100849{
Jens Axboeb5af8292007-03-08 12:43:13 +0100850 struct netio_data *nd = td->io_ops->data;
851
852 if (nd) {
Jens Axboe64b24cd2007-06-24 21:28:39 +0200853 if (nd->listenfd != -1)
854 close(nd->listenfd);
855 if (nd->pipes[0] != -1)
856 close(nd->pipes[0]);
857 if (nd->pipes[1] != -1)
858 close(nd->pipes[1]);
859
Jens Axboeb5af8292007-03-08 12:43:13 +0100860 free(nd);
Jens Axboeb5af8292007-03-08 12:43:13 +0100861 }
862}
863
864static int fio_netio_setup(struct thread_data *td)
865{
Jens Axboe7bb48f82007-03-27 15:30:28 +0200866 struct netio_data *nd;
Jens Axboeb5af8292007-03-08 12:43:13 +0100867
Steven Langde890a12011-11-09 14:03:34 +0100868 if (!td->files_index) {
869 add_file(td, td->o.filename ?: "net");
870 td->o.nr_files = td->o.nr_files ?: 1;
871 }
872
Jens Axboe7bb48f82007-03-27 15:30:28 +0200873 if (!td->io_ops->data) {
874 nd = malloc(sizeof(*nd));;
875
876 memset(nd, 0, sizeof(*nd));
877 nd->listenfd = -1;
Jens Axboe64b24cd2007-06-24 21:28:39 +0200878 nd->pipes[0] = nd->pipes[1] = -1;
Jens Axboe7bb48f82007-03-27 15:30:28 +0200879 td->io_ops->data = nd;
Jens Axboe7bb48f82007-03-27 15:30:28 +0200880 }
881
Jens Axboe9bec88e2007-03-02 08:55:48 +0100882 return 0;
883}
884
Jens Axboe36d80bc2012-11-30 21:46:06 +0100885static void fio_netio_terminate(struct thread_data *td)
886{
887 kill(td->pid, SIGUSR2);
888}
889
Jens Axboe5921e802008-05-30 15:02:38 +0200890#ifdef FIO_HAVE_SPLICE
Jens Axboe9cce02e2007-06-22 15:42:21 +0200891static int fio_netio_setup_splice(struct thread_data *td)
892{
893 struct netio_data *nd;
894
895 fio_netio_setup(td);
896
897 nd = td->io_ops->data;
898 if (nd) {
899 if (pipe(nd->pipes) < 0)
900 return 1;
901
902 nd->use_splice = 1;
903 return 0;
904 }
905
906 return 1;
907}
908
Jens Axboe5921e802008-05-30 15:02:38 +0200909static struct ioengine_ops ioengine_splice = {
Steven Langde890a12011-11-09 14:03:34 +0100910 .name = "netsplice",
911 .version = FIO_IOOPS_VERSION,
912 .prep = fio_netio_prep,
913 .queue = fio_netio_queue,
914 .setup = fio_netio_setup_splice,
915 .init = fio_netio_init,
916 .cleanup = fio_netio_cleanup,
917 .open_file = fio_netio_open_file,
Jens Axboe36d80bc2012-11-30 21:46:06 +0100918 .close_file = fio_netio_close_file,
919 .terminate = fio_netio_terminate,
Steven Langde890a12011-11-09 14:03:34 +0100920 .options = options,
921 .option_struct_size = sizeof(struct netio_options),
922 .flags = FIO_SYNCIO | FIO_DISKLESSIO | FIO_UNIDIR |
Jens Axboe36d80bc2012-11-30 21:46:06 +0100923 FIO_PIPEIO,
Jens Axboe5921e802008-05-30 15:02:38 +0200924};
925#endif
926
Jens Axboe9cce02e2007-06-22 15:42:21 +0200927static struct ioengine_ops ioengine_rw = {
Steven Langde890a12011-11-09 14:03:34 +0100928 .name = "net",
929 .version = FIO_IOOPS_VERSION,
930 .prep = fio_netio_prep,
931 .queue = fio_netio_queue,
932 .setup = fio_netio_setup,
933 .init = fio_netio_init,
934 .cleanup = fio_netio_cleanup,
935 .open_file = fio_netio_open_file,
936 .close_file = fio_netio_close_file,
Jens Axboe36d80bc2012-11-30 21:46:06 +0100937 .terminate = fio_netio_terminate,
Steven Langde890a12011-11-09 14:03:34 +0100938 .options = options,
939 .option_struct_size = sizeof(struct netio_options),
940 .flags = FIO_SYNCIO | FIO_DISKLESSIO | FIO_UNIDIR |
Jens Axboe36d80bc2012-11-30 21:46:06 +0100941 FIO_PIPEIO,
Jens Axboeed92ac02007-02-06 14:43:52 +0100942};
943
Steven Langde890a12011-11-09 14:03:34 +0100944static int str_hostname_cb(void *data, const char *input)
945{
946 struct netio_options *o = data;
947
948 if (o->td->o.filename)
949 free(o->td->o.filename);
950 o->td->o.filename = strdup(input);
951 return 0;
952}
953
Jens Axboeed92ac02007-02-06 14:43:52 +0100954static void fio_init fio_netio_register(void)
955{
Jens Axboe9cce02e2007-06-22 15:42:21 +0200956 register_ioengine(&ioengine_rw);
Jens Axboe5921e802008-05-30 15:02:38 +0200957#ifdef FIO_HAVE_SPLICE
Jens Axboe9cce02e2007-06-22 15:42:21 +0200958 register_ioengine(&ioengine_splice);
Jens Axboe5921e802008-05-30 15:02:38 +0200959#endif
Jens Axboeed92ac02007-02-06 14:43:52 +0100960}
961
962static void fio_exit fio_netio_unregister(void)
963{
Jens Axboe9cce02e2007-06-22 15:42:21 +0200964 unregister_ioengine(&ioengine_rw);
Jens Axboe5921e802008-05-30 15:02:38 +0200965#ifdef FIO_HAVE_SPLICE
Jens Axboe9cce02e2007-06-22 15:42:21 +0200966 unregister_ioengine(&ioengine_splice);
Jens Axboe5921e802008-05-30 15:02:38 +0200967#endif
Jens Axboeed92ac02007-02-06 14:43:52 +0100968}