net.c revision 7292056a38857ded6f7a64f11d14d642772c31bd
1ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe/* 2da751ca9665bcdeca56d2eec5b629a0953c07662Jens Axboe * net engine 3da751ca9665bcdeca56d2eec5b629a0953c07662Jens Axboe * 4da751ca9665bcdeca56d2eec5b629a0953c07662Jens Axboe * IO engine that reads/writes to/from sockets. 5da751ca9665bcdeca56d2eec5b629a0953c07662Jens Axboe * 6ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe */ 7ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe#include <stdio.h> 8ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe#include <stdlib.h> 9ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe#include <unistd.h> 10ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe#include <errno.h> 11ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe#include <assert.h> 12ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe#include <netinet/in.h> 13ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe#include <arpa/inet.h> 14ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe#include <netdb.h> 155fdd124a3b811993542825847f207587d5f4661eJens Axboe#include <sys/poll.h> 167292056a38857ded6f7a64f11d14d642772c31bdJens Axboe#include <sys/types.h> 177292056a38857ded6f7a64f11d14d642772c31bdJens Axboe#include <sys/socket.h> 18ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 19ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe#include "../fio.h" 20ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 21b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboestruct netio_data { 22b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe int listenfd; 23b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe int send_to_net; 249cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe int use_splice; 259cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe int pipes[2]; 26b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe char host[64]; 27b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe struct sockaddr_in addr; 28b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe}; 29ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 30ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboestatic int fio_netio_prep(struct thread_data *td, struct io_u *io_u) 31ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe{ 32b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe struct netio_data *nd = td->io_ops->data; 33ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 347a6499dada619928267d26b4629b0c8623dc423aJens Axboe /* 357a6499dada619928267d26b4629b0c8623dc423aJens Axboe * Make sure we don't see spurious reads to a receiver, and vice versa 367a6499dada619928267d26b4629b0c8623dc423aJens Axboe */ 37b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe if ((nd->send_to_net && io_u->ddir == DDIR_READ) || 38b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe (!nd->send_to_net && io_u->ddir == DDIR_WRITE)) { 39e1161c325f7866bae879e686d1c673ca32ab09aeJens Axboe td_verror(td, EINVAL, "bad direction"); 407a6499dada619928267d26b4629b0c8623dc423aJens Axboe return 1; 41ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe } 427a6499dada619928267d26b4629b0c8623dc423aJens Axboe 43f85ac25a7d5c9d5ba4d5c73363a6a2a461a9b013Jens Axboe return 0; 44ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe} 45ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 465921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe#ifdef FIO_HAVE_SPLICE 47cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboestatic int splice_io_u(int fdin, int fdout, unsigned int len) 48ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe{ 499cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe int bytes = 0; 507a6499dada619928267d26b4629b0c8623dc423aJens Axboe 519cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe while (len) { 52cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe int ret = splice(fdin, NULL, fdout, NULL, len, 0); 539cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 549cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe if (ret < 0) { 559cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe if (!bytes) 569cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe bytes = ret; 579cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 589cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe break; 599cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe } else if (!ret) 609cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe break; 619cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 629cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe bytes += ret; 63f657a2fbbb0deaf455edc478d73b664929bcb766Jens Axboe len -= ret; 649cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe } 659cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 669cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe return bytes; 679cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe} 689cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 699cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe/* 70cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe * Receive bytes from a socket and fill them into the internal pipe 719cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe */ 72cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboestatic int splice_in(struct thread_data *td, struct io_u *io_u) 739cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe{ 749cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe struct netio_data *nd = td->io_ops->data; 759cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 76cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe return splice_io_u(io_u->file->fd, nd->pipes[1], io_u->xfer_buflen); 779cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe} 789cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 799cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe/* 80cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe * Transmit 'len' bytes from the internal pipe 819cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe */ 82cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboestatic int splice_out(struct thread_data *td, struct io_u *io_u, 83cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe unsigned int len) 849cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe{ 859cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe struct netio_data *nd = td->io_ops->data; 86cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe 87cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe return splice_io_u(nd->pipes[0], io_u->file->fd, len); 88cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe} 89cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe 90cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboestatic int vmsplice_io_u(struct io_u *io_u, int fd, unsigned int len) 91cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe{ 929cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe struct iovec iov = { 939cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe .iov_base = io_u->xfer_buf, 949cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe .iov_len = len, 959cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe }; 969cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe int bytes = 0; 979cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 989cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe while (iov.iov_len) { 99cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe int ret = vmsplice(fd, &iov, 1, SPLICE_F_MOVE); 1009cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1019cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe if (ret < 0) { 1029cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe if (!bytes) 1039cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe bytes = ret; 1049cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe break; 1059cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe } else if (!ret) 1069cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe break; 1079cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1089cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe iov.iov_len -= ret; 109cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe iov.iov_base += ret; 110f657a2fbbb0deaf455edc478d73b664929bcb766Jens Axboe bytes += ret; 1119cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe } 1129cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1139cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe return bytes; 114cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe 1159cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe} 1169cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1179cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe/* 118cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe * vmsplice() pipe to io_u buffer 1199cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe */ 120cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboestatic int vmsplice_io_u_out(struct thread_data *td, struct io_u *io_u, 121cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe unsigned int len) 1229cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe{ 1239cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe struct netio_data *nd = td->io_ops->data; 1249cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 125cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe return vmsplice_io_u(io_u, nd->pipes[0], len); 126cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe} 1279cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 128cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe/* 129cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe * vmsplice() io_u to pipe 130cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe */ 131cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboestatic int vmsplice_io_u_in(struct thread_data *td, struct io_u *io_u) 132cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe{ 133cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe struct netio_data *nd = td->io_ops->data; 134ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 135cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe return vmsplice_io_u(io_u, nd->pipes[1], io_u->xfer_buflen); 1369cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe} 1379cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 138cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe/* 139cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe * splice receive - transfer socket data into a pipe using splice, then map 140cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe * that pipe data into the io_u using vmsplice. 141cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe */ 1429cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboestatic int fio_netio_splice_in(struct thread_data *td, struct io_u *io_u) 1439cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe{ 1449cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe int ret; 1459cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1469cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe ret = splice_in(td, io_u); 147cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe if (ret > 0) 148cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe return vmsplice_io_u_out(td, io_u, ret); 1499cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 150cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe return ret; 1519cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe} 1529cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 153cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe/* 154cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe * splice transmit - map data from the io_u into a pipe by using vmsplice, 155cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe * then transfer that pipe to a socket using splice. 156cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe */ 1579cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboestatic int fio_netio_splice_out(struct thread_data *td, struct io_u *io_u) 1589cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe{ 1599cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe int ret; 1609cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1619cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe ret = vmsplice_io_u_in(td, io_u); 162cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe if (ret > 0) 163cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe return splice_out(td, io_u, ret); 1649cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 165cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe return ret; 1669cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe} 1675921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe#else 1685921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboestatic int fio_netio_splice_in(struct thread_data *td, struct io_u *io_u) 1695921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe{ 170af8771b9b91eb2cd23a40aaa729bad4f78acb928Jens Axboe errno = EOPNOTSUPP; 1715921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe return -1; 1725921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe} 1735921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe 1745921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboestatic int fio_netio_splice_out(struct thread_data *td, struct io_u *io_u) 1755921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe{ 176af8771b9b91eb2cd23a40aaa729bad4f78acb928Jens Axboe errno = EOPNOTSUPP; 1775921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe return -1; 1785921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe} 1795921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe#endif 1809cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1819cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboestatic int fio_netio_send(struct thread_data *td, struct io_u *io_u) 1829cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe{ 1839cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe int flags = 0; 1849cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1859cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe /* 1869cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe * if we are going to write more, set MSG_MORE 1879cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe */ 1885921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe#ifdef MSG_MORE 1899cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe if (td->this_io_bytes[DDIR_WRITE] + io_u->xfer_buflen < td->o.size) 1909cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe flags = MSG_MORE; 1915921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe#endif 1929cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1939cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe return send(io_u->file->fd, io_u->xfer_buf, io_u->xfer_buflen, flags); 1949cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe} 1959cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1969cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboestatic int fio_netio_recv(struct io_u *io_u) 1979cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe{ 1989cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe int flags = MSG_WAITALL; 1999cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 2009cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe return recv(io_u->file->fd, io_u->xfer_buf, io_u->xfer_buflen, flags); 2019cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe} 2029cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 2039cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboestatic int fio_netio_queue(struct thread_data *td, struct io_u *io_u) 2049cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe{ 2059cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe struct netio_data *nd = td->io_ops->data; 2069cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe int ret; 2079cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 2087101d9c24abec4be58a086d85d6d92ec6e6492e9Jens Axboe fio_ro_check(td, io_u); 2097101d9c24abec4be58a086d85d6d92ec6e6492e9Jens Axboe 2109cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe if (io_u->ddir == DDIR_WRITE) { 2119cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe if (nd->use_splice) 2129cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe ret = fio_netio_splice_out(td, io_u); 2139cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe else 2149cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe ret = fio_netio_send(td, io_u); 215d4f12dd05cfb2e8e7a72604cd870e10f2394914eJens Axboe } else if (io_u->ddir == DDIR_READ) { 2169cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe if (nd->use_splice) 2179cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe ret = fio_netio_splice_in(td, io_u); 2189cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe else 2199cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe ret = fio_netio_recv(io_u); 220d4f12dd05cfb2e8e7a72604cd870e10f2394914eJens Axboe } else 2217a6499dada619928267d26b4629b0c8623dc423aJens Axboe ret = 0; /* must be a SYNC */ 222ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 223cec6b55da1c282b5b91ad346c7804171fccf151eJens Axboe if (ret != (int) io_u->xfer_buflen) { 22422819ec237297fc39435ed566bee01a4225bfb39Jens Axboe if (ret >= 0) { 225cec6b55da1c282b5b91ad346c7804171fccf151eJens Axboe io_u->resid = io_u->xfer_buflen - ret; 226cec6b55da1c282b5b91ad346c7804171fccf151eJens Axboe io_u->error = 0; 22736167d82e5f49dee91c6d2cd426068edee90e36fJens Axboe return FIO_Q_COMPLETED; 228ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe } else 229ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe io_u->error = errno; 230ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe } 231ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 23236167d82e5f49dee91c6d2cd426068edee90e36fJens Axboe if (io_u->error) 233e1161c325f7866bae879e686d1c673ca32ab09aeJens Axboe td_verror(td, io_u->error, "xfer"); 234ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 23536167d82e5f49dee91c6d2cd426068edee90e36fJens Axboe return FIO_Q_COMPLETED; 236ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe} 237ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 238b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboestatic int fio_netio_connect(struct thread_data *td, struct fio_file *f) 239ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe{ 240b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe struct netio_data *nd = td->io_ops->data; 241ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 242b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe f->fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 243b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe if (f->fd < 0) { 244b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe td_verror(td, errno, "socket"); 245b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe return 1; 246ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe } 247ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 248b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe if (connect(f->fd, (struct sockaddr *) &nd->addr, sizeof(nd->addr)) < 0) { 249b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe td_verror(td, errno, "connect"); 250b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe return 1; 251ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe } 252ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 253ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe return 0; 254ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe} 255ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 256b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboestatic int fio_netio_accept(struct thread_data *td, struct fio_file *f) 2575fdd124a3b811993542825847f207587d5f4661eJens Axboe{ 258b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe struct netio_data *nd = td->io_ops->data; 259b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe socklen_t socklen = sizeof(nd->addr); 2605fdd124a3b811993542825847f207587d5f4661eJens Axboe struct pollfd pfd; 261b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe int ret; 2625fdd124a3b811993542825847f207587d5f4661eJens Axboe 2636d86144dd10b05e8b82e9b895c35dd778e5e71abJens Axboe log_info("fio: waiting for connection\n"); 2645fdd124a3b811993542825847f207587d5f4661eJens Axboe 2655fdd124a3b811993542825847f207587d5f4661eJens Axboe /* 2665fdd124a3b811993542825847f207587d5f4661eJens Axboe * Accept loop. poll for incoming events, accept them. Repeat until we 2675fdd124a3b811993542825847f207587d5f4661eJens Axboe * have all connections. 2685fdd124a3b811993542825847f207587d5f4661eJens Axboe */ 269b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe while (!td->terminate) { 270b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe pfd.fd = nd->listenfd; 2715fdd124a3b811993542825847f207587d5f4661eJens Axboe pfd.events = POLLIN; 2725fdd124a3b811993542825847f207587d5f4661eJens Axboe 2735fdd124a3b811993542825847f207587d5f4661eJens Axboe ret = poll(&pfd, 1, -1); 2745fdd124a3b811993542825847f207587d5f4661eJens Axboe if (ret < 0) { 2755fdd124a3b811993542825847f207587d5f4661eJens Axboe if (errno == EINTR) 2765fdd124a3b811993542825847f207587d5f4661eJens Axboe continue; 2775fdd124a3b811993542825847f207587d5f4661eJens Axboe 278e1161c325f7866bae879e686d1c673ca32ab09aeJens Axboe td_verror(td, errno, "poll"); 2795fdd124a3b811993542825847f207587d5f4661eJens Axboe break; 2805fdd124a3b811993542825847f207587d5f4661eJens Axboe } else if (!ret) 2815fdd124a3b811993542825847f207587d5f4661eJens Axboe continue; 2825fdd124a3b811993542825847f207587d5f4661eJens Axboe 2830c09442b26216aed16f758712f744a2c54726cdbJens Axboe /* 2840c09442b26216aed16f758712f744a2c54726cdbJens Axboe * should be impossible 2850c09442b26216aed16f758712f744a2c54726cdbJens Axboe */ 2860c09442b26216aed16f758712f744a2c54726cdbJens Axboe if (!(pfd.revents & POLLIN)) 2870c09442b26216aed16f758712f744a2c54726cdbJens Axboe continue; 2880c09442b26216aed16f758712f744a2c54726cdbJens Axboe 289b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe f->fd = accept(nd->listenfd, (struct sockaddr *) &nd->addr, &socklen); 290b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe if (f->fd < 0) { 291b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe td_verror(td, errno, "accept"); 292b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe return 1; 293b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe } 294b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe break; 295b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe } 2965fdd124a3b811993542825847f207587d5f4661eJens Axboe 297b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe return 0; 298b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe} 299b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe 300b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboestatic int fio_netio_open_file(struct thread_data *td, struct fio_file *f) 301b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe{ 302b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe if (td_read(td)) 303b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe return fio_netio_accept(td, f); 304b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe else 305b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe return fio_netio_connect(td, f); 306b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe} 307b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe 308b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboestatic int fio_netio_setup_connect(struct thread_data *td, const char *host, 309b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe unsigned short port) 310b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe{ 311b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe struct netio_data *nd = td->io_ops->data; 312b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe 313b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe nd->addr.sin_family = AF_INET; 314b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe nd->addr.sin_port = htons(port); 315b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe 316b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe if (inet_aton(host, &nd->addr.sin_addr) != 1) { 317b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe struct hostent *hent; 318b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe 319b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe hent = gethostbyname(host); 320b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe if (!hent) { 321b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe td_verror(td, errno, "gethostbyname"); 322b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe return 1; 3235fdd124a3b811993542825847f207587d5f4661eJens Axboe } 324b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe 325b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe memcpy(&nd->addr.sin_addr, hent->h_addr, 4); 3265fdd124a3b811993542825847f207587d5f4661eJens Axboe } 3275fdd124a3b811993542825847f207587d5f4661eJens Axboe 3285fdd124a3b811993542825847f207587d5f4661eJens Axboe return 0; 3295fdd124a3b811993542825847f207587d5f4661eJens Axboe} 3305fdd124a3b811993542825847f207587d5f4661eJens Axboe 331b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboestatic int fio_netio_setup_listen(struct thread_data *td, short port) 332ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe{ 333b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe struct netio_data *nd = td->io_ops->data; 3345fdd124a3b811993542825847f207587d5f4661eJens Axboe int fd, opt; 335ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 3366bedbfafcffbc7202b5bb621ac5886aafdc0f362Jens Axboe fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 337ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe if (fd < 0) { 338e1161c325f7866bae879e686d1c673ca32ab09aeJens Axboe td_verror(td, errno, "socket"); 339ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe return 1; 340ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe } 341ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 342ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe opt = 1; 343ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) { 344e1161c325f7866bae879e686d1c673ca32ab09aeJens Axboe td_verror(td, errno, "setsockopt"); 345ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe return 1; 346ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe } 3476bedbfafcffbc7202b5bb621ac5886aafdc0f362Jens Axboe#ifdef SO_REUSEPORT 3486bedbfafcffbc7202b5bb621ac5886aafdc0f362Jens Axboe if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &opt, sizeof(opt)) < 0) { 349e1161c325f7866bae879e686d1c673ca32ab09aeJens Axboe td_verror(td, errno, "setsockopt"); 3506bedbfafcffbc7202b5bb621ac5886aafdc0f362Jens Axboe return 1; 3516bedbfafcffbc7202b5bb621ac5886aafdc0f362Jens Axboe } 3526bedbfafcffbc7202b5bb621ac5886aafdc0f362Jens Axboe#endif 353ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 354b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe nd->addr.sin_family = AF_INET; 355b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe nd->addr.sin_addr.s_addr = htonl(INADDR_ANY); 356b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe nd->addr.sin_port = htons(port); 357ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 358b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe if (bind(fd, (struct sockaddr *) &nd->addr, sizeof(nd->addr)) < 0) { 359e1161c325f7866bae879e686d1c673ca32ab09aeJens Axboe td_verror(td, errno, "bind"); 360ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe return 1; 361ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe } 362ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe if (listen(fd, 1) < 0) { 363e1161c325f7866bae879e686d1c673ca32ab09aeJens Axboe td_verror(td, errno, "listen"); 364ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe return 1; 365ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe } 366ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 367b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe nd->listenfd = fd; 368b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe return 0; 369ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe} 370ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 3719bec88e15aad76c16ac65048270ecac8b5956a61Jens Axboestatic int fio_netio_init(struct thread_data *td) 372ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe{ 373b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe struct netio_data *nd = td->io_ops->data; 374443662efa60d9082bc820641e7d1d31dd58d3ae1Jens Axboe unsigned int port; 375b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe char host[64], buf[128]; 376ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe char *sep; 377af52b3455ad892322aab2791282b6bd4efdfdbf3Jens Axboe int ret; 378ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 379413dd459a7710ba421061e840dd9ac3161c70f20Jens Axboe if (td_rw(td)) { 380ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe log_err("fio: network connections must be read OR write\n"); 381ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe return 1; 382ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe } 38316d55aae770b8b1a966d4b4a814918ce49a76ba3Jens Axboe if (td_random(td)) { 38416d55aae770b8b1a966d4b4a814918ce49a76ba3Jens Axboe log_err("fio: network IO can't be random\n"); 38516d55aae770b8b1a966d4b4a814918ce49a76ba3Jens Axboe return 1; 38616d55aae770b8b1a966d4b4a814918ce49a76ba3Jens Axboe } 387ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 3882dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe strcpy(buf, td->o.filename); 389ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 3909f9214f243701626a04b4a0f9aceec03b8b40e0fJens Axboe sep = strchr(buf, '/'); 391443662efa60d9082bc820641e7d1d31dd58d3ae1Jens Axboe if (!sep) 392443662efa60d9082bc820641e7d1d31dd58d3ae1Jens Axboe goto bad_host; 393ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 394ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe *sep = '\0'; 395ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe sep++; 396ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe strcpy(host, buf); 397443662efa60d9082bc820641e7d1d31dd58d3ae1Jens Axboe if (!strlen(host)) 398443662efa60d9082bc820641e7d1d31dd58d3ae1Jens Axboe goto bad_host; 399443662efa60d9082bc820641e7d1d31dd58d3ae1Jens Axboe 400443662efa60d9082bc820641e7d1d31dd58d3ae1Jens Axboe port = strtol(sep, NULL, 10); 401443662efa60d9082bc820641e7d1d31dd58d3ae1Jens Axboe if (!port || port > 65535) 402443662efa60d9082bc820641e7d1d31dd58d3ae1Jens Axboe goto bad_host; 403ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 404413dd459a7710ba421061e840dd9ac3161c70f20Jens Axboe if (td_read(td)) { 405b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe nd->send_to_net = 0; 406ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe ret = fio_netio_setup_listen(td, port); 407ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe } else { 408b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe nd->send_to_net = 1; 409ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe ret = fio_netio_setup_connect(td, host, port); 410ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe } 411ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 4127bb48f84ac78cac1f90e3e04d0220d90d6a64a6bJens Axboe return ret; 413443662efa60d9082bc820641e7d1d31dd58d3ae1Jens Axboebad_host: 414443662efa60d9082bc820641e7d1d31dd58d3ae1Jens Axboe log_err("fio: bad network host/port: %s\n", td->o.filename); 415443662efa60d9082bc820641e7d1d31dd58d3ae1Jens Axboe return 1; 416ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe} 417ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 418b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboestatic void fio_netio_cleanup(struct thread_data *td) 4199bec88e15aad76c16ac65048270ecac8b5956a61Jens Axboe{ 420b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe struct netio_data *nd = td->io_ops->data; 421b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe 422b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe if (nd) { 42364b24cd8a5ea87bccec60e0236d93071480201e7Jens Axboe if (nd->listenfd != -1) 42464b24cd8a5ea87bccec60e0236d93071480201e7Jens Axboe close(nd->listenfd); 42564b24cd8a5ea87bccec60e0236d93071480201e7Jens Axboe if (nd->pipes[0] != -1) 42664b24cd8a5ea87bccec60e0236d93071480201e7Jens Axboe close(nd->pipes[0]); 42764b24cd8a5ea87bccec60e0236d93071480201e7Jens Axboe if (nd->pipes[1] != -1) 42864b24cd8a5ea87bccec60e0236d93071480201e7Jens Axboe close(nd->pipes[1]); 42964b24cd8a5ea87bccec60e0236d93071480201e7Jens Axboe 430b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe free(nd); 431b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe } 432b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe} 433b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe 434b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboestatic int fio_netio_setup(struct thread_data *td) 435b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe{ 4367bb48f84ac78cac1f90e3e04d0220d90d6a64a6bJens Axboe struct netio_data *nd; 4377bb48f84ac78cac1f90e3e04d0220d90d6a64a6bJens Axboe 4387bb48f84ac78cac1f90e3e04d0220d90d6a64a6bJens Axboe if (!td->io_ops->data) { 4397bb48f84ac78cac1f90e3e04d0220d90d6a64a6bJens Axboe nd = malloc(sizeof(*nd));; 4407bb48f84ac78cac1f90e3e04d0220d90d6a64a6bJens Axboe 4417bb48f84ac78cac1f90e3e04d0220d90d6a64a6bJens Axboe memset(nd, 0, sizeof(*nd)); 4427bb48f84ac78cac1f90e3e04d0220d90d6a64a6bJens Axboe nd->listenfd = -1; 44364b24cd8a5ea87bccec60e0236d93071480201e7Jens Axboe nd->pipes[0] = nd->pipes[1] = -1; 4447bb48f84ac78cac1f90e3e04d0220d90d6a64a6bJens Axboe td->io_ops->data = nd; 4457bb48f84ac78cac1f90e3e04d0220d90d6a64a6bJens Axboe } 446b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe 4479bec88e15aad76c16ac65048270ecac8b5956a61Jens Axboe return 0; 4489bec88e15aad76c16ac65048270ecac8b5956a61Jens Axboe} 4499bec88e15aad76c16ac65048270ecac8b5956a61Jens Axboe 4505921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe#ifdef FIO_HAVE_SPLICE 4519cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboestatic int fio_netio_setup_splice(struct thread_data *td) 4529cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe{ 4539cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe struct netio_data *nd; 4549cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 4559cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe fio_netio_setup(td); 4569cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 4579cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe nd = td->io_ops->data; 4589cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe if (nd) { 4599cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe if (pipe(nd->pipes) < 0) 4609cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe return 1; 4619cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 4629cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe nd->use_splice = 1; 4639cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe return 0; 4649cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe } 4659cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 4669cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe return 1; 4679cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe} 4689cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 4695921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboestatic struct ioengine_ops ioengine_splice = { 4705921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe .name = "netsplice", 471ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe .version = FIO_IOOPS_VERSION, 472ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe .prep = fio_netio_prep, 473ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe .queue = fio_netio_queue, 4745921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe .setup = fio_netio_setup_splice, 4759bec88e15aad76c16ac65048270ecac8b5956a61Jens Axboe .init = fio_netio_init, 476b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe .cleanup = fio_netio_cleanup, 477b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe .open_file = fio_netio_open_file, 478b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe .close_file = generic_close_file, 479ad830ed7386eff264bdb5189675d6dfa672bd16bJens Axboe .flags = FIO_SYNCIO | FIO_DISKLESSIO | FIO_UNIDIR | 480ad830ed7386eff264bdb5189675d6dfa672bd16bJens Axboe FIO_SIGQUIT, 481ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe}; 4825921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe#endif 483ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 4845921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboestatic struct ioengine_ops ioengine_rw = { 4855921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe .name = "net", 4869cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe .version = FIO_IOOPS_VERSION, 4879cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe .prep = fio_netio_prep, 4889cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe .queue = fio_netio_queue, 4895921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe .setup = fio_netio_setup, 4909cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe .init = fio_netio_init, 4919cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe .cleanup = fio_netio_cleanup, 4929cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe .open_file = fio_netio_open_file, 4939cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe .close_file = generic_close_file, 494ad830ed7386eff264bdb5189675d6dfa672bd16bJens Axboe .flags = FIO_SYNCIO | FIO_DISKLESSIO | FIO_UNIDIR | 495ad830ed7386eff264bdb5189675d6dfa672bd16bJens Axboe FIO_SIGQUIT, 4969cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe}; 4979cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 498ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboestatic void fio_init fio_netio_register(void) 499ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe{ 5009cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe register_ioengine(&ioengine_rw); 5015921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe#ifdef FIO_HAVE_SPLICE 5029cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe register_ioengine(&ioengine_splice); 5035921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe#endif 504ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe} 505ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 506ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboestatic void fio_exit fio_netio_unregister(void) 507ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe{ 5089cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe unregister_ioengine(&ioengine_rw); 5095921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe#ifdef FIO_HAVE_SPLICE 5109cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe unregister_ioengine(&ioengine_splice); 5115921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe#endif 512ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe} 513