client/server: pass ->unit_base properly
[fio.git] / client.c
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>
11 #include <sys/socket.h>
12 #include <sys/un.h>
13 #include <netinet/in.h>
14 #include <arpa/inet.h>
15 #include <netdb.h>
16 #include <signal.h>
17 #include <zlib.h>
18
19 #include "fio.h"
20 #include "client.h"
21 #include "server.h"
22 #include "flist.h"
23 #include "hash.h"
24
25 static void handle_du(struct fio_client *client, struct fio_net_cmd *cmd);
26 static void handle_ts(struct fio_client *client, struct fio_net_cmd *cmd);
27 static void handle_gs(struct fio_client *client, struct fio_net_cmd *cmd);
28 static void handle_probe(struct fio_client *client, struct fio_net_cmd *cmd);
29 static void handle_text(struct fio_client *client, struct fio_net_cmd *cmd);
30 static void handle_stop(struct fio_client *client, struct fio_net_cmd *cmd);
31 static void handle_start(struct fio_client *client, struct fio_net_cmd *cmd);
32
33 struct client_ops fio_client_ops = {
34         .text           = handle_text,
35         .disk_util      = handle_du,
36         .thread_status  = handle_ts,
37         .group_stats    = handle_gs,
38         .stop           = handle_stop,
39         .start          = handle_start,
40         .eta            = display_thread_status,
41         .probe          = handle_probe,
42         .eta_msec       = FIO_CLIENT_DEF_ETA_MSEC,
43         .client_type    = FIO_CLIENT_TYPE_CLI,
44 };
45
46 static struct timeval eta_tv;
47
48 static FLIST_HEAD(client_list);
49 static FLIST_HEAD(eta_list);
50
51 static FLIST_HEAD(arg_list);
52
53 struct thread_stat client_ts;
54 struct group_run_stats client_gs;
55 int sum_stat_clients;
56
57 static int sum_stat_nr;
58 static int do_output_all_clients;
59
60 #define FIO_CLIENT_HASH_BITS    7
61 #define FIO_CLIENT_HASH_SZ      (1 << FIO_CLIENT_HASH_BITS)
62 #define FIO_CLIENT_HASH_MASK    (FIO_CLIENT_HASH_SZ - 1)
63 static struct flist_head client_hash[FIO_CLIENT_HASH_SZ];
64
65 static void fio_client_add_hash(struct fio_client *client)
66 {
67         int bucket = hash_long(client->fd, FIO_CLIENT_HASH_BITS);
68
69         bucket &= FIO_CLIENT_HASH_MASK;
70         flist_add(&client->hash_list, &client_hash[bucket]);
71 }
72
73 static void fio_client_remove_hash(struct fio_client *client)
74 {
75         if (!flist_empty(&client->hash_list))
76                 flist_del_init(&client->hash_list);
77 }
78
79 static void fio_init fio_client_hash_init(void)
80 {
81         int i;
82
83         for (i = 0; i < FIO_CLIENT_HASH_SZ; i++)
84                 INIT_FLIST_HEAD(&client_hash[i]);
85 }
86
87 static struct fio_client *find_client_by_fd(int fd)
88 {
89         int bucket = hash_long(fd, FIO_CLIENT_HASH_BITS) & FIO_CLIENT_HASH_MASK;
90         struct fio_client *client;
91         struct flist_head *entry;
92
93         flist_for_each(entry, &client_hash[bucket]) {
94                 client = flist_entry(entry, struct fio_client, hash_list);
95
96                 if (client->fd == fd) {
97                         client->refs++;
98                         return client;
99                 }
100         }
101
102         return NULL;
103 }
104
105 void fio_put_client(struct fio_client *client)
106 {
107         if (--client->refs)
108                 return;
109
110         free(client->hostname);
111         if (client->argv)
112                 free(client->argv);
113         if (client->name)
114                 free(client->name);
115         while (client->nr_ini_file)
116                 free(client->ini_file[--client->nr_ini_file]);
117         if (client->ini_file)
118                 free(client->ini_file);
119
120         if (!client->did_stat)
121                 sum_stat_clients -= client->nr_stat;
122
123         free(client);
124 }
125
126 static void remove_client(struct fio_client *client)
127 {
128         assert(client->refs);
129
130         dprint(FD_NET, "client: removed <%s>\n", client->hostname);
131
132         if (!flist_empty(&client->list))
133                 flist_del_init(&client->list);
134
135         fio_client_remove_hash(client);
136
137         if (!flist_empty(&client->eta_list)) {
138                 flist_del_init(&client->eta_list);
139                 fio_client_dec_jobs_eta(client->eta_in_flight, client->ops->eta);
140         }
141
142         close(client->fd);
143         client->fd = -1;
144
145         if (client->ops->removed)
146                 client->ops->removed(client);
147
148         nr_clients--;
149         fio_put_client(client);
150 }
151
152 struct fio_client *fio_get_client(struct fio_client *client)
153 {
154         client->refs++;
155         return client;
156 }
157
158 static void __fio_client_add_cmd_option(struct fio_client *client,
159                                         const char *opt)
160 {
161         int index;
162
163         index = client->argc++;
164         client->argv = realloc(client->argv, sizeof(char *) * client->argc);
165         client->argv[index] = strdup(opt);
166         dprint(FD_NET, "client: add cmd %d: %s\n", index, opt);
167 }
168
169 void fio_client_add_cmd_option(void *cookie, const char *opt)
170 {
171         struct fio_client *client = cookie;
172         struct flist_head *entry;
173
174         if (!client || !opt)
175                 return;
176
177         __fio_client_add_cmd_option(client, opt);
178
179         /*
180          * Duplicate arguments to shared client group
181          */
182         flist_for_each(entry, &arg_list) {
183                 client = flist_entry(entry, struct fio_client, arg_list);
184
185                 __fio_client_add_cmd_option(client, opt);
186         }
187 }
188
189 struct fio_client *fio_client_add_explicit(struct client_ops *ops,
190                                            const char *hostname, int type,
191                                            int port)
192 {
193         struct fio_client *client;
194
195         client = malloc(sizeof(*client));
196         memset(client, 0, sizeof(*client));
197
198         INIT_FLIST_HEAD(&client->list);
199         INIT_FLIST_HEAD(&client->hash_list);
200         INIT_FLIST_HEAD(&client->arg_list);
201         INIT_FLIST_HEAD(&client->eta_list);
202         INIT_FLIST_HEAD(&client->cmd_list);
203
204         client->hostname = strdup(hostname);
205
206         if (type == Fio_client_socket)
207                 client->is_sock = 1;
208         else {
209                 int ipv6;
210
211                 ipv6 = type == Fio_client_ipv6;
212                 if (fio_server_parse_host(hostname, &ipv6,
213                                                 &client->addr.sin_addr,
214                                                 &client->addr6.sin6_addr))
215                         goto err;
216
217                 client->port = port;
218         }
219
220         client->fd = -1;
221         client->ops = ops;
222         client->refs = 1;
223         client->type = ops->client_type;
224
225         __fio_client_add_cmd_option(client, "fio");
226
227         flist_add(&client->list, &client_list);
228         nr_clients++;
229         dprint(FD_NET, "client: added <%s>\n", client->hostname);
230         return client;
231 err:
232         free(client);
233         return NULL;
234 }
235
236 void fio_client_add_ini_file(void *cookie, const char *ini_file)
237 {
238         struct fio_client *client = cookie;
239         size_t new_size;
240
241         dprint(FD_NET, "client <%s>: add ini %s\n", client->hostname, ini_file);
242
243         new_size = (client->nr_ini_file + 1) * sizeof(char *);
244         client->ini_file = realloc(client->ini_file, new_size);
245         client->ini_file[client->nr_ini_file] = strdup(ini_file);
246         client->nr_ini_file++;
247 }
248
249 int fio_client_add(struct client_ops *ops, const char *hostname, void **cookie)
250 {
251         struct fio_client *existing = *cookie;
252         struct fio_client *client;
253
254         if (existing) {
255                 /*
256                  * We always add our "exec" name as the option, hence 1
257                  * means empty.
258                  */
259                 if (existing->argc == 1)
260                         flist_add_tail(&existing->arg_list, &arg_list);
261                 else {
262                         while (!flist_empty(&arg_list))
263                                 flist_del_init(arg_list.next);
264                 }
265         }
266
267         client = malloc(sizeof(*client));
268         memset(client, 0, sizeof(*client));
269
270         INIT_FLIST_HEAD(&client->list);
271         INIT_FLIST_HEAD(&client->hash_list);
272         INIT_FLIST_HEAD(&client->arg_list);
273         INIT_FLIST_HEAD(&client->eta_list);
274         INIT_FLIST_HEAD(&client->cmd_list);
275
276         if (fio_server_parse_string(hostname, &client->hostname,
277                                         &client->is_sock, &client->port,
278                                         &client->addr.sin_addr,
279                                         &client->addr6.sin6_addr,
280                                         &client->ipv6))
281                 return -1;
282
283         client->fd = -1;
284         client->ops = ops;
285         client->refs = 1;
286         client->type = ops->client_type;
287
288         __fio_client_add_cmd_option(client, "fio");
289
290         flist_add(&client->list, &client_list);
291         nr_clients++;
292         dprint(FD_NET, "client: added <%s>\n", client->hostname);
293         *cookie = client;
294         return 0;
295 }
296
297 static void probe_client(struct fio_client *client)
298 {
299         dprint(FD_NET, "client: send probe\n");
300
301         fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_PROBE, 0, &client->cmd_list);
302 }
303
304 static int fio_client_connect_ip(struct fio_client *client)
305 {
306         struct sockaddr *addr;
307         socklen_t socklen;
308         int fd, domain;
309
310         if (client->ipv6) {
311                 client->addr6.sin6_family = AF_INET6;
312                 client->addr6.sin6_port = htons(client->port);
313                 domain = AF_INET6;
314                 addr = (struct sockaddr *) &client->addr6;
315                 socklen = sizeof(client->addr6);
316         } else {
317                 client->addr.sin_family = AF_INET;
318                 client->addr.sin_port = htons(client->port);
319                 domain = AF_INET;
320                 addr = (struct sockaddr *) &client->addr;
321                 socklen = sizeof(client->addr);
322         }
323
324         fd = socket(domain, SOCK_STREAM, 0);
325         if (fd < 0) {
326                 int ret = -errno;
327
328                 log_err("fio: socket: %s\n", strerror(errno));
329                 return ret;
330         }
331
332         if (connect(fd, addr, socklen) < 0) {
333                 int ret = -errno;
334
335                 log_err("fio: connect: %s\n", strerror(errno));
336                 log_err("fio: failed to connect to %s:%u\n", client->hostname,
337                                                                 client->port);
338                 close(fd);
339                 return ret;
340         }
341
342         return fd;
343 }
344
345 static int fio_client_connect_sock(struct fio_client *client)
346 {
347         struct sockaddr_un *addr = &client->addr_un;
348         socklen_t len;
349         int fd;
350
351         memset(addr, 0, sizeof(*addr));
352         addr->sun_family = AF_UNIX;
353         strcpy(addr->sun_path, client->hostname);
354
355         fd = socket(AF_UNIX, SOCK_STREAM, 0);
356         if (fd < 0) {
357                 int ret = -errno;
358
359                 log_err("fio: socket: %s\n", strerror(errno));
360                 return ret;
361         }
362
363         len = sizeof(addr->sun_family) + strlen(addr->sun_path) + 1;
364         if (connect(fd, (struct sockaddr *) addr, len) < 0) {
365                 int ret = -errno;
366
367                 log_err("fio: connect; %s\n", strerror(errno));
368                 close(fd);
369                 return ret;
370         }
371
372         return fd;
373 }
374
375 int fio_client_connect(struct fio_client *client)
376 {
377         int fd;
378
379         dprint(FD_NET, "client: connect to host %s\n", client->hostname);
380
381         if (client->is_sock)
382                 fd = fio_client_connect_sock(client);
383         else
384                 fd = fio_client_connect_ip(client);
385
386         dprint(FD_NET, "client: %s connected %d\n", client->hostname, fd);
387
388         if (fd < 0)
389                 return fd;
390
391         client->fd = fd;
392         fio_client_add_hash(client);
393         client->state = Client_connected;
394
395         probe_client(client);
396         return 0;
397 }
398
399 int fio_client_terminate(struct fio_client *client)
400 {
401         return fio_net_send_quit(client->fd);
402 }
403
404 void fio_clients_terminate(void)
405 {
406         struct flist_head *entry;
407         struct fio_client *client;
408
409         dprint(FD_NET, "client: terminate clients\n");
410
411         flist_for_each(entry, &client_list) {
412                 client = flist_entry(entry, struct fio_client, list);
413                 fio_client_terminate(client);
414         }
415 }
416
417 static void sig_int(int sig)
418 {
419         dprint(FD_NET, "client: got signal %d\n", sig);
420         fio_clients_terminate();
421 }
422
423 static void sig_show_status(int sig)
424 {
425         show_running_run_stats();
426 }
427
428 static void client_signal_handler(void)
429 {
430         struct sigaction act;
431
432         memset(&act, 0, sizeof(act));
433         act.sa_handler = sig_int;
434         act.sa_flags = SA_RESTART;
435         sigaction(SIGINT, &act, NULL);
436
437         memset(&act, 0, sizeof(act));
438         act.sa_handler = sig_int;
439         act.sa_flags = SA_RESTART;
440         sigaction(SIGTERM, &act, NULL);
441
442 /* Windows uses SIGBREAK as a quit signal from other applications */
443 #ifdef WIN32
444         memset(&act, 0, sizeof(act));
445         act.sa_handler = sig_int;
446         act.sa_flags = SA_RESTART;
447         sigaction(SIGBREAK, &act, NULL);
448 #endif
449
450         memset(&act, 0, sizeof(act));
451         act.sa_handler = sig_show_status;
452         act.sa_flags = SA_RESTART;
453         sigaction(SIGUSR1, &act, NULL);
454 }
455
456 static int send_client_cmd_line(struct fio_client *client)
457 {
458         struct cmd_single_line_pdu *cslp;
459         struct cmd_line_pdu *clp;
460         unsigned long offset;
461         unsigned int *lens;
462         void *pdu;
463         size_t mem;
464         int i, ret;
465
466         dprint(FD_NET, "client: send cmdline %d\n", client->argc);
467
468         lens = malloc(client->argc * sizeof(unsigned int));
469
470         /*
471          * Find out how much mem we need
472          */
473         for (i = 0, mem = 0; i < client->argc; i++) {
474                 lens[i] = strlen(client->argv[i]) + 1;
475                 mem += lens[i];
476         }
477
478         /*
479          * We need one cmd_line_pdu, and argc number of cmd_single_line_pdu
480          */
481         mem += sizeof(*clp) + (client->argc * sizeof(*cslp));
482
483         pdu = malloc(mem);
484         clp = pdu;
485         offset = sizeof(*clp);
486
487         for (i = 0; i < client->argc; i++) {
488                 uint16_t arg_len = lens[i];
489
490                 cslp = pdu + offset;
491                 strcpy((char *) cslp->text, client->argv[i]);
492                 cslp->len = cpu_to_le16(arg_len);
493                 offset += sizeof(*cslp) + arg_len;
494         }
495
496         free(lens);
497         clp->lines = cpu_to_le16(client->argc);
498         clp->client_type = __cpu_to_le16(client->type);
499         ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOBLINE, pdu, mem, NULL, NULL);
500         free(pdu);
501         return ret;
502 }
503
504 int fio_clients_connect(void)
505 {
506         struct fio_client *client;
507         struct flist_head *entry, *tmp;
508         int ret;
509
510 #ifdef WIN32
511         WSADATA wsd;
512         WSAStartup(MAKEWORD(2, 2), &wsd);
513 #endif
514
515         dprint(FD_NET, "client: connect all\n");
516
517         client_signal_handler();
518
519         flist_for_each_safe(entry, tmp, &client_list) {
520                 client = flist_entry(entry, struct fio_client, list);
521
522                 ret = fio_client_connect(client);
523                 if (ret) {
524                         remove_client(client);
525                         continue;
526                 }
527
528                 if (client->argc > 1)
529                         send_client_cmd_line(client);
530         }
531
532         return !nr_clients;
533 }
534
535 int fio_start_client(struct fio_client *client)
536 {
537         dprint(FD_NET, "client: start %s\n", client->hostname);
538         return fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_RUN, 0, NULL);
539 }
540
541 int fio_start_all_clients(void)
542 {
543         struct fio_client *client;
544         struct flist_head *entry, *tmp;
545         int ret;
546
547         dprint(FD_NET, "client: start all\n");
548
549         flist_for_each_safe(entry, tmp, &client_list) {
550                 client = flist_entry(entry, struct fio_client, list);
551
552                 ret = fio_start_client(client);
553                 if (ret) {
554                         remove_client(client);
555                         continue;
556                 }
557         }
558
559         return flist_empty(&client_list);
560 }
561
562 /*
563  * Send file contents to server backend. We could use sendfile(), but to remain
564  * more portable lets just read/write the darn thing.
565  */
566 static int __fio_client_send_ini(struct fio_client *client, const char *filename)
567 {
568         struct cmd_job_pdu *pdu;
569         size_t p_size;
570         struct stat sb;
571         char *p;
572         void *buf;
573         off_t len;
574         int fd, ret;
575
576         dprint(FD_NET, "send ini %s to %s\n", filename, client->hostname);
577
578         fd = open(filename, O_RDONLY);
579         if (fd < 0) {
580                 int ret = -errno;
581
582                 log_err("fio: job file <%s> open: %s\n", filename, strerror(errno));
583                 return ret;
584         }
585
586         if (fstat(fd, &sb) < 0) {
587                 int ret = -errno;
588
589                 log_err("fio: job file stat: %s\n", strerror(errno));
590                 close(fd);
591                 return ret;
592         }
593
594         p_size = sb.st_size + sizeof(*pdu);
595         pdu = malloc(p_size);
596         buf = pdu->buf;
597
598         len = sb.st_size;
599         p = buf;
600         do {
601                 ret = read(fd, p, len);
602                 if (ret > 0) {
603                         len -= ret;
604                         if (!len)
605                                 break;
606                         p += ret;
607                         continue;
608                 } else if (!ret)
609                         break;
610                 else if (errno == EAGAIN || errno == EINTR)
611                         continue;
612         } while (1);
613
614         if (len) {
615                 log_err("fio: failed reading job file %s\n", filename);
616                 close(fd);
617                 free(buf);
618                 return 1;
619         }
620
621         pdu->buf_len = __cpu_to_le32(sb.st_size);
622         pdu->client_type = cpu_to_le32(client->type);
623
624         client->sent_job = 1;
625         ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOB, pdu, p_size, NULL, NULL);
626         free(pdu);
627         close(fd);
628         return ret;
629 }
630
631 int fio_client_send_ini(struct fio_client *client, const char *filename)
632 {
633         int ret;
634
635         ret = __fio_client_send_ini(client, filename);
636         if (!ret)
637                 client->sent_job = 1;
638
639         return ret;
640 }
641
642 int fio_clients_send_ini(const char *filename)
643 {
644         struct fio_client *client;
645         struct flist_head *entry, *tmp;
646
647         flist_for_each_safe(entry, tmp, &client_list) {
648                 client = flist_entry(entry, struct fio_client, list);
649
650                 if (client->nr_ini_file) {
651                         int i;
652
653                         for (i = 0; i < client->nr_ini_file; i++) {
654                                 const char *ini = client->ini_file[i];
655
656                                 if (fio_client_send_ini(client, ini)) {
657                                         remove_client(client);
658                                         break;
659                                 }
660                         }
661                 } else if (!filename || fio_client_send_ini(client, filename))
662                         remove_client(client);
663         }
664
665         return !nr_clients;
666 }
667
668 int fio_client_update_options(struct fio_client *client,
669                               struct thread_options *o, uint64_t *tag)
670 {
671         struct cmd_add_job_pdu pdu;
672
673         pdu.thread_number = cpu_to_le32(client->thread_number);
674         pdu.groupid = cpu_to_le32(client->groupid);
675         convert_thread_options_to_net(&pdu.top, o);
676         
677         return fio_net_send_cmd(client->fd, FIO_NET_CMD_UPDATE_JOB, &pdu, sizeof(pdu), tag, &client->cmd_list);
678 }
679
680 static void convert_io_stat(struct io_stat *dst, struct io_stat *src)
681 {
682         dst->max_val    = le64_to_cpu(src->max_val);
683         dst->min_val    = le64_to_cpu(src->min_val);
684         dst->samples    = le64_to_cpu(src->samples);
685
686         /*
687          * Floats arrive as IEEE 754 encoded uint64_t, convert back to double
688          */
689         dst->mean.u.f   = fio_uint64_to_double(le64_to_cpu(dst->mean.u.i));
690         dst->S.u.f      = fio_uint64_to_double(le64_to_cpu(dst->S.u.i));
691 }
692
693 static void convert_ts(struct thread_stat *dst, struct thread_stat *src)
694 {
695         int i, j;
696
697         dst->error              = le32_to_cpu(src->error);
698         dst->thread_number      = le32_to_cpu(src->thread_number);
699         dst->groupid            = le32_to_cpu(src->groupid);
700         dst->pid                = le32_to_cpu(src->pid);
701         dst->members            = le32_to_cpu(src->members);
702         dst->unified_rw_rep     = le32_to_cpu(src->unified_rw_rep);
703
704         for (i = 0; i < DDIR_RWDIR_CNT; i++) {
705                 convert_io_stat(&dst->clat_stat[i], &src->clat_stat[i]);
706                 convert_io_stat(&dst->slat_stat[i], &src->slat_stat[i]);
707                 convert_io_stat(&dst->lat_stat[i], &src->lat_stat[i]);
708                 convert_io_stat(&dst->bw_stat[i], &src->bw_stat[i]);
709         }
710
711         dst->usr_time           = le64_to_cpu(src->usr_time);
712         dst->sys_time           = le64_to_cpu(src->sys_time);
713         dst->ctx                = le64_to_cpu(src->ctx);
714         dst->minf               = le64_to_cpu(src->minf);
715         dst->majf               = le64_to_cpu(src->majf);
716         dst->clat_percentiles   = le64_to_cpu(src->clat_percentiles);
717
718         for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) {
719                 fio_fp64_t *fps = &src->percentile_list[i];
720                 fio_fp64_t *fpd = &dst->percentile_list[i];
721
722                 fpd->u.f = fio_uint64_to_double(le64_to_cpu(fps->u.i));
723         }
724
725         for (i = 0; i < FIO_IO_U_MAP_NR; i++) {
726                 dst->io_u_map[i]        = le32_to_cpu(src->io_u_map[i]);
727                 dst->io_u_submit[i]     = le32_to_cpu(src->io_u_submit[i]);
728                 dst->io_u_complete[i]   = le32_to_cpu(src->io_u_complete[i]);
729         }
730
731         for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) {
732                 dst->io_u_lat_u[i]      = le32_to_cpu(src->io_u_lat_u[i]);
733                 dst->io_u_lat_m[i]      = le32_to_cpu(src->io_u_lat_m[i]);
734         }
735
736         for (i = 0; i < DDIR_RWDIR_CNT; i++)
737                 for (j = 0; j < FIO_IO_U_PLAT_NR; j++)
738                         dst->io_u_plat[i][j] = le32_to_cpu(src->io_u_plat[i][j]);
739
740         for (i = 0; i < DDIR_RWDIR_CNT; i++) {
741                 dst->total_io_u[i]      = le64_to_cpu(src->total_io_u[i]);
742                 dst->short_io_u[i]      = le64_to_cpu(src->short_io_u[i]);
743         }
744
745         dst->total_submit       = le64_to_cpu(src->total_submit);
746         dst->total_complete     = le64_to_cpu(src->total_complete);
747
748         for (i = 0; i < DDIR_RWDIR_CNT; i++) {
749                 dst->io_bytes[i]        = le64_to_cpu(src->io_bytes[i]);
750                 dst->runtime[i]         = le64_to_cpu(src->runtime[i]);
751         }
752
753         dst->total_run_time     = le64_to_cpu(src->total_run_time);
754         dst->continue_on_error  = le16_to_cpu(src->continue_on_error);
755         dst->total_err_count    = le64_to_cpu(src->total_err_count);
756         dst->first_error        = le32_to_cpu(src->first_error);
757         dst->kb_base            = le32_to_cpu(src->kb_base);
758         dst->unit_base          = le32_to_cpu(src->unit_base);
759 }
760
761 static void convert_gs(struct group_run_stats *dst, struct group_run_stats *src)
762 {
763         int i;
764
765         for (i = 0; i < DDIR_RWDIR_CNT; i++) {
766                 dst->max_run[i]         = le64_to_cpu(src->max_run[i]);
767                 dst->min_run[i]         = le64_to_cpu(src->min_run[i]);
768                 dst->max_bw[i]          = le64_to_cpu(src->max_bw[i]);
769                 dst->min_bw[i]          = le64_to_cpu(src->min_bw[i]);
770                 dst->io_kb[i]           = le64_to_cpu(src->io_kb[i]);
771                 dst->agg[i]             = le64_to_cpu(src->agg[i]);
772         }
773
774         dst->kb_base    = le32_to_cpu(src->kb_base);
775         dst->unit_base  = le32_to_cpu(src->unit_base);
776         dst->groupid    = le32_to_cpu(src->groupid);
777         dst->unified_rw_rep     = le32_to_cpu(src->unified_rw_rep);
778 }
779
780 static void handle_ts(struct fio_client *client, struct fio_net_cmd *cmd)
781 {
782         struct cmd_ts_pdu *p = (struct cmd_ts_pdu *) cmd->payload;
783
784         show_thread_status(&p->ts, &p->rs);
785         client->did_stat = 1;
786
787         if (!do_output_all_clients)
788                 return;
789
790         sum_thread_stats(&client_ts, &p->ts, sum_stat_nr);
791         sum_group_stats(&client_gs, &p->rs);
792
793         client_ts.members++;
794         client_ts.thread_number = p->ts.thread_number;
795         client_ts.groupid = p->ts.groupid;
796         client_ts.unified_rw_rep = p->ts.unified_rw_rep;
797
798         if (++sum_stat_nr == sum_stat_clients) {
799                 strcpy(client_ts.name, "All clients");
800                 show_thread_status(&client_ts, &client_gs);
801         }
802 }
803
804 static void handle_gs(struct fio_client *client, struct fio_net_cmd *cmd)
805 {
806         struct group_run_stats *gs = (struct group_run_stats *) cmd->payload;
807
808         show_group_stats(gs);
809 }
810
811 static void handle_text(struct fio_client *client, struct fio_net_cmd *cmd)
812 {
813         struct cmd_text_pdu *pdu = (struct cmd_text_pdu *) cmd->payload;
814         const char *buf = (const char *) pdu->buf;
815         const char *name;
816         int fio_unused ret;
817
818         name = client->name ? client->name : client->hostname;
819
820         if (!client->skip_newline)
821                 fprintf(f_out, "<%s> ", name);
822         ret = fwrite(buf, pdu->buf_len, 1, f_out);
823         fflush(f_out);
824         client->skip_newline = strchr(buf, '\n') == NULL;
825 }
826
827 static void convert_agg(struct disk_util_agg *agg)
828 {
829         int i;
830
831         for (i = 0; i < 2; i++) {
832                 agg->ios[i]     = le32_to_cpu(agg->ios[i]);
833                 agg->merges[i]  = le32_to_cpu(agg->merges[i]);
834                 agg->sectors[i] = le64_to_cpu(agg->sectors[i]);
835                 agg->ticks[i]   = le32_to_cpu(agg->ticks[i]);
836         }
837
838         agg->io_ticks           = le32_to_cpu(agg->io_ticks);
839         agg->time_in_queue      = le32_to_cpu(agg->time_in_queue);
840         agg->slavecount         = le32_to_cpu(agg->slavecount);
841         agg->max_util.u.f       = fio_uint64_to_double(__le64_to_cpu(agg->max_util.u.i));
842 }
843
844 static void convert_dus(struct disk_util_stat *dus)
845 {
846         int i;
847
848         for (i = 0; i < 2; i++) {
849                 dus->ios[i]     = le32_to_cpu(dus->ios[i]);
850                 dus->merges[i]  = le32_to_cpu(dus->merges[i]);
851                 dus->sectors[i] = le64_to_cpu(dus->sectors[i]);
852                 dus->ticks[i]   = le32_to_cpu(dus->ticks[i]);
853         }
854
855         dus->io_ticks           = le32_to_cpu(dus->io_ticks);
856         dus->time_in_queue      = le32_to_cpu(dus->time_in_queue);
857         dus->msec               = le64_to_cpu(dus->msec);
858 }
859
860 static void handle_du(struct fio_client *client, struct fio_net_cmd *cmd)
861 {
862         struct cmd_du_pdu *du = (struct cmd_du_pdu *) cmd->payload;
863
864         if (!client->disk_stats_shown) {
865                 client->disk_stats_shown = 1;
866                 log_info("\nDisk stats (read/write):\n");
867         }
868
869         print_disk_util(&du->dus, &du->agg, output_format == FIO_OUTPUT_TERSE);
870 }
871
872 static void convert_jobs_eta(struct jobs_eta *je)
873 {
874         int i;
875
876         je->nr_running          = le32_to_cpu(je->nr_running);
877         je->nr_ramp             = le32_to_cpu(je->nr_ramp);
878         je->nr_pending          = le32_to_cpu(je->nr_pending);
879         je->files_open          = le32_to_cpu(je->files_open);
880
881         for (i = 0; i < DDIR_RWDIR_CNT; i++) {
882                 je->m_rate[i]   = le32_to_cpu(je->m_rate[i]);
883                 je->t_rate[i]   = le32_to_cpu(je->t_rate[i]);
884                 je->m_iops[i]   = le32_to_cpu(je->m_iops[i]);
885                 je->t_iops[i]   = le32_to_cpu(je->t_iops[i]);
886                 je->rate[i]     = le32_to_cpu(je->rate[i]);
887                 je->iops[i]     = le32_to_cpu(je->iops[i]);
888         }
889
890         je->elapsed_sec         = le64_to_cpu(je->elapsed_sec);
891         je->eta_sec             = le64_to_cpu(je->eta_sec);
892         je->nr_threads          = le32_to_cpu(je->nr_threads);
893         je->is_pow2             = le32_to_cpu(je->is_pow2);
894         je->unit_base           = le32_to_cpu(je->unit_base);
895 }
896
897 void fio_client_sum_jobs_eta(struct jobs_eta *dst, struct jobs_eta *je)
898 {
899         int i;
900
901         dst->nr_running         += je->nr_running;
902         dst->nr_ramp            += je->nr_ramp;
903         dst->nr_pending         += je->nr_pending;
904         dst->files_open         += je->files_open;
905
906         for (i = 0; i < DDIR_RWDIR_CNT; i++) {
907                 dst->m_rate[i]  += je->m_rate[i];
908                 dst->t_rate[i]  += je->t_rate[i];
909                 dst->m_iops[i]  += je->m_iops[i];
910                 dst->t_iops[i]  += je->t_iops[i];
911                 dst->rate[i]    += je->rate[i];
912                 dst->iops[i]    += je->iops[i];
913         }
914
915         dst->elapsed_sec        += je->elapsed_sec;
916
917         if (je->eta_sec > dst->eta_sec)
918                 dst->eta_sec = je->eta_sec;
919
920         dst->nr_threads         += je->nr_threads;
921         /* we need to handle je->run_str too ... */
922 }
923
924 void fio_client_dec_jobs_eta(struct client_eta *eta, client_eta_op eta_fn)
925 {
926         if (!--eta->pending) {
927                 eta_fn(&eta->eta);
928                 free(eta);
929         }
930 }
931
932 static void remove_reply_cmd(struct fio_client *client, struct fio_net_cmd *cmd)
933 {
934         struct fio_net_cmd_reply *reply = NULL;
935         struct flist_head *entry;
936
937         flist_for_each(entry, &client->cmd_list) {
938                 reply = flist_entry(entry, struct fio_net_cmd_reply, list);
939
940                 if (cmd->tag == (uintptr_t) reply)
941                         break;
942
943                 reply = NULL;
944         }
945
946         if (!reply) {
947                 log_err("fio: client: unable to find matching tag (%lx)\n", cmd->tag);
948                 return;
949         }
950
951         flist_del(&reply->list);
952         cmd->tag = reply->saved_tag;
953         free(reply);
954 }
955
956 int fio_client_wait_for_reply(struct fio_client *client, uint64_t tag)
957 {
958         do {
959                 struct fio_net_cmd_reply *reply = NULL;
960                 struct flist_head *entry;
961
962                 flist_for_each(entry, &client->cmd_list) {
963                         reply = flist_entry(entry, struct fio_net_cmd_reply, list);
964
965                         if (tag == (uintptr_t) reply)
966                                 break;
967
968                         reply = NULL;
969                 }
970
971                 if (!reply)
972                         break;
973
974                 usleep(1000);
975         } while (1);
976
977         return 0;
978 }
979
980 static void handle_eta(struct fio_client *client, struct fio_net_cmd *cmd)
981 {
982         struct jobs_eta *je = (struct jobs_eta *) cmd->payload;
983         struct client_eta *eta = (struct client_eta *) (uintptr_t) cmd->tag;
984
985         dprint(FD_NET, "client: got eta tag %p, %d\n", eta, eta->pending);
986
987         assert(client->eta_in_flight == eta);
988
989         client->eta_in_flight = NULL;
990         flist_del_init(&client->eta_list);
991
992         if (client->ops->jobs_eta)
993                 client->ops->jobs_eta(client, je);
994
995         fio_client_sum_jobs_eta(&eta->eta, je);
996         fio_client_dec_jobs_eta(eta, client->ops->eta);
997 }
998
999 static void handle_probe(struct fio_client *client, struct fio_net_cmd *cmd)
1000 {
1001         struct cmd_probe_pdu *probe = (struct cmd_probe_pdu *) cmd->payload;
1002         const char *os, *arch;
1003         char bit[16];
1004
1005         os = fio_get_os_string(probe->os);
1006         if (!os)
1007                 os = "unknown";
1008
1009         arch = fio_get_arch_string(probe->arch);
1010         if (!arch)
1011                 os = "unknown";
1012
1013         sprintf(bit, "%d-bit", probe->bpp * 8);
1014
1015         log_info("hostname=%s, be=%u, %s, os=%s, arch=%s, fio=%s\n",
1016                 probe->hostname, probe->bigendian, bit, os, arch,
1017                 probe->fio_version);
1018
1019         if (!client->name)
1020                 client->name = strdup((char *) probe->hostname);
1021 }
1022
1023 static void handle_start(struct fio_client *client, struct fio_net_cmd *cmd)
1024 {
1025         struct cmd_start_pdu *pdu = (struct cmd_start_pdu *) cmd->payload;
1026
1027         client->state = Client_started;
1028         client->jobs = le32_to_cpu(pdu->jobs);
1029         client->nr_stat = le32_to_cpu(pdu->stat_outputs);
1030
1031         if (sum_stat_clients > 1)
1032                 do_output_all_clients = 1;
1033
1034         sum_stat_clients += client->nr_stat;
1035 }
1036
1037 static void handle_stop(struct fio_client *client, struct fio_net_cmd *cmd)
1038 {
1039         if (client->error)
1040                 log_info("client <%s>: exited with error %d\n", client->hostname, client->error);
1041 }
1042
1043 static void convert_stop(struct fio_net_cmd *cmd)
1044 {
1045         struct cmd_end_pdu *pdu = (struct cmd_end_pdu *) cmd->payload;
1046
1047         pdu->error = le32_to_cpu(pdu->error);
1048 }
1049
1050 static void convert_text(struct fio_net_cmd *cmd)
1051 {
1052         struct cmd_text_pdu *pdu = (struct cmd_text_pdu *) cmd->payload;
1053
1054         pdu->level      = le32_to_cpu(pdu->level);
1055         pdu->buf_len    = le32_to_cpu(pdu->buf_len);
1056         pdu->log_sec    = le64_to_cpu(pdu->log_sec);
1057         pdu->log_usec   = le64_to_cpu(pdu->log_usec);
1058 }
1059
1060 /*
1061  * This has been compressed on the server side, since it can be big.
1062  * Uncompress here.
1063  */
1064 static struct cmd_iolog_pdu *convert_iolog(struct fio_net_cmd *cmd)
1065 {
1066         struct cmd_iolog_pdu *pdu = (struct cmd_iolog_pdu *) cmd->payload;
1067         struct cmd_iolog_pdu *ret;
1068         uint32_t nr_samples;
1069         unsigned long total;
1070         z_stream stream;
1071         void *p;
1072         int i;
1073
1074         stream.zalloc = Z_NULL;
1075         stream.zfree = Z_NULL;
1076         stream.opaque = Z_NULL;
1077         stream.avail_in = 0;
1078         stream.next_in = Z_NULL;
1079
1080         if (inflateInit(&stream) != Z_OK)
1081                 return NULL;
1082
1083         /*
1084          * Get header first, it's not compressed
1085          */
1086         nr_samples = le32_to_cpu(pdu->nr_samples);
1087
1088         total = nr_samples * sizeof(struct io_sample);
1089         ret = malloc(total + sizeof(*pdu));
1090         ret->thread_number = le32_to_cpu(pdu->thread_number);
1091         ret->nr_samples = nr_samples;
1092         ret->log_type = le32_to_cpu(pdu->log_type);
1093         strcpy((char *) ret->name, (char *) pdu->name);
1094
1095         p = (void *) ret + sizeof(*pdu);
1096
1097         stream.avail_in = cmd->pdu_len - sizeof(*pdu);
1098         stream.next_in = (void *) pdu + sizeof(*pdu);
1099         while (stream.avail_in) {
1100                 unsigned int this_chunk = 65536;
1101                 unsigned int this_len;
1102                 int err;
1103
1104                 if (this_chunk > total)
1105                         this_chunk = total;
1106
1107                 stream.avail_out = this_chunk;
1108                 stream.next_out = p;
1109                 err = inflate(&stream, Z_NO_FLUSH);
1110                 /* may be Z_OK, or Z_STREAM_END */
1111                 if (err < 0) {
1112                         log_err("fio: inflate error %d\n", err);
1113                         free(ret);
1114                         ret = NULL;
1115                         goto out;
1116                 }
1117
1118                 this_len = this_chunk - stream.avail_out;
1119                 p += this_len;
1120                 total -= this_len;
1121         }
1122
1123         for (i = 0; i < ret->nr_samples; i++) {
1124                 struct io_sample *s = &ret->samples[i];
1125
1126                 s->time = le64_to_cpu(s->time);
1127                 s->val  = le64_to_cpu(s->val);
1128                 s->ddir = le32_to_cpu(s->ddir);
1129                 s->bs   = le32_to_cpu(s->bs);
1130         }
1131
1132 out:
1133         inflateEnd(&stream);
1134         return ret;
1135 }
1136
1137 int fio_handle_client(struct fio_client *client)
1138 {
1139         struct client_ops *ops = client->ops;
1140         struct fio_net_cmd *cmd;
1141
1142         dprint(FD_NET, "client: handle %s\n", client->hostname);
1143
1144         cmd = fio_net_recv_cmd(client->fd);
1145         if (!cmd)
1146                 return 0;
1147
1148         dprint(FD_NET, "client: got cmd op %s from %s (pdu=%u)\n",
1149                 fio_server_op(cmd->opcode), client->hostname, cmd->pdu_len);
1150
1151         switch (cmd->opcode) {
1152         case FIO_NET_CMD_QUIT:
1153                 if (ops->quit)
1154                         ops->quit(client, cmd);
1155                 remove_client(client);
1156                 free(cmd);
1157                 break;
1158         case FIO_NET_CMD_TEXT:
1159                 convert_text(cmd);
1160                 ops->text(client, cmd);
1161                 free(cmd);
1162                 break;
1163         case FIO_NET_CMD_DU: {
1164                 struct cmd_du_pdu *du = (struct cmd_du_pdu *) cmd->payload;
1165
1166                 convert_dus(&du->dus);
1167                 convert_agg(&du->agg);
1168
1169                 ops->disk_util(client, cmd);
1170                 free(cmd);
1171                 break;
1172                 }
1173         case FIO_NET_CMD_TS: {
1174                 struct cmd_ts_pdu *p = (struct cmd_ts_pdu *) cmd->payload;
1175
1176                 convert_ts(&p->ts, &p->ts);
1177                 convert_gs(&p->rs, &p->rs);
1178
1179                 ops->thread_status(client, cmd);
1180                 free(cmd);
1181                 break;
1182                 }
1183         case FIO_NET_CMD_GS: {
1184                 struct group_run_stats *gs = (struct group_run_stats *) cmd->payload;
1185
1186                 convert_gs(gs, gs);
1187
1188                 ops->group_stats(client, cmd);
1189                 free(cmd);
1190                 break;
1191                 }
1192         case FIO_NET_CMD_ETA: {
1193                 struct jobs_eta *je = (struct jobs_eta *) cmd->payload;
1194
1195                 remove_reply_cmd(client, cmd);
1196                 convert_jobs_eta(je);
1197                 handle_eta(client, cmd);
1198                 free(cmd);
1199                 break;
1200                 }
1201         case FIO_NET_CMD_PROBE:
1202                 remove_reply_cmd(client, cmd);
1203                 ops->probe(client, cmd);
1204                 free(cmd);
1205                 break;
1206         case FIO_NET_CMD_SERVER_START:
1207                 client->state = Client_running;
1208                 if (ops->job_start)
1209                         ops->job_start(client, cmd);
1210                 free(cmd);
1211                 break;
1212         case FIO_NET_CMD_START: {
1213                 struct cmd_start_pdu *pdu = (struct cmd_start_pdu *) cmd->payload;
1214
1215                 pdu->jobs = le32_to_cpu(pdu->jobs);
1216                 ops->start(client, cmd);
1217                 free(cmd);
1218                 break;
1219                 }
1220         case FIO_NET_CMD_STOP: {
1221                 struct cmd_end_pdu *pdu = (struct cmd_end_pdu *) cmd->payload;
1222
1223                 convert_stop(cmd);
1224                 client->state = Client_stopped;
1225                 client->error = le32_to_cpu(pdu->error);
1226                 client->signal = le32_to_cpu(pdu->signal);
1227                 ops->stop(client, cmd);
1228                 free(cmd);
1229                 break;
1230                 }
1231         case FIO_NET_CMD_ADD_JOB: {
1232                 struct cmd_add_job_pdu *pdu = (struct cmd_add_job_pdu *) cmd->payload;
1233
1234                 client->thread_number = le32_to_cpu(pdu->thread_number);
1235                 client->groupid = le32_to_cpu(pdu->groupid);
1236
1237                 if (ops->add_job)
1238                         ops->add_job(client, cmd);
1239                 free(cmd);
1240                 break;
1241                 }
1242         case FIO_NET_CMD_IOLOG:
1243                 if (ops->iolog) {
1244                         struct cmd_iolog_pdu *pdu;
1245
1246                         pdu = convert_iolog(cmd);
1247                         ops->iolog(client, pdu);
1248                 }
1249                 free(cmd);
1250                 break;
1251         case FIO_NET_CMD_UPDATE_JOB:
1252                 ops->update_job(client, cmd);
1253                 remove_reply_cmd(client, cmd);
1254                 free(cmd);
1255                 break;
1256         default:
1257                 log_err("fio: unknown client op: %s\n", fio_server_op(cmd->opcode));
1258                 free(cmd);
1259                 break;
1260         }
1261
1262         return 1;
1263 }
1264
1265 static void request_client_etas(struct client_ops *ops)
1266 {
1267         struct fio_client *client;
1268         struct flist_head *entry;
1269         struct client_eta *eta;
1270         int skipped = 0;
1271
1272         dprint(FD_NET, "client: request eta (%d)\n", nr_clients);
1273
1274         eta = malloc(sizeof(*eta));
1275         memset(&eta->eta, 0, sizeof(eta->eta));
1276         eta->pending = nr_clients;
1277
1278         flist_for_each(entry, &client_list) {
1279                 client = flist_entry(entry, struct fio_client, list);
1280
1281                 if (!flist_empty(&client->eta_list)) {
1282                         skipped++;
1283                         continue;
1284                 }
1285                 if (client->state != Client_running)
1286                         continue;
1287
1288                 assert(!client->eta_in_flight);
1289                 flist_add_tail(&client->eta_list, &eta_list);
1290                 client->eta_in_flight = eta;
1291                 fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_SEND_ETA,
1292                                         (uintptr_t) eta, &client->cmd_list);
1293         }
1294
1295         while (skipped--)
1296                 fio_client_dec_jobs_eta(eta, ops->eta);
1297
1298         dprint(FD_NET, "client: requested eta tag %p\n", eta);
1299 }
1300
1301 static int client_check_cmd_timeout(struct fio_client *client,
1302                                     struct timeval *now)
1303 {
1304         struct fio_net_cmd_reply *reply;
1305         struct flist_head *entry, *tmp;
1306         int ret = 0;
1307
1308         flist_for_each_safe(entry, tmp, &client->cmd_list) {
1309                 reply = flist_entry(entry, struct fio_net_cmd_reply, list);
1310
1311                 if (mtime_since(&reply->tv, now) < FIO_NET_CLIENT_TIMEOUT)
1312                         continue;
1313
1314                 log_err("fio: client %s, timeout on cmd %s\n", client->hostname,
1315                                                 fio_server_op(reply->opcode));
1316                 flist_del(&reply->list);
1317                 free(reply);
1318                 ret = 1;
1319         }
1320
1321         return flist_empty(&client->cmd_list) && ret;
1322 }
1323
1324 static int fio_check_clients_timed_out(void)
1325 {
1326         struct fio_client *client;
1327         struct flist_head *entry, *tmp;
1328         struct timeval tv;
1329         int ret = 0;
1330
1331         fio_gettime(&tv, NULL);
1332
1333         flist_for_each_safe(entry, tmp, &client_list) {
1334                 client = flist_entry(entry, struct fio_client, list);
1335
1336                 if (flist_empty(&client->cmd_list))
1337                         continue;
1338
1339                 if (!client_check_cmd_timeout(client, &tv))
1340                         continue;
1341
1342                 if (client->ops->timed_out)
1343                         client->ops->timed_out(client);
1344                 else
1345                         log_err("fio: client %s timed out\n", client->hostname);
1346
1347                 remove_client(client);
1348                 ret = 1;
1349         }
1350
1351         return ret;
1352 }
1353
1354 int fio_handle_clients(struct client_ops *ops)
1355 {
1356         struct pollfd *pfds;
1357         int i, ret = 0, retval = 0;
1358
1359         fio_gettime(&eta_tv, NULL);
1360
1361         pfds = malloc(nr_clients * sizeof(struct pollfd));
1362
1363         init_thread_stat(&client_ts);
1364         init_group_run_stat(&client_gs);
1365
1366         while (!exit_backend && nr_clients) {
1367                 struct flist_head *entry, *tmp;
1368                 struct fio_client *client;
1369
1370                 i = 0;
1371                 flist_for_each_safe(entry, tmp, &client_list) {
1372                         client = flist_entry(entry, struct fio_client, list);
1373
1374                         if (!client->sent_job && !client->ops->stay_connected &&
1375                             flist_empty(&client->cmd_list)) {
1376                                 remove_client(client);
1377                                 continue;
1378                         }
1379
1380                         pfds[i].fd = client->fd;
1381                         pfds[i].events = POLLIN;
1382                         i++;
1383                 }
1384
1385                 if (!nr_clients)
1386                         break;
1387
1388                 assert(i == nr_clients);
1389
1390                 do {
1391                         struct timeval tv;
1392
1393                         fio_gettime(&tv, NULL);
1394                         if (mtime_since(&eta_tv, &tv) >= 900) {
1395                                 request_client_etas(ops);
1396                                 memcpy(&eta_tv, &tv, sizeof(tv));
1397
1398                                 if (fio_check_clients_timed_out())
1399                                         break;
1400                         }
1401
1402                         ret = poll(pfds, nr_clients, ops->eta_msec);
1403                         if (ret < 0) {
1404                                 if (errno == EINTR)
1405                                         continue;
1406                                 log_err("fio: poll clients: %s\n", strerror(errno));
1407                                 break;
1408                         } else if (!ret)
1409                                 continue;
1410                 } while (ret <= 0);
1411
1412                 for (i = 0; i < nr_clients; i++) {
1413                         if (!(pfds[i].revents & POLLIN))
1414                                 continue;
1415
1416                         client = find_client_by_fd(pfds[i].fd);
1417                         if (!client) {
1418                                 log_err("fio: unknown client fd %d\n", pfds[i].fd);
1419                                 continue;
1420                         }
1421                         if (!fio_handle_client(client)) {
1422                                 log_info("client: host=%s disconnected\n",
1423                                                 client->hostname);
1424                                 remove_client(client);
1425                                 retval = 1;
1426                         } else if (client->error)
1427                                 retval = 1;
1428                         fio_put_client(client);
1429                 }
1430         }
1431
1432         free(pfds);
1433         return retval;
1434 }