blob: 94bae95af988e167143c089d015a1eda58b81d05 [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>
10#include <errno.h>
11#include <assert.h>
12#include <netinet/in.h>
13#include <arpa/inet.h>
14#include <netdb.h>
Jens Axboe5fdd1242007-02-11 04:00:37 +010015#include <sys/poll.h>
Jens Axboeed92ac02007-02-06 14:43:52 +010016
17#include "../fio.h"
Jens Axboeed92ac02007-02-06 14:43:52 +010018
Jens Axboeb5af8292007-03-08 12:43:13 +010019struct netio_data {
20 int listenfd;
21 int send_to_net;
Jens Axboe9cce02e2007-06-22 15:42:21 +020022 int use_splice;
23 int pipes[2];
Jens Axboeb5af8292007-03-08 12:43:13 +010024 char host[64];
25 struct sockaddr_in addr;
26};
Jens Axboeed92ac02007-02-06 14:43:52 +010027
28static int fio_netio_prep(struct thread_data *td, struct io_u *io_u)
29{
Jens Axboeb5af8292007-03-08 12:43:13 +010030 struct netio_data *nd = td->io_ops->data;
Jens Axboeed92ac02007-02-06 14:43:52 +010031
Jens Axboe7a6499d2007-02-07 09:35:29 +010032 /*
33 * Make sure we don't see spurious reads to a receiver, and vice versa
34 */
Jens Axboeb5af8292007-03-08 12:43:13 +010035 if ((nd->send_to_net && io_u->ddir == DDIR_READ) ||
36 (!nd->send_to_net && io_u->ddir == DDIR_WRITE)) {
Jens Axboee1161c32007-02-22 19:36:48 +010037 td_verror(td, EINVAL, "bad direction");
Jens Axboe7a6499d2007-02-07 09:35:29 +010038 return 1;
Jens Axboeed92ac02007-02-06 14:43:52 +010039 }
Jens Axboe7a6499d2007-02-07 09:35:29 +010040
Jens Axboef85ac252008-03-01 18:09:49 +010041 return 0;
Jens Axboeed92ac02007-02-06 14:43:52 +010042}
43
Jens Axboe5921e802008-05-30 15:02:38 +020044#ifdef FIO_HAVE_SPLICE
Jens Axboecd963e12007-06-24 21:41:46 +020045static int splice_io_u(int fdin, int fdout, unsigned int len)
Jens Axboe9cce02e2007-06-22 15:42:21 +020046{
Jens Axboe9cce02e2007-06-22 15:42:21 +020047 int bytes = 0;
48
49 while (len) {
Jens Axboecd963e12007-06-24 21:41:46 +020050 int ret = splice(fdin, NULL, fdout, NULL, len, 0);
Jens Axboe9cce02e2007-06-22 15:42:21 +020051
52 if (ret < 0) {
53 if (!bytes)
54 bytes = ret;
55
56 break;
57 } else if (!ret)
58 break;
59
60 bytes += ret;
Jens Axboef657a2f2007-06-22 20:40:10 +020061 len -= ret;
Jens Axboe9cce02e2007-06-22 15:42:21 +020062 }
63
64 return bytes;
65}
66
67/*
Jens Axboecd963e12007-06-24 21:41:46 +020068 * Receive bytes from a socket and fill them into the internal pipe
69 */
70static int splice_in(struct thread_data *td, struct io_u *io_u)
71{
72 struct netio_data *nd = td->io_ops->data;
73
74 return splice_io_u(io_u->file->fd, nd->pipes[1], io_u->xfer_buflen);
75}
76
77/*
Jens Axboe9cce02e2007-06-22 15:42:21 +020078 * Transmit 'len' bytes from the internal pipe
79 */
80static int splice_out(struct thread_data *td, struct io_u *io_u,
81 unsigned int len)
82{
83 struct netio_data *nd = td->io_ops->data;
Jens Axboecd963e12007-06-24 21:41:46 +020084
85 return splice_io_u(nd->pipes[0], io_u->file->fd, len);
86}
87
88static int vmsplice_io_u(struct io_u *io_u, int fd, unsigned int len)
89{
90 struct iovec iov = {
91 .iov_base = io_u->xfer_buf,
92 .iov_len = len,
93 };
Jens Axboe9cce02e2007-06-22 15:42:21 +020094 int bytes = 0;
95
Jens Axboecd963e12007-06-24 21:41:46 +020096 while (iov.iov_len) {
97 int ret = vmsplice(fd, &iov, 1, SPLICE_F_MOVE);
Jens Axboe9cce02e2007-06-22 15:42:21 +020098
99 if (ret < 0) {
100 if (!bytes)
101 bytes = ret;
Jens Axboe9cce02e2007-06-22 15:42:21 +0200102 break;
103 } else if (!ret)
104 break;
105
Jens Axboecd963e12007-06-24 21:41:46 +0200106 iov.iov_len -= ret;
107 iov.iov_base += ret;
Jens Axboe9cce02e2007-06-22 15:42:21 +0200108 bytes += ret;
Jens Axboe9cce02e2007-06-22 15:42:21 +0200109 }
110
111 return bytes;
Jens Axboecd963e12007-06-24 21:41:46 +0200112
Jens Axboe9cce02e2007-06-22 15:42:21 +0200113}
114
115/*
116 * vmsplice() pipe to io_u buffer
117 */
118static int vmsplice_io_u_out(struct thread_data *td, struct io_u *io_u,
119 unsigned int len)
120{
121 struct netio_data *nd = td->io_ops->data;
Jens Axboe9cce02e2007-06-22 15:42:21 +0200122
Jens Axboecd963e12007-06-24 21:41:46 +0200123 return vmsplice_io_u(io_u, nd->pipes[0], len);
Jens Axboe9cce02e2007-06-22 15:42:21 +0200124}
125
126/*
127 * vmsplice() io_u to pipe
128 */
129static int vmsplice_io_u_in(struct thread_data *td, struct io_u *io_u)
130{
131 struct netio_data *nd = td->io_ops->data;
Jens Axboe9cce02e2007-06-22 15:42:21 +0200132
Jens Axboecd963e12007-06-24 21:41:46 +0200133 return vmsplice_io_u(io_u, nd->pipes[1], io_u->xfer_buflen);
Jens Axboe9cce02e2007-06-22 15:42:21 +0200134}
135
Jens Axboecd963e12007-06-24 21:41:46 +0200136/*
137 * splice receive - transfer socket data into a pipe using splice, then map
138 * that pipe data into the io_u using vmsplice.
139 */
Jens Axboe9cce02e2007-06-22 15:42:21 +0200140static int fio_netio_splice_in(struct thread_data *td, struct io_u *io_u)
141{
142 int ret;
143
144 ret = splice_in(td, io_u);
Jens Axboecd963e12007-06-24 21:41:46 +0200145 if (ret > 0)
146 return vmsplice_io_u_out(td, io_u, ret);
Jens Axboe9cce02e2007-06-22 15:42:21 +0200147
Jens Axboecd963e12007-06-24 21:41:46 +0200148 return ret;
Jens Axboe9cce02e2007-06-22 15:42:21 +0200149}
150
Jens Axboecd963e12007-06-24 21:41:46 +0200151/*
152 * splice transmit - map data from the io_u into a pipe by using vmsplice,
153 * then transfer that pipe to a socket using splice.
154 */
Jens Axboe9cce02e2007-06-22 15:42:21 +0200155static int fio_netio_splice_out(struct thread_data *td, struct io_u *io_u)
156{
157 int ret;
158
159 ret = vmsplice_io_u_in(td, io_u);
Jens Axboecd963e12007-06-24 21:41:46 +0200160 if (ret > 0)
161 return splice_out(td, io_u, ret);
Jens Axboe9cce02e2007-06-22 15:42:21 +0200162
Jens Axboecd963e12007-06-24 21:41:46 +0200163 return ret;
Jens Axboe9cce02e2007-06-22 15:42:21 +0200164}
Jens Axboe5921e802008-05-30 15:02:38 +0200165#else
166static int fio_netio_splice_in(struct thread_data *td, struct io_u *io_u)
167{
Jens Axboeaf8771b2008-05-30 22:58:28 +0200168 errno = EOPNOTSUPP;
Jens Axboe5921e802008-05-30 15:02:38 +0200169 return -1;
170}
171
172static int fio_netio_splice_out(struct thread_data *td, struct io_u *io_u)
173{
Jens Axboeaf8771b2008-05-30 22:58:28 +0200174 errno = EOPNOTSUPP;
Jens Axboe5921e802008-05-30 15:02:38 +0200175 return -1;
176}
177#endif
Jens Axboe9cce02e2007-06-22 15:42:21 +0200178
179static int fio_netio_send(struct thread_data *td, struct io_u *io_u)
180{
181 int flags = 0;
182
183 /*
184 * if we are going to write more, set MSG_MORE
185 */
Jens Axboe5921e802008-05-30 15:02:38 +0200186#ifdef MSG_MORE
Jens Axboe9cce02e2007-06-22 15:42:21 +0200187 if (td->this_io_bytes[DDIR_WRITE] + io_u->xfer_buflen < td->o.size)
188 flags = MSG_MORE;
Jens Axboe5921e802008-05-30 15:02:38 +0200189#endif
Jens Axboe9cce02e2007-06-22 15:42:21 +0200190
191 return send(io_u->file->fd, io_u->xfer_buf, io_u->xfer_buflen, flags);
192}
193
194static int fio_netio_recv(struct io_u *io_u)
195{
196 int flags = MSG_WAITALL;
197
198 return recv(io_u->file->fd, io_u->xfer_buf, io_u->xfer_buflen, flags);
199}
200
Jens Axboeed92ac02007-02-06 14:43:52 +0100201static int fio_netio_queue(struct thread_data *td, struct io_u *io_u)
202{
Jens Axboe9cce02e2007-06-22 15:42:21 +0200203 struct netio_data *nd = td->io_ops->data;
204 int ret;
Jens Axboeed92ac02007-02-06 14:43:52 +0100205
Jens Axboe7101d9c2007-09-12 13:12:39 +0200206 fio_ro_check(td, io_u);
207
Jens Axboe7a6499d2007-02-07 09:35:29 +0100208 if (io_u->ddir == DDIR_WRITE) {
Jens Axboe9cce02e2007-06-22 15:42:21 +0200209 if (nd->use_splice)
210 ret = fio_netio_splice_out(td, io_u);
211 else
212 ret = fio_netio_send(td, io_u);
Jens Axboed4f12dd2007-02-08 12:59:02 +0100213 } else if (io_u->ddir == DDIR_READ) {
Jens Axboe9cce02e2007-06-22 15:42:21 +0200214 if (nd->use_splice)
215 ret = fio_netio_splice_in(td, io_u);
216 else
217 ret = fio_netio_recv(io_u);
Jens Axboed4f12dd2007-02-08 12:59:02 +0100218 } else
Jens Axboe7a6499d2007-02-07 09:35:29 +0100219 ret = 0; /* must be a SYNC */
Jens Axboeed92ac02007-02-06 14:43:52 +0100220
Jens Axboecec6b552007-02-06 20:15:38 +0100221 if (ret != (int) io_u->xfer_buflen) {
Jens Axboe22819ec2007-02-18 07:47:14 +0100222 if (ret >= 0) {
Jens Axboecec6b552007-02-06 20:15:38 +0100223 io_u->resid = io_u->xfer_buflen - ret;
224 io_u->error = 0;
Jens Axboe36167d82007-02-18 05:41:31 +0100225 return FIO_Q_COMPLETED;
Jens Axboeed92ac02007-02-06 14:43:52 +0100226 } else
227 io_u->error = errno;
228 }
229
Jens Axboe36167d82007-02-18 05:41:31 +0100230 if (io_u->error)
Jens Axboee1161c32007-02-22 19:36:48 +0100231 td_verror(td, io_u->error, "xfer");
Jens Axboeed92ac02007-02-06 14:43:52 +0100232
Jens Axboe36167d82007-02-18 05:41:31 +0100233 return FIO_Q_COMPLETED;
Jens Axboeed92ac02007-02-06 14:43:52 +0100234}
235
Jens Axboeb5af8292007-03-08 12:43:13 +0100236static int fio_netio_connect(struct thread_data *td, struct fio_file *f)
Jens Axboeed92ac02007-02-06 14:43:52 +0100237{
Jens Axboeb5af8292007-03-08 12:43:13 +0100238 struct netio_data *nd = td->io_ops->data;
Jens Axboeed92ac02007-02-06 14:43:52 +0100239
Jens Axboeb5af8292007-03-08 12:43:13 +0100240 f->fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
241 if (f->fd < 0) {
242 td_verror(td, errno, "socket");
243 return 1;
Jens Axboeed92ac02007-02-06 14:43:52 +0100244 }
245
Jens Axboeb5af8292007-03-08 12:43:13 +0100246 if (connect(f->fd, (struct sockaddr *) &nd->addr, sizeof(nd->addr)) < 0) {
247 td_verror(td, errno, "connect");
248 return 1;
Jens Axboeed92ac02007-02-06 14:43:52 +0100249 }
250
251 return 0;
Jens Axboeed92ac02007-02-06 14:43:52 +0100252}
253
Jens Axboeb5af8292007-03-08 12:43:13 +0100254static int fio_netio_accept(struct thread_data *td, struct fio_file *f)
Jens Axboe5fdd1242007-02-11 04:00:37 +0100255{
Jens Axboeb5af8292007-03-08 12:43:13 +0100256 struct netio_data *nd = td->io_ops->data;
257 socklen_t socklen = sizeof(nd->addr);
Jens Axboe5fdd1242007-02-11 04:00:37 +0100258 struct pollfd pfd;
Jens Axboeb5af8292007-03-08 12:43:13 +0100259 int ret;
Jens Axboe5fdd1242007-02-11 04:00:37 +0100260
Jens Axboe6d861442007-03-15 09:22:23 +0100261 log_info("fio: waiting for connection\n");
Jens Axboe5fdd1242007-02-11 04:00:37 +0100262
263 /*
264 * Accept loop. poll for incoming events, accept them. Repeat until we
265 * have all connections.
266 */
Jens Axboeb5af8292007-03-08 12:43:13 +0100267 while (!td->terminate) {
268 pfd.fd = nd->listenfd;
Jens Axboe5fdd1242007-02-11 04:00:37 +0100269 pfd.events = POLLIN;
270
271 ret = poll(&pfd, 1, -1);
272 if (ret < 0) {
273 if (errno == EINTR)
274 continue;
275
Jens Axboee1161c32007-02-22 19:36:48 +0100276 td_verror(td, errno, "poll");
Jens Axboe5fdd1242007-02-11 04:00:37 +0100277 break;
278 } else if (!ret)
279 continue;
280
Jens Axboe0c094422007-02-11 04:44:02 +0100281 /*
282 * should be impossible
283 */
284 if (!(pfd.revents & POLLIN))
285 continue;
286
Jens Axboeb5af8292007-03-08 12:43:13 +0100287 f->fd = accept(nd->listenfd, (struct sockaddr *) &nd->addr, &socklen);
288 if (f->fd < 0) {
289 td_verror(td, errno, "accept");
290 return 1;
Jens Axboe5fdd1242007-02-11 04:00:37 +0100291 }
Jens Axboeb5af8292007-03-08 12:43:13 +0100292 break;
Jens Axboe5fdd1242007-02-11 04:00:37 +0100293 }
294
295 return 0;
296}
297
Jens Axboeb5af8292007-03-08 12:43:13 +0100298static int fio_netio_open_file(struct thread_data *td, struct fio_file *f)
Jens Axboeed92ac02007-02-06 14:43:52 +0100299{
Jens Axboeb5af8292007-03-08 12:43:13 +0100300 if (td_read(td))
301 return fio_netio_accept(td, f);
302 else
303 return fio_netio_connect(td, f);
304}
305
306static int fio_netio_setup_connect(struct thread_data *td, const char *host,
307 unsigned short port)
308{
309 struct netio_data *nd = td->io_ops->data;
310
311 nd->addr.sin_family = AF_INET;
312 nd->addr.sin_port = htons(port);
313
314 if (inet_aton(host, &nd->addr.sin_addr) != 1) {
315 struct hostent *hent;
316
317 hent = gethostbyname(host);
318 if (!hent) {
319 td_verror(td, errno, "gethostbyname");
320 return 1;
321 }
322
323 memcpy(&nd->addr.sin_addr, hent->h_addr, 4);
324 }
325
326 return 0;
327}
328
329static int fio_netio_setup_listen(struct thread_data *td, short port)
330{
331 struct netio_data *nd = td->io_ops->data;
Jens Axboe5fdd1242007-02-11 04:00:37 +0100332 int fd, opt;
Jens Axboeed92ac02007-02-06 14:43:52 +0100333
Jens Axboe6bedbfa2007-02-07 09:54:40 +0100334 fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
Jens Axboeed92ac02007-02-06 14:43:52 +0100335 if (fd < 0) {
Jens Axboee1161c32007-02-22 19:36:48 +0100336 td_verror(td, errno, "socket");
Jens Axboeed92ac02007-02-06 14:43:52 +0100337 return 1;
338 }
339
340 opt = 1;
341 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) {
Jens Axboee1161c32007-02-22 19:36:48 +0100342 td_verror(td, errno, "setsockopt");
Jens Axboeed92ac02007-02-06 14:43:52 +0100343 return 1;
344 }
Jens Axboe6bedbfa2007-02-07 09:54:40 +0100345#ifdef SO_REUSEPORT
346 if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &opt, sizeof(opt)) < 0) {
Jens Axboee1161c32007-02-22 19:36:48 +0100347 td_verror(td, errno, "setsockopt");
Jens Axboe6bedbfa2007-02-07 09:54:40 +0100348 return 1;
349 }
350#endif
Jens Axboeed92ac02007-02-06 14:43:52 +0100351
Jens Axboeb5af8292007-03-08 12:43:13 +0100352 nd->addr.sin_family = AF_INET;
353 nd->addr.sin_addr.s_addr = htonl(INADDR_ANY);
354 nd->addr.sin_port = htons(port);
Jens Axboeed92ac02007-02-06 14:43:52 +0100355
Jens Axboeb5af8292007-03-08 12:43:13 +0100356 if (bind(fd, (struct sockaddr *) &nd->addr, sizeof(nd->addr)) < 0) {
Jens Axboee1161c32007-02-22 19:36:48 +0100357 td_verror(td, errno, "bind");
Jens Axboeed92ac02007-02-06 14:43:52 +0100358 return 1;
359 }
360 if (listen(fd, 1) < 0) {
Jens Axboee1161c32007-02-22 19:36:48 +0100361 td_verror(td, errno, "listen");
Jens Axboeed92ac02007-02-06 14:43:52 +0100362 return 1;
363 }
364
Jens Axboeb5af8292007-03-08 12:43:13 +0100365 nd->listenfd = fd;
366 return 0;
Jens Axboeed92ac02007-02-06 14:43:52 +0100367}
368
Jens Axboe9bec88e2007-03-02 08:55:48 +0100369static int fio_netio_init(struct thread_data *td)
Jens Axboeed92ac02007-02-06 14:43:52 +0100370{
Jens Axboeb5af8292007-03-08 12:43:13 +0100371 struct netio_data *nd = td->io_ops->data;
Jens Axboe443662e2008-05-30 13:29:03 +0200372 unsigned int port;
Jens Axboeb5af8292007-03-08 12:43:13 +0100373 char host[64], buf[128];
Jens Axboeed92ac02007-02-06 14:43:52 +0100374 char *sep;
Jens Axboeaf52b342007-03-13 10:07:47 +0100375 int ret;
Jens Axboeed92ac02007-02-06 14:43:52 +0100376
Jens Axboe413dd452007-02-23 09:26:09 +0100377 if (td_rw(td)) {
Jens Axboeed92ac02007-02-06 14:43:52 +0100378 log_err("fio: network connections must be read OR write\n");
379 return 1;
380 }
Jens Axboe16d55aa2007-05-22 09:21:37 +0200381 if (td_random(td)) {
382 log_err("fio: network IO can't be random\n");
383 return 1;
384 }
Jens Axboeed92ac02007-02-06 14:43:52 +0100385
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100386 strcpy(buf, td->o.filename);
Jens Axboeed92ac02007-02-06 14:43:52 +0100387
Jens Axboe9f9214f2007-03-13 14:02:16 +0100388 sep = strchr(buf, '/');
Jens Axboe443662e2008-05-30 13:29:03 +0200389 if (!sep)
390 goto bad_host;
Jens Axboeed92ac02007-02-06 14:43:52 +0100391
392 *sep = '\0';
393 sep++;
394 strcpy(host, buf);
Jens Axboe443662e2008-05-30 13:29:03 +0200395 if (!strlen(host))
396 goto bad_host;
397
398 port = strtol(sep, NULL, 10);
399 if (!port || port > 65535)
400 goto bad_host;
Jens Axboeed92ac02007-02-06 14:43:52 +0100401
Jens Axboe413dd452007-02-23 09:26:09 +0100402 if (td_read(td)) {
Jens Axboeb5af8292007-03-08 12:43:13 +0100403 nd->send_to_net = 0;
Jens Axboeed92ac02007-02-06 14:43:52 +0100404 ret = fio_netio_setup_listen(td, port);
405 } else {
Jens Axboeb5af8292007-03-08 12:43:13 +0100406 nd->send_to_net = 1;
Jens Axboeed92ac02007-02-06 14:43:52 +0100407 ret = fio_netio_setup_connect(td, host, port);
408 }
409
Jens Axboe7bb48f82007-03-27 15:30:28 +0200410 return ret;
Jens Axboe443662e2008-05-30 13:29:03 +0200411bad_host:
412 log_err("fio: bad network host/port: %s\n", td->o.filename);
413 return 1;
Jens Axboeed92ac02007-02-06 14:43:52 +0100414}
415
Jens Axboeb5af8292007-03-08 12:43:13 +0100416static void fio_netio_cleanup(struct thread_data *td)
Jens Axboe9bec88e2007-03-02 08:55:48 +0100417{
Jens Axboeb5af8292007-03-08 12:43:13 +0100418 struct netio_data *nd = td->io_ops->data;
419
420 if (nd) {
Jens Axboe64b24cd2007-06-24 21:28:39 +0200421 if (nd->listenfd != -1)
422 close(nd->listenfd);
423 if (nd->pipes[0] != -1)
424 close(nd->pipes[0]);
425 if (nd->pipes[1] != -1)
426 close(nd->pipes[1]);
427
Jens Axboeb5af8292007-03-08 12:43:13 +0100428 free(nd);
Jens Axboeb5af8292007-03-08 12:43:13 +0100429 }
430}
431
432static int fio_netio_setup(struct thread_data *td)
433{
Jens Axboe7bb48f82007-03-27 15:30:28 +0200434 struct netio_data *nd;
Jens Axboeb5af8292007-03-08 12:43:13 +0100435
Jens Axboe7bb48f82007-03-27 15:30:28 +0200436 if (!td->io_ops->data) {
437 nd = malloc(sizeof(*nd));;
438
439 memset(nd, 0, sizeof(*nd));
440 nd->listenfd = -1;
Jens Axboe64b24cd2007-06-24 21:28:39 +0200441 nd->pipes[0] = nd->pipes[1] = -1;
Jens Axboe7bb48f82007-03-27 15:30:28 +0200442 td->io_ops->data = nd;
Jens Axboe7bb48f82007-03-27 15:30:28 +0200443 }
444
Jens Axboe9bec88e2007-03-02 08:55:48 +0100445 return 0;
446}
447
Jens Axboe5921e802008-05-30 15:02:38 +0200448#ifdef FIO_HAVE_SPLICE
Jens Axboe9cce02e2007-06-22 15:42:21 +0200449static int fio_netio_setup_splice(struct thread_data *td)
450{
451 struct netio_data *nd;
452
453 fio_netio_setup(td);
454
455 nd = td->io_ops->data;
456 if (nd) {
457 if (pipe(nd->pipes) < 0)
458 return 1;
459
460 nd->use_splice = 1;
461 return 0;
462 }
463
464 return 1;
465}
466
Jens Axboe5921e802008-05-30 15:02:38 +0200467static struct ioengine_ops ioengine_splice = {
468 .name = "netsplice",
469 .version = FIO_IOOPS_VERSION,
470 .prep = fio_netio_prep,
471 .queue = fio_netio_queue,
472 .setup = fio_netio_setup_splice,
473 .init = fio_netio_init,
474 .cleanup = fio_netio_cleanup,
475 .open_file = fio_netio_open_file,
476 .close_file = generic_close_file,
477 .flags = FIO_SYNCIO | FIO_DISKLESSIO | FIO_UNIDIR |
478 FIO_SIGQUIT,
479};
480#endif
481
Jens Axboe9cce02e2007-06-22 15:42:21 +0200482static struct ioengine_ops ioengine_rw = {
Jens Axboeed92ac02007-02-06 14:43:52 +0100483 .name = "net",
484 .version = FIO_IOOPS_VERSION,
Jens Axboeed92ac02007-02-06 14:43:52 +0100485 .prep = fio_netio_prep,
486 .queue = fio_netio_queue,
Jens Axboeed92ac02007-02-06 14:43:52 +0100487 .setup = fio_netio_setup,
Jens Axboe9bec88e2007-03-02 08:55:48 +0100488 .init = fio_netio_init,
Jens Axboeb5af8292007-03-08 12:43:13 +0100489 .cleanup = fio_netio_cleanup,
490 .open_file = fio_netio_open_file,
491 .close_file = generic_close_file,
Jens Axboead830ed2008-02-18 21:11:24 +0100492 .flags = FIO_SYNCIO | FIO_DISKLESSIO | FIO_UNIDIR |
493 FIO_SIGQUIT,
Jens Axboeed92ac02007-02-06 14:43:52 +0100494};
495
496static void fio_init fio_netio_register(void)
497{
Jens Axboe9cce02e2007-06-22 15:42:21 +0200498 register_ioengine(&ioengine_rw);
Jens Axboe5921e802008-05-30 15:02:38 +0200499#ifdef FIO_HAVE_SPLICE
Jens Axboe9cce02e2007-06-22 15:42:21 +0200500 register_ioengine(&ioengine_splice);
Jens Axboe5921e802008-05-30 15:02:38 +0200501#endif
Jens Axboeed92ac02007-02-06 14:43:52 +0100502}
503
504static void fio_exit fio_netio_unregister(void)
505{
Jens Axboe9cce02e2007-06-22 15:42:21 +0200506 unregister_ioengine(&ioengine_rw);
Jens Axboe5921e802008-05-30 15:02:38 +0200507#ifdef FIO_HAVE_SPLICE
Jens Axboe9cce02e2007-06-22 15:42:21 +0200508 unregister_ioengine(&ioengine_splice);
Jens Axboe5921e802008-05-30 15:02:38 +0200509#endif
Jens Axboeed92ac02007-02-06 14:43:52 +0100510}