X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=client.c;h=a61bc803b4267708a7f1f8affe160f9154256ac5;hp=fb678e177363c7b5a5fb4d1438627dc15653a92e;hb=811826be429fd6fc5154d9b04ced1cd22bd66758;hpb=01be038efc66ea1b49b4471f2ba9dd2d7121cfe7 diff --git a/client.c b/client.c index fb678e17..a61bc803 100644 --- a/client.c +++ b/client.c @@ -29,8 +29,11 @@ struct fio_client { struct flist_head list; struct flist_head hash_list; struct flist_head arg_list; - struct sockaddr_in addr; - struct sockaddr_un addr_un; + union { + struct sockaddr_in addr; + struct sockaddr_in6 addr6; + struct sockaddr_un addr_un; + }; char *hostname; int port; int fd; @@ -42,6 +45,9 @@ struct fio_client { int skip_newline; int is_sock; int disk_stats_shown; + unsigned int jobs; + int error; + int ipv6; struct flist_head eta_list; struct client_eta *eta_in_flight; @@ -202,7 +208,9 @@ int fio_client_add(const char *hostname, void **cookie) if (fio_server_parse_string(hostname, &client->hostname, &client->is_sock, &client->port, - &client->addr.sin_addr)) + &client->addr.sin_addr, + &client->addr6.sin6_addr, + &client->ipv6)) return -1; client->fd = -1; @@ -218,18 +226,31 @@ int fio_client_add(const char *hostname, void **cookie) static int fio_client_connect_ip(struct fio_client *client) { - int fd; - - client->addr.sin_family = AF_INET; - client->addr.sin_port = htons(client->port); + struct sockaddr *addr; + fio_socklen_t socklen; + int fd, domain; + + if (client->ipv6) { + client->addr6.sin6_family = AF_INET6; + client->addr6.sin6_port = htons(client->port); + domain = AF_INET6; + addr = (struct sockaddr *) &client->addr6; + socklen = sizeof(client->addr6); + } else { + client->addr.sin_family = AF_INET; + client->addr.sin_port = htons(client->port); + domain = AF_INET; + addr = (struct sockaddr *) &client->addr; + socklen = sizeof(client->addr); + } - fd = socket(AF_INET, SOCK_STREAM, 0); + fd = socket(domain, SOCK_STREAM, 0); if (fd < 0) { log_err("fio: socket: %s\n", strerror(errno)); return -1; } - if (connect(fd, (struct sockaddr *) &client->addr, sizeof(client->addr)) < 0) { + if (connect(fd, addr, socklen) < 0) { log_err("fio: connect: %s\n", strerror(errno)); log_err("fio: failed to connect to %s:%u\n", client->hostname, client->port); @@ -770,6 +791,25 @@ static void handle_probe(struct fio_client *client, struct fio_net_cmd *cmd) client->name = strdup((char *) probe->hostname); } +static void handle_start(struct fio_client *client, struct fio_net_cmd *cmd) +{ + struct cmd_start_pdu *pdu = (struct cmd_start_pdu *) cmd->payload; + + client->state = Client_started; + client->jobs = le32_to_cpu(pdu->jobs); +} + +static void handle_stop(struct fio_client *client, struct fio_net_cmd *cmd) +{ + struct cmd_end_pdu *pdu = (struct cmd_end_pdu *) cmd->payload; + + client->state = Client_stopped; + client->error = le32_to_cpu(pdu->error); + + if (client->error) + log_info("client <%s>: exited with error %d\n", client->hostname, client->error); +} + static int handle_client(struct fio_client *client) { struct fio_net_cmd *cmd; @@ -830,11 +870,11 @@ static int handle_client(struct fio_client *client) free(cmd); break; case FIO_NET_CMD_START: - client->state = Client_started; + handle_start(client, cmd); free(cmd); break; case FIO_NET_CMD_STOP: - client->state = Client_stopped; + handle_stop(client, cmd); free(cmd); break; default: @@ -936,7 +976,7 @@ int fio_handle_clients(void) struct fio_client *client; struct flist_head *entry; struct pollfd *pfds; - int i, ret = 0; + int i, ret = 0, retval = 0; gettimeofday(&eta_tv, NULL); @@ -993,10 +1033,12 @@ int fio_handle_clients(void) log_info("client: host=%s disconnected\n", client->hostname); remove_client(client); - } + retval = 1; + } else if (client->error) + retval = 1; } } free(pfds); - return 0; + return retval; }