net.c revision 64b24cd8a5ea87bccec60e0236d93071480201e7
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> 16ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 17ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe#include "../fio.h" 18ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 19b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboestruct netio_data { 20b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe int listenfd; 21b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe int send_to_net; 229cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe int use_splice; 239cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe int pipes[2]; 24b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe char host[64]; 25b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe struct sockaddr_in addr; 26b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe}; 27ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 28ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboestatic int fio_netio_prep(struct thread_data *td, struct io_u *io_u) 29ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe{ 30b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe struct netio_data *nd = td->io_ops->data; 31ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe struct fio_file *f = io_u->file; 32ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 337a6499dada619928267d26b4629b0c8623dc423aJens Axboe /* 347a6499dada619928267d26b4629b0c8623dc423aJens Axboe * Make sure we don't see spurious reads to a receiver, and vice versa 357a6499dada619928267d26b4629b0c8623dc423aJens Axboe */ 36b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe if ((nd->send_to_net && io_u->ddir == DDIR_READ) || 37b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe (!nd->send_to_net && io_u->ddir == DDIR_WRITE)) { 38e1161c325f7866bae879e686d1c673ca32ab09aeJens Axboe td_verror(td, EINVAL, "bad direction"); 397a6499dada619928267d26b4629b0c8623dc423aJens Axboe return 1; 40ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe } 417a6499dada619928267d26b4629b0c8623dc423aJens Axboe 42ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe if (io_u->ddir == DDIR_SYNC) 43ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe return 0; 44ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe if (io_u->offset == f->last_completed_pos) 45ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe return 0; 46ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 47e01547d2b8bf79c3abe14e03c72398cf8998eb1eJens Axboe /* 48e01547d2b8bf79c3abe14e03c72398cf8998eb1eJens Axboe * If offset is different from last end position, it's a seek. 49e01547d2b8bf79c3abe14e03c72398cf8998eb1eJens Axboe * As network io is purely sequential, we don't allow seeks. 50e01547d2b8bf79c3abe14e03c72398cf8998eb1eJens Axboe */ 51e1161c325f7866bae879e686d1c673ca32ab09aeJens Axboe td_verror(td, EINVAL, "cannot seek"); 52ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe return 1; 53ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe} 54ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 559cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe/* 569cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe * Receive bytes from a socket and fill them into the internal pipe 579cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe */ 589cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboestatic int splice_in(struct thread_data *td, struct io_u *io_u) 59ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe{ 609cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe struct netio_data *nd = td->io_ops->data; 619cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe unsigned int len = io_u->xfer_buflen; 62ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe struct fio_file *f = io_u->file; 639cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe int bytes = 0; 647a6499dada619928267d26b4629b0c8623dc423aJens Axboe 659cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe while (len) { 66f657a2fbbb0deaf455edc478d73b664929bcb766Jens Axboe int ret = splice(f->fd, NULL, nd->pipes[1], NULL, len, 0); 679cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 689cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe if (ret < 0) { 699cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe if (!bytes) 709cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe bytes = ret; 719cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 729cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe break; 739cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe } else if (!ret) 749cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe break; 759cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 769cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe bytes += ret; 77f657a2fbbb0deaf455edc478d73b664929bcb766Jens Axboe len -= ret; 789cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe } 799cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 809cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe return bytes; 819cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe} 829cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 839cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe/* 849cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe * Transmit 'len' bytes from the internal pipe 859cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe */ 869cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboestatic int splice_out(struct thread_data *td, struct io_u *io_u, 879cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe unsigned int len) 889cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe{ 899cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe struct netio_data *nd = td->io_ops->data; 909cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe struct fio_file *f = io_u->file; 919cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe int bytes = 0; 929cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 939cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe while (len) { 949cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe int ret = splice(nd->pipes[0], NULL, f->fd, NULL, len, 0); 959cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 969cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe if (ret < 0) { 979cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe if (!bytes) 989cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe bytes = ret; 999cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1009cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe break; 1019cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe } else if (!ret) 1029cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe break; 1039cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1049cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe bytes += ret; 1059cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe len -= ret; 1069cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe } 1079cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1089cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe return bytes; 1099cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe} 1109cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1119cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe/* 1129cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe * vmsplice() pipe to io_u buffer 1139cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe */ 1149cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboestatic int vmsplice_io_u_out(struct thread_data *td, struct io_u *io_u, 1159cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe unsigned int len) 1169cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe{ 1179cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe struct netio_data *nd = td->io_ops->data; 1189cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe struct iovec iov = { 1199cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe .iov_base = io_u->xfer_buf, 1209cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe .iov_len = len, 1219cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe }; 1229cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe int bytes = 0; 1239cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1249cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe while (iov.iov_len) { 1254d94c275d2344b9231d9dc4585bd42b8e9fb7794Jens Axboe int ret = vmsplice(nd->pipes[0], &iov, 1, SPLICE_F_MOVE); 1269cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1279cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe if (ret < 0) { 1289cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe if (!bytes) 1299cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe bytes = ret; 1309cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe break; 1319cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe } else if (!ret) 1329cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe break; 1339cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1349cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe iov.iov_len -= ret; 135f657a2fbbb0deaf455edc478d73b664929bcb766Jens Axboe bytes += ret; 1369cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe if (iov.iov_len) 1379cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe iov.iov_base += ret; 1389cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe } 1399cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1409cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe return bytes; 1419cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe} 1429cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1439cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe/* 1449cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe * vmsplice() io_u to pipe 1459cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe */ 1469cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboestatic int vmsplice_io_u_in(struct thread_data *td, struct io_u *io_u) 1479cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe{ 1489cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe struct netio_data *nd = td->io_ops->data; 1499cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe struct iovec iov = { 1509cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe .iov_base = io_u->xfer_buf, 1519cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe .iov_len = io_u->xfer_buflen, 1529cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe }; 1539cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe unsigned int bytes = 0; 1549cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1559cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe while (iov.iov_len) { 1564d94c275d2344b9231d9dc4585bd42b8e9fb7794Jens Axboe int ret = vmsplice(nd->pipes[1], &iov, 1, SPLICE_F_MOVE); 1579cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1589cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe if (ret < 0) 1599cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe return -1; 1609cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe else if (!ret) 1619cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe return bytes; 1629cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1639cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe iov.iov_len -= ret; 1649cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe bytes += ret; 1659cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe if (iov.iov_len) 1669cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe iov.iov_base += ret; 1679cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe } 168ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 1699cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe return bytes; 1709cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe} 1719cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1729cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboestatic int fio_netio_splice_in(struct thread_data *td, struct io_u *io_u) 1739cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe{ 1749cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe int ret; 1759cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1769cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe ret = splice_in(td, io_u); 1779cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe if (ret <= 0) 1789cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe return ret; 1799cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1809cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe return vmsplice_io_u_out(td, io_u, ret); 1819cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe} 1829cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1839cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboestatic int fio_netio_splice_out(struct thread_data *td, struct io_u *io_u) 1849cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe{ 1859cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe int ret; 1869cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1879cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe ret = vmsplice_io_u_in(td, io_u); 1889cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe if (ret <= 0) 1899cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe return ret; 1909cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1919cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe return splice_out(td, io_u, ret); 1929cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe} 1939cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1949cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboestatic int fio_netio_send(struct thread_data *td, struct io_u *io_u) 1959cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe{ 1969cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe int flags = 0; 1979cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1989cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe /* 1999cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe * if we are going to write more, set MSG_MORE 2009cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe */ 2019cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe if (td->this_io_bytes[DDIR_WRITE] + io_u->xfer_buflen < td->o.size) 2029cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe flags = MSG_MORE; 2039cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 2049cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe return send(io_u->file->fd, io_u->xfer_buf, io_u->xfer_buflen, flags); 2059cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe} 2069cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 2079cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboestatic int fio_netio_recv(struct io_u *io_u) 2089cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe{ 2099cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe int flags = MSG_WAITALL; 2109cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 2119cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe return recv(io_u->file->fd, io_u->xfer_buf, io_u->xfer_buflen, flags); 2129cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe} 2139cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 2149cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboestatic int fio_netio_queue(struct thread_data *td, struct io_u *io_u) 2159cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe{ 2169cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe struct netio_data *nd = td->io_ops->data; 2179cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe int ret; 2189cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 2199cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe if (io_u->ddir == DDIR_WRITE) { 2209cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe if (nd->use_splice) 2219cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe ret = fio_netio_splice_out(td, io_u); 2229cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe else 2239cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe ret = fio_netio_send(td, io_u); 224d4f12dd05cfb2e8e7a72604cd870e10f2394914eJens Axboe } else if (io_u->ddir == DDIR_READ) { 2259cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe if (nd->use_splice) 2269cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe ret = fio_netio_splice_in(td, io_u); 2279cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe else 2289cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe ret = fio_netio_recv(io_u); 229d4f12dd05cfb2e8e7a72604cd870e10f2394914eJens Axboe } else 2307a6499dada619928267d26b4629b0c8623dc423aJens Axboe ret = 0; /* must be a SYNC */ 231ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 232cec6b55da1c282b5b91ad346c7804171fccf151eJens Axboe if (ret != (int) io_u->xfer_buflen) { 23322819ec237297fc39435ed566bee01a4225bfb39Jens Axboe if (ret >= 0) { 234cec6b55da1c282b5b91ad346c7804171fccf151eJens Axboe io_u->resid = io_u->xfer_buflen - ret; 235cec6b55da1c282b5b91ad346c7804171fccf151eJens Axboe io_u->error = 0; 23636167d82e5f49dee91c6d2cd426068edee90e36fJens Axboe return FIO_Q_COMPLETED; 237ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe } else 238ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe io_u->error = errno; 239ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe } 240ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 24136167d82e5f49dee91c6d2cd426068edee90e36fJens Axboe if (io_u->error) 242e1161c325f7866bae879e686d1c673ca32ab09aeJens Axboe td_verror(td, io_u->error, "xfer"); 243ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 24436167d82e5f49dee91c6d2cd426068edee90e36fJens Axboe return FIO_Q_COMPLETED; 245ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe} 246ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 247b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboestatic int fio_netio_connect(struct thread_data *td, struct fio_file *f) 248ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe{ 249b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe struct netio_data *nd = td->io_ops->data; 250ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 251b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe f->fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 252b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe if (f->fd < 0) { 253b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe td_verror(td, errno, "socket"); 254b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe return 1; 255ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe } 256ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 257b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe if (connect(f->fd, (struct sockaddr *) &nd->addr, sizeof(nd->addr)) < 0) { 258b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe td_verror(td, errno, "connect"); 259b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe return 1; 260ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe } 261ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 262ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe return 0; 263ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe} 264ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 265b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboestatic int fio_netio_accept(struct thread_data *td, struct fio_file *f) 2665fdd124a3b811993542825847f207587d5f4661eJens Axboe{ 267b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe struct netio_data *nd = td->io_ops->data; 268b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe socklen_t socklen = sizeof(nd->addr); 2695fdd124a3b811993542825847f207587d5f4661eJens Axboe struct pollfd pfd; 270b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe int ret; 2715fdd124a3b811993542825847f207587d5f4661eJens Axboe 2726d86144dd10b05e8b82e9b895c35dd778e5e71abJens Axboe log_info("fio: waiting for connection\n"); 2735fdd124a3b811993542825847f207587d5f4661eJens Axboe 2745fdd124a3b811993542825847f207587d5f4661eJens Axboe /* 2755fdd124a3b811993542825847f207587d5f4661eJens Axboe * Accept loop. poll for incoming events, accept them. Repeat until we 2765fdd124a3b811993542825847f207587d5f4661eJens Axboe * have all connections. 2775fdd124a3b811993542825847f207587d5f4661eJens Axboe */ 278b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe while (!td->terminate) { 279b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe pfd.fd = nd->listenfd; 2805fdd124a3b811993542825847f207587d5f4661eJens Axboe pfd.events = POLLIN; 2815fdd124a3b811993542825847f207587d5f4661eJens Axboe 2825fdd124a3b811993542825847f207587d5f4661eJens Axboe ret = poll(&pfd, 1, -1); 2835fdd124a3b811993542825847f207587d5f4661eJens Axboe if (ret < 0) { 2845fdd124a3b811993542825847f207587d5f4661eJens Axboe if (errno == EINTR) 2855fdd124a3b811993542825847f207587d5f4661eJens Axboe continue; 2865fdd124a3b811993542825847f207587d5f4661eJens Axboe 287e1161c325f7866bae879e686d1c673ca32ab09aeJens Axboe td_verror(td, errno, "poll"); 2885fdd124a3b811993542825847f207587d5f4661eJens Axboe break; 2895fdd124a3b811993542825847f207587d5f4661eJens Axboe } else if (!ret) 2905fdd124a3b811993542825847f207587d5f4661eJens Axboe continue; 2915fdd124a3b811993542825847f207587d5f4661eJens Axboe 2920c09442b26216aed16f758712f744a2c54726cdbJens Axboe /* 2930c09442b26216aed16f758712f744a2c54726cdbJens Axboe * should be impossible 2940c09442b26216aed16f758712f744a2c54726cdbJens Axboe */ 2950c09442b26216aed16f758712f744a2c54726cdbJens Axboe if (!(pfd.revents & POLLIN)) 2960c09442b26216aed16f758712f744a2c54726cdbJens Axboe continue; 2970c09442b26216aed16f758712f744a2c54726cdbJens Axboe 298b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe f->fd = accept(nd->listenfd, (struct sockaddr *) &nd->addr, &socklen); 299b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe if (f->fd < 0) { 300b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe td_verror(td, errno, "accept"); 301b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe return 1; 302b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe } 303b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe break; 304b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe } 3055fdd124a3b811993542825847f207587d5f4661eJens Axboe 306b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe return 0; 307b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe} 308b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe 309b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe 310b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboestatic int fio_netio_open_file(struct thread_data *td, struct fio_file *f) 311b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe{ 312b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe if (td_read(td)) 313b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe return fio_netio_accept(td, f); 314b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe else 315b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe return fio_netio_connect(td, f); 316b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe} 317b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe 318b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboestatic int fio_netio_setup_connect(struct thread_data *td, const char *host, 319b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe unsigned short port) 320b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe{ 321b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe struct netio_data *nd = td->io_ops->data; 322b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe 323b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe nd->addr.sin_family = AF_INET; 324b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe nd->addr.sin_port = htons(port); 325b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe 326b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe if (inet_aton(host, &nd->addr.sin_addr) != 1) { 327b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe struct hostent *hent; 328b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe 329b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe hent = gethostbyname(host); 330b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe if (!hent) { 331b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe td_verror(td, errno, "gethostbyname"); 332b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe return 1; 3335fdd124a3b811993542825847f207587d5f4661eJens Axboe } 334b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe 335b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe memcpy(&nd->addr.sin_addr, hent->h_addr, 4); 3365fdd124a3b811993542825847f207587d5f4661eJens Axboe } 3375fdd124a3b811993542825847f207587d5f4661eJens Axboe 3385fdd124a3b811993542825847f207587d5f4661eJens Axboe return 0; 3395fdd124a3b811993542825847f207587d5f4661eJens Axboe} 3405fdd124a3b811993542825847f207587d5f4661eJens Axboe 341b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboestatic int fio_netio_setup_listen(struct thread_data *td, short port) 342ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe{ 343b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe struct netio_data *nd = td->io_ops->data; 3445fdd124a3b811993542825847f207587d5f4661eJens Axboe int fd, opt; 345ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 3466bedbfafcffbc7202b5bb621ac5886aafdc0f362Jens Axboe fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 347ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe if (fd < 0) { 348e1161c325f7866bae879e686d1c673ca32ab09aeJens Axboe td_verror(td, errno, "socket"); 349ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe return 1; 350ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe } 351ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 352ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe opt = 1; 353ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) { 354e1161c325f7866bae879e686d1c673ca32ab09aeJens Axboe td_verror(td, errno, "setsockopt"); 355ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe return 1; 356ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe } 3576bedbfafcffbc7202b5bb621ac5886aafdc0f362Jens Axboe#ifdef SO_REUSEPORT 3586bedbfafcffbc7202b5bb621ac5886aafdc0f362Jens Axboe if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &opt, sizeof(opt)) < 0) { 359e1161c325f7866bae879e686d1c673ca32ab09aeJens Axboe td_verror(td, errno, "setsockopt"); 3606bedbfafcffbc7202b5bb621ac5886aafdc0f362Jens Axboe return 1; 3616bedbfafcffbc7202b5bb621ac5886aafdc0f362Jens Axboe } 3626bedbfafcffbc7202b5bb621ac5886aafdc0f362Jens Axboe#endif 363ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 364b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe nd->addr.sin_family = AF_INET; 365b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe nd->addr.sin_addr.s_addr = htonl(INADDR_ANY); 366b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe nd->addr.sin_port = htons(port); 367ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 368b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe if (bind(fd, (struct sockaddr *) &nd->addr, sizeof(nd->addr)) < 0) { 369e1161c325f7866bae879e686d1c673ca32ab09aeJens Axboe td_verror(td, errno, "bind"); 370ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe return 1; 371ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe } 372ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe if (listen(fd, 1) < 0) { 373e1161c325f7866bae879e686d1c673ca32ab09aeJens Axboe td_verror(td, errno, "listen"); 374ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe return 1; 375ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe } 376ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 377b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe nd->listenfd = fd; 378b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe return 0; 379ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe} 380ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 3819bec88e15aad76c16ac65048270ecac8b5956a61Jens Axboestatic int fio_netio_init(struct thread_data *td) 382ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe{ 383b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe struct netio_data *nd = td->io_ops->data; 384e01547d2b8bf79c3abe14e03c72398cf8998eb1eJens Axboe unsigned short port; 385b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe char host[64], buf[128]; 386ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe char *sep; 387af52b3455ad892322aab2791282b6bd4efdfdbf3Jens Axboe int ret; 388ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 389413dd459a7710ba421061e840dd9ac3161c70f20Jens Axboe if (td_rw(td)) { 390ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe log_err("fio: network connections must be read OR write\n"); 391ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe return 1; 392ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe } 39316d55aae770b8b1a966d4b4a814918ce49a76ba3Jens Axboe if (td_random(td)) { 39416d55aae770b8b1a966d4b4a814918ce49a76ba3Jens Axboe log_err("fio: network IO can't be random\n"); 39516d55aae770b8b1a966d4b4a814918ce49a76ba3Jens Axboe return 1; 39616d55aae770b8b1a966d4b4a814918ce49a76ba3Jens Axboe } 397ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 3982dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe strcpy(buf, td->o.filename); 399ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 4009f9214f243701626a04b4a0f9aceec03b8b40e0fJens Axboe sep = strchr(buf, '/'); 401ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe if (!sep) { 4022dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe log_err("fio: bad network host/port <<%s>>\n", td->o.filename); 403ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe return 1; 404ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe } 405ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 406ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe *sep = '\0'; 407ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe sep++; 408ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe strcpy(host, buf); 409e01547d2b8bf79c3abe14e03c72398cf8998eb1eJens Axboe port = atoi(sep); 410ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 411413dd459a7710ba421061e840dd9ac3161c70f20Jens Axboe if (td_read(td)) { 412b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe nd->send_to_net = 0; 413ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe ret = fio_netio_setup_listen(td, port); 414ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe } else { 415b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe nd->send_to_net = 1; 416ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe ret = fio_netio_setup_connect(td, host, port); 417ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe } 418ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 4197bb48f84ac78cac1f90e3e04d0220d90d6a64a6bJens Axboe return ret; 420ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe} 421ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 422b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboestatic void fio_netio_cleanup(struct thread_data *td) 4239bec88e15aad76c16ac65048270ecac8b5956a61Jens Axboe{ 424b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe struct netio_data *nd = td->io_ops->data; 425b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe 426b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe if (nd) { 42764b24cd8a5ea87bccec60e0236d93071480201e7Jens Axboe if (nd->listenfd != -1) 42864b24cd8a5ea87bccec60e0236d93071480201e7Jens Axboe close(nd->listenfd); 42964b24cd8a5ea87bccec60e0236d93071480201e7Jens Axboe if (nd->pipes[0] != -1) 43064b24cd8a5ea87bccec60e0236d93071480201e7Jens Axboe close(nd->pipes[0]); 43164b24cd8a5ea87bccec60e0236d93071480201e7Jens Axboe if (nd->pipes[1] != -1) 43264b24cd8a5ea87bccec60e0236d93071480201e7Jens Axboe close(nd->pipes[1]); 43364b24cd8a5ea87bccec60e0236d93071480201e7Jens Axboe 434b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe free(nd); 435b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe td->io_ops->data = NULL; 436b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe } 437b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe} 438b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe 439b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboestatic int fio_netio_setup(struct thread_data *td) 440b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe{ 4417bb48f84ac78cac1f90e3e04d0220d90d6a64a6bJens Axboe struct netio_data *nd; 4427bb48f84ac78cac1f90e3e04d0220d90d6a64a6bJens Axboe 4437bb48f84ac78cac1f90e3e04d0220d90d6a64a6bJens Axboe if (!td->io_ops->data) { 4447bb48f84ac78cac1f90e3e04d0220d90d6a64a6bJens Axboe nd = malloc(sizeof(*nd));; 4457bb48f84ac78cac1f90e3e04d0220d90d6a64a6bJens Axboe 4467bb48f84ac78cac1f90e3e04d0220d90d6a64a6bJens Axboe memset(nd, 0, sizeof(*nd)); 4477bb48f84ac78cac1f90e3e04d0220d90d6a64a6bJens Axboe nd->listenfd = -1; 44864b24cd8a5ea87bccec60e0236d93071480201e7Jens Axboe nd->pipes[0] = nd->pipes[1] = -1; 4497bb48f84ac78cac1f90e3e04d0220d90d6a64a6bJens Axboe td->io_ops->data = nd; 4507bb48f84ac78cac1f90e3e04d0220d90d6a64a6bJens Axboe } 451b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe 4529bec88e15aad76c16ac65048270ecac8b5956a61Jens Axboe return 0; 4539bec88e15aad76c16ac65048270ecac8b5956a61Jens Axboe} 4549bec88e15aad76c16ac65048270ecac8b5956a61Jens Axboe 4559cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboestatic int fio_netio_setup_splice(struct thread_data *td) 4569cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe{ 4579cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe struct netio_data *nd; 4589cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 4599cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe fio_netio_setup(td); 4609cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 4619cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe nd = td->io_ops->data; 4629cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe if (nd) { 4639cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe if (pipe(nd->pipes) < 0) 4649cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe return 1; 4659cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 4669cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe nd->use_splice = 1; 4679cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe return 0; 4689cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe } 4699cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 4709cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe return 1; 4719cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe} 4729cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 4739cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboestatic struct ioengine_ops ioengine_rw = { 474ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe .name = "net", 475ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe .version = FIO_IOOPS_VERSION, 476ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe .prep = fio_netio_prep, 477ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe .queue = fio_netio_queue, 478ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe .setup = fio_netio_setup, 4799bec88e15aad76c16ac65048270ecac8b5956a61Jens Axboe .init = fio_netio_init, 480b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe .cleanup = fio_netio_cleanup, 481b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe .open_file = fio_netio_open_file, 482b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe .close_file = generic_close_file, 483b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe .flags = FIO_SYNCIO | FIO_DISKLESSIO, 484ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe}; 485ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 4869cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboestatic struct ioengine_ops ioengine_splice = { 4879cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe .name = "netsplice", 4889cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe .version = FIO_IOOPS_VERSION, 4899cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe .prep = fio_netio_prep, 4909cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe .queue = fio_netio_queue, 4919cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe .setup = fio_netio_setup_splice, 4929cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe .init = fio_netio_init, 4939cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe .cleanup = fio_netio_cleanup, 4949cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe .open_file = fio_netio_open_file, 4959cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe .close_file = generic_close_file, 4969cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe .flags = FIO_SYNCIO | FIO_DISKLESSIO, 4979cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe}; 4989cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 499ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboestatic void fio_init fio_netio_register(void) 500ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe{ 5019cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe register_ioengine(&ioengine_rw); 5029cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe register_ioengine(&ioengine_splice); 503ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe} 504ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 505ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboestatic void fio_exit fio_netio_unregister(void) 506ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe{ 5079cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe unregister_ioengine(&ioengine_rw); 5089cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe unregister_ioengine(&ioengine_splice); 509ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe} 510