blob: 74c9c76ba10c380cdbf1aa629d0298ea04c8e2b6 [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 Axboe3c5f57e2011-10-06 12:37:50 +020065#define FIO_CLIENT_HASH_BITS 7
66#define FIO_CLIENT_HASH_SZ (1 << FIO_CLIENT_HASH_BITS)
67#define FIO_CLIENT_HASH_MASK (FIO_CLIENT_HASH_SZ - 1)
Jens Axboebebe6392011-10-07 10:00:51 +020068static struct flist_head client_hash[FIO_CLIENT_HASH_SZ];
Jens Axboe3c5f57e2011-10-06 12:37:50 +020069
Jens Axboebebe6392011-10-07 10:00:51 +020070static void fio_client_add_hash(struct fio_client *client)
Jens Axboe3c5f57e2011-10-06 12:37:50 +020071{
72 int bucket = hash_long(client->fd, FIO_CLIENT_HASH_BITS);
73
74 bucket &= FIO_CLIENT_HASH_MASK;
Jens Axboebebe6392011-10-07 10:00:51 +020075 flist_add(&client->hash_list, &client_hash[bucket]);
Jens Axboe3c5f57e2011-10-06 12:37:50 +020076}
77
Jens Axboebebe6392011-10-07 10:00:51 +020078static void fio_client_remove_hash(struct fio_client *client)
Jens Axboe3c5f57e2011-10-06 12:37:50 +020079{
Jens Axboebebe6392011-10-07 10:00:51 +020080 if (!flist_empty(&client->hash_list))
81 flist_del_init(&client->hash_list);
Jens Axboe3c5f57e2011-10-06 12:37:50 +020082}
83
84static void fio_init fio_client_hash_init(void)
85{
86 int i;
87
Jens Axboebebe6392011-10-07 10:00:51 +020088 for (i = 0; i < FIO_CLIENT_HASH_SZ; i++)
89 INIT_FLIST_HEAD(&client_hash[i]);
Jens Axboe3c5f57e2011-10-06 12:37:50 +020090}
91
Jens Axboe3d0be7c2014-11-11 10:24:00 -070092static int read_data(int fd, void *data, size_t size)
93{
94 ssize_t ret;
95
96 while (size) {
97 ret = read(fd, data, size);
98 if (ret < 0) {
99 if (errno == EAGAIN || errno == EINTR)
100 continue;
101 break;
102 } else if (!ret)
103 break;
104 else {
105 data += ret;
106 size -= ret;
107 }
108 }
109
110 if (size)
111 return EAGAIN;
112
113 return 0;
114}
115
Castor Fu952b05e2013-10-31 11:00:34 -0600116static void fio_client_json_init(void)
117{
118 if (output_format != FIO_OUTPUT_JSON)
119 return;
120 root = json_create_object();
121 json_object_add_value_string(root, "fio version", fio_version_string);
122 clients_array = json_create_array();
123 json_object_add_value_array(root, "client_stats", clients_array);
124 du_array = json_create_array();
125 json_object_add_value_array(root, "disk_util", du_array);
126}
127
128static void fio_client_json_fini(void)
129{
130 if (output_format != FIO_OUTPUT_JSON)
131 return;
132 json_print_object(root);
133 log_info("\n");
134 json_free_object(root);
135 root = NULL;
136 clients_array = NULL;
137 du_array = NULL;
138}
139
Jens Axboeb66570d2011-10-01 11:11:35 -0600140static struct fio_client *find_client_by_fd(int fd)
141{
Jens Axboe3c5f57e2011-10-06 12:37:50 +0200142 int bucket = hash_long(fd, FIO_CLIENT_HASH_BITS) & FIO_CLIENT_HASH_MASK;
Jens Axboeb66570d2011-10-01 11:11:35 -0600143 struct fio_client *client;
144 struct flist_head *entry;
145
Jens Axboebebe6392011-10-07 10:00:51 +0200146 flist_for_each(entry, &client_hash[bucket]) {
147 client = flist_entry(entry, struct fio_client, hash_list);
Jens Axboeb66570d2011-10-01 11:11:35 -0600148
Jens Axboee55f8f32012-03-06 15:42:31 +0100149 if (client->fd == fd) {
150 client->refs++;
Jens Axboeb66570d2011-10-01 11:11:35 -0600151 return client;
Jens Axboee55f8f32012-03-06 15:42:31 +0100152 }
Jens Axboeb66570d2011-10-01 11:11:35 -0600153 }
154
155 return NULL;
156}
157
Jens Axboe3af45202012-03-13 09:59:53 +0100158void fio_put_client(struct fio_client *client)
Jens Axboeb66570d2011-10-01 11:11:35 -0600159{
Jens Axboe5121a9a2012-03-05 13:32:47 +0100160 if (--client->refs)
161 return;
162
Jens Axboeb66570d2011-10-01 11:11:35 -0600163 free(client->hostname);
Jens Axboe81179ee2011-10-04 12:42:06 +0200164 if (client->argv)
165 free(client->argv);
Jens Axboeb5296dd2011-10-07 16:35:56 +0200166 if (client->name)
167 free(client->name);
Jens Axboe35899182014-10-07 20:56:28 -0600168 while (client->nr_files) {
169 struct client_file *cf = &client->files[--client->nr_files];
170
171 free(cf->file);
172 }
173 if (client->files)
174 free(client->files);
Jens Axboe81179ee2011-10-04 12:42:06 +0200175
Jens Axboe108fea72012-11-14 13:09:45 -0700176 if (!client->did_stat)
Jens Axboebfa8f5d2014-10-13 10:09:28 -0600177 sum_stat_clients--;
Jens Axboe108fea72012-11-14 13:09:45 -0700178
Jens Axboeb66570d2011-10-01 11:11:35 -0600179 free(client);
180}
Jens Axboe132159a2011-09-30 15:01:32 -0600181
Jens Axboe3af45202012-03-13 09:59:53 +0100182static void remove_client(struct fio_client *client)
Jens Axboe5121a9a2012-03-05 13:32:47 +0100183{
Jens Axboe3af45202012-03-13 09:59:53 +0100184 assert(client->refs);
185
186 dprint(FD_NET, "client: removed <%s>\n", client->hostname);
187
188 if (!flist_empty(&client->list))
189 flist_del_init(&client->list);
190
191 fio_client_remove_hash(client);
192
193 if (!flist_empty(&client->eta_list)) {
194 flist_del_init(&client->eta_list);
195 fio_client_dec_jobs_eta(client->eta_in_flight, client->ops->eta);
196 }
197
Jens Axboe1e0c1842012-03-20 15:15:00 +0100198 close(client->fd);
199 client->fd = -1;
200
Jens Axboe0cf3ece2012-03-21 10:15:20 +0100201 if (client->ops->removed)
202 client->ops->removed(client);
203
Jens Axboe3af45202012-03-13 09:59:53 +0100204 nr_clients--;
Jens Axboe3af45202012-03-13 09:59:53 +0100205 fio_put_client(client);
Jens Axboe5121a9a2012-03-05 13:32:47 +0100206}
207
Jens Axboe343cb4a2012-03-09 17:16:51 +0100208struct fio_client *fio_get_client(struct fio_client *client)
209{
210 client->refs++;
211 return client;
212}
213
Jens Axboefa2ea802011-10-08 21:07:29 +0200214static void __fio_client_add_cmd_option(struct fio_client *client,
215 const char *opt)
Jens Axboe81179ee2011-10-04 12:42:06 +0200216{
Jens Axboe39e8e012011-10-04 13:46:08 +0200217 int index;
218
219 index = client->argc++;
Jens Axboe81179ee2011-10-04 12:42:06 +0200220 client->argv = realloc(client->argv, sizeof(char *) * client->argc);
Jens Axboe39e8e012011-10-04 13:46:08 +0200221 client->argv[index] = strdup(opt);
222 dprint(FD_NET, "client: add cmd %d: %s\n", index, opt);
Jens Axboe81179ee2011-10-04 12:42:06 +0200223}
224
Jens Axboefa2ea802011-10-08 21:07:29 +0200225void fio_client_add_cmd_option(void *cookie, const char *opt)
Jens Axboe81179ee2011-10-04 12:42:06 +0200226{
Jens Axboebebe6392011-10-07 10:00:51 +0200227 struct fio_client *client = cookie;
Jens Axboe3f3a4542011-10-10 21:11:09 +0200228 struct flist_head *entry;
Jens Axboe81179ee2011-10-04 12:42:06 +0200229
Jens Axboebebe6392011-10-07 10:00:51 +0200230 if (!client || !opt)
Jens Axboefa2ea802011-10-08 21:07:29 +0200231 return;
Jens Axboe81179ee2011-10-04 12:42:06 +0200232
Jens Axboefa2ea802011-10-08 21:07:29 +0200233 __fio_client_add_cmd_option(client, opt);
Jens Axboe3f3a4542011-10-10 21:11:09 +0200234
235 /*
236 * Duplicate arguments to shared client group
237 */
238 flist_for_each(entry, &arg_list) {
239 client = flist_entry(entry, struct fio_client, arg_list);
240
241 __fio_client_add_cmd_option(client, opt);
242 }
Jens Axboe81179ee2011-10-04 12:42:06 +0200243}
244
Jens Axboea5276612012-03-04 15:15:08 +0100245struct fio_client *fio_client_add_explicit(struct client_ops *ops,
246 const char *hostname, int type,
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100247 int port)
248{
249 struct fio_client *client;
250
251 client = malloc(sizeof(*client));
252 memset(client, 0, sizeof(*client));
253
254 INIT_FLIST_HEAD(&client->list);
255 INIT_FLIST_HEAD(&client->hash_list);
256 INIT_FLIST_HEAD(&client->arg_list);
257 INIT_FLIST_HEAD(&client->eta_list);
258 INIT_FLIST_HEAD(&client->cmd_list);
259
260 client->hostname = strdup(hostname);
261
262 if (type == Fio_client_socket)
263 client->is_sock = 1;
264 else {
265 int ipv6;
266
267 ipv6 = type == Fio_client_ipv6;
Jens Axboe3aa3cee2014-01-24 18:56:56 -0800268 if (fio_server_parse_host(hostname, ipv6,
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100269 &client->addr.sin_addr,
270 &client->addr6.sin6_addr))
271 goto err;
272
273 client->port = port;
274 }
275
276 client->fd = -1;
Jens Axboea5276612012-03-04 15:15:08 +0100277 client->ops = ops;
Jens Axboe5121a9a2012-03-05 13:32:47 +0100278 client->refs = 1;
Jens Axboe46bcd492012-03-14 11:31:21 +0100279 client->type = ops->client_type;
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100280
281 __fio_client_add_cmd_option(client, "fio");
282
283 flist_add(&client->list, &client_list);
284 nr_clients++;
285 dprint(FD_NET, "client: added <%s>\n", client->hostname);
286 return client;
287err:
288 free(client);
289 return NULL;
290}
291
Jens Axboe35899182014-10-07 20:56:28 -0600292int fio_client_add_ini_file(void *cookie, const char *ini_file, int remote)
Jens Axboe14ea90e2012-08-26 17:33:34 +0200293{
294 struct fio_client *client = cookie;
Jens Axboe35899182014-10-07 20:56:28 -0600295 struct client_file *cf;
Jens Axboe14ea90e2012-08-26 17:33:34 +0200296 size_t new_size;
Jens Axboe35899182014-10-07 20:56:28 -0600297 void *new_files;
Jens Axboe14ea90e2012-08-26 17:33:34 +0200298
Jens Axboe722b5cd2014-10-14 19:56:25 -0600299 if (!client)
300 return 1;
301
Jens Axboe14ea90e2012-08-26 17:33:34 +0200302 dprint(FD_NET, "client <%s>: add ini %s\n", client->hostname, ini_file);
303
Jens Axboe35899182014-10-07 20:56:28 -0600304 new_size = (client->nr_files + 1) * sizeof(struct client_file);
305 new_files = realloc(client->files, new_size);
306 if (!new_files)
307 return 1;
308
309 client->files = new_files;
310 cf = &client->files[client->nr_files];
311 cf->file = strdup(ini_file);
312 cf->remote = remote;
313 client->nr_files++;
314 return 0;
Jens Axboe14ea90e2012-08-26 17:33:34 +0200315}
316
Jens Axboea5276612012-03-04 15:15:08 +0100317int fio_client_add(struct client_ops *ops, const char *hostname, void **cookie)
Jens Axboe132159a2011-09-30 15:01:32 -0600318{
Jens Axboe3f3a4542011-10-10 21:11:09 +0200319 struct fio_client *existing = *cookie;
Jens Axboeb66570d2011-10-01 11:11:35 -0600320 struct fio_client *client;
Jens Axboe132159a2011-09-30 15:01:32 -0600321
Jens Axboe3f3a4542011-10-10 21:11:09 +0200322 if (existing) {
323 /*
324 * We always add our "exec" name as the option, hence 1
325 * means empty.
326 */
327 if (existing->argc == 1)
328 flist_add_tail(&existing->arg_list, &arg_list);
329 else {
330 while (!flist_empty(&arg_list))
331 flist_del_init(arg_list.next);
332 }
333 }
334
Jens Axboeb66570d2011-10-01 11:11:35 -0600335 client = malloc(sizeof(*client));
Jens Axboea37f69b2011-10-01 12:24:21 -0600336 memset(client, 0, sizeof(*client));
Jens Axboe81179ee2011-10-04 12:42:06 +0200337
Jens Axboe3c5f57e2011-10-06 12:37:50 +0200338 INIT_FLIST_HEAD(&client->list);
Jens Axboebebe6392011-10-07 10:00:51 +0200339 INIT_FLIST_HEAD(&client->hash_list);
Jens Axboe3f3a4542011-10-10 21:11:09 +0200340 INIT_FLIST_HEAD(&client->arg_list);
Jens Axboe82c1ed32011-10-10 08:56:18 +0200341 INIT_FLIST_HEAD(&client->eta_list);
Jens Axboe89c17072011-10-11 10:15:51 +0200342 INIT_FLIST_HEAD(&client->cmd_list);
Jens Axboe3c5f57e2011-10-06 12:37:50 +0200343
Jens Axboebebe6392011-10-07 10:00:51 +0200344 if (fio_server_parse_string(hostname, &client->hostname,
345 &client->is_sock, &client->port,
Jens Axboe811826b2011-10-24 09:11:50 +0200346 &client->addr.sin_addr,
347 &client->addr6.sin6_addr,
348 &client->ipv6))
Jens Axboebebe6392011-10-07 10:00:51 +0200349 return -1;
350
Jens Axboea37f69b2011-10-01 12:24:21 -0600351 client->fd = -1;
Jens Axboea5276612012-03-04 15:15:08 +0100352 client->ops = ops;
Jens Axboe5121a9a2012-03-05 13:32:47 +0100353 client->refs = 1;
Jens Axboe46bcd492012-03-14 11:31:21 +0100354 client->type = ops->client_type;
Jens Axboe81179ee2011-10-04 12:42:06 +0200355
356 __fio_client_add_cmd_option(client, "fio");
357
Jens Axboea37f69b2011-10-01 12:24:21 -0600358 flist_add(&client->list, &client_list);
359 nr_clients++;
Jens Axboebebe6392011-10-07 10:00:51 +0200360 dprint(FD_NET, "client: added <%s>\n", client->hostname);
361 *cookie = client;
362 return 0;
Jens Axboea37f69b2011-10-01 12:24:21 -0600363}
364
Jens Axboede54cfd2014-11-10 20:34:00 -0700365static const char *server_name(struct fio_client *client, char *buf,
366 size_t bufsize)
367{
368 const char *from;
369
370 if (client->ipv6)
371 from = inet_ntop(AF_INET6, (struct sockaddr *) &client->addr6.sin6_addr, buf, bufsize);
372 else if (client->is_sock)
373 from = "sock";
374 else
375 from = inet_ntop(AF_INET, (struct sockaddr *) &client->addr.sin_addr, buf, bufsize);
376
377 return from;
378}
379
Jens Axboed824c3b2012-03-09 17:45:43 +0100380static void probe_client(struct fio_client *client)
381{
Jens Axboe3989b142013-04-12 13:13:24 +0200382 struct cmd_client_probe_pdu pdu;
Jens Axboe75289ee2015-01-05 08:47:01 -0700383 const char *sname;
Jens Axboe3989b142013-04-12 13:13:24 +0200384 uint64_t tag;
Jens Axboede54cfd2014-11-10 20:34:00 -0700385 char buf[64];
Jens Axboe3989b142013-04-12 13:13:24 +0200386
Jens Axboed824c3b2012-03-09 17:45:43 +0100387 dprint(FD_NET, "client: send probe\n");
388
Jens Axboe3989b142013-04-12 13:13:24 +0200389#ifdef CONFIG_ZLIB
390 pdu.flags = __le64_to_cpu(FIO_PROBE_FLAG_ZLIB);
391#else
392 pdu.flags = 0;
393#endif
394
Jens Axboe75289ee2015-01-05 08:47:01 -0700395 sname = server_name(client, buf, sizeof(buf));
396 memset(pdu.server, 0, sizeof(pdu.server));
397 strncpy((char *) pdu.server, sname, sizeof(pdu.server) - 1);
Jens Axboede54cfd2014-11-10 20:34:00 -0700398
Jens Axboe3989b142013-04-12 13:13:24 +0200399 fio_net_send_cmd(client->fd, FIO_NET_CMD_PROBE, &pdu, sizeof(pdu), &tag, &client->cmd_list);
Jens Axboed824c3b2012-03-09 17:45:43 +0100400}
401
Jens Axboe87aa8f12011-10-06 21:24:13 +0200402static int fio_client_connect_ip(struct fio_client *client)
Jens Axboea37f69b2011-10-01 12:24:21 -0600403{
Jens Axboe811826b2011-10-24 09:11:50 +0200404 struct sockaddr *addr;
Jens Axboe67bf9822013-01-10 11:23:19 +0100405 socklen_t socklen;
Jens Axboe811826b2011-10-24 09:11:50 +0200406 int fd, domain;
Jens Axboe132159a2011-09-30 15:01:32 -0600407
Jens Axboe811826b2011-10-24 09:11:50 +0200408 if (client->ipv6) {
409 client->addr6.sin6_family = AF_INET6;
410 client->addr6.sin6_port = htons(client->port);
411 domain = AF_INET6;
412 addr = (struct sockaddr *) &client->addr6;
413 socklen = sizeof(client->addr6);
414 } else {
415 client->addr.sin_family = AF_INET;
416 client->addr.sin_port = htons(client->port);
417 domain = AF_INET;
418 addr = (struct sockaddr *) &client->addr;
419 socklen = sizeof(client->addr);
420 }
Jens Axboe132159a2011-09-30 15:01:32 -0600421
Jens Axboe811826b2011-10-24 09:11:50 +0200422 fd = socket(domain, SOCK_STREAM, 0);
Jens Axboe132159a2011-09-30 15:01:32 -0600423 if (fd < 0) {
Jens Axboe25095e12012-03-09 17:09:55 +0100424 int ret = -errno;
425
Jens Axboe132159a2011-09-30 15:01:32 -0600426 log_err("fio: socket: %s\n", strerror(errno));
Jens Axboe25095e12012-03-09 17:09:55 +0100427 return ret;
Jens Axboe132159a2011-09-30 15:01:32 -0600428 }
429
Jens Axboe811826b2011-10-24 09:11:50 +0200430 if (connect(fd, addr, socklen) < 0) {
Jens Axboe25095e12012-03-09 17:09:55 +0100431 int ret = -errno;
432
Jens Axboe132159a2011-09-30 15:01:32 -0600433 log_err("fio: connect: %s\n", strerror(errno));
Jens Axboea7de0a12011-10-07 12:55:14 +0200434 log_err("fio: failed to connect to %s:%u\n", client->hostname,
435 client->port);
Jens Axboeb94cba42011-10-06 21:27:10 +0200436 close(fd);
Jens Axboe25095e12012-03-09 17:09:55 +0100437 return ret;
Jens Axboe132159a2011-09-30 15:01:32 -0600438 }
439
Jens Axboe87aa8f12011-10-06 21:24:13 +0200440 return fd;
441}
442
443static int fio_client_connect_sock(struct fio_client *client)
444{
445 struct sockaddr_un *addr = &client->addr_un;
Jens Axboe67bf9822013-01-10 11:23:19 +0100446 socklen_t len;
Jens Axboe87aa8f12011-10-06 21:24:13 +0200447 int fd;
448
449 memset(addr, 0, sizeof(*addr));
450 addr->sun_family = AF_UNIX;
Jens Axboe1cb96412014-04-14 08:50:33 -0600451 strncpy(addr->sun_path, client->hostname, sizeof(addr->sun_path) - 1);
Jens Axboe87aa8f12011-10-06 21:24:13 +0200452
453 fd = socket(AF_UNIX, SOCK_STREAM, 0);
454 if (fd < 0) {
Jens Axboe25095e12012-03-09 17:09:55 +0100455 int ret = -errno;
456
Jens Axboe87aa8f12011-10-06 21:24:13 +0200457 log_err("fio: socket: %s\n", strerror(errno));
Jens Axboe25095e12012-03-09 17:09:55 +0100458 return ret;
Jens Axboe87aa8f12011-10-06 21:24:13 +0200459 }
460
461 len = sizeof(addr->sun_family) + strlen(addr->sun_path) + 1;
462 if (connect(fd, (struct sockaddr *) addr, len) < 0) {
Jens Axboe25095e12012-03-09 17:09:55 +0100463 int ret = -errno;
464
Jens Axboe87aa8f12011-10-06 21:24:13 +0200465 log_err("fio: connect; %s\n", strerror(errno));
Jens Axboeb94cba42011-10-06 21:27:10 +0200466 close(fd);
Jens Axboe25095e12012-03-09 17:09:55 +0100467 return ret;
Jens Axboe87aa8f12011-10-06 21:24:13 +0200468 }
469
470 return fd;
471}
472
Jens Axboe2f99deb2012-03-09 14:37:29 +0100473int fio_client_connect(struct fio_client *client)
Jens Axboe87aa8f12011-10-06 21:24:13 +0200474{
475 int fd;
476
477 dprint(FD_NET, "client: connect to host %s\n", client->hostname);
478
Jens Axboe87aa8f12011-10-06 21:24:13 +0200479 if (client->is_sock)
480 fd = fio_client_connect_sock(client);
481 else
482 fd = fio_client_connect_ip(client);
483
Jens Axboe89c17072011-10-11 10:15:51 +0200484 dprint(FD_NET, "client: %s connected %d\n", client->hostname, fd);
485
Jens Axboe87aa8f12011-10-06 21:24:13 +0200486 if (fd < 0)
Jens Axboea1a3ed52012-03-09 17:00:01 +0100487 return fd;
Jens Axboe87aa8f12011-10-06 21:24:13 +0200488
Jens Axboeb66570d2011-10-01 11:11:35 -0600489 client->fd = fd;
Jens Axboebebe6392011-10-07 10:00:51 +0200490 fio_client_add_hash(client);
Jens Axboe81179ee2011-10-04 12:42:06 +0200491 client->state = Client_connected;
Jens Axboed824c3b2012-03-09 17:45:43 +0100492
493 probe_client(client);
Jens Axboe132159a2011-09-30 15:01:32 -0600494 return 0;
495}
496
Jens Axboe0cf3ece2012-03-21 10:15:20 +0100497int fio_client_terminate(struct fio_client *client)
Jens Axboe2f99deb2012-03-09 14:37:29 +0100498{
Jens Axboe0cf3ece2012-03-21 10:15:20 +0100499 return fio_net_send_quit(client->fd);
Jens Axboe2f99deb2012-03-09 14:37:29 +0100500}
501
Jens Axboecc0df002011-10-03 20:53:32 +0200502void fio_clients_terminate(void)
503{
504 struct flist_head *entry;
505 struct fio_client *client;
506
Jens Axboe60efd142011-10-04 13:30:11 +0200507 dprint(FD_NET, "client: terminate clients\n");
508
Jens Axboecc0df002011-10-03 20:53:32 +0200509 flist_for_each(entry, &client_list) {
510 client = flist_entry(entry, struct fio_client, list);
Jens Axboe2f99deb2012-03-09 14:37:29 +0100511 fio_client_terminate(client);
Jens Axboecc0df002011-10-03 20:53:32 +0200512 }
513}
514
515static void sig_int(int sig)
516{
Jens Axboebebe6392011-10-07 10:00:51 +0200517 dprint(FD_NET, "client: got signal %d\n", sig);
Jens Axboecc0df002011-10-03 20:53:32 +0200518 fio_clients_terminate();
519}
520
Jens Axboeb852e7c2012-03-30 10:30:35 +0200521static void sig_show_status(int sig)
522{
523 show_running_run_stats();
524}
525
Jens Axboecc0df002011-10-03 20:53:32 +0200526static void client_signal_handler(void)
527{
528 struct sigaction act;
529
530 memset(&act, 0, sizeof(act));
531 act.sa_handler = sig_int;
532 act.sa_flags = SA_RESTART;
533 sigaction(SIGINT, &act, NULL);
534
535 memset(&act, 0, sizeof(act));
536 act.sa_handler = sig_int;
537 act.sa_flags = SA_RESTART;
538 sigaction(SIGTERM, &act, NULL);
Jens Axboeb852e7c2012-03-30 10:30:35 +0200539
Bruce Cran2f694502012-10-10 16:34:13 +0100540/* Windows uses SIGBREAK as a quit signal from other applications */
541#ifdef WIN32
542 memset(&act, 0, sizeof(act));
543 act.sa_handler = sig_int;
544 act.sa_flags = SA_RESTART;
545 sigaction(SIGBREAK, &act, NULL);
546#endif
547
Jens Axboeb852e7c2012-03-30 10:30:35 +0200548 memset(&act, 0, sizeof(act));
549 act.sa_handler = sig_show_status;
550 act.sa_flags = SA_RESTART;
551 sigaction(SIGUSR1, &act, NULL);
Jens Axboecc0df002011-10-03 20:53:32 +0200552}
553
Jens Axboe81179ee2011-10-04 12:42:06 +0200554static int send_client_cmd_line(struct fio_client *client)
555{
Jens Axboefa2ea802011-10-08 21:07:29 +0200556 struct cmd_single_line_pdu *cslp;
557 struct cmd_line_pdu *clp;
558 unsigned long offset;
Jens Axboe7f868312011-10-10 09:55:21 +0200559 unsigned int *lens;
Jens Axboefa2ea802011-10-08 21:07:29 +0200560 void *pdu;
561 size_t mem;
Jens Axboe81179ee2011-10-04 12:42:06 +0200562 int i, ret;
563
Jens Axboe39e8e012011-10-04 13:46:08 +0200564 dprint(FD_NET, "client: send cmdline %d\n", client->argc);
Jens Axboe60efd142011-10-04 13:30:11 +0200565
Jens Axboe7f868312011-10-10 09:55:21 +0200566 lens = malloc(client->argc * sizeof(unsigned int));
567
Jens Axboefa2ea802011-10-08 21:07:29 +0200568 /*
569 * Find out how much mem we need
570 */
Jens Axboe7f868312011-10-10 09:55:21 +0200571 for (i = 0, mem = 0; i < client->argc; i++) {
572 lens[i] = strlen(client->argv[i]) + 1;
573 mem += lens[i];
574 }
Jens Axboe81179ee2011-10-04 12:42:06 +0200575
Jens Axboefa2ea802011-10-08 21:07:29 +0200576 /*
577 * We need one cmd_line_pdu, and argc number of cmd_single_line_pdu
578 */
579 mem += sizeof(*clp) + (client->argc * sizeof(*cslp));
580
581 pdu = malloc(mem);
582 clp = pdu;
583 offset = sizeof(*clp);
584
585 for (i = 0; i < client->argc; i++) {
Jens Axboe7f868312011-10-10 09:55:21 +0200586 uint16_t arg_len = lens[i];
Jens Axboefa2ea802011-10-08 21:07:29 +0200587
588 cslp = pdu + offset;
589 strcpy((char *) cslp->text, client->argv[i]);
590 cslp->len = cpu_to_le16(arg_len);
591 offset += sizeof(*cslp) + arg_len;
592 }
593
Jens Axboe7f868312011-10-10 09:55:21 +0200594 free(lens);
Jens Axboefa2ea802011-10-08 21:07:29 +0200595 clp->lines = cpu_to_le16(client->argc);
Jens Axboe46bcd492012-03-14 11:31:21 +0100596 clp->client_type = __cpu_to_le16(client->type);
Jens Axboe40c60512012-03-27 16:03:04 +0200597 ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOBLINE, pdu, mem, NULL, NULL);
Jens Axboe81179ee2011-10-04 12:42:06 +0200598 free(pdu);
599 return ret;
600}
601
Jens Axboea37f69b2011-10-01 12:24:21 -0600602int fio_clients_connect(void)
603{
604 struct fio_client *client;
605 struct flist_head *entry, *tmp;
606 int ret;
607
Bruce Cran93bcfd22012-02-20 20:18:19 +0100608#ifdef WIN32
609 WSADATA wsd;
Jens Axboe3c3ed072012-03-27 09:12:39 +0200610 WSAStartup(MAKEWORD(2, 2), &wsd);
Bruce Cran93bcfd22012-02-20 20:18:19 +0100611#endif
612
Jens Axboe60efd142011-10-04 13:30:11 +0200613 dprint(FD_NET, "client: connect all\n");
614
Jens Axboecc0df002011-10-03 20:53:32 +0200615 client_signal_handler();
616
Jens Axboea37f69b2011-10-01 12:24:21 -0600617 flist_for_each_safe(entry, tmp, &client_list) {
618 client = flist_entry(entry, struct fio_client, list);
619
620 ret = fio_client_connect(client);
Jens Axboe0b8f30a2011-10-04 10:31:53 +0200621 if (ret) {
Jens Axboea37f69b2011-10-01 12:24:21 -0600622 remove_client(client);
Jens Axboe0b8f30a2011-10-04 10:31:53 +0200623 continue;
624 }
625
Jens Axboe81179ee2011-10-04 12:42:06 +0200626 if (client->argc > 1)
627 send_client_cmd_line(client);
Jens Axboea37f69b2011-10-01 12:24:21 -0600628 }
629
630 return !nr_clients;
631}
632
Jens Axboeb9d2f302012-03-08 20:36:28 +0100633int fio_start_client(struct fio_client *client)
634{
635 dprint(FD_NET, "client: start %s\n", client->hostname);
636 return fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_RUN, 0, NULL);
637}
638
639int fio_start_all_clients(void)
640{
641 struct fio_client *client;
642 struct flist_head *entry, *tmp;
643 int ret;
644
645 dprint(FD_NET, "client: start all\n");
646
Castor Fu952b05e2013-10-31 11:00:34 -0600647 fio_client_json_init();
648
Jens Axboeb9d2f302012-03-08 20:36:28 +0100649 flist_for_each_safe(entry, tmp, &client_list) {
650 client = flist_entry(entry, struct fio_client, list);
651
652 ret = fio_start_client(client);
653 if (ret) {
654 remove_client(client);
655 continue;
656 }
657 }
658
659 return flist_empty(&client_list);
660}
661
Jens Axboe35899182014-10-07 20:56:28 -0600662static int __fio_client_send_remote_ini(struct fio_client *client,
663 const char *filename)
664{
665 struct cmd_load_file_pdu *pdu;
666 size_t p_size;
667 int ret;
668
669 dprint(FD_NET, "send remote ini %s to %s\n", filename, client->hostname);
670
Jens Axboe79ecc302014-10-07 22:02:21 -0600671 p_size = sizeof(*pdu) + strlen(filename) + 1;
Jens Axboe35899182014-10-07 20:56:28 -0600672 pdu = malloc(p_size);
Jens Axboe79ecc302014-10-07 22:02:21 -0600673 memset(pdu, 0, p_size);
Jens Axboe35899182014-10-07 20:56:28 -0600674 pdu->name_len = strlen(filename);
675 strcpy((char *) pdu->file, filename);
676 pdu->client_type = cpu_to_le16((uint16_t) client->type);
677
678 client->sent_job = 1;
679 ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_LOAD_FILE, pdu, p_size,NULL, NULL);
680 free(pdu);
681 return ret;
682}
683
Jens Axboe132159a2011-09-30 15:01:32 -0600684/*
685 * Send file contents to server backend. We could use sendfile(), but to remain
686 * more portable lets just read/write the darn thing.
687 */
Jens Axboe35899182014-10-07 20:56:28 -0600688static int __fio_client_send_local_ini(struct fio_client *client,
689 const char *filename)
Jens Axboe132159a2011-09-30 15:01:32 -0600690{
Jens Axboe46bcd492012-03-14 11:31:21 +0100691 struct cmd_job_pdu *pdu;
692 size_t p_size;
Jens Axboe132159a2011-09-30 15:01:32 -0600693 struct stat sb;
Jens Axboe46bcd492012-03-14 11:31:21 +0100694 char *p;
695 void *buf;
Jens Axboe132159a2011-09-30 15:01:32 -0600696 off_t len;
697 int fd, ret;
698
Jens Axboe46c48f12011-10-01 12:50:51 -0600699 dprint(FD_NET, "send ini %s to %s\n", filename, client->hostname);
700
Jens Axboe132159a2011-09-30 15:01:32 -0600701 fd = open(filename, O_RDONLY);
702 if (fd < 0) {
Jens Axboe0f7f9a92014-11-06 09:21:10 -0700703 ret = -errno;
Jens Axboee951bdc2011-10-05 21:58:45 +0200704 log_err("fio: job file <%s> open: %s\n", filename, strerror(errno));
Jens Axboe25095e12012-03-09 17:09:55 +0100705 return ret;
Jens Axboe132159a2011-09-30 15:01:32 -0600706 }
707
708 if (fstat(fd, &sb) < 0) {
Jens Axboe0f7f9a92014-11-06 09:21:10 -0700709 ret = -errno;
Jens Axboe132159a2011-09-30 15:01:32 -0600710 log_err("fio: job file stat: %s\n", strerror(errno));
Jens Axboeb94cba42011-10-06 21:27:10 +0200711 close(fd);
Jens Axboe25095e12012-03-09 17:09:55 +0100712 return ret;
Jens Axboe132159a2011-09-30 15:01:32 -0600713 }
714
Jens Axboe46bcd492012-03-14 11:31:21 +0100715 p_size = sb.st_size + sizeof(*pdu);
716 pdu = malloc(p_size);
717 buf = pdu->buf;
Jens Axboe132159a2011-09-30 15:01:32 -0600718
719 len = sb.st_size;
720 p = buf;
Jens Axboe3d0be7c2014-11-11 10:24:00 -0700721 if (read_data(fd, p, len)) {
Jens Axboe0b8f30a2011-10-04 10:31:53 +0200722 log_err("fio: failed reading job file %s\n", filename);
Jens Axboeb94cba42011-10-06 21:27:10 +0200723 close(fd);
Hong Zhiguo03a22d92013-10-16 08:35:12 -0600724 free(pdu);
Jens Axboe0b8f30a2011-10-04 10:31:53 +0200725 return 1;
726 }
727
Jens Axboe46bcd492012-03-14 11:31:21 +0100728 pdu->buf_len = __cpu_to_le32(sb.st_size);
729 pdu->client_type = cpu_to_le32(client->type);
730
Jens Axboec2cb6862012-02-23 20:56:12 +0100731 client->sent_job = 1;
Jens Axboe40c60512012-03-27 16:03:04 +0200732 ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOB, pdu, p_size, NULL, NULL);
Jens Axboe46bcd492012-03-14 11:31:21 +0100733 free(pdu);
Jens Axboeb94cba42011-10-06 21:27:10 +0200734 close(fd);
Jens Axboe132159a2011-09-30 15:01:32 -0600735 return ret;
736}
Jens Axboe37db14f2011-09-30 17:00:42 -0600737
Jens Axboe35899182014-10-07 20:56:28 -0600738int fio_client_send_ini(struct fio_client *client, const char *filename,
739 int remote)
Jens Axboe9988ca72012-03-09 15:14:06 +0100740{
Jens Axboe25095e12012-03-09 17:09:55 +0100741 int ret;
742
Jens Axboe35899182014-10-07 20:56:28 -0600743 if (!remote)
744 ret = __fio_client_send_local_ini(client, filename);
745 else
746 ret = __fio_client_send_remote_ini(client, filename);
747
Jens Axboe3af45202012-03-13 09:59:53 +0100748 if (!ret)
749 client->sent_job = 1;
Jens Axboe9988ca72012-03-09 15:14:06 +0100750
Jens Axboe25095e12012-03-09 17:09:55 +0100751 return ret;
Jens Axboe9988ca72012-03-09 15:14:06 +0100752}
753
Jens Axboe35899182014-10-07 20:56:28 -0600754static int fio_client_send_cf(struct fio_client *client,
755 struct client_file *cf)
756{
757 return fio_client_send_ini(client, cf->file, cf->remote);
758}
759
Jens Axboea37f69b2011-10-01 12:24:21 -0600760int fio_clients_send_ini(const char *filename)
761{
762 struct fio_client *client;
763 struct flist_head *entry, *tmp;
764
765 flist_for_each_safe(entry, tmp, &client_list) {
766 client = flist_entry(entry, struct fio_client, list);
767
Jens Axboe35899182014-10-07 20:56:28 -0600768 if (client->nr_files) {
Jens Axboe14ea90e2012-08-26 17:33:34 +0200769 int i;
770
Jens Axboe35899182014-10-07 20:56:28 -0600771 for (i = 0; i < client->nr_files; i++) {
772 struct client_file *cf;
Jens Axboe14ea90e2012-08-26 17:33:34 +0200773
Jens Axboe35899182014-10-07 20:56:28 -0600774 cf = &client->files[i];
775
776 if (fio_client_send_cf(client, cf)) {
Jens Axboe14ea90e2012-08-26 17:33:34 +0200777 remove_client(client);
778 break;
779 }
780 }
Jens Axboe35899182014-10-07 20:56:28 -0600781 }
782 if (client->sent_job)
783 continue;
784 if (!filename || fio_client_send_ini(client, filename, 0))
Jens Axboe3af45202012-03-13 09:59:53 +0100785 remove_client(client);
Jens Axboea37f69b2011-10-01 12:24:21 -0600786 }
787
788 return !nr_clients;
789}
790
Jens Axboe40c60512012-03-27 16:03:04 +0200791int fio_client_update_options(struct fio_client *client,
792 struct thread_options *o, uint64_t *tag)
793{
794 struct cmd_add_job_pdu pdu;
795
796 pdu.thread_number = cpu_to_le32(client->thread_number);
797 pdu.groupid = cpu_to_le32(client->groupid);
798 convert_thread_options_to_net(&pdu.top, o);
Castor Fu952b05e2013-10-31 11:00:34 -0600799
Jens Axboe40c60512012-03-27 16:03:04 +0200800 return fio_net_send_cmd(client->fd, FIO_NET_CMD_UPDATE_JOB, &pdu, sizeof(pdu), tag, &client->cmd_list);
801}
802
Jens Axboea64e88d2011-10-03 14:20:01 +0200803static void convert_io_stat(struct io_stat *dst, struct io_stat *src)
804{
805 dst->max_val = le64_to_cpu(src->max_val);
806 dst->min_val = le64_to_cpu(src->min_val);
807 dst->samples = le64_to_cpu(src->samples);
Jens Axboe802ad4a2011-10-05 09:51:58 +0200808
809 /*
810 * Floats arrive as IEEE 754 encoded uint64_t, convert back to double
811 */
812 dst->mean.u.f = fio_uint64_to_double(le64_to_cpu(dst->mean.u.i));
813 dst->S.u.f = fio_uint64_to_double(le64_to_cpu(dst->S.u.i));
Jens Axboea64e88d2011-10-03 14:20:01 +0200814}
815
816static void convert_ts(struct thread_stat *dst, struct thread_stat *src)
817{
818 int i, j;
819
Jens Axboe2f122b12012-03-15 13:10:19 +0100820 dst->error = le32_to_cpu(src->error);
821 dst->thread_number = le32_to_cpu(src->thread_number);
822 dst->groupid = le32_to_cpu(src->groupid);
823 dst->pid = le32_to_cpu(src->pid);
824 dst->members = le32_to_cpu(src->members);
Jens Axboe771e58b2013-01-30 12:56:23 +0100825 dst->unified_rw_rep = le32_to_cpu(src->unified_rw_rep);
Jens Axboea64e88d2011-10-03 14:20:01 +0200826
Jens Axboe298921d2012-09-24 18:47:01 +0200827 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
Jens Axboea64e88d2011-10-03 14:20:01 +0200828 convert_io_stat(&dst->clat_stat[i], &src->clat_stat[i]);
829 convert_io_stat(&dst->slat_stat[i], &src->slat_stat[i]);
830 convert_io_stat(&dst->lat_stat[i], &src->lat_stat[i]);
831 convert_io_stat(&dst->bw_stat[i], &src->bw_stat[i]);
832 }
833
834 dst->usr_time = le64_to_cpu(src->usr_time);
835 dst->sys_time = le64_to_cpu(src->sys_time);
836 dst->ctx = le64_to_cpu(src->ctx);
837 dst->minf = le64_to_cpu(src->minf);
838 dst->majf = le64_to_cpu(src->majf);
839 dst->clat_percentiles = le64_to_cpu(src->clat_percentiles);
Jens Axboe623216d2014-11-07 18:47:41 -0700840 dst->percentile_precision = le64_to_cpu(src->percentile_precision);
Jens Axboe802ad4a2011-10-05 09:51:58 +0200841
842 for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) {
843 fio_fp64_t *fps = &src->percentile_list[i];
844 fio_fp64_t *fpd = &dst->percentile_list[i];
845
846 fpd->u.f = fio_uint64_to_double(le64_to_cpu(fps->u.i));
847 }
Jens Axboea64e88d2011-10-03 14:20:01 +0200848
849 for (i = 0; i < FIO_IO_U_MAP_NR; i++) {
850 dst->io_u_map[i] = le32_to_cpu(src->io_u_map[i]);
851 dst->io_u_submit[i] = le32_to_cpu(src->io_u_submit[i]);
852 dst->io_u_complete[i] = le32_to_cpu(src->io_u_complete[i]);
853 }
854
855 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) {
856 dst->io_u_lat_u[i] = le32_to_cpu(src->io_u_lat_u[i]);
857 dst->io_u_lat_m[i] = le32_to_cpu(src->io_u_lat_m[i]);
858 }
859
Jens Axboe298921d2012-09-24 18:47:01 +0200860 for (i = 0; i < DDIR_RWDIR_CNT; i++)
Jens Axboea64e88d2011-10-03 14:20:01 +0200861 for (j = 0; j < FIO_IO_U_PLAT_NR; j++)
862 dst->io_u_plat[i][j] = le32_to_cpu(src->io_u_plat[i][j]);
863
Jens Axboe78799de2013-01-29 20:53:52 +0100864 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
Jens Axboea64e88d2011-10-03 14:20:01 +0200865 dst->total_io_u[i] = le64_to_cpu(src->total_io_u[i]);
Jens Axboe93eee042011-10-03 21:08:48 +0200866 dst->short_io_u[i] = le64_to_cpu(src->short_io_u[i]);
Jens Axboe67e149c2014-10-09 13:27:44 -0600867 dst->drop_io_u[i] = le64_to_cpu(src->drop_io_u[i]);
Jens Axboea64e88d2011-10-03 14:20:01 +0200868 }
869
870 dst->total_submit = le64_to_cpu(src->total_submit);
871 dst->total_complete = le64_to_cpu(src->total_complete);
872
Jens Axboe298921d2012-09-24 18:47:01 +0200873 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
Jens Axboea64e88d2011-10-03 14:20:01 +0200874 dst->io_bytes[i] = le64_to_cpu(src->io_bytes[i]);
875 dst->runtime[i] = le64_to_cpu(src->runtime[i]);
876 }
877
878 dst->total_run_time = le64_to_cpu(src->total_run_time);
879 dst->continue_on_error = le16_to_cpu(src->continue_on_error);
880 dst->total_err_count = le64_to_cpu(src->total_err_count);
Jens Axboeddcc0b62011-10-03 14:45:27 +0200881 dst->first_error = le32_to_cpu(src->first_error);
882 dst->kb_base = le32_to_cpu(src->kb_base);
Steven Noonanad705bc2013-04-08 15:05:25 -0700883 dst->unit_base = le32_to_cpu(src->unit_base);
Jens Axboe3e260a42013-12-09 12:38:53 -0700884
885 dst->latency_depth = le32_to_cpu(src->latency_depth);
886 dst->latency_target = le64_to_cpu(src->latency_target);
887 dst->latency_window = le64_to_cpu(src->latency_window);
888 dst->latency_percentile.u.f = fio_uint64_to_double(le64_to_cpu(src->latency_percentile.u.i));
Jens Axboea64e88d2011-10-03 14:20:01 +0200889}
890
891static void convert_gs(struct group_run_stats *dst, struct group_run_stats *src)
892{
893 int i;
894
Jens Axboe298921d2012-09-24 18:47:01 +0200895 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
Jens Axboea64e88d2011-10-03 14:20:01 +0200896 dst->max_run[i] = le64_to_cpu(src->max_run[i]);
897 dst->min_run[i] = le64_to_cpu(src->min_run[i]);
898 dst->max_bw[i] = le64_to_cpu(src->max_bw[i]);
899 dst->min_bw[i] = le64_to_cpu(src->min_bw[i]);
900 dst->io_kb[i] = le64_to_cpu(src->io_kb[i]);
901 dst->agg[i] = le64_to_cpu(src->agg[i]);
902 }
903
904 dst->kb_base = le32_to_cpu(src->kb_base);
Steven Noonanad705bc2013-04-08 15:05:25 -0700905 dst->unit_base = le32_to_cpu(src->unit_base);
Jens Axboea64e88d2011-10-03 14:20:01 +0200906 dst->groupid = le32_to_cpu(src->groupid);
Jens Axboe771e58b2013-01-30 12:56:23 +0100907 dst->unified_rw_rep = le32_to_cpu(src->unified_rw_rep);
Jens Axboea64e88d2011-10-03 14:20:01 +0200908}
909
Castor Fu952b05e2013-10-31 11:00:34 -0600910static void json_object_add_client_info(struct json_object *obj,
Castor Fu54bcda52014-08-22 17:16:44 -0500911 struct fio_client *client)
Castor Fu952b05e2013-10-31 11:00:34 -0600912{
Castor Fu54bcda52014-08-22 17:16:44 -0500913 const char *hostname = client->hostname ? client->hostname : "";
914
915 json_object_add_value_string(obj, "hostname", hostname);
Castor Fu952b05e2013-10-31 11:00:34 -0600916 json_object_add_value_int(obj, "port", client->port);
917}
918
Jens Axboe89e5fad2012-03-05 09:21:12 +0100919static void handle_ts(struct fio_client *client, struct fio_net_cmd *cmd)
Jens Axboea64e88d2011-10-03 14:20:01 +0200920{
921 struct cmd_ts_pdu *p = (struct cmd_ts_pdu *) cmd->payload;
Castor Fu952b05e2013-10-31 11:00:34 -0600922 struct json_object *tsobj;
Jens Axboea64e88d2011-10-03 14:20:01 +0200923
Castor Fu952b05e2013-10-31 11:00:34 -0600924 tsobj = show_thread_status(&p->ts, &p->rs);
Jens Axboe108fea72012-11-14 13:09:45 -0700925 client->did_stat = 1;
Castor Fu952b05e2013-10-31 11:00:34 -0600926 if (tsobj) {
927 json_object_add_client_info(tsobj, client);
928 json_array_add_value_object(clients_array, tsobj);
929 }
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200930
Jens Axboebfa8f5d2014-10-13 10:09:28 -0600931 if (sum_stat_clients <= 1)
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200932 return;
933
934 sum_thread_stats(&client_ts, &p->ts, sum_stat_nr);
935 sum_group_stats(&client_gs, &p->rs);
936
937 client_ts.members++;
Jens Axboe2f122b12012-03-15 13:10:19 +0100938 client_ts.thread_number = p->ts.thread_number;
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200939 client_ts.groupid = p->ts.groupid;
Jens Axboe771e58b2013-01-30 12:56:23 +0100940 client_ts.unified_rw_rep = p->ts.unified_rw_rep;
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200941
942 if (++sum_stat_nr == sum_stat_clients) {
943 strcpy(client_ts.name, "All clients");
Castor Fu952b05e2013-10-31 11:00:34 -0600944 tsobj = show_thread_status(&client_ts, &client_gs);
945 if (tsobj) {
946 json_object_add_client_info(tsobj, client);
947 json_array_add_value_object(clients_array, tsobj);
948 }
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200949 }
Jens Axboea64e88d2011-10-03 14:20:01 +0200950}
951
Jens Axboe89e5fad2012-03-05 09:21:12 +0100952static void handle_gs(struct fio_client *client, struct fio_net_cmd *cmd)
Jens Axboea64e88d2011-10-03 14:20:01 +0200953{
954 struct group_run_stats *gs = (struct group_run_stats *) cmd->payload;
955
Jens Axboea64e88d2011-10-03 14:20:01 +0200956 show_group_stats(gs);
957}
958
Jens Axboe3bf236c2012-03-03 20:35:50 +0100959static void handle_text(struct fio_client *client, struct fio_net_cmd *cmd)
960{
961 struct cmd_text_pdu *pdu = (struct cmd_text_pdu *) cmd->payload;
962 const char *buf = (const char *) pdu->buf;
963 const char *name;
964 int fio_unused ret;
965
966 name = client->name ? client->name : client->hostname;
967
968 if (!client->skip_newline)
969 fprintf(f_out, "<%s> ", name);
970 ret = fwrite(buf, pdu->buf_len, 1, f_out);
971 fflush(f_out);
972 client->skip_newline = strchr(buf, '\n') == NULL;
973}
974
Jens Axboed09a64a2011-10-13 11:38:56 +0200975static void convert_agg(struct disk_util_agg *agg)
976{
977 int i;
978
979 for (i = 0; i < 2; i++) {
Jens Axboe2a3bf762014-12-01 09:42:48 -0700980 agg->ios[i] = le64_to_cpu(agg->ios[i]);
981 agg->merges[i] = le64_to_cpu(agg->merges[i]);
Jens Axboed09a64a2011-10-13 11:38:56 +0200982 agg->sectors[i] = le64_to_cpu(agg->sectors[i]);
Jens Axboe2a3bf762014-12-01 09:42:48 -0700983 agg->ticks[i] = le64_to_cpu(agg->ticks[i]);
Jens Axboed09a64a2011-10-13 11:38:56 +0200984 }
985
Jens Axboe2a3bf762014-12-01 09:42:48 -0700986 agg->io_ticks = le64_to_cpu(agg->io_ticks);
987 agg->time_in_queue = le64_to_cpu(agg->time_in_queue);
Jens Axboed09a64a2011-10-13 11:38:56 +0200988 agg->slavecount = le32_to_cpu(agg->slavecount);
Jens Axboe2b827fa2014-10-13 16:05:10 -0600989 agg->max_util.u.f = fio_uint64_to_double(le64_to_cpu(agg->max_util.u.i));
Jens Axboed09a64a2011-10-13 11:38:56 +0200990}
991
992static void convert_dus(struct disk_util_stat *dus)
993{
994 int i;
995
996 for (i = 0; i < 2; i++) {
Jens Axboe2a3bf762014-12-01 09:42:48 -0700997 dus->s.ios[i] = le64_to_cpu(dus->s.ios[i]);
998 dus->s.merges[i] = le64_to_cpu(dus->s.merges[i]);
Jens Axboea3b4cf72014-04-11 12:17:53 -0600999 dus->s.sectors[i] = le64_to_cpu(dus->s.sectors[i]);
Jens Axboe2a3bf762014-12-01 09:42:48 -07001000 dus->s.ticks[i] = le64_to_cpu(dus->s.ticks[i]);
Jens Axboed09a64a2011-10-13 11:38:56 +02001001 }
1002
Jens Axboe2a3bf762014-12-01 09:42:48 -07001003 dus->s.io_ticks = le64_to_cpu(dus->s.io_ticks);
1004 dus->s.time_in_queue = le64_to_cpu(dus->s.time_in_queue);
Jens Axboea3b4cf72014-04-11 12:17:53 -06001005 dus->s.msec = le64_to_cpu(dus->s.msec);
Jens Axboed09a64a2011-10-13 11:38:56 +02001006}
1007
1008static void handle_du(struct fio_client *client, struct fio_net_cmd *cmd)
1009{
1010 struct cmd_du_pdu *du = (struct cmd_du_pdu *) cmd->payload;
1011
Jens Axboed09a64a2011-10-13 11:38:56 +02001012 if (!client->disk_stats_shown) {
1013 client->disk_stats_shown = 1;
1014 log_info("\nDisk stats (read/write):\n");
1015 }
1016
Castor Fu952b05e2013-10-31 11:00:34 -06001017 if (output_format == FIO_OUTPUT_JSON) {
1018 struct json_object *duobj;
1019 json_array_add_disk_util(&du->dus, &du->agg, du_array);
1020 duobj = json_array_last_value_object(du_array);
1021 json_object_add_client_info(duobj, client);
1022 } else
1023 print_disk_util(&du->dus, &du->agg, output_format == FIO_OUTPUT_TERSE);
Jens Axboed09a64a2011-10-13 11:38:56 +02001024}
1025
Jens Axboe3bf236c2012-03-03 20:35:50 +01001026static void convert_jobs_eta(struct jobs_eta *je)
Jens Axboecf451d12011-10-03 16:48:30 +02001027{
Jens Axboecf451d12011-10-03 16:48:30 +02001028 int i;
1029
1030 je->nr_running = le32_to_cpu(je->nr_running);
1031 je->nr_ramp = le32_to_cpu(je->nr_ramp);
1032 je->nr_pending = le32_to_cpu(je->nr_pending);
Jens Axboe714e85f2013-04-15 10:21:56 +02001033 je->nr_setting_up = le32_to_cpu(je->nr_setting_up);
Jens Axboecf451d12011-10-03 16:48:30 +02001034 je->files_open = le32_to_cpu(je->files_open);
Jens Axboecf451d12011-10-03 16:48:30 +02001035
Jens Axboe298921d2012-09-24 18:47:01 +02001036 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
1037 je->m_rate[i] = le32_to_cpu(je->m_rate[i]);
1038 je->t_rate[i] = le32_to_cpu(je->t_rate[i]);
1039 je->m_iops[i] = le32_to_cpu(je->m_iops[i]);
1040 je->t_iops[i] = le32_to_cpu(je->t_iops[i]);
Jens Axboe16725bb2013-04-11 12:43:05 +02001041 je->rate[i] = le32_to_cpu(je->rate[i]);
1042 je->iops[i] = le32_to_cpu(je->iops[i]);
Jens Axboecf451d12011-10-03 16:48:30 +02001043 }
1044
Jens Axboeb51eedb2011-10-09 12:13:39 +02001045 je->elapsed_sec = le64_to_cpu(je->elapsed_sec);
Jens Axboecf451d12011-10-03 16:48:30 +02001046 je->eta_sec = le64_to_cpu(je->eta_sec);
Jens Axboe8c621fb2012-03-08 12:30:48 +01001047 je->nr_threads = le32_to_cpu(je->nr_threads);
Jens Axboeb7f05eb2012-05-11 20:33:02 +02001048 je->is_pow2 = le32_to_cpu(je->is_pow2);
Jens Axboeed2c0a12013-04-11 12:55:16 +02001049 je->unit_base = le32_to_cpu(je->unit_base);
Jens Axboe48fbb462011-10-09 12:19:08 +02001050}
Jens Axboecf451d12011-10-03 16:48:30 +02001051
Jens Axboe3e47bd22012-02-29 13:45:02 +01001052void fio_client_sum_jobs_eta(struct jobs_eta *dst, struct jobs_eta *je)
Jens Axboe48fbb462011-10-09 12:19:08 +02001053{
Jens Axboe48fbb462011-10-09 12:19:08 +02001054 int i;
1055
1056 dst->nr_running += je->nr_running;
1057 dst->nr_ramp += je->nr_ramp;
1058 dst->nr_pending += je->nr_pending;
Jens Axboe714e85f2013-04-15 10:21:56 +02001059 dst->nr_setting_up += je->nr_setting_up;
Jens Axboe48fbb462011-10-09 12:19:08 +02001060 dst->files_open += je->files_open;
Jens Axboe48fbb462011-10-09 12:19:08 +02001061
Jens Axboe298921d2012-09-24 18:47:01 +02001062 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
Jens Axboe3e47bd22012-02-29 13:45:02 +01001063 dst->m_rate[i] += je->m_rate[i];
1064 dst->t_rate[i] += je->t_rate[i];
1065 dst->m_iops[i] += je->m_iops[i];
1066 dst->t_iops[i] += je->t_iops[i];
Jens Axboe16725bb2013-04-11 12:43:05 +02001067 dst->rate[i] += je->rate[i];
1068 dst->iops[i] += je->iops[i];
Jens Axboe48fbb462011-10-09 12:19:08 +02001069 }
1070
1071 dst->elapsed_sec += je->elapsed_sec;
1072
1073 if (je->eta_sec > dst->eta_sec)
1074 dst->eta_sec = je->eta_sec;
Jens Axboe8c621fb2012-03-08 12:30:48 +01001075
1076 dst->nr_threads += je->nr_threads;
Jens Axboe27b91552014-06-27 15:30:06 -06001077
1078 /*
1079 * This wont be correct for multiple strings, but at least it
1080 * works for the basic cases.
1081 */
1082 strcpy((char *) dst->run_str, (char *) je->run_str);
Jens Axboe48fbb462011-10-09 12:19:08 +02001083}
1084
Jens Axboea5276612012-03-04 15:15:08 +01001085void fio_client_dec_jobs_eta(struct client_eta *eta, client_eta_op eta_fn)
Jens Axboe82c1ed32011-10-10 08:56:18 +02001086{
1087 if (!--eta->pending) {
Jens Axboea5276612012-03-04 15:15:08 +01001088 eta_fn(&eta->eta);
Jens Axboe82c1ed32011-10-10 08:56:18 +02001089 free(eta);
1090 }
1091}
1092
Jens Axboe89c17072011-10-11 10:15:51 +02001093static void remove_reply_cmd(struct fio_client *client, struct fio_net_cmd *cmd)
1094{
Jens Axboe40c60512012-03-27 16:03:04 +02001095 struct fio_net_cmd_reply *reply = NULL;
Jens Axboe89c17072011-10-11 10:15:51 +02001096 struct flist_head *entry;
1097
1098 flist_for_each(entry, &client->cmd_list) {
Jens Axboe40c60512012-03-27 16:03:04 +02001099 reply = flist_entry(entry, struct fio_net_cmd_reply, list);
Jens Axboe89c17072011-10-11 10:15:51 +02001100
Jens Axboe40c60512012-03-27 16:03:04 +02001101 if (cmd->tag == (uintptr_t) reply)
Jens Axboe89c17072011-10-11 10:15:51 +02001102 break;
1103
Jens Axboe40c60512012-03-27 16:03:04 +02001104 reply = NULL;
Jens Axboe89c17072011-10-11 10:15:51 +02001105 }
1106
Jens Axboe40c60512012-03-27 16:03:04 +02001107 if (!reply) {
Jens Axboe4e0a8fa2013-04-15 11:40:57 +02001108 log_err("fio: client: unable to find matching tag (%llx)\n", (unsigned long long) cmd->tag);
Jens Axboe89c17072011-10-11 10:15:51 +02001109 return;
1110 }
1111
Jens Axboe40c60512012-03-27 16:03:04 +02001112 flist_del(&reply->list);
1113 cmd->tag = reply->saved_tag;
1114 free(reply);
1115}
1116
1117int fio_client_wait_for_reply(struct fio_client *client, uint64_t tag)
1118{
1119 do {
1120 struct fio_net_cmd_reply *reply = NULL;
1121 struct flist_head *entry;
1122
1123 flist_for_each(entry, &client->cmd_list) {
1124 reply = flist_entry(entry, struct fio_net_cmd_reply, list);
1125
1126 if (tag == (uintptr_t) reply)
1127 break;
1128
1129 reply = NULL;
1130 }
1131
1132 if (!reply)
1133 break;
1134
1135 usleep(1000);
1136 } while (1);
1137
1138 return 0;
Jens Axboe89c17072011-10-11 10:15:51 +02001139}
1140
Jens Axboe82c1ed32011-10-10 08:56:18 +02001141static void handle_eta(struct fio_client *client, struct fio_net_cmd *cmd)
Jens Axboe48fbb462011-10-09 12:19:08 +02001142{
1143 struct jobs_eta *je = (struct jobs_eta *) cmd->payload;
Jens Axboedf380932011-10-11 14:25:08 +02001144 struct client_eta *eta = (struct client_eta *) (uintptr_t) cmd->tag;
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001145
1146 dprint(FD_NET, "client: got eta tag %p, %d\n", eta, eta->pending);
Jens Axboe48fbb462011-10-09 12:19:08 +02001147
Jens Axboef77d2672011-10-10 14:36:07 +02001148 assert(client->eta_in_flight == eta);
1149
1150 client->eta_in_flight = NULL;
Jens Axboe82c1ed32011-10-10 08:56:18 +02001151 flist_del_init(&client->eta_list);
1152
Jens Axboe2f99deb2012-03-09 14:37:29 +01001153 if (client->ops->jobs_eta)
1154 client->ops->jobs_eta(client, je);
1155
Jens Axboe3e47bd22012-02-29 13:45:02 +01001156 fio_client_sum_jobs_eta(&eta->eta, je);
Jens Axboea5276612012-03-04 15:15:08 +01001157 fio_client_dec_jobs_eta(eta, client->ops->eta);
Jens Axboecf451d12011-10-03 16:48:30 +02001158}
1159
Jens Axboeb5296dd2011-10-07 16:35:56 +02001160static void handle_probe(struct fio_client *client, struct fio_net_cmd *cmd)
Jens Axboe2e03b4b2011-10-04 09:00:40 +02001161{
Jens Axboe3989b142013-04-12 13:13:24 +02001162 struct cmd_probe_reply_pdu *probe = (struct cmd_probe_reply_pdu *) cmd->payload;
Jens Axboed2333352011-10-11 15:07:23 +02001163 const char *os, *arch;
1164 char bit[16];
Jens Axboe2e03b4b2011-10-04 09:00:40 +02001165
Jens Axboecca84642011-10-07 12:47:57 +02001166 os = fio_get_os_string(probe->os);
1167 if (!os)
1168 os = "unknown";
1169
1170 arch = fio_get_arch_string(probe->arch);
1171 if (!arch)
1172 os = "unknown";
1173
Jens Axboed2333352011-10-11 15:07:23 +02001174 sprintf(bit, "%d-bit", probe->bpp * 8);
Jens Axboe3989b142013-04-12 13:13:24 +02001175 probe->flags = le64_to_cpu(probe->flags);
Jens Axboe38fdef22011-10-11 14:30:06 +02001176
Jens Axboe3989b142013-04-12 13:13:24 +02001177 log_info("hostname=%s, be=%u, %s, os=%s, arch=%s, fio=%s, flags=%lx\n",
Jens Axboe38fdef22011-10-11 14:30:06 +02001178 probe->hostname, probe->bigendian, bit, os, arch,
Jens Axboe3989b142013-04-12 13:13:24 +02001179 probe->fio_version, (unsigned long) probe->flags);
Jens Axboeb5296dd2011-10-07 16:35:56 +02001180
1181 if (!client->name)
1182 client->name = strdup((char *) probe->hostname);
Jens Axboe2e03b4b2011-10-04 09:00:40 +02001183}
1184
Jens Axboe11e950b2011-10-16 21:34:14 +02001185static void handle_start(struct fio_client *client, struct fio_net_cmd *cmd)
1186{
1187 struct cmd_start_pdu *pdu = (struct cmd_start_pdu *) cmd->payload;
1188
1189 client->state = Client_started;
1190 client->jobs = le32_to_cpu(pdu->jobs);
Jens Axboe30f8e312014-10-13 11:33:27 -06001191 client->nr_stat = le32_to_cpu(pdu->stat_outputs);
Jens Axboe108fea72012-11-14 13:09:45 -07001192
Jens Axboe30f8e312014-10-13 11:33:27 -06001193 sum_stat_clients += client->nr_stat;
Jens Axboe11e950b2011-10-16 21:34:14 +02001194}
1195
1196static void handle_stop(struct fio_client *client, struct fio_net_cmd *cmd)
1197{
Jens Axboe498c92c2011-10-17 09:14:42 +02001198 if (client->error)
1199 log_info("client <%s>: exited with error %d\n", client->hostname, client->error);
Jens Axboe11e950b2011-10-16 21:34:14 +02001200}
1201
Jens Axboe6b79c802012-03-08 10:51:36 +01001202static void convert_stop(struct fio_net_cmd *cmd)
1203{
1204 struct cmd_end_pdu *pdu = (struct cmd_end_pdu *) cmd->payload;
1205
1206 pdu->error = le32_to_cpu(pdu->error);
1207}
1208
Jens Axboe084d1c62012-03-03 20:28:07 +01001209static void convert_text(struct fio_net_cmd *cmd)
1210{
1211 struct cmd_text_pdu *pdu = (struct cmd_text_pdu *) cmd->payload;
1212
1213 pdu->level = le32_to_cpu(pdu->level);
1214 pdu->buf_len = le32_to_cpu(pdu->buf_len);
1215 pdu->log_sec = le64_to_cpu(pdu->log_sec);
1216 pdu->log_usec = le64_to_cpu(pdu->log_usec);
1217}
1218
Jens Axboe3989b142013-04-12 13:13:24 +02001219static struct cmd_iolog_pdu *convert_iolog_gz(struct fio_net_cmd *cmd,
1220 struct cmd_iolog_pdu *pdu)
Jens Axboe1b427252012-03-14 15:03:03 +01001221{
Jens Axboe3989b142013-04-12 13:13:24 +02001222#ifdef CONFIG_ZLIB
Jens Axboe1b427252012-03-14 15:03:03 +01001223 struct cmd_iolog_pdu *ret;
Jens Axboe1b427252012-03-14 15:03:03 +01001224 z_stream stream;
Jens Axboe3989b142013-04-12 13:13:24 +02001225 uint32_t nr_samples;
1226 size_t total;
Jens Axboe1b427252012-03-14 15:03:03 +01001227 void *p;
1228
1229 stream.zalloc = Z_NULL;
1230 stream.zfree = Z_NULL;
1231 stream.opaque = Z_NULL;
1232 stream.avail_in = 0;
1233 stream.next_in = Z_NULL;
1234
1235 if (inflateInit(&stream) != Z_OK)
1236 return NULL;
1237
1238 /*
Jens Axboef5ed7652012-03-14 16:28:07 +01001239 * Get header first, it's not compressed
Jens Axboe1b427252012-03-14 15:03:03 +01001240 */
Jens Axboef2b9a672014-07-01 08:47:11 -06001241 nr_samples = le64_to_cpu(pdu->nr_samples);
Jens Axboe1b427252012-03-14 15:03:03 +01001242
Jens Axboef2b9a672014-07-01 08:47:11 -06001243 total = nr_samples * __log_entry_sz(le32_to_cpu(pdu->log_offset));
Jens Axboef5ed7652012-03-14 16:28:07 +01001244 ret = malloc(total + sizeof(*pdu));
Jens Axboe1b427252012-03-14 15:03:03 +01001245 ret->nr_samples = nr_samples;
Jens Axboe3989b142013-04-12 13:13:24 +02001246
1247 memcpy(ret, pdu, sizeof(*pdu));
Jens Axboe1b427252012-03-14 15:03:03 +01001248
Jens Axboef5ed7652012-03-14 16:28:07 +01001249 p = (void *) ret + sizeof(*pdu);
1250
1251 stream.avail_in = cmd->pdu_len - sizeof(*pdu);
1252 stream.next_in = (void *) pdu + sizeof(*pdu);
Jens Axboe1b427252012-03-14 15:03:03 +01001253 while (stream.avail_in) {
1254 unsigned int this_chunk = 65536;
1255 unsigned int this_len;
1256 int err;
1257
1258 if (this_chunk > total)
1259 this_chunk = total;
1260
1261 stream.avail_out = this_chunk;
1262 stream.next_out = p;
1263 err = inflate(&stream, Z_NO_FLUSH);
Jens Axboe3c547fe2012-03-14 21:53:00 +01001264 /* may be Z_OK, or Z_STREAM_END */
1265 if (err < 0) {
Jens Axboe1b427252012-03-14 15:03:03 +01001266 log_err("fio: inflate error %d\n", err);
Jens Axboef5ed7652012-03-14 16:28:07 +01001267 free(ret);
1268 ret = NULL;
Jens Axboe3989b142013-04-12 13:13:24 +02001269 goto err;
Jens Axboe1b427252012-03-14 15:03:03 +01001270 }
1271
1272 this_len = this_chunk - stream.avail_out;
1273 p += this_len;
1274 total -= this_len;
1275 }
1276
Jens Axboe3989b142013-04-12 13:13:24 +02001277err:
1278 inflateEnd(&stream);
1279 return ret;
1280#else
1281 return NULL;
1282#endif
1283}
1284
1285/*
1286 * This has been compressed on the server side, since it can be big.
1287 * Uncompress here.
1288 */
1289static struct cmd_iolog_pdu *convert_iolog(struct fio_net_cmd *cmd)
1290{
1291 struct cmd_iolog_pdu *pdu = (struct cmd_iolog_pdu *) cmd->payload;
1292 struct cmd_iolog_pdu *ret;
Jens Axboeccefd5f2014-06-30 20:59:03 -06001293 uint64_t i;
1294 void *samples;
Jens Axboe3989b142013-04-12 13:13:24 +02001295
1296 /*
1297 * Convert if compressed and we support it. If it's not
1298 * compressed, we need not do anything.
1299 */
1300 if (le32_to_cpu(pdu->compressed)) {
1301#ifndef CONFIG_ZLIB
1302 log_err("fio: server sent compressed data by mistake\n");
1303 return NULL;
1304#endif
1305 ret = convert_iolog_gz(cmd, pdu);
1306 if (!ret) {
1307 log_err("fio: failed decompressing log\n");
1308 return NULL;
1309 }
1310 } else
1311 ret = pdu;
1312
Jens Axboeccefd5f2014-06-30 20:59:03 -06001313 ret->nr_samples = le64_to_cpu(ret->nr_samples);
Jens Axboe3989b142013-04-12 13:13:24 +02001314 ret->thread_number = le32_to_cpu(ret->thread_number);
Jens Axboe3989b142013-04-12 13:13:24 +02001315 ret->log_type = le32_to_cpu(ret->log_type);
1316 ret->compressed = le32_to_cpu(ret->compressed);
Jens Axboeccefd5f2014-06-30 20:59:03 -06001317 ret->log_offset = le32_to_cpu(ret->log_offset);
Jens Axboe3989b142013-04-12 13:13:24 +02001318
Jens Axboee8c4fb02014-07-01 16:07:59 -06001319 samples = &ret->samples[0];
Jens Axboef5ed7652012-03-14 16:28:07 +01001320 for (i = 0; i < ret->nr_samples; i++) {
Jens Axboeccefd5f2014-06-30 20:59:03 -06001321 struct io_sample *s;
Jens Axboef5ed7652012-03-14 16:28:07 +01001322
Jens Axboeccefd5f2014-06-30 20:59:03 -06001323 s = __get_sample(samples, ret->log_offset, i);
Jens Axboebac4af12014-07-03 13:42:28 -06001324 s->time = le64_to_cpu(s->time);
1325 s->val = le64_to_cpu(s->val);
1326 s->__ddir = le32_to_cpu(s->__ddir);
1327 s->bs = le32_to_cpu(s->bs);
Jens Axboeccefd5f2014-06-30 20:59:03 -06001328
1329 if (ret->log_offset) {
1330 struct io_sample_offset *so = (void *) s;
1331
1332 so->offset = le64_to_cpu(so->offset);
1333 }
Jens Axboef5ed7652012-03-14 16:28:07 +01001334 }
1335
Jens Axboe1b427252012-03-14 15:03:03 +01001336 return ret;
1337}
1338
Jens Axboede54cfd2014-11-10 20:34:00 -07001339static void sendfile_reply(int fd, struct cmd_sendfile_reply *rep,
1340 size_t size, uint64_t tag)
1341{
1342 rep->error = cpu_to_le32(rep->error);
1343 fio_net_send_cmd(fd, FIO_NET_CMD_SENDFILE, rep, size, &tag, NULL);
1344}
1345
Jens Axboede54cfd2014-11-10 20:34:00 -07001346static int send_file(struct fio_client *client, struct cmd_sendfile *pdu,
1347 uint64_t tag)
1348{
1349 struct cmd_sendfile_reply *rep;
1350 struct stat sb;
1351 size_t size;
1352 int fd;
1353
1354 size = sizeof(*rep);
1355 rep = malloc(size);
1356
1357 if (stat((char *)pdu->path, &sb) < 0) {
1358fail:
1359 rep->error = errno;
1360 sendfile_reply(client->fd, rep, size, tag);
1361 free(rep);
1362 return 1;
1363 }
1364
1365 size += sb.st_size;
1366 rep = realloc(rep, size);
1367 rep->size = cpu_to_le32((uint32_t) sb.st_size);
1368
1369 fd = open((char *)pdu->path, O_RDONLY);
1370 if (fd == -1 )
1371 goto fail;
1372
1373 rep->error = read_data(fd, &rep->data, sb.st_size);
1374 sendfile_reply(client->fd, rep, size, tag);
1375 free(rep);
1376 close(fd);
1377 return 0;
1378}
1379
Jens Axboea5276612012-03-04 15:15:08 +01001380int fio_handle_client(struct fio_client *client)
Jens Axboe37db14f2011-09-30 17:00:42 -06001381{
Jens Axboea5276612012-03-04 15:15:08 +01001382 struct client_ops *ops = client->ops;
Jens Axboe37db14f2011-09-30 17:00:42 -06001383 struct fio_net_cmd *cmd;
1384
Jens Axboe60efd142011-10-04 13:30:11 +02001385 dprint(FD_NET, "client: handle %s\n", client->hostname);
1386
Jens Axboee951bdc2011-10-05 21:58:45 +02001387 cmd = fio_net_recv_cmd(client->fd);
1388 if (!cmd)
1389 return 0;
Jens Axboec2c94582011-10-05 20:31:30 +02001390
Jens Axboeb9d2f302012-03-08 20:36:28 +01001391 dprint(FD_NET, "client: got cmd op %s from %s (pdu=%u)\n",
1392 fio_server_op(cmd->opcode), client->hostname, cmd->pdu_len);
Jens Axboe46c48f12011-10-01 12:50:51 -06001393
Jens Axboee951bdc2011-10-05 21:58:45 +02001394 switch (cmd->opcode) {
1395 case FIO_NET_CMD_QUIT:
Jens Axboe3ec62ec2012-03-01 12:01:29 +01001396 if (ops->quit)
Jens Axboe35c0ba72012-03-14 10:56:40 +01001397 ops->quit(client, cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001398 remove_client(client);
Jens Axboee951bdc2011-10-05 21:58:45 +02001399 break;
Jens Axboe084d1c62012-03-03 20:28:07 +01001400 case FIO_NET_CMD_TEXT:
1401 convert_text(cmd);
Jens Axboe35c0ba72012-03-14 10:56:40 +01001402 ops->text(client, cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001403 break;
Jens Axboe3bf236c2012-03-03 20:35:50 +01001404 case FIO_NET_CMD_DU: {
1405 struct cmd_du_pdu *du = (struct cmd_du_pdu *) cmd->payload;
1406
1407 convert_dus(&du->dus);
1408 convert_agg(&du->agg);
1409
Stephen M. Camerondd366722012-02-24 08:17:30 +01001410 ops->disk_util(client, cmd);
Jens Axboed09a64a2011-10-13 11:38:56 +02001411 break;
Jens Axboe3bf236c2012-03-03 20:35:50 +01001412 }
1413 case FIO_NET_CMD_TS: {
1414 struct cmd_ts_pdu *p = (struct cmd_ts_pdu *) cmd->payload;
1415
1416 convert_ts(&p->ts, &p->ts);
1417 convert_gs(&p->rs, &p->rs);
1418
Jens Axboe89e5fad2012-03-05 09:21:12 +01001419 ops->thread_status(client, cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001420 break;
Jens Axboe3bf236c2012-03-03 20:35:50 +01001421 }
1422 case FIO_NET_CMD_GS: {
1423 struct group_run_stats *gs = (struct group_run_stats *) cmd->payload;
1424
1425 convert_gs(gs, gs);
1426
Jens Axboe89e5fad2012-03-05 09:21:12 +01001427 ops->group_stats(client, cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001428 break;
Jens Axboe3bf236c2012-03-03 20:35:50 +01001429 }
1430 case FIO_NET_CMD_ETA: {
1431 struct jobs_eta *je = (struct jobs_eta *) cmd->payload;
1432
Jens Axboe89c17072011-10-11 10:15:51 +02001433 remove_reply_cmd(client, cmd);
Jens Axboe3bf236c2012-03-03 20:35:50 +01001434 convert_jobs_eta(je);
Jens Axboea5276612012-03-04 15:15:08 +01001435 handle_eta(client, cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001436 break;
Jens Axboe3bf236c2012-03-03 20:35:50 +01001437 }
Jens Axboee951bdc2011-10-05 21:58:45 +02001438 case FIO_NET_CMD_PROBE:
Jens Axboe89c17072011-10-11 10:15:51 +02001439 remove_reply_cmd(client, cmd);
Stephen M. Camerondd366722012-02-24 08:17:30 +01001440 ops->probe(client, cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001441 break;
Jens Axboe5d7793a2012-03-08 19:59:16 +01001442 case FIO_NET_CMD_SERVER_START:
Jens Axboe01be0382011-10-15 14:43:41 +02001443 client->state = Client_running;
Jens Axboe85dd01e2012-03-12 14:33:16 +01001444 if (ops->job_start)
1445 ops->job_start(client, cmd);
Jens Axboe01be0382011-10-15 14:43:41 +02001446 break;
Jens Axboe85dd01e2012-03-12 14:33:16 +01001447 case FIO_NET_CMD_START: {
1448 struct cmd_start_pdu *pdu = (struct cmd_start_pdu *) cmd->payload;
1449
1450 pdu->jobs = le32_to_cpu(pdu->jobs);
1451 ops->start(client, cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001452 break;
Jens Axboe85dd01e2012-03-12 14:33:16 +01001453 }
Jens Axboe6b79c802012-03-08 10:51:36 +01001454 case FIO_NET_CMD_STOP: {
1455 struct cmd_end_pdu *pdu = (struct cmd_end_pdu *) cmd->payload;
1456
1457 convert_stop(cmd);
1458 client->state = Client_stopped;
Jens Axboe122c7722012-03-19 09:13:15 +01001459 client->error = le32_to_cpu(pdu->error);
1460 client->signal = le32_to_cpu(pdu->signal);
Jens Axboe6b79c802012-03-08 10:51:36 +01001461 ops->stop(client, cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001462 break;
Jens Axboe6b79c802012-03-08 10:51:36 +01001463 }
Jens Axboe40c60512012-03-27 16:03:04 +02001464 case FIO_NET_CMD_ADD_JOB: {
1465 struct cmd_add_job_pdu *pdu = (struct cmd_add_job_pdu *) cmd->payload;
1466
1467 client->thread_number = le32_to_cpu(pdu->thread_number);
1468 client->groupid = le32_to_cpu(pdu->groupid);
1469
Jens Axboe807f9972012-03-02 10:25:24 +01001470 if (ops->add_job)
1471 ops->add_job(client, cmd);
Jens Axboe807f9972012-03-02 10:25:24 +01001472 break;
Jens Axboe40c60512012-03-27 16:03:04 +02001473 }
Jens Axboe1b427252012-03-14 15:03:03 +01001474 case FIO_NET_CMD_IOLOG:
1475 if (ops->iolog) {
1476 struct cmd_iolog_pdu *pdu;
1477
1478 pdu = convert_iolog(cmd);
1479 ops->iolog(client, pdu);
1480 }
Jens Axboe1b427252012-03-14 15:03:03 +01001481 break;
Jens Axboe40c60512012-03-27 16:03:04 +02001482 case FIO_NET_CMD_UPDATE_JOB:
Jens Axboe40c60512012-03-27 16:03:04 +02001483 ops->update_job(client, cmd);
Jens Axboe649cee92012-03-28 09:15:32 +02001484 remove_reply_cmd(client, cmd);
Jens Axboe40c60512012-03-27 16:03:04 +02001485 break;
Jens Axboede54cfd2014-11-10 20:34:00 -07001486 case FIO_NET_CMD_VTRIGGER: {
1487 struct all_io_list *pdu = (struct all_io_list *) cmd->payload;
1488 char buf[64];
1489
1490 __verify_save_state(pdu, server_name(client, buf, sizeof(buf)));
Jens Axboe7eebf502014-11-19 09:09:01 -07001491 exec_trigger(trigger_cmd);
Jens Axboede54cfd2014-11-10 20:34:00 -07001492 break;
1493 }
1494 case FIO_NET_CMD_SENDFILE: {
1495 struct cmd_sendfile *pdu = (struct cmd_sendfile *) cmd->payload;
1496 send_file(client, pdu, cmd->tag);
1497 break;
1498 }
Jens Axboee951bdc2011-10-05 21:58:45 +02001499 default:
Jens Axboe89c17072011-10-11 10:15:51 +02001500 log_err("fio: unknown client op: %s\n", fio_server_op(cmd->opcode));
Jens Axboee951bdc2011-10-05 21:58:45 +02001501 break;
Jens Axboe37db14f2011-09-30 17:00:42 -06001502 }
1503
Jens Axboede54cfd2014-11-10 20:34:00 -07001504 free(cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001505 return 1;
Jens Axboe37db14f2011-09-30 17:00:42 -06001506}
Jens Axboeb66570d2011-10-01 11:11:35 -06001507
Jens Axboede54cfd2014-11-10 20:34:00 -07001508int fio_clients_send_trigger(const char *cmd)
1509{
1510 struct flist_head *entry;
1511 struct fio_client *client;
1512 size_t slen;
1513
1514 dprint(FD_NET, "client: send vtrigger: %s\n", cmd);
1515
1516 if (!cmd)
1517 slen = 0;
1518 else
1519 slen = strlen(cmd);
1520
1521 flist_for_each(entry, &client_list) {
1522 struct cmd_vtrigger_pdu *pdu;
1523
1524 client = flist_entry(entry, struct fio_client, list);
1525
1526 pdu = malloc(sizeof(*pdu) + slen);
1527 pdu->len = cpu_to_le16((uint16_t) slen);
1528 if (slen)
1529 memcpy(pdu->cmd, cmd, slen);
1530 fio_net_send_cmd(client->fd, FIO_NET_CMD_VTRIGGER, pdu,
1531 sizeof(*pdu) + slen, NULL, NULL);
1532 free(pdu);
1533 }
1534
1535 return 0;
1536}
1537
Jens Axboea5276612012-03-04 15:15:08 +01001538static void request_client_etas(struct client_ops *ops)
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001539{
1540 struct fio_client *client;
1541 struct flist_head *entry;
1542 struct client_eta *eta;
Jens Axboe82c1ed32011-10-10 08:56:18 +02001543 int skipped = 0;
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001544
1545 dprint(FD_NET, "client: request eta (%d)\n", nr_clients);
1546
Jens Axboe27b91552014-06-27 15:30:06 -06001547 eta = calloc(1, sizeof(*eta) + __THREAD_RUNSTR_SZ(REAL_MAX_JOBS));
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001548 eta->pending = nr_clients;
1549
1550 flist_for_each(entry, &client_list) {
1551 client = flist_entry(entry, struct fio_client, list);
1552
Jens Axboe82c1ed32011-10-10 08:56:18 +02001553 if (!flist_empty(&client->eta_list)) {
1554 skipped++;
1555 continue;
1556 }
Jens Axboe01be0382011-10-15 14:43:41 +02001557 if (client->state != Client_running)
1558 continue;
Jens Axboe82c1ed32011-10-10 08:56:18 +02001559
Jens Axboef77d2672011-10-10 14:36:07 +02001560 assert(!client->eta_in_flight);
Jens Axboe82c1ed32011-10-10 08:56:18 +02001561 flist_add_tail(&client->eta_list, &eta_list);
Jens Axboef77d2672011-10-10 14:36:07 +02001562 client->eta_in_flight = eta;
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001563 fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_SEND_ETA,
Jens Axboedf380932011-10-11 14:25:08 +02001564 (uintptr_t) eta, &client->cmd_list);
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001565 }
1566
Jens Axboe82c1ed32011-10-10 08:56:18 +02001567 while (skipped--)
Jens Axboea5276612012-03-04 15:15:08 +01001568 fio_client_dec_jobs_eta(eta, ops->eta);
Jens Axboe82c1ed32011-10-10 08:56:18 +02001569
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001570 dprint(FD_NET, "client: requested eta tag %p\n", eta);
1571}
1572
Jens Axboe89c17072011-10-11 10:15:51 +02001573static int client_check_cmd_timeout(struct fio_client *client,
1574 struct timeval *now)
1575{
Jens Axboe40c60512012-03-27 16:03:04 +02001576 struct fio_net_cmd_reply *reply;
Jens Axboe89c17072011-10-11 10:15:51 +02001577 struct flist_head *entry, *tmp;
1578 int ret = 0;
1579
1580 flist_for_each_safe(entry, tmp, &client->cmd_list) {
Jens Axboe40c60512012-03-27 16:03:04 +02001581 reply = flist_entry(entry, struct fio_net_cmd_reply, list);
Jens Axboe89c17072011-10-11 10:15:51 +02001582
Jens Axboe40c60512012-03-27 16:03:04 +02001583 if (mtime_since(&reply->tv, now) < FIO_NET_CLIENT_TIMEOUT)
Jens Axboe89c17072011-10-11 10:15:51 +02001584 continue;
1585
1586 log_err("fio: client %s, timeout on cmd %s\n", client->hostname,
Jens Axboe40c60512012-03-27 16:03:04 +02001587 fio_server_op(reply->opcode));
1588 flist_del(&reply->list);
1589 free(reply);
Jens Axboe89c17072011-10-11 10:15:51 +02001590 ret = 1;
1591 }
1592
1593 return flist_empty(&client->cmd_list) && ret;
1594}
1595
Jens Axboea5276612012-03-04 15:15:08 +01001596static int fio_check_clients_timed_out(void)
Jens Axboe89c17072011-10-11 10:15:51 +02001597{
1598 struct fio_client *client;
1599 struct flist_head *entry, *tmp;
1600 struct timeval tv;
1601 int ret = 0;
1602
Jens Axboe67bf9822013-01-10 11:23:19 +01001603 fio_gettime(&tv, NULL);
Jens Axboe89c17072011-10-11 10:15:51 +02001604
1605 flist_for_each_safe(entry, tmp, &client_list) {
1606 client = flist_entry(entry, struct fio_client, list);
1607
1608 if (flist_empty(&client->cmd_list))
1609 continue;
1610
1611 if (!client_check_cmd_timeout(client, &tv))
1612 continue;
1613
Jens Axboea5276612012-03-04 15:15:08 +01001614 if (client->ops->timed_out)
1615 client->ops->timed_out(client);
Jens Axboeed727a42012-03-02 12:14:40 +01001616 else
1617 log_err("fio: client %s timed out\n", client->hostname);
1618
Jens Axboe89c17072011-10-11 10:15:51 +02001619 remove_client(client);
1620 ret = 1;
1621 }
1622
1623 return ret;
1624}
1625
Stephen M. Camerondd366722012-02-24 08:17:30 +01001626int fio_handle_clients(struct client_ops *ops)
Jens Axboeb66570d2011-10-01 11:11:35 -06001627{
Jens Axboeb66570d2011-10-01 11:11:35 -06001628 struct pollfd *pfds;
Jens Axboe498c92c2011-10-17 09:14:42 +02001629 int i, ret = 0, retval = 0;
Jens Axboeb66570d2011-10-01 11:11:35 -06001630
Jens Axboe67bf9822013-01-10 11:23:19 +01001631 fio_gettime(&eta_tv, NULL);
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001632
Jens Axboeb66570d2011-10-01 11:11:35 -06001633 pfds = malloc(nr_clients * sizeof(struct pollfd));
1634
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001635 init_thread_stat(&client_ts);
1636 init_group_run_stat(&client_gs);
1637
Jens Axboeb66570d2011-10-01 11:11:35 -06001638 while (!exit_backend && nr_clients) {
Jens Axboec2cb6862012-02-23 20:56:12 +01001639 struct flist_head *entry, *tmp;
1640 struct fio_client *client;
1641
Jens Axboe82a4be12011-10-01 12:40:32 -06001642 i = 0;
Jens Axboec2cb6862012-02-23 20:56:12 +01001643 flist_for_each_safe(entry, tmp, &client_list) {
Jens Axboe82a4be12011-10-01 12:40:32 -06001644 client = flist_entry(entry, struct fio_client, list);
1645
Jens Axboea5276612012-03-04 15:15:08 +01001646 if (!client->sent_job && !client->ops->stay_connected &&
Jens Axboec2cb6862012-02-23 20:56:12 +01001647 flist_empty(&client->cmd_list)) {
1648 remove_client(client);
1649 continue;
1650 }
1651
Jens Axboe82a4be12011-10-01 12:40:32 -06001652 pfds[i].fd = client->fd;
1653 pfds[i].events = POLLIN;
1654 i++;
1655 }
1656
Jens Axboec2cb6862012-02-23 20:56:12 +01001657 if (!nr_clients)
1658 break;
1659
Jens Axboe82a4be12011-10-01 12:40:32 -06001660 assert(i == nr_clients);
1661
Jens Axboe5c2857f2011-10-04 13:14:32 +02001662 do {
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001663 struct timeval tv;
Jens Axboede54cfd2014-11-10 20:34:00 -07001664 int timeout;
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001665
Jens Axboe67bf9822013-01-10 11:23:19 +01001666 fio_gettime(&tv, NULL);
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001667 if (mtime_since(&eta_tv, &tv) >= 900) {
Jens Axboea5276612012-03-04 15:15:08 +01001668 request_client_etas(ops);
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001669 memcpy(&eta_tv, &tv, sizeof(tv));
Jens Axboe89c17072011-10-11 10:15:51 +02001670
Jens Axboea5276612012-03-04 15:15:08 +01001671 if (fio_check_clients_timed_out())
Jens Axboe89c17072011-10-11 10:15:51 +02001672 break;
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001673 }
1674
Jens Axboede54cfd2014-11-10 20:34:00 -07001675 check_trigger_file();
1676
1677 timeout = min(100u, ops->eta_msec);
1678
1679 ret = poll(pfds, nr_clients, timeout);
Jens Axboe5c2857f2011-10-04 13:14:32 +02001680 if (ret < 0) {
1681 if (errno == EINTR)
1682 continue;
1683 log_err("fio: poll clients: %s\n", strerror(errno));
1684 break;
1685 } else if (!ret)
Jens Axboeb66570d2011-10-01 11:11:35 -06001686 continue;
Jens Axboe5c2857f2011-10-04 13:14:32 +02001687 } while (ret <= 0);
Jens Axboeb66570d2011-10-01 11:11:35 -06001688
1689 for (i = 0; i < nr_clients; i++) {
1690 if (!(pfds[i].revents & POLLIN))
1691 continue;
1692
1693 client = find_client_by_fd(pfds[i].fd);
1694 if (!client) {
Jens Axboe65e1a122013-08-30 10:13:36 -06001695 log_err("fio: unknown client fd %ld\n", (long) pfds[i].fd);
Jens Axboeb66570d2011-10-01 11:11:35 -06001696 continue;
1697 }
Jens Axboea5276612012-03-04 15:15:08 +01001698 if (!fio_handle_client(client)) {
Jens Axboe28d3ab02011-10-05 20:45:37 +02001699 log_info("client: host=%s disconnected\n",
1700 client->hostname);
1701 remove_client(client);
Jens Axboe498c92c2011-10-17 09:14:42 +02001702 retval = 1;
Jens Axboe38990762011-10-17 13:31:33 +02001703 } else if (client->error)
Jens Axboe498c92c2011-10-17 09:14:42 +02001704 retval = 1;
Jens Axboe343cb4a2012-03-09 17:16:51 +01001705 fio_put_client(client);
Jens Axboeb66570d2011-10-01 11:11:35 -06001706 }
1707 }
1708
Castor Fu952b05e2013-10-31 11:00:34 -06001709 fio_client_json_fini();
1710
Jens Axboeb66570d2011-10-01 11:11:35 -06001711 free(pfds);
Jens Axboe498c92c2011-10-17 09:14:42 +02001712 return retval;
Jens Axboeb66570d2011-10-01 11:11:35 -06001713}