11 #include <sys/socket.h>
13 #include <netinet/in.h>
14 #include <arpa/inet.h>
29 struct flist_head list;
30 struct flist_head hash_list;
31 struct flist_head arg_list;
33 struct sockaddr_in addr;
34 struct sockaddr_in6 addr6;
35 struct sockaddr_un addr_un;
54 struct flist_head eta_list;
55 struct client_eta *eta_in_flight;
57 struct flist_head cmd_list;
63 static struct timeval eta_tv;
74 static FLIST_HEAD(client_list);
75 static FLIST_HEAD(eta_list);
77 static FLIST_HEAD(arg_list);
79 static struct thread_stat client_ts;
80 static struct group_run_stats client_gs;
81 static int sum_stat_clients;
82 static int sum_stat_nr;
84 #define FIO_CLIENT_HASH_BITS 7
85 #define FIO_CLIENT_HASH_SZ (1 << FIO_CLIENT_HASH_BITS)
86 #define FIO_CLIENT_HASH_MASK (FIO_CLIENT_HASH_SZ - 1)
87 static struct flist_head client_hash[FIO_CLIENT_HASH_SZ];
89 static int handle_client(struct fio_client *client);
90 static void dec_jobs_eta(struct client_eta *eta);
92 static void fio_client_add_hash(struct fio_client *client)
94 int bucket = hash_long(client->fd, FIO_CLIENT_HASH_BITS);
96 bucket &= FIO_CLIENT_HASH_MASK;
97 flist_add(&client->hash_list, &client_hash[bucket]);
100 static void fio_client_remove_hash(struct fio_client *client)
102 if (!flist_empty(&client->hash_list))
103 flist_del_init(&client->hash_list);
106 static void fio_init fio_client_hash_init(void)
110 for (i = 0; i < FIO_CLIENT_HASH_SZ; i++)
111 INIT_FLIST_HEAD(&client_hash[i]);
114 static struct fio_client *find_client_by_fd(int fd)
116 int bucket = hash_long(fd, FIO_CLIENT_HASH_BITS) & FIO_CLIENT_HASH_MASK;
117 struct fio_client *client;
118 struct flist_head *entry;
120 flist_for_each(entry, &client_hash[bucket]) {
121 client = flist_entry(entry, struct fio_client, hash_list);
123 if (client->fd == fd) {
132 static void remove_client(struct fio_client *client)
134 assert(client->refs);
139 dprint(FD_NET, "client: removed <%s>\n", client->hostname);
140 flist_del(&client->list);
142 fio_client_remove_hash(client);
144 if (!flist_empty(&client->eta_list)) {
145 flist_del_init(&client->eta_list);
146 dec_jobs_eta(client->eta_in_flight);
149 free(client->hostname);
160 static void put_client(struct fio_client *client)
162 remove_client(client);
165 static void __fio_client_add_cmd_option(struct fio_client *client,
170 index = client->argc++;
171 client->argv = realloc(client->argv, sizeof(char *) * client->argc);
172 client->argv[index] = strdup(opt);
173 dprint(FD_NET, "client: add cmd %d: %s\n", index, opt);
176 void fio_client_add_cmd_option(void *cookie, const char *opt)
178 struct fio_client *client = cookie;
179 struct flist_head *entry;
184 __fio_client_add_cmd_option(client, opt);
187 * Duplicate arguments to shared client group
189 flist_for_each(entry, &arg_list) {
190 client = flist_entry(entry, struct fio_client, arg_list);
192 __fio_client_add_cmd_option(client, opt);
196 int fio_client_add(const char *hostname, void **cookie)
198 struct fio_client *existing = *cookie;
199 struct fio_client *client;
203 * We always add our "exec" name as the option, hence 1
206 if (existing->argc == 1)
207 flist_add_tail(&existing->arg_list, &arg_list);
209 while (!flist_empty(&arg_list))
210 flist_del_init(arg_list.next);
214 client = malloc(sizeof(*client));
215 memset(client, 0, sizeof(*client));
217 INIT_FLIST_HEAD(&client->list);
218 INIT_FLIST_HEAD(&client->hash_list);
219 INIT_FLIST_HEAD(&client->arg_list);
220 INIT_FLIST_HEAD(&client->eta_list);
221 INIT_FLIST_HEAD(&client->cmd_list);
223 if (fio_server_parse_string(hostname, &client->hostname,
224 &client->is_sock, &client->port,
225 &client->addr.sin_addr,
226 &client->addr6.sin6_addr,
233 __fio_client_add_cmd_option(client, "fio");
235 flist_add(&client->list, &client_list);
237 dprint(FD_NET, "client: added <%s>\n", client->hostname);
242 static int fio_client_connect_ip(struct fio_client *client)
244 struct sockaddr *addr;
245 fio_socklen_t socklen;
249 client->addr6.sin6_family = AF_INET6;
250 client->addr6.sin6_port = htons(client->port);
252 addr = (struct sockaddr *) &client->addr6;
253 socklen = sizeof(client->addr6);
255 client->addr.sin_family = AF_INET;
256 client->addr.sin_port = htons(client->port);
258 addr = (struct sockaddr *) &client->addr;
259 socklen = sizeof(client->addr);
262 fd = socket(domain, SOCK_STREAM, 0);
264 log_err("fio: socket: %s\n", strerror(errno));
268 if (connect(fd, addr, socklen) < 0) {
269 log_err("fio: connect: %s\n", strerror(errno));
270 log_err("fio: failed to connect to %s:%u\n", client->hostname,
279 static int fio_client_connect_sock(struct fio_client *client)
281 struct sockaddr_un *addr = &client->addr_un;
285 memset(addr, 0, sizeof(*addr));
286 addr->sun_family = AF_UNIX;
287 strcpy(addr->sun_path, client->hostname);
289 fd = socket(AF_UNIX, SOCK_STREAM, 0);
291 log_err("fio: socket: %s\n", strerror(errno));
295 len = sizeof(addr->sun_family) + strlen(addr->sun_path) + 1;
296 if (connect(fd, (struct sockaddr *) addr, len) < 0) {
297 log_err("fio: connect; %s\n", strerror(errno));
305 static int fio_client_connect(struct fio_client *client)
309 dprint(FD_NET, "client: connect to host %s\n", client->hostname);
312 fd = fio_client_connect_sock(client);
314 fd = fio_client_connect_ip(client);
316 dprint(FD_NET, "client: %s connected %d\n", client->hostname, fd);
322 fio_client_add_hash(client);
323 client->state = Client_connected;
327 void fio_clients_terminate(void)
329 struct flist_head *entry;
330 struct fio_client *client;
332 dprint(FD_NET, "client: terminate clients\n");
334 flist_for_each(entry, &client_list) {
335 client = flist_entry(entry, struct fio_client, list);
337 fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_QUIT, 0, NULL);
341 static void sig_int(int sig)
343 dprint(FD_NET, "client: got signal %d\n", sig);
344 fio_clients_terminate();
347 static void sig_show_status(int sig)
349 show_running_run_stats();
352 static void client_signal_handler(void)
354 struct sigaction act;
356 memset(&act, 0, sizeof(act));
357 act.sa_handler = sig_int;
358 act.sa_flags = SA_RESTART;
359 sigaction(SIGINT, &act, NULL);
361 memset(&act, 0, sizeof(act));
362 act.sa_handler = sig_int;
363 act.sa_flags = SA_RESTART;
364 sigaction(SIGTERM, &act, NULL);
366 memset(&act, 0, sizeof(act));
367 act.sa_handler = sig_show_status;
368 act.sa_flags = SA_RESTART;
369 sigaction(SIGUSR1, &act, NULL);
372 static void probe_client(struct fio_client *client)
374 dprint(FD_NET, "client: send probe\n");
376 fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_PROBE, 0, &client->cmd_list);
379 static int send_client_cmd_line(struct fio_client *client)
381 struct cmd_single_line_pdu *cslp;
382 struct cmd_line_pdu *clp;
383 unsigned long offset;
389 dprint(FD_NET, "client: send cmdline %d\n", client->argc);
391 lens = malloc(client->argc * sizeof(unsigned int));
394 * Find out how much mem we need
396 for (i = 0, mem = 0; i < client->argc; i++) {
397 lens[i] = strlen(client->argv[i]) + 1;
402 * We need one cmd_line_pdu, and argc number of cmd_single_line_pdu
404 mem += sizeof(*clp) + (client->argc * sizeof(*cslp));
408 offset = sizeof(*clp);
410 for (i = 0; i < client->argc; i++) {
411 uint16_t arg_len = lens[i];
414 strcpy((char *) cslp->text, client->argv[i]);
415 cslp->len = cpu_to_le16(arg_len);
416 offset += sizeof(*cslp) + arg_len;
420 clp->lines = cpu_to_le16(client->argc);
421 ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOBLINE, pdu, mem, 0);
426 int fio_clients_connect(void)
428 struct fio_client *client;
429 struct flist_head *entry, *tmp;
434 WSAStartup(MAKEWORD(2,2), &wsd);
437 dprint(FD_NET, "client: connect all\n");
439 client_signal_handler();
441 flist_for_each_safe(entry, tmp, &client_list) {
442 client = flist_entry(entry, struct fio_client, list);
444 ret = fio_client_connect(client);
446 remove_client(client);
450 probe_client(client);
452 if (client->argc > 1)
453 send_client_cmd_line(client);
460 * Send file contents to server backend. We could use sendfile(), but to remain
461 * more portable lets just read/write the darn thing.
463 static int fio_client_send_ini(struct fio_client *client, const char *filename)
470 dprint(FD_NET, "send ini %s to %s\n", filename, client->hostname);
472 fd = open(filename, O_RDONLY);
474 log_err("fio: job file <%s> open: %s\n", filename, strerror(errno));
478 if (fstat(fd, &sb) < 0) {
479 log_err("fio: job file stat: %s\n", strerror(errno));
484 buf = malloc(sb.st_size);
489 ret = read(fd, p, len);
498 else if (errno == EAGAIN || errno == EINTR)
503 log_err("fio: failed reading job file %s\n", filename);
509 client->sent_job = 1;
510 ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOB, buf, sb.st_size, 0);
516 int fio_clients_send_ini(const char *filename)
518 struct fio_client *client;
519 struct flist_head *entry, *tmp;
521 flist_for_each_safe(entry, tmp, &client_list) {
522 client = flist_entry(entry, struct fio_client, list);
524 if (fio_client_send_ini(client, filename))
525 remove_client(client);
527 client->sent_job = 1;
533 static void convert_io_stat(struct io_stat *dst, struct io_stat *src)
535 dst->max_val = le64_to_cpu(src->max_val);
536 dst->min_val = le64_to_cpu(src->min_val);
537 dst->samples = le64_to_cpu(src->samples);
540 * Floats arrive as IEEE 754 encoded uint64_t, convert back to double
542 dst->mean.u.f = fio_uint64_to_double(le64_to_cpu(dst->mean.u.i));
543 dst->S.u.f = fio_uint64_to_double(le64_to_cpu(dst->S.u.i));
546 static void convert_ts(struct thread_stat *dst, struct thread_stat *src)
550 dst->error = le32_to_cpu(src->error);
551 dst->groupid = le32_to_cpu(src->groupid);
552 dst->pid = le32_to_cpu(src->pid);
553 dst->members = le32_to_cpu(src->members);
555 for (i = 0; i < 2; i++) {
556 convert_io_stat(&dst->clat_stat[i], &src->clat_stat[i]);
557 convert_io_stat(&dst->slat_stat[i], &src->slat_stat[i]);
558 convert_io_stat(&dst->lat_stat[i], &src->lat_stat[i]);
559 convert_io_stat(&dst->bw_stat[i], &src->bw_stat[i]);
562 dst->usr_time = le64_to_cpu(src->usr_time);
563 dst->sys_time = le64_to_cpu(src->sys_time);
564 dst->ctx = le64_to_cpu(src->ctx);
565 dst->minf = le64_to_cpu(src->minf);
566 dst->majf = le64_to_cpu(src->majf);
567 dst->clat_percentiles = le64_to_cpu(src->clat_percentiles);
569 for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) {
570 fio_fp64_t *fps = &src->percentile_list[i];
571 fio_fp64_t *fpd = &dst->percentile_list[i];
573 fpd->u.f = fio_uint64_to_double(le64_to_cpu(fps->u.i));
576 for (i = 0; i < FIO_IO_U_MAP_NR; i++) {
577 dst->io_u_map[i] = le32_to_cpu(src->io_u_map[i]);
578 dst->io_u_submit[i] = le32_to_cpu(src->io_u_submit[i]);
579 dst->io_u_complete[i] = le32_to_cpu(src->io_u_complete[i]);
582 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) {
583 dst->io_u_lat_u[i] = le32_to_cpu(src->io_u_lat_u[i]);
584 dst->io_u_lat_m[i] = le32_to_cpu(src->io_u_lat_m[i]);
587 for (i = 0; i < 2; i++)
588 for (j = 0; j < FIO_IO_U_PLAT_NR; j++)
589 dst->io_u_plat[i][j] = le32_to_cpu(src->io_u_plat[i][j]);
591 for (i = 0; i < 3; i++) {
592 dst->total_io_u[i] = le64_to_cpu(src->total_io_u[i]);
593 dst->short_io_u[i] = le64_to_cpu(src->short_io_u[i]);
596 dst->total_submit = le64_to_cpu(src->total_submit);
597 dst->total_complete = le64_to_cpu(src->total_complete);
599 for (i = 0; i < 2; i++) {
600 dst->io_bytes[i] = le64_to_cpu(src->io_bytes[i]);
601 dst->runtime[i] = le64_to_cpu(src->runtime[i]);
604 dst->total_run_time = le64_to_cpu(src->total_run_time);
605 dst->continue_on_error = le16_to_cpu(src->continue_on_error);
606 dst->total_err_count = le64_to_cpu(src->total_err_count);
607 dst->first_error = le32_to_cpu(src->first_error);
608 dst->kb_base = le32_to_cpu(src->kb_base);
611 static void convert_gs(struct group_run_stats *dst, struct group_run_stats *src)
615 for (i = 0; i < 2; i++) {
616 dst->max_run[i] = le64_to_cpu(src->max_run[i]);
617 dst->min_run[i] = le64_to_cpu(src->min_run[i]);
618 dst->max_bw[i] = le64_to_cpu(src->max_bw[i]);
619 dst->min_bw[i] = le64_to_cpu(src->min_bw[i]);
620 dst->io_kb[i] = le64_to_cpu(src->io_kb[i]);
621 dst->agg[i] = le64_to_cpu(src->agg[i]);
624 dst->kb_base = le32_to_cpu(src->kb_base);
625 dst->groupid = le32_to_cpu(src->groupid);
628 static void handle_ts(struct fio_net_cmd *cmd)
630 struct cmd_ts_pdu *p = (struct cmd_ts_pdu *) cmd->payload;
632 convert_ts(&p->ts, &p->ts);
633 convert_gs(&p->rs, &p->rs);
635 show_thread_status(&p->ts, &p->rs);
637 if (sum_stat_clients == 1)
640 sum_thread_stats(&client_ts, &p->ts, sum_stat_nr);
641 sum_group_stats(&client_gs, &p->rs);
644 client_ts.groupid = p->ts.groupid;
646 if (++sum_stat_nr == sum_stat_clients) {
647 strcpy(client_ts.name, "All clients");
648 show_thread_status(&client_ts, &client_gs);
652 static void handle_gs(struct fio_net_cmd *cmd)
654 struct group_run_stats *gs = (struct group_run_stats *) cmd->payload;
657 show_group_stats(gs);
660 static void convert_agg(struct disk_util_agg *agg)
664 for (i = 0; i < 2; i++) {
665 agg->ios[i] = le32_to_cpu(agg->ios[i]);
666 agg->merges[i] = le32_to_cpu(agg->merges[i]);
667 agg->sectors[i] = le64_to_cpu(agg->sectors[i]);
668 agg->ticks[i] = le32_to_cpu(agg->ticks[i]);
671 agg->io_ticks = le32_to_cpu(agg->io_ticks);
672 agg->time_in_queue = le32_to_cpu(agg->time_in_queue);
673 agg->slavecount = le32_to_cpu(agg->slavecount);
674 agg->max_util.u.f = fio_uint64_to_double(__le64_to_cpu(agg->max_util.u.i));
677 static void convert_dus(struct disk_util_stat *dus)
681 for (i = 0; i < 2; i++) {
682 dus->ios[i] = le32_to_cpu(dus->ios[i]);
683 dus->merges[i] = le32_to_cpu(dus->merges[i]);
684 dus->sectors[i] = le64_to_cpu(dus->sectors[i]);
685 dus->ticks[i] = le32_to_cpu(dus->ticks[i]);
688 dus->io_ticks = le32_to_cpu(dus->io_ticks);
689 dus->time_in_queue = le32_to_cpu(dus->time_in_queue);
690 dus->msec = le64_to_cpu(dus->msec);
693 static void handle_du(struct fio_client *client, struct fio_net_cmd *cmd)
695 struct cmd_du_pdu *du = (struct cmd_du_pdu *) cmd->payload;
697 convert_dus(&du->dus);
698 convert_agg(&du->agg);
700 if (!client->disk_stats_shown) {
701 client->disk_stats_shown = 1;
702 log_info("\nDisk stats (read/write):\n");
705 print_disk_util(&du->dus, &du->agg, terse_output);
708 static void convert_jobs_eta(struct jobs_eta *je)
712 je->nr_running = le32_to_cpu(je->nr_running);
713 je->nr_ramp = le32_to_cpu(je->nr_ramp);
714 je->nr_pending = le32_to_cpu(je->nr_pending);
715 je->files_open = le32_to_cpu(je->files_open);
716 je->m_rate = le32_to_cpu(je->m_rate);
717 je->t_rate = le32_to_cpu(je->t_rate);
718 je->m_iops = le32_to_cpu(je->m_iops);
719 je->t_iops = le32_to_cpu(je->t_iops);
721 for (i = 0; i < 2; i++) {
722 je->rate[i] = le32_to_cpu(je->rate[i]);
723 je->iops[i] = le32_to_cpu(je->iops[i]);
726 je->elapsed_sec = le64_to_cpu(je->elapsed_sec);
727 je->eta_sec = le64_to_cpu(je->eta_sec);
730 static void sum_jobs_eta(struct jobs_eta *dst, struct jobs_eta *je)
734 dst->nr_running += je->nr_running;
735 dst->nr_ramp += je->nr_ramp;
736 dst->nr_pending += je->nr_pending;
737 dst->files_open += je->files_open;
738 dst->m_rate += je->m_rate;
739 dst->t_rate += je->t_rate;
740 dst->m_iops += je->m_iops;
741 dst->t_iops += je->t_iops;
743 for (i = 0; i < 2; i++) {
744 dst->rate[i] += je->rate[i];
745 dst->iops[i] += je->iops[i];
748 dst->elapsed_sec += je->elapsed_sec;
750 if (je->eta_sec > dst->eta_sec)
751 dst->eta_sec = je->eta_sec;
754 static void dec_jobs_eta(struct client_eta *eta)
756 if (!--eta->pending) {
757 display_thread_status(&eta->eta);
762 static void remove_reply_cmd(struct fio_client *client, struct fio_net_cmd *cmd)
764 struct fio_net_int_cmd *icmd = NULL;
765 struct flist_head *entry;
767 flist_for_each(entry, &client->cmd_list) {
768 icmd = flist_entry(entry, struct fio_net_int_cmd, list);
770 if (cmd->tag == (uintptr_t) icmd)
777 log_err("fio: client: unable to find matching tag\n");
781 flist_del(&icmd->list);
782 cmd->tag = icmd->saved_tag;
786 static void handle_eta(struct fio_client *client, struct fio_net_cmd *cmd)
788 struct jobs_eta *je = (struct jobs_eta *) cmd->payload;
789 struct client_eta *eta = (struct client_eta *) (uintptr_t) cmd->tag;
791 dprint(FD_NET, "client: got eta tag %p, %d\n", eta, eta->pending);
793 assert(client->eta_in_flight == eta);
795 client->eta_in_flight = NULL;
796 flist_del_init(&client->eta_list);
798 convert_jobs_eta(je);
799 sum_jobs_eta(&eta->eta, je);
803 static void handle_probe(struct fio_client *client, struct fio_net_cmd *cmd)
805 struct cmd_probe_pdu *probe = (struct cmd_probe_pdu *) cmd->payload;
806 const char *os, *arch;
809 os = fio_get_os_string(probe->os);
813 arch = fio_get_arch_string(probe->arch);
817 sprintf(bit, "%d-bit", probe->bpp * 8);
819 log_info("hostname=%s, be=%u, %s, os=%s, arch=%s, fio=%s\n",
820 probe->hostname, probe->bigendian, bit, os, arch,
824 client->name = strdup((char *) probe->hostname);
827 static void handle_start(struct fio_client *client, struct fio_net_cmd *cmd)
829 struct cmd_start_pdu *pdu = (struct cmd_start_pdu *) cmd->payload;
831 client->state = Client_started;
832 client->jobs = le32_to_cpu(pdu->jobs);
835 static void handle_stop(struct fio_client *client, struct fio_net_cmd *cmd)
837 struct cmd_end_pdu *pdu = (struct cmd_end_pdu *) cmd->payload;
839 client->state = Client_stopped;
840 client->error = le32_to_cpu(pdu->error);
843 log_info("client <%s>: exited with error %d\n", client->hostname, client->error);
846 static int handle_client(struct fio_client *client)
848 struct fio_net_cmd *cmd;
850 dprint(FD_NET, "client: handle %s\n", client->hostname);
852 cmd = fio_net_recv_cmd(client->fd);
856 dprint(FD_NET, "client: got cmd op %s from %s\n",
857 fio_server_op(cmd->opcode), client->hostname);
859 switch (cmd->opcode) {
860 case FIO_NET_CMD_QUIT:
861 remove_client(client);
864 case FIO_NET_CMD_TEXT: {
865 const char *buf = (const char *) cmd->payload;
869 name = client->name ? client->name : client->hostname;
871 if (!client->skip_newline)
872 fprintf(f_out, "<%s> ", name);
873 ret = fwrite(buf, cmd->pdu_len, 1, f_out);
875 client->skip_newline = strchr(buf, '\n') == NULL;
880 handle_du(client, cmd);
891 case FIO_NET_CMD_ETA:
892 remove_reply_cmd(client, cmd);
893 handle_eta(client, cmd);
896 case FIO_NET_CMD_PROBE:
897 remove_reply_cmd(client, cmd);
898 handle_probe(client, cmd);
901 case FIO_NET_CMD_RUN:
902 client->state = Client_running;
905 case FIO_NET_CMD_START:
906 handle_start(client, cmd);
909 case FIO_NET_CMD_STOP:
910 handle_stop(client, cmd);
914 log_err("fio: unknown client op: %s\n", fio_server_op(cmd->opcode));
922 static void request_client_etas(void)
924 struct fio_client *client;
925 struct flist_head *entry;
926 struct client_eta *eta;
929 dprint(FD_NET, "client: request eta (%d)\n", nr_clients);
931 eta = malloc(sizeof(*eta));
932 memset(&eta->eta, 0, sizeof(eta->eta));
933 eta->pending = nr_clients;
935 flist_for_each(entry, &client_list) {
936 client = flist_entry(entry, struct fio_client, list);
938 if (!flist_empty(&client->eta_list)) {
942 if (client->state != Client_running)
945 assert(!client->eta_in_flight);
946 flist_add_tail(&client->eta_list, &eta_list);
947 client->eta_in_flight = eta;
948 fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_SEND_ETA,
949 (uintptr_t) eta, &client->cmd_list);
955 dprint(FD_NET, "client: requested eta tag %p\n", eta);
958 static int client_check_cmd_timeout(struct fio_client *client,
961 struct fio_net_int_cmd *cmd;
962 struct flist_head *entry, *tmp;
965 flist_for_each_safe(entry, tmp, &client->cmd_list) {
966 cmd = flist_entry(entry, struct fio_net_int_cmd, list);
968 if (mtime_since(&cmd->tv, now) < FIO_NET_CLIENT_TIMEOUT)
971 log_err("fio: client %s, timeout on cmd %s\n", client->hostname,
972 fio_server_op(cmd->cmd.opcode));
973 flist_del(&cmd->list);
978 return flist_empty(&client->cmd_list) && ret;
981 static int fio_client_timed_out(void)
983 struct fio_client *client;
984 struct flist_head *entry, *tmp;
988 gettimeofday(&tv, NULL);
990 flist_for_each_safe(entry, tmp, &client_list) {
991 client = flist_entry(entry, struct fio_client, list);
993 if (flist_empty(&client->cmd_list))
996 if (!client_check_cmd_timeout(client, &tv))
999 log_err("fio: client %s timed out\n", client->hostname);
1000 remove_client(client);
1007 int fio_handle_clients(void)
1009 struct pollfd *pfds;
1010 int i, ret = 0, retval = 0;
1012 gettimeofday(&eta_tv, NULL);
1014 pfds = malloc(nr_clients * sizeof(struct pollfd));
1016 sum_stat_clients = nr_clients;
1017 init_thread_stat(&client_ts);
1018 init_group_run_stat(&client_gs);
1020 while (!exit_backend && nr_clients) {
1021 struct flist_head *entry, *tmp;
1022 struct fio_client *client;
1025 flist_for_each_safe(entry, tmp, &client_list) {
1026 client = flist_entry(entry, struct fio_client, list);
1028 if (!client->sent_job &&
1029 flist_empty(&client->cmd_list)) {
1030 remove_client(client);
1034 pfds[i].fd = client->fd;
1035 pfds[i].events = POLLIN;
1042 assert(i == nr_clients);
1047 gettimeofday(&tv, NULL);
1048 if (mtime_since(&eta_tv, &tv) >= 900) {
1049 request_client_etas();
1050 memcpy(&eta_tv, &tv, sizeof(tv));
1052 if (fio_client_timed_out())
1056 ret = poll(pfds, nr_clients, 100);
1060 log_err("fio: poll clients: %s\n", strerror(errno));
1066 for (i = 0; i < nr_clients; i++) {
1067 if (!(pfds[i].revents & POLLIN))
1070 client = find_client_by_fd(pfds[i].fd);
1072 log_err("fio: unknown client fd %d\n", pfds[i].fd);
1075 if (!handle_client(client)) {
1076 log_info("client: host=%s disconnected\n",
1078 remove_client(client);
1080 } else if (client->error)