posixaio engine: residual data count
[fio.git] / engines / net.c
index 381c731c9bf3892c9261aabcb45bf0d5812f21a2..2381f7390ea3d0d9934599409ce6ddbadb4ab5b1 100644 (file)
@@ -25,7 +25,7 @@ static int fio_netio_prep(struct thread_data *td, struct io_u *io_u)
         */
        if ((send_to_net(td) && io_u->ddir == DDIR_READ) ||
            (!send_to_net(td) && io_u->ddir == DDIR_WRITE)) {
-               td_verror(td, EINVAL);
+               td_verror(td, EINVAL, "bad direction");
                return 1;
        }
                
@@ -38,7 +38,7 @@ static int fio_netio_prep(struct thread_data *td, struct io_u *io_u)
         * If offset is different from last end position, it's a seek.
         * As network io is purely sequential, we don't allow seeks.
         */
-       td_verror(td, EINVAL);
+       td_verror(td, EINVAL, "cannot seek");
        return 1;
 }
 
@@ -72,7 +72,7 @@ static int fio_netio_queue(struct thread_data *td, struct io_u *io_u)
        }
 
        if (io_u->error)
-               td_verror(td, io_u->error);
+               td_verror(td, io_u->error, "xfer");
 
        return FIO_Q_COMPLETED;
 }
@@ -93,7 +93,7 @@ static int fio_netio_setup_connect(struct thread_data *td, const char *host,
 
                hent = gethostbyname(host);
                if (!hent) {
-                       td_verror(td, errno);
+                       td_verror(td, errno, "gethostbyname");
                        return 1;
                }
 
@@ -103,12 +103,12 @@ static int fio_netio_setup_connect(struct thread_data *td, const char *host,
        for_each_file(td, f, i) {
                f->fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
                if (f->fd < 0) {
-                       td_verror(td, errno);
+                       td_verror(td, errno, "socket");
                        return 1;
                }
 
                if (connect(f->fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
-                       td_verror(td, errno);
+                       td_verror(td, errno, "connect");
                        return 1;
                }
        }
@@ -142,7 +142,7 @@ static int fio_netio_accept_connections(struct thread_data *td, int fd,
                        if (errno == EINTR)
                                continue;
 
-                       td_verror(td, errno);
+                       td_verror(td, errno, "poll");
                        break;
                } else if (!ret)
                        continue;
@@ -159,7 +159,7 @@ static int fio_netio_accept_connections(struct thread_data *td, int fd,
 
                        f->fd = accept(fd, (struct sockaddr *) addr, &socklen);
                        if (f->fd < 0) {
-                               td_verror(td, errno);
+                               td_verror(td, errno, "accept");
                                return 1;
                        }
                        accepts++;
@@ -177,18 +177,18 @@ static int fio_netio_setup_listen(struct thread_data *td, unsigned short port)
 
        fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
        if (fd < 0) {
-               td_verror(td, errno);
+               td_verror(td, errno, "socket");
                return 1;
        }
 
        opt = 1;
        if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) {
-               td_verror(td, errno);
+               td_verror(td, errno, "setsockopt");
                return 1;
        }
 #ifdef SO_REUSEPORT
        if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &opt, sizeof(opt)) < 0) {
-               td_verror(td, errno);
+               td_verror(td, errno, "setsockopt");
                return 1;
        }
 #endif
@@ -199,18 +199,18 @@ static int fio_netio_setup_listen(struct thread_data *td, unsigned short port)
        addr.sin_port = htons(port);
 
        if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
-               td_verror(td, errno);
+               td_verror(td, errno, "bind");
                return 1;
        }
        if (listen(fd, 1) < 0) {
-               td_verror(td, errno);
+               td_verror(td, errno, "listen");
                return 1;
        }
 
        return fio_netio_accept_connections(td, fd, &addr);
 }
 
-static int fio_netio_setup(struct thread_data *td)
+static int fio_netio_init(struct thread_data *td)
 {
        char host[64], buf[128];
        unsigned short port;
@@ -223,7 +223,7 @@ static int fio_netio_setup(struct thread_data *td)
                return 1;
        }
 
-       if (td->iomix) {
+       if (td_rw(td)) {
                log_err("fio: network connections must be read OR write\n");
                return 1;
        }
@@ -241,7 +241,7 @@ static int fio_netio_setup(struct thread_data *td)
        strcpy(host, buf);
        port = atoi(sep);
 
-       if (td->ddir == DDIR_READ) {
+       if (td_read(td)) {
                send_to_net(td) = 0;
                ret = fio_netio_setup_listen(td, port);
        } else {
@@ -260,6 +260,12 @@ static int fio_netio_setup(struct thread_data *td)
                f->real_file_size = f->file_size;
        }
 
+       td->nr_open_files = td->nr_files;
+       return 0;
+}
+
+static int fio_netio_setup(struct thread_data fio_unused *td)
+{
        return 0;
 }
 
@@ -269,7 +275,8 @@ static struct ioengine_ops ioengine = {
        .prep           = fio_netio_prep,
        .queue          = fio_netio_queue,
        .setup          = fio_netio_setup,
-       .flags          = FIO_SYNCIO | FIO_NETIO,
+       .init           = fio_netio_init,
+       .flags          = FIO_SYNCIO | FIO_DISKLESSIO | FIO_SELFOPEN,
 };
 
 static void fio_init fio_netio_register(void)