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> |
| 10 | #include <errno.h> |
| 11 | #include <assert.h> |
| 12 | #include <netinet/in.h> |
| 13 | #include <arpa/inet.h> |
| 14 | #include <netdb.h> |
Jens Axboe | 5fdd124 | 2007-02-11 04:00:37 +0100 | [diff] [blame] | 15 | #include <sys/poll.h> |
Jens Axboe | 7292056 | 2008-06-02 12:30:06 +0200 | [diff] [blame] | 16 | #include <sys/types.h> |
| 17 | #include <sys/socket.h> |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 18 | |
| 19 | #include "../fio.h" |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 20 | |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 21 | struct netio_data { |
| 22 | int listenfd; |
| 23 | int send_to_net; |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 24 | int use_splice; |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 25 | int net_protocol; |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 26 | int pipes[2]; |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 27 | char host[64]; |
| 28 | struct sockaddr_in addr; |
| 29 | }; |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 30 | |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 31 | struct udp_close_msg { |
| 32 | uint32_t magic; |
| 33 | uint32_t cmd; |
| 34 | }; |
| 35 | |
| 36 | enum { |
| 37 | FIO_LINK_CLOSE = 0x89, |
| 38 | FIO_LINK_CLOSE_MAGIC = 0x6c696e6b, |
| 39 | }; |
| 40 | |
Jens Axboe | 371d456 | 2009-01-19 10:17:06 +0100 | [diff] [blame] | 41 | /* |
| 42 | * Return -1 for error and 'nr events' for a positive number |
| 43 | * of events |
| 44 | */ |
| 45 | static int poll_wait(struct thread_data *td, int fd, short events) |
| 46 | { |
| 47 | struct pollfd pfd; |
| 48 | int ret; |
| 49 | |
| 50 | while (!td->terminate) { |
| 51 | pfd.fd = fd; |
| 52 | pfd.events = events; |
| 53 | ret = poll(&pfd, 1, -1); |
| 54 | if (ret < 0) { |
| 55 | if (errno == EINTR) |
Jens Axboe | d5b388a | 2009-01-19 12:38:27 +0100 | [diff] [blame] | 56 | break; |
Jens Axboe | 371d456 | 2009-01-19 10:17:06 +0100 | [diff] [blame] | 57 | |
| 58 | td_verror(td, errno, "poll"); |
| 59 | return -1; |
| 60 | } else if (!ret) |
| 61 | continue; |
| 62 | |
| 63 | break; |
| 64 | } |
| 65 | |
| 66 | if (pfd.revents & events) |
| 67 | return 1; |
Jens Axboe | 371d456 | 2009-01-19 10:17:06 +0100 | [diff] [blame] | 68 | |
| 69 | return -1; |
| 70 | } |
| 71 | |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 72 | static int fio_netio_prep(struct thread_data *td, struct io_u *io_u) |
| 73 | { |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 74 | struct netio_data *nd = td->io_ops->data; |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 75 | |
Jens Axboe | 7a6499d | 2007-02-07 09:35:29 +0100 | [diff] [blame] | 76 | /* |
| 77 | * Make sure we don't see spurious reads to a receiver, and vice versa |
| 78 | */ |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 79 | if ((nd->send_to_net && io_u->ddir == DDIR_READ) || |
| 80 | (!nd->send_to_net && io_u->ddir == DDIR_WRITE)) { |
Jens Axboe | e1161c3 | 2007-02-22 19:36:48 +0100 | [diff] [blame] | 81 | td_verror(td, EINVAL, "bad direction"); |
Jens Axboe | 7a6499d | 2007-02-07 09:35:29 +0100 | [diff] [blame] | 82 | return 1; |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 83 | } |
Jens Axboe | 7a6499d | 2007-02-07 09:35:29 +0100 | [diff] [blame] | 84 | |
Jens Axboe | f85ac25 | 2008-03-01 18:09:49 +0100 | [diff] [blame] | 85 | return 0; |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 86 | } |
| 87 | |
Jens Axboe | 5921e80 | 2008-05-30 15:02:38 +0200 | [diff] [blame] | 88 | #ifdef FIO_HAVE_SPLICE |
Jens Axboe | cd963e1 | 2007-06-24 21:41:46 +0200 | [diff] [blame] | 89 | static int splice_io_u(int fdin, int fdout, unsigned int len) |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 90 | { |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 91 | int bytes = 0; |
| 92 | |
| 93 | while (len) { |
Jens Axboe | cd963e1 | 2007-06-24 21:41:46 +0200 | [diff] [blame] | 94 | int ret = splice(fdin, NULL, fdout, NULL, len, 0); |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 95 | |
| 96 | if (ret < 0) { |
| 97 | if (!bytes) |
| 98 | bytes = ret; |
| 99 | |
| 100 | break; |
| 101 | } else if (!ret) |
| 102 | break; |
| 103 | |
| 104 | bytes += ret; |
Jens Axboe | f657a2f | 2007-06-22 20:40:10 +0200 | [diff] [blame] | 105 | len -= ret; |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | return bytes; |
| 109 | } |
| 110 | |
| 111 | /* |
Jens Axboe | cd963e1 | 2007-06-24 21:41:46 +0200 | [diff] [blame] | 112 | * Receive bytes from a socket and fill them into the internal pipe |
| 113 | */ |
| 114 | static int splice_in(struct thread_data *td, struct io_u *io_u) |
| 115 | { |
| 116 | struct netio_data *nd = td->io_ops->data; |
| 117 | |
| 118 | return splice_io_u(io_u->file->fd, nd->pipes[1], io_u->xfer_buflen); |
| 119 | } |
| 120 | |
| 121 | /* |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 122 | * Transmit 'len' bytes from the internal pipe |
| 123 | */ |
| 124 | static int splice_out(struct thread_data *td, struct io_u *io_u, |
| 125 | unsigned int len) |
| 126 | { |
| 127 | struct netio_data *nd = td->io_ops->data; |
Jens Axboe | cd963e1 | 2007-06-24 21:41:46 +0200 | [diff] [blame] | 128 | |
| 129 | return splice_io_u(nd->pipes[0], io_u->file->fd, len); |
| 130 | } |
| 131 | |
| 132 | static int vmsplice_io_u(struct io_u *io_u, int fd, unsigned int len) |
| 133 | { |
| 134 | struct iovec iov = { |
| 135 | .iov_base = io_u->xfer_buf, |
| 136 | .iov_len = len, |
| 137 | }; |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 138 | int bytes = 0; |
| 139 | |
Jens Axboe | cd963e1 | 2007-06-24 21:41:46 +0200 | [diff] [blame] | 140 | while (iov.iov_len) { |
| 141 | int ret = vmsplice(fd, &iov, 1, SPLICE_F_MOVE); |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 142 | |
| 143 | if (ret < 0) { |
| 144 | if (!bytes) |
| 145 | bytes = ret; |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 146 | break; |
| 147 | } else if (!ret) |
| 148 | break; |
| 149 | |
Jens Axboe | cd963e1 | 2007-06-24 21:41:46 +0200 | [diff] [blame] | 150 | iov.iov_len -= ret; |
| 151 | iov.iov_base += ret; |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 152 | bytes += ret; |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | return bytes; |
Jens Axboe | cd963e1 | 2007-06-24 21:41:46 +0200 | [diff] [blame] | 156 | |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | /* |
| 160 | * vmsplice() pipe to io_u buffer |
| 161 | */ |
| 162 | static int vmsplice_io_u_out(struct thread_data *td, struct io_u *io_u, |
| 163 | unsigned int len) |
| 164 | { |
| 165 | struct netio_data *nd = td->io_ops->data; |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 166 | |
Jens Axboe | cd963e1 | 2007-06-24 21:41:46 +0200 | [diff] [blame] | 167 | return vmsplice_io_u(io_u, nd->pipes[0], len); |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | /* |
| 171 | * vmsplice() io_u to pipe |
| 172 | */ |
| 173 | static int vmsplice_io_u_in(struct thread_data *td, struct io_u *io_u) |
| 174 | { |
| 175 | struct netio_data *nd = td->io_ops->data; |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 176 | |
Jens Axboe | cd963e1 | 2007-06-24 21:41:46 +0200 | [diff] [blame] | 177 | 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] | 178 | } |
| 179 | |
Jens Axboe | cd963e1 | 2007-06-24 21:41:46 +0200 | [diff] [blame] | 180 | /* |
| 181 | * splice receive - transfer socket data into a pipe using splice, then map |
| 182 | * that pipe data into the io_u using vmsplice. |
| 183 | */ |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 184 | static int fio_netio_splice_in(struct thread_data *td, struct io_u *io_u) |
| 185 | { |
| 186 | int ret; |
| 187 | |
| 188 | ret = splice_in(td, io_u); |
Jens Axboe | cd963e1 | 2007-06-24 21:41:46 +0200 | [diff] [blame] | 189 | if (ret > 0) |
| 190 | return vmsplice_io_u_out(td, io_u, ret); |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 191 | |
Jens Axboe | cd963e1 | 2007-06-24 21:41:46 +0200 | [diff] [blame] | 192 | return ret; |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 193 | } |
| 194 | |
Jens Axboe | cd963e1 | 2007-06-24 21:41:46 +0200 | [diff] [blame] | 195 | /* |
| 196 | * splice transmit - map data from the io_u into a pipe by using vmsplice, |
| 197 | * then transfer that pipe to a socket using splice. |
| 198 | */ |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 199 | static int fio_netio_splice_out(struct thread_data *td, struct io_u *io_u) |
| 200 | { |
| 201 | int ret; |
| 202 | |
| 203 | ret = vmsplice_io_u_in(td, io_u); |
Jens Axboe | cd963e1 | 2007-06-24 21:41:46 +0200 | [diff] [blame] | 204 | if (ret > 0) |
| 205 | return splice_out(td, io_u, ret); |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 206 | |
Jens Axboe | cd963e1 | 2007-06-24 21:41:46 +0200 | [diff] [blame] | 207 | return ret; |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 208 | } |
Jens Axboe | 5921e80 | 2008-05-30 15:02:38 +0200 | [diff] [blame] | 209 | #else |
| 210 | static int fio_netio_splice_in(struct thread_data *td, struct io_u *io_u) |
| 211 | { |
Jens Axboe | af8771b | 2008-05-30 22:58:28 +0200 | [diff] [blame] | 212 | errno = EOPNOTSUPP; |
Jens Axboe | 5921e80 | 2008-05-30 15:02:38 +0200 | [diff] [blame] | 213 | return -1; |
| 214 | } |
| 215 | |
| 216 | static int fio_netio_splice_out(struct thread_data *td, struct io_u *io_u) |
| 217 | { |
Jens Axboe | af8771b | 2008-05-30 22:58:28 +0200 | [diff] [blame] | 218 | errno = EOPNOTSUPP; |
Jens Axboe | 5921e80 | 2008-05-30 15:02:38 +0200 | [diff] [blame] | 219 | return -1; |
| 220 | } |
| 221 | #endif |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 222 | |
| 223 | static int fio_netio_send(struct thread_data *td, struct io_u *io_u) |
| 224 | { |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 225 | struct netio_data *nd = td->io_ops->data; |
Jens Axboe | 8e239ca | 2010-08-11 10:29:12 -0400 | [diff] [blame] | 226 | int ret, flags = OS_MSG_DONTWAIT; |
Jens Axboe | 371d456 | 2009-01-19 10:17:06 +0100 | [diff] [blame] | 227 | |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 228 | do { |
| 229 | if (nd->net_protocol == IPPROTO_UDP) { |
Jens Axboe | 62b3892 | 2009-05-11 10:37:33 +0200 | [diff] [blame] | 230 | struct sockaddr *to = (struct sockaddr *) &nd->addr; |
| 231 | |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 232 | ret = sendto(io_u->file->fd, io_u->xfer_buf, |
Jens Axboe | 62b3892 | 2009-05-11 10:37:33 +0200 | [diff] [blame] | 233 | io_u->xfer_buflen, flags, to, |
| 234 | sizeof(*to)); |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 235 | } else { |
| 236 | /* |
| 237 | * if we are going to write more, set MSG_MORE |
| 238 | */ |
Jens Axboe | 5921e80 | 2008-05-30 15:02:38 +0200 | [diff] [blame] | 239 | #ifdef MSG_MORE |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 240 | if (td->this_io_bytes[DDIR_WRITE] + io_u->xfer_buflen < |
| 241 | td->o.size) |
| 242 | flags |= MSG_MORE; |
Jens Axboe | 5921e80 | 2008-05-30 15:02:38 +0200 | [diff] [blame] | 243 | #endif |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 244 | ret = send(io_u->file->fd, io_u->xfer_buf, |
| 245 | io_u->xfer_buflen, flags); |
| 246 | } |
| 247 | if (ret > 0) |
| 248 | break; |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 249 | |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 250 | ret = poll_wait(td, io_u->file->fd, POLLOUT); |
| 251 | if (ret <= 0) |
| 252 | break; |
| 253 | |
Jens Axboe | 8e239ca | 2010-08-11 10:29:12 -0400 | [diff] [blame] | 254 | flags &= ~OS_MSG_DONTWAIT; |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 255 | } while (1); |
| 256 | |
| 257 | return ret; |
| 258 | } |
| 259 | |
| 260 | static int is_udp_close(struct io_u *io_u, int len) |
| 261 | { |
| 262 | struct udp_close_msg *msg; |
| 263 | |
| 264 | if (len != sizeof(struct udp_close_msg)) |
| 265 | return 0; |
| 266 | |
| 267 | msg = io_u->xfer_buf; |
| 268 | if (ntohl(msg->magic) != FIO_LINK_CLOSE_MAGIC) |
| 269 | return 0; |
| 270 | if (ntohl(msg->cmd) != FIO_LINK_CLOSE) |
| 271 | return 0; |
| 272 | |
| 273 | return 1; |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 274 | } |
| 275 | |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 276 | 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] | 277 | { |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 278 | struct netio_data *nd = td->io_ops->data; |
Jens Axboe | 8e239ca | 2010-08-11 10:29:12 -0400 | [diff] [blame] | 279 | int ret, flags = OS_MSG_DONTWAIT; |
Jens Axboe | 371d456 | 2009-01-19 10:17:06 +0100 | [diff] [blame] | 280 | |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 281 | do { |
| 282 | if (nd->net_protocol == IPPROTO_UDP) { |
Jens Axboe | d48a979 | 2011-07-09 08:54:26 +0200 | [diff] [blame] | 283 | #ifdef __hpux |
| 284 | int len = sizeof(nd->addr); |
| 285 | #else |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 286 | socklen_t len = sizeof(nd->addr); |
Jens Axboe | d48a979 | 2011-07-09 08:54:26 +0200 | [diff] [blame] | 287 | #endif |
Jens Axboe | 62b3892 | 2009-05-11 10:37:33 +0200 | [diff] [blame] | 288 | struct sockaddr *from = (struct sockaddr *) &nd->addr; |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 289 | |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 290 | ret = recvfrom(io_u->file->fd, io_u->xfer_buf, |
Jens Axboe | 62b3892 | 2009-05-11 10:37:33 +0200 | [diff] [blame] | 291 | io_u->xfer_buflen, flags, from, &len); |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 292 | if (is_udp_close(io_u, ret)) { |
| 293 | td->done = 1; |
| 294 | return 0; |
| 295 | } |
| 296 | } else { |
| 297 | ret = recv(io_u->file->fd, io_u->xfer_buf, |
| 298 | io_u->xfer_buflen, flags); |
| 299 | } |
| 300 | if (ret > 0) |
| 301 | break; |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 302 | |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 303 | ret = poll_wait(td, io_u->file->fd, POLLIN); |
| 304 | if (ret <= 0) |
| 305 | break; |
Jens Axboe | 8e239ca | 2010-08-11 10:29:12 -0400 | [diff] [blame] | 306 | flags &= ~OS_MSG_DONTWAIT; |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 307 | flags |= MSG_WAITALL; |
| 308 | } while (1); |
| 309 | |
| 310 | return ret; |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 311 | } |
| 312 | |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 313 | static int fio_netio_queue(struct thread_data *td, struct io_u *io_u) |
| 314 | { |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 315 | struct netio_data *nd = td->io_ops->data; |
| 316 | int ret; |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 317 | |
Jens Axboe | 7101d9c | 2007-09-12 13:12:39 +0200 | [diff] [blame] | 318 | fio_ro_check(td, io_u); |
| 319 | |
Jens Axboe | 7a6499d | 2007-02-07 09:35:29 +0100 | [diff] [blame] | 320 | if (io_u->ddir == DDIR_WRITE) { |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 321 | if (!nd->use_splice || nd->net_protocol == IPPROTO_UDP) |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 322 | ret = fio_netio_send(td, io_u); |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 323 | else |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 324 | ret = fio_netio_splice_out(td, io_u); |
| 325 | } else if (io_u->ddir == DDIR_READ) { |
| 326 | if (!nd->use_splice || nd->net_protocol == IPPROTO_UDP) |
| 327 | ret = fio_netio_recv(td, io_u); |
| 328 | else |
| 329 | ret = fio_netio_splice_in(td, io_u); |
Jens Axboe | d4f12dd | 2007-02-08 12:59:02 +0100 | [diff] [blame] | 330 | } else |
Jens Axboe | 7a6499d | 2007-02-07 09:35:29 +0100 | [diff] [blame] | 331 | ret = 0; /* must be a SYNC */ |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 332 | |
Jens Axboe | cec6b55 | 2007-02-06 20:15:38 +0100 | [diff] [blame] | 333 | if (ret != (int) io_u->xfer_buflen) { |
Jens Axboe | 22819ec | 2007-02-18 07:47:14 +0100 | [diff] [blame] | 334 | if (ret >= 0) { |
Jens Axboe | cec6b55 | 2007-02-06 20:15:38 +0100 | [diff] [blame] | 335 | io_u->resid = io_u->xfer_buflen - ret; |
| 336 | io_u->error = 0; |
Jens Axboe | 36167d8 | 2007-02-18 05:41:31 +0100 | [diff] [blame] | 337 | return FIO_Q_COMPLETED; |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 338 | } else { |
| 339 | int err = errno; |
| 340 | |
| 341 | if (io_u->ddir == DDIR_WRITE && err == EMSGSIZE) |
| 342 | return FIO_Q_BUSY; |
| 343 | |
| 344 | io_u->error = err; |
| 345 | } |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 346 | } |
| 347 | |
Jens Axboe | 36167d8 | 2007-02-18 05:41:31 +0100 | [diff] [blame] | 348 | if (io_u->error) |
Jens Axboe | e1161c3 | 2007-02-22 19:36:48 +0100 | [diff] [blame] | 349 | td_verror(td, io_u->error, "xfer"); |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 350 | |
Jens Axboe | 36167d8 | 2007-02-18 05:41:31 +0100 | [diff] [blame] | 351 | return FIO_Q_COMPLETED; |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 352 | } |
| 353 | |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 354 | 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] | 355 | { |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 356 | struct netio_data *nd = td->io_ops->data; |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 357 | int type; |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 358 | |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 359 | if (nd->net_protocol == IPPROTO_TCP) |
| 360 | type = SOCK_STREAM; |
| 361 | else |
| 362 | type = SOCK_DGRAM; |
| 363 | |
| 364 | f->fd = socket(AF_INET, type, nd->net_protocol); |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 365 | if (f->fd < 0) { |
| 366 | td_verror(td, errno, "socket"); |
| 367 | return 1; |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 368 | } |
| 369 | |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 370 | if (nd->net_protocol == IPPROTO_UDP) |
| 371 | return 0; |
| 372 | |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 373 | if (connect(f->fd, (struct sockaddr *) &nd->addr, sizeof(nd->addr)) < 0) { |
| 374 | td_verror(td, errno, "connect"); |
| 375 | return 1; |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | return 0; |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 379 | } |
| 380 | |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 381 | 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] | 382 | { |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 383 | struct netio_data *nd = td->io_ops->data; |
Jens Axboe | d48a979 | 2011-07-09 08:54:26 +0200 | [diff] [blame] | 384 | #ifdef __hpux |
| 385 | int socklen = sizeof(nd->addr); |
| 386 | #else |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 387 | socklen_t socklen = sizeof(nd->addr); |
Jens Axboe | d48a979 | 2011-07-09 08:54:26 +0200 | [diff] [blame] | 388 | #endif |
Jens Axboe | 5fdd124 | 2007-02-11 04:00:37 +0100 | [diff] [blame] | 389 | |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 390 | if (nd->net_protocol == IPPROTO_UDP) { |
| 391 | f->fd = nd->listenfd; |
| 392 | return 0; |
| 393 | } |
| 394 | |
Jens Axboe | 6d86144 | 2007-03-15 09:22:23 +0100 | [diff] [blame] | 395 | log_info("fio: waiting for connection\n"); |
Jens Axboe | 5fdd124 | 2007-02-11 04:00:37 +0100 | [diff] [blame] | 396 | |
Jens Axboe | 371d456 | 2009-01-19 10:17:06 +0100 | [diff] [blame] | 397 | if (poll_wait(td, nd->listenfd, POLLIN) < 0) |
| 398 | return 1; |
Jens Axboe | 5fdd124 | 2007-02-11 04:00:37 +0100 | [diff] [blame] | 399 | |
Jens Axboe | 371d456 | 2009-01-19 10:17:06 +0100 | [diff] [blame] | 400 | f->fd = accept(nd->listenfd, (struct sockaddr *) &nd->addr, &socklen); |
| 401 | if (f->fd < 0) { |
| 402 | td_verror(td, errno, "accept"); |
| 403 | return 1; |
Jens Axboe | 5fdd124 | 2007-02-11 04:00:37 +0100 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | return 0; |
| 407 | } |
| 408 | |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 409 | static int fio_netio_open_file(struct thread_data *td, struct fio_file *f) |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 410 | { |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 411 | if (td_read(td)) |
| 412 | return fio_netio_accept(td, f); |
| 413 | else |
| 414 | return fio_netio_connect(td, f); |
| 415 | } |
| 416 | |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 417 | static void fio_netio_udp_close(struct thread_data *td, struct fio_file *f) |
| 418 | { |
| 419 | struct netio_data *nd = td->io_ops->data; |
| 420 | struct udp_close_msg msg; |
Jens Axboe | 62b3892 | 2009-05-11 10:37:33 +0200 | [diff] [blame] | 421 | struct sockaddr *to = (struct sockaddr *) &nd->addr; |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 422 | int ret; |
| 423 | |
| 424 | msg.magic = htonl(FIO_LINK_CLOSE_MAGIC); |
| 425 | msg.cmd = htonl(FIO_LINK_CLOSE); |
| 426 | |
Jens Axboe | 62b3892 | 2009-05-11 10:37:33 +0200 | [diff] [blame] | 427 | ret = sendto(f->fd, &msg, sizeof(msg), MSG_WAITALL, to, |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 428 | sizeof(nd->addr)); |
| 429 | if (ret < 0) |
| 430 | td_verror(td, errno, "sendto udp link close"); |
| 431 | } |
| 432 | |
| 433 | static int fio_netio_close_file(struct thread_data *td, struct fio_file *f) |
| 434 | { |
| 435 | struct netio_data *nd = td->io_ops->data; |
| 436 | |
| 437 | /* |
| 438 | * If this is an UDP connection, notify the receiver that we are |
| 439 | * closing down the link |
| 440 | */ |
| 441 | if (nd->net_protocol == IPPROTO_UDP) |
| 442 | fio_netio_udp_close(td, f); |
| 443 | |
| 444 | return generic_close_file(td, f); |
| 445 | } |
| 446 | |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 447 | static int fio_netio_setup_connect(struct thread_data *td, const char *host, |
| 448 | unsigned short port) |
| 449 | { |
| 450 | struct netio_data *nd = td->io_ops->data; |
| 451 | |
| 452 | nd->addr.sin_family = AF_INET; |
| 453 | nd->addr.sin_port = htons(port); |
| 454 | |
| 455 | if (inet_aton(host, &nd->addr.sin_addr) != 1) { |
| 456 | struct hostent *hent; |
| 457 | |
| 458 | hent = gethostbyname(host); |
| 459 | if (!hent) { |
| 460 | td_verror(td, errno, "gethostbyname"); |
| 461 | return 1; |
| 462 | } |
| 463 | |
| 464 | memcpy(&nd->addr.sin_addr, hent->h_addr, 4); |
| 465 | } |
| 466 | |
| 467 | return 0; |
| 468 | } |
| 469 | |
| 470 | static int fio_netio_setup_listen(struct thread_data *td, short port) |
| 471 | { |
| 472 | struct netio_data *nd = td->io_ops->data; |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 473 | int fd, opt, type; |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 474 | |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 475 | if (nd->net_protocol == IPPROTO_TCP) |
| 476 | type = SOCK_STREAM; |
| 477 | else |
| 478 | type = SOCK_DGRAM; |
| 479 | |
| 480 | fd = socket(AF_INET, type, nd->net_protocol); |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 481 | if (fd < 0) { |
Jens Axboe | e1161c3 | 2007-02-22 19:36:48 +0100 | [diff] [blame] | 482 | td_verror(td, errno, "socket"); |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 483 | return 1; |
| 484 | } |
| 485 | |
| 486 | opt = 1; |
| 487 | if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) { |
Jens Axboe | e1161c3 | 2007-02-22 19:36:48 +0100 | [diff] [blame] | 488 | td_verror(td, errno, "setsockopt"); |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 489 | return 1; |
| 490 | } |
Jens Axboe | 6bedbfa | 2007-02-07 09:54:40 +0100 | [diff] [blame] | 491 | #ifdef SO_REUSEPORT |
| 492 | if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &opt, sizeof(opt)) < 0) { |
Jens Axboe | e1161c3 | 2007-02-22 19:36:48 +0100 | [diff] [blame] | 493 | td_verror(td, errno, "setsockopt"); |
Jens Axboe | 6bedbfa | 2007-02-07 09:54:40 +0100 | [diff] [blame] | 494 | return 1; |
| 495 | } |
| 496 | #endif |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 497 | |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 498 | nd->addr.sin_family = AF_INET; |
| 499 | nd->addr.sin_addr.s_addr = htonl(INADDR_ANY); |
| 500 | nd->addr.sin_port = htons(port); |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 501 | |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 502 | if (bind(fd, (struct sockaddr *) &nd->addr, sizeof(nd->addr)) < 0) { |
Jens Axboe | e1161c3 | 2007-02-22 19:36:48 +0100 | [diff] [blame] | 503 | td_verror(td, errno, "bind"); |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 504 | return 1; |
| 505 | } |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 506 | if (nd->net_protocol == IPPROTO_TCP && listen(fd, 1) < 0) { |
Jens Axboe | e1161c3 | 2007-02-22 19:36:48 +0100 | [diff] [blame] | 507 | td_verror(td, errno, "listen"); |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 508 | return 1; |
| 509 | } |
| 510 | |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 511 | nd->listenfd = fd; |
| 512 | return 0; |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 513 | } |
| 514 | |
Jens Axboe | 9bec88e | 2007-03-02 08:55:48 +0100 | [diff] [blame] | 515 | static int fio_netio_init(struct thread_data *td) |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 516 | { |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 517 | struct netio_data *nd = td->io_ops->data; |
Jens Axboe | 443662e | 2008-05-30 13:29:03 +0200 | [diff] [blame] | 518 | unsigned int port; |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 519 | char host[64], buf[128]; |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 520 | char *sep, *portp, *modep; |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 521 | int ret; |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 522 | |
Jens Axboe | 413dd45 | 2007-02-23 09:26:09 +0100 | [diff] [blame] | 523 | if (td_rw(td)) { |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 524 | log_err("fio: network connections must be read OR write\n"); |
| 525 | return 1; |
| 526 | } |
Jens Axboe | 16d55aa | 2007-05-22 09:21:37 +0200 | [diff] [blame] | 527 | if (td_random(td)) { |
| 528 | log_err("fio: network IO can't be random\n"); |
| 529 | return 1; |
| 530 | } |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 531 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 532 | strcpy(buf, td->o.filename); |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 533 | |
Jens Axboe | 9f9214f | 2007-03-13 14:02:16 +0100 | [diff] [blame] | 534 | sep = strchr(buf, '/'); |
Jens Axboe | 443662e | 2008-05-30 13:29:03 +0200 | [diff] [blame] | 535 | if (!sep) |
| 536 | goto bad_host; |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 537 | |
| 538 | *sep = '\0'; |
| 539 | sep++; |
| 540 | strcpy(host, buf); |
Jens Axboe | 443662e | 2008-05-30 13:29:03 +0200 | [diff] [blame] | 541 | if (!strlen(host)) |
| 542 | goto bad_host; |
| 543 | |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 544 | modep = NULL; |
| 545 | portp = sep; |
| 546 | sep = strchr(portp, '/'); |
| 547 | if (sep) { |
| 548 | *sep = '\0'; |
| 549 | modep = sep + 1; |
| 550 | } |
| 551 | |
| 552 | port = strtol(portp, NULL, 10); |
Jens Axboe | 443662e | 2008-05-30 13:29:03 +0200 | [diff] [blame] | 553 | if (!port || port > 65535) |
| 554 | goto bad_host; |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 555 | |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 556 | if (modep) { |
Jens Axboe | 3f8fc5a | 2009-01-16 13:22:26 +0100 | [diff] [blame] | 557 | if (!strncmp("tcp", modep, strlen(modep)) || |
| 558 | !strncmp("TCP", modep, strlen(modep))) |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 559 | nd->net_protocol = IPPROTO_TCP; |
Jens Axboe | 3f8fc5a | 2009-01-16 13:22:26 +0100 | [diff] [blame] | 560 | else if (!strncmp("udp", modep, strlen(modep)) || |
| 561 | !strncmp("UDP", modep, strlen(modep))) |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 562 | nd->net_protocol = IPPROTO_UDP; |
| 563 | else |
| 564 | goto bad_host; |
| 565 | } else |
| 566 | nd->net_protocol = IPPROTO_TCP; |
| 567 | |
Jens Axboe | 413dd45 | 2007-02-23 09:26:09 +0100 | [diff] [blame] | 568 | if (td_read(td)) { |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 569 | nd->send_to_net = 0; |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 570 | ret = fio_netio_setup_listen(td, port); |
| 571 | } else { |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 572 | nd->send_to_net = 1; |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 573 | ret = fio_netio_setup_connect(td, host, port); |
| 574 | } |
| 575 | |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 576 | return ret; |
Jens Axboe | 443662e | 2008-05-30 13:29:03 +0200 | [diff] [blame] | 577 | bad_host: |
Jens Axboe | 414c2a3 | 2009-01-16 13:21:15 +0100 | [diff] [blame] | 578 | log_err("fio: bad network host/port/protocol: %s\n", td->o.filename); |
Jens Axboe | 443662e | 2008-05-30 13:29:03 +0200 | [diff] [blame] | 579 | return 1; |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 580 | } |
| 581 | |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 582 | static void fio_netio_cleanup(struct thread_data *td) |
Jens Axboe | 9bec88e | 2007-03-02 08:55:48 +0100 | [diff] [blame] | 583 | { |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 584 | struct netio_data *nd = td->io_ops->data; |
| 585 | |
| 586 | if (nd) { |
Jens Axboe | 64b24cd | 2007-06-24 21:28:39 +0200 | [diff] [blame] | 587 | if (nd->listenfd != -1) |
| 588 | close(nd->listenfd); |
| 589 | if (nd->pipes[0] != -1) |
| 590 | close(nd->pipes[0]); |
| 591 | if (nd->pipes[1] != -1) |
| 592 | close(nd->pipes[1]); |
| 593 | |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 594 | free(nd); |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 595 | } |
| 596 | } |
| 597 | |
| 598 | static int fio_netio_setup(struct thread_data *td) |
| 599 | { |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 600 | struct netio_data *nd; |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 601 | |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 602 | if (!td->io_ops->data) { |
| 603 | nd = malloc(sizeof(*nd));; |
| 604 | |
| 605 | memset(nd, 0, sizeof(*nd)); |
| 606 | nd->listenfd = -1; |
Jens Axboe | 64b24cd | 2007-06-24 21:28:39 +0200 | [diff] [blame] | 607 | nd->pipes[0] = nd->pipes[1] = -1; |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 608 | td->io_ops->data = nd; |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 609 | } |
| 610 | |
Jens Axboe | 9bec88e | 2007-03-02 08:55:48 +0100 | [diff] [blame] | 611 | return 0; |
| 612 | } |
| 613 | |
Jens Axboe | 5921e80 | 2008-05-30 15:02:38 +0200 | [diff] [blame] | 614 | #ifdef FIO_HAVE_SPLICE |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 615 | static int fio_netio_setup_splice(struct thread_data *td) |
| 616 | { |
| 617 | struct netio_data *nd; |
| 618 | |
| 619 | fio_netio_setup(td); |
| 620 | |
| 621 | nd = td->io_ops->data; |
| 622 | if (nd) { |
| 623 | if (pipe(nd->pipes) < 0) |
| 624 | return 1; |
| 625 | |
| 626 | nd->use_splice = 1; |
| 627 | return 0; |
| 628 | } |
| 629 | |
| 630 | return 1; |
| 631 | } |
| 632 | |
Jens Axboe | 5921e80 | 2008-05-30 15:02:38 +0200 | [diff] [blame] | 633 | static struct ioengine_ops ioengine_splice = { |
| 634 | .name = "netsplice", |
| 635 | .version = FIO_IOOPS_VERSION, |
| 636 | .prep = fio_netio_prep, |
| 637 | .queue = fio_netio_queue, |
| 638 | .setup = fio_netio_setup_splice, |
| 639 | .init = fio_netio_init, |
| 640 | .cleanup = fio_netio_cleanup, |
| 641 | .open_file = fio_netio_open_file, |
| 642 | .close_file = generic_close_file, |
| 643 | .flags = FIO_SYNCIO | FIO_DISKLESSIO | FIO_UNIDIR | |
Bruce Cran | 03e20d6 | 2011-01-02 20:14:54 +0100 | [diff] [blame] | 644 | FIO_SIGTERM | FIO_PIPEIO, |
Jens Axboe | 5921e80 | 2008-05-30 15:02:38 +0200 | [diff] [blame] | 645 | }; |
| 646 | #endif |
| 647 | |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 648 | static struct ioengine_ops ioengine_rw = { |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 649 | .name = "net", |
| 650 | .version = FIO_IOOPS_VERSION, |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 651 | .prep = fio_netio_prep, |
| 652 | .queue = fio_netio_queue, |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 653 | .setup = fio_netio_setup, |
Jens Axboe | 9bec88e | 2007-03-02 08:55:48 +0100 | [diff] [blame] | 654 | .init = fio_netio_init, |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 655 | .cleanup = fio_netio_cleanup, |
| 656 | .open_file = fio_netio_open_file, |
Jens Axboe | 664fb3b | 2009-01-19 13:26:36 +0100 | [diff] [blame] | 657 | .close_file = fio_netio_close_file, |
Jens Axboe | ad830ed | 2008-02-18 21:11:24 +0100 | [diff] [blame] | 658 | .flags = FIO_SYNCIO | FIO_DISKLESSIO | FIO_UNIDIR | |
Bruce Cran | 03e20d6 | 2011-01-02 20:14:54 +0100 | [diff] [blame] | 659 | FIO_SIGTERM | FIO_PIPEIO, |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 660 | }; |
| 661 | |
| 662 | static void fio_init fio_netio_register(void) |
| 663 | { |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 664 | register_ioengine(&ioengine_rw); |
Jens Axboe | 5921e80 | 2008-05-30 15:02:38 +0200 | [diff] [blame] | 665 | #ifdef FIO_HAVE_SPLICE |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 666 | register_ioengine(&ioengine_splice); |
Jens Axboe | 5921e80 | 2008-05-30 15:02:38 +0200 | [diff] [blame] | 667 | #endif |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | static void fio_exit fio_netio_unregister(void) |
| 671 | { |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 672 | unregister_ioengine(&ioengine_rw); |
Jens Axboe | 5921e80 | 2008-05-30 15:02:38 +0200 | [diff] [blame] | 673 | #ifdef FIO_HAVE_SPLICE |
Jens Axboe | 9cce02e | 2007-06-22 15:42:21 +0200 | [diff] [blame] | 674 | unregister_ioengine(&ioengine_splice); |
Jens Axboe | 5921e80 | 2008-05-30 15:02:38 +0200 | [diff] [blame] | 675 | #endif |
Jens Axboe | ed92ac0 | 2007-02-06 14:43:52 +0100 | [diff] [blame] | 676 | } |