blob: 760ec85087b73bba197c95b033154f08c245bc7f [file] [log] [blame]
Jens Axboe132159a2011-09-30 15:01:32 -06001#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>
Jens Axboed05c4a02011-10-05 00:16:11 +020011#include <sys/socket.h>
Jens Axboe87aa8f12011-10-06 21:24:13 +020012#include <sys/un.h>
Jens Axboe132159a2011-09-30 15:01:32 -060013#include <netinet/in.h>
14#include <arpa/inet.h>
15#include <netdb.h>
Jens Axboe9e22ecb2011-10-04 14:50:21 +020016#include <signal.h>
Jens Axboe3989b142013-04-12 13:13:24 +020017#ifdef CONFIG_ZLIB
Jens Axboe1b427252012-03-14 15:03:03 +010018#include <zlib.h>
Jens Axboe3989b142013-04-12 13:13:24 +020019#endif
Jens Axboe132159a2011-09-30 15:01:32 -060020
21#include "fio.h"
Stephen M. Camerondd366722012-02-24 08:17:30 +010022#include "client.h"
Jens Axboe132159a2011-09-30 15:01:32 -060023#include "server.h"
Jens Axboeb66570d2011-10-01 11:11:35 -060024#include "flist.h"
Jens Axboe3c5f57e2011-10-06 12:37:50 +020025#include "hash.h"
Jens Axboede54cfd2014-11-10 20:34:00 -070026#include "verify.h"
Jens Axboe132159a2011-09-30 15:01:32 -060027
Stephen M. Camerondd366722012-02-24 08:17:30 +010028static void handle_du(struct fio_client *client, struct fio_net_cmd *cmd);
Jens Axboe89e5fad2012-03-05 09:21:12 +010029static void handle_ts(struct fio_client *client, struct fio_net_cmd *cmd);
30static void handle_gs(struct fio_client *client, struct fio_net_cmd *cmd);
Stephen M. Camerondd366722012-02-24 08:17:30 +010031static void handle_probe(struct fio_client *client, struct fio_net_cmd *cmd);
Jens Axboe084d1c62012-03-03 20:28:07 +010032static void handle_text(struct fio_client *client, struct fio_net_cmd *cmd);
Jens Axboe6b79c802012-03-08 10:51:36 +010033static void handle_stop(struct fio_client *client, struct fio_net_cmd *cmd);
Jens Axboe85dd01e2012-03-12 14:33:16 +010034static void handle_start(struct fio_client *client, struct fio_net_cmd *cmd);
Stephen M. Camerondd366722012-02-24 08:17:30 +010035
36struct client_ops fio_client_ops = {
Jens Axboe35c0ba72012-03-14 10:56:40 +010037 .text = handle_text,
Jens Axboe0420ba62012-02-29 11:16:52 +010038 .disk_util = handle_du,
39 .thread_status = handle_ts,
40 .group_stats = handle_gs,
Jens Axboe6b79c802012-03-08 10:51:36 +010041 .stop = handle_stop,
Jens Axboe85dd01e2012-03-12 14:33:16 +010042 .start = handle_start,
Jens Axboea5276612012-03-04 15:15:08 +010043 .eta = display_thread_status,
Jens Axboe0420ba62012-02-29 11:16:52 +010044 .probe = handle_probe,
Jens Axboe6433ee02012-03-09 20:10:51 +010045 .eta_msec = FIO_CLIENT_DEF_ETA_MSEC,
Jens Axboe46bcd492012-03-14 11:31:21 +010046 .client_type = FIO_CLIENT_TYPE_CLI,
Stephen M. Camerondd366722012-02-24 08:17:30 +010047};
48
Jens Axboeaf9c9fb2011-10-09 21:54:10 +020049static struct timeval eta_tv;
Jens Axboe48fbb462011-10-09 12:19:08 +020050
Jens Axboeb66570d2011-10-01 11:11:35 -060051static FLIST_HEAD(client_list);
Jens Axboe82c1ed32011-10-10 08:56:18 +020052static FLIST_HEAD(eta_list);
Jens Axboeb66570d2011-10-01 11:11:35 -060053
Jens Axboe3f3a4542011-10-10 21:11:09 +020054static FLIST_HEAD(arg_list);
55
Jens Axboe3650a3c2012-03-05 14:09:03 +010056struct thread_stat client_ts;
57struct group_run_stats client_gs;
58int sum_stat_clients;
59
Jens Axboe37f0c1a2011-10-11 14:08:33 +020060static int sum_stat_nr;
Castor Fu952b05e2013-10-31 11:00:34 -060061static struct json_object *root = NULL;
62static struct json_array *clients_array = NULL;
63static struct json_array *du_array = NULL;
Jens Axboe37f0c1a2011-10-11 14:08:33 +020064
Jens Axboe4811fff2015-01-13 21:47:43 -070065static int error_clients;
66
Jens Axboe3c5f57e2011-10-06 12:37:50 +020067#define FIO_CLIENT_HASH_BITS 7
68#define FIO_CLIENT_HASH_SZ (1 << FIO_CLIENT_HASH_BITS)
69#define FIO_CLIENT_HASH_MASK (FIO_CLIENT_HASH_SZ - 1)
Jens Axboebebe6392011-10-07 10:00:51 +020070static struct flist_head client_hash[FIO_CLIENT_HASH_SZ];
Jens Axboe3c5f57e2011-10-06 12:37:50 +020071
Jens Axboebebe6392011-10-07 10:00:51 +020072static void fio_client_add_hash(struct fio_client *client)
Jens Axboe3c5f57e2011-10-06 12:37:50 +020073{
74 int bucket = hash_long(client->fd, FIO_CLIENT_HASH_BITS);
75
76 bucket &= FIO_CLIENT_HASH_MASK;
Jens Axboebebe6392011-10-07 10:00:51 +020077 flist_add(&client->hash_list, &client_hash[bucket]);
Jens Axboe3c5f57e2011-10-06 12:37:50 +020078}
79
Jens Axboebebe6392011-10-07 10:00:51 +020080static void fio_client_remove_hash(struct fio_client *client)
Jens Axboe3c5f57e2011-10-06 12:37:50 +020081{
Jens Axboebebe6392011-10-07 10:00:51 +020082 if (!flist_empty(&client->hash_list))
83 flist_del_init(&client->hash_list);
Jens Axboe3c5f57e2011-10-06 12:37:50 +020084}
85
86static void fio_init fio_client_hash_init(void)
87{
88 int i;
89
Jens Axboebebe6392011-10-07 10:00:51 +020090 for (i = 0; i < FIO_CLIENT_HASH_SZ; i++)
91 INIT_FLIST_HEAD(&client_hash[i]);
Jens Axboe3c5f57e2011-10-06 12:37:50 +020092}
93
Jens Axboe3d0be7c2014-11-11 10:24:00 -070094static int read_data(int fd, void *data, size_t size)
95{
96 ssize_t ret;
97
98 while (size) {
99 ret = read(fd, data, size);
100 if (ret < 0) {
101 if (errno == EAGAIN || errno == EINTR)
102 continue;
103 break;
104 } else if (!ret)
105 break;
106 else {
107 data += ret;
108 size -= ret;
109 }
110 }
111
112 if (size)
113 return EAGAIN;
114
115 return 0;
116}
117
Castor Fu952b05e2013-10-31 11:00:34 -0600118static void fio_client_json_init(void)
119{
120 if (output_format != FIO_OUTPUT_JSON)
121 return;
122 root = json_create_object();
123 json_object_add_value_string(root, "fio version", fio_version_string);
124 clients_array = json_create_array();
125 json_object_add_value_array(root, "client_stats", clients_array);
126 du_array = json_create_array();
127 json_object_add_value_array(root, "disk_util", du_array);
128}
129
130static void fio_client_json_fini(void)
131{
132 if (output_format != FIO_OUTPUT_JSON)
133 return;
134 json_print_object(root);
135 log_info("\n");
136 json_free_object(root);
137 root = NULL;
138 clients_array = NULL;
139 du_array = NULL;
140}
141
Jens Axboeb66570d2011-10-01 11:11:35 -0600142static struct fio_client *find_client_by_fd(int fd)
143{
Jens Axboe3c5f57e2011-10-06 12:37:50 +0200144 int bucket = hash_long(fd, FIO_CLIENT_HASH_BITS) & FIO_CLIENT_HASH_MASK;
Jens Axboeb66570d2011-10-01 11:11:35 -0600145 struct fio_client *client;
146 struct flist_head *entry;
147
Jens Axboebebe6392011-10-07 10:00:51 +0200148 flist_for_each(entry, &client_hash[bucket]) {
149 client = flist_entry(entry, struct fio_client, hash_list);
Jens Axboeb66570d2011-10-01 11:11:35 -0600150
Jens Axboee55f8f32012-03-06 15:42:31 +0100151 if (client->fd == fd) {
152 client->refs++;
Jens Axboeb66570d2011-10-01 11:11:35 -0600153 return client;
Jens Axboee55f8f32012-03-06 15:42:31 +0100154 }
Jens Axboeb66570d2011-10-01 11:11:35 -0600155 }
156
157 return NULL;
158}
159
Jens Axboe3af45202012-03-13 09:59:53 +0100160void fio_put_client(struct fio_client *client)
Jens Axboeb66570d2011-10-01 11:11:35 -0600161{
Jens Axboe5121a9a2012-03-05 13:32:47 +0100162 if (--client->refs)
163 return;
164
Jens Axboeb66570d2011-10-01 11:11:35 -0600165 free(client->hostname);
Jens Axboe81179ee2011-10-04 12:42:06 +0200166 if (client->argv)
167 free(client->argv);
Jens Axboeb5296dd2011-10-07 16:35:56 +0200168 if (client->name)
169 free(client->name);
Jens Axboe35899182014-10-07 20:56:28 -0600170 while (client->nr_files) {
171 struct client_file *cf = &client->files[--client->nr_files];
172
173 free(cf->file);
174 }
175 if (client->files)
176 free(client->files);
Jens Axboe81179ee2011-10-04 12:42:06 +0200177
Jens Axboe108fea72012-11-14 13:09:45 -0700178 if (!client->did_stat)
Jens Axboebfa8f5d2014-10-13 10:09:28 -0600179 sum_stat_clients--;
Jens Axboe108fea72012-11-14 13:09:45 -0700180
Jens Axboe4811fff2015-01-13 21:47:43 -0700181 if (client->error)
182 error_clients++;
183
Jens Axboeb66570d2011-10-01 11:11:35 -0600184 free(client);
185}
Jens Axboe132159a2011-09-30 15:01:32 -0600186
Jens Axboe3af45202012-03-13 09:59:53 +0100187static void remove_client(struct fio_client *client)
Jens Axboe5121a9a2012-03-05 13:32:47 +0100188{
Jens Axboe3af45202012-03-13 09:59:53 +0100189 assert(client->refs);
190
191 dprint(FD_NET, "client: removed <%s>\n", client->hostname);
192
193 if (!flist_empty(&client->list))
194 flist_del_init(&client->list);
195
196 fio_client_remove_hash(client);
197
198 if (!flist_empty(&client->eta_list)) {
199 flist_del_init(&client->eta_list);
200 fio_client_dec_jobs_eta(client->eta_in_flight, client->ops->eta);
201 }
202
Jens Axboe1e0c1842012-03-20 15:15:00 +0100203 close(client->fd);
204 client->fd = -1;
205
Jens Axboe0cf3ece2012-03-21 10:15:20 +0100206 if (client->ops->removed)
207 client->ops->removed(client);
208
Jens Axboe3af45202012-03-13 09:59:53 +0100209 nr_clients--;
Jens Axboe3af45202012-03-13 09:59:53 +0100210 fio_put_client(client);
Jens Axboe5121a9a2012-03-05 13:32:47 +0100211}
212
Jens Axboe343cb4a2012-03-09 17:16:51 +0100213struct fio_client *fio_get_client(struct fio_client *client)
214{
215 client->refs++;
216 return client;
217}
218
Jens Axboefa2ea802011-10-08 21:07:29 +0200219static void __fio_client_add_cmd_option(struct fio_client *client,
220 const char *opt)
Jens Axboe81179ee2011-10-04 12:42:06 +0200221{
Jens Axboe39e8e012011-10-04 13:46:08 +0200222 int index;
223
224 index = client->argc++;
Jens Axboe81179ee2011-10-04 12:42:06 +0200225 client->argv = realloc(client->argv, sizeof(char *) * client->argc);
Jens Axboe39e8e012011-10-04 13:46:08 +0200226 client->argv[index] = strdup(opt);
227 dprint(FD_NET, "client: add cmd %d: %s\n", index, opt);
Jens Axboe81179ee2011-10-04 12:42:06 +0200228}
229
Jens Axboefa2ea802011-10-08 21:07:29 +0200230void fio_client_add_cmd_option(void *cookie, const char *opt)
Jens Axboe81179ee2011-10-04 12:42:06 +0200231{
Jens Axboebebe6392011-10-07 10:00:51 +0200232 struct fio_client *client = cookie;
Jens Axboe3f3a4542011-10-10 21:11:09 +0200233 struct flist_head *entry;
Jens Axboe81179ee2011-10-04 12:42:06 +0200234
Jens Axboebebe6392011-10-07 10:00:51 +0200235 if (!client || !opt)
Jens Axboefa2ea802011-10-08 21:07:29 +0200236 return;
Jens Axboe81179ee2011-10-04 12:42:06 +0200237
Jens Axboefa2ea802011-10-08 21:07:29 +0200238 __fio_client_add_cmd_option(client, opt);
Jens Axboe3f3a4542011-10-10 21:11:09 +0200239
240 /*
241 * Duplicate arguments to shared client group
242 */
243 flist_for_each(entry, &arg_list) {
244 client = flist_entry(entry, struct fio_client, arg_list);
245
246 __fio_client_add_cmd_option(client, opt);
247 }
Jens Axboe81179ee2011-10-04 12:42:06 +0200248}
249
Jens Axboea5276612012-03-04 15:15:08 +0100250struct fio_client *fio_client_add_explicit(struct client_ops *ops,
251 const char *hostname, int type,
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100252 int port)
253{
254 struct fio_client *client;
255
256 client = malloc(sizeof(*client));
257 memset(client, 0, sizeof(*client));
258
259 INIT_FLIST_HEAD(&client->list);
260 INIT_FLIST_HEAD(&client->hash_list);
261 INIT_FLIST_HEAD(&client->arg_list);
262 INIT_FLIST_HEAD(&client->eta_list);
263 INIT_FLIST_HEAD(&client->cmd_list);
264
265 client->hostname = strdup(hostname);
266
267 if (type == Fio_client_socket)
268 client->is_sock = 1;
269 else {
270 int ipv6;
271
272 ipv6 = type == Fio_client_ipv6;
Jens Axboe3aa3cee2014-01-24 18:56:56 -0800273 if (fio_server_parse_host(hostname, ipv6,
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100274 &client->addr.sin_addr,
275 &client->addr6.sin6_addr))
276 goto err;
277
278 client->port = port;
279 }
280
281 client->fd = -1;
Jens Axboea5276612012-03-04 15:15:08 +0100282 client->ops = ops;
Jens Axboe5121a9a2012-03-05 13:32:47 +0100283 client->refs = 1;
Jens Axboe46bcd492012-03-14 11:31:21 +0100284 client->type = ops->client_type;
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100285
286 __fio_client_add_cmd_option(client, "fio");
287
288 flist_add(&client->list, &client_list);
289 nr_clients++;
290 dprint(FD_NET, "client: added <%s>\n", client->hostname);
291 return client;
292err:
293 free(client);
294 return NULL;
295}
296
Jens Axboe35899182014-10-07 20:56:28 -0600297int fio_client_add_ini_file(void *cookie, const char *ini_file, int remote)
Jens Axboe14ea90e2012-08-26 17:33:34 +0200298{
299 struct fio_client *client = cookie;
Jens Axboe35899182014-10-07 20:56:28 -0600300 struct client_file *cf;
Jens Axboe14ea90e2012-08-26 17:33:34 +0200301 size_t new_size;
Jens Axboe35899182014-10-07 20:56:28 -0600302 void *new_files;
Jens Axboe14ea90e2012-08-26 17:33:34 +0200303
Jens Axboe722b5cd2014-10-14 19:56:25 -0600304 if (!client)
305 return 1;
306
Jens Axboe14ea90e2012-08-26 17:33:34 +0200307 dprint(FD_NET, "client <%s>: add ini %s\n", client->hostname, ini_file);
308
Jens Axboe35899182014-10-07 20:56:28 -0600309 new_size = (client->nr_files + 1) * sizeof(struct client_file);
310 new_files = realloc(client->files, new_size);
311 if (!new_files)
312 return 1;
313
314 client->files = new_files;
315 cf = &client->files[client->nr_files];
316 cf->file = strdup(ini_file);
317 cf->remote = remote;
318 client->nr_files++;
319 return 0;
Jens Axboe14ea90e2012-08-26 17:33:34 +0200320}
321
Jens Axboea5276612012-03-04 15:15:08 +0100322int fio_client_add(struct client_ops *ops, const char *hostname, void **cookie)
Jens Axboe132159a2011-09-30 15:01:32 -0600323{
Jens Axboe3f3a4542011-10-10 21:11:09 +0200324 struct fio_client *existing = *cookie;
Jens Axboeb66570d2011-10-01 11:11:35 -0600325 struct fio_client *client;
Jens Axboe132159a2011-09-30 15:01:32 -0600326
Jens Axboe3f3a4542011-10-10 21:11:09 +0200327 if (existing) {
328 /*
329 * We always add our "exec" name as the option, hence 1
330 * means empty.
331 */
332 if (existing->argc == 1)
333 flist_add_tail(&existing->arg_list, &arg_list);
334 else {
335 while (!flist_empty(&arg_list))
336 flist_del_init(arg_list.next);
337 }
338 }
339
Jens Axboeb66570d2011-10-01 11:11:35 -0600340 client = malloc(sizeof(*client));
Jens Axboea37f69b2011-10-01 12:24:21 -0600341 memset(client, 0, sizeof(*client));
Jens Axboe81179ee2011-10-04 12:42:06 +0200342
Jens Axboe3c5f57e2011-10-06 12:37:50 +0200343 INIT_FLIST_HEAD(&client->list);
Jens Axboebebe6392011-10-07 10:00:51 +0200344 INIT_FLIST_HEAD(&client->hash_list);
Jens Axboe3f3a4542011-10-10 21:11:09 +0200345 INIT_FLIST_HEAD(&client->arg_list);
Jens Axboe82c1ed32011-10-10 08:56:18 +0200346 INIT_FLIST_HEAD(&client->eta_list);
Jens Axboe89c17072011-10-11 10:15:51 +0200347 INIT_FLIST_HEAD(&client->cmd_list);
Jens Axboe3c5f57e2011-10-06 12:37:50 +0200348
Jens Axboebebe6392011-10-07 10:00:51 +0200349 if (fio_server_parse_string(hostname, &client->hostname,
350 &client->is_sock, &client->port,
Jens Axboe811826b2011-10-24 09:11:50 +0200351 &client->addr.sin_addr,
352 &client->addr6.sin6_addr,
353 &client->ipv6))
Jens Axboebebe6392011-10-07 10:00:51 +0200354 return -1;
355
Jens Axboea37f69b2011-10-01 12:24:21 -0600356 client->fd = -1;
Jens Axboea5276612012-03-04 15:15:08 +0100357 client->ops = ops;
Jens Axboe5121a9a2012-03-05 13:32:47 +0100358 client->refs = 1;
Jens Axboe46bcd492012-03-14 11:31:21 +0100359 client->type = ops->client_type;
Jens Axboe81179ee2011-10-04 12:42:06 +0200360
361 __fio_client_add_cmd_option(client, "fio");
362
Jens Axboea37f69b2011-10-01 12:24:21 -0600363 flist_add(&client->list, &client_list);
364 nr_clients++;
Jens Axboebebe6392011-10-07 10:00:51 +0200365 dprint(FD_NET, "client: added <%s>\n", client->hostname);
366 *cookie = client;
367 return 0;
Jens Axboea37f69b2011-10-01 12:24:21 -0600368}
369
Jens Axboede54cfd2014-11-10 20:34:00 -0700370static const char *server_name(struct fio_client *client, char *buf,
371 size_t bufsize)
372{
373 const char *from;
374
375 if (client->ipv6)
376 from = inet_ntop(AF_INET6, (struct sockaddr *) &client->addr6.sin6_addr, buf, bufsize);
377 else if (client->is_sock)
378 from = "sock";
379 else
380 from = inet_ntop(AF_INET, (struct sockaddr *) &client->addr.sin_addr, buf, bufsize);
381
382 return from;
383}
384
Jens Axboed824c3b2012-03-09 17:45:43 +0100385static void probe_client(struct fio_client *client)
386{
Jens Axboe3989b142013-04-12 13:13:24 +0200387 struct cmd_client_probe_pdu pdu;
Jens Axboe75289ee2015-01-05 08:47:01 -0700388 const char *sname;
Jens Axboe3989b142013-04-12 13:13:24 +0200389 uint64_t tag;
Jens Axboede54cfd2014-11-10 20:34:00 -0700390 char buf[64];
Jens Axboe3989b142013-04-12 13:13:24 +0200391
Jens Axboed824c3b2012-03-09 17:45:43 +0100392 dprint(FD_NET, "client: send probe\n");
393
Jens Axboe3989b142013-04-12 13:13:24 +0200394#ifdef CONFIG_ZLIB
395 pdu.flags = __le64_to_cpu(FIO_PROBE_FLAG_ZLIB);
396#else
397 pdu.flags = 0;
398#endif
399
Jens Axboe75289ee2015-01-05 08:47:01 -0700400 sname = server_name(client, buf, sizeof(buf));
401 memset(pdu.server, 0, sizeof(pdu.server));
402 strncpy((char *) pdu.server, sname, sizeof(pdu.server) - 1);
Jens Axboede54cfd2014-11-10 20:34:00 -0700403
Jens Axboe3989b142013-04-12 13:13:24 +0200404 fio_net_send_cmd(client->fd, FIO_NET_CMD_PROBE, &pdu, sizeof(pdu), &tag, &client->cmd_list);
Jens Axboed824c3b2012-03-09 17:45:43 +0100405}
406
Jens Axboe87aa8f12011-10-06 21:24:13 +0200407static int fio_client_connect_ip(struct fio_client *client)
Jens Axboea37f69b2011-10-01 12:24:21 -0600408{
Jens Axboe811826b2011-10-24 09:11:50 +0200409 struct sockaddr *addr;
Jens Axboe67bf9822013-01-10 11:23:19 +0100410 socklen_t socklen;
Jens Axboe811826b2011-10-24 09:11:50 +0200411 int fd, domain;
Jens Axboe132159a2011-09-30 15:01:32 -0600412
Jens Axboe811826b2011-10-24 09:11:50 +0200413 if (client->ipv6) {
414 client->addr6.sin6_family = AF_INET6;
415 client->addr6.sin6_port = htons(client->port);
416 domain = AF_INET6;
417 addr = (struct sockaddr *) &client->addr6;
418 socklen = sizeof(client->addr6);
419 } else {
420 client->addr.sin_family = AF_INET;
421 client->addr.sin_port = htons(client->port);
422 domain = AF_INET;
423 addr = (struct sockaddr *) &client->addr;
424 socklen = sizeof(client->addr);
425 }
Jens Axboe132159a2011-09-30 15:01:32 -0600426
Jens Axboe811826b2011-10-24 09:11:50 +0200427 fd = socket(domain, SOCK_STREAM, 0);
Jens Axboe132159a2011-09-30 15:01:32 -0600428 if (fd < 0) {
Jens Axboe25095e12012-03-09 17:09:55 +0100429 int ret = -errno;
430
Jens Axboe132159a2011-09-30 15:01:32 -0600431 log_err("fio: socket: %s\n", strerror(errno));
Jens Axboe25095e12012-03-09 17:09:55 +0100432 return ret;
Jens Axboe132159a2011-09-30 15:01:32 -0600433 }
434
Jens Axboe811826b2011-10-24 09:11:50 +0200435 if (connect(fd, addr, socklen) < 0) {
Jens Axboe25095e12012-03-09 17:09:55 +0100436 int ret = -errno;
437
Jens Axboe132159a2011-09-30 15:01:32 -0600438 log_err("fio: connect: %s\n", strerror(errno));
Jens Axboea7de0a12011-10-07 12:55:14 +0200439 log_err("fio: failed to connect to %s:%u\n", client->hostname,
440 client->port);
Jens Axboeb94cba42011-10-06 21:27:10 +0200441 close(fd);
Jens Axboe25095e12012-03-09 17:09:55 +0100442 return ret;
Jens Axboe132159a2011-09-30 15:01:32 -0600443 }
444
Jens Axboe87aa8f12011-10-06 21:24:13 +0200445 return fd;
446}
447
448static int fio_client_connect_sock(struct fio_client *client)
449{
450 struct sockaddr_un *addr = &client->addr_un;
Jens Axboe67bf9822013-01-10 11:23:19 +0100451 socklen_t len;
Jens Axboe87aa8f12011-10-06 21:24:13 +0200452 int fd;
453
454 memset(addr, 0, sizeof(*addr));
455 addr->sun_family = AF_UNIX;
Jens Axboe1cb96412014-04-14 08:50:33 -0600456 strncpy(addr->sun_path, client->hostname, sizeof(addr->sun_path) - 1);
Jens Axboe87aa8f12011-10-06 21:24:13 +0200457
458 fd = socket(AF_UNIX, SOCK_STREAM, 0);
459 if (fd < 0) {
Jens Axboe25095e12012-03-09 17:09:55 +0100460 int ret = -errno;
461
Jens Axboe87aa8f12011-10-06 21:24:13 +0200462 log_err("fio: socket: %s\n", strerror(errno));
Jens Axboe25095e12012-03-09 17:09:55 +0100463 return ret;
Jens Axboe87aa8f12011-10-06 21:24:13 +0200464 }
465
466 len = sizeof(addr->sun_family) + strlen(addr->sun_path) + 1;
467 if (connect(fd, (struct sockaddr *) addr, len) < 0) {
Jens Axboe25095e12012-03-09 17:09:55 +0100468 int ret = -errno;
469
Jens Axboe87aa8f12011-10-06 21:24:13 +0200470 log_err("fio: connect; %s\n", strerror(errno));
Jens Axboeb94cba42011-10-06 21:27:10 +0200471 close(fd);
Jens Axboe25095e12012-03-09 17:09:55 +0100472 return ret;
Jens Axboe87aa8f12011-10-06 21:24:13 +0200473 }
474
475 return fd;
476}
477
Jens Axboe2f99deb2012-03-09 14:37:29 +0100478int fio_client_connect(struct fio_client *client)
Jens Axboe87aa8f12011-10-06 21:24:13 +0200479{
480 int fd;
481
482 dprint(FD_NET, "client: connect to host %s\n", client->hostname);
483
Jens Axboe87aa8f12011-10-06 21:24:13 +0200484 if (client->is_sock)
485 fd = fio_client_connect_sock(client);
486 else
487 fd = fio_client_connect_ip(client);
488
Jens Axboe89c17072011-10-11 10:15:51 +0200489 dprint(FD_NET, "client: %s connected %d\n", client->hostname, fd);
490
Jens Axboe87aa8f12011-10-06 21:24:13 +0200491 if (fd < 0)
Jens Axboea1a3ed52012-03-09 17:00:01 +0100492 return fd;
Jens Axboe87aa8f12011-10-06 21:24:13 +0200493
Jens Axboeb66570d2011-10-01 11:11:35 -0600494 client->fd = fd;
Jens Axboebebe6392011-10-07 10:00:51 +0200495 fio_client_add_hash(client);
Jens Axboe81179ee2011-10-04 12:42:06 +0200496 client->state = Client_connected;
Jens Axboed824c3b2012-03-09 17:45:43 +0100497
498 probe_client(client);
Jens Axboe132159a2011-09-30 15:01:32 -0600499 return 0;
500}
501
Jens Axboe0cf3ece2012-03-21 10:15:20 +0100502int fio_client_terminate(struct fio_client *client)
Jens Axboe2f99deb2012-03-09 14:37:29 +0100503{
Jens Axboe0cf3ece2012-03-21 10:15:20 +0100504 return fio_net_send_quit(client->fd);
Jens Axboe2f99deb2012-03-09 14:37:29 +0100505}
506
Jens Axboecc0df002011-10-03 20:53:32 +0200507void fio_clients_terminate(void)
508{
509 struct flist_head *entry;
510 struct fio_client *client;
511
Jens Axboe60efd142011-10-04 13:30:11 +0200512 dprint(FD_NET, "client: terminate clients\n");
513
Jens Axboecc0df002011-10-03 20:53:32 +0200514 flist_for_each(entry, &client_list) {
515 client = flist_entry(entry, struct fio_client, list);
Jens Axboe2f99deb2012-03-09 14:37:29 +0100516 fio_client_terminate(client);
Jens Axboecc0df002011-10-03 20:53:32 +0200517 }
518}
519
520static void sig_int(int sig)
521{
Jens Axboebebe6392011-10-07 10:00:51 +0200522 dprint(FD_NET, "client: got signal %d\n", sig);
Jens Axboecc0df002011-10-03 20:53:32 +0200523 fio_clients_terminate();
524}
525
Jens Axboeb852e7c2012-03-30 10:30:35 +0200526static void sig_show_status(int sig)
527{
528 show_running_run_stats();
529}
530
Jens Axboecc0df002011-10-03 20:53:32 +0200531static void client_signal_handler(void)
532{
533 struct sigaction act;
534
535 memset(&act, 0, sizeof(act));
536 act.sa_handler = sig_int;
537 act.sa_flags = SA_RESTART;
538 sigaction(SIGINT, &act, NULL);
539
540 memset(&act, 0, sizeof(act));
541 act.sa_handler = sig_int;
542 act.sa_flags = SA_RESTART;
543 sigaction(SIGTERM, &act, NULL);
Jens Axboeb852e7c2012-03-30 10:30:35 +0200544
Bruce Cran2f694502012-10-10 16:34:13 +0100545/* Windows uses SIGBREAK as a quit signal from other applications */
546#ifdef WIN32
547 memset(&act, 0, sizeof(act));
548 act.sa_handler = sig_int;
549 act.sa_flags = SA_RESTART;
550 sigaction(SIGBREAK, &act, NULL);
551#endif
552
Jens Axboeb852e7c2012-03-30 10:30:35 +0200553 memset(&act, 0, sizeof(act));
554 act.sa_handler = sig_show_status;
555 act.sa_flags = SA_RESTART;
556 sigaction(SIGUSR1, &act, NULL);
Jens Axboecc0df002011-10-03 20:53:32 +0200557}
558
Jens Axboe81179ee2011-10-04 12:42:06 +0200559static int send_client_cmd_line(struct fio_client *client)
560{
Jens Axboefa2ea802011-10-08 21:07:29 +0200561 struct cmd_single_line_pdu *cslp;
562 struct cmd_line_pdu *clp;
563 unsigned long offset;
Jens Axboe7f868312011-10-10 09:55:21 +0200564 unsigned int *lens;
Jens Axboefa2ea802011-10-08 21:07:29 +0200565 void *pdu;
566 size_t mem;
Jens Axboe81179ee2011-10-04 12:42:06 +0200567 int i, ret;
568
Jens Axboe39e8e012011-10-04 13:46:08 +0200569 dprint(FD_NET, "client: send cmdline %d\n", client->argc);
Jens Axboe60efd142011-10-04 13:30:11 +0200570
Jens Axboe7f868312011-10-10 09:55:21 +0200571 lens = malloc(client->argc * sizeof(unsigned int));
572
Jens Axboefa2ea802011-10-08 21:07:29 +0200573 /*
574 * Find out how much mem we need
575 */
Jens Axboe7f868312011-10-10 09:55:21 +0200576 for (i = 0, mem = 0; i < client->argc; i++) {
577 lens[i] = strlen(client->argv[i]) + 1;
578 mem += lens[i];
579 }
Jens Axboe81179ee2011-10-04 12:42:06 +0200580
Jens Axboefa2ea802011-10-08 21:07:29 +0200581 /*
582 * We need one cmd_line_pdu, and argc number of cmd_single_line_pdu
583 */
584 mem += sizeof(*clp) + (client->argc * sizeof(*cslp));
585
586 pdu = malloc(mem);
587 clp = pdu;
588 offset = sizeof(*clp);
589
590 for (i = 0; i < client->argc; i++) {
Jens Axboe7f868312011-10-10 09:55:21 +0200591 uint16_t arg_len = lens[i];
Jens Axboefa2ea802011-10-08 21:07:29 +0200592
593 cslp = pdu + offset;
594 strcpy((char *) cslp->text, client->argv[i]);
595 cslp->len = cpu_to_le16(arg_len);
596 offset += sizeof(*cslp) + arg_len;
597 }
598
Jens Axboe7f868312011-10-10 09:55:21 +0200599 free(lens);
Jens Axboefa2ea802011-10-08 21:07:29 +0200600 clp->lines = cpu_to_le16(client->argc);
Jens Axboe46bcd492012-03-14 11:31:21 +0100601 clp->client_type = __cpu_to_le16(client->type);
Jens Axboe40c60512012-03-27 16:03:04 +0200602 ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOBLINE, pdu, mem, NULL, NULL);
Jens Axboe81179ee2011-10-04 12:42:06 +0200603 free(pdu);
604 return ret;
605}
606
Jens Axboea37f69b2011-10-01 12:24:21 -0600607int fio_clients_connect(void)
608{
609 struct fio_client *client;
610 struct flist_head *entry, *tmp;
611 int ret;
612
Bruce Cran93bcfd22012-02-20 20:18:19 +0100613#ifdef WIN32
614 WSADATA wsd;
Jens Axboe3c3ed072012-03-27 09:12:39 +0200615 WSAStartup(MAKEWORD(2, 2), &wsd);
Bruce Cran93bcfd22012-02-20 20:18:19 +0100616#endif
617
Jens Axboe60efd142011-10-04 13:30:11 +0200618 dprint(FD_NET, "client: connect all\n");
619
Jens Axboecc0df002011-10-03 20:53:32 +0200620 client_signal_handler();
621
Jens Axboea37f69b2011-10-01 12:24:21 -0600622 flist_for_each_safe(entry, tmp, &client_list) {
623 client = flist_entry(entry, struct fio_client, list);
624
625 ret = fio_client_connect(client);
Jens Axboe0b8f30a2011-10-04 10:31:53 +0200626 if (ret) {
Jens Axboea37f69b2011-10-01 12:24:21 -0600627 remove_client(client);
Jens Axboe0b8f30a2011-10-04 10:31:53 +0200628 continue;
629 }
630
Jens Axboe81179ee2011-10-04 12:42:06 +0200631 if (client->argc > 1)
632 send_client_cmd_line(client);
Jens Axboea37f69b2011-10-01 12:24:21 -0600633 }
634
635 return !nr_clients;
636}
637
Jens Axboeb9d2f302012-03-08 20:36:28 +0100638int fio_start_client(struct fio_client *client)
639{
640 dprint(FD_NET, "client: start %s\n", client->hostname);
641 return fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_RUN, 0, NULL);
642}
643
644int fio_start_all_clients(void)
645{
646 struct fio_client *client;
647 struct flist_head *entry, *tmp;
648 int ret;
649
650 dprint(FD_NET, "client: start all\n");
651
Castor Fu952b05e2013-10-31 11:00:34 -0600652 fio_client_json_init();
653
Jens Axboeb9d2f302012-03-08 20:36:28 +0100654 flist_for_each_safe(entry, tmp, &client_list) {
655 client = flist_entry(entry, struct fio_client, list);
656
657 ret = fio_start_client(client);
658 if (ret) {
659 remove_client(client);
660 continue;
661 }
662 }
663
664 return flist_empty(&client_list);
665}
666
Jens Axboe35899182014-10-07 20:56:28 -0600667static int __fio_client_send_remote_ini(struct fio_client *client,
668 const char *filename)
669{
670 struct cmd_load_file_pdu *pdu;
671 size_t p_size;
672 int ret;
673
674 dprint(FD_NET, "send remote ini %s to %s\n", filename, client->hostname);
675
Jens Axboe79ecc302014-10-07 22:02:21 -0600676 p_size = sizeof(*pdu) + strlen(filename) + 1;
Jens Axboe35899182014-10-07 20:56:28 -0600677 pdu = malloc(p_size);
Jens Axboe79ecc302014-10-07 22:02:21 -0600678 memset(pdu, 0, p_size);
Jens Axboe35899182014-10-07 20:56:28 -0600679 pdu->name_len = strlen(filename);
680 strcpy((char *) pdu->file, filename);
681 pdu->client_type = cpu_to_le16((uint16_t) client->type);
682
683 client->sent_job = 1;
684 ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_LOAD_FILE, pdu, p_size,NULL, NULL);
685 free(pdu);
686 return ret;
687}
688
Jens Axboe132159a2011-09-30 15:01:32 -0600689/*
690 * Send file contents to server backend. We could use sendfile(), but to remain
691 * more portable lets just read/write the darn thing.
692 */
Jens Axboe35899182014-10-07 20:56:28 -0600693static int __fio_client_send_local_ini(struct fio_client *client,
694 const char *filename)
Jens Axboe132159a2011-09-30 15:01:32 -0600695{
Jens Axboe46bcd492012-03-14 11:31:21 +0100696 struct cmd_job_pdu *pdu;
697 size_t p_size;
Jens Axboe132159a2011-09-30 15:01:32 -0600698 struct stat sb;
Jens Axboe46bcd492012-03-14 11:31:21 +0100699 char *p;
700 void *buf;
Jens Axboe132159a2011-09-30 15:01:32 -0600701 off_t len;
702 int fd, ret;
703
Jens Axboe46c48f12011-10-01 12:50:51 -0600704 dprint(FD_NET, "send ini %s to %s\n", filename, client->hostname);
705
Jens Axboe132159a2011-09-30 15:01:32 -0600706 fd = open(filename, O_RDONLY);
707 if (fd < 0) {
Jens Axboe0f7f9a92014-11-06 09:21:10 -0700708 ret = -errno;
Jens Axboee951bdc2011-10-05 21:58:45 +0200709 log_err("fio: job file <%s> open: %s\n", filename, strerror(errno));
Jens Axboe25095e12012-03-09 17:09:55 +0100710 return ret;
Jens Axboe132159a2011-09-30 15:01:32 -0600711 }
712
713 if (fstat(fd, &sb) < 0) {
Jens Axboe0f7f9a92014-11-06 09:21:10 -0700714 ret = -errno;
Jens Axboe132159a2011-09-30 15:01:32 -0600715 log_err("fio: job file stat: %s\n", strerror(errno));
Jens Axboeb94cba42011-10-06 21:27:10 +0200716 close(fd);
Jens Axboe25095e12012-03-09 17:09:55 +0100717 return ret;
Jens Axboe132159a2011-09-30 15:01:32 -0600718 }
719
Jens Axboe46bcd492012-03-14 11:31:21 +0100720 p_size = sb.st_size + sizeof(*pdu);
721 pdu = malloc(p_size);
722 buf = pdu->buf;
Jens Axboe132159a2011-09-30 15:01:32 -0600723
724 len = sb.st_size;
725 p = buf;
Jens Axboe3d0be7c2014-11-11 10:24:00 -0700726 if (read_data(fd, p, len)) {
Jens Axboe0b8f30a2011-10-04 10:31:53 +0200727 log_err("fio: failed reading job file %s\n", filename);
Jens Axboeb94cba42011-10-06 21:27:10 +0200728 close(fd);
Hong Zhiguo03a22d92013-10-16 08:35:12 -0600729 free(pdu);
Jens Axboe0b8f30a2011-10-04 10:31:53 +0200730 return 1;
731 }
732
Jens Axboe46bcd492012-03-14 11:31:21 +0100733 pdu->buf_len = __cpu_to_le32(sb.st_size);
734 pdu->client_type = cpu_to_le32(client->type);
735
Jens Axboec2cb6862012-02-23 20:56:12 +0100736 client->sent_job = 1;
Jens Axboe40c60512012-03-27 16:03:04 +0200737 ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOB, pdu, p_size, NULL, NULL);
Jens Axboe46bcd492012-03-14 11:31:21 +0100738 free(pdu);
Jens Axboeb94cba42011-10-06 21:27:10 +0200739 close(fd);
Jens Axboe132159a2011-09-30 15:01:32 -0600740 return ret;
741}
Jens Axboe37db14f2011-09-30 17:00:42 -0600742
Jens Axboe35899182014-10-07 20:56:28 -0600743int fio_client_send_ini(struct fio_client *client, const char *filename,
744 int remote)
Jens Axboe9988ca72012-03-09 15:14:06 +0100745{
Jens Axboe25095e12012-03-09 17:09:55 +0100746 int ret;
747
Jens Axboe35899182014-10-07 20:56:28 -0600748 if (!remote)
749 ret = __fio_client_send_local_ini(client, filename);
750 else
751 ret = __fio_client_send_remote_ini(client, filename);
752
Jens Axboe3af45202012-03-13 09:59:53 +0100753 if (!ret)
754 client->sent_job = 1;
Jens Axboe9988ca72012-03-09 15:14:06 +0100755
Jens Axboe25095e12012-03-09 17:09:55 +0100756 return ret;
Jens Axboe9988ca72012-03-09 15:14:06 +0100757}
758
Jens Axboe35899182014-10-07 20:56:28 -0600759static int fio_client_send_cf(struct fio_client *client,
760 struct client_file *cf)
761{
762 return fio_client_send_ini(client, cf->file, cf->remote);
763}
764
Jens Axboea37f69b2011-10-01 12:24:21 -0600765int fio_clients_send_ini(const char *filename)
766{
767 struct fio_client *client;
768 struct flist_head *entry, *tmp;
769
770 flist_for_each_safe(entry, tmp, &client_list) {
771 client = flist_entry(entry, struct fio_client, list);
772
Jens Axboe35899182014-10-07 20:56:28 -0600773 if (client->nr_files) {
Jens Axboe14ea90e2012-08-26 17:33:34 +0200774 int i;
775
Jens Axboe35899182014-10-07 20:56:28 -0600776 for (i = 0; i < client->nr_files; i++) {
777 struct client_file *cf;
Jens Axboe14ea90e2012-08-26 17:33:34 +0200778
Jens Axboe35899182014-10-07 20:56:28 -0600779 cf = &client->files[i];
780
781 if (fio_client_send_cf(client, cf)) {
Jens Axboe14ea90e2012-08-26 17:33:34 +0200782 remove_client(client);
783 break;
784 }
785 }
Jens Axboe35899182014-10-07 20:56:28 -0600786 }
787 if (client->sent_job)
788 continue;
789 if (!filename || fio_client_send_ini(client, filename, 0))
Jens Axboe3af45202012-03-13 09:59:53 +0100790 remove_client(client);
Jens Axboea37f69b2011-10-01 12:24:21 -0600791 }
792
793 return !nr_clients;
794}
795
Jens Axboe40c60512012-03-27 16:03:04 +0200796int fio_client_update_options(struct fio_client *client,
797 struct thread_options *o, uint64_t *tag)
798{
799 struct cmd_add_job_pdu pdu;
800
801 pdu.thread_number = cpu_to_le32(client->thread_number);
802 pdu.groupid = cpu_to_le32(client->groupid);
803 convert_thread_options_to_net(&pdu.top, o);
Castor Fu952b05e2013-10-31 11:00:34 -0600804
Jens Axboe40c60512012-03-27 16:03:04 +0200805 return fio_net_send_cmd(client->fd, FIO_NET_CMD_UPDATE_JOB, &pdu, sizeof(pdu), tag, &client->cmd_list);
806}
807
Jens Axboea64e88d2011-10-03 14:20:01 +0200808static void convert_io_stat(struct io_stat *dst, struct io_stat *src)
809{
810 dst->max_val = le64_to_cpu(src->max_val);
811 dst->min_val = le64_to_cpu(src->min_val);
812 dst->samples = le64_to_cpu(src->samples);
Jens Axboe802ad4a2011-10-05 09:51:58 +0200813
814 /*
815 * Floats arrive as IEEE 754 encoded uint64_t, convert back to double
816 */
817 dst->mean.u.f = fio_uint64_to_double(le64_to_cpu(dst->mean.u.i));
818 dst->S.u.f = fio_uint64_to_double(le64_to_cpu(dst->S.u.i));
Jens Axboea64e88d2011-10-03 14:20:01 +0200819}
820
821static void convert_ts(struct thread_stat *dst, struct thread_stat *src)
822{
823 int i, j;
824
Jens Axboe2f122b12012-03-15 13:10:19 +0100825 dst->error = le32_to_cpu(src->error);
826 dst->thread_number = le32_to_cpu(src->thread_number);
827 dst->groupid = le32_to_cpu(src->groupid);
828 dst->pid = le32_to_cpu(src->pid);
829 dst->members = le32_to_cpu(src->members);
Jens Axboe771e58b2013-01-30 12:56:23 +0100830 dst->unified_rw_rep = le32_to_cpu(src->unified_rw_rep);
Jens Axboea64e88d2011-10-03 14:20:01 +0200831
Jens Axboe298921d2012-09-24 18:47:01 +0200832 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
Jens Axboea64e88d2011-10-03 14:20:01 +0200833 convert_io_stat(&dst->clat_stat[i], &src->clat_stat[i]);
834 convert_io_stat(&dst->slat_stat[i], &src->slat_stat[i]);
835 convert_io_stat(&dst->lat_stat[i], &src->lat_stat[i]);
836 convert_io_stat(&dst->bw_stat[i], &src->bw_stat[i]);
837 }
838
839 dst->usr_time = le64_to_cpu(src->usr_time);
840 dst->sys_time = le64_to_cpu(src->sys_time);
841 dst->ctx = le64_to_cpu(src->ctx);
842 dst->minf = le64_to_cpu(src->minf);
843 dst->majf = le64_to_cpu(src->majf);
844 dst->clat_percentiles = le64_to_cpu(src->clat_percentiles);
Jens Axboe623216d2014-11-07 18:47:41 -0700845 dst->percentile_precision = le64_to_cpu(src->percentile_precision);
Jens Axboe802ad4a2011-10-05 09:51:58 +0200846
847 for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) {
848 fio_fp64_t *fps = &src->percentile_list[i];
849 fio_fp64_t *fpd = &dst->percentile_list[i];
850
851 fpd->u.f = fio_uint64_to_double(le64_to_cpu(fps->u.i));
852 }
Jens Axboea64e88d2011-10-03 14:20:01 +0200853
854 for (i = 0; i < FIO_IO_U_MAP_NR; i++) {
855 dst->io_u_map[i] = le32_to_cpu(src->io_u_map[i]);
856 dst->io_u_submit[i] = le32_to_cpu(src->io_u_submit[i]);
857 dst->io_u_complete[i] = le32_to_cpu(src->io_u_complete[i]);
858 }
859
860 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) {
861 dst->io_u_lat_u[i] = le32_to_cpu(src->io_u_lat_u[i]);
862 dst->io_u_lat_m[i] = le32_to_cpu(src->io_u_lat_m[i]);
863 }
864
Jens Axboe298921d2012-09-24 18:47:01 +0200865 for (i = 0; i < DDIR_RWDIR_CNT; i++)
Jens Axboea64e88d2011-10-03 14:20:01 +0200866 for (j = 0; j < FIO_IO_U_PLAT_NR; j++)
867 dst->io_u_plat[i][j] = le32_to_cpu(src->io_u_plat[i][j]);
868
Jens Axboe78799de2013-01-29 20:53:52 +0100869 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
Jens Axboea64e88d2011-10-03 14:20:01 +0200870 dst->total_io_u[i] = le64_to_cpu(src->total_io_u[i]);
Jens Axboe93eee042011-10-03 21:08:48 +0200871 dst->short_io_u[i] = le64_to_cpu(src->short_io_u[i]);
Jens Axboe67e149c2014-10-09 13:27:44 -0600872 dst->drop_io_u[i] = le64_to_cpu(src->drop_io_u[i]);
Jens Axboea64e88d2011-10-03 14:20:01 +0200873 }
874
875 dst->total_submit = le64_to_cpu(src->total_submit);
876 dst->total_complete = le64_to_cpu(src->total_complete);
877
Jens Axboe298921d2012-09-24 18:47:01 +0200878 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
Jens Axboea64e88d2011-10-03 14:20:01 +0200879 dst->io_bytes[i] = le64_to_cpu(src->io_bytes[i]);
880 dst->runtime[i] = le64_to_cpu(src->runtime[i]);
881 }
882
883 dst->total_run_time = le64_to_cpu(src->total_run_time);
884 dst->continue_on_error = le16_to_cpu(src->continue_on_error);
885 dst->total_err_count = le64_to_cpu(src->total_err_count);
Jens Axboeddcc0b62011-10-03 14:45:27 +0200886 dst->first_error = le32_to_cpu(src->first_error);
887 dst->kb_base = le32_to_cpu(src->kb_base);
Steven Noonanad705bc2013-04-08 15:05:25 -0700888 dst->unit_base = le32_to_cpu(src->unit_base);
Jens Axboe3e260a42013-12-09 12:38:53 -0700889
890 dst->latency_depth = le32_to_cpu(src->latency_depth);
891 dst->latency_target = le64_to_cpu(src->latency_target);
892 dst->latency_window = le64_to_cpu(src->latency_window);
893 dst->latency_percentile.u.f = fio_uint64_to_double(le64_to_cpu(src->latency_percentile.u.i));
Jens Axboea64e88d2011-10-03 14:20:01 +0200894}
895
896static void convert_gs(struct group_run_stats *dst, struct group_run_stats *src)
897{
898 int i;
899
Jens Axboe298921d2012-09-24 18:47:01 +0200900 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
Jens Axboea64e88d2011-10-03 14:20:01 +0200901 dst->max_run[i] = le64_to_cpu(src->max_run[i]);
902 dst->min_run[i] = le64_to_cpu(src->min_run[i]);
903 dst->max_bw[i] = le64_to_cpu(src->max_bw[i]);
904 dst->min_bw[i] = le64_to_cpu(src->min_bw[i]);
905 dst->io_kb[i] = le64_to_cpu(src->io_kb[i]);
906 dst->agg[i] = le64_to_cpu(src->agg[i]);
907 }
908
909 dst->kb_base = le32_to_cpu(src->kb_base);
Steven Noonanad705bc2013-04-08 15:05:25 -0700910 dst->unit_base = le32_to_cpu(src->unit_base);
Jens Axboea64e88d2011-10-03 14:20:01 +0200911 dst->groupid = le32_to_cpu(src->groupid);
Jens Axboe771e58b2013-01-30 12:56:23 +0100912 dst->unified_rw_rep = le32_to_cpu(src->unified_rw_rep);
Jens Axboea64e88d2011-10-03 14:20:01 +0200913}
914
Castor Fu952b05e2013-10-31 11:00:34 -0600915static void json_object_add_client_info(struct json_object *obj,
Castor Fu54bcda52014-08-22 17:16:44 -0500916 struct fio_client *client)
Castor Fu952b05e2013-10-31 11:00:34 -0600917{
Castor Fu54bcda52014-08-22 17:16:44 -0500918 const char *hostname = client->hostname ? client->hostname : "";
919
920 json_object_add_value_string(obj, "hostname", hostname);
Castor Fu952b05e2013-10-31 11:00:34 -0600921 json_object_add_value_int(obj, "port", client->port);
922}
923
Jens Axboe89e5fad2012-03-05 09:21:12 +0100924static void handle_ts(struct fio_client *client, struct fio_net_cmd *cmd)
Jens Axboea64e88d2011-10-03 14:20:01 +0200925{
926 struct cmd_ts_pdu *p = (struct cmd_ts_pdu *) cmd->payload;
Castor Fu952b05e2013-10-31 11:00:34 -0600927 struct json_object *tsobj;
Jens Axboea64e88d2011-10-03 14:20:01 +0200928
Castor Fu952b05e2013-10-31 11:00:34 -0600929 tsobj = show_thread_status(&p->ts, &p->rs);
Jens Axboe108fea72012-11-14 13:09:45 -0700930 client->did_stat = 1;
Castor Fu952b05e2013-10-31 11:00:34 -0600931 if (tsobj) {
932 json_object_add_client_info(tsobj, client);
933 json_array_add_value_object(clients_array, tsobj);
934 }
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200935
Jens Axboebfa8f5d2014-10-13 10:09:28 -0600936 if (sum_stat_clients <= 1)
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200937 return;
938
939 sum_thread_stats(&client_ts, &p->ts, sum_stat_nr);
940 sum_group_stats(&client_gs, &p->rs);
941
942 client_ts.members++;
Jens Axboe2f122b12012-03-15 13:10:19 +0100943 client_ts.thread_number = p->ts.thread_number;
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200944 client_ts.groupid = p->ts.groupid;
Jens Axboe771e58b2013-01-30 12:56:23 +0100945 client_ts.unified_rw_rep = p->ts.unified_rw_rep;
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200946
947 if (++sum_stat_nr == sum_stat_clients) {
948 strcpy(client_ts.name, "All clients");
Castor Fu952b05e2013-10-31 11:00:34 -0600949 tsobj = show_thread_status(&client_ts, &client_gs);
950 if (tsobj) {
951 json_object_add_client_info(tsobj, client);
952 json_array_add_value_object(clients_array, tsobj);
953 }
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200954 }
Jens Axboea64e88d2011-10-03 14:20:01 +0200955}
956
Jens Axboe89e5fad2012-03-05 09:21:12 +0100957static void handle_gs(struct fio_client *client, struct fio_net_cmd *cmd)
Jens Axboea64e88d2011-10-03 14:20:01 +0200958{
959 struct group_run_stats *gs = (struct group_run_stats *) cmd->payload;
960
Jens Axboea64e88d2011-10-03 14:20:01 +0200961 show_group_stats(gs);
962}
963
Jens Axboe3bf236c2012-03-03 20:35:50 +0100964static void handle_text(struct fio_client *client, struct fio_net_cmd *cmd)
965{
966 struct cmd_text_pdu *pdu = (struct cmd_text_pdu *) cmd->payload;
967 const char *buf = (const char *) pdu->buf;
968 const char *name;
969 int fio_unused ret;
970
971 name = client->name ? client->name : client->hostname;
972
973 if (!client->skip_newline)
974 fprintf(f_out, "<%s> ", name);
975 ret = fwrite(buf, pdu->buf_len, 1, f_out);
976 fflush(f_out);
977 client->skip_newline = strchr(buf, '\n') == NULL;
978}
979
Jens Axboed09a64a2011-10-13 11:38:56 +0200980static void convert_agg(struct disk_util_agg *agg)
981{
982 int i;
983
984 for (i = 0; i < 2; i++) {
Jens Axboe2a3bf762014-12-01 09:42:48 -0700985 agg->ios[i] = le64_to_cpu(agg->ios[i]);
986 agg->merges[i] = le64_to_cpu(agg->merges[i]);
Jens Axboed09a64a2011-10-13 11:38:56 +0200987 agg->sectors[i] = le64_to_cpu(agg->sectors[i]);
Jens Axboe2a3bf762014-12-01 09:42:48 -0700988 agg->ticks[i] = le64_to_cpu(agg->ticks[i]);
Jens Axboed09a64a2011-10-13 11:38:56 +0200989 }
990
Jens Axboe2a3bf762014-12-01 09:42:48 -0700991 agg->io_ticks = le64_to_cpu(agg->io_ticks);
992 agg->time_in_queue = le64_to_cpu(agg->time_in_queue);
Jens Axboed09a64a2011-10-13 11:38:56 +0200993 agg->slavecount = le32_to_cpu(agg->slavecount);
Jens Axboe2b827fa2014-10-13 16:05:10 -0600994 agg->max_util.u.f = fio_uint64_to_double(le64_to_cpu(agg->max_util.u.i));
Jens Axboed09a64a2011-10-13 11:38:56 +0200995}
996
997static void convert_dus(struct disk_util_stat *dus)
998{
999 int i;
1000
1001 for (i = 0; i < 2; i++) {
Jens Axboe2a3bf762014-12-01 09:42:48 -07001002 dus->s.ios[i] = le64_to_cpu(dus->s.ios[i]);
1003 dus->s.merges[i] = le64_to_cpu(dus->s.merges[i]);
Jens Axboea3b4cf72014-04-11 12:17:53 -06001004 dus->s.sectors[i] = le64_to_cpu(dus->s.sectors[i]);
Jens Axboe2a3bf762014-12-01 09:42:48 -07001005 dus->s.ticks[i] = le64_to_cpu(dus->s.ticks[i]);
Jens Axboed09a64a2011-10-13 11:38:56 +02001006 }
1007
Jens Axboe2a3bf762014-12-01 09:42:48 -07001008 dus->s.io_ticks = le64_to_cpu(dus->s.io_ticks);
1009 dus->s.time_in_queue = le64_to_cpu(dus->s.time_in_queue);
Jens Axboea3b4cf72014-04-11 12:17:53 -06001010 dus->s.msec = le64_to_cpu(dus->s.msec);
Jens Axboed09a64a2011-10-13 11:38:56 +02001011}
1012
1013static void handle_du(struct fio_client *client, struct fio_net_cmd *cmd)
1014{
1015 struct cmd_du_pdu *du = (struct cmd_du_pdu *) cmd->payload;
1016
Jens Axboed09a64a2011-10-13 11:38:56 +02001017 if (!client->disk_stats_shown) {
1018 client->disk_stats_shown = 1;
1019 log_info("\nDisk stats (read/write):\n");
1020 }
1021
Castor Fu952b05e2013-10-31 11:00:34 -06001022 if (output_format == FIO_OUTPUT_JSON) {
1023 struct json_object *duobj;
1024 json_array_add_disk_util(&du->dus, &du->agg, du_array);
1025 duobj = json_array_last_value_object(du_array);
1026 json_object_add_client_info(duobj, client);
1027 } else
1028 print_disk_util(&du->dus, &du->agg, output_format == FIO_OUTPUT_TERSE);
Jens Axboed09a64a2011-10-13 11:38:56 +02001029}
1030
Jens Axboe3bf236c2012-03-03 20:35:50 +01001031static void convert_jobs_eta(struct jobs_eta *je)
Jens Axboecf451d12011-10-03 16:48:30 +02001032{
Jens Axboecf451d12011-10-03 16:48:30 +02001033 int i;
1034
1035 je->nr_running = le32_to_cpu(je->nr_running);
1036 je->nr_ramp = le32_to_cpu(je->nr_ramp);
1037 je->nr_pending = le32_to_cpu(je->nr_pending);
Jens Axboe714e85f2013-04-15 10:21:56 +02001038 je->nr_setting_up = le32_to_cpu(je->nr_setting_up);
Jens Axboecf451d12011-10-03 16:48:30 +02001039 je->files_open = le32_to_cpu(je->files_open);
Jens Axboecf451d12011-10-03 16:48:30 +02001040
Jens Axboe298921d2012-09-24 18:47:01 +02001041 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
1042 je->m_rate[i] = le32_to_cpu(je->m_rate[i]);
1043 je->t_rate[i] = le32_to_cpu(je->t_rate[i]);
1044 je->m_iops[i] = le32_to_cpu(je->m_iops[i]);
1045 je->t_iops[i] = le32_to_cpu(je->t_iops[i]);
Jens Axboe16725bb2013-04-11 12:43:05 +02001046 je->rate[i] = le32_to_cpu(je->rate[i]);
1047 je->iops[i] = le32_to_cpu(je->iops[i]);
Jens Axboecf451d12011-10-03 16:48:30 +02001048 }
1049
Jens Axboeb51eedb2011-10-09 12:13:39 +02001050 je->elapsed_sec = le64_to_cpu(je->elapsed_sec);
Jens Axboecf451d12011-10-03 16:48:30 +02001051 je->eta_sec = le64_to_cpu(je->eta_sec);
Jens Axboe8c621fb2012-03-08 12:30:48 +01001052 je->nr_threads = le32_to_cpu(je->nr_threads);
Jens Axboeb7f05eb2012-05-11 20:33:02 +02001053 je->is_pow2 = le32_to_cpu(je->is_pow2);
Jens Axboeed2c0a12013-04-11 12:55:16 +02001054 je->unit_base = le32_to_cpu(je->unit_base);
Jens Axboe48fbb462011-10-09 12:19:08 +02001055}
Jens Axboecf451d12011-10-03 16:48:30 +02001056
Jens Axboe3e47bd22012-02-29 13:45:02 +01001057void fio_client_sum_jobs_eta(struct jobs_eta *dst, struct jobs_eta *je)
Jens Axboe48fbb462011-10-09 12:19:08 +02001058{
Jens Axboe48fbb462011-10-09 12:19:08 +02001059 int i;
1060
1061 dst->nr_running += je->nr_running;
1062 dst->nr_ramp += je->nr_ramp;
1063 dst->nr_pending += je->nr_pending;
Jens Axboe714e85f2013-04-15 10:21:56 +02001064 dst->nr_setting_up += je->nr_setting_up;
Jens Axboe48fbb462011-10-09 12:19:08 +02001065 dst->files_open += je->files_open;
Jens Axboe48fbb462011-10-09 12:19:08 +02001066
Jens Axboe298921d2012-09-24 18:47:01 +02001067 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
Jens Axboe3e47bd22012-02-29 13:45:02 +01001068 dst->m_rate[i] += je->m_rate[i];
1069 dst->t_rate[i] += je->t_rate[i];
1070 dst->m_iops[i] += je->m_iops[i];
1071 dst->t_iops[i] += je->t_iops[i];
Jens Axboe16725bb2013-04-11 12:43:05 +02001072 dst->rate[i] += je->rate[i];
1073 dst->iops[i] += je->iops[i];
Jens Axboe48fbb462011-10-09 12:19:08 +02001074 }
1075
1076 dst->elapsed_sec += je->elapsed_sec;
1077
1078 if (je->eta_sec > dst->eta_sec)
1079 dst->eta_sec = je->eta_sec;
Jens Axboe8c621fb2012-03-08 12:30:48 +01001080
1081 dst->nr_threads += je->nr_threads;
Jens Axboe27b91552014-06-27 15:30:06 -06001082
1083 /*
1084 * This wont be correct for multiple strings, but at least it
1085 * works for the basic cases.
1086 */
1087 strcpy((char *) dst->run_str, (char *) je->run_str);
Jens Axboe48fbb462011-10-09 12:19:08 +02001088}
1089
Jens Axboea5276612012-03-04 15:15:08 +01001090void fio_client_dec_jobs_eta(struct client_eta *eta, client_eta_op eta_fn)
Jens Axboe82c1ed32011-10-10 08:56:18 +02001091{
1092 if (!--eta->pending) {
Jens Axboea5276612012-03-04 15:15:08 +01001093 eta_fn(&eta->eta);
Jens Axboe82c1ed32011-10-10 08:56:18 +02001094 free(eta);
1095 }
1096}
1097
Jens Axboe89c17072011-10-11 10:15:51 +02001098static void remove_reply_cmd(struct fio_client *client, struct fio_net_cmd *cmd)
1099{
Jens Axboe40c60512012-03-27 16:03:04 +02001100 struct fio_net_cmd_reply *reply = NULL;
Jens Axboe89c17072011-10-11 10:15:51 +02001101 struct flist_head *entry;
1102
1103 flist_for_each(entry, &client->cmd_list) {
Jens Axboe40c60512012-03-27 16:03:04 +02001104 reply = flist_entry(entry, struct fio_net_cmd_reply, list);
Jens Axboe89c17072011-10-11 10:15:51 +02001105
Jens Axboe40c60512012-03-27 16:03:04 +02001106 if (cmd->tag == (uintptr_t) reply)
Jens Axboe89c17072011-10-11 10:15:51 +02001107 break;
1108
Jens Axboe40c60512012-03-27 16:03:04 +02001109 reply = NULL;
Jens Axboe89c17072011-10-11 10:15:51 +02001110 }
1111
Jens Axboe40c60512012-03-27 16:03:04 +02001112 if (!reply) {
Jens Axboe4e0a8fa2013-04-15 11:40:57 +02001113 log_err("fio: client: unable to find matching tag (%llx)\n", (unsigned long long) cmd->tag);
Jens Axboe89c17072011-10-11 10:15:51 +02001114 return;
1115 }
1116
Jens Axboe40c60512012-03-27 16:03:04 +02001117 flist_del(&reply->list);
1118 cmd->tag = reply->saved_tag;
1119 free(reply);
1120}
1121
1122int fio_client_wait_for_reply(struct fio_client *client, uint64_t tag)
1123{
1124 do {
1125 struct fio_net_cmd_reply *reply = NULL;
1126 struct flist_head *entry;
1127
1128 flist_for_each(entry, &client->cmd_list) {
1129 reply = flist_entry(entry, struct fio_net_cmd_reply, list);
1130
1131 if (tag == (uintptr_t) reply)
1132 break;
1133
1134 reply = NULL;
1135 }
1136
1137 if (!reply)
1138 break;
1139
1140 usleep(1000);
1141 } while (1);
1142
1143 return 0;
Jens Axboe89c17072011-10-11 10:15:51 +02001144}
1145
Jens Axboe82c1ed32011-10-10 08:56:18 +02001146static void handle_eta(struct fio_client *client, struct fio_net_cmd *cmd)
Jens Axboe48fbb462011-10-09 12:19:08 +02001147{
1148 struct jobs_eta *je = (struct jobs_eta *) cmd->payload;
Jens Axboedf380932011-10-11 14:25:08 +02001149 struct client_eta *eta = (struct client_eta *) (uintptr_t) cmd->tag;
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001150
1151 dprint(FD_NET, "client: got eta tag %p, %d\n", eta, eta->pending);
Jens Axboe48fbb462011-10-09 12:19:08 +02001152
Jens Axboef77d2672011-10-10 14:36:07 +02001153 assert(client->eta_in_flight == eta);
1154
1155 client->eta_in_flight = NULL;
Jens Axboe82c1ed32011-10-10 08:56:18 +02001156 flist_del_init(&client->eta_list);
1157
Jens Axboe2f99deb2012-03-09 14:37:29 +01001158 if (client->ops->jobs_eta)
1159 client->ops->jobs_eta(client, je);
1160
Jens Axboe3e47bd22012-02-29 13:45:02 +01001161 fio_client_sum_jobs_eta(&eta->eta, je);
Jens Axboea5276612012-03-04 15:15:08 +01001162 fio_client_dec_jobs_eta(eta, client->ops->eta);
Jens Axboecf451d12011-10-03 16:48:30 +02001163}
1164
Jens Axboeb5296dd2011-10-07 16:35:56 +02001165static void handle_probe(struct fio_client *client, struct fio_net_cmd *cmd)
Jens Axboe2e03b4b2011-10-04 09:00:40 +02001166{
Jens Axboe3989b142013-04-12 13:13:24 +02001167 struct cmd_probe_reply_pdu *probe = (struct cmd_probe_reply_pdu *) cmd->payload;
Jens Axboed2333352011-10-11 15:07:23 +02001168 const char *os, *arch;
1169 char bit[16];
Jens Axboe2e03b4b2011-10-04 09:00:40 +02001170
Jens Axboecca84642011-10-07 12:47:57 +02001171 os = fio_get_os_string(probe->os);
1172 if (!os)
1173 os = "unknown";
1174
1175 arch = fio_get_arch_string(probe->arch);
1176 if (!arch)
1177 os = "unknown";
1178
Jens Axboed2333352011-10-11 15:07:23 +02001179 sprintf(bit, "%d-bit", probe->bpp * 8);
Jens Axboe3989b142013-04-12 13:13:24 +02001180 probe->flags = le64_to_cpu(probe->flags);
Jens Axboe38fdef22011-10-11 14:30:06 +02001181
Jens Axboe3989b142013-04-12 13:13:24 +02001182 log_info("hostname=%s, be=%u, %s, os=%s, arch=%s, fio=%s, flags=%lx\n",
Jens Axboe38fdef22011-10-11 14:30:06 +02001183 probe->hostname, probe->bigendian, bit, os, arch,
Jens Axboe3989b142013-04-12 13:13:24 +02001184 probe->fio_version, (unsigned long) probe->flags);
Jens Axboeb5296dd2011-10-07 16:35:56 +02001185
1186 if (!client->name)
1187 client->name = strdup((char *) probe->hostname);
Jens Axboe2e03b4b2011-10-04 09:00:40 +02001188}
1189
Jens Axboe11e950b2011-10-16 21:34:14 +02001190static void handle_start(struct fio_client *client, struct fio_net_cmd *cmd)
1191{
1192 struct cmd_start_pdu *pdu = (struct cmd_start_pdu *) cmd->payload;
1193
1194 client->state = Client_started;
1195 client->jobs = le32_to_cpu(pdu->jobs);
Jens Axboe30f8e312014-10-13 11:33:27 -06001196 client->nr_stat = le32_to_cpu(pdu->stat_outputs);
Jens Axboe108fea72012-11-14 13:09:45 -07001197
Jens Axboe30f8e312014-10-13 11:33:27 -06001198 sum_stat_clients += client->nr_stat;
Jens Axboe11e950b2011-10-16 21:34:14 +02001199}
1200
1201static void handle_stop(struct fio_client *client, struct fio_net_cmd *cmd)
1202{
Jens Axboe498c92c2011-10-17 09:14:42 +02001203 if (client->error)
1204 log_info("client <%s>: exited with error %d\n", client->hostname, client->error);
Jens Axboe11e950b2011-10-16 21:34:14 +02001205}
1206
Jens Axboe6b79c802012-03-08 10:51:36 +01001207static void convert_stop(struct fio_net_cmd *cmd)
1208{
1209 struct cmd_end_pdu *pdu = (struct cmd_end_pdu *) cmd->payload;
1210
1211 pdu->error = le32_to_cpu(pdu->error);
1212}
1213
Jens Axboe084d1c62012-03-03 20:28:07 +01001214static void convert_text(struct fio_net_cmd *cmd)
1215{
1216 struct cmd_text_pdu *pdu = (struct cmd_text_pdu *) cmd->payload;
1217
1218 pdu->level = le32_to_cpu(pdu->level);
1219 pdu->buf_len = le32_to_cpu(pdu->buf_len);
1220 pdu->log_sec = le64_to_cpu(pdu->log_sec);
1221 pdu->log_usec = le64_to_cpu(pdu->log_usec);
1222}
1223
Jens Axboe3989b142013-04-12 13:13:24 +02001224static struct cmd_iolog_pdu *convert_iolog_gz(struct fio_net_cmd *cmd,
1225 struct cmd_iolog_pdu *pdu)
Jens Axboe1b427252012-03-14 15:03:03 +01001226{
Jens Axboe3989b142013-04-12 13:13:24 +02001227#ifdef CONFIG_ZLIB
Jens Axboe1b427252012-03-14 15:03:03 +01001228 struct cmd_iolog_pdu *ret;
Jens Axboe1b427252012-03-14 15:03:03 +01001229 z_stream stream;
Jens Axboe3989b142013-04-12 13:13:24 +02001230 uint32_t nr_samples;
1231 size_t total;
Jens Axboe1b427252012-03-14 15:03:03 +01001232 void *p;
1233
1234 stream.zalloc = Z_NULL;
1235 stream.zfree = Z_NULL;
1236 stream.opaque = Z_NULL;
1237 stream.avail_in = 0;
1238 stream.next_in = Z_NULL;
1239
1240 if (inflateInit(&stream) != Z_OK)
1241 return NULL;
1242
1243 /*
Jens Axboef5ed7652012-03-14 16:28:07 +01001244 * Get header first, it's not compressed
Jens Axboe1b427252012-03-14 15:03:03 +01001245 */
Jens Axboef2b9a672014-07-01 08:47:11 -06001246 nr_samples = le64_to_cpu(pdu->nr_samples);
Jens Axboe1b427252012-03-14 15:03:03 +01001247
Jens Axboef2b9a672014-07-01 08:47:11 -06001248 total = nr_samples * __log_entry_sz(le32_to_cpu(pdu->log_offset));
Jens Axboef5ed7652012-03-14 16:28:07 +01001249 ret = malloc(total + sizeof(*pdu));
Jens Axboe1b427252012-03-14 15:03:03 +01001250 ret->nr_samples = nr_samples;
Jens Axboe3989b142013-04-12 13:13:24 +02001251
1252 memcpy(ret, pdu, sizeof(*pdu));
Jens Axboe1b427252012-03-14 15:03:03 +01001253
Jens Axboef5ed7652012-03-14 16:28:07 +01001254 p = (void *) ret + sizeof(*pdu);
1255
1256 stream.avail_in = cmd->pdu_len - sizeof(*pdu);
1257 stream.next_in = (void *) pdu + sizeof(*pdu);
Jens Axboe1b427252012-03-14 15:03:03 +01001258 while (stream.avail_in) {
1259 unsigned int this_chunk = 65536;
1260 unsigned int this_len;
1261 int err;
1262
1263 if (this_chunk > total)
1264 this_chunk = total;
1265
1266 stream.avail_out = this_chunk;
1267 stream.next_out = p;
1268 err = inflate(&stream, Z_NO_FLUSH);
Jens Axboe3c547fe2012-03-14 21:53:00 +01001269 /* may be Z_OK, or Z_STREAM_END */
1270 if (err < 0) {
Jens Axboe1b427252012-03-14 15:03:03 +01001271 log_err("fio: inflate error %d\n", err);
Jens Axboef5ed7652012-03-14 16:28:07 +01001272 free(ret);
1273 ret = NULL;
Jens Axboe3989b142013-04-12 13:13:24 +02001274 goto err;
Jens Axboe1b427252012-03-14 15:03:03 +01001275 }
1276
1277 this_len = this_chunk - stream.avail_out;
1278 p += this_len;
1279 total -= this_len;
1280 }
1281
Jens Axboe3989b142013-04-12 13:13:24 +02001282err:
1283 inflateEnd(&stream);
1284 return ret;
1285#else
1286 return NULL;
1287#endif
1288}
1289
1290/*
1291 * This has been compressed on the server side, since it can be big.
1292 * Uncompress here.
1293 */
1294static struct cmd_iolog_pdu *convert_iolog(struct fio_net_cmd *cmd)
1295{
1296 struct cmd_iolog_pdu *pdu = (struct cmd_iolog_pdu *) cmd->payload;
1297 struct cmd_iolog_pdu *ret;
Jens Axboeccefd5f2014-06-30 20:59:03 -06001298 uint64_t i;
1299 void *samples;
Jens Axboe3989b142013-04-12 13:13:24 +02001300
1301 /*
1302 * Convert if compressed and we support it. If it's not
1303 * compressed, we need not do anything.
1304 */
1305 if (le32_to_cpu(pdu->compressed)) {
1306#ifndef CONFIG_ZLIB
1307 log_err("fio: server sent compressed data by mistake\n");
1308 return NULL;
1309#endif
1310 ret = convert_iolog_gz(cmd, pdu);
1311 if (!ret) {
1312 log_err("fio: failed decompressing log\n");
1313 return NULL;
1314 }
1315 } else
1316 ret = pdu;
1317
Jens Axboeccefd5f2014-06-30 20:59:03 -06001318 ret->nr_samples = le64_to_cpu(ret->nr_samples);
Jens Axboe3989b142013-04-12 13:13:24 +02001319 ret->thread_number = le32_to_cpu(ret->thread_number);
Jens Axboe3989b142013-04-12 13:13:24 +02001320 ret->log_type = le32_to_cpu(ret->log_type);
1321 ret->compressed = le32_to_cpu(ret->compressed);
Jens Axboeccefd5f2014-06-30 20:59:03 -06001322 ret->log_offset = le32_to_cpu(ret->log_offset);
Jens Axboe3989b142013-04-12 13:13:24 +02001323
Jens Axboee8c4fb02014-07-01 16:07:59 -06001324 samples = &ret->samples[0];
Jens Axboef5ed7652012-03-14 16:28:07 +01001325 for (i = 0; i < ret->nr_samples; i++) {
Jens Axboeccefd5f2014-06-30 20:59:03 -06001326 struct io_sample *s;
Jens Axboef5ed7652012-03-14 16:28:07 +01001327
Jens Axboeccefd5f2014-06-30 20:59:03 -06001328 s = __get_sample(samples, ret->log_offset, i);
Jens Axboebac4af12014-07-03 13:42:28 -06001329 s->time = le64_to_cpu(s->time);
1330 s->val = le64_to_cpu(s->val);
1331 s->__ddir = le32_to_cpu(s->__ddir);
1332 s->bs = le32_to_cpu(s->bs);
Jens Axboeccefd5f2014-06-30 20:59:03 -06001333
1334 if (ret->log_offset) {
1335 struct io_sample_offset *so = (void *) s;
1336
1337 so->offset = le64_to_cpu(so->offset);
1338 }
Jens Axboef5ed7652012-03-14 16:28:07 +01001339 }
1340
Jens Axboe1b427252012-03-14 15:03:03 +01001341 return ret;
1342}
1343
Jens Axboede54cfd2014-11-10 20:34:00 -07001344static void sendfile_reply(int fd, struct cmd_sendfile_reply *rep,
1345 size_t size, uint64_t tag)
1346{
1347 rep->error = cpu_to_le32(rep->error);
1348 fio_net_send_cmd(fd, FIO_NET_CMD_SENDFILE, rep, size, &tag, NULL);
1349}
1350
Jens Axboede54cfd2014-11-10 20:34:00 -07001351static int send_file(struct fio_client *client, struct cmd_sendfile *pdu,
1352 uint64_t tag)
1353{
1354 struct cmd_sendfile_reply *rep;
1355 struct stat sb;
1356 size_t size;
1357 int fd;
1358
1359 size = sizeof(*rep);
1360 rep = malloc(size);
1361
1362 if (stat((char *)pdu->path, &sb) < 0) {
1363fail:
1364 rep->error = errno;
1365 sendfile_reply(client->fd, rep, size, tag);
1366 free(rep);
1367 return 1;
1368 }
1369
1370 size += sb.st_size;
1371 rep = realloc(rep, size);
1372 rep->size = cpu_to_le32((uint32_t) sb.st_size);
1373
1374 fd = open((char *)pdu->path, O_RDONLY);
1375 if (fd == -1 )
1376 goto fail;
1377
1378 rep->error = read_data(fd, &rep->data, sb.st_size);
1379 sendfile_reply(client->fd, rep, size, tag);
1380 free(rep);
1381 close(fd);
1382 return 0;
1383}
1384
Jens Axboea5276612012-03-04 15:15:08 +01001385int fio_handle_client(struct fio_client *client)
Jens Axboe37db14f2011-09-30 17:00:42 -06001386{
Jens Axboea5276612012-03-04 15:15:08 +01001387 struct client_ops *ops = client->ops;
Jens Axboe37db14f2011-09-30 17:00:42 -06001388 struct fio_net_cmd *cmd;
1389
Jens Axboe60efd142011-10-04 13:30:11 +02001390 dprint(FD_NET, "client: handle %s\n", client->hostname);
1391
Jens Axboee951bdc2011-10-05 21:58:45 +02001392 cmd = fio_net_recv_cmd(client->fd);
1393 if (!cmd)
1394 return 0;
Jens Axboec2c94582011-10-05 20:31:30 +02001395
Jens Axboeb9d2f302012-03-08 20:36:28 +01001396 dprint(FD_NET, "client: got cmd op %s from %s (pdu=%u)\n",
1397 fio_server_op(cmd->opcode), client->hostname, cmd->pdu_len);
Jens Axboe46c48f12011-10-01 12:50:51 -06001398
Jens Axboee951bdc2011-10-05 21:58:45 +02001399 switch (cmd->opcode) {
1400 case FIO_NET_CMD_QUIT:
Jens Axboe3ec62ec2012-03-01 12:01:29 +01001401 if (ops->quit)
Jens Axboe35c0ba72012-03-14 10:56:40 +01001402 ops->quit(client, cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001403 remove_client(client);
Jens Axboee951bdc2011-10-05 21:58:45 +02001404 break;
Jens Axboe084d1c62012-03-03 20:28:07 +01001405 case FIO_NET_CMD_TEXT:
1406 convert_text(cmd);
Jens Axboe35c0ba72012-03-14 10:56:40 +01001407 ops->text(client, cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001408 break;
Jens Axboe3bf236c2012-03-03 20:35:50 +01001409 case FIO_NET_CMD_DU: {
1410 struct cmd_du_pdu *du = (struct cmd_du_pdu *) cmd->payload;
1411
1412 convert_dus(&du->dus);
1413 convert_agg(&du->agg);
1414
Stephen M. Camerondd366722012-02-24 08:17:30 +01001415 ops->disk_util(client, cmd);
Jens Axboed09a64a2011-10-13 11:38:56 +02001416 break;
Jens Axboe3bf236c2012-03-03 20:35:50 +01001417 }
1418 case FIO_NET_CMD_TS: {
1419 struct cmd_ts_pdu *p = (struct cmd_ts_pdu *) cmd->payload;
1420
1421 convert_ts(&p->ts, &p->ts);
1422 convert_gs(&p->rs, &p->rs);
1423
Jens Axboe89e5fad2012-03-05 09:21:12 +01001424 ops->thread_status(client, cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001425 break;
Jens Axboe3bf236c2012-03-03 20:35:50 +01001426 }
1427 case FIO_NET_CMD_GS: {
1428 struct group_run_stats *gs = (struct group_run_stats *) cmd->payload;
1429
1430 convert_gs(gs, gs);
1431
Jens Axboe89e5fad2012-03-05 09:21:12 +01001432 ops->group_stats(client, cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001433 break;
Jens Axboe3bf236c2012-03-03 20:35:50 +01001434 }
1435 case FIO_NET_CMD_ETA: {
1436 struct jobs_eta *je = (struct jobs_eta *) cmd->payload;
1437
Jens Axboe89c17072011-10-11 10:15:51 +02001438 remove_reply_cmd(client, cmd);
Jens Axboe3bf236c2012-03-03 20:35:50 +01001439 convert_jobs_eta(je);
Jens Axboea5276612012-03-04 15:15:08 +01001440 handle_eta(client, cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001441 break;
Jens Axboe3bf236c2012-03-03 20:35:50 +01001442 }
Jens Axboee951bdc2011-10-05 21:58:45 +02001443 case FIO_NET_CMD_PROBE:
Jens Axboe89c17072011-10-11 10:15:51 +02001444 remove_reply_cmd(client, cmd);
Stephen M. Camerondd366722012-02-24 08:17:30 +01001445 ops->probe(client, cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001446 break;
Jens Axboe5d7793a2012-03-08 19:59:16 +01001447 case FIO_NET_CMD_SERVER_START:
Jens Axboe01be0382011-10-15 14:43:41 +02001448 client->state = Client_running;
Jens Axboe85dd01e2012-03-12 14:33:16 +01001449 if (ops->job_start)
1450 ops->job_start(client, cmd);
Jens Axboe01be0382011-10-15 14:43:41 +02001451 break;
Jens Axboe85dd01e2012-03-12 14:33:16 +01001452 case FIO_NET_CMD_START: {
1453 struct cmd_start_pdu *pdu = (struct cmd_start_pdu *) cmd->payload;
1454
1455 pdu->jobs = le32_to_cpu(pdu->jobs);
1456 ops->start(client, cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001457 break;
Jens Axboe85dd01e2012-03-12 14:33:16 +01001458 }
Jens Axboe6b79c802012-03-08 10:51:36 +01001459 case FIO_NET_CMD_STOP: {
1460 struct cmd_end_pdu *pdu = (struct cmd_end_pdu *) cmd->payload;
1461
1462 convert_stop(cmd);
1463 client->state = Client_stopped;
Jens Axboe122c7722012-03-19 09:13:15 +01001464 client->error = le32_to_cpu(pdu->error);
1465 client->signal = le32_to_cpu(pdu->signal);
Jens Axboe6b79c802012-03-08 10:51:36 +01001466 ops->stop(client, cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001467 break;
Jens Axboe6b79c802012-03-08 10:51:36 +01001468 }
Jens Axboe40c60512012-03-27 16:03:04 +02001469 case FIO_NET_CMD_ADD_JOB: {
1470 struct cmd_add_job_pdu *pdu = (struct cmd_add_job_pdu *) cmd->payload;
1471
1472 client->thread_number = le32_to_cpu(pdu->thread_number);
1473 client->groupid = le32_to_cpu(pdu->groupid);
1474
Jens Axboe807f9972012-03-02 10:25:24 +01001475 if (ops->add_job)
1476 ops->add_job(client, cmd);
Jens Axboe807f9972012-03-02 10:25:24 +01001477 break;
Jens Axboe40c60512012-03-27 16:03:04 +02001478 }
Jens Axboe1b427252012-03-14 15:03:03 +01001479 case FIO_NET_CMD_IOLOG:
1480 if (ops->iolog) {
1481 struct cmd_iolog_pdu *pdu;
1482
1483 pdu = convert_iolog(cmd);
1484 ops->iolog(client, pdu);
1485 }
Jens Axboe1b427252012-03-14 15:03:03 +01001486 break;
Jens Axboe40c60512012-03-27 16:03:04 +02001487 case FIO_NET_CMD_UPDATE_JOB:
Jens Axboe40c60512012-03-27 16:03:04 +02001488 ops->update_job(client, cmd);
Jens Axboe649cee92012-03-28 09:15:32 +02001489 remove_reply_cmd(client, cmd);
Jens Axboe40c60512012-03-27 16:03:04 +02001490 break;
Jens Axboede54cfd2014-11-10 20:34:00 -07001491 case FIO_NET_CMD_VTRIGGER: {
1492 struct all_io_list *pdu = (struct all_io_list *) cmd->payload;
1493 char buf[64];
1494
1495 __verify_save_state(pdu, server_name(client, buf, sizeof(buf)));
Jens Axboe7eebf502014-11-19 09:09:01 -07001496 exec_trigger(trigger_cmd);
Jens Axboede54cfd2014-11-10 20:34:00 -07001497 break;
1498 }
1499 case FIO_NET_CMD_SENDFILE: {
1500 struct cmd_sendfile *pdu = (struct cmd_sendfile *) cmd->payload;
1501 send_file(client, pdu, cmd->tag);
1502 break;
1503 }
Jens Axboee951bdc2011-10-05 21:58:45 +02001504 default:
Jens Axboe89c17072011-10-11 10:15:51 +02001505 log_err("fio: unknown client op: %s\n", fio_server_op(cmd->opcode));
Jens Axboee951bdc2011-10-05 21:58:45 +02001506 break;
Jens Axboe37db14f2011-09-30 17:00:42 -06001507 }
1508
Jens Axboede54cfd2014-11-10 20:34:00 -07001509 free(cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001510 return 1;
Jens Axboe37db14f2011-09-30 17:00:42 -06001511}
Jens Axboeb66570d2011-10-01 11:11:35 -06001512
Jens Axboede54cfd2014-11-10 20:34:00 -07001513int fio_clients_send_trigger(const char *cmd)
1514{
1515 struct flist_head *entry;
1516 struct fio_client *client;
1517 size_t slen;
1518
1519 dprint(FD_NET, "client: send vtrigger: %s\n", cmd);
1520
1521 if (!cmd)
1522 slen = 0;
1523 else
1524 slen = strlen(cmd);
1525
1526 flist_for_each(entry, &client_list) {
1527 struct cmd_vtrigger_pdu *pdu;
1528
1529 client = flist_entry(entry, struct fio_client, list);
1530
1531 pdu = malloc(sizeof(*pdu) + slen);
1532 pdu->len = cpu_to_le16((uint16_t) slen);
1533 if (slen)
1534 memcpy(pdu->cmd, cmd, slen);
1535 fio_net_send_cmd(client->fd, FIO_NET_CMD_VTRIGGER, pdu,
1536 sizeof(*pdu) + slen, NULL, NULL);
1537 free(pdu);
1538 }
1539
1540 return 0;
1541}
1542
Jens Axboea5276612012-03-04 15:15:08 +01001543static void request_client_etas(struct client_ops *ops)
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001544{
1545 struct fio_client *client;
1546 struct flist_head *entry;
1547 struct client_eta *eta;
Jens Axboe82c1ed32011-10-10 08:56:18 +02001548 int skipped = 0;
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001549
1550 dprint(FD_NET, "client: request eta (%d)\n", nr_clients);
1551
Jens Axboe27b91552014-06-27 15:30:06 -06001552 eta = calloc(1, sizeof(*eta) + __THREAD_RUNSTR_SZ(REAL_MAX_JOBS));
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001553 eta->pending = nr_clients;
1554
1555 flist_for_each(entry, &client_list) {
1556 client = flist_entry(entry, struct fio_client, list);
1557
Jens Axboe82c1ed32011-10-10 08:56:18 +02001558 if (!flist_empty(&client->eta_list)) {
1559 skipped++;
1560 continue;
1561 }
Jens Axboe01be0382011-10-15 14:43:41 +02001562 if (client->state != Client_running)
1563 continue;
Jens Axboe82c1ed32011-10-10 08:56:18 +02001564
Jens Axboef77d2672011-10-10 14:36:07 +02001565 assert(!client->eta_in_flight);
Jens Axboe82c1ed32011-10-10 08:56:18 +02001566 flist_add_tail(&client->eta_list, &eta_list);
Jens Axboef77d2672011-10-10 14:36:07 +02001567 client->eta_in_flight = eta;
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001568 fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_SEND_ETA,
Jens Axboedf380932011-10-11 14:25:08 +02001569 (uintptr_t) eta, &client->cmd_list);
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001570 }
1571
Jens Axboe82c1ed32011-10-10 08:56:18 +02001572 while (skipped--)
Jens Axboea5276612012-03-04 15:15:08 +01001573 fio_client_dec_jobs_eta(eta, ops->eta);
Jens Axboe82c1ed32011-10-10 08:56:18 +02001574
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001575 dprint(FD_NET, "client: requested eta tag %p\n", eta);
1576}
1577
Jens Axboe89c17072011-10-11 10:15:51 +02001578static int client_check_cmd_timeout(struct fio_client *client,
1579 struct timeval *now)
1580{
Jens Axboe40c60512012-03-27 16:03:04 +02001581 struct fio_net_cmd_reply *reply;
Jens Axboe89c17072011-10-11 10:15:51 +02001582 struct flist_head *entry, *tmp;
1583 int ret = 0;
1584
1585 flist_for_each_safe(entry, tmp, &client->cmd_list) {
Jens Axboe40c60512012-03-27 16:03:04 +02001586 reply = flist_entry(entry, struct fio_net_cmd_reply, list);
Jens Axboe89c17072011-10-11 10:15:51 +02001587
Jens Axboe40c60512012-03-27 16:03:04 +02001588 if (mtime_since(&reply->tv, now) < FIO_NET_CLIENT_TIMEOUT)
Jens Axboe89c17072011-10-11 10:15:51 +02001589 continue;
1590
1591 log_err("fio: client %s, timeout on cmd %s\n", client->hostname,
Jens Axboe40c60512012-03-27 16:03:04 +02001592 fio_server_op(reply->opcode));
1593 flist_del(&reply->list);
1594 free(reply);
Jens Axboe89c17072011-10-11 10:15:51 +02001595 ret = 1;
1596 }
1597
1598 return flist_empty(&client->cmd_list) && ret;
1599}
1600
Jens Axboea5276612012-03-04 15:15:08 +01001601static int fio_check_clients_timed_out(void)
Jens Axboe89c17072011-10-11 10:15:51 +02001602{
1603 struct fio_client *client;
1604 struct flist_head *entry, *tmp;
1605 struct timeval tv;
1606 int ret = 0;
1607
Jens Axboe67bf9822013-01-10 11:23:19 +01001608 fio_gettime(&tv, NULL);
Jens Axboe89c17072011-10-11 10:15:51 +02001609
1610 flist_for_each_safe(entry, tmp, &client_list) {
1611 client = flist_entry(entry, struct fio_client, list);
1612
1613 if (flist_empty(&client->cmd_list))
1614 continue;
1615
1616 if (!client_check_cmd_timeout(client, &tv))
1617 continue;
1618
Jens Axboea5276612012-03-04 15:15:08 +01001619 if (client->ops->timed_out)
1620 client->ops->timed_out(client);
Jens Axboeed727a42012-03-02 12:14:40 +01001621 else
1622 log_err("fio: client %s timed out\n", client->hostname);
1623
Jens Axboe4811fff2015-01-13 21:47:43 -07001624 client->error = ETIMEDOUT;
Jens Axboe89c17072011-10-11 10:15:51 +02001625 remove_client(client);
1626 ret = 1;
1627 }
1628
1629 return ret;
1630}
1631
Stephen M. Camerondd366722012-02-24 08:17:30 +01001632int fio_handle_clients(struct client_ops *ops)
Jens Axboeb66570d2011-10-01 11:11:35 -06001633{
Jens Axboeb66570d2011-10-01 11:11:35 -06001634 struct pollfd *pfds;
Jens Axboe498c92c2011-10-17 09:14:42 +02001635 int i, ret = 0, retval = 0;
Jens Axboeb66570d2011-10-01 11:11:35 -06001636
Jens Axboe67bf9822013-01-10 11:23:19 +01001637 fio_gettime(&eta_tv, NULL);
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001638
Jens Axboeb66570d2011-10-01 11:11:35 -06001639 pfds = malloc(nr_clients * sizeof(struct pollfd));
1640
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001641 init_thread_stat(&client_ts);
1642 init_group_run_stat(&client_gs);
1643
Jens Axboeb66570d2011-10-01 11:11:35 -06001644 while (!exit_backend && nr_clients) {
Jens Axboec2cb6862012-02-23 20:56:12 +01001645 struct flist_head *entry, *tmp;
1646 struct fio_client *client;
1647
Jens Axboe82a4be12011-10-01 12:40:32 -06001648 i = 0;
Jens Axboec2cb6862012-02-23 20:56:12 +01001649 flist_for_each_safe(entry, tmp, &client_list) {
Jens Axboe82a4be12011-10-01 12:40:32 -06001650 client = flist_entry(entry, struct fio_client, list);
1651
Jens Axboea5276612012-03-04 15:15:08 +01001652 if (!client->sent_job && !client->ops->stay_connected &&
Jens Axboec2cb6862012-02-23 20:56:12 +01001653 flist_empty(&client->cmd_list)) {
1654 remove_client(client);
1655 continue;
1656 }
1657
Jens Axboe82a4be12011-10-01 12:40:32 -06001658 pfds[i].fd = client->fd;
1659 pfds[i].events = POLLIN;
1660 i++;
1661 }
1662
Jens Axboec2cb6862012-02-23 20:56:12 +01001663 if (!nr_clients)
1664 break;
1665
Jens Axboe82a4be12011-10-01 12:40:32 -06001666 assert(i == nr_clients);
1667
Jens Axboe5c2857f2011-10-04 13:14:32 +02001668 do {
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001669 struct timeval tv;
Jens Axboede54cfd2014-11-10 20:34:00 -07001670 int timeout;
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001671
Jens Axboe67bf9822013-01-10 11:23:19 +01001672 fio_gettime(&tv, NULL);
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001673 if (mtime_since(&eta_tv, &tv) >= 900) {
Jens Axboea5276612012-03-04 15:15:08 +01001674 request_client_etas(ops);
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001675 memcpy(&eta_tv, &tv, sizeof(tv));
Jens Axboe89c17072011-10-11 10:15:51 +02001676
Jens Axboea5276612012-03-04 15:15:08 +01001677 if (fio_check_clients_timed_out())
Jens Axboe89c17072011-10-11 10:15:51 +02001678 break;
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001679 }
1680
Jens Axboede54cfd2014-11-10 20:34:00 -07001681 check_trigger_file();
1682
1683 timeout = min(100u, ops->eta_msec);
1684
1685 ret = poll(pfds, nr_clients, timeout);
Jens Axboe5c2857f2011-10-04 13:14:32 +02001686 if (ret < 0) {
1687 if (errno == EINTR)
1688 continue;
1689 log_err("fio: poll clients: %s\n", strerror(errno));
1690 break;
1691 } else if (!ret)
Jens Axboeb66570d2011-10-01 11:11:35 -06001692 continue;
Jens Axboe5c2857f2011-10-04 13:14:32 +02001693 } while (ret <= 0);
Jens Axboeb66570d2011-10-01 11:11:35 -06001694
1695 for (i = 0; i < nr_clients; i++) {
1696 if (!(pfds[i].revents & POLLIN))
1697 continue;
1698
1699 client = find_client_by_fd(pfds[i].fd);
1700 if (!client) {
Jens Axboe65e1a122013-08-30 10:13:36 -06001701 log_err("fio: unknown client fd %ld\n", (long) pfds[i].fd);
Jens Axboeb66570d2011-10-01 11:11:35 -06001702 continue;
1703 }
Jens Axboea5276612012-03-04 15:15:08 +01001704 if (!fio_handle_client(client)) {
Jens Axboe28d3ab02011-10-05 20:45:37 +02001705 log_info("client: host=%s disconnected\n",
1706 client->hostname);
1707 remove_client(client);
Jens Axboe498c92c2011-10-17 09:14:42 +02001708 retval = 1;
Jens Axboe38990762011-10-17 13:31:33 +02001709 } else if (client->error)
Jens Axboe498c92c2011-10-17 09:14:42 +02001710 retval = 1;
Jens Axboe343cb4a2012-03-09 17:16:51 +01001711 fio_put_client(client);
Jens Axboeb66570d2011-10-01 11:11:35 -06001712 }
1713 }
1714
Castor Fu952b05e2013-10-31 11:00:34 -06001715 fio_client_json_fini();
1716
Jens Axboeb66570d2011-10-01 11:11:35 -06001717 free(pfds);
Jens Axboe4811fff2015-01-13 21:47:43 -07001718 return retval || error_clients;
Jens Axboeb66570d2011-10-01 11:11:35 -06001719}