Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 1 | /* |
Jens Axboe | da751ca | 2007-03-14 10:59:33 +0100 | [diff] [blame] | 2 | * net engine |
| 3 | * |
| 4 | * IO engine that reads/writes to/from sockets. |
| 5 | * |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 6 | */ |
| 7 | #include <stdio.h> |
| 8 | #include <stdlib.h> |
| 9 | #include <unistd.h> |
Steven Noonan | 842805f | 2012-12-01 08:16:55 +0000 | [diff] [blame] | 10 | #include <signal.h> |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 11 | #include <errno.h> |
| 12 | #include <assert.h> |
| 13 | #include <netinet/in.h> |
Steven Noonan | 70a7878 | 2012-11-28 14:52:36 -0800 | [diff] [blame] | 14 | #include <netinet/tcp.h> |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 15 | #include <arpa/inet.h> |
| 16 | #include <netdb.h> |
Jens Axboe | 5fdd124 | 2007-02-11 04:00:37 +0100 | [diff] [blame] | 17 | #include <sys/poll.h> |
Jens Axboe | 7292056 | 2008-06-02 12:30:06 +0200 | [diff] [blame] | 18 | #include <sys/types.h> |
Jens Axboe | 0fd666b | 2011-10-06 20:08:53 +0200 | [diff] [blame] | 19 | #include <sys/stat.h> |
Jens Axboe | 7292056 | 2008-06-02 12:30:06 +0200 | [diff] [blame] | 20 | #include <sys/socket.h> |
Jens Axboe | 0fd666b | 2011-10-06 20:08:53 +0200 | [diff] [blame] | 21 | #include <sys/un.h> |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 22 | |
| 23 | #include "../fio.h" |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 24 | |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 25 | struct netio_data { |
| 26 | int listenfd; |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 27 | int use_splice; |
| 28 | int pipes[2]; |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 29 | struct sockaddr_in addr; |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 30 | struct sockaddr_in6 addr6; |
Jens Axboe | 0fd666b | 2011-10-06 20:08:53 +0200 | [diff] [blame] | 31 | struct sockaddr_un addr_un; |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 32 | }; |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 33 | |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 34 | struct netio_options { |
| 35 | struct thread_data *td; |
| 36 | unsigned int port; |
| 37 | unsigned int proto; |
| 38 | unsigned int listen; |
Jens Axboe | 6f73a7f | 2012-11-30 09:59:20 +0100 | [diff] [blame] | 39 | unsigned int pingpong; |
Steven Noonan | 70a7878 | 2012-11-28 14:52:36 -0800 | [diff] [blame] | 40 | unsigned int nodelay; |
Shawn Bohrer | d3a623d | 2013-07-19 13:24:08 -0500 | [diff] [blame] | 41 | unsigned int ttl; |
Bruce Cran | f16b740 | 2013-10-08 15:05:27 +0100 | [diff] [blame] | 42 | char *intfc; |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 43 | }; |
| 44 | |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 45 | struct udp_close_msg { |
| 46 | uint32_t magic; |
| 47 | uint32_t cmd; |
| 48 | }; |
| 49 | |
| 50 | enum { |
| 51 | FIO_LINK_CLOSE = 0x89, |
Jens Axboe | b96d243 | 2012-11-30 08:27:46 +0100 | [diff] [blame] | 52 | FIO_LINK_OPEN_CLOSE_MAGIC = 0x6c696e6b, |
| 53 | FIO_LINK_OPEN = 0x98, |
Jens Axboe | 0fd666b | 2011-10-06 20:08:53 +0200 | [diff] [blame] | 54 | |
| 55 | FIO_TYPE_TCP = 1, |
| 56 | FIO_TYPE_UDP = 2, |
| 57 | FIO_TYPE_UNIX = 3, |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 58 | FIO_TYPE_TCP_V6 = 4, |
| 59 | FIO_TYPE_UDP_V6 = 5, |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 60 | }; |
| 61 | |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 62 | static int str_hostname_cb(void *data, const char *input); |
| 63 | static struct fio_option options[] = { |
| 64 | { |
| 65 | .name = "hostname", |
Jens Axboe | e8b0e95 | 2012-03-19 14:37:08 +0100 | [diff] [blame] | 66 | .lname = "net engine hostname", |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 67 | .type = FIO_OPT_STR_STORE, |
| 68 | .cb = str_hostname_cb, |
| 69 | .help = "Hostname for net IO engine", |
Jens Axboe | e90a0ad | 2013-04-10 19:43:59 +0200 | [diff] [blame] | 70 | .category = FIO_OPT_C_ENGINE, |
| 71 | .group = FIO_OPT_G_NETIO, |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 72 | }, |
| 73 | { |
| 74 | .name = "port", |
Jens Axboe | e8b0e95 | 2012-03-19 14:37:08 +0100 | [diff] [blame] | 75 | .lname = "net engine port", |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 76 | .type = FIO_OPT_INT, |
| 77 | .off1 = offsetof(struct netio_options, port), |
| 78 | .minval = 1, |
| 79 | .maxval = 65535, |
| 80 | .help = "Port to use for TCP or UDP net connections", |
Jens Axboe | e90a0ad | 2013-04-10 19:43:59 +0200 | [diff] [blame] | 81 | .category = FIO_OPT_C_ENGINE, |
| 82 | .group = FIO_OPT_G_NETIO, |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 83 | }, |
| 84 | { |
| 85 | .name = "protocol", |
Jens Axboe | e8b0e95 | 2012-03-19 14:37:08 +0100 | [diff] [blame] | 86 | .lname = "net engine protocol", |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 87 | .alias = "proto", |
| 88 | .type = FIO_OPT_STR, |
| 89 | .off1 = offsetof(struct netio_options, proto), |
| 90 | .help = "Network protocol to use", |
| 91 | .def = "tcp", |
| 92 | .posval = { |
| 93 | { .ival = "tcp", |
| 94 | .oval = FIO_TYPE_TCP, |
| 95 | .help = "Transmission Control Protocol", |
| 96 | }, |
Jens Axboe | eb23231 | 2014-01-24 18:59:15 -0800 | [diff] [blame] | 97 | #ifdef CONFIG_IPV6 |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 98 | { .ival = "tcpv6", |
| 99 | .oval = FIO_TYPE_TCP_V6, |
| 100 | .help = "Transmission Control Protocol V6", |
| 101 | }, |
Jens Axboe | eb23231 | 2014-01-24 18:59:15 -0800 | [diff] [blame] | 102 | #endif |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 103 | { .ival = "udp", |
| 104 | .oval = FIO_TYPE_UDP, |
Bruce Cran | f5cc3d0 | 2012-10-10 08:17:44 -0600 | [diff] [blame] | 105 | .help = "User Datagram Protocol", |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 106 | }, |
Jens Axboe | eb23231 | 2014-01-24 18:59:15 -0800 | [diff] [blame] | 107 | #ifdef CONFIG_IPV6 |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 108 | { .ival = "udpv6", |
| 109 | .oval = FIO_TYPE_UDP_V6, |
| 110 | .help = "User Datagram Protocol V6", |
| 111 | }, |
Jens Axboe | eb23231 | 2014-01-24 18:59:15 -0800 | [diff] [blame] | 112 | #endif |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 113 | { .ival = "unix", |
| 114 | .oval = FIO_TYPE_UNIX, |
| 115 | .help = "UNIX domain socket", |
| 116 | }, |
| 117 | }, |
Jens Axboe | e90a0ad | 2013-04-10 19:43:59 +0200 | [diff] [blame] | 118 | .category = FIO_OPT_C_ENGINE, |
| 119 | .group = FIO_OPT_G_NETIO, |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 120 | }, |
Jens Axboe | 1eafa37 | 2013-01-31 10:19:51 +0100 | [diff] [blame] | 121 | #ifdef CONFIG_TCP_NODELAY |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 122 | { |
Steven Noonan | 70a7878 | 2012-11-28 14:52:36 -0800 | [diff] [blame] | 123 | .name = "nodelay", |
| 124 | .type = FIO_OPT_BOOL, |
| 125 | .off1 = offsetof(struct netio_options, nodelay), |
| 126 | .help = "Use TCP_NODELAY on TCP connections", |
Jens Axboe | e90a0ad | 2013-04-10 19:43:59 +0200 | [diff] [blame] | 127 | .category = FIO_OPT_C_ENGINE, |
| 128 | .group = FIO_OPT_G_NETIO, |
Steven Noonan | 70a7878 | 2012-11-28 14:52:36 -0800 | [diff] [blame] | 129 | }, |
Jens Axboe | 1eafa37 | 2013-01-31 10:19:51 +0100 | [diff] [blame] | 130 | #endif |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 131 | { |
| 132 | .name = "listen", |
Jens Axboe | e8b0e95 | 2012-03-19 14:37:08 +0100 | [diff] [blame] | 133 | .lname = "net engine listen", |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 134 | .type = FIO_OPT_STR_SET, |
| 135 | .off1 = offsetof(struct netio_options, listen), |
| 136 | .help = "Listen for incoming TCP connections", |
Jens Axboe | e90a0ad | 2013-04-10 19:43:59 +0200 | [diff] [blame] | 137 | .category = FIO_OPT_C_ENGINE, |
| 138 | .group = FIO_OPT_G_NETIO, |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 139 | }, |
| 140 | { |
Jens Axboe | 6f73a7f | 2012-11-30 09:59:20 +0100 | [diff] [blame] | 141 | .name = "pingpong", |
| 142 | .type = FIO_OPT_STR_SET, |
| 143 | .off1 = offsetof(struct netio_options, pingpong), |
| 144 | .help = "Ping-pong IO requests", |
Jens Axboe | e90a0ad | 2013-04-10 19:43:59 +0200 | [diff] [blame] | 145 | .category = FIO_OPT_C_ENGINE, |
| 146 | .group = FIO_OPT_G_NETIO, |
Jens Axboe | 6f73a7f | 2012-11-30 09:59:20 +0100 | [diff] [blame] | 147 | }, |
| 148 | { |
Shawn Bohrer | b93b6a2 | 2013-07-19 13:24:07 -0500 | [diff] [blame] | 149 | .name = "interface", |
| 150 | .lname = "net engine interface", |
| 151 | .type = FIO_OPT_STR_STORE, |
Bruce Cran | f16b740 | 2013-10-08 15:05:27 +0100 | [diff] [blame] | 152 | .off1 = offsetof(struct netio_options, intfc), |
Shawn Bohrer | b93b6a2 | 2013-07-19 13:24:07 -0500 | [diff] [blame] | 153 | .help = "Network interface to use", |
| 154 | .category = FIO_OPT_C_ENGINE, |
| 155 | .group = FIO_OPT_G_NETIO, |
| 156 | }, |
| 157 | { |
Shawn Bohrer | d3a623d | 2013-07-19 13:24:08 -0500 | [diff] [blame] | 158 | .name = "ttl", |
| 159 | .lname = "net engine multicast ttl", |
| 160 | .type = FIO_OPT_INT, |
| 161 | .off1 = offsetof(struct netio_options, ttl), |
| 162 | .def = "1", |
| 163 | .minval = 0, |
| 164 | .help = "Time-to-live value for outgoing UDP multicast packets", |
| 165 | .category = FIO_OPT_C_ENGINE, |
| 166 | .group = FIO_OPT_G_NETIO, |
| 167 | }, |
| 168 | { |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 169 | .name = NULL, |
| 170 | }, |
| 171 | }; |
| 172 | |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 173 | static inline int is_udp(struct netio_options *o) |
| 174 | { |
| 175 | return o->proto == FIO_TYPE_UDP || o->proto == FIO_TYPE_UDP_V6; |
| 176 | } |
| 177 | |
| 178 | static inline int is_tcp(struct netio_options *o) |
| 179 | { |
| 180 | return o->proto == FIO_TYPE_TCP || o->proto == FIO_TYPE_TCP_V6; |
| 181 | } |
| 182 | |
| 183 | static inline int is_ipv6(struct netio_options *o) |
| 184 | { |
| 185 | return o->proto == FIO_TYPE_UDP_V6 || o->proto == FIO_TYPE_TCP_V6; |
| 186 | } |
| 187 | |
Jens Axboe | 371d456 | 2009-01-19 10:17:06 +0100 | [diff] [blame] | 188 | /* |
| 189 | * Return -1 for error and 'nr events' for a positive number |
| 190 | * of events |
| 191 | */ |
| 192 | static int poll_wait(struct thread_data *td, int fd, short events) |
| 193 | { |
| 194 | struct pollfd pfd; |
| 195 | int ret; |
| 196 | |
| 197 | while (!td->terminate) { |
| 198 | pfd.fd = fd; |
| 199 | pfd.events = events; |
| 200 | ret = poll(&pfd, 1, -1); |
| 201 | if (ret < 0) { |
| 202 | if (errno == EINTR) |
Jens Axboe | d5b388a | 2009-01-19 12:38:27 +0100 | [diff] [blame] | 203 | break; |
Jens Axboe | 371d456 | 2009-01-19 10:17:06 +0100 | [diff] [blame] | 204 | |
| 205 | td_verror(td, errno, "poll"); |
| 206 | return -1; |
| 207 | } else if (!ret) |
| 208 | continue; |
| 209 | |
| 210 | break; |
| 211 | } |
| 212 | |
| 213 | if (pfd.revents & events) |
| 214 | return 1; |
Jens Axboe | 371d456 | 2009-01-19 10:17:06 +0100 | [diff] [blame] | 215 | |
| 216 | return -1; |
| 217 | } |
| 218 | |
Shawn Bohrer | b511c9a | 2013-07-19 13:24:06 -0500 | [diff] [blame] | 219 | static int fio_netio_is_multicast(const char *mcaddr) |
| 220 | { |
| 221 | in_addr_t addr = inet_network(mcaddr); |
| 222 | if (addr == -1) |
| 223 | return 0; |
| 224 | |
| 225 | if (inet_network("224.0.0.0") <= addr && |
| 226 | inet_network("239.255.255.255") >= addr) |
| 227 | return 1; |
| 228 | |
| 229 | return 0; |
| 230 | } |
| 231 | |
| 232 | |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 233 | static int fio_netio_prep(struct thread_data *td, struct io_u *io_u) |
| 234 | { |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 235 | struct netio_options *o = td->eo; |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 236 | |
Jens Axboe | 7a6499d | 2007-02-07 09:35:29 +0100 | [diff] [blame] | 237 | /* |
| 238 | * Make sure we don't see spurious reads to a receiver, and vice versa |
| 239 | */ |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 240 | if (is_tcp(o)) |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 241 | return 0; |
| 242 | |
| 243 | if ((o->listen && io_u->ddir == DDIR_WRITE) || |
| 244 | (!o->listen && io_u->ddir == DDIR_READ)) { |
Jens Axboe | e1161c3 | 2007-02-22 19:36:48 +0100 | [diff] [blame] | 245 | td_verror(td, EINVAL, "bad direction"); |
Jens Axboe | 7a6499d | 2007-02-07 09:35:29 +0100 | [diff] [blame] | 246 | return 1; |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 247 | } |
Bruce Cran | 3f457be | 2012-10-10 13:37:41 +0100 | [diff] [blame] | 248 | |
Jens Axboe | f85ac25 | 2008-03-01 18:09:49 +0100 | [diff] [blame] | 249 | return 0; |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 250 | } |
| 251 | |
Jens Axboe | 67bf982 | 2013-01-10 11:23:19 +0100 | [diff] [blame] | 252 | #ifdef CONFIG_LINUX_SPLICE |
Jens Axboe | cd963e1 | 2007-06-24 21:41:46 +0200 | [diff] [blame] | 253 | static int splice_io_u(int fdin, int fdout, unsigned int len) |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 254 | { |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 255 | int bytes = 0; |
| 256 | |
| 257 | while (len) { |
Jens Axboe | cd963e1 | 2007-06-24 21:41:46 +0200 | [diff] [blame] | 258 | int ret = splice(fdin, NULL, fdout, NULL, len, 0); |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 259 | |
| 260 | if (ret < 0) { |
| 261 | if (!bytes) |
| 262 | bytes = ret; |
| 263 | |
| 264 | break; |
| 265 | } else if (!ret) |
| 266 | break; |
| 267 | |
| 268 | bytes += ret; |
Jens Axboe | f657a2f | 2007-06-22 20:40:10 +0200 | [diff] [blame] | 269 | len -= ret; |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | return bytes; |
| 273 | } |
| 274 | |
| 275 | /* |
Jens Axboe | cd963e1 | 2007-06-24 21:41:46 +0200 | [diff] [blame] | 276 | * Receive bytes from a socket and fill them into the internal pipe |
| 277 | */ |
| 278 | static int splice_in(struct thread_data *td, struct io_u *io_u) |
| 279 | { |
| 280 | struct netio_data *nd = td->io_ops->data; |
| 281 | |
| 282 | return splice_io_u(io_u->file->fd, nd->pipes[1], io_u->xfer_buflen); |
| 283 | } |
| 284 | |
| 285 | /* |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 286 | * Transmit 'len' bytes from the internal pipe |
| 287 | */ |
| 288 | static int splice_out(struct thread_data *td, struct io_u *io_u, |
| 289 | unsigned int len) |
| 290 | { |
| 291 | struct netio_data *nd = td->io_ops->data; |
Jens Axboe | cd963e1 | 2007-06-24 21:41:46 +0200 | [diff] [blame] | 292 | |
| 293 | return splice_io_u(nd->pipes[0], io_u->file->fd, len); |
| 294 | } |
| 295 | |
| 296 | static int vmsplice_io_u(struct io_u *io_u, int fd, unsigned int len) |
| 297 | { |
| 298 | struct iovec iov = { |
| 299 | .iov_base = io_u->xfer_buf, |
| 300 | .iov_len = len, |
| 301 | }; |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 302 | int bytes = 0; |
| 303 | |
Jens Axboe | cd963e1 | 2007-06-24 21:41:46 +0200 | [diff] [blame] | 304 | while (iov.iov_len) { |
| 305 | int ret = vmsplice(fd, &iov, 1, SPLICE_F_MOVE); |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 306 | |
| 307 | if (ret < 0) { |
| 308 | if (!bytes) |
| 309 | bytes = ret; |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 310 | break; |
| 311 | } else if (!ret) |
| 312 | break; |
| 313 | |
Jens Axboe | cd963e1 | 2007-06-24 21:41:46 +0200 | [diff] [blame] | 314 | iov.iov_len -= ret; |
| 315 | iov.iov_base += ret; |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 316 | bytes += ret; |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | return bytes; |
Jens Axboe | cd963e1 | 2007-06-24 21:41:46 +0200 | [diff] [blame] | 320 | |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | /* |
| 324 | * vmsplice() pipe to io_u buffer |
| 325 | */ |
| 326 | static int vmsplice_io_u_out(struct thread_data *td, struct io_u *io_u, |
| 327 | unsigned int len) |
| 328 | { |
| 329 | struct netio_data *nd = td->io_ops->data; |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 330 | |
Jens Axboe | cd963e1 | 2007-06-24 21:41:46 +0200 | [diff] [blame] | 331 | return vmsplice_io_u(io_u, nd->pipes[0], len); |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | /* |
| 335 | * vmsplice() io_u to pipe |
| 336 | */ |
| 337 | static int vmsplice_io_u_in(struct thread_data *td, struct io_u *io_u) |
| 338 | { |
| 339 | struct netio_data *nd = td->io_ops->data; |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 340 | |
Jens Axboe | cd963e1 | 2007-06-24 21:41:46 +0200 | [diff] [blame] | 341 | return vmsplice_io_u(io_u, nd->pipes[1], io_u->xfer_buflen); |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 342 | } |
| 343 | |
Jens Axboe | cd963e1 | 2007-06-24 21:41:46 +0200 | [diff] [blame] | 344 | /* |
| 345 | * splice receive - transfer socket data into a pipe using splice, then map |
| 346 | * that pipe data into the io_u using vmsplice. |
| 347 | */ |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 348 | static int fio_netio_splice_in(struct thread_data *td, struct io_u *io_u) |
| 349 | { |
| 350 | int ret; |
| 351 | |
| 352 | ret = splice_in(td, io_u); |
Jens Axboe | cd963e1 | 2007-06-24 21:41:46 +0200 | [diff] [blame] | 353 | if (ret > 0) |
| 354 | return vmsplice_io_u_out(td, io_u, ret); |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 355 | |
Jens Axboe | cd963e1 | 2007-06-24 21:41:46 +0200 | [diff] [blame] | 356 | return ret; |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 357 | } |
| 358 | |
Jens Axboe | cd963e1 | 2007-06-24 21:41:46 +0200 | [diff] [blame] | 359 | /* |
| 360 | * splice transmit - map data from the io_u into a pipe by using vmsplice, |
| 361 | * then transfer that pipe to a socket using splice. |
| 362 | */ |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 363 | static int fio_netio_splice_out(struct thread_data *td, struct io_u *io_u) |
| 364 | { |
| 365 | int ret; |
| 366 | |
| 367 | ret = vmsplice_io_u_in(td, io_u); |
Jens Axboe | cd963e1 | 2007-06-24 21:41:46 +0200 | [diff] [blame] | 368 | if (ret > 0) |
| 369 | return splice_out(td, io_u, ret); |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 370 | |
Jens Axboe | cd963e1 | 2007-06-24 21:41:46 +0200 | [diff] [blame] | 371 | return ret; |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 372 | } |
Jens Axboe | 5921e80 | 2008-05-30 15:02:38 +0200 | [diff] [blame] | 373 | #else |
| 374 | static int fio_netio_splice_in(struct thread_data *td, struct io_u *io_u) |
| 375 | { |
Jens Axboe | af8771b | 2008-05-30 22:58:28 +0200 | [diff] [blame] | 376 | errno = EOPNOTSUPP; |
Jens Axboe | 5921e80 | 2008-05-30 15:02:38 +0200 | [diff] [blame] | 377 | return -1; |
| 378 | } |
| 379 | |
| 380 | static int fio_netio_splice_out(struct thread_data *td, struct io_u *io_u) |
| 381 | { |
Jens Axboe | af8771b | 2008-05-30 22:58:28 +0200 | [diff] [blame] | 382 | errno = EOPNOTSUPP; |
Jens Axboe | 5921e80 | 2008-05-30 15:02:38 +0200 | [diff] [blame] | 383 | return -1; |
| 384 | } |
| 385 | #endif |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 386 | |
| 387 | static int fio_netio_send(struct thread_data *td, struct io_u *io_u) |
| 388 | { |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 389 | struct netio_data *nd = td->io_ops->data; |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 390 | struct netio_options *o = td->eo; |
Jens Axboe | 6f73a7f | 2012-11-30 09:59:20 +0100 | [diff] [blame] | 391 | int ret, flags = 0; |
Jens Axboe | 371d456 | 2009-01-19 10:17:06 +0100 | [diff] [blame] | 392 | |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 393 | do { |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 394 | if (is_udp(o)) { |
| 395 | struct sockaddr *to; |
| 396 | socklen_t len; |
| 397 | |
| 398 | if (is_ipv6(o)) { |
| 399 | to = (struct sockaddr *) &nd->addr6; |
| 400 | len = sizeof(nd->addr6); |
| 401 | } else { |
| 402 | to = (struct sockaddr *) &nd->addr; |
| 403 | len = sizeof(nd->addr); |
| 404 | } |
Jens Axboe | 62b3892 | 2009-05-11 10:37:33 +0200 | [diff] [blame] | 405 | |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 406 | ret = sendto(io_u->file->fd, io_u->xfer_buf, |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 407 | io_u->xfer_buflen, flags, to, len); |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 408 | } else { |
| 409 | /* |
| 410 | * if we are going to write more, set MSG_MORE |
| 411 | */ |
Jens Axboe | 5921e80 | 2008-05-30 15:02:38 +0200 | [diff] [blame] | 412 | #ifdef MSG_MORE |
Jens Axboe | 6f73a7f | 2012-11-30 09:59:20 +0100 | [diff] [blame] | 413 | if ((td->this_io_bytes[DDIR_WRITE] + io_u->xfer_buflen < |
| 414 | td->o.size) && !o->pingpong) |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 415 | flags |= MSG_MORE; |
Jens Axboe | 5921e80 | 2008-05-30 15:02:38 +0200 | [diff] [blame] | 416 | #endif |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 417 | ret = send(io_u->file->fd, io_u->xfer_buf, |
| 418 | io_u->xfer_buflen, flags); |
| 419 | } |
| 420 | if (ret > 0) |
| 421 | break; |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 422 | |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 423 | ret = poll_wait(td, io_u->file->fd, POLLOUT); |
| 424 | if (ret <= 0) |
| 425 | break; |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 426 | } while (1); |
| 427 | |
| 428 | return ret; |
| 429 | } |
| 430 | |
| 431 | static int is_udp_close(struct io_u *io_u, int len) |
| 432 | { |
| 433 | struct udp_close_msg *msg; |
| 434 | |
| 435 | if (len != sizeof(struct udp_close_msg)) |
| 436 | return 0; |
| 437 | |
| 438 | msg = io_u->xfer_buf; |
Jens Axboe | b96d243 | 2012-11-30 08:27:46 +0100 | [diff] [blame] | 439 | if (ntohl(msg->magic) != FIO_LINK_OPEN_CLOSE_MAGIC) |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 440 | return 0; |
| 441 | if (ntohl(msg->cmd) != FIO_LINK_CLOSE) |
| 442 | return 0; |
| 443 | |
| 444 | return 1; |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 445 | } |
| 446 | |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 447 | static int fio_netio_recv(struct thread_data *td, struct io_u *io_u) |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 448 | { |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 449 | struct netio_data *nd = td->io_ops->data; |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 450 | struct netio_options *o = td->eo; |
Jens Axboe | 6f73a7f | 2012-11-30 09:59:20 +0100 | [diff] [blame] | 451 | int ret, flags = 0; |
Jens Axboe | 371d456 | 2009-01-19 10:17:06 +0100 | [diff] [blame] | 452 | |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 453 | do { |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 454 | if (is_udp(o)) { |
Shawn Bohrer | b511c9a | 2013-07-19 13:24:06 -0500 | [diff] [blame] | 455 | struct sockaddr *from; |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 456 | socklen_t l, *len = &l; |
Shawn Bohrer | b511c9a | 2013-07-19 13:24:06 -0500 | [diff] [blame] | 457 | |
| 458 | if (o->listen) { |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 459 | if (!is_ipv6(o)) { |
| 460 | from = (struct sockaddr *) &nd->addr; |
| 461 | *len = sizeof(nd->addr); |
| 462 | } else { |
| 463 | from = (struct sockaddr *) &nd->addr6; |
| 464 | *len = sizeof(nd->addr6); |
| 465 | } |
Shawn Bohrer | b511c9a | 2013-07-19 13:24:06 -0500 | [diff] [blame] | 466 | } else { |
| 467 | from = NULL; |
| 468 | len = NULL; |
| 469 | } |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 470 | |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 471 | ret = recvfrom(io_u->file->fd, io_u->xfer_buf, |
Shawn Bohrer | b511c9a | 2013-07-19 13:24:06 -0500 | [diff] [blame] | 472 | io_u->xfer_buflen, flags, from, len); |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 473 | if (is_udp_close(io_u, ret)) { |
| 474 | td->done = 1; |
| 475 | return 0; |
| 476 | } |
| 477 | } else { |
| 478 | ret = recv(io_u->file->fd, io_u->xfer_buf, |
| 479 | io_u->xfer_buflen, flags); |
| 480 | } |
| 481 | if (ret > 0) |
| 482 | break; |
Jens Axboe | 7d988f6 | 2012-11-29 19:57:35 +0100 | [diff] [blame] | 483 | else if (!ret && (flags & MSG_WAITALL)) |
| 484 | break; |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 485 | |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 486 | ret = poll_wait(td, io_u->file->fd, POLLIN); |
| 487 | if (ret <= 0) |
| 488 | break; |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 489 | flags |= MSG_WAITALL; |
| 490 | } while (1); |
| 491 | |
| 492 | return ret; |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 493 | } |
| 494 | |
Jens Axboe | 6f73a7f | 2012-11-30 09:59:20 +0100 | [diff] [blame] | 495 | static int __fio_netio_queue(struct thread_data *td, struct io_u *io_u, |
| 496 | enum fio_ddir ddir) |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 497 | { |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 498 | struct netio_data *nd = td->io_ops->data; |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 499 | struct netio_options *o = td->eo; |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 500 | int ret; |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 501 | |
Jens Axboe | 6f73a7f | 2012-11-30 09:59:20 +0100 | [diff] [blame] | 502 | if (ddir == DDIR_WRITE) { |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 503 | if (!nd->use_splice || is_udp(o) || |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 504 | o->proto == FIO_TYPE_UNIX) |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 505 | ret = fio_netio_send(td, io_u); |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 506 | else |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 507 | ret = fio_netio_splice_out(td, io_u); |
Jens Axboe | 6f73a7f | 2012-11-30 09:59:20 +0100 | [diff] [blame] | 508 | } else if (ddir == DDIR_READ) { |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 509 | if (!nd->use_splice || is_udp(o) || |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 510 | o->proto == FIO_TYPE_UNIX) |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 511 | ret = fio_netio_recv(td, io_u); |
| 512 | else |
| 513 | ret = fio_netio_splice_in(td, io_u); |
Jens Axboe | d4f12dd | 2007-02-08 12:59:02 +0100 | [diff] [blame] | 514 | } else |
Jens Axboe | 7a6499d | 2007-02-07 09:35:29 +0100 | [diff] [blame] | 515 | ret = 0; /* must be a SYNC */ |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 516 | |
Jens Axboe | cec6b55 | 2007-02-06 20:15:38 +0100 | [diff] [blame] | 517 | if (ret != (int) io_u->xfer_buflen) { |
Jens Axboe | 22819ec | 2007-02-18 07:47:14 +0100 | [diff] [blame] | 518 | if (ret >= 0) { |
Jens Axboe | cec6b55 | 2007-02-06 20:15:38 +0100 | [diff] [blame] | 519 | io_u->resid = io_u->xfer_buflen - ret; |
| 520 | io_u->error = 0; |
Jens Axboe | 36167d8 | 2007-02-18 05:41:31 +0100 | [diff] [blame] | 521 | return FIO_Q_COMPLETED; |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 522 | } else { |
| 523 | int err = errno; |
| 524 | |
Jens Axboe | 6f73a7f | 2012-11-30 09:59:20 +0100 | [diff] [blame] | 525 | if (ddir == DDIR_WRITE && err == EMSGSIZE) |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 526 | return FIO_Q_BUSY; |
| 527 | |
| 528 | io_u->error = err; |
| 529 | } |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 530 | } |
| 531 | |
Jens Axboe | 36167d8 | 2007-02-18 05:41:31 +0100 | [diff] [blame] | 532 | if (io_u->error) |
Jens Axboe | e1161c3 | 2007-02-22 19:36:48 +0100 | [diff] [blame] | 533 | td_verror(td, io_u->error, "xfer"); |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 534 | |
Jens Axboe | 36167d8 | 2007-02-18 05:41:31 +0100 | [diff] [blame] | 535 | return FIO_Q_COMPLETED; |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 536 | } |
| 537 | |
Jens Axboe | 6f73a7f | 2012-11-30 09:59:20 +0100 | [diff] [blame] | 538 | static int fio_netio_queue(struct thread_data *td, struct io_u *io_u) |
| 539 | { |
| 540 | struct netio_options *o = td->eo; |
| 541 | int ret; |
| 542 | |
| 543 | fio_ro_check(td, io_u); |
| 544 | |
| 545 | ret = __fio_netio_queue(td, io_u, io_u->ddir); |
| 546 | if (!o->pingpong || ret != FIO_Q_COMPLETED) |
| 547 | return ret; |
| 548 | |
| 549 | /* |
| 550 | * For ping-pong mode, receive or send reply as needed |
| 551 | */ |
| 552 | if (td_read(td) && io_u->ddir == DDIR_READ) |
| 553 | ret = __fio_netio_queue(td, io_u, DDIR_WRITE); |
| 554 | else if (td_write(td) && io_u->ddir == DDIR_WRITE) |
| 555 | ret = __fio_netio_queue(td, io_u, DDIR_READ); |
| 556 | |
| 557 | return ret; |
| 558 | } |
| 559 | |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 560 | static int fio_netio_connect(struct thread_data *td, struct fio_file *f) |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 561 | { |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 562 | struct netio_data *nd = td->io_ops->data; |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 563 | struct netio_options *o = td->eo; |
Jens Axboe | 6264c7a | 2013-02-28 08:24:23 +0100 | [diff] [blame] | 564 | int type, domain; |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 565 | |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 566 | if (o->proto == FIO_TYPE_TCP) { |
Jens Axboe | 0fd666b | 2011-10-06 20:08:53 +0200 | [diff] [blame] | 567 | domain = AF_INET; |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 568 | type = SOCK_STREAM; |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 569 | } else if (o->proto == FIO_TYPE_TCP_V6) { |
| 570 | domain = AF_INET6; |
| 571 | type = SOCK_STREAM; |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 572 | } else if (o->proto == FIO_TYPE_UDP) { |
Jens Axboe | 0fd666b | 2011-10-06 20:08:53 +0200 | [diff] [blame] | 573 | domain = AF_INET; |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 574 | type = SOCK_DGRAM; |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 575 | } else if (o->proto == FIO_TYPE_UDP_V6) { |
| 576 | domain = AF_INET6; |
| 577 | type = SOCK_DGRAM; |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 578 | } else if (o->proto == FIO_TYPE_UNIX) { |
Jens Axboe | 0fd666b | 2011-10-06 20:08:53 +0200 | [diff] [blame] | 579 | domain = AF_UNIX; |
| 580 | type = SOCK_STREAM; |
| 581 | } else { |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 582 | log_err("fio: bad network type %d\n", o->proto); |
Jens Axboe | 0fd666b | 2011-10-06 20:08:53 +0200 | [diff] [blame] | 583 | f->fd = -1; |
| 584 | return 1; |
| 585 | } |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 586 | |
Jens Axboe | 0fd666b | 2011-10-06 20:08:53 +0200 | [diff] [blame] | 587 | f->fd = socket(domain, type, 0); |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 588 | if (f->fd < 0) { |
| 589 | td_verror(td, errno, "socket"); |
| 590 | return 1; |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 591 | } |
| 592 | |
Jens Axboe | 1eafa37 | 2013-01-31 10:19:51 +0100 | [diff] [blame] | 593 | #ifdef CONFIG_TCP_NODELAY |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 594 | if (o->nodelay && is_tcp(o)) { |
Jens Axboe | 6264c7a | 2013-02-28 08:24:23 +0100 | [diff] [blame] | 595 | int optval = 1; |
| 596 | |
Jens Axboe | 26e594a | 2013-01-30 21:52:37 +0100 | [diff] [blame] | 597 | if (setsockopt(f->fd, IPPROTO_TCP, TCP_NODELAY, (void *) &optval, sizeof(int)) < 0) { |
Steven Noonan | 70a7878 | 2012-11-28 14:52:36 -0800 | [diff] [blame] | 598 | log_err("fio: cannot set TCP_NODELAY option on socket (%s), disable with 'nodelay=0'\n", strerror(errno)); |
| 599 | return 1; |
| 600 | } |
| 601 | } |
Jens Axboe | 1eafa37 | 2013-01-31 10:19:51 +0100 | [diff] [blame] | 602 | #endif |
Steven Noonan | 70a7878 | 2012-11-28 14:52:36 -0800 | [diff] [blame] | 603 | |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 604 | if (is_udp(o)) { |
Shawn Bohrer | d3a623d | 2013-07-19 13:24:08 -0500 | [diff] [blame] | 605 | if (!fio_netio_is_multicast(td->o.filename)) |
| 606 | return 0; |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 607 | if (is_ipv6(o)) { |
| 608 | log_err("fio: multicast not supported on IPv6\n"); |
| 609 | close(f->fd); |
| 610 | return 1; |
| 611 | } |
Shawn Bohrer | d3a623d | 2013-07-19 13:24:08 -0500 | [diff] [blame] | 612 | |
Bruce Cran | f16b740 | 2013-10-08 15:05:27 +0100 | [diff] [blame] | 613 | if (o->intfc) { |
Shawn Bohrer | b93b6a2 | 2013-07-19 13:24:07 -0500 | [diff] [blame] | 614 | struct in_addr interface_addr; |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 615 | |
Bruce Cran | f16b740 | 2013-10-08 15:05:27 +0100 | [diff] [blame] | 616 | if (inet_aton(o->intfc, &interface_addr) == 0) { |
Shawn Bohrer | b93b6a2 | 2013-07-19 13:24:07 -0500 | [diff] [blame] | 617 | log_err("fio: interface not valid interface IP\n"); |
| 618 | close(f->fd); |
| 619 | return 1; |
| 620 | } |
Bruce Cran | f16b740 | 2013-10-08 15:05:27 +0100 | [diff] [blame] | 621 | if (setsockopt(f->fd, IPPROTO_IP, IP_MULTICAST_IF, (const char*)&interface_addr, sizeof(interface_addr)) < 0) { |
Shawn Bohrer | b93b6a2 | 2013-07-19 13:24:07 -0500 | [diff] [blame] | 622 | td_verror(td, errno, "setsockopt IP_MULTICAST_IF"); |
| 623 | close(f->fd); |
| 624 | return 1; |
| 625 | } |
| 626 | } |
Bruce Cran | f16b740 | 2013-10-08 15:05:27 +0100 | [diff] [blame] | 627 | if (setsockopt(f->fd, IPPROTO_IP, IP_MULTICAST_TTL, (const char*)&o->ttl, sizeof(o->ttl)) < 0) { |
Shawn Bohrer | d3a623d | 2013-07-19 13:24:08 -0500 | [diff] [blame] | 628 | td_verror(td, errno, "setsockopt IP_MULTICAST_TTL"); |
| 629 | close(f->fd); |
| 630 | return 1; |
| 631 | } |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 632 | return 0; |
Shawn Bohrer | b93b6a2 | 2013-07-19 13:24:07 -0500 | [diff] [blame] | 633 | } else if (o->proto == FIO_TYPE_TCP) { |
Jens Axboe | 67bf982 | 2013-01-10 11:23:19 +0100 | [diff] [blame] | 634 | socklen_t len = sizeof(nd->addr); |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 635 | |
Jens Axboe | 0fd666b | 2011-10-06 20:08:53 +0200 | [diff] [blame] | 636 | if (connect(f->fd, (struct sockaddr *) &nd->addr, len) < 0) { |
| 637 | td_verror(td, errno, "connect"); |
Jens Axboe | b94cba4 | 2011-10-06 21:27:10 +0200 | [diff] [blame] | 638 | close(f->fd); |
Jens Axboe | 0fd666b | 2011-10-06 20:08:53 +0200 | [diff] [blame] | 639 | return 1; |
| 640 | } |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 641 | } else if (o->proto == FIO_TYPE_TCP_V6) { |
| 642 | socklen_t len = sizeof(nd->addr6); |
| 643 | |
| 644 | if (connect(f->fd, (struct sockaddr *) &nd->addr6, len) < 0) { |
| 645 | td_verror(td, errno, "connect"); |
| 646 | close(f->fd); |
| 647 | return 1; |
| 648 | } |
| 649 | |
Jens Axboe | 0fd666b | 2011-10-06 20:08:53 +0200 | [diff] [blame] | 650 | } else { |
| 651 | struct sockaddr_un *addr = &nd->addr_un; |
Jens Axboe | 67bf982 | 2013-01-10 11:23:19 +0100 | [diff] [blame] | 652 | socklen_t len; |
Jens Axboe | 0fd666b | 2011-10-06 20:08:53 +0200 | [diff] [blame] | 653 | |
| 654 | len = sizeof(addr->sun_family) + strlen(addr->sun_path) + 1; |
| 655 | |
| 656 | if (connect(f->fd, (struct sockaddr *) addr, len) < 0) { |
| 657 | td_verror(td, errno, "connect"); |
Jens Axboe | b94cba4 | 2011-10-06 21:27:10 +0200 | [diff] [blame] | 658 | close(f->fd); |
Jens Axboe | 0fd666b | 2011-10-06 20:08:53 +0200 | [diff] [blame] | 659 | return 1; |
| 660 | } |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | return 0; |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 664 | } |
| 665 | |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 666 | static int fio_netio_accept(struct thread_data *td, struct fio_file *f) |
Jens Axboe | 5fdd124 | 2007-02-11 04:00:37 +0100 | [diff] [blame] | 667 | { |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 668 | struct netio_data *nd = td->io_ops->data; |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 669 | struct netio_options *o = td->eo; |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 670 | socklen_t socklen; |
Jens Axboe | 6264c7a | 2013-02-28 08:24:23 +0100 | [diff] [blame] | 671 | int state; |
Jens Axboe | 5fdd124 | 2007-02-11 04:00:37 +0100 | [diff] [blame] | 672 | |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 673 | if (is_udp(o)) { |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 674 | f->fd = nd->listenfd; |
| 675 | return 0; |
| 676 | } |
| 677 | |
Jens Axboe | 859088d | 2012-11-29 20:02:50 +0100 | [diff] [blame] | 678 | state = td->runstate; |
| 679 | td_set_runstate(td, TD_SETTING_UP); |
| 680 | |
Jens Axboe | 6d86144 | 2007-03-15 09:22:23 +0100 | [diff] [blame] | 681 | log_info("fio: waiting for connection\n"); |
Jens Axboe | 5fdd124 | 2007-02-11 04:00:37 +0100 | [diff] [blame] | 682 | |
Jens Axboe | 371d456 | 2009-01-19 10:17:06 +0100 | [diff] [blame] | 683 | if (poll_wait(td, nd->listenfd, POLLIN) < 0) |
Jens Axboe | 859088d | 2012-11-29 20:02:50 +0100 | [diff] [blame] | 684 | goto err; |
Jens Axboe | 5fdd124 | 2007-02-11 04:00:37 +0100 | [diff] [blame] | 685 | |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 686 | if (o->proto == FIO_TYPE_TCP) { |
| 687 | socklen = sizeof(nd->addr); |
| 688 | f->fd = accept(nd->listenfd, (struct sockaddr *) &nd->addr, &socklen); |
| 689 | } else { |
| 690 | socklen = sizeof(nd->addr6); |
| 691 | f->fd = accept(nd->listenfd, (struct sockaddr *) &nd->addr6, &socklen); |
| 692 | } |
| 693 | |
Jens Axboe | 371d456 | 2009-01-19 10:17:06 +0100 | [diff] [blame] | 694 | if (f->fd < 0) { |
| 695 | td_verror(td, errno, "accept"); |
Jens Axboe | 859088d | 2012-11-29 20:02:50 +0100 | [diff] [blame] | 696 | goto err; |
Jens Axboe | 5fdd124 | 2007-02-11 04:00:37 +0100 | [diff] [blame] | 697 | } |
| 698 | |
Jens Axboe | 1eafa37 | 2013-01-31 10:19:51 +0100 | [diff] [blame] | 699 | #ifdef CONFIG_TCP_NODELAY |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 700 | if (o->nodelay && is_tcp(o)) { |
Jens Axboe | 6264c7a | 2013-02-28 08:24:23 +0100 | [diff] [blame] | 701 | int optval = 1; |
| 702 | |
Jens Axboe | 26e594a | 2013-01-30 21:52:37 +0100 | [diff] [blame] | 703 | if (setsockopt(f->fd, IPPROTO_TCP, TCP_NODELAY, (void *) &optval, sizeof(int)) < 0) { |
Steven Noonan | 70a7878 | 2012-11-28 14:52:36 -0800 | [diff] [blame] | 704 | log_err("fio: cannot set TCP_NODELAY option on socket (%s), disable with 'nodelay=0'\n", strerror(errno)); |
| 705 | return 1; |
| 706 | } |
| 707 | } |
Jens Axboe | 1eafa37 | 2013-01-31 10:19:51 +0100 | [diff] [blame] | 708 | #endif |
Steven Noonan | 70a7878 | 2012-11-28 14:52:36 -0800 | [diff] [blame] | 709 | |
Jens Axboe | 0cae16f | 2012-11-30 16:22:31 +0100 | [diff] [blame] | 710 | reset_all_stats(td); |
Jens Axboe | 859088d | 2012-11-29 20:02:50 +0100 | [diff] [blame] | 711 | td_set_runstate(td, state); |
Jens Axboe | 5fdd124 | 2007-02-11 04:00:37 +0100 | [diff] [blame] | 712 | return 0; |
Jens Axboe | 859088d | 2012-11-29 20:02:50 +0100 | [diff] [blame] | 713 | err: |
| 714 | td_set_runstate(td, state); |
| 715 | return 1; |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 716 | } |
| 717 | |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 718 | static void fio_netio_udp_close(struct thread_data *td, struct fio_file *f) |
| 719 | { |
| 720 | struct netio_data *nd = td->io_ops->data; |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 721 | struct netio_options *o = td->eo; |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 722 | struct udp_close_msg msg; |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 723 | struct sockaddr *to; |
| 724 | socklen_t len; |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 725 | int ret; |
| 726 | |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 727 | if (is_ipv6(o)) { |
| 728 | to = (struct sockaddr *) &nd->addr6; |
| 729 | len = sizeof(nd->addr6); |
| 730 | } else { |
| 731 | to = (struct sockaddr *) &nd->addr; |
| 732 | len = sizeof(nd->addr); |
| 733 | } |
| 734 | |
Jens Axboe | b96d243 | 2012-11-30 08:27:46 +0100 | [diff] [blame] | 735 | msg.magic = htonl(FIO_LINK_OPEN_CLOSE_MAGIC); |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 736 | msg.cmd = htonl(FIO_LINK_CLOSE); |
| 737 | |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 738 | ret = sendto(f->fd, (void *) &msg, sizeof(msg), MSG_WAITALL, to, len); |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 739 | if (ret < 0) |
| 740 | td_verror(td, errno, "sendto udp link close"); |
| 741 | } |
| 742 | |
| 743 | static int fio_netio_close_file(struct thread_data *td, struct fio_file *f) |
| 744 | { |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 745 | struct netio_options *o = td->eo; |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 746 | |
| 747 | /* |
| 748 | * If this is an UDP connection, notify the receiver that we are |
| 749 | * closing down the link |
| 750 | */ |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 751 | if (is_udp(o)) |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 752 | fio_netio_udp_close(td, f); |
| 753 | |
| 754 | return generic_close_file(td, f); |
| 755 | } |
| 756 | |
Jens Axboe | b96d243 | 2012-11-30 08:27:46 +0100 | [diff] [blame] | 757 | static int fio_netio_udp_recv_open(struct thread_data *td, struct fio_file *f) |
| 758 | { |
| 759 | struct netio_data *nd = td->io_ops->data; |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 760 | struct netio_options *o = td->eo; |
Jens Axboe | b96d243 | 2012-11-30 08:27:46 +0100 | [diff] [blame] | 761 | struct udp_close_msg msg; |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 762 | struct sockaddr *to; |
| 763 | socklen_t len; |
Jens Axboe | b96d243 | 2012-11-30 08:27:46 +0100 | [diff] [blame] | 764 | int ret; |
| 765 | |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 766 | if (is_ipv6(o)) { |
| 767 | len = sizeof(nd->addr6); |
| 768 | to = (struct sockaddr *) &nd->addr6; |
| 769 | } else { |
| 770 | len = sizeof(nd->addr); |
| 771 | to = (struct sockaddr *) &nd->addr; |
| 772 | } |
| 773 | |
Jens Axboe | 1f81991 | 2013-01-23 17:21:41 -0700 | [diff] [blame] | 774 | ret = recvfrom(f->fd, (void *) &msg, sizeof(msg), MSG_WAITALL, to, &len); |
Jens Axboe | b96d243 | 2012-11-30 08:27:46 +0100 | [diff] [blame] | 775 | if (ret < 0) { |
Shawn Bohrer | ee7062f | 2013-07-19 13:24:09 -0500 | [diff] [blame] | 776 | td_verror(td, errno, "recvfrom udp link open"); |
Jens Axboe | b96d243 | 2012-11-30 08:27:46 +0100 | [diff] [blame] | 777 | return ret; |
| 778 | } |
| 779 | |
| 780 | if (ntohl(msg.magic) != FIO_LINK_OPEN_CLOSE_MAGIC || |
| 781 | ntohl(msg.cmd) != FIO_LINK_OPEN) { |
| 782 | log_err("fio: bad udp open magic %x/%x\n", ntohl(msg.magic), |
| 783 | ntohl(msg.cmd)); |
| 784 | return -1; |
| 785 | } |
| 786 | |
| 787 | return 0; |
| 788 | } |
| 789 | |
| 790 | static int fio_netio_udp_send_open(struct thread_data *td, struct fio_file *f) |
| 791 | { |
| 792 | struct netio_data *nd = td->io_ops->data; |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 793 | struct netio_options *o = td->eo; |
Jens Axboe | b96d243 | 2012-11-30 08:27:46 +0100 | [diff] [blame] | 794 | struct udp_close_msg msg; |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 795 | struct sockaddr *to; |
| 796 | socklen_t len; |
Jens Axboe | b96d243 | 2012-11-30 08:27:46 +0100 | [diff] [blame] | 797 | int ret; |
| 798 | |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 799 | if (is_ipv6(o)) { |
| 800 | len = sizeof(nd->addr6); |
| 801 | to = (struct sockaddr *) &nd->addr6; |
| 802 | } else { |
| 803 | len = sizeof(nd->addr); |
| 804 | to = (struct sockaddr *) &nd->addr; |
| 805 | } |
| 806 | |
Jens Axboe | b96d243 | 2012-11-30 08:27:46 +0100 | [diff] [blame] | 807 | msg.magic = htonl(FIO_LINK_OPEN_CLOSE_MAGIC); |
| 808 | msg.cmd = htonl(FIO_LINK_OPEN); |
| 809 | |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 810 | ret = sendto(f->fd, (void *) &msg, sizeof(msg), MSG_WAITALL, to, len); |
Jens Axboe | b96d243 | 2012-11-30 08:27:46 +0100 | [diff] [blame] | 811 | if (ret < 0) { |
| 812 | td_verror(td, errno, "sendto udp link open"); |
| 813 | return ret; |
| 814 | } |
| 815 | |
| 816 | return 0; |
| 817 | } |
| 818 | |
| 819 | static int fio_netio_open_file(struct thread_data *td, struct fio_file *f) |
| 820 | { |
| 821 | int ret; |
| 822 | struct netio_options *o = td->eo; |
| 823 | |
| 824 | if (o->listen) |
| 825 | ret = fio_netio_accept(td, f); |
| 826 | else |
| 827 | ret = fio_netio_connect(td, f); |
| 828 | |
| 829 | if (ret) { |
| 830 | f->fd = -1; |
| 831 | return ret; |
| 832 | } |
| 833 | |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 834 | if (is_udp(o)) { |
Jens Axboe | b96d243 | 2012-11-30 08:27:46 +0100 | [diff] [blame] | 835 | if (td_write(td)) |
| 836 | ret = fio_netio_udp_send_open(td, f); |
| 837 | else { |
| 838 | int state; |
| 839 | |
| 840 | state = td->runstate; |
| 841 | td_set_runstate(td, TD_SETTING_UP); |
| 842 | ret = fio_netio_udp_recv_open(td, f); |
| 843 | td_set_runstate(td, state); |
| 844 | } |
| 845 | } |
| 846 | |
| 847 | if (ret) |
| 848 | fio_netio_close_file(td, f); |
| 849 | |
| 850 | return ret; |
| 851 | } |
| 852 | |
Jens Axboe | 0b78334 | 2014-01-23 20:19:17 -0800 | [diff] [blame] | 853 | static int fio_fill_addr(struct thread_data *td, const char *host, int af, |
| 854 | void *dst, struct addrinfo **res) |
| 855 | { |
| 856 | struct netio_options *o = td->eo; |
| 857 | struct addrinfo hints; |
| 858 | int ret; |
| 859 | |
| 860 | if (inet_pton(af, host, dst)) |
| 861 | return 0; |
| 862 | |
| 863 | memset(&hints, 0, sizeof(hints)); |
Jens Axboe | 0b78334 | 2014-01-23 20:19:17 -0800 | [diff] [blame] | 864 | |
| 865 | if (is_tcp(o)) |
| 866 | hints.ai_socktype = SOCK_STREAM; |
| 867 | else |
| 868 | hints.ai_socktype = SOCK_DGRAM; |
| 869 | |
Jens Axboe | b1b1be2 | 2014-01-23 20:41:33 -0800 | [diff] [blame] | 870 | if (is_ipv6(o)) |
| 871 | hints.ai_family = AF_INET6; |
| 872 | else |
| 873 | hints.ai_family = AF_INET; |
| 874 | |
Jens Axboe | 0b78334 | 2014-01-23 20:19:17 -0800 | [diff] [blame] | 875 | ret = getaddrinfo(host, NULL, &hints, res); |
| 876 | if (ret) { |
| 877 | int e = EINVAL; |
| 878 | char str[128]; |
| 879 | |
| 880 | if (ret == EAI_SYSTEM) |
| 881 | e = errno; |
| 882 | |
| 883 | snprintf(str, sizeof(str), "getaddrinfo: %s", gai_strerror(ret)); |
| 884 | td_verror(td, e, str); |
| 885 | return 1; |
| 886 | } |
| 887 | |
| 888 | return 0; |
| 889 | } |
| 890 | |
Jens Axboe | 0fd666b | 2011-10-06 20:08:53 +0200 | [diff] [blame] | 891 | static int fio_netio_setup_connect_inet(struct thread_data *td, |
| 892 | const char *host, unsigned short port) |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 893 | { |
| 894 | struct netio_data *nd = td->io_ops->data; |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 895 | struct netio_options *o = td->eo; |
Jens Axboe | 0b78334 | 2014-01-23 20:19:17 -0800 | [diff] [blame] | 896 | struct addrinfo *res = NULL; |
| 897 | void *dst, *src; |
| 898 | int af, len; |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 899 | |
Jens Axboe | 166dce4 | 2012-11-29 14:35:33 +0100 | [diff] [blame] | 900 | if (!host) { |
| 901 | log_err("fio: connect with no host to connect to.\n"); |
| 902 | if (td_read(td)) |
| 903 | log_err("fio: did you forget to set 'listen'?\n"); |
| 904 | |
| 905 | td_verror(td, EINVAL, "no hostname= set"); |
| 906 | return 1; |
| 907 | } |
| 908 | |
Jens Axboe | 0b78334 | 2014-01-23 20:19:17 -0800 | [diff] [blame] | 909 | nd->addr.sin_family = AF_INET; |
| 910 | nd->addr.sin_port = htons(port); |
| 911 | nd->addr6.sin6_family = AF_INET6; |
| 912 | nd->addr6.sin6_port = htons(port); |
| 913 | |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 914 | if (is_ipv6(o)) { |
Jens Axboe | 0b78334 | 2014-01-23 20:19:17 -0800 | [diff] [blame] | 915 | af = AF_INET6; |
Jens Axboe | 68631b3 | 2014-02-25 13:43:38 -0800 | [diff] [blame] | 916 | dst = &nd->addr6.sin6_addr; |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 917 | } else { |
Jens Axboe | 0b78334 | 2014-01-23 20:19:17 -0800 | [diff] [blame] | 918 | af = AF_INET; |
Jens Axboe | 68631b3 | 2014-02-25 13:43:38 -0800 | [diff] [blame] | 919 | dst = &nd->addr.sin_addr; |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 920 | } |
| 921 | |
Jens Axboe | 0b78334 | 2014-01-23 20:19:17 -0800 | [diff] [blame] | 922 | if (fio_fill_addr(td, host, af, dst, &res)) |
| 923 | return 1; |
| 924 | |
| 925 | if (!res) |
| 926 | return 0; |
| 927 | |
| 928 | if (is_ipv6(o)) { |
| 929 | len = sizeof(nd->addr6.sin6_addr); |
| 930 | src = &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr; |
| 931 | } else { |
| 932 | len = sizeof(nd->addr.sin_addr); |
| 933 | src = &((struct sockaddr_in *) res->ai_addr)->sin_addr; |
| 934 | } |
| 935 | |
| 936 | memcpy(dst, src, len); |
| 937 | freeaddrinfo(res); |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 938 | return 0; |
| 939 | } |
| 940 | |
Jens Axboe | 0fd666b | 2011-10-06 20:08:53 +0200 | [diff] [blame] | 941 | static int fio_netio_setup_connect_unix(struct thread_data *td, |
| 942 | const char *path) |
| 943 | { |
| 944 | struct netio_data *nd = td->io_ops->data; |
| 945 | struct sockaddr_un *soun = &nd->addr_un; |
| 946 | |
| 947 | soun->sun_family = AF_UNIX; |
| 948 | strcpy(soun->sun_path, path); |
| 949 | return 0; |
| 950 | } |
| 951 | |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 952 | static int fio_netio_setup_connect(struct thread_data *td) |
Jens Axboe | 0fd666b | 2011-10-06 20:08:53 +0200 | [diff] [blame] | 953 | { |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 954 | struct netio_options *o = td->eo; |
Jens Axboe | 0fd666b | 2011-10-06 20:08:53 +0200 | [diff] [blame] | 955 | |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 956 | if (is_udp(o) || is_tcp(o)) |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 957 | return fio_netio_setup_connect_inet(td, td->o.filename,o->port); |
Jens Axboe | 0fd666b | 2011-10-06 20:08:53 +0200 | [diff] [blame] | 958 | else |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 959 | return fio_netio_setup_connect_unix(td, td->o.filename); |
Jens Axboe | 0fd666b | 2011-10-06 20:08:53 +0200 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | static int fio_netio_setup_listen_unix(struct thread_data *td, const char *path) |
| 963 | { |
| 964 | struct netio_data *nd = td->io_ops->data; |
| 965 | struct sockaddr_un *addr = &nd->addr_un; |
| 966 | mode_t mode; |
| 967 | int len, fd; |
| 968 | |
| 969 | fd = socket(AF_UNIX, SOCK_STREAM, 0); |
| 970 | if (fd < 0) { |
| 971 | log_err("fio: socket: %s\n", strerror(errno)); |
| 972 | return -1; |
| 973 | } |
| 974 | |
| 975 | mode = umask(000); |
| 976 | |
| 977 | memset(addr, 0, sizeof(*addr)); |
| 978 | addr->sun_family = AF_UNIX; |
| 979 | strcpy(addr->sun_path, path); |
| 980 | unlink(path); |
| 981 | |
| 982 | len = sizeof(addr->sun_family) + strlen(path) + 1; |
| 983 | |
| 984 | if (bind(fd, (struct sockaddr *) addr, len) < 0) { |
| 985 | log_err("fio: bind: %s\n", strerror(errno)); |
Jens Axboe | b94cba4 | 2011-10-06 21:27:10 +0200 | [diff] [blame] | 986 | close(fd); |
Jens Axboe | 0fd666b | 2011-10-06 20:08:53 +0200 | [diff] [blame] | 987 | return -1; |
| 988 | } |
| 989 | |
| 990 | umask(mode); |
| 991 | nd->listenfd = fd; |
| 992 | return 0; |
| 993 | } |
| 994 | |
| 995 | static int fio_netio_setup_listen_inet(struct thread_data *td, short port) |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 996 | { |
| 997 | struct netio_data *nd = td->io_ops->data; |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 998 | struct netio_options *o = td->eo; |
Shawn Bohrer | b511c9a | 2013-07-19 13:24:06 -0500 | [diff] [blame] | 999 | struct ip_mreq mr; |
| 1000 | struct sockaddr_in sin; |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 1001 | struct sockaddr_in6 sin6; |
| 1002 | struct sockaddr *saddr; |
| 1003 | int fd, opt, type, domain; |
| 1004 | socklen_t len; |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 1005 | |
Shawn Bohrer | b511c9a | 2013-07-19 13:24:06 -0500 | [diff] [blame] | 1006 | memset(&sin, 0, sizeof(sin)); |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 1007 | memset(&sin6, 0, sizeof(sin6)); |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 1008 | |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 1009 | if (o->proto == FIO_TYPE_TCP) { |
| 1010 | type = SOCK_STREAM; |
| 1011 | domain = AF_INET; |
| 1012 | } else if (o->proto == FIO_TYPE_TCP_V6) { |
| 1013 | type = SOCK_STREAM; |
| 1014 | domain = AF_INET6; |
| 1015 | } else if (o->proto == FIO_TYPE_UDP) { |
| 1016 | type = SOCK_DGRAM; |
| 1017 | domain = AF_INET; |
| 1018 | } else if (o->proto == FIO_TYPE_UDP_V6) { |
| 1019 | type = SOCK_DGRAM; |
| 1020 | domain = AF_INET6; |
| 1021 | } else { |
| 1022 | log_err("fio: unknown proto %d\n", o->proto); |
| 1023 | return 1; |
| 1024 | } |
| 1025 | |
| 1026 | fd = socket(domain, type, 0); |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 1027 | if (fd < 0) { |
Jens Axboe | e1161c3 | 2007-02-22 19:36:48 +0100 | [diff] [blame] | 1028 | td_verror(td, errno, "socket"); |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 1029 | return 1; |
| 1030 | } |
| 1031 | |
| 1032 | opt = 1; |
Jens Axboe | 26e594a | 2013-01-30 21:52:37 +0100 | [diff] [blame] | 1033 | if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *) &opt, sizeof(opt)) < 0) { |
Jens Axboe | e1161c3 | 2007-02-22 19:36:48 +0100 | [diff] [blame] | 1034 | td_verror(td, errno, "setsockopt"); |
Shawn Bohrer | 4a93dec | 2013-07-19 13:24:10 -0500 | [diff] [blame] | 1035 | close(fd); |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 1036 | return 1; |
| 1037 | } |
Jens Axboe | 6bedbfa | 2007-02-07 09:54:40 +0100 | [diff] [blame] | 1038 | #ifdef SO_REUSEPORT |
Jens Axboe | 26e594a | 2013-01-30 21:52:37 +0100 | [diff] [blame] | 1039 | if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, (void *) &opt, sizeof(opt)) < 0) { |
Jens Axboe | e1161c3 | 2007-02-22 19:36:48 +0100 | [diff] [blame] | 1040 | td_verror(td, errno, "setsockopt"); |
Shawn Bohrer | 4a93dec | 2013-07-19 13:24:10 -0500 | [diff] [blame] | 1041 | close(fd); |
Jens Axboe | 6bedbfa | 2007-02-07 09:54:40 +0100 | [diff] [blame] | 1042 | return 1; |
| 1043 | } |
| 1044 | #endif |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 1045 | |
Jens Axboe | 6611e9c | 2014-01-24 07:36:43 -0800 | [diff] [blame] | 1046 | if (td->o.filename) { |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 1047 | if (!is_udp(o) || !fio_netio_is_multicast(td->o.filename)) { |
Shawn Bohrer | b511c9a | 2013-07-19 13:24:06 -0500 | [diff] [blame] | 1048 | log_err("fio: hostname not valid for non-multicast inbound network IO\n"); |
| 1049 | close(fd); |
| 1050 | return 1; |
| 1051 | } |
Jens Axboe | 6611e9c | 2014-01-24 07:36:43 -0800 | [diff] [blame] | 1052 | if (is_ipv6(o)) { |
| 1053 | log_err("fio: IPv6 not supported for multicast network IO"); |
| 1054 | close(fd); |
| 1055 | return 1; |
| 1056 | } |
Shawn Bohrer | b511c9a | 2013-07-19 13:24:06 -0500 | [diff] [blame] | 1057 | |
| 1058 | inet_aton(td->o.filename, &sin.sin_addr); |
| 1059 | |
| 1060 | mr.imr_multiaddr = sin.sin_addr; |
Bruce Cran | f16b740 | 2013-10-08 15:05:27 +0100 | [diff] [blame] | 1061 | if (o->intfc) { |
| 1062 | if (inet_aton(o->intfc, &mr.imr_interface) == 0) { |
Shawn Bohrer | b93b6a2 | 2013-07-19 13:24:07 -0500 | [diff] [blame] | 1063 | log_err("fio: interface not valid interface IP\n"); |
| 1064 | close(fd); |
| 1065 | return 1; |
| 1066 | } |
| 1067 | } else { |
| 1068 | mr.imr_interface.s_addr = htonl(INADDR_ANY); |
| 1069 | } |
Jens Axboe | 6611e9c | 2014-01-24 07:36:43 -0800 | [diff] [blame] | 1070 | |
Bruce Cran | f16b740 | 2013-10-08 15:05:27 +0100 | [diff] [blame] | 1071 | if (setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const char*)&mr, sizeof(mr)) < 0) { |
Shawn Bohrer | b511c9a | 2013-07-19 13:24:06 -0500 | [diff] [blame] | 1072 | td_verror(td, errno, "setsockopt IP_ADD_MEMBERSHIP"); |
| 1073 | close(fd); |
| 1074 | return 1; |
| 1075 | } |
| 1076 | } |
| 1077 | |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 1078 | if (!is_ipv6(o)) { |
| 1079 | saddr = (struct sockaddr *) &nd->addr; |
| 1080 | len = sizeof(nd->addr); |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 1081 | |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 1082 | nd->addr.sin_family = AF_INET; |
| 1083 | nd->addr.sin_addr.s_addr = sin.sin_addr.s_addr ? sin.sin_addr.s_addr : htonl(INADDR_ANY); |
| 1084 | nd->addr.sin_port = htons(port); |
| 1085 | } else { |
| 1086 | saddr = (struct sockaddr *) &nd->addr6; |
| 1087 | len = sizeof(nd->addr6); |
| 1088 | |
| 1089 | nd->addr6.sin6_family = AF_INET6; |
| 1090 | nd->addr6.sin6_addr = sin6.sin6_addr.s6_addr ? sin6.sin6_addr : in6addr_any; |
| 1091 | nd->addr6.sin6_port = htons(port); |
| 1092 | } |
| 1093 | |
| 1094 | if (bind(fd, saddr, len) < 0) { |
Jens Axboe | e1161c3 | 2007-02-22 19:36:48 +0100 | [diff] [blame] | 1095 | td_verror(td, errno, "bind"); |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 1096 | return 1; |
| 1097 | } |
Jens Axboe | 0fd666b | 2011-10-06 20:08:53 +0200 | [diff] [blame] | 1098 | |
| 1099 | nd->listenfd = fd; |
| 1100 | return 0; |
| 1101 | } |
| 1102 | |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1103 | static int fio_netio_setup_listen(struct thread_data *td) |
Jens Axboe | 0fd666b | 2011-10-06 20:08:53 +0200 | [diff] [blame] | 1104 | { |
| 1105 | struct netio_data *nd = td->io_ops->data; |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1106 | struct netio_options *o = td->eo; |
Jens Axboe | 0fd666b | 2011-10-06 20:08:53 +0200 | [diff] [blame] | 1107 | int ret; |
| 1108 | |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 1109 | if (is_udp(o) || is_tcp(o)) |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1110 | ret = fio_netio_setup_listen_inet(td, o->port); |
Jens Axboe | 0fd666b | 2011-10-06 20:08:53 +0200 | [diff] [blame] | 1111 | else |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1112 | ret = fio_netio_setup_listen_unix(td, td->o.filename); |
Jens Axboe | 0fd666b | 2011-10-06 20:08:53 +0200 | [diff] [blame] | 1113 | |
| 1114 | if (ret) |
| 1115 | return ret; |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 1116 | if (is_udp(o)) |
Jens Axboe | 0fd666b | 2011-10-06 20:08:53 +0200 | [diff] [blame] | 1117 | return 0; |
| 1118 | |
| 1119 | if (listen(nd->listenfd, 10) < 0) { |
Jens Axboe | e1161c3 | 2007-02-22 19:36:48 +0100 | [diff] [blame] | 1120 | td_verror(td, errno, "listen"); |
Jens Axboe | 0fd666b | 2011-10-06 20:08:53 +0200 | [diff] [blame] | 1121 | nd->listenfd = -1; |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 1122 | return 1; |
| 1123 | } |
| 1124 | |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 1125 | return 0; |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 1126 | } |
| 1127 | |
Jens Axboe | 9bec88e | 2007-03-02 08:55:48 +0100 | [diff] [blame] | 1128 | static int fio_netio_init(struct thread_data *td) |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 1129 | { |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1130 | struct netio_options *o = td->eo; |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 1131 | int ret; |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 1132 | |
Bruce Cran | 3f457be | 2012-10-10 13:37:41 +0100 | [diff] [blame] | 1133 | #ifdef WIN32 |
| 1134 | WSADATA wsd; |
| 1135 | WSAStartup(MAKEWORD(2,2), &wsd); |
| 1136 | #endif |
| 1137 | |
Jens Axboe | 16d55aa | 2007-05-22 09:21:37 +0200 | [diff] [blame] | 1138 | if (td_random(td)) { |
| 1139 | log_err("fio: network IO can't be random\n"); |
| 1140 | return 1; |
| 1141 | } |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 1142 | |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1143 | if (o->proto == FIO_TYPE_UNIX && o->port) { |
| 1144 | log_err("fio: network IO port not valid with unix socket\n"); |
| 1145 | return 1; |
| 1146 | } else if (o->proto != FIO_TYPE_UNIX && !o->port) { |
| 1147 | log_err("fio: network IO requires port for tcp or udp\n"); |
| 1148 | return 1; |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 1149 | } |
Jens Axboe | 0fd666b | 2011-10-06 20:08:53 +0200 | [diff] [blame] | 1150 | |
Jens Axboe | 49ccb8c | 2014-01-23 16:49:37 -0800 | [diff] [blame] | 1151 | if (!is_tcp(o)) { |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1152 | if (o->listen) { |
Jens Axboe | 9b98606 | 2011-12-19 08:57:18 +0100 | [diff] [blame] | 1153 | log_err("fio: listen only valid for TCP proto IO\n"); |
| 1154 | return 1; |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1155 | } |
| 1156 | if (td_rw(td)) { |
Jens Axboe | 9b98606 | 2011-12-19 08:57:18 +0100 | [diff] [blame] | 1157 | log_err("fio: datagram network connections must be" |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1158 | " read OR write\n"); |
Jens Axboe | 9b98606 | 2011-12-19 08:57:18 +0100 | [diff] [blame] | 1159 | return 1; |
| 1160 | } |
| 1161 | if (o->proto == FIO_TYPE_UNIX && !td->o.filename) { |
| 1162 | log_err("fio: UNIX sockets need host/filename\n"); |
| 1163 | return 1; |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1164 | } |
| 1165 | o->listen = td_read(td); |
| 1166 | } |
| 1167 | |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1168 | if (o->listen) |
| 1169 | ret = fio_netio_setup_listen(td); |
Jens Axboe | 0fd666b | 2011-10-06 20:08:53 +0200 | [diff] [blame] | 1170 | else |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1171 | ret = fio_netio_setup_connect(td); |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 1172 | |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 1173 | return ret; |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 1174 | } |
| 1175 | |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 1176 | static void fio_netio_cleanup(struct thread_data *td) |
Jens Axboe | 9bec88e | 2007-03-02 08:55:48 +0100 | [diff] [blame] | 1177 | { |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 1178 | struct netio_data *nd = td->io_ops->data; |
| 1179 | |
| 1180 | if (nd) { |
Jens Axboe | 64b24cd | 2007-06-24 21:28:39 +0200 | [diff] [blame] | 1181 | if (nd->listenfd != -1) |
| 1182 | close(nd->listenfd); |
| 1183 | if (nd->pipes[0] != -1) |
| 1184 | close(nd->pipes[0]); |
| 1185 | if (nd->pipes[1] != -1) |
| 1186 | close(nd->pipes[1]); |
| 1187 | |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 1188 | free(nd); |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 1189 | } |
| 1190 | } |
| 1191 | |
| 1192 | static int fio_netio_setup(struct thread_data *td) |
| 1193 | { |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 1194 | struct netio_data *nd; |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 1195 | |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1196 | if (!td->files_index) { |
Jens Axboe | 5903e7b | 2014-02-26 13:42:13 -0800 | [diff] [blame] | 1197 | add_file(td, td->o.filename ?: "net", 0, 0); |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1198 | td->o.nr_files = td->o.nr_files ?: 1; |
| 1199 | } |
| 1200 | |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 1201 | if (!td->io_ops->data) { |
| 1202 | nd = malloc(sizeof(*nd));; |
| 1203 | |
| 1204 | memset(nd, 0, sizeof(*nd)); |
| 1205 | nd->listenfd = -1; |
Jens Axboe | 64b24cd | 2007-06-24 21:28:39 +0200 | [diff] [blame] | 1206 | nd->pipes[0] = nd->pipes[1] = -1; |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 1207 | td->io_ops->data = nd; |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 1208 | } |
| 1209 | |
Jens Axboe | 9bec88e | 2007-03-02 08:55:48 +0100 | [diff] [blame] | 1210 | return 0; |
| 1211 | } |
| 1212 | |
Jens Axboe | 36d80bc | 2012-11-30 21:46:06 +0100 | [diff] [blame] | 1213 | static void fio_netio_terminate(struct thread_data *td) |
| 1214 | { |
| 1215 | kill(td->pid, SIGUSR2); |
| 1216 | } |
| 1217 | |
Jens Axboe | 67bf982 | 2013-01-10 11:23:19 +0100 | [diff] [blame] | 1218 | #ifdef CONFIG_LINUX_SPLICE |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 1219 | static int fio_netio_setup_splice(struct thread_data *td) |
| 1220 | { |
| 1221 | struct netio_data *nd; |
| 1222 | |
| 1223 | fio_netio_setup(td); |
| 1224 | |
| 1225 | nd = td->io_ops->data; |
| 1226 | if (nd) { |
| 1227 | if (pipe(nd->pipes) < 0) |
| 1228 | return 1; |
| 1229 | |
| 1230 | nd->use_splice = 1; |
| 1231 | return 0; |
| 1232 | } |
| 1233 | |
| 1234 | return 1; |
| 1235 | } |
| 1236 | |
Jens Axboe | 5921e80 | 2008-05-30 15:02:38 +0200 | [diff] [blame] | 1237 | static struct ioengine_ops ioengine_splice = { |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1238 | .name = "netsplice", |
| 1239 | .version = FIO_IOOPS_VERSION, |
| 1240 | .prep = fio_netio_prep, |
| 1241 | .queue = fio_netio_queue, |
| 1242 | .setup = fio_netio_setup_splice, |
| 1243 | .init = fio_netio_init, |
| 1244 | .cleanup = fio_netio_cleanup, |
| 1245 | .open_file = fio_netio_open_file, |
Jens Axboe | 36d80bc | 2012-11-30 21:46:06 +0100 | [diff] [blame] | 1246 | .close_file = fio_netio_close_file, |
| 1247 | .terminate = fio_netio_terminate, |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1248 | .options = options, |
| 1249 | .option_struct_size = sizeof(struct netio_options), |
| 1250 | .flags = FIO_SYNCIO | FIO_DISKLESSIO | FIO_UNIDIR | |
Jens Axboe | 36d80bc | 2012-11-30 21:46:06 +0100 | [diff] [blame] | 1251 | FIO_PIPEIO, |
Jens Axboe | 5921e80 | 2008-05-30 15:02:38 +0200 | [diff] [blame] | 1252 | }; |
| 1253 | #endif |
| 1254 | |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 1255 | static struct ioengine_ops ioengine_rw = { |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1256 | .name = "net", |
| 1257 | .version = FIO_IOOPS_VERSION, |
| 1258 | .prep = fio_netio_prep, |
| 1259 | .queue = fio_netio_queue, |
| 1260 | .setup = fio_netio_setup, |
| 1261 | .init = fio_netio_init, |
| 1262 | .cleanup = fio_netio_cleanup, |
| 1263 | .open_file = fio_netio_open_file, |
| 1264 | .close_file = fio_netio_close_file, |
Jens Axboe | 36d80bc | 2012-11-30 21:46:06 +0100 | [diff] [blame] | 1265 | .terminate = fio_netio_terminate, |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1266 | .options = options, |
| 1267 | .option_struct_size = sizeof(struct netio_options), |
| 1268 | .flags = FIO_SYNCIO | FIO_DISKLESSIO | FIO_UNIDIR | |
Steven Noonan | ad705bc | 2013-04-08 15:05:25 -0700 | [diff] [blame] | 1269 | FIO_PIPEIO | FIO_BIT_BASED, |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 1270 | }; |
| 1271 | |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1272 | static int str_hostname_cb(void *data, const char *input) |
| 1273 | { |
| 1274 | struct netio_options *o = data; |
| 1275 | |
| 1276 | if (o->td->o.filename) |
| 1277 | free(o->td->o.filename); |
| 1278 | o->td->o.filename = strdup(input); |
| 1279 | return 0; |
| 1280 | } |
| 1281 | |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 1282 | static void fio_init fio_netio_register(void) |
| 1283 | { |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 1284 | register_ioengine(&ioengine_rw); |
Jens Axboe | 67bf982 | 2013-01-10 11:23:19 +0100 | [diff] [blame] | 1285 | #ifdef CONFIG_LINUX_SPLICE |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 1286 | register_ioengine(&ioengine_splice); |
Jens Axboe | 5921e80 | 2008-05-30 15:02:38 +0200 | [diff] [blame] | 1287 | #endif |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 1288 | } |
| 1289 | |
| 1290 | static void fio_exit fio_netio_unregister(void) |
| 1291 | { |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 1292 | unregister_ioengine(&ioengine_rw); |
Jens Axboe | 67bf982 | 2013-01-10 11:23:19 +0100 | [diff] [blame] | 1293 | #ifdef CONFIG_LINUX_SPLICE |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 1294 | unregister_ioengine(&ioengine_splice); |
Jens Axboe | 5921e80 | 2008-05-30 15:02:38 +0200 | [diff] [blame] | 1295 | #endif |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 1296 | } |