Update TODO
[fio.git] / client.c
CommitLineData
132159a5
JA
1#include <stdio.h>
2#include <stdlib.h>
3#include <unistd.h>
4#include <limits.h>
5#include <errno.h>
6#include <fcntl.h>
7#include <sys/poll.h>
8#include <sys/types.h>
9#include <sys/stat.h>
10#include <sys/wait.h>
d05c4a03 11#include <sys/socket.h>
87aa8f19 12#include <sys/un.h>
132159a5
JA
13#include <netinet/in.h>
14#include <arpa/inet.h>
15#include <netdb.h>
9e22ecb0 16#include <signal.h>
132159a5
JA
17
18#include "fio.h"
19#include "server.h"
b66570dc 20#include "flist.h"
3c5f57e3 21#include "hash.h"
132159a5 22
b66570dc
JA
23struct fio_client {
24 struct flist_head list;
bebe6398 25 struct flist_head hash_list;
b66570dc 26 struct sockaddr_in addr;
87aa8f19 27 struct sockaddr_un addr_un;
b66570dc 28 char *hostname;
bebe6398 29 int port;
b66570dc 30 int fd;
81179eec 31
b5296ddb
JA
32 char *name;
33
81179eec 34 int state;
17dd1764 35 int skip_newline;
87aa8f19 36 int is_sock;
81179eec
JA
37
38 uint16_t argc;
39 char **argv;
40};
41
42enum {
5c2857f9 43 Client_created = 0,
81179eec
JA
44 Client_connected = 1,
45 Client_started = 2,
46 Client_stopped = 3,
5c2857f9 47 Client_exited = 4,
b66570dc
JA
48};
49
50static FLIST_HEAD(client_list);
b66570dc 51
3c5f57e3
JA
52#define FIO_CLIENT_HASH_BITS 7
53#define FIO_CLIENT_HASH_SZ (1 << FIO_CLIENT_HASH_BITS)
54#define FIO_CLIENT_HASH_MASK (FIO_CLIENT_HASH_SZ - 1)
bebe6398 55static struct flist_head client_hash[FIO_CLIENT_HASH_SZ];
3c5f57e3 56
e951bdc4 57static int handle_client(struct fio_client *client);
0b8f30a5 58
bebe6398 59static void fio_client_add_hash(struct fio_client *client)
3c5f57e3
JA
60{
61 int bucket = hash_long(client->fd, FIO_CLIENT_HASH_BITS);
62
63 bucket &= FIO_CLIENT_HASH_MASK;
bebe6398 64 flist_add(&client->hash_list, &client_hash[bucket]);
3c5f57e3
JA
65}
66
bebe6398 67static void fio_client_remove_hash(struct fio_client *client)
3c5f57e3 68{
bebe6398
JA
69 if (!flist_empty(&client->hash_list))
70 flist_del_init(&client->hash_list);
3c5f57e3
JA
71}
72
73static void fio_init fio_client_hash_init(void)
74{
75 int i;
76
bebe6398
JA
77 for (i = 0; i < FIO_CLIENT_HASH_SZ; i++)
78 INIT_FLIST_HEAD(&client_hash[i]);
3c5f57e3
JA
79}
80
b66570dc
JA
81static struct fio_client *find_client_by_fd(int fd)
82{
3c5f57e3 83 int bucket = hash_long(fd, FIO_CLIENT_HASH_BITS) & FIO_CLIENT_HASH_MASK;
b66570dc
JA
84 struct fio_client *client;
85 struct flist_head *entry;
86
bebe6398
JA
87 flist_for_each(entry, &client_hash[bucket]) {
88 client = flist_entry(entry, struct fio_client, hash_list);
b66570dc
JA
89
90 if (client->fd == fd)
91 return client;
92 }
93
94 return NULL;
95}
96
b66570dc
JA
97static void remove_client(struct fio_client *client)
98{
39e8e016 99 dprint(FD_NET, "client: removed <%s>\n", client->hostname);
b66570dc 100 flist_del(&client->list);
3c5f57e3 101
bebe6398 102 fio_client_remove_hash(client);
81179eec 103
b66570dc 104 free(client->hostname);
81179eec
JA
105 if (client->argv)
106 free(client->argv);
b5296ddb
JA
107 if (client->name)
108 free(client->name);
81179eec 109
b66570dc 110 free(client);
3c5f57e3 111 nr_clients--;
b66570dc 112}
132159a5 113
fa2ea806
JA
114static void __fio_client_add_cmd_option(struct fio_client *client,
115 const char *opt)
81179eec 116{
39e8e016
JA
117 int index;
118
119 index = client->argc++;
81179eec 120 client->argv = realloc(client->argv, sizeof(char *) * client->argc);
39e8e016
JA
121 client->argv[index] = strdup(opt);
122 dprint(FD_NET, "client: add cmd %d: %s\n", index, opt);
81179eec
JA
123}
124
fa2ea806 125void fio_client_add_cmd_option(void *cookie, const char *opt)
81179eec 126{
bebe6398 127 struct fio_client *client = cookie;
81179eec 128
bebe6398 129 if (!client || !opt)
fa2ea806 130 return;
81179eec 131
fa2ea806 132 __fio_client_add_cmd_option(client, opt);
81179eec
JA
133}
134
bebe6398 135int fio_client_add(const char *hostname, void **cookie)
132159a5 136{
b66570dc 137 struct fio_client *client;
132159a5 138
b66570dc 139 client = malloc(sizeof(*client));
a37f69b7 140 memset(client, 0, sizeof(*client));
81179eec 141
3c5f57e3 142 INIT_FLIST_HEAD(&client->list);
bebe6398 143 INIT_FLIST_HEAD(&client->hash_list);
3c5f57e3 144
bebe6398
JA
145 if (fio_server_parse_string(hostname, &client->hostname,
146 &client->is_sock, &client->port,
147 &client->addr.sin_addr))
148 return -1;
87aa8f19 149
bebe6398 150 client->fd = -1;
3c5f57e3 151
81179eec
JA
152 __fio_client_add_cmd_option(client, "fio");
153
a37f69b7
JA
154 flist_add(&client->list, &client_list);
155 nr_clients++;
bebe6398
JA
156 dprint(FD_NET, "client: added <%s>\n", client->hostname);
157 *cookie = client;
158 return 0;
a37f69b7
JA
159}
160
87aa8f19 161static int fio_client_connect_ip(struct fio_client *client)
a37f69b7
JA
162{
163 int fd;
132159a5 164
b66570dc 165 client->addr.sin_family = AF_INET;
bebe6398 166 client->addr.sin_port = htons(client->port);
132159a5
JA
167
168 fd = socket(AF_INET, SOCK_STREAM, 0);
169 if (fd < 0) {
170 log_err("fio: socket: %s\n", strerror(errno));
87aa8f19 171 return -1;
132159a5
JA
172 }
173
b66570dc 174 if (connect(fd, (struct sockaddr *) &client->addr, sizeof(client->addr)) < 0) {
132159a5 175 log_err("fio: connect: %s\n", strerror(errno));
a7de0a11
JA
176 log_err("fio: failed to connect to %s:%u\n", client->hostname,
177 client->port);
b94cba47 178 close(fd);
87aa8f19
JA
179 return -1;
180 }
181
182 return fd;
183}
184
185static int fio_client_connect_sock(struct fio_client *client)
186{
187 struct sockaddr_un *addr = &client->addr_un;
188 fio_socklen_t len;
189 int fd;
190
191 memset(addr, 0, sizeof(*addr));
192 addr->sun_family = AF_UNIX;
193 strcpy(addr->sun_path, client->hostname);
194
195 fd = socket(AF_UNIX, SOCK_STREAM, 0);
196 if (fd < 0) {
197 log_err("fio: socket: %s\n", strerror(errno));
198 return -1;
199 }
200
201 len = sizeof(addr->sun_family) + strlen(addr->sun_path) + 1;
202 if (connect(fd, (struct sockaddr *) addr, len) < 0) {
203 log_err("fio: connect; %s\n", strerror(errno));
b94cba47 204 close(fd);
87aa8f19 205 return -1;
132159a5
JA
206 }
207
87aa8f19
JA
208 return fd;
209}
210
211static int fio_client_connect(struct fio_client *client)
212{
213 int fd;
214
215 dprint(FD_NET, "client: connect to host %s\n", client->hostname);
216
87aa8f19
JA
217 if (client->is_sock)
218 fd = fio_client_connect_sock(client);
219 else
220 fd = fio_client_connect_ip(client);
221
222 if (fd < 0)
223 return 1;
224
b66570dc 225 client->fd = fd;
bebe6398 226 fio_client_add_hash(client);
81179eec 227 client->state = Client_connected;
132159a5
JA
228 return 0;
229}
230
cc0df00a
JA
231void fio_clients_terminate(void)
232{
233 struct flist_head *entry;
234 struct fio_client *client;
235
60efd14e
JA
236 dprint(FD_NET, "client: terminate clients\n");
237
cc0df00a
JA
238 flist_for_each(entry, &client_list) {
239 client = flist_entry(entry, struct fio_client, list);
240
241 fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_QUIT, 0);
242 }
243}
244
245static void sig_int(int sig)
246{
bebe6398 247 dprint(FD_NET, "client: got signal %d\n", sig);
cc0df00a
JA
248 fio_clients_terminate();
249}
250
251static void client_signal_handler(void)
252{
253 struct sigaction act;
254
255 memset(&act, 0, sizeof(act));
256 act.sa_handler = sig_int;
257 act.sa_flags = SA_RESTART;
258 sigaction(SIGINT, &act, NULL);
259
260 memset(&act, 0, sizeof(act));
261 act.sa_handler = sig_int;
262 act.sa_flags = SA_RESTART;
263 sigaction(SIGTERM, &act, NULL);
264}
265
0b8f30a5
JA
266static void probe_client(struct fio_client *client)
267{
60efd14e
JA
268 dprint(FD_NET, "client: send probe\n");
269
0b8f30a5 270 fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_PROBE, 0);
e951bdc4 271 handle_client(client);
0b8f30a5
JA
272}
273
81179eec
JA
274static int send_client_cmd_line(struct fio_client *client)
275{
fa2ea806
JA
276 struct cmd_single_line_pdu *cslp;
277 struct cmd_line_pdu *clp;
278 unsigned long offset;
279 void *pdu;
280 size_t mem;
81179eec
JA
281 int i, ret;
282
39e8e016 283 dprint(FD_NET, "client: send cmdline %d\n", client->argc);
60efd14e 284
fa2ea806
JA
285 /*
286 * Find out how much mem we need
287 */
288 for (i = 0, mem = 0; i < client->argc; i++)
289 mem += strlen(client->argv[i]) + 1;
290
291 /*
292 * We need one cmd_line_pdu, and argc number of cmd_single_line_pdu
293 */
294 mem += sizeof(*clp) + (client->argc * sizeof(*cslp));
295
296 pdu = malloc(mem);
297 clp = pdu;
298 offset = sizeof(*clp);
299
300 for (i = 0; i < client->argc; i++) {
301 uint16_t arg_len = strlen(client->argv[i]) + 1;
302
303 cslp = pdu + offset;
304 strcpy((char *) cslp->text, client->argv[i]);
305 cslp->len = cpu_to_le16(arg_len);
306 offset += sizeof(*cslp) + arg_len;
307 }
81179eec 308
fa2ea806
JA
309 clp->lines = cpu_to_le16(client->argc);
310 ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOBLINE, pdu, mem);
81179eec
JA
311 free(pdu);
312 return ret;
313}
314
a37f69b7
JA
315int fio_clients_connect(void)
316{
317 struct fio_client *client;
318 struct flist_head *entry, *tmp;
319 int ret;
320
60efd14e
JA
321 dprint(FD_NET, "client: connect all\n");
322
cc0df00a
JA
323 client_signal_handler();
324
a37f69b7
JA
325 flist_for_each_safe(entry, tmp, &client_list) {
326 client = flist_entry(entry, struct fio_client, list);
327
328 ret = fio_client_connect(client);
0b8f30a5 329 if (ret) {
a37f69b7 330 remove_client(client);
0b8f30a5
JA
331 continue;
332 }
333
334 probe_client(client);
81179eec
JA
335
336 if (client->argc > 1)
337 send_client_cmd_line(client);
a37f69b7
JA
338 }
339
340 return !nr_clients;
341}
342
132159a5
JA
343/*
344 * Send file contents to server backend. We could use sendfile(), but to remain
345 * more portable lets just read/write the darn thing.
346 */
a37f69b7 347static int fio_client_send_ini(struct fio_client *client, const char *filename)
132159a5
JA
348{
349 struct stat sb;
350 char *p, *buf;
351 off_t len;
352 int fd, ret;
353
46c48f1f
JA
354 dprint(FD_NET, "send ini %s to %s\n", filename, client->hostname);
355
132159a5
JA
356 fd = open(filename, O_RDONLY);
357 if (fd < 0) {
e951bdc4 358 log_err("fio: job file <%s> open: %s\n", filename, strerror(errno));
132159a5
JA
359 return 1;
360 }
361
362 if (fstat(fd, &sb) < 0) {
363 log_err("fio: job file stat: %s\n", strerror(errno));
b94cba47 364 close(fd);
132159a5
JA
365 return 1;
366 }
367
368 buf = malloc(sb.st_size);
369
370 len = sb.st_size;
371 p = buf;
372 do {
373 ret = read(fd, p, len);
374 if (ret > 0) {
375 len -= ret;
376 if (!len)
377 break;
378 p += ret;
379 continue;
380 } else if (!ret)
381 break;
382 else if (errno == EAGAIN || errno == EINTR)
383 continue;
384 } while (1);
385
0b8f30a5
JA
386 if (len) {
387 log_err("fio: failed reading job file %s\n", filename);
b94cba47 388 close(fd);
c524ef72 389 free(buf);
0b8f30a5
JA
390 return 1;
391 }
392
81179eec 393 ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOB, buf, sb.st_size);
132159a5 394 free(buf);
b94cba47 395 close(fd);
132159a5
JA
396 return ret;
397}
37db14fe 398
a37f69b7
JA
399int fio_clients_send_ini(const char *filename)
400{
401 struct fio_client *client;
402 struct flist_head *entry, *tmp;
403
404 flist_for_each_safe(entry, tmp, &client_list) {
405 client = flist_entry(entry, struct fio_client, list);
406
407 if (fio_client_send_ini(client, filename))
408 remove_client(client);
409 }
410
411 return !nr_clients;
412}
413
a64e88da
JA
414static void convert_io_stat(struct io_stat *dst, struct io_stat *src)
415{
416 dst->max_val = le64_to_cpu(src->max_val);
417 dst->min_val = le64_to_cpu(src->min_val);
418 dst->samples = le64_to_cpu(src->samples);
802ad4a8
JA
419
420 /*
421 * Floats arrive as IEEE 754 encoded uint64_t, convert back to double
422 */
423 dst->mean.u.f = fio_uint64_to_double(le64_to_cpu(dst->mean.u.i));
424 dst->S.u.f = fio_uint64_to_double(le64_to_cpu(dst->S.u.i));
a64e88da
JA
425}
426
427static void convert_ts(struct thread_stat *dst, struct thread_stat *src)
428{
429 int i, j;
430
431 dst->error = le32_to_cpu(src->error);
432 dst->groupid = le32_to_cpu(src->groupid);
433 dst->pid = le32_to_cpu(src->pid);
434 dst->members = le32_to_cpu(src->members);
435
436 for (i = 0; i < 2; i++) {
437 convert_io_stat(&dst->clat_stat[i], &src->clat_stat[i]);
438 convert_io_stat(&dst->slat_stat[i], &src->slat_stat[i]);
439 convert_io_stat(&dst->lat_stat[i], &src->lat_stat[i]);
440 convert_io_stat(&dst->bw_stat[i], &src->bw_stat[i]);
441 }
442
443 dst->usr_time = le64_to_cpu(src->usr_time);
444 dst->sys_time = le64_to_cpu(src->sys_time);
445 dst->ctx = le64_to_cpu(src->ctx);
446 dst->minf = le64_to_cpu(src->minf);
447 dst->majf = le64_to_cpu(src->majf);
448 dst->clat_percentiles = le64_to_cpu(src->clat_percentiles);
802ad4a8
JA
449
450 for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) {
451 fio_fp64_t *fps = &src->percentile_list[i];
452 fio_fp64_t *fpd = &dst->percentile_list[i];
453
454 fpd->u.f = fio_uint64_to_double(le64_to_cpu(fps->u.i));
455 }
a64e88da
JA
456
457 for (i = 0; i < FIO_IO_U_MAP_NR; i++) {
458 dst->io_u_map[i] = le32_to_cpu(src->io_u_map[i]);
459 dst->io_u_submit[i] = le32_to_cpu(src->io_u_submit[i]);
460 dst->io_u_complete[i] = le32_to_cpu(src->io_u_complete[i]);
461 }
462
463 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) {
464 dst->io_u_lat_u[i] = le32_to_cpu(src->io_u_lat_u[i]);
465 dst->io_u_lat_m[i] = le32_to_cpu(src->io_u_lat_m[i]);
466 }
467
468 for (i = 0; i < 2; i++)
469 for (j = 0; j < FIO_IO_U_PLAT_NR; j++)
470 dst->io_u_plat[i][j] = le32_to_cpu(src->io_u_plat[i][j]);
471
472 for (i = 0; i < 3; i++) {
473 dst->total_io_u[i] = le64_to_cpu(src->total_io_u[i]);
93eee04a 474 dst->short_io_u[i] = le64_to_cpu(src->short_io_u[i]);
a64e88da
JA
475 }
476
477 dst->total_submit = le64_to_cpu(src->total_submit);
478 dst->total_complete = le64_to_cpu(src->total_complete);
479
480 for (i = 0; i < 2; i++) {
481 dst->io_bytes[i] = le64_to_cpu(src->io_bytes[i]);
482 dst->runtime[i] = le64_to_cpu(src->runtime[i]);
483 }
484
485 dst->total_run_time = le64_to_cpu(src->total_run_time);
486 dst->continue_on_error = le16_to_cpu(src->continue_on_error);
487 dst->total_err_count = le64_to_cpu(src->total_err_count);
ddcc0b69
JA
488 dst->first_error = le32_to_cpu(src->first_error);
489 dst->kb_base = le32_to_cpu(src->kb_base);
a64e88da
JA
490}
491
492static void convert_gs(struct group_run_stats *dst, struct group_run_stats *src)
493{
494 int i;
495
496 for (i = 0; i < 2; i++) {
497 dst->max_run[i] = le64_to_cpu(src->max_run[i]);
498 dst->min_run[i] = le64_to_cpu(src->min_run[i]);
499 dst->max_bw[i] = le64_to_cpu(src->max_bw[i]);
500 dst->min_bw[i] = le64_to_cpu(src->min_bw[i]);
501 dst->io_kb[i] = le64_to_cpu(src->io_kb[i]);
502 dst->agg[i] = le64_to_cpu(src->agg[i]);
503 }
504
505 dst->kb_base = le32_to_cpu(src->kb_base);
506 dst->groupid = le32_to_cpu(src->groupid);
507}
508
509static void handle_ts(struct fio_net_cmd *cmd)
510{
511 struct cmd_ts_pdu *p = (struct cmd_ts_pdu *) cmd->payload;
512
513 convert_ts(&p->ts, &p->ts);
514 convert_gs(&p->rs, &p->rs);
515
516 show_thread_status(&p->ts, &p->rs);
517}
518
519static void handle_gs(struct fio_net_cmd *cmd)
520{
521 struct group_run_stats *gs = (struct group_run_stats *) cmd->payload;
522
523 convert_gs(gs, gs);
524 show_group_stats(gs);
525}
526
cf451d1e
JA
527static void handle_eta(struct fio_net_cmd *cmd)
528{
529 struct jobs_eta *je = (struct jobs_eta *) cmd->payload;
530 int i;
531
532 je->nr_running = le32_to_cpu(je->nr_running);
533 je->nr_ramp = le32_to_cpu(je->nr_ramp);
534 je->nr_pending = le32_to_cpu(je->nr_pending);
535 je->files_open = le32_to_cpu(je->files_open);
536 je->m_rate = le32_to_cpu(je->m_rate);
537 je->t_rate = le32_to_cpu(je->t_rate);
538 je->m_iops = le32_to_cpu(je->m_iops);
539 je->t_iops = le32_to_cpu(je->t_iops);
540
541 for (i = 0; i < 2; i++) {
542 je->rate[i] = le32_to_cpu(je->rate[i]);
543 je->iops[i] = le32_to_cpu(je->iops[i]);
544 }
545
546 je->elapsed_sec = le32_to_cpu(je->nr_running);
547 je->eta_sec = le64_to_cpu(je->eta_sec);
548
549 display_thread_status(je);
550}
551
b5296ddb 552static void handle_probe(struct fio_client *client, struct fio_net_cmd *cmd)
2e03b4b2
JA
553{
554 struct cmd_probe_pdu *probe = (struct cmd_probe_pdu *) cmd->payload;
cca84643 555 const char *os, *arch;
2e03b4b2 556
cca84643
JA
557 os = fio_get_os_string(probe->os);
558 if (!os)
559 os = "unknown";
560
561 arch = fio_get_arch_string(probe->arch);
562 if (!arch)
563 os = "unknown";
564
c71233ee 565 log_info("hostname=%s, be=%u, os=%s, arch=%s, fio=%u.%u.%u\n",
cca84643 566 probe->hostname, probe->bigendian, os, arch, probe->fio_major,
6eb24791 567 probe->fio_minor, probe->fio_patch);
b5296ddb
JA
568
569 if (!client->name)
570 client->name = strdup((char *) probe->hostname);
2e03b4b2
JA
571}
572
e951bdc4 573static int handle_client(struct fio_client *client)
37db14fe
JA
574{
575 struct fio_net_cmd *cmd;
576
60efd14e
JA
577 dprint(FD_NET, "client: handle %s\n", client->hostname);
578
e951bdc4
JA
579 cmd = fio_net_recv_cmd(client->fd);
580 if (!cmd)
581 return 0;
c2c94585 582
e951bdc4 583 dprint(FD_NET, "client: got cmd op %d from %s\n",
c2c94585 584 cmd->opcode, client->hostname);
46c48f1f 585
e951bdc4
JA
586 switch (cmd->opcode) {
587 case FIO_NET_CMD_QUIT:
588 remove_client(client);
589 free(cmd);
590 break;
591 case FIO_NET_CMD_TEXT: {
592 const char *buf = (const char *) cmd->payload;
b5296ddb 593 const char *name;
e951bdc4
JA
594 int fio_unused ret;
595
b5296ddb
JA
596 name = client->name ? client->name : client->hostname;
597
e951bdc4 598 if (!client->skip_newline)
b5296ddb 599 fprintf(f_out, "<%s> ", name);
e951bdc4
JA
600 ret = fwrite(buf, cmd->pdu_len, 1, f_out);
601 fflush(f_out);
602 client->skip_newline = strchr(buf, '\n') == NULL;
603 free(cmd);
604 break;
37db14fe 605 }
e951bdc4
JA
606 case FIO_NET_CMD_TS:
607 handle_ts(cmd);
608 free(cmd);
609 break;
610 case FIO_NET_CMD_GS:
611 handle_gs(cmd);
612 free(cmd);
613 break;
614 case FIO_NET_CMD_ETA:
615 handle_eta(cmd);
616 free(cmd);
617 break;
618 case FIO_NET_CMD_PROBE:
b5296ddb 619 handle_probe(client, cmd);
e951bdc4
JA
620 free(cmd);
621 break;
622 case FIO_NET_CMD_START:
623 client->state = Client_started;
624 free(cmd);
625 break;
626 case FIO_NET_CMD_STOP:
627 client->state = Client_stopped;
628 free(cmd);
629 break;
630 default:
631 log_err("fio: unknown client op: %d\n", cmd->opcode);
632 free(cmd);
633 break;
37db14fe
JA
634 }
635
e951bdc4 636 return 1;
37db14fe 637}
b66570dc
JA
638
639int fio_handle_clients(void)
640{
641 struct fio_client *client;
642 struct flist_head *entry;
643 struct pollfd *pfds;
82a4be1b 644 int i, ret = 0;
b66570dc
JA
645
646 pfds = malloc(nr_clients * sizeof(struct pollfd));
647
82a4be1b
JA
648 while (!exit_backend && nr_clients) {
649 i = 0;
650 flist_for_each(entry, &client_list) {
651 client = flist_entry(entry, struct fio_client, list);
b66570dc 652
82a4be1b
JA
653 pfds[i].fd = client->fd;
654 pfds[i].events = POLLIN;
655 i++;
656 }
657
658 assert(i == nr_clients);
b66570dc 659
5c2857f9
JA
660 do {
661 ret = poll(pfds, nr_clients, 100);
662 if (ret < 0) {
663 if (errno == EINTR)
664 continue;
665 log_err("fio: poll clients: %s\n", strerror(errno));
666 break;
667 } else if (!ret)
b66570dc 668 continue;
5c2857f9 669 } while (ret <= 0);
b66570dc
JA
670
671 for (i = 0; i < nr_clients; i++) {
672 if (!(pfds[i].revents & POLLIN))
673 continue;
674
675 client = find_client_by_fd(pfds[i].fd);
676 if (!client) {
3c5f57e3 677 log_err("fio: unknown client fd %d\n", pfds[i].fd);
b66570dc
JA
678 continue;
679 }
e951bdc4 680 if (!handle_client(client)) {
28d3ab07
JA
681 log_info("client: host=%s disconnected\n",
682 client->hostname);
683 remove_client(client);
684 }
b66570dc
JA
685 }
686 }
687
688 free(pfds);
b66570dc
JA
689 return 0;
690}