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 unsigned int nr_ini_file;
66 static struct timeval eta_tv;
77 static FLIST_HEAD(client_list);
78 static FLIST_HEAD(eta_list);
80 static FLIST_HEAD(arg_list);
82 static struct thread_stat client_ts;
83 static struct group_run_stats client_gs;
84 static int sum_stat_clients;
85 static int sum_stat_nr;
87 #define FIO_CLIENT_HASH_BITS 7
88 #define FIO_CLIENT_HASH_SZ (1 << FIO_CLIENT_HASH_BITS)
89 #define FIO_CLIENT_HASH_MASK (FIO_CLIENT_HASH_SZ - 1)
90 static struct flist_head client_hash[FIO_CLIENT_HASH_SZ];
92 static int handle_client(struct fio_client *client);
93 static void dec_jobs_eta(struct client_eta *eta);
95 static void fio_client_add_hash(struct fio_client *client)
97 int bucket = hash_long(client->fd, FIO_CLIENT_HASH_BITS);
99 bucket &= FIO_CLIENT_HASH_MASK;
100 flist_add(&client->hash_list, &client_hash[bucket]);
103 static void fio_client_remove_hash(struct fio_client *client)
105 if (!flist_empty(&client->hash_list))
106 flist_del_init(&client->hash_list);
109 static void fio_init fio_client_hash_init(void)
113 for (i = 0; i < FIO_CLIENT_HASH_SZ; i++)
114 INIT_FLIST_HEAD(&client_hash[i]);
117 static struct fio_client *find_client_by_fd(int fd)
119 int bucket = hash_long(fd, FIO_CLIENT_HASH_BITS) & FIO_CLIENT_HASH_MASK;
120 struct fio_client *client;
121 struct flist_head *entry;
123 flist_for_each(entry, &client_hash[bucket]) {
124 client = flist_entry(entry, struct fio_client, hash_list);
126 if (client->fd == fd) {
135 static void remove_client(struct fio_client *client)
137 assert(client->refs);
142 dprint(FD_NET, "client: removed <%s>\n", client->hostname);
143 flist_del(&client->list);
145 fio_client_remove_hash(client);
147 if (!flist_empty(&client->eta_list)) {
148 flist_del_init(&client->eta_list);
149 dec_jobs_eta(client->eta_in_flight);
152 free(client->hostname);
157 while (client->nr_ini_file)
158 free(client->ini_file[--client->nr_ini_file]);
159 if (client->ini_file)
160 free(client->ini_file);
167 static void put_client(struct fio_client *client)
169 remove_client(client);
172 static void __fio_client_add_cmd_option(struct fio_client *client,
177 index = client->argc++;
178 client->argv = realloc(client->argv, sizeof(char *) * client->argc);
179 client->argv[index] = strdup(opt);
180 dprint(FD_NET, "client: add cmd %d: %s\n", index, opt);
183 void fio_client_add_cmd_option(void *cookie, const char *opt)
185 struct fio_client *client = cookie;
186 struct flist_head *entry;
191 __fio_client_add_cmd_option(client, opt);
194 * Duplicate arguments to shared client group
196 flist_for_each(entry, &arg_list) {
197 client = flist_entry(entry, struct fio_client, arg_list);
199 __fio_client_add_cmd_option(client, opt);
203 void fio_client_add_ini_file(void *cookie, const char *ini_file)
205 struct fio_client *client = cookie;
208 dprint(FD_NET, "client <%s>: add ini %s\n", client->hostname, ini_file);
210 new_size = (client->nr_ini_file + 1) * sizeof(char *);
211 client->ini_file = realloc(client->ini_file, new_size);
212 client->ini_file[client->nr_ini_file] = strdup(ini_file);
213 client->nr_ini_file++;
216 int fio_client_add(const char *hostname, void **cookie)
218 struct fio_client *existing = *cookie;
219 struct fio_client *client;
223 * We always add our "exec" name as the option, hence 1
226 if (existing->argc == 1)
227 flist_add_tail(&existing->arg_list, &arg_list);
229 while (!flist_empty(&arg_list))
230 flist_del_init(arg_list.next);
234 client = malloc(sizeof(*client));
235 memset(client, 0, sizeof(*client));
237 INIT_FLIST_HEAD(&client->list);
238 INIT_FLIST_HEAD(&client->hash_list);
239 INIT_FLIST_HEAD(&client->arg_list);
240 INIT_FLIST_HEAD(&client->eta_list);
241 INIT_FLIST_HEAD(&client->cmd_list);
243 if (fio_server_parse_string(hostname, &client->hostname,
244 &client->is_sock, &client->port,
245 &client->addr.sin_addr,
246 &client->addr6.sin6_addr,
253 __fio_client_add_cmd_option(client, "fio");
255 flist_add(&client->list, &client_list);
257 dprint(FD_NET, "client: added <%s>\n", client->hostname);
262 static int fio_client_connect_ip(struct fio_client *client)
264 struct sockaddr *addr;
265 fio_socklen_t socklen;
269 client->addr6.sin6_family = AF_INET6;
270 client->addr6.sin6_port = htons(client->port);
272 addr = (struct sockaddr *) &client->addr6;
273 socklen = sizeof(client->addr6);
275 client->addr.sin_family = AF_INET;
276 client->addr.sin_port = htons(client->port);
278 addr = (struct sockaddr *) &client->addr;
279 socklen = sizeof(client->addr);
282 fd = socket(domain, SOCK_STREAM, 0);
284 log_err("fio: socket: %s\n", strerror(errno));
288 if (connect(fd, addr, socklen) < 0) {
289 log_err("fio: connect: %s\n", strerror(errno));
290 log_err("fio: failed to connect to %s:%u\n", client->hostname,
299 static int fio_client_connect_sock(struct fio_client *client)
301 struct sockaddr_un *addr = &client->addr_un;
305 memset(addr, 0, sizeof(*addr));
306 addr->sun_family = AF_UNIX;
307 strcpy(addr->sun_path, client->hostname);
309 fd = socket(AF_UNIX, SOCK_STREAM, 0);
311 log_err("fio: socket: %s\n", strerror(errno));
315 len = sizeof(addr->sun_family) + strlen(addr->sun_path) + 1;
316 if (connect(fd, (struct sockaddr *) addr, len) < 0) {
317 log_err("fio: connect; %s\n", strerror(errno));
325 static int fio_client_connect(struct fio_client *client)
329 dprint(FD_NET, "client: connect to host %s\n", client->hostname);
332 fd = fio_client_connect_sock(client);
334 fd = fio_client_connect_ip(client);
336 dprint(FD_NET, "client: %s connected %d\n", client->hostname, fd);
342 fio_client_add_hash(client);
343 client->state = Client_connected;
347 void fio_clients_terminate(void)
349 struct flist_head *entry;
350 struct fio_client *client;
352 dprint(FD_NET, "client: terminate clients\n");
354 flist_for_each(entry, &client_list) {
355 client = flist_entry(entry, struct fio_client, list);
357 fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_QUIT, 0, NULL);
361 static void sig_int(int sig)
363 dprint(FD_NET, "client: got signal %d\n", sig);
364 fio_clients_terminate();
367 static void sig_show_status(int sig)
369 show_running_run_stats();
372 static void client_signal_handler(void)
374 struct sigaction act;
376 memset(&act, 0, sizeof(act));
377 act.sa_handler = sig_int;
378 act.sa_flags = SA_RESTART;
379 sigaction(SIGINT, &act, NULL);
381 memset(&act, 0, sizeof(act));
382 act.sa_handler = sig_int;
383 act.sa_flags = SA_RESTART;
384 sigaction(SIGTERM, &act, NULL);
386 memset(&act, 0, sizeof(act));
387 act.sa_handler = sig_show_status;
388 act.sa_flags = SA_RESTART;
389 sigaction(SIGUSR1, &act, NULL);
392 static void probe_client(struct fio_client *client)
394 dprint(FD_NET, "client: send probe\n");
396 fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_PROBE, 0, &client->cmd_list);
399 static int send_client_cmd_line(struct fio_client *client)
401 struct cmd_single_line_pdu *cslp;
402 struct cmd_line_pdu *clp;
403 unsigned long offset;
409 dprint(FD_NET, "client: send cmdline %d\n", client->argc);
411 lens = malloc(client->argc * sizeof(unsigned int));
414 * Find out how much mem we need
416 for (i = 0, mem = 0; i < client->argc; i++) {
417 lens[i] = strlen(client->argv[i]) + 1;
422 * We need one cmd_line_pdu, and argc number of cmd_single_line_pdu
424 mem += sizeof(*clp) + (client->argc * sizeof(*cslp));
428 offset = sizeof(*clp);
430 for (i = 0; i < client->argc; i++) {
431 uint16_t arg_len = lens[i];
434 strcpy((char *) cslp->text, client->argv[i]);
435 cslp->len = cpu_to_le16(arg_len);
436 offset += sizeof(*cslp) + arg_len;
440 clp->lines = cpu_to_le16(client->argc);
441 ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOBLINE, pdu, mem, 0);
446 int fio_clients_connect(void)
448 struct fio_client *client;
449 struct flist_head *entry, *tmp;
454 WSAStartup(MAKEWORD(2,2), &wsd);
457 dprint(FD_NET, "client: connect all\n");
459 client_signal_handler();
461 flist_for_each_safe(entry, tmp, &client_list) {
462 client = flist_entry(entry, struct fio_client, list);
464 ret = fio_client_connect(client);
466 remove_client(client);
470 probe_client(client);
472 if (client->argc > 1)
473 send_client_cmd_line(client);
480 * Send file contents to server backend. We could use sendfile(), but to remain
481 * more portable lets just read/write the darn thing.
483 static int fio_client_send_ini(struct fio_client *client, const char *filename)
490 dprint(FD_NET, "send ini %s to %s\n", filename, client->hostname);
492 fd = open(filename, O_RDONLY);
494 log_err("fio: job file <%s> open: %s\n", filename, strerror(errno));
498 if (fstat(fd, &sb) < 0) {
499 log_err("fio: job file stat: %s\n", strerror(errno));
504 buf = malloc(sb.st_size);
509 ret = read(fd, p, len);
518 else if (errno == EAGAIN || errno == EINTR)
523 log_err("fio: failed reading job file %s\n", filename);
529 client->sent_job = 1;
530 ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOB, buf, sb.st_size, 0);
536 int fio_clients_send_ini(const char *filename)
538 struct fio_client *client;
539 struct flist_head *entry, *tmp;
541 flist_for_each_safe(entry, tmp, &client_list) {
542 client = flist_entry(entry, struct fio_client, list);
544 if (client->nr_ini_file) {
547 for (i = 0; i < client->nr_ini_file; i++) {
548 const char *ini = client->ini_file[i];
550 if (fio_client_send_ini(client, ini)) {
551 remove_client(client);
555 } else if (!filename || fio_client_send_ini(client, filename))
556 remove_client(client);
558 client->sent_job = 1;
564 static void convert_io_stat(struct io_stat *dst, struct io_stat *src)
566 dst->max_val = le64_to_cpu(src->max_val);
567 dst->min_val = le64_to_cpu(src->min_val);
568 dst->samples = le64_to_cpu(src->samples);
571 * Floats arrive as IEEE 754 encoded uint64_t, convert back to double
573 dst->mean.u.f = fio_uint64_to_double(le64_to_cpu(dst->mean.u.i));
574 dst->S.u.f = fio_uint64_to_double(le64_to_cpu(dst->S.u.i));
577 static void convert_ts(struct thread_stat *dst, struct thread_stat *src)
581 dst->error = le32_to_cpu(src->error);
582 dst->groupid = le32_to_cpu(src->groupid);
583 dst->pid = le32_to_cpu(src->pid);
584 dst->members = le32_to_cpu(src->members);
586 for (i = 0; i < 2; i++) {
587 convert_io_stat(&dst->clat_stat[i], &src->clat_stat[i]);
588 convert_io_stat(&dst->slat_stat[i], &src->slat_stat[i]);
589 convert_io_stat(&dst->lat_stat[i], &src->lat_stat[i]);
590 convert_io_stat(&dst->bw_stat[i], &src->bw_stat[i]);
593 dst->usr_time = le64_to_cpu(src->usr_time);
594 dst->sys_time = le64_to_cpu(src->sys_time);
595 dst->ctx = le64_to_cpu(src->ctx);
596 dst->minf = le64_to_cpu(src->minf);
597 dst->majf = le64_to_cpu(src->majf);
598 dst->clat_percentiles = le64_to_cpu(src->clat_percentiles);
600 for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) {
601 fio_fp64_t *fps = &src->percentile_list[i];
602 fio_fp64_t *fpd = &dst->percentile_list[i];
604 fpd->u.f = fio_uint64_to_double(le64_to_cpu(fps->u.i));
607 for (i = 0; i < FIO_IO_U_MAP_NR; i++) {
608 dst->io_u_map[i] = le32_to_cpu(src->io_u_map[i]);
609 dst->io_u_submit[i] = le32_to_cpu(src->io_u_submit[i]);
610 dst->io_u_complete[i] = le32_to_cpu(src->io_u_complete[i]);
613 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) {
614 dst->io_u_lat_u[i] = le32_to_cpu(src->io_u_lat_u[i]);
615 dst->io_u_lat_m[i] = le32_to_cpu(src->io_u_lat_m[i]);
618 for (i = 0; i < 2; i++)
619 for (j = 0; j < FIO_IO_U_PLAT_NR; j++)
620 dst->io_u_plat[i][j] = le32_to_cpu(src->io_u_plat[i][j]);
622 for (i = 0; i < 3; i++) {
623 dst->total_io_u[i] = le64_to_cpu(src->total_io_u[i]);
624 dst->short_io_u[i] = le64_to_cpu(src->short_io_u[i]);
627 dst->total_submit = le64_to_cpu(src->total_submit);
628 dst->total_complete = le64_to_cpu(src->total_complete);
630 for (i = 0; i < 2; i++) {
631 dst->io_bytes[i] = le64_to_cpu(src->io_bytes[i]);
632 dst->runtime[i] = le64_to_cpu(src->runtime[i]);
635 dst->total_run_time = le64_to_cpu(src->total_run_time);
636 dst->continue_on_error = le16_to_cpu(src->continue_on_error);
637 dst->total_err_count = le64_to_cpu(src->total_err_count);
638 dst->first_error = le32_to_cpu(src->first_error);
639 dst->kb_base = le32_to_cpu(src->kb_base);
642 static void convert_gs(struct group_run_stats *dst, struct group_run_stats *src)
646 for (i = 0; i < 2; i++) {
647 dst->max_run[i] = le64_to_cpu(src->max_run[i]);
648 dst->min_run[i] = le64_to_cpu(src->min_run[i]);
649 dst->max_bw[i] = le64_to_cpu(src->max_bw[i]);
650 dst->min_bw[i] = le64_to_cpu(src->min_bw[i]);
651 dst->io_kb[i] = le64_to_cpu(src->io_kb[i]);
652 dst->agg[i] = le64_to_cpu(src->agg[i]);
655 dst->kb_base = le32_to_cpu(src->kb_base);
656 dst->groupid = le32_to_cpu(src->groupid);
659 static void handle_ts(struct fio_net_cmd *cmd)
661 struct cmd_ts_pdu *p = (struct cmd_ts_pdu *) cmd->payload;
663 convert_ts(&p->ts, &p->ts);
664 convert_gs(&p->rs, &p->rs);
666 show_thread_status(&p->ts, &p->rs);
668 if (sum_stat_clients == 1)
671 sum_thread_stats(&client_ts, &p->ts, sum_stat_nr);
672 sum_group_stats(&client_gs, &p->rs);
675 client_ts.groupid = p->ts.groupid;
677 if (++sum_stat_nr == sum_stat_clients) {
678 strcpy(client_ts.name, "All clients");
679 show_thread_status(&client_ts, &client_gs);
683 static void handle_gs(struct fio_net_cmd *cmd)
685 struct group_run_stats *gs = (struct group_run_stats *) cmd->payload;
688 show_group_stats(gs);
691 static void convert_agg(struct disk_util_agg *agg)
695 for (i = 0; i < 2; i++) {
696 agg->ios[i] = le32_to_cpu(agg->ios[i]);
697 agg->merges[i] = le32_to_cpu(agg->merges[i]);
698 agg->sectors[i] = le64_to_cpu(agg->sectors[i]);
699 agg->ticks[i] = le32_to_cpu(agg->ticks[i]);
702 agg->io_ticks = le32_to_cpu(agg->io_ticks);
703 agg->time_in_queue = le32_to_cpu(agg->time_in_queue);
704 agg->slavecount = le32_to_cpu(agg->slavecount);
705 agg->max_util.u.f = fio_uint64_to_double(__le64_to_cpu(agg->max_util.u.i));
708 static void convert_dus(struct disk_util_stat *dus)
712 for (i = 0; i < 2; i++) {
713 dus->ios[i] = le32_to_cpu(dus->ios[i]);
714 dus->merges[i] = le32_to_cpu(dus->merges[i]);
715 dus->sectors[i] = le64_to_cpu(dus->sectors[i]);
716 dus->ticks[i] = le32_to_cpu(dus->ticks[i]);
719 dus->io_ticks = le32_to_cpu(dus->io_ticks);
720 dus->time_in_queue = le32_to_cpu(dus->time_in_queue);
721 dus->msec = le64_to_cpu(dus->msec);
724 static void handle_du(struct fio_client *client, struct fio_net_cmd *cmd)
726 struct cmd_du_pdu *du = (struct cmd_du_pdu *) cmd->payload;
728 convert_dus(&du->dus);
729 convert_agg(&du->agg);
731 if (!client->disk_stats_shown) {
732 client->disk_stats_shown = 1;
733 log_info("\nDisk stats (read/write):\n");
736 print_disk_util(&du->dus, &du->agg, output_format == FIO_OUTPUT_TERSE);
739 static void convert_jobs_eta(struct jobs_eta *je)
743 je->nr_running = le32_to_cpu(je->nr_running);
744 je->nr_ramp = le32_to_cpu(je->nr_ramp);
745 je->nr_pending = le32_to_cpu(je->nr_pending);
746 je->files_open = le32_to_cpu(je->files_open);
747 je->m_rate = le32_to_cpu(je->m_rate);
748 je->t_rate = le32_to_cpu(je->t_rate);
749 je->m_iops = le32_to_cpu(je->m_iops);
750 je->t_iops = le32_to_cpu(je->t_iops);
752 for (i = 0; i < 2; i++) {
753 je->rate[i] = le32_to_cpu(je->rate[i]);
754 je->iops[i] = le32_to_cpu(je->iops[i]);
757 je->elapsed_sec = le64_to_cpu(je->elapsed_sec);
758 je->eta_sec = le64_to_cpu(je->eta_sec);
759 je->is_pow2 = le32_to_cpu(je->is_pow2);
762 static void sum_jobs_eta(struct jobs_eta *dst, struct jobs_eta *je)
766 dst->nr_running += je->nr_running;
767 dst->nr_ramp += je->nr_ramp;
768 dst->nr_pending += je->nr_pending;
769 dst->files_open += je->files_open;
770 dst->m_rate += je->m_rate;
771 dst->t_rate += je->t_rate;
772 dst->m_iops += je->m_iops;
773 dst->t_iops += je->t_iops;
775 for (i = 0; i < 2; i++) {
776 dst->rate[i] += je->rate[i];
777 dst->iops[i] += je->iops[i];
780 dst->elapsed_sec += je->elapsed_sec;
782 if (je->eta_sec > dst->eta_sec)
783 dst->eta_sec = je->eta_sec;
786 static void dec_jobs_eta(struct client_eta *eta)
788 if (!--eta->pending) {
789 display_thread_status(&eta->eta);
794 static void remove_reply_cmd(struct fio_client *client, struct fio_net_cmd *cmd)
796 struct fio_net_int_cmd *icmd = NULL;
797 struct flist_head *entry;
799 flist_for_each(entry, &client->cmd_list) {
800 icmd = flist_entry(entry, struct fio_net_int_cmd, list);
802 if (cmd->tag == (uintptr_t) icmd)
809 log_err("fio: client: unable to find matching tag\n");
813 flist_del(&icmd->list);
814 cmd->tag = icmd->saved_tag;
818 static void handle_eta(struct fio_client *client, struct fio_net_cmd *cmd)
820 struct jobs_eta *je = (struct jobs_eta *) cmd->payload;
821 struct client_eta *eta = (struct client_eta *) (uintptr_t) cmd->tag;
823 dprint(FD_NET, "client: got eta tag %p, %d\n", eta, eta->pending);
825 assert(client->eta_in_flight == eta);
827 client->eta_in_flight = NULL;
828 flist_del_init(&client->eta_list);
830 convert_jobs_eta(je);
831 sum_jobs_eta(&eta->eta, je);
835 static void handle_probe(struct fio_client *client, struct fio_net_cmd *cmd)
837 struct cmd_probe_pdu *probe = (struct cmd_probe_pdu *) cmd->payload;
838 const char *os, *arch;
841 os = fio_get_os_string(probe->os);
845 arch = fio_get_arch_string(probe->arch);
849 sprintf(bit, "%d-bit", probe->bpp * 8);
851 log_info("hostname=%s, be=%u, %s, os=%s, arch=%s, fio=%s\n",
852 probe->hostname, probe->bigendian, bit, os, arch,
856 client->name = strdup((char *) probe->hostname);
859 static void handle_start(struct fio_client *client, struct fio_net_cmd *cmd)
861 struct cmd_start_pdu *pdu = (struct cmd_start_pdu *) cmd->payload;
863 client->state = Client_started;
864 client->jobs = le32_to_cpu(pdu->jobs);
867 static void handle_stop(struct fio_client *client, struct fio_net_cmd *cmd)
869 struct cmd_end_pdu *pdu = (struct cmd_end_pdu *) cmd->payload;
871 client->state = Client_stopped;
872 client->error = le32_to_cpu(pdu->error);
875 log_info("client <%s>: exited with error %d\n", client->hostname, client->error);
878 static int handle_client(struct fio_client *client)
880 struct fio_net_cmd *cmd;
882 dprint(FD_NET, "client: handle %s\n", client->hostname);
884 cmd = fio_net_recv_cmd(client->fd);
888 dprint(FD_NET, "client: got cmd op %s from %s\n",
889 fio_server_op(cmd->opcode), client->hostname);
891 switch (cmd->opcode) {
892 case FIO_NET_CMD_QUIT:
893 remove_client(client);
896 case FIO_NET_CMD_TEXT: {
897 const char *buf = (const char *) cmd->payload;
901 name = client->name ? client->name : client->hostname;
903 if (!client->skip_newline)
904 fprintf(f_out, "<%s> ", name);
905 ret = fwrite(buf, cmd->pdu_len, 1, f_out);
907 client->skip_newline = strchr(buf, '\n') == NULL;
912 handle_du(client, cmd);
923 case FIO_NET_CMD_ETA:
924 remove_reply_cmd(client, cmd);
925 handle_eta(client, cmd);
928 case FIO_NET_CMD_PROBE:
929 remove_reply_cmd(client, cmd);
930 handle_probe(client, cmd);
933 case FIO_NET_CMD_RUN:
934 client->state = Client_running;
937 case FIO_NET_CMD_START:
938 handle_start(client, cmd);
941 case FIO_NET_CMD_STOP:
942 handle_stop(client, cmd);
946 log_err("fio: unknown client op: %s\n", fio_server_op(cmd->opcode));
954 static void request_client_etas(void)
956 struct fio_client *client;
957 struct flist_head *entry;
958 struct client_eta *eta;
961 dprint(FD_NET, "client: request eta (%d)\n", nr_clients);
963 eta = malloc(sizeof(*eta));
964 memset(&eta->eta, 0, sizeof(eta->eta));
965 eta->pending = nr_clients;
967 flist_for_each(entry, &client_list) {
968 client = flist_entry(entry, struct fio_client, list);
970 if (!flist_empty(&client->eta_list)) {
974 if (client->state != Client_running)
977 assert(!client->eta_in_flight);
978 flist_add_tail(&client->eta_list, &eta_list);
979 client->eta_in_flight = eta;
980 fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_SEND_ETA,
981 (uintptr_t) eta, &client->cmd_list);
987 dprint(FD_NET, "client: requested eta tag %p\n", eta);
990 static int client_check_cmd_timeout(struct fio_client *client,
993 struct fio_net_int_cmd *cmd;
994 struct flist_head *entry, *tmp;
997 flist_for_each_safe(entry, tmp, &client->cmd_list) {
998 cmd = flist_entry(entry, struct fio_net_int_cmd, list);
1000 if (mtime_since(&cmd->tv, now) < FIO_NET_CLIENT_TIMEOUT)
1003 log_err("fio: client %s, timeout on cmd %s\n", client->hostname,
1004 fio_server_op(cmd->cmd.opcode));
1005 flist_del(&cmd->list);
1010 return flist_empty(&client->cmd_list) && ret;
1013 static int fio_client_timed_out(void)
1015 struct fio_client *client;
1016 struct flist_head *entry, *tmp;
1020 gettimeofday(&tv, NULL);
1022 flist_for_each_safe(entry, tmp, &client_list) {
1023 client = flist_entry(entry, struct fio_client, list);
1025 if (flist_empty(&client->cmd_list))
1028 if (!client_check_cmd_timeout(client, &tv))
1031 log_err("fio: client %s timed out\n", client->hostname);
1032 remove_client(client);
1039 int fio_handle_clients(void)
1041 struct pollfd *pfds;
1042 int i, ret = 0, retval = 0;
1044 gettimeofday(&eta_tv, NULL);
1046 pfds = malloc(nr_clients * sizeof(struct pollfd));
1048 sum_stat_clients = nr_clients;
1049 init_thread_stat(&client_ts);
1050 init_group_run_stat(&client_gs);
1052 while (!exit_backend && nr_clients) {
1053 struct flist_head *entry, *tmp;
1054 struct fio_client *client;
1057 flist_for_each_safe(entry, tmp, &client_list) {
1058 client = flist_entry(entry, struct fio_client, list);
1060 if (!client->sent_job &&
1061 flist_empty(&client->cmd_list)) {
1062 remove_client(client);
1066 pfds[i].fd = client->fd;
1067 pfds[i].events = POLLIN;
1074 assert(i == nr_clients);
1079 gettimeofday(&tv, NULL);
1080 if (mtime_since(&eta_tv, &tv) >= 900) {
1081 request_client_etas();
1082 memcpy(&eta_tv, &tv, sizeof(tv));
1084 if (fio_client_timed_out())
1088 ret = poll(pfds, nr_clients, 100);
1092 log_err("fio: poll clients: %s\n", strerror(errno));
1098 for (i = 0; i < nr_clients; i++) {
1099 if (!(pfds[i].revents & POLLIN))
1102 client = find_client_by_fd(pfds[i].fd);
1104 log_err("fio: unknown client fd %d\n", pfds[i].fd);
1107 if (!handle_client(client)) {
1108 log_info("client: host=%s disconnected\n",
1110 remove_client(client);
1112 } else if (client->error)