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;
52 struct flist_head eta_list;
53 struct client_eta *eta_in_flight;
55 struct flist_head cmd_list;
61 static struct timeval eta_tv;
72 static FLIST_HEAD(client_list);
73 static FLIST_HEAD(eta_list);
75 static FLIST_HEAD(arg_list);
77 static struct thread_stat client_ts;
78 static struct group_run_stats client_gs;
79 static int sum_stat_clients;
80 static int sum_stat_nr;
82 #define FIO_CLIENT_HASH_BITS 7
83 #define FIO_CLIENT_HASH_SZ (1 << FIO_CLIENT_HASH_BITS)
84 #define FIO_CLIENT_HASH_MASK (FIO_CLIENT_HASH_SZ - 1)
85 static struct flist_head client_hash[FIO_CLIENT_HASH_SZ];
87 static int handle_client(struct fio_client *client);
88 static void dec_jobs_eta(struct client_eta *eta);
90 static void fio_client_add_hash(struct fio_client *client)
92 int bucket = hash_long(client->fd, FIO_CLIENT_HASH_BITS);
94 bucket &= FIO_CLIENT_HASH_MASK;
95 flist_add(&client->hash_list, &client_hash[bucket]);
98 static void fio_client_remove_hash(struct fio_client *client)
100 if (!flist_empty(&client->hash_list))
101 flist_del_init(&client->hash_list);
104 static void fio_init fio_client_hash_init(void)
108 for (i = 0; i < FIO_CLIENT_HASH_SZ; i++)
109 INIT_FLIST_HEAD(&client_hash[i]);
112 static struct fio_client *find_client_by_fd(int fd)
114 int bucket = hash_long(fd, FIO_CLIENT_HASH_BITS) & FIO_CLIENT_HASH_MASK;
115 struct fio_client *client;
116 struct flist_head *entry;
118 flist_for_each(entry, &client_hash[bucket]) {
119 client = flist_entry(entry, struct fio_client, hash_list);
121 if (client->fd == fd)
128 static void remove_client(struct fio_client *client)
130 dprint(FD_NET, "client: removed <%s>\n", client->hostname);
131 flist_del(&client->list);
133 fio_client_remove_hash(client);
135 if (!flist_empty(&client->eta_list)) {
136 flist_del_init(&client->eta_list);
137 dec_jobs_eta(client->eta_in_flight);
140 free(client->hostname);
151 static void __fio_client_add_cmd_option(struct fio_client *client,
156 index = client->argc++;
157 client->argv = realloc(client->argv, sizeof(char *) * client->argc);
158 client->argv[index] = strdup(opt);
159 dprint(FD_NET, "client: add cmd %d: %s\n", index, opt);
162 void fio_client_add_cmd_option(void *cookie, const char *opt)
164 struct fio_client *client = cookie;
165 struct flist_head *entry;
170 __fio_client_add_cmd_option(client, opt);
173 * Duplicate arguments to shared client group
175 flist_for_each(entry, &arg_list) {
176 client = flist_entry(entry, struct fio_client, arg_list);
178 __fio_client_add_cmd_option(client, opt);
182 int fio_client_add(const char *hostname, void **cookie)
184 struct fio_client *existing = *cookie;
185 struct fio_client *client;
189 * We always add our "exec" name as the option, hence 1
192 if (existing->argc == 1)
193 flist_add_tail(&existing->arg_list, &arg_list);
195 while (!flist_empty(&arg_list))
196 flist_del_init(arg_list.next);
200 client = malloc(sizeof(*client));
201 memset(client, 0, sizeof(*client));
203 INIT_FLIST_HEAD(&client->list);
204 INIT_FLIST_HEAD(&client->hash_list);
205 INIT_FLIST_HEAD(&client->arg_list);
206 INIT_FLIST_HEAD(&client->eta_list);
207 INIT_FLIST_HEAD(&client->cmd_list);
209 if (fio_server_parse_string(hostname, &client->hostname,
210 &client->is_sock, &client->port,
211 &client->addr.sin_addr,
212 &client->addr6.sin6_addr,
218 __fio_client_add_cmd_option(client, "fio");
220 flist_add(&client->list, &client_list);
222 dprint(FD_NET, "client: added <%s>\n", client->hostname);
227 static int fio_client_connect_ip(struct fio_client *client)
229 struct sockaddr *addr;
230 fio_socklen_t socklen;
234 client->addr6.sin6_family = AF_INET6;
235 client->addr6.sin6_port = htons(client->port);
237 addr = (struct sockaddr *) &client->addr6;
238 socklen = sizeof(client->addr6);
240 client->addr.sin_family = AF_INET;
241 client->addr.sin_port = htons(client->port);
243 addr = (struct sockaddr *) &client->addr;
244 socklen = sizeof(client->addr);
247 fd = socket(domain, SOCK_STREAM, 0);
249 log_err("fio: socket: %s\n", strerror(errno));
253 if (connect(fd, addr, socklen) < 0) {
254 log_err("fio: connect: %s\n", strerror(errno));
255 log_err("fio: failed to connect to %s:%u\n", client->hostname,
264 static int fio_client_connect_sock(struct fio_client *client)
266 struct sockaddr_un *addr = &client->addr_un;
270 memset(addr, 0, sizeof(*addr));
271 addr->sun_family = AF_UNIX;
272 strcpy(addr->sun_path, client->hostname);
274 fd = socket(AF_UNIX, SOCK_STREAM, 0);
276 log_err("fio: socket: %s\n", strerror(errno));
280 len = sizeof(addr->sun_family) + strlen(addr->sun_path) + 1;
281 if (connect(fd, (struct sockaddr *) addr, len) < 0) {
282 log_err("fio: connect; %s\n", strerror(errno));
290 static int fio_client_connect(struct fio_client *client)
294 dprint(FD_NET, "client: connect to host %s\n", client->hostname);
297 fd = fio_client_connect_sock(client);
299 fd = fio_client_connect_ip(client);
301 dprint(FD_NET, "client: %s connected %d\n", client->hostname, fd);
307 fio_client_add_hash(client);
308 client->state = Client_connected;
312 void fio_clients_terminate(void)
314 struct flist_head *entry;
315 struct fio_client *client;
317 dprint(FD_NET, "client: terminate clients\n");
319 flist_for_each(entry, &client_list) {
320 client = flist_entry(entry, struct fio_client, list);
322 fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_QUIT, 0, NULL);
326 static void sig_int(int sig)
328 dprint(FD_NET, "client: got signal %d\n", sig);
329 fio_clients_terminate();
332 static void client_signal_handler(void)
334 struct sigaction act;
336 memset(&act, 0, sizeof(act));
337 act.sa_handler = sig_int;
338 act.sa_flags = SA_RESTART;
339 sigaction(SIGINT, &act, NULL);
341 memset(&act, 0, sizeof(act));
342 act.sa_handler = sig_int;
343 act.sa_flags = SA_RESTART;
344 sigaction(SIGTERM, &act, NULL);
347 static void probe_client(struct fio_client *client)
349 dprint(FD_NET, "client: send probe\n");
351 fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_PROBE, 0, &client->cmd_list);
354 static int send_client_cmd_line(struct fio_client *client)
356 struct cmd_single_line_pdu *cslp;
357 struct cmd_line_pdu *clp;
358 unsigned long offset;
364 dprint(FD_NET, "client: send cmdline %d\n", client->argc);
366 lens = malloc(client->argc * sizeof(unsigned int));
369 * Find out how much mem we need
371 for (i = 0, mem = 0; i < client->argc; i++) {
372 lens[i] = strlen(client->argv[i]) + 1;
377 * We need one cmd_line_pdu, and argc number of cmd_single_line_pdu
379 mem += sizeof(*clp) + (client->argc * sizeof(*cslp));
383 offset = sizeof(*clp);
385 for (i = 0; i < client->argc; i++) {
386 uint16_t arg_len = lens[i];
389 strcpy((char *) cslp->text, client->argv[i]);
390 cslp->len = cpu_to_le16(arg_len);
391 offset += sizeof(*cslp) + arg_len;
395 clp->lines = cpu_to_le16(client->argc);
396 ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOBLINE, pdu, mem, 0);
401 int fio_clients_connect(void)
403 struct fio_client *client;
404 struct flist_head *entry, *tmp;
409 WSAStartup(MAKEWORD(2,2), &wsd);
412 dprint(FD_NET, "client: connect all\n");
414 client_signal_handler();
416 flist_for_each_safe(entry, tmp, &client_list) {
417 client = flist_entry(entry, struct fio_client, list);
419 ret = fio_client_connect(client);
421 remove_client(client);
425 probe_client(client);
427 if (client->argc > 1)
428 send_client_cmd_line(client);
435 * Send file contents to server backend. We could use sendfile(), but to remain
436 * more portable lets just read/write the darn thing.
438 static int fio_client_send_ini(struct fio_client *client, const char *filename)
445 dprint(FD_NET, "send ini %s to %s\n", filename, client->hostname);
447 fd = open(filename, O_RDONLY);
449 log_err("fio: job file <%s> open: %s\n", filename, strerror(errno));
453 if (fstat(fd, &sb) < 0) {
454 log_err("fio: job file stat: %s\n", strerror(errno));
459 buf = malloc(sb.st_size);
464 ret = read(fd, p, len);
473 else if (errno == EAGAIN || errno == EINTR)
478 log_err("fio: failed reading job file %s\n", filename);
484 ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOB, buf, sb.st_size, 0);
490 int fio_clients_send_ini(const char *filename)
492 struct fio_client *client;
493 struct flist_head *entry, *tmp;
495 flist_for_each_safe(entry, tmp, &client_list) {
496 client = flist_entry(entry, struct fio_client, list);
498 if (fio_client_send_ini(client, filename))
499 remove_client(client);
505 static void convert_io_stat(struct io_stat *dst, struct io_stat *src)
507 dst->max_val = le64_to_cpu(src->max_val);
508 dst->min_val = le64_to_cpu(src->min_val);
509 dst->samples = le64_to_cpu(src->samples);
512 * Floats arrive as IEEE 754 encoded uint64_t, convert back to double
514 dst->mean.u.f = fio_uint64_to_double(le64_to_cpu(dst->mean.u.i));
515 dst->S.u.f = fio_uint64_to_double(le64_to_cpu(dst->S.u.i));
518 static void convert_ts(struct thread_stat *dst, struct thread_stat *src)
522 dst->error = le32_to_cpu(src->error);
523 dst->groupid = le32_to_cpu(src->groupid);
524 dst->pid = le32_to_cpu(src->pid);
525 dst->members = le32_to_cpu(src->members);
527 for (i = 0; i < 2; i++) {
528 convert_io_stat(&dst->clat_stat[i], &src->clat_stat[i]);
529 convert_io_stat(&dst->slat_stat[i], &src->slat_stat[i]);
530 convert_io_stat(&dst->lat_stat[i], &src->lat_stat[i]);
531 convert_io_stat(&dst->bw_stat[i], &src->bw_stat[i]);
534 dst->usr_time = le64_to_cpu(src->usr_time);
535 dst->sys_time = le64_to_cpu(src->sys_time);
536 dst->ctx = le64_to_cpu(src->ctx);
537 dst->minf = le64_to_cpu(src->minf);
538 dst->majf = le64_to_cpu(src->majf);
539 dst->clat_percentiles = le64_to_cpu(src->clat_percentiles);
541 for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) {
542 fio_fp64_t *fps = &src->percentile_list[i];
543 fio_fp64_t *fpd = &dst->percentile_list[i];
545 fpd->u.f = fio_uint64_to_double(le64_to_cpu(fps->u.i));
548 for (i = 0; i < FIO_IO_U_MAP_NR; i++) {
549 dst->io_u_map[i] = le32_to_cpu(src->io_u_map[i]);
550 dst->io_u_submit[i] = le32_to_cpu(src->io_u_submit[i]);
551 dst->io_u_complete[i] = le32_to_cpu(src->io_u_complete[i]);
554 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) {
555 dst->io_u_lat_u[i] = le32_to_cpu(src->io_u_lat_u[i]);
556 dst->io_u_lat_m[i] = le32_to_cpu(src->io_u_lat_m[i]);
559 for (i = 0; i < 2; i++)
560 for (j = 0; j < FIO_IO_U_PLAT_NR; j++)
561 dst->io_u_plat[i][j] = le32_to_cpu(src->io_u_plat[i][j]);
563 for (i = 0; i < 3; i++) {
564 dst->total_io_u[i] = le64_to_cpu(src->total_io_u[i]);
565 dst->short_io_u[i] = le64_to_cpu(src->short_io_u[i]);
568 dst->total_submit = le64_to_cpu(src->total_submit);
569 dst->total_complete = le64_to_cpu(src->total_complete);
571 for (i = 0; i < 2; i++) {
572 dst->io_bytes[i] = le64_to_cpu(src->io_bytes[i]);
573 dst->runtime[i] = le64_to_cpu(src->runtime[i]);
576 dst->total_run_time = le64_to_cpu(src->total_run_time);
577 dst->continue_on_error = le16_to_cpu(src->continue_on_error);
578 dst->total_err_count = le64_to_cpu(src->total_err_count);
579 dst->first_error = le32_to_cpu(src->first_error);
580 dst->kb_base = le32_to_cpu(src->kb_base);
583 static void convert_gs(struct group_run_stats *dst, struct group_run_stats *src)
587 for (i = 0; i < 2; i++) {
588 dst->max_run[i] = le64_to_cpu(src->max_run[i]);
589 dst->min_run[i] = le64_to_cpu(src->min_run[i]);
590 dst->max_bw[i] = le64_to_cpu(src->max_bw[i]);
591 dst->min_bw[i] = le64_to_cpu(src->min_bw[i]);
592 dst->io_kb[i] = le64_to_cpu(src->io_kb[i]);
593 dst->agg[i] = le64_to_cpu(src->agg[i]);
596 dst->kb_base = le32_to_cpu(src->kb_base);
597 dst->groupid = le32_to_cpu(src->groupid);
600 static void handle_ts(struct fio_net_cmd *cmd)
602 struct cmd_ts_pdu *p = (struct cmd_ts_pdu *) cmd->payload;
604 convert_ts(&p->ts, &p->ts);
605 convert_gs(&p->rs, &p->rs);
607 show_thread_status(&p->ts, &p->rs);
609 if (sum_stat_clients == 1)
612 sum_thread_stats(&client_ts, &p->ts, sum_stat_nr);
613 sum_group_stats(&client_gs, &p->rs);
616 client_ts.groupid = p->ts.groupid;
618 if (++sum_stat_nr == sum_stat_clients) {
619 strcpy(client_ts.name, "All clients");
620 show_thread_status(&client_ts, &client_gs);
624 static void handle_gs(struct fio_net_cmd *cmd)
626 struct group_run_stats *gs = (struct group_run_stats *) cmd->payload;
629 show_group_stats(gs);
632 static void convert_agg(struct disk_util_agg *agg)
636 for (i = 0; i < 2; i++) {
637 agg->ios[i] = le32_to_cpu(agg->ios[i]);
638 agg->merges[i] = le32_to_cpu(agg->merges[i]);
639 agg->sectors[i] = le64_to_cpu(agg->sectors[i]);
640 agg->ticks[i] = le32_to_cpu(agg->ticks[i]);
643 agg->io_ticks = le32_to_cpu(agg->io_ticks);
644 agg->time_in_queue = le32_to_cpu(agg->time_in_queue);
645 agg->slavecount = le32_to_cpu(agg->slavecount);
646 agg->max_util.u.f = fio_uint64_to_double(__le64_to_cpu(agg->max_util.u.i));
649 static void convert_dus(struct disk_util_stat *dus)
653 for (i = 0; i < 2; i++) {
654 dus->ios[i] = le32_to_cpu(dus->ios[i]);
655 dus->merges[i] = le32_to_cpu(dus->merges[i]);
656 dus->sectors[i] = le64_to_cpu(dus->sectors[i]);
657 dus->ticks[i] = le32_to_cpu(dus->ticks[i]);
660 dus->io_ticks = le32_to_cpu(dus->io_ticks);
661 dus->time_in_queue = le32_to_cpu(dus->time_in_queue);
662 dus->msec = le64_to_cpu(dus->msec);
665 static void handle_du(struct fio_client *client, struct fio_net_cmd *cmd)
667 struct cmd_du_pdu *du = (struct cmd_du_pdu *) cmd->payload;
669 convert_dus(&du->dus);
670 convert_agg(&du->agg);
672 if (!client->disk_stats_shown) {
673 client->disk_stats_shown = 1;
674 log_info("\nDisk stats (read/write):\n");
677 print_disk_util(&du->dus, &du->agg, terse_output);
680 static void convert_jobs_eta(struct jobs_eta *je)
684 je->nr_running = le32_to_cpu(je->nr_running);
685 je->nr_ramp = le32_to_cpu(je->nr_ramp);
686 je->nr_pending = le32_to_cpu(je->nr_pending);
687 je->files_open = le32_to_cpu(je->files_open);
688 je->m_rate = le32_to_cpu(je->m_rate);
689 je->t_rate = le32_to_cpu(je->t_rate);
690 je->m_iops = le32_to_cpu(je->m_iops);
691 je->t_iops = le32_to_cpu(je->t_iops);
693 for (i = 0; i < 2; i++) {
694 je->rate[i] = le32_to_cpu(je->rate[i]);
695 je->iops[i] = le32_to_cpu(je->iops[i]);
698 je->elapsed_sec = le64_to_cpu(je->elapsed_sec);
699 je->eta_sec = le64_to_cpu(je->eta_sec);
702 static void sum_jobs_eta(struct jobs_eta *dst, struct jobs_eta *je)
706 dst->nr_running += je->nr_running;
707 dst->nr_ramp += je->nr_ramp;
708 dst->nr_pending += je->nr_pending;
709 dst->files_open += je->files_open;
710 dst->m_rate += je->m_rate;
711 dst->t_rate += je->t_rate;
712 dst->m_iops += je->m_iops;
713 dst->t_iops += je->t_iops;
715 for (i = 0; i < 2; i++) {
716 dst->rate[i] += je->rate[i];
717 dst->iops[i] += je->iops[i];
720 dst->elapsed_sec += je->elapsed_sec;
722 if (je->eta_sec > dst->eta_sec)
723 dst->eta_sec = je->eta_sec;
726 static void dec_jobs_eta(struct client_eta *eta)
728 if (!--eta->pending) {
729 display_thread_status(&eta->eta);
734 static void remove_reply_cmd(struct fio_client *client, struct fio_net_cmd *cmd)
736 struct fio_net_int_cmd *icmd = NULL;
737 struct flist_head *entry;
739 flist_for_each(entry, &client->cmd_list) {
740 icmd = flist_entry(entry, struct fio_net_int_cmd, list);
742 if (cmd->tag == (uintptr_t) icmd)
749 log_err("fio: client: unable to find matching tag\n");
753 flist_del(&icmd->list);
754 cmd->tag = icmd->saved_tag;
758 static void handle_eta(struct fio_client *client, struct fio_net_cmd *cmd)
760 struct jobs_eta *je = (struct jobs_eta *) cmd->payload;
761 struct client_eta *eta = (struct client_eta *) (uintptr_t) cmd->tag;
763 dprint(FD_NET, "client: got eta tag %p, %d\n", eta, eta->pending);
765 assert(client->eta_in_flight == eta);
767 client->eta_in_flight = NULL;
768 flist_del_init(&client->eta_list);
770 convert_jobs_eta(je);
771 sum_jobs_eta(&eta->eta, je);
775 static void handle_probe(struct fio_client *client, struct fio_net_cmd *cmd)
777 struct cmd_probe_pdu *probe = (struct cmd_probe_pdu *) cmd->payload;
778 const char *os, *arch;
781 os = fio_get_os_string(probe->os);
785 arch = fio_get_arch_string(probe->arch);
789 sprintf(bit, "%d-bit", probe->bpp * 8);
791 log_info("hostname=%s, be=%u, %s, os=%s, arch=%s, fio=%u.%u.%u\n",
792 probe->hostname, probe->bigendian, bit, os, arch,
793 probe->fio_major, probe->fio_minor, probe->fio_patch);
796 client->name = strdup((char *) probe->hostname);
799 static void handle_start(struct fio_client *client, struct fio_net_cmd *cmd)
801 struct cmd_start_pdu *pdu = (struct cmd_start_pdu *) cmd->payload;
803 client->state = Client_started;
804 client->jobs = le32_to_cpu(pdu->jobs);
807 static void handle_stop(struct fio_client *client, struct fio_net_cmd *cmd)
809 struct cmd_end_pdu *pdu = (struct cmd_end_pdu *) cmd->payload;
811 client->state = Client_stopped;
812 client->error = le32_to_cpu(pdu->error);
815 log_info("client <%s>: exited with error %d\n", client->hostname, client->error);
818 static int handle_client(struct fio_client *client)
820 struct fio_net_cmd *cmd;
822 dprint(FD_NET, "client: handle %s\n", client->hostname);
824 cmd = fio_net_recv_cmd(client->fd);
828 dprint(FD_NET, "client: got cmd op %s from %s\n",
829 fio_server_op(cmd->opcode), client->hostname);
831 switch (cmd->opcode) {
832 case FIO_NET_CMD_QUIT:
833 remove_client(client);
836 case FIO_NET_CMD_TEXT: {
837 const char *buf = (const char *) cmd->payload;
841 name = client->name ? client->name : client->hostname;
843 if (!client->skip_newline)
844 fprintf(f_out, "<%s> ", name);
845 ret = fwrite(buf, cmd->pdu_len, 1, f_out);
847 client->skip_newline = strchr(buf, '\n') == NULL;
852 handle_du(client, cmd);
863 case FIO_NET_CMD_ETA:
864 remove_reply_cmd(client, cmd);
865 handle_eta(client, cmd);
868 case FIO_NET_CMD_PROBE:
869 remove_reply_cmd(client, cmd);
870 handle_probe(client, cmd);
873 case FIO_NET_CMD_RUN:
874 client->state = Client_running;
877 case FIO_NET_CMD_START:
878 handle_start(client, cmd);
881 case FIO_NET_CMD_STOP:
882 handle_stop(client, cmd);
886 log_err("fio: unknown client op: %s\n", fio_server_op(cmd->opcode));
894 static void request_client_etas(void)
896 struct fio_client *client;
897 struct flist_head *entry;
898 struct client_eta *eta;
901 dprint(FD_NET, "client: request eta (%d)\n", nr_clients);
903 eta = malloc(sizeof(*eta));
904 memset(&eta->eta, 0, sizeof(eta->eta));
905 eta->pending = nr_clients;
907 flist_for_each(entry, &client_list) {
908 client = flist_entry(entry, struct fio_client, list);
910 if (!flist_empty(&client->eta_list)) {
914 if (client->state != Client_running)
917 assert(!client->eta_in_flight);
918 flist_add_tail(&client->eta_list, &eta_list);
919 client->eta_in_flight = eta;
920 fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_SEND_ETA,
921 (uintptr_t) eta, &client->cmd_list);
927 dprint(FD_NET, "client: requested eta tag %p\n", eta);
930 static int client_check_cmd_timeout(struct fio_client *client,
933 struct fio_net_int_cmd *cmd;
934 struct flist_head *entry, *tmp;
937 flist_for_each_safe(entry, tmp, &client->cmd_list) {
938 cmd = flist_entry(entry, struct fio_net_int_cmd, list);
940 if (mtime_since(&cmd->tv, now) < FIO_NET_CLIENT_TIMEOUT)
943 log_err("fio: client %s, timeout on cmd %s\n", client->hostname,
944 fio_server_op(cmd->cmd.opcode));
945 flist_del(&cmd->list);
950 return flist_empty(&client->cmd_list) && ret;
953 static int fio_client_timed_out(void)
955 struct fio_client *client;
956 struct flist_head *entry, *tmp;
960 gettimeofday(&tv, NULL);
962 flist_for_each_safe(entry, tmp, &client_list) {
963 client = flist_entry(entry, struct fio_client, list);
965 if (flist_empty(&client->cmd_list))
968 if (!client_check_cmd_timeout(client, &tv))
971 log_err("fio: client %s timed out\n", client->hostname);
972 remove_client(client);
979 int fio_handle_clients(void)
981 struct fio_client *client;
982 struct flist_head *entry;
984 int i, ret = 0, retval = 0;
986 gettimeofday(&eta_tv, NULL);
988 pfds = malloc(nr_clients * sizeof(struct pollfd));
990 sum_stat_clients = nr_clients;
991 init_thread_stat(&client_ts);
992 init_group_run_stat(&client_gs);
994 while (!exit_backend && nr_clients) {
996 flist_for_each(entry, &client_list) {
997 client = flist_entry(entry, struct fio_client, list);
999 pfds[i].fd = client->fd;
1000 pfds[i].events = POLLIN;
1004 assert(i == nr_clients);
1009 gettimeofday(&tv, NULL);
1010 if (mtime_since(&eta_tv, &tv) >= 900) {
1011 request_client_etas();
1012 memcpy(&eta_tv, &tv, sizeof(tv));
1014 if (fio_client_timed_out())
1018 ret = poll(pfds, nr_clients, 100);
1022 log_err("fio: poll clients: %s\n", strerror(errno));
1028 for (i = 0; i < nr_clients; i++) {
1029 if (!(pfds[i].revents & POLLIN))
1032 client = find_client_by_fd(pfds[i].fd);
1034 log_err("fio: unknown client fd %d\n", pfds[i].fd);
1037 if (!handle_client(client)) {
1038 log_info("client: host=%s disconnected\n",
1040 remove_client(client);
1042 } else if (client->error)