X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=client.c;h=5545a8a90a9982f87af5ca73515daaf848a5c1b1;hb=6433ee054a5dc6533066e105baee4ff85197d392;hp=225f6643e5aaa0ec283f35f8903415789debb3b7;hpb=9988ca70151a191c477179be7999300ddff16230;p=fio.git diff --git a/client.c b/client.c index 225f6643..5545a8a9 100644 --- a/client.c +++ b/client.c @@ -36,6 +36,7 @@ struct client_ops fio_client_ops = { .stop = handle_stop, .eta = display_thread_status, .probe = handle_probe, + .eta_msec = FIO_CLIENT_DEF_ETA_MSEC, }; static struct timeval eta_tv; @@ -87,10 +88,8 @@ static struct fio_client *find_client_by_fd(int fd) flist_for_each(entry, &client_hash[bucket]) { client = flist_entry(entry, struct fio_client, hash_list); - if (client->fd == fd) { - client->refs++; - return client; - } + if (client->fd == fd) + return fio_get_client(client); } return NULL; @@ -124,11 +123,17 @@ static void remove_client(struct fio_client *client) sum_stat_clients--; } -static void put_client(struct fio_client *client) +void fio_put_client(struct fio_client *client) { remove_client(client); } +struct fio_client *fio_get_client(struct fio_client *client) +{ + client->refs++; + return client; +} + static void __fio_client_add_cmd_option(struct fio_client *client, const char *opt) { @@ -253,6 +258,13 @@ int fio_client_add(struct client_ops *ops, const char *hostname, void **cookie) return 0; } +static void probe_client(struct fio_client *client) +{ + dprint(FD_NET, "client: send probe\n"); + + fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_PROBE, 0, &client->cmd_list); +} + static int fio_client_connect_ip(struct fio_client *client) { struct sockaddr *addr; @@ -275,16 +287,20 @@ static int fio_client_connect_ip(struct fio_client *client) fd = socket(domain, SOCK_STREAM, 0); if (fd < 0) { + int ret = -errno; + log_err("fio: socket: %s\n", strerror(errno)); - return -1; + return ret; } if (connect(fd, addr, socklen) < 0) { + int ret = -errno; + log_err("fio: connect: %s\n", strerror(errno)); log_err("fio: failed to connect to %s:%u\n", client->hostname, client->port); close(fd); - return -1; + return ret; } return fd; @@ -302,15 +318,19 @@ static int fio_client_connect_sock(struct fio_client *client) fd = socket(AF_UNIX, SOCK_STREAM, 0); if (fd < 0) { + int ret = -errno; + log_err("fio: socket: %s\n", strerror(errno)); - return -1; + return ret; } len = sizeof(addr->sun_family) + strlen(addr->sun_path) + 1; if (connect(fd, (struct sockaddr *) addr, len) < 0) { + int ret = -errno; + log_err("fio: connect; %s\n", strerror(errno)); close(fd); - return -1; + return ret; } return fd; @@ -330,11 +350,13 @@ int fio_client_connect(struct fio_client *client) dprint(FD_NET, "client: %s connected %d\n", client->hostname, fd); if (fd < 0) - return 1; + return fd; client->fd = fd; fio_client_add_hash(client); client->state = Client_connected; + + probe_client(client); return 0; } @@ -377,13 +399,6 @@ static void client_signal_handler(void) sigaction(SIGTERM, &act, NULL); } -static void probe_client(struct fio_client *client) -{ - dprint(FD_NET, "client: send probe\n"); - - fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_PROBE, 0, &client->cmd_list); -} - static int send_client_cmd_line(struct fio_client *client) { struct cmd_single_line_pdu *cslp; @@ -455,8 +470,6 @@ int fio_clients_connect(void) continue; } - probe_client(client); - if (client->argc > 1) send_client_cmd_line(client); } @@ -506,14 +519,18 @@ static int __fio_client_send_ini(struct fio_client *client, const char *filename fd = open(filename, O_RDONLY); if (fd < 0) { + int ret = -errno; + log_err("fio: job file <%s> open: %s\n", filename, strerror(errno)); - return 1; + return ret; } if (fstat(fd, &sb) < 0) { + int ret = -errno; + log_err("fio: job file stat: %s\n", strerror(errno)); close(fd); - return 1; + return ret; } buf = malloc(sb.st_size); @@ -550,13 +567,16 @@ static int __fio_client_send_ini(struct fio_client *client, const char *filename int fio_client_send_ini(struct fio_client *client, const char *filename) { - if (__fio_client_send_ini(client, filename)) { + int ret; + + ret = __fio_client_send_ini(client, filename); + if (ret) { remove_client(client); - return 1; + return ret; } client->sent_job = 1; - return 0; + return ret; } int fio_clients_send_ini(const char *filename) @@ -1144,7 +1164,7 @@ int fio_handle_clients(struct client_ops *ops) struct timeval tv; gettimeofday(&tv, NULL); - if (mtime_since(&eta_tv, &tv) >= 900) { + if (mtime_since(&eta_tv, &tv) >= ops->eta_msec) { request_client_etas(ops); memcpy(&eta_tv, &tv, sizeof(tv)); @@ -1178,7 +1198,7 @@ int fio_handle_clients(struct client_ops *ops) retval = 1; } else if (client->error) retval = 1; - put_client(client); + fio_put_client(client); } }