X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=engines%2Fnet.c;h=43026e5f747469c50093587d234732f874e801fe;hp=8ef781103462ce4af9dcf2e9644ddc1e937550e6;hb=cec6b55da1c282b5b91ad346c7804171fccf151e;hpb=ed92ac0ce9ce1cc64697272d307d4fa7d18ed64c diff --git a/engines/net.c b/engines/net.c index 8ef78110..43026e5f 100644 --- a/engines/net.c +++ b/engines/net.c @@ -65,6 +65,10 @@ static int fio_netio_prep(struct thread_data *td, struct io_u *io_u) if (io_u->offset == f->last_completed_pos) return 0; + /* + * 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); return 1; } @@ -73,17 +77,18 @@ static int fio_netio_queue(struct thread_data *td, struct io_u *io_u) { struct net_data *nd = td->io_ops->data; struct fio_file *f = io_u->file; - unsigned int ret = 0; + int ret = 0; if (io_u->ddir == DDIR_WRITE) - ret = write(f->fd, io_u->buf, io_u->buflen); + ret = write(f->fd, io_u->xfer_buf, io_u->xfer_buflen); else if (io_u->ddir == DDIR_READ) - ret = read(f->fd, io_u->buf, io_u->buflen); + ret = read(f->fd, io_u->xfer_buf, io_u->xfer_buflen); - if (ret != io_u->buflen) { + if (ret != (int) io_u->xfer_buflen) { if (ret > 0) { - io_u->resid = io_u->buflen - ret; - io_u->error = EIO; + io_u->resid = io_u->xfer_buflen - ret; + io_u->error = 0; + return ret; } else io_u->error = errno; } @@ -95,14 +100,15 @@ static int fio_netio_queue(struct thread_data *td, struct io_u *io_u) } static int fio_netio_setup_connect(struct thread_data *td, const char *host, - const char *port) + unsigned short port) { struct sockaddr_in addr; struct fio_file *f; + int i; memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; - addr.sin_port = htons(atoi(port)); + addr.sin_port = htons(port); if (inet_aton(host, &addr.sin_addr) != 1) { struct hostent *hent = gethostbyname(host); @@ -115,28 +121,29 @@ static int fio_netio_setup_connect(struct thread_data *td, const char *host, memcpy(&addr.sin_addr, hent->h_addr, 4); } - f = &td->files[0]; - - f->fd = socket(AF_INET, SOCK_STREAM, 0); - if (f->fd < 0) { - td_vmsg(td, errno, "socket"); - return 1; - } + for_each_file(td, f, i) { + f->fd = socket(AF_INET, SOCK_STREAM, 0); + if (f->fd < 0) { + td_vmsg(td, errno, "socket"); + return 1; + } - if (connect(f->fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) { - td_vmsg(td, errno, "connect"); - return 1; + if (connect(f->fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) { + td_vmsg(td, errno, "connect"); + return 1; + } } return 0; } -static int fio_netio_setup_listen(struct thread_data *td, const char *port) +static int fio_netio_setup_listen(struct thread_data *td, unsigned short port) { struct sockaddr_in addr; socklen_t socklen; - int fd, opt; + struct fio_file *f; + int fd, opt, i; fd = socket(AF_INET, SOCK_STREAM, 0); if (fd < 0) { @@ -153,7 +160,7 @@ static int fio_netio_setup_listen(struct thread_data *td, const char *port) memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl(INADDR_ANY); - addr.sin_port = htons(atoi(port)); + addr.sin_port = htons(port); if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) { td_vmsg(td, errno, "bind"); @@ -164,11 +171,15 @@ static int fio_netio_setup_listen(struct thread_data *td, const char *port) return 1; } + fprintf(f_out, "fio: waiting for %u connections\n", td->nr_files); + socklen = sizeof(addr); - td->files[0].fd = accept(fd, (struct sockaddr *) &addr, &socklen); - if (td->files[0].fd < 0) { - td_vmsg(td, errno, "accept"); - return 1; + for_each_file(td, f, i) { + f->fd = accept(fd, (struct sockaddr *) &addr, &socklen); + if (f->fd < 0) { + td_vmsg(td, errno, "accept"); + return 1; + } } return 0; @@ -176,10 +187,12 @@ static int fio_netio_setup_listen(struct thread_data *td, const char *port) static int fio_netio_setup(struct thread_data *td) { - char host[64], port[64], buf[128]; + char host[64], buf[128]; struct net_data *nd; + unsigned short port; + struct fio_file *f; char *sep; - int ret; + int ret, i; /* * work around for late init call @@ -193,10 +206,6 @@ static int fio_netio_setup(struct thread_data *td) log_err("fio: network connections must be read OR write\n"); return 1; } - if (td->nr_files > 1) { - log_err("fio: only one file supported for network\n"); - return 1; - } strcpy(buf, td->filename); @@ -209,7 +218,7 @@ static int fio_netio_setup(struct thread_data *td) *sep = '\0'; sep++; strcpy(host, buf); - strcpy(port, sep); + port = atoi(sep); if (td->ddir == READ) { nd->send_to_net = 0; @@ -219,13 +228,18 @@ static int fio_netio_setup(struct thread_data *td) ret = fio_netio_setup_connect(td, host, port); } - if (!ret) { - td->io_size = td->total_file_size; - td->total_io_size = td->io_size; - td->files[0].real_file_size = td->io_size; + if (ret) + return ret; + + td->io_size = td->total_file_size; + td->total_io_size = td->io_size; + + for_each_file(td, f, i) { + f->file_size = td->total_file_size / td->nr_files; + f->real_file_size = f->file_size; } - return ret; + return 0; } static void fio_netio_cleanup(struct thread_data *td) @@ -240,6 +254,10 @@ static int fio_netio_init(struct thread_data *td) { struct net_data *nd; + /* + * Hack to work-around the ->setup() function calling init on its + * own, since it needs ->io_ops->data to be set up. + */ if (td->io_ops->data) return 0;