blob: 3cb7c1c50a92f27706da48f5d4ce64ccb7ca6b59 [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;
383 uint64_t tag;
Jens Axboede54cfd2014-11-10 20:34:00 -0700384 char buf[64];
Jens Axboe3989b142013-04-12 13:13:24 +0200385
Jens Axboed824c3b2012-03-09 17:45:43 +0100386 dprint(FD_NET, "client: send probe\n");
387
Jens Axboe3989b142013-04-12 13:13:24 +0200388#ifdef CONFIG_ZLIB
389 pdu.flags = __le64_to_cpu(FIO_PROBE_FLAG_ZLIB);
390#else
391 pdu.flags = 0;
392#endif
393
Jens Axboede54cfd2014-11-10 20:34:00 -0700394 strcpy((char *) pdu.server, server_name(client, buf, sizeof(buf)));
395
Jens Axboe3989b142013-04-12 13:13:24 +0200396 fio_net_send_cmd(client->fd, FIO_NET_CMD_PROBE, &pdu, sizeof(pdu), &tag, &client->cmd_list);
Jens Axboed824c3b2012-03-09 17:45:43 +0100397}
398
Jens Axboe87aa8f12011-10-06 21:24:13 +0200399static int fio_client_connect_ip(struct fio_client *client)
Jens Axboea37f69b2011-10-01 12:24:21 -0600400{
Jens Axboe811826b2011-10-24 09:11:50 +0200401 struct sockaddr *addr;
Jens Axboe67bf9822013-01-10 11:23:19 +0100402 socklen_t socklen;
Jens Axboe811826b2011-10-24 09:11:50 +0200403 int fd, domain;
Jens Axboe132159a2011-09-30 15:01:32 -0600404
Jens Axboe811826b2011-10-24 09:11:50 +0200405 if (client->ipv6) {
406 client->addr6.sin6_family = AF_INET6;
407 client->addr6.sin6_port = htons(client->port);
408 domain = AF_INET6;
409 addr = (struct sockaddr *) &client->addr6;
410 socklen = sizeof(client->addr6);
411 } else {
412 client->addr.sin_family = AF_INET;
413 client->addr.sin_port = htons(client->port);
414 domain = AF_INET;
415 addr = (struct sockaddr *) &client->addr;
416 socklen = sizeof(client->addr);
417 }
Jens Axboe132159a2011-09-30 15:01:32 -0600418
Jens Axboe811826b2011-10-24 09:11:50 +0200419 fd = socket(domain, SOCK_STREAM, 0);
Jens Axboe132159a2011-09-30 15:01:32 -0600420 if (fd < 0) {
Jens Axboe25095e12012-03-09 17:09:55 +0100421 int ret = -errno;
422
Jens Axboe132159a2011-09-30 15:01:32 -0600423 log_err("fio: socket: %s\n", strerror(errno));
Jens Axboe25095e12012-03-09 17:09:55 +0100424 return ret;
Jens Axboe132159a2011-09-30 15:01:32 -0600425 }
426
Jens Axboe811826b2011-10-24 09:11:50 +0200427 if (connect(fd, addr, socklen) < 0) {
Jens Axboe25095e12012-03-09 17:09:55 +0100428 int ret = -errno;
429
Jens Axboe132159a2011-09-30 15:01:32 -0600430 log_err("fio: connect: %s\n", strerror(errno));
Jens Axboea7de0a12011-10-07 12:55:14 +0200431 log_err("fio: failed to connect to %s:%u\n", client->hostname,
432 client->port);
Jens Axboeb94cba42011-10-06 21:27:10 +0200433 close(fd);
Jens Axboe25095e12012-03-09 17:09:55 +0100434 return ret;
Jens Axboe132159a2011-09-30 15:01:32 -0600435 }
436
Jens Axboe87aa8f12011-10-06 21:24:13 +0200437 return fd;
438}
439
440static int fio_client_connect_sock(struct fio_client *client)
441{
442 struct sockaddr_un *addr = &client->addr_un;
Jens Axboe67bf9822013-01-10 11:23:19 +0100443 socklen_t len;
Jens Axboe87aa8f12011-10-06 21:24:13 +0200444 int fd;
445
446 memset(addr, 0, sizeof(*addr));
447 addr->sun_family = AF_UNIX;
Jens Axboe1cb96412014-04-14 08:50:33 -0600448 strncpy(addr->sun_path, client->hostname, sizeof(addr->sun_path) - 1);
Jens Axboe87aa8f12011-10-06 21:24:13 +0200449
450 fd = socket(AF_UNIX, SOCK_STREAM, 0);
451 if (fd < 0) {
Jens Axboe25095e12012-03-09 17:09:55 +0100452 int ret = -errno;
453
Jens Axboe87aa8f12011-10-06 21:24:13 +0200454 log_err("fio: socket: %s\n", strerror(errno));
Jens Axboe25095e12012-03-09 17:09:55 +0100455 return ret;
Jens Axboe87aa8f12011-10-06 21:24:13 +0200456 }
457
458 len = sizeof(addr->sun_family) + strlen(addr->sun_path) + 1;
459 if (connect(fd, (struct sockaddr *) addr, len) < 0) {
Jens Axboe25095e12012-03-09 17:09:55 +0100460 int ret = -errno;
461
Jens Axboe87aa8f12011-10-06 21:24:13 +0200462 log_err("fio: connect; %s\n", strerror(errno));
Jens Axboeb94cba42011-10-06 21:27:10 +0200463 close(fd);
Jens Axboe25095e12012-03-09 17:09:55 +0100464 return ret;
Jens Axboe87aa8f12011-10-06 21:24:13 +0200465 }
466
467 return fd;
468}
469
Jens Axboe2f99deb2012-03-09 14:37:29 +0100470int fio_client_connect(struct fio_client *client)
Jens Axboe87aa8f12011-10-06 21:24:13 +0200471{
472 int fd;
473
474 dprint(FD_NET, "client: connect to host %s\n", client->hostname);
475
Jens Axboe87aa8f12011-10-06 21:24:13 +0200476 if (client->is_sock)
477 fd = fio_client_connect_sock(client);
478 else
479 fd = fio_client_connect_ip(client);
480
Jens Axboe89c17072011-10-11 10:15:51 +0200481 dprint(FD_NET, "client: %s connected %d\n", client->hostname, fd);
482
Jens Axboe87aa8f12011-10-06 21:24:13 +0200483 if (fd < 0)
Jens Axboea1a3ed52012-03-09 17:00:01 +0100484 return fd;
Jens Axboe87aa8f12011-10-06 21:24:13 +0200485
Jens Axboeb66570d2011-10-01 11:11:35 -0600486 client->fd = fd;
Jens Axboebebe6392011-10-07 10:00:51 +0200487 fio_client_add_hash(client);
Jens Axboe81179ee2011-10-04 12:42:06 +0200488 client->state = Client_connected;
Jens Axboed824c3b2012-03-09 17:45:43 +0100489
490 probe_client(client);
Jens Axboe132159a2011-09-30 15:01:32 -0600491 return 0;
492}
493
Jens Axboe0cf3ece2012-03-21 10:15:20 +0100494int fio_client_terminate(struct fio_client *client)
Jens Axboe2f99deb2012-03-09 14:37:29 +0100495{
Jens Axboe0cf3ece2012-03-21 10:15:20 +0100496 return fio_net_send_quit(client->fd);
Jens Axboe2f99deb2012-03-09 14:37:29 +0100497}
498
Jens Axboecc0df002011-10-03 20:53:32 +0200499void fio_clients_terminate(void)
500{
501 struct flist_head *entry;
502 struct fio_client *client;
503
Jens Axboe60efd142011-10-04 13:30:11 +0200504 dprint(FD_NET, "client: terminate clients\n");
505
Jens Axboecc0df002011-10-03 20:53:32 +0200506 flist_for_each(entry, &client_list) {
507 client = flist_entry(entry, struct fio_client, list);
Jens Axboe2f99deb2012-03-09 14:37:29 +0100508 fio_client_terminate(client);
Jens Axboecc0df002011-10-03 20:53:32 +0200509 }
510}
511
512static void sig_int(int sig)
513{
Jens Axboebebe6392011-10-07 10:00:51 +0200514 dprint(FD_NET, "client: got signal %d\n", sig);
Jens Axboecc0df002011-10-03 20:53:32 +0200515 fio_clients_terminate();
516}
517
Jens Axboeb852e7c2012-03-30 10:30:35 +0200518static void sig_show_status(int sig)
519{
520 show_running_run_stats();
521}
522
Jens Axboecc0df002011-10-03 20:53:32 +0200523static void client_signal_handler(void)
524{
525 struct sigaction act;
526
527 memset(&act, 0, sizeof(act));
528 act.sa_handler = sig_int;
529 act.sa_flags = SA_RESTART;
530 sigaction(SIGINT, &act, NULL);
531
532 memset(&act, 0, sizeof(act));
533 act.sa_handler = sig_int;
534 act.sa_flags = SA_RESTART;
535 sigaction(SIGTERM, &act, NULL);
Jens Axboeb852e7c2012-03-30 10:30:35 +0200536
Bruce Cran2f694502012-10-10 16:34:13 +0100537/* Windows uses SIGBREAK as a quit signal from other applications */
538#ifdef WIN32
539 memset(&act, 0, sizeof(act));
540 act.sa_handler = sig_int;
541 act.sa_flags = SA_RESTART;
542 sigaction(SIGBREAK, &act, NULL);
543#endif
544
Jens Axboeb852e7c2012-03-30 10:30:35 +0200545 memset(&act, 0, sizeof(act));
546 act.sa_handler = sig_show_status;
547 act.sa_flags = SA_RESTART;
548 sigaction(SIGUSR1, &act, NULL);
Jens Axboecc0df002011-10-03 20:53:32 +0200549}
550
Jens Axboe81179ee2011-10-04 12:42:06 +0200551static int send_client_cmd_line(struct fio_client *client)
552{
Jens Axboefa2ea802011-10-08 21:07:29 +0200553 struct cmd_single_line_pdu *cslp;
554 struct cmd_line_pdu *clp;
555 unsigned long offset;
Jens Axboe7f868312011-10-10 09:55:21 +0200556 unsigned int *lens;
Jens Axboefa2ea802011-10-08 21:07:29 +0200557 void *pdu;
558 size_t mem;
Jens Axboe81179ee2011-10-04 12:42:06 +0200559 int i, ret;
560
Jens Axboe39e8e012011-10-04 13:46:08 +0200561 dprint(FD_NET, "client: send cmdline %d\n", client->argc);
Jens Axboe60efd142011-10-04 13:30:11 +0200562
Jens Axboe7f868312011-10-10 09:55:21 +0200563 lens = malloc(client->argc * sizeof(unsigned int));
564
Jens Axboefa2ea802011-10-08 21:07:29 +0200565 /*
566 * Find out how much mem we need
567 */
Jens Axboe7f868312011-10-10 09:55:21 +0200568 for (i = 0, mem = 0; i < client->argc; i++) {
569 lens[i] = strlen(client->argv[i]) + 1;
570 mem += lens[i];
571 }
Jens Axboe81179ee2011-10-04 12:42:06 +0200572
Jens Axboefa2ea802011-10-08 21:07:29 +0200573 /*
574 * We need one cmd_line_pdu, and argc number of cmd_single_line_pdu
575 */
576 mem += sizeof(*clp) + (client->argc * sizeof(*cslp));
577
578 pdu = malloc(mem);
579 clp = pdu;
580 offset = sizeof(*clp);
581
582 for (i = 0; i < client->argc; i++) {
Jens Axboe7f868312011-10-10 09:55:21 +0200583 uint16_t arg_len = lens[i];
Jens Axboefa2ea802011-10-08 21:07:29 +0200584
585 cslp = pdu + offset;
586 strcpy((char *) cslp->text, client->argv[i]);
587 cslp->len = cpu_to_le16(arg_len);
588 offset += sizeof(*cslp) + arg_len;
589 }
590
Jens Axboe7f868312011-10-10 09:55:21 +0200591 free(lens);
Jens Axboefa2ea802011-10-08 21:07:29 +0200592 clp->lines = cpu_to_le16(client->argc);
Jens Axboe46bcd492012-03-14 11:31:21 +0100593 clp->client_type = __cpu_to_le16(client->type);
Jens Axboe40c60512012-03-27 16:03:04 +0200594 ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOBLINE, pdu, mem, NULL, NULL);
Jens Axboe81179ee2011-10-04 12:42:06 +0200595 free(pdu);
596 return ret;
597}
598
Jens Axboea37f69b2011-10-01 12:24:21 -0600599int fio_clients_connect(void)
600{
601 struct fio_client *client;
602 struct flist_head *entry, *tmp;
603 int ret;
604
Bruce Cran93bcfd22012-02-20 20:18:19 +0100605#ifdef WIN32
606 WSADATA wsd;
Jens Axboe3c3ed072012-03-27 09:12:39 +0200607 WSAStartup(MAKEWORD(2, 2), &wsd);
Bruce Cran93bcfd22012-02-20 20:18:19 +0100608#endif
609
Jens Axboe60efd142011-10-04 13:30:11 +0200610 dprint(FD_NET, "client: connect all\n");
611
Jens Axboecc0df002011-10-03 20:53:32 +0200612 client_signal_handler();
613
Jens Axboea37f69b2011-10-01 12:24:21 -0600614 flist_for_each_safe(entry, tmp, &client_list) {
615 client = flist_entry(entry, struct fio_client, list);
616
617 ret = fio_client_connect(client);
Jens Axboe0b8f30a2011-10-04 10:31:53 +0200618 if (ret) {
Jens Axboea37f69b2011-10-01 12:24:21 -0600619 remove_client(client);
Jens Axboe0b8f30a2011-10-04 10:31:53 +0200620 continue;
621 }
622
Jens Axboe81179ee2011-10-04 12:42:06 +0200623 if (client->argc > 1)
624 send_client_cmd_line(client);
Jens Axboea37f69b2011-10-01 12:24:21 -0600625 }
626
627 return !nr_clients;
628}
629
Jens Axboeb9d2f302012-03-08 20:36:28 +0100630int fio_start_client(struct fio_client *client)
631{
632 dprint(FD_NET, "client: start %s\n", client->hostname);
633 return fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_RUN, 0, NULL);
634}
635
636int fio_start_all_clients(void)
637{
638 struct fio_client *client;
639 struct flist_head *entry, *tmp;
640 int ret;
641
642 dprint(FD_NET, "client: start all\n");
643
Castor Fu952b05e2013-10-31 11:00:34 -0600644 fio_client_json_init();
645
Jens Axboeb9d2f302012-03-08 20:36:28 +0100646 flist_for_each_safe(entry, tmp, &client_list) {
647 client = flist_entry(entry, struct fio_client, list);
648
649 ret = fio_start_client(client);
650 if (ret) {
651 remove_client(client);
652 continue;
653 }
654 }
655
656 return flist_empty(&client_list);
657}
658
Jens Axboe35899182014-10-07 20:56:28 -0600659static int __fio_client_send_remote_ini(struct fio_client *client,
660 const char *filename)
661{
662 struct cmd_load_file_pdu *pdu;
663 size_t p_size;
664 int ret;
665
666 dprint(FD_NET, "send remote ini %s to %s\n", filename, client->hostname);
667
Jens Axboe79ecc302014-10-07 22:02:21 -0600668 p_size = sizeof(*pdu) + strlen(filename) + 1;
Jens Axboe35899182014-10-07 20:56:28 -0600669 pdu = malloc(p_size);
Jens Axboe79ecc302014-10-07 22:02:21 -0600670 memset(pdu, 0, p_size);
Jens Axboe35899182014-10-07 20:56:28 -0600671 pdu->name_len = strlen(filename);
672 strcpy((char *) pdu->file, filename);
673 pdu->client_type = cpu_to_le16((uint16_t) client->type);
674
675 client->sent_job = 1;
676 ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_LOAD_FILE, pdu, p_size,NULL, NULL);
677 free(pdu);
678 return ret;
679}
680
Jens Axboe132159a2011-09-30 15:01:32 -0600681/*
682 * Send file contents to server backend. We could use sendfile(), but to remain
683 * more portable lets just read/write the darn thing.
684 */
Jens Axboe35899182014-10-07 20:56:28 -0600685static int __fio_client_send_local_ini(struct fio_client *client,
686 const char *filename)
Jens Axboe132159a2011-09-30 15:01:32 -0600687{
Jens Axboe46bcd492012-03-14 11:31:21 +0100688 struct cmd_job_pdu *pdu;
689 size_t p_size;
Jens Axboe132159a2011-09-30 15:01:32 -0600690 struct stat sb;
Jens Axboe46bcd492012-03-14 11:31:21 +0100691 char *p;
692 void *buf;
Jens Axboe132159a2011-09-30 15:01:32 -0600693 off_t len;
694 int fd, ret;
695
Jens Axboe46c48f12011-10-01 12:50:51 -0600696 dprint(FD_NET, "send ini %s to %s\n", filename, client->hostname);
697
Jens Axboe132159a2011-09-30 15:01:32 -0600698 fd = open(filename, O_RDONLY);
699 if (fd < 0) {
Jens Axboe0f7f9a92014-11-06 09:21:10 -0700700 ret = -errno;
Jens Axboee951bdc2011-10-05 21:58:45 +0200701 log_err("fio: job file <%s> open: %s\n", filename, strerror(errno));
Jens Axboe25095e12012-03-09 17:09:55 +0100702 return ret;
Jens Axboe132159a2011-09-30 15:01:32 -0600703 }
704
705 if (fstat(fd, &sb) < 0) {
Jens Axboe0f7f9a92014-11-06 09:21:10 -0700706 ret = -errno;
Jens Axboe132159a2011-09-30 15:01:32 -0600707 log_err("fio: job file stat: %s\n", strerror(errno));
Jens Axboeb94cba42011-10-06 21:27:10 +0200708 close(fd);
Jens Axboe25095e12012-03-09 17:09:55 +0100709 return ret;
Jens Axboe132159a2011-09-30 15:01:32 -0600710 }
711
Jens Axboe46bcd492012-03-14 11:31:21 +0100712 p_size = sb.st_size + sizeof(*pdu);
713 pdu = malloc(p_size);
714 buf = pdu->buf;
Jens Axboe132159a2011-09-30 15:01:32 -0600715
716 len = sb.st_size;
717 p = buf;
Jens Axboe3d0be7c2014-11-11 10:24:00 -0700718 if (read_data(fd, p, len)) {
Jens Axboe0b8f30a2011-10-04 10:31:53 +0200719 log_err("fio: failed reading job file %s\n", filename);
Jens Axboeb94cba42011-10-06 21:27:10 +0200720 close(fd);
Hong Zhiguo03a22d92013-10-16 08:35:12 -0600721 free(pdu);
Jens Axboe0b8f30a2011-10-04 10:31:53 +0200722 return 1;
723 }
724
Jens Axboe46bcd492012-03-14 11:31:21 +0100725 pdu->buf_len = __cpu_to_le32(sb.st_size);
726 pdu->client_type = cpu_to_le32(client->type);
727
Jens Axboec2cb6862012-02-23 20:56:12 +0100728 client->sent_job = 1;
Jens Axboe40c60512012-03-27 16:03:04 +0200729 ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOB, pdu, p_size, NULL, NULL);
Jens Axboe46bcd492012-03-14 11:31:21 +0100730 free(pdu);
Jens Axboeb94cba42011-10-06 21:27:10 +0200731 close(fd);
Jens Axboe132159a2011-09-30 15:01:32 -0600732 return ret;
733}
Jens Axboe37db14f2011-09-30 17:00:42 -0600734
Jens Axboe35899182014-10-07 20:56:28 -0600735int fio_client_send_ini(struct fio_client *client, const char *filename,
736 int remote)
Jens Axboe9988ca72012-03-09 15:14:06 +0100737{
Jens Axboe25095e12012-03-09 17:09:55 +0100738 int ret;
739
Jens Axboe35899182014-10-07 20:56:28 -0600740 if (!remote)
741 ret = __fio_client_send_local_ini(client, filename);
742 else
743 ret = __fio_client_send_remote_ini(client, filename);
744
Jens Axboe3af45202012-03-13 09:59:53 +0100745 if (!ret)
746 client->sent_job = 1;
Jens Axboe9988ca72012-03-09 15:14:06 +0100747
Jens Axboe25095e12012-03-09 17:09:55 +0100748 return ret;
Jens Axboe9988ca72012-03-09 15:14:06 +0100749}
750
Jens Axboe35899182014-10-07 20:56:28 -0600751static int fio_client_send_cf(struct fio_client *client,
752 struct client_file *cf)
753{
754 return fio_client_send_ini(client, cf->file, cf->remote);
755}
756
Jens Axboea37f69b2011-10-01 12:24:21 -0600757int fio_clients_send_ini(const char *filename)
758{
759 struct fio_client *client;
760 struct flist_head *entry, *tmp;
761
762 flist_for_each_safe(entry, tmp, &client_list) {
763 client = flist_entry(entry, struct fio_client, list);
764
Jens Axboe35899182014-10-07 20:56:28 -0600765 if (client->nr_files) {
Jens Axboe14ea90e2012-08-26 17:33:34 +0200766 int i;
767
Jens Axboe35899182014-10-07 20:56:28 -0600768 for (i = 0; i < client->nr_files; i++) {
769 struct client_file *cf;
Jens Axboe14ea90e2012-08-26 17:33:34 +0200770
Jens Axboe35899182014-10-07 20:56:28 -0600771 cf = &client->files[i];
772
773 if (fio_client_send_cf(client, cf)) {
Jens Axboe14ea90e2012-08-26 17:33:34 +0200774 remove_client(client);
775 break;
776 }
777 }
Jens Axboe35899182014-10-07 20:56:28 -0600778 }
779 if (client->sent_job)
780 continue;
781 if (!filename || fio_client_send_ini(client, filename, 0))
Jens Axboe3af45202012-03-13 09:59:53 +0100782 remove_client(client);
Jens Axboea37f69b2011-10-01 12:24:21 -0600783 }
784
785 return !nr_clients;
786}
787
Jens Axboe40c60512012-03-27 16:03:04 +0200788int fio_client_update_options(struct fio_client *client,
789 struct thread_options *o, uint64_t *tag)
790{
791 struct cmd_add_job_pdu pdu;
792
793 pdu.thread_number = cpu_to_le32(client->thread_number);
794 pdu.groupid = cpu_to_le32(client->groupid);
795 convert_thread_options_to_net(&pdu.top, o);
Castor Fu952b05e2013-10-31 11:00:34 -0600796
Jens Axboe40c60512012-03-27 16:03:04 +0200797 return fio_net_send_cmd(client->fd, FIO_NET_CMD_UPDATE_JOB, &pdu, sizeof(pdu), tag, &client->cmd_list);
798}
799
Jens Axboea64e88d2011-10-03 14:20:01 +0200800static void convert_io_stat(struct io_stat *dst, struct io_stat *src)
801{
802 dst->max_val = le64_to_cpu(src->max_val);
803 dst->min_val = le64_to_cpu(src->min_val);
804 dst->samples = le64_to_cpu(src->samples);
Jens Axboe802ad4a2011-10-05 09:51:58 +0200805
806 /*
807 * Floats arrive as IEEE 754 encoded uint64_t, convert back to double
808 */
809 dst->mean.u.f = fio_uint64_to_double(le64_to_cpu(dst->mean.u.i));
810 dst->S.u.f = fio_uint64_to_double(le64_to_cpu(dst->S.u.i));
Jens Axboea64e88d2011-10-03 14:20:01 +0200811}
812
813static void convert_ts(struct thread_stat *dst, struct thread_stat *src)
814{
815 int i, j;
816
Jens Axboe2f122b12012-03-15 13:10:19 +0100817 dst->error = le32_to_cpu(src->error);
818 dst->thread_number = le32_to_cpu(src->thread_number);
819 dst->groupid = le32_to_cpu(src->groupid);
820 dst->pid = le32_to_cpu(src->pid);
821 dst->members = le32_to_cpu(src->members);
Jens Axboe771e58b2013-01-30 12:56:23 +0100822 dst->unified_rw_rep = le32_to_cpu(src->unified_rw_rep);
Jens Axboea64e88d2011-10-03 14:20:01 +0200823
Jens Axboe298921d2012-09-24 18:47:01 +0200824 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
Jens Axboea64e88d2011-10-03 14:20:01 +0200825 convert_io_stat(&dst->clat_stat[i], &src->clat_stat[i]);
826 convert_io_stat(&dst->slat_stat[i], &src->slat_stat[i]);
827 convert_io_stat(&dst->lat_stat[i], &src->lat_stat[i]);
828 convert_io_stat(&dst->bw_stat[i], &src->bw_stat[i]);
829 }
830
831 dst->usr_time = le64_to_cpu(src->usr_time);
832 dst->sys_time = le64_to_cpu(src->sys_time);
833 dst->ctx = le64_to_cpu(src->ctx);
834 dst->minf = le64_to_cpu(src->minf);
835 dst->majf = le64_to_cpu(src->majf);
836 dst->clat_percentiles = le64_to_cpu(src->clat_percentiles);
Jens Axboe623216d2014-11-07 18:47:41 -0700837 dst->percentile_precision = le64_to_cpu(src->percentile_precision);
Jens Axboe802ad4a2011-10-05 09:51:58 +0200838
839 for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) {
840 fio_fp64_t *fps = &src->percentile_list[i];
841 fio_fp64_t *fpd = &dst->percentile_list[i];
842
843 fpd->u.f = fio_uint64_to_double(le64_to_cpu(fps->u.i));
844 }
Jens Axboea64e88d2011-10-03 14:20:01 +0200845
846 for (i = 0; i < FIO_IO_U_MAP_NR; i++) {
847 dst->io_u_map[i] = le32_to_cpu(src->io_u_map[i]);
848 dst->io_u_submit[i] = le32_to_cpu(src->io_u_submit[i]);
849 dst->io_u_complete[i] = le32_to_cpu(src->io_u_complete[i]);
850 }
851
852 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) {
853 dst->io_u_lat_u[i] = le32_to_cpu(src->io_u_lat_u[i]);
854 dst->io_u_lat_m[i] = le32_to_cpu(src->io_u_lat_m[i]);
855 }
856
Jens Axboe298921d2012-09-24 18:47:01 +0200857 for (i = 0; i < DDIR_RWDIR_CNT; i++)
Jens Axboea64e88d2011-10-03 14:20:01 +0200858 for (j = 0; j < FIO_IO_U_PLAT_NR; j++)
859 dst->io_u_plat[i][j] = le32_to_cpu(src->io_u_plat[i][j]);
860
Jens Axboe78799de2013-01-29 20:53:52 +0100861 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
Jens Axboea64e88d2011-10-03 14:20:01 +0200862 dst->total_io_u[i] = le64_to_cpu(src->total_io_u[i]);
Jens Axboe93eee042011-10-03 21:08:48 +0200863 dst->short_io_u[i] = le64_to_cpu(src->short_io_u[i]);
Jens Axboe67e149c2014-10-09 13:27:44 -0600864 dst->drop_io_u[i] = le64_to_cpu(src->drop_io_u[i]);
Jens Axboea64e88d2011-10-03 14:20:01 +0200865 }
866
867 dst->total_submit = le64_to_cpu(src->total_submit);
868 dst->total_complete = le64_to_cpu(src->total_complete);
869
Jens Axboe298921d2012-09-24 18:47:01 +0200870 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
Jens Axboea64e88d2011-10-03 14:20:01 +0200871 dst->io_bytes[i] = le64_to_cpu(src->io_bytes[i]);
872 dst->runtime[i] = le64_to_cpu(src->runtime[i]);
873 }
874
875 dst->total_run_time = le64_to_cpu(src->total_run_time);
876 dst->continue_on_error = le16_to_cpu(src->continue_on_error);
877 dst->total_err_count = le64_to_cpu(src->total_err_count);
Jens Axboeddcc0b62011-10-03 14:45:27 +0200878 dst->first_error = le32_to_cpu(src->first_error);
879 dst->kb_base = le32_to_cpu(src->kb_base);
Steven Noonanad705bc2013-04-08 15:05:25 -0700880 dst->unit_base = le32_to_cpu(src->unit_base);
Jens Axboe3e260a42013-12-09 12:38:53 -0700881
882 dst->latency_depth = le32_to_cpu(src->latency_depth);
883 dst->latency_target = le64_to_cpu(src->latency_target);
884 dst->latency_window = le64_to_cpu(src->latency_window);
885 dst->latency_percentile.u.f = fio_uint64_to_double(le64_to_cpu(src->latency_percentile.u.i));
Jens Axboea64e88d2011-10-03 14:20:01 +0200886}
887
888static void convert_gs(struct group_run_stats *dst, struct group_run_stats *src)
889{
890 int i;
891
Jens Axboe298921d2012-09-24 18:47:01 +0200892 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
Jens Axboea64e88d2011-10-03 14:20:01 +0200893 dst->max_run[i] = le64_to_cpu(src->max_run[i]);
894 dst->min_run[i] = le64_to_cpu(src->min_run[i]);
895 dst->max_bw[i] = le64_to_cpu(src->max_bw[i]);
896 dst->min_bw[i] = le64_to_cpu(src->min_bw[i]);
897 dst->io_kb[i] = le64_to_cpu(src->io_kb[i]);
898 dst->agg[i] = le64_to_cpu(src->agg[i]);
899 }
900
901 dst->kb_base = le32_to_cpu(src->kb_base);
Steven Noonanad705bc2013-04-08 15:05:25 -0700902 dst->unit_base = le32_to_cpu(src->unit_base);
Jens Axboea64e88d2011-10-03 14:20:01 +0200903 dst->groupid = le32_to_cpu(src->groupid);
Jens Axboe771e58b2013-01-30 12:56:23 +0100904 dst->unified_rw_rep = le32_to_cpu(src->unified_rw_rep);
Jens Axboea64e88d2011-10-03 14:20:01 +0200905}
906
Castor Fu952b05e2013-10-31 11:00:34 -0600907static void json_object_add_client_info(struct json_object *obj,
Castor Fu54bcda52014-08-22 17:16:44 -0500908 struct fio_client *client)
Castor Fu952b05e2013-10-31 11:00:34 -0600909{
Castor Fu54bcda52014-08-22 17:16:44 -0500910 const char *hostname = client->hostname ? client->hostname : "";
911
912 json_object_add_value_string(obj, "hostname", hostname);
Castor Fu952b05e2013-10-31 11:00:34 -0600913 json_object_add_value_int(obj, "port", client->port);
914}
915
Jens Axboe89e5fad2012-03-05 09:21:12 +0100916static void handle_ts(struct fio_client *client, struct fio_net_cmd *cmd)
Jens Axboea64e88d2011-10-03 14:20:01 +0200917{
918 struct cmd_ts_pdu *p = (struct cmd_ts_pdu *) cmd->payload;
Castor Fu952b05e2013-10-31 11:00:34 -0600919 struct json_object *tsobj;
Jens Axboea64e88d2011-10-03 14:20:01 +0200920
Castor Fu952b05e2013-10-31 11:00:34 -0600921 tsobj = show_thread_status(&p->ts, &p->rs);
Jens Axboe108fea72012-11-14 13:09:45 -0700922 client->did_stat = 1;
Castor Fu952b05e2013-10-31 11:00:34 -0600923 if (tsobj) {
924 json_object_add_client_info(tsobj, client);
925 json_array_add_value_object(clients_array, tsobj);
926 }
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200927
Jens Axboebfa8f5d2014-10-13 10:09:28 -0600928 if (sum_stat_clients <= 1)
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200929 return;
930
931 sum_thread_stats(&client_ts, &p->ts, sum_stat_nr);
932 sum_group_stats(&client_gs, &p->rs);
933
934 client_ts.members++;
Jens Axboe2f122b12012-03-15 13:10:19 +0100935 client_ts.thread_number = p->ts.thread_number;
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200936 client_ts.groupid = p->ts.groupid;
Jens Axboe771e58b2013-01-30 12:56:23 +0100937 client_ts.unified_rw_rep = p->ts.unified_rw_rep;
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200938
939 if (++sum_stat_nr == sum_stat_clients) {
940 strcpy(client_ts.name, "All clients");
Castor Fu952b05e2013-10-31 11:00:34 -0600941 tsobj = show_thread_status(&client_ts, &client_gs);
942 if (tsobj) {
943 json_object_add_client_info(tsobj, client);
944 json_array_add_value_object(clients_array, tsobj);
945 }
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200946 }
Jens Axboea64e88d2011-10-03 14:20:01 +0200947}
948
Jens Axboe89e5fad2012-03-05 09:21:12 +0100949static void handle_gs(struct fio_client *client, struct fio_net_cmd *cmd)
Jens Axboea64e88d2011-10-03 14:20:01 +0200950{
951 struct group_run_stats *gs = (struct group_run_stats *) cmd->payload;
952
Jens Axboea64e88d2011-10-03 14:20:01 +0200953 show_group_stats(gs);
954}
955
Jens Axboe3bf236c2012-03-03 20:35:50 +0100956static void handle_text(struct fio_client *client, struct fio_net_cmd *cmd)
957{
958 struct cmd_text_pdu *pdu = (struct cmd_text_pdu *) cmd->payload;
959 const char *buf = (const char *) pdu->buf;
960 const char *name;
961 int fio_unused ret;
962
963 name = client->name ? client->name : client->hostname;
964
965 if (!client->skip_newline)
966 fprintf(f_out, "<%s> ", name);
967 ret = fwrite(buf, pdu->buf_len, 1, f_out);
968 fflush(f_out);
969 client->skip_newline = strchr(buf, '\n') == NULL;
970}
971
Jens Axboed09a64a2011-10-13 11:38:56 +0200972static void convert_agg(struct disk_util_agg *agg)
973{
974 int i;
975
976 for (i = 0; i < 2; i++) {
Jens Axboe2a3bf762014-12-01 09:42:48 -0700977 agg->ios[i] = le64_to_cpu(agg->ios[i]);
978 agg->merges[i] = le64_to_cpu(agg->merges[i]);
Jens Axboed09a64a2011-10-13 11:38:56 +0200979 agg->sectors[i] = le64_to_cpu(agg->sectors[i]);
Jens Axboe2a3bf762014-12-01 09:42:48 -0700980 agg->ticks[i] = le64_to_cpu(agg->ticks[i]);
Jens Axboed09a64a2011-10-13 11:38:56 +0200981 }
982
Jens Axboe2a3bf762014-12-01 09:42:48 -0700983 agg->io_ticks = le64_to_cpu(agg->io_ticks);
984 agg->time_in_queue = le64_to_cpu(agg->time_in_queue);
Jens Axboed09a64a2011-10-13 11:38:56 +0200985 agg->slavecount = le32_to_cpu(agg->slavecount);
Jens Axboe2b827fa2014-10-13 16:05:10 -0600986 agg->max_util.u.f = fio_uint64_to_double(le64_to_cpu(agg->max_util.u.i));
Jens Axboed09a64a2011-10-13 11:38:56 +0200987}
988
989static void convert_dus(struct disk_util_stat *dus)
990{
991 int i;
992
993 for (i = 0; i < 2; i++) {
Jens Axboe2a3bf762014-12-01 09:42:48 -0700994 dus->s.ios[i] = le64_to_cpu(dus->s.ios[i]);
995 dus->s.merges[i] = le64_to_cpu(dus->s.merges[i]);
Jens Axboea3b4cf72014-04-11 12:17:53 -0600996 dus->s.sectors[i] = le64_to_cpu(dus->s.sectors[i]);
Jens Axboe2a3bf762014-12-01 09:42:48 -0700997 dus->s.ticks[i] = le64_to_cpu(dus->s.ticks[i]);
Jens Axboed09a64a2011-10-13 11:38:56 +0200998 }
999
Jens Axboe2a3bf762014-12-01 09:42:48 -07001000 dus->s.io_ticks = le64_to_cpu(dus->s.io_ticks);
1001 dus->s.time_in_queue = le64_to_cpu(dus->s.time_in_queue);
Jens Axboea3b4cf72014-04-11 12:17:53 -06001002 dus->s.msec = le64_to_cpu(dus->s.msec);
Jens Axboed09a64a2011-10-13 11:38:56 +02001003}
1004
1005static void handle_du(struct fio_client *client, struct fio_net_cmd *cmd)
1006{
1007 struct cmd_du_pdu *du = (struct cmd_du_pdu *) cmd->payload;
1008
Jens Axboed09a64a2011-10-13 11:38:56 +02001009 if (!client->disk_stats_shown) {
1010 client->disk_stats_shown = 1;
1011 log_info("\nDisk stats (read/write):\n");
1012 }
1013
Castor Fu952b05e2013-10-31 11:00:34 -06001014 if (output_format == FIO_OUTPUT_JSON) {
1015 struct json_object *duobj;
1016 json_array_add_disk_util(&du->dus, &du->agg, du_array);
1017 duobj = json_array_last_value_object(du_array);
1018 json_object_add_client_info(duobj, client);
1019 } else
1020 print_disk_util(&du->dus, &du->agg, output_format == FIO_OUTPUT_TERSE);
Jens Axboed09a64a2011-10-13 11:38:56 +02001021}
1022
Jens Axboe3bf236c2012-03-03 20:35:50 +01001023static void convert_jobs_eta(struct jobs_eta *je)
Jens Axboecf451d12011-10-03 16:48:30 +02001024{
Jens Axboecf451d12011-10-03 16:48:30 +02001025 int i;
1026
1027 je->nr_running = le32_to_cpu(je->nr_running);
1028 je->nr_ramp = le32_to_cpu(je->nr_ramp);
1029 je->nr_pending = le32_to_cpu(je->nr_pending);
Jens Axboe714e85f2013-04-15 10:21:56 +02001030 je->nr_setting_up = le32_to_cpu(je->nr_setting_up);
Jens Axboecf451d12011-10-03 16:48:30 +02001031 je->files_open = le32_to_cpu(je->files_open);
Jens Axboecf451d12011-10-03 16:48:30 +02001032
Jens Axboe298921d2012-09-24 18:47:01 +02001033 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
1034 je->m_rate[i] = le32_to_cpu(je->m_rate[i]);
1035 je->t_rate[i] = le32_to_cpu(je->t_rate[i]);
1036 je->m_iops[i] = le32_to_cpu(je->m_iops[i]);
1037 je->t_iops[i] = le32_to_cpu(je->t_iops[i]);
Jens Axboe16725bb2013-04-11 12:43:05 +02001038 je->rate[i] = le32_to_cpu(je->rate[i]);
1039 je->iops[i] = le32_to_cpu(je->iops[i]);
Jens Axboecf451d12011-10-03 16:48:30 +02001040 }
1041
Jens Axboeb51eedb2011-10-09 12:13:39 +02001042 je->elapsed_sec = le64_to_cpu(je->elapsed_sec);
Jens Axboecf451d12011-10-03 16:48:30 +02001043 je->eta_sec = le64_to_cpu(je->eta_sec);
Jens Axboe8c621fb2012-03-08 12:30:48 +01001044 je->nr_threads = le32_to_cpu(je->nr_threads);
Jens Axboeb7f05eb2012-05-11 20:33:02 +02001045 je->is_pow2 = le32_to_cpu(je->is_pow2);
Jens Axboeed2c0a12013-04-11 12:55:16 +02001046 je->unit_base = le32_to_cpu(je->unit_base);
Jens Axboe48fbb462011-10-09 12:19:08 +02001047}
Jens Axboecf451d12011-10-03 16:48:30 +02001048
Jens Axboe3e47bd22012-02-29 13:45:02 +01001049void fio_client_sum_jobs_eta(struct jobs_eta *dst, struct jobs_eta *je)
Jens Axboe48fbb462011-10-09 12:19:08 +02001050{
Jens Axboe48fbb462011-10-09 12:19:08 +02001051 int i;
1052
1053 dst->nr_running += je->nr_running;
1054 dst->nr_ramp += je->nr_ramp;
1055 dst->nr_pending += je->nr_pending;
Jens Axboe714e85f2013-04-15 10:21:56 +02001056 dst->nr_setting_up += je->nr_setting_up;
Jens Axboe48fbb462011-10-09 12:19:08 +02001057 dst->files_open += je->files_open;
Jens Axboe48fbb462011-10-09 12:19:08 +02001058
Jens Axboe298921d2012-09-24 18:47:01 +02001059 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
Jens Axboe3e47bd22012-02-29 13:45:02 +01001060 dst->m_rate[i] += je->m_rate[i];
1061 dst->t_rate[i] += je->t_rate[i];
1062 dst->m_iops[i] += je->m_iops[i];
1063 dst->t_iops[i] += je->t_iops[i];
Jens Axboe16725bb2013-04-11 12:43:05 +02001064 dst->rate[i] += je->rate[i];
1065 dst->iops[i] += je->iops[i];
Jens Axboe48fbb462011-10-09 12:19:08 +02001066 }
1067
1068 dst->elapsed_sec += je->elapsed_sec;
1069
1070 if (je->eta_sec > dst->eta_sec)
1071 dst->eta_sec = je->eta_sec;
Jens Axboe8c621fb2012-03-08 12:30:48 +01001072
1073 dst->nr_threads += je->nr_threads;
Jens Axboe27b91552014-06-27 15:30:06 -06001074
1075 /*
1076 * This wont be correct for multiple strings, but at least it
1077 * works for the basic cases.
1078 */
1079 strcpy((char *) dst->run_str, (char *) je->run_str);
Jens Axboe48fbb462011-10-09 12:19:08 +02001080}
1081
Jens Axboea5276612012-03-04 15:15:08 +01001082void fio_client_dec_jobs_eta(struct client_eta *eta, client_eta_op eta_fn)
Jens Axboe82c1ed32011-10-10 08:56:18 +02001083{
1084 if (!--eta->pending) {
Jens Axboea5276612012-03-04 15:15:08 +01001085 eta_fn(&eta->eta);
Jens Axboe82c1ed32011-10-10 08:56:18 +02001086 free(eta);
1087 }
1088}
1089
Jens Axboe89c17072011-10-11 10:15:51 +02001090static void remove_reply_cmd(struct fio_client *client, struct fio_net_cmd *cmd)
1091{
Jens Axboe40c60512012-03-27 16:03:04 +02001092 struct fio_net_cmd_reply *reply = NULL;
Jens Axboe89c17072011-10-11 10:15:51 +02001093 struct flist_head *entry;
1094
1095 flist_for_each(entry, &client->cmd_list) {
Jens Axboe40c60512012-03-27 16:03:04 +02001096 reply = flist_entry(entry, struct fio_net_cmd_reply, list);
Jens Axboe89c17072011-10-11 10:15:51 +02001097
Jens Axboe40c60512012-03-27 16:03:04 +02001098 if (cmd->tag == (uintptr_t) reply)
Jens Axboe89c17072011-10-11 10:15:51 +02001099 break;
1100
Jens Axboe40c60512012-03-27 16:03:04 +02001101 reply = NULL;
Jens Axboe89c17072011-10-11 10:15:51 +02001102 }
1103
Jens Axboe40c60512012-03-27 16:03:04 +02001104 if (!reply) {
Jens Axboe4e0a8fa2013-04-15 11:40:57 +02001105 log_err("fio: client: unable to find matching tag (%llx)\n", (unsigned long long) cmd->tag);
Jens Axboe89c17072011-10-11 10:15:51 +02001106 return;
1107 }
1108
Jens Axboe40c60512012-03-27 16:03:04 +02001109 flist_del(&reply->list);
1110 cmd->tag = reply->saved_tag;
1111 free(reply);
1112}
1113
1114int fio_client_wait_for_reply(struct fio_client *client, uint64_t tag)
1115{
1116 do {
1117 struct fio_net_cmd_reply *reply = NULL;
1118 struct flist_head *entry;
1119
1120 flist_for_each(entry, &client->cmd_list) {
1121 reply = flist_entry(entry, struct fio_net_cmd_reply, list);
1122
1123 if (tag == (uintptr_t) reply)
1124 break;
1125
1126 reply = NULL;
1127 }
1128
1129 if (!reply)
1130 break;
1131
1132 usleep(1000);
1133 } while (1);
1134
1135 return 0;
Jens Axboe89c17072011-10-11 10:15:51 +02001136}
1137
Jens Axboe82c1ed32011-10-10 08:56:18 +02001138static void handle_eta(struct fio_client *client, struct fio_net_cmd *cmd)
Jens Axboe48fbb462011-10-09 12:19:08 +02001139{
1140 struct jobs_eta *je = (struct jobs_eta *) cmd->payload;
Jens Axboedf380932011-10-11 14:25:08 +02001141 struct client_eta *eta = (struct client_eta *) (uintptr_t) cmd->tag;
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001142
1143 dprint(FD_NET, "client: got eta tag %p, %d\n", eta, eta->pending);
Jens Axboe48fbb462011-10-09 12:19:08 +02001144
Jens Axboef77d2672011-10-10 14:36:07 +02001145 assert(client->eta_in_flight == eta);
1146
1147 client->eta_in_flight = NULL;
Jens Axboe82c1ed32011-10-10 08:56:18 +02001148 flist_del_init(&client->eta_list);
1149
Jens Axboe2f99deb2012-03-09 14:37:29 +01001150 if (client->ops->jobs_eta)
1151 client->ops->jobs_eta(client, je);
1152
Jens Axboe3e47bd22012-02-29 13:45:02 +01001153 fio_client_sum_jobs_eta(&eta->eta, je);
Jens Axboea5276612012-03-04 15:15:08 +01001154 fio_client_dec_jobs_eta(eta, client->ops->eta);
Jens Axboecf451d12011-10-03 16:48:30 +02001155}
1156
Jens Axboeb5296dd2011-10-07 16:35:56 +02001157static void handle_probe(struct fio_client *client, struct fio_net_cmd *cmd)
Jens Axboe2e03b4b2011-10-04 09:00:40 +02001158{
Jens Axboe3989b142013-04-12 13:13:24 +02001159 struct cmd_probe_reply_pdu *probe = (struct cmd_probe_reply_pdu *) cmd->payload;
Jens Axboed2333352011-10-11 15:07:23 +02001160 const char *os, *arch;
1161 char bit[16];
Jens Axboe2e03b4b2011-10-04 09:00:40 +02001162
Jens Axboecca84642011-10-07 12:47:57 +02001163 os = fio_get_os_string(probe->os);
1164 if (!os)
1165 os = "unknown";
1166
1167 arch = fio_get_arch_string(probe->arch);
1168 if (!arch)
1169 os = "unknown";
1170
Jens Axboed2333352011-10-11 15:07:23 +02001171 sprintf(bit, "%d-bit", probe->bpp * 8);
Jens Axboe3989b142013-04-12 13:13:24 +02001172 probe->flags = le64_to_cpu(probe->flags);
Jens Axboe38fdef22011-10-11 14:30:06 +02001173
Jens Axboe3989b142013-04-12 13:13:24 +02001174 log_info("hostname=%s, be=%u, %s, os=%s, arch=%s, fio=%s, flags=%lx\n",
Jens Axboe38fdef22011-10-11 14:30:06 +02001175 probe->hostname, probe->bigendian, bit, os, arch,
Jens Axboe3989b142013-04-12 13:13:24 +02001176 probe->fio_version, (unsigned long) probe->flags);
Jens Axboeb5296dd2011-10-07 16:35:56 +02001177
1178 if (!client->name)
1179 client->name = strdup((char *) probe->hostname);
Jens Axboe2e03b4b2011-10-04 09:00:40 +02001180}
1181
Jens Axboe11e950b2011-10-16 21:34:14 +02001182static void handle_start(struct fio_client *client, struct fio_net_cmd *cmd)
1183{
1184 struct cmd_start_pdu *pdu = (struct cmd_start_pdu *) cmd->payload;
1185
1186 client->state = Client_started;
1187 client->jobs = le32_to_cpu(pdu->jobs);
Jens Axboe30f8e312014-10-13 11:33:27 -06001188 client->nr_stat = le32_to_cpu(pdu->stat_outputs);
Jens Axboe108fea72012-11-14 13:09:45 -07001189
Jens Axboe30f8e312014-10-13 11:33:27 -06001190 sum_stat_clients += client->nr_stat;
Jens Axboe11e950b2011-10-16 21:34:14 +02001191}
1192
1193static void handle_stop(struct fio_client *client, struct fio_net_cmd *cmd)
1194{
Jens Axboe498c92c2011-10-17 09:14:42 +02001195 if (client->error)
1196 log_info("client <%s>: exited with error %d\n", client->hostname, client->error);
Jens Axboe11e950b2011-10-16 21:34:14 +02001197}
1198
Jens Axboe6b79c802012-03-08 10:51:36 +01001199static void convert_stop(struct fio_net_cmd *cmd)
1200{
1201 struct cmd_end_pdu *pdu = (struct cmd_end_pdu *) cmd->payload;
1202
1203 pdu->error = le32_to_cpu(pdu->error);
1204}
1205
Jens Axboe084d1c62012-03-03 20:28:07 +01001206static void convert_text(struct fio_net_cmd *cmd)
1207{
1208 struct cmd_text_pdu *pdu = (struct cmd_text_pdu *) cmd->payload;
1209
1210 pdu->level = le32_to_cpu(pdu->level);
1211 pdu->buf_len = le32_to_cpu(pdu->buf_len);
1212 pdu->log_sec = le64_to_cpu(pdu->log_sec);
1213 pdu->log_usec = le64_to_cpu(pdu->log_usec);
1214}
1215
Jens Axboe3989b142013-04-12 13:13:24 +02001216static struct cmd_iolog_pdu *convert_iolog_gz(struct fio_net_cmd *cmd,
1217 struct cmd_iolog_pdu *pdu)
Jens Axboe1b427252012-03-14 15:03:03 +01001218{
Jens Axboe3989b142013-04-12 13:13:24 +02001219#ifdef CONFIG_ZLIB
Jens Axboe1b427252012-03-14 15:03:03 +01001220 struct cmd_iolog_pdu *ret;
Jens Axboe1b427252012-03-14 15:03:03 +01001221 z_stream stream;
Jens Axboe3989b142013-04-12 13:13:24 +02001222 uint32_t nr_samples;
1223 size_t total;
Jens Axboe1b427252012-03-14 15:03:03 +01001224 void *p;
1225
1226 stream.zalloc = Z_NULL;
1227 stream.zfree = Z_NULL;
1228 stream.opaque = Z_NULL;
1229 stream.avail_in = 0;
1230 stream.next_in = Z_NULL;
1231
1232 if (inflateInit(&stream) != Z_OK)
1233 return NULL;
1234
1235 /*
Jens Axboef5ed7652012-03-14 16:28:07 +01001236 * Get header first, it's not compressed
Jens Axboe1b427252012-03-14 15:03:03 +01001237 */
Jens Axboef2b9a672014-07-01 08:47:11 -06001238 nr_samples = le64_to_cpu(pdu->nr_samples);
Jens Axboe1b427252012-03-14 15:03:03 +01001239
Jens Axboef2b9a672014-07-01 08:47:11 -06001240 total = nr_samples * __log_entry_sz(le32_to_cpu(pdu->log_offset));
Jens Axboef5ed7652012-03-14 16:28:07 +01001241 ret = malloc(total + sizeof(*pdu));
Jens Axboe1b427252012-03-14 15:03:03 +01001242 ret->nr_samples = nr_samples;
Jens Axboe3989b142013-04-12 13:13:24 +02001243
1244 memcpy(ret, pdu, sizeof(*pdu));
Jens Axboe1b427252012-03-14 15:03:03 +01001245
Jens Axboef5ed7652012-03-14 16:28:07 +01001246 p = (void *) ret + sizeof(*pdu);
1247
1248 stream.avail_in = cmd->pdu_len - sizeof(*pdu);
1249 stream.next_in = (void *) pdu + sizeof(*pdu);
Jens Axboe1b427252012-03-14 15:03:03 +01001250 while (stream.avail_in) {
1251 unsigned int this_chunk = 65536;
1252 unsigned int this_len;
1253 int err;
1254
1255 if (this_chunk > total)
1256 this_chunk = total;
1257
1258 stream.avail_out = this_chunk;
1259 stream.next_out = p;
1260 err = inflate(&stream, Z_NO_FLUSH);
Jens Axboe3c547fe2012-03-14 21:53:00 +01001261 /* may be Z_OK, or Z_STREAM_END */
1262 if (err < 0) {
Jens Axboe1b427252012-03-14 15:03:03 +01001263 log_err("fio: inflate error %d\n", err);
Jens Axboef5ed7652012-03-14 16:28:07 +01001264 free(ret);
1265 ret = NULL;
Jens Axboe3989b142013-04-12 13:13:24 +02001266 goto err;
Jens Axboe1b427252012-03-14 15:03:03 +01001267 }
1268
1269 this_len = this_chunk - stream.avail_out;
1270 p += this_len;
1271 total -= this_len;
1272 }
1273
Jens Axboe3989b142013-04-12 13:13:24 +02001274err:
1275 inflateEnd(&stream);
1276 return ret;
1277#else
1278 return NULL;
1279#endif
1280}
1281
1282/*
1283 * This has been compressed on the server side, since it can be big.
1284 * Uncompress here.
1285 */
1286static struct cmd_iolog_pdu *convert_iolog(struct fio_net_cmd *cmd)
1287{
1288 struct cmd_iolog_pdu *pdu = (struct cmd_iolog_pdu *) cmd->payload;
1289 struct cmd_iolog_pdu *ret;
Jens Axboeccefd5f2014-06-30 20:59:03 -06001290 uint64_t i;
1291 void *samples;
Jens Axboe3989b142013-04-12 13:13:24 +02001292
1293 /*
1294 * Convert if compressed and we support it. If it's not
1295 * compressed, we need not do anything.
1296 */
1297 if (le32_to_cpu(pdu->compressed)) {
1298#ifndef CONFIG_ZLIB
1299 log_err("fio: server sent compressed data by mistake\n");
1300 return NULL;
1301#endif
1302 ret = convert_iolog_gz(cmd, pdu);
1303 if (!ret) {
1304 log_err("fio: failed decompressing log\n");
1305 return NULL;
1306 }
1307 } else
1308 ret = pdu;
1309
Jens Axboeccefd5f2014-06-30 20:59:03 -06001310 ret->nr_samples = le64_to_cpu(ret->nr_samples);
Jens Axboe3989b142013-04-12 13:13:24 +02001311 ret->thread_number = le32_to_cpu(ret->thread_number);
Jens Axboe3989b142013-04-12 13:13:24 +02001312 ret->log_type = le32_to_cpu(ret->log_type);
1313 ret->compressed = le32_to_cpu(ret->compressed);
Jens Axboeccefd5f2014-06-30 20:59:03 -06001314 ret->log_offset = le32_to_cpu(ret->log_offset);
Jens Axboe3989b142013-04-12 13:13:24 +02001315
Jens Axboee8c4fb02014-07-01 16:07:59 -06001316 samples = &ret->samples[0];
Jens Axboef5ed7652012-03-14 16:28:07 +01001317 for (i = 0; i < ret->nr_samples; i++) {
Jens Axboeccefd5f2014-06-30 20:59:03 -06001318 struct io_sample *s;
Jens Axboef5ed7652012-03-14 16:28:07 +01001319
Jens Axboeccefd5f2014-06-30 20:59:03 -06001320 s = __get_sample(samples, ret->log_offset, i);
Jens Axboebac4af12014-07-03 13:42:28 -06001321 s->time = le64_to_cpu(s->time);
1322 s->val = le64_to_cpu(s->val);
1323 s->__ddir = le32_to_cpu(s->__ddir);
1324 s->bs = le32_to_cpu(s->bs);
Jens Axboeccefd5f2014-06-30 20:59:03 -06001325
1326 if (ret->log_offset) {
1327 struct io_sample_offset *so = (void *) s;
1328
1329 so->offset = le64_to_cpu(so->offset);
1330 }
Jens Axboef5ed7652012-03-14 16:28:07 +01001331 }
1332
Jens Axboe1b427252012-03-14 15:03:03 +01001333 return ret;
1334}
1335
Jens Axboede54cfd2014-11-10 20:34:00 -07001336static void sendfile_reply(int fd, struct cmd_sendfile_reply *rep,
1337 size_t size, uint64_t tag)
1338{
1339 rep->error = cpu_to_le32(rep->error);
1340 fio_net_send_cmd(fd, FIO_NET_CMD_SENDFILE, rep, size, &tag, NULL);
1341}
1342
Jens Axboede54cfd2014-11-10 20:34:00 -07001343static int send_file(struct fio_client *client, struct cmd_sendfile *pdu,
1344 uint64_t tag)
1345{
1346 struct cmd_sendfile_reply *rep;
1347 struct stat sb;
1348 size_t size;
1349 int fd;
1350
1351 size = sizeof(*rep);
1352 rep = malloc(size);
1353
1354 if (stat((char *)pdu->path, &sb) < 0) {
1355fail:
1356 rep->error = errno;
1357 sendfile_reply(client->fd, rep, size, tag);
1358 free(rep);
1359 return 1;
1360 }
1361
1362 size += sb.st_size;
1363 rep = realloc(rep, size);
1364 rep->size = cpu_to_le32((uint32_t) sb.st_size);
1365
1366 fd = open((char *)pdu->path, O_RDONLY);
1367 if (fd == -1 )
1368 goto fail;
1369
1370 rep->error = read_data(fd, &rep->data, sb.st_size);
1371 sendfile_reply(client->fd, rep, size, tag);
1372 free(rep);
1373 close(fd);
1374 return 0;
1375}
1376
Jens Axboea5276612012-03-04 15:15:08 +01001377int fio_handle_client(struct fio_client *client)
Jens Axboe37db14f2011-09-30 17:00:42 -06001378{
Jens Axboea5276612012-03-04 15:15:08 +01001379 struct client_ops *ops = client->ops;
Jens Axboe37db14f2011-09-30 17:00:42 -06001380 struct fio_net_cmd *cmd;
1381
Jens Axboe60efd142011-10-04 13:30:11 +02001382 dprint(FD_NET, "client: handle %s\n", client->hostname);
1383
Jens Axboee951bdc2011-10-05 21:58:45 +02001384 cmd = fio_net_recv_cmd(client->fd);
1385 if (!cmd)
1386 return 0;
Jens Axboec2c94582011-10-05 20:31:30 +02001387
Jens Axboeb9d2f302012-03-08 20:36:28 +01001388 dprint(FD_NET, "client: got cmd op %s from %s (pdu=%u)\n",
1389 fio_server_op(cmd->opcode), client->hostname, cmd->pdu_len);
Jens Axboe46c48f12011-10-01 12:50:51 -06001390
Jens Axboee951bdc2011-10-05 21:58:45 +02001391 switch (cmd->opcode) {
1392 case FIO_NET_CMD_QUIT:
Jens Axboe3ec62ec2012-03-01 12:01:29 +01001393 if (ops->quit)
Jens Axboe35c0ba72012-03-14 10:56:40 +01001394 ops->quit(client, cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001395 remove_client(client);
Jens Axboee951bdc2011-10-05 21:58:45 +02001396 break;
Jens Axboe084d1c62012-03-03 20:28:07 +01001397 case FIO_NET_CMD_TEXT:
1398 convert_text(cmd);
Jens Axboe35c0ba72012-03-14 10:56:40 +01001399 ops->text(client, cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001400 break;
Jens Axboe3bf236c2012-03-03 20:35:50 +01001401 case FIO_NET_CMD_DU: {
1402 struct cmd_du_pdu *du = (struct cmd_du_pdu *) cmd->payload;
1403
1404 convert_dus(&du->dus);
1405 convert_agg(&du->agg);
1406
Stephen M. Camerondd366722012-02-24 08:17:30 +01001407 ops->disk_util(client, cmd);
Jens Axboed09a64a2011-10-13 11:38:56 +02001408 break;
Jens Axboe3bf236c2012-03-03 20:35:50 +01001409 }
1410 case FIO_NET_CMD_TS: {
1411 struct cmd_ts_pdu *p = (struct cmd_ts_pdu *) cmd->payload;
1412
1413 convert_ts(&p->ts, &p->ts);
1414 convert_gs(&p->rs, &p->rs);
1415
Jens Axboe89e5fad2012-03-05 09:21:12 +01001416 ops->thread_status(client, cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001417 break;
Jens Axboe3bf236c2012-03-03 20:35:50 +01001418 }
1419 case FIO_NET_CMD_GS: {
1420 struct group_run_stats *gs = (struct group_run_stats *) cmd->payload;
1421
1422 convert_gs(gs, gs);
1423
Jens Axboe89e5fad2012-03-05 09:21:12 +01001424 ops->group_stats(client, cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001425 break;
Jens Axboe3bf236c2012-03-03 20:35:50 +01001426 }
1427 case FIO_NET_CMD_ETA: {
1428 struct jobs_eta *je = (struct jobs_eta *) cmd->payload;
1429
Jens Axboe89c17072011-10-11 10:15:51 +02001430 remove_reply_cmd(client, cmd);
Jens Axboe3bf236c2012-03-03 20:35:50 +01001431 convert_jobs_eta(je);
Jens Axboea5276612012-03-04 15:15:08 +01001432 handle_eta(client, cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001433 break;
Jens Axboe3bf236c2012-03-03 20:35:50 +01001434 }
Jens Axboee951bdc2011-10-05 21:58:45 +02001435 case FIO_NET_CMD_PROBE:
Jens Axboe89c17072011-10-11 10:15:51 +02001436 remove_reply_cmd(client, cmd);
Stephen M. Camerondd366722012-02-24 08:17:30 +01001437 ops->probe(client, cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001438 break;
Jens Axboe5d7793a2012-03-08 19:59:16 +01001439 case FIO_NET_CMD_SERVER_START:
Jens Axboe01be0382011-10-15 14:43:41 +02001440 client->state = Client_running;
Jens Axboe85dd01e2012-03-12 14:33:16 +01001441 if (ops->job_start)
1442 ops->job_start(client, cmd);
Jens Axboe01be0382011-10-15 14:43:41 +02001443 break;
Jens Axboe85dd01e2012-03-12 14:33:16 +01001444 case FIO_NET_CMD_START: {
1445 struct cmd_start_pdu *pdu = (struct cmd_start_pdu *) cmd->payload;
1446
1447 pdu->jobs = le32_to_cpu(pdu->jobs);
1448 ops->start(client, cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001449 break;
Jens Axboe85dd01e2012-03-12 14:33:16 +01001450 }
Jens Axboe6b79c802012-03-08 10:51:36 +01001451 case FIO_NET_CMD_STOP: {
1452 struct cmd_end_pdu *pdu = (struct cmd_end_pdu *) cmd->payload;
1453
1454 convert_stop(cmd);
1455 client->state = Client_stopped;
Jens Axboe122c7722012-03-19 09:13:15 +01001456 client->error = le32_to_cpu(pdu->error);
1457 client->signal = le32_to_cpu(pdu->signal);
Jens Axboe6b79c802012-03-08 10:51:36 +01001458 ops->stop(client, cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001459 break;
Jens Axboe6b79c802012-03-08 10:51:36 +01001460 }
Jens Axboe40c60512012-03-27 16:03:04 +02001461 case FIO_NET_CMD_ADD_JOB: {
1462 struct cmd_add_job_pdu *pdu = (struct cmd_add_job_pdu *) cmd->payload;
1463
1464 client->thread_number = le32_to_cpu(pdu->thread_number);
1465 client->groupid = le32_to_cpu(pdu->groupid);
1466
Jens Axboe807f9972012-03-02 10:25:24 +01001467 if (ops->add_job)
1468 ops->add_job(client, cmd);
Jens Axboe807f9972012-03-02 10:25:24 +01001469 break;
Jens Axboe40c60512012-03-27 16:03:04 +02001470 }
Jens Axboe1b427252012-03-14 15:03:03 +01001471 case FIO_NET_CMD_IOLOG:
1472 if (ops->iolog) {
1473 struct cmd_iolog_pdu *pdu;
1474
1475 pdu = convert_iolog(cmd);
1476 ops->iolog(client, pdu);
1477 }
Jens Axboe1b427252012-03-14 15:03:03 +01001478 break;
Jens Axboe40c60512012-03-27 16:03:04 +02001479 case FIO_NET_CMD_UPDATE_JOB:
Jens Axboe40c60512012-03-27 16:03:04 +02001480 ops->update_job(client, cmd);
Jens Axboe649cee92012-03-28 09:15:32 +02001481 remove_reply_cmd(client, cmd);
Jens Axboe40c60512012-03-27 16:03:04 +02001482 break;
Jens Axboede54cfd2014-11-10 20:34:00 -07001483 case FIO_NET_CMD_VTRIGGER: {
1484 struct all_io_list *pdu = (struct all_io_list *) cmd->payload;
1485 char buf[64];
1486
1487 __verify_save_state(pdu, server_name(client, buf, sizeof(buf)));
Jens Axboe7eebf502014-11-19 09:09:01 -07001488 exec_trigger(trigger_cmd);
Jens Axboede54cfd2014-11-10 20:34:00 -07001489 break;
1490 }
1491 case FIO_NET_CMD_SENDFILE: {
1492 struct cmd_sendfile *pdu = (struct cmd_sendfile *) cmd->payload;
1493 send_file(client, pdu, cmd->tag);
1494 break;
1495 }
Jens Axboee951bdc2011-10-05 21:58:45 +02001496 default:
Jens Axboe89c17072011-10-11 10:15:51 +02001497 log_err("fio: unknown client op: %s\n", fio_server_op(cmd->opcode));
Jens Axboee951bdc2011-10-05 21:58:45 +02001498 break;
Jens Axboe37db14f2011-09-30 17:00:42 -06001499 }
1500
Jens Axboede54cfd2014-11-10 20:34:00 -07001501 free(cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001502 return 1;
Jens Axboe37db14f2011-09-30 17:00:42 -06001503}
Jens Axboeb66570d2011-10-01 11:11:35 -06001504
Jens Axboede54cfd2014-11-10 20:34:00 -07001505int fio_clients_send_trigger(const char *cmd)
1506{
1507 struct flist_head *entry;
1508 struct fio_client *client;
1509 size_t slen;
1510
1511 dprint(FD_NET, "client: send vtrigger: %s\n", cmd);
1512
1513 if (!cmd)
1514 slen = 0;
1515 else
1516 slen = strlen(cmd);
1517
1518 flist_for_each(entry, &client_list) {
1519 struct cmd_vtrigger_pdu *pdu;
1520
1521 client = flist_entry(entry, struct fio_client, list);
1522
1523 pdu = malloc(sizeof(*pdu) + slen);
1524 pdu->len = cpu_to_le16((uint16_t) slen);
1525 if (slen)
1526 memcpy(pdu->cmd, cmd, slen);
1527 fio_net_send_cmd(client->fd, FIO_NET_CMD_VTRIGGER, pdu,
1528 sizeof(*pdu) + slen, NULL, NULL);
1529 free(pdu);
1530 }
1531
1532 return 0;
1533}
1534
Jens Axboea5276612012-03-04 15:15:08 +01001535static void request_client_etas(struct client_ops *ops)
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001536{
1537 struct fio_client *client;
1538 struct flist_head *entry;
1539 struct client_eta *eta;
Jens Axboe82c1ed32011-10-10 08:56:18 +02001540 int skipped = 0;
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001541
1542 dprint(FD_NET, "client: request eta (%d)\n", nr_clients);
1543
Jens Axboe27b91552014-06-27 15:30:06 -06001544 eta = calloc(1, sizeof(*eta) + __THREAD_RUNSTR_SZ(REAL_MAX_JOBS));
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001545 eta->pending = nr_clients;
1546
1547 flist_for_each(entry, &client_list) {
1548 client = flist_entry(entry, struct fio_client, list);
1549
Jens Axboe82c1ed32011-10-10 08:56:18 +02001550 if (!flist_empty(&client->eta_list)) {
1551 skipped++;
1552 continue;
1553 }
Jens Axboe01be0382011-10-15 14:43:41 +02001554 if (client->state != Client_running)
1555 continue;
Jens Axboe82c1ed32011-10-10 08:56:18 +02001556
Jens Axboef77d2672011-10-10 14:36:07 +02001557 assert(!client->eta_in_flight);
Jens Axboe82c1ed32011-10-10 08:56:18 +02001558 flist_add_tail(&client->eta_list, &eta_list);
Jens Axboef77d2672011-10-10 14:36:07 +02001559 client->eta_in_flight = eta;
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001560 fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_SEND_ETA,
Jens Axboedf380932011-10-11 14:25:08 +02001561 (uintptr_t) eta, &client->cmd_list);
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001562 }
1563
Jens Axboe82c1ed32011-10-10 08:56:18 +02001564 while (skipped--)
Jens Axboea5276612012-03-04 15:15:08 +01001565 fio_client_dec_jobs_eta(eta, ops->eta);
Jens Axboe82c1ed32011-10-10 08:56:18 +02001566
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001567 dprint(FD_NET, "client: requested eta tag %p\n", eta);
1568}
1569
Jens Axboe89c17072011-10-11 10:15:51 +02001570static int client_check_cmd_timeout(struct fio_client *client,
1571 struct timeval *now)
1572{
Jens Axboe40c60512012-03-27 16:03:04 +02001573 struct fio_net_cmd_reply *reply;
Jens Axboe89c17072011-10-11 10:15:51 +02001574 struct flist_head *entry, *tmp;
1575 int ret = 0;
1576
1577 flist_for_each_safe(entry, tmp, &client->cmd_list) {
Jens Axboe40c60512012-03-27 16:03:04 +02001578 reply = flist_entry(entry, struct fio_net_cmd_reply, list);
Jens Axboe89c17072011-10-11 10:15:51 +02001579
Jens Axboe40c60512012-03-27 16:03:04 +02001580 if (mtime_since(&reply->tv, now) < FIO_NET_CLIENT_TIMEOUT)
Jens Axboe89c17072011-10-11 10:15:51 +02001581 continue;
1582
1583 log_err("fio: client %s, timeout on cmd %s\n", client->hostname,
Jens Axboe40c60512012-03-27 16:03:04 +02001584 fio_server_op(reply->opcode));
1585 flist_del(&reply->list);
1586 free(reply);
Jens Axboe89c17072011-10-11 10:15:51 +02001587 ret = 1;
1588 }
1589
1590 return flist_empty(&client->cmd_list) && ret;
1591}
1592
Jens Axboea5276612012-03-04 15:15:08 +01001593static int fio_check_clients_timed_out(void)
Jens Axboe89c17072011-10-11 10:15:51 +02001594{
1595 struct fio_client *client;
1596 struct flist_head *entry, *tmp;
1597 struct timeval tv;
1598 int ret = 0;
1599
Jens Axboe67bf9822013-01-10 11:23:19 +01001600 fio_gettime(&tv, NULL);
Jens Axboe89c17072011-10-11 10:15:51 +02001601
1602 flist_for_each_safe(entry, tmp, &client_list) {
1603 client = flist_entry(entry, struct fio_client, list);
1604
1605 if (flist_empty(&client->cmd_list))
1606 continue;
1607
1608 if (!client_check_cmd_timeout(client, &tv))
1609 continue;
1610
Jens Axboea5276612012-03-04 15:15:08 +01001611 if (client->ops->timed_out)
1612 client->ops->timed_out(client);
Jens Axboeed727a42012-03-02 12:14:40 +01001613 else
1614 log_err("fio: client %s timed out\n", client->hostname);
1615
Jens Axboe89c17072011-10-11 10:15:51 +02001616 remove_client(client);
1617 ret = 1;
1618 }
1619
1620 return ret;
1621}
1622
Stephen M. Camerondd366722012-02-24 08:17:30 +01001623int fio_handle_clients(struct client_ops *ops)
Jens Axboeb66570d2011-10-01 11:11:35 -06001624{
Jens Axboeb66570d2011-10-01 11:11:35 -06001625 struct pollfd *pfds;
Jens Axboe498c92c2011-10-17 09:14:42 +02001626 int i, ret = 0, retval = 0;
Jens Axboeb66570d2011-10-01 11:11:35 -06001627
Jens Axboe67bf9822013-01-10 11:23:19 +01001628 fio_gettime(&eta_tv, NULL);
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001629
Jens Axboeb66570d2011-10-01 11:11:35 -06001630 pfds = malloc(nr_clients * sizeof(struct pollfd));
1631
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001632 init_thread_stat(&client_ts);
1633 init_group_run_stat(&client_gs);
1634
Jens Axboeb66570d2011-10-01 11:11:35 -06001635 while (!exit_backend && nr_clients) {
Jens Axboec2cb6862012-02-23 20:56:12 +01001636 struct flist_head *entry, *tmp;
1637 struct fio_client *client;
1638
Jens Axboe82a4be12011-10-01 12:40:32 -06001639 i = 0;
Jens Axboec2cb6862012-02-23 20:56:12 +01001640 flist_for_each_safe(entry, tmp, &client_list) {
Jens Axboe82a4be12011-10-01 12:40:32 -06001641 client = flist_entry(entry, struct fio_client, list);
1642
Jens Axboea5276612012-03-04 15:15:08 +01001643 if (!client->sent_job && !client->ops->stay_connected &&
Jens Axboec2cb6862012-02-23 20:56:12 +01001644 flist_empty(&client->cmd_list)) {
1645 remove_client(client);
1646 continue;
1647 }
1648
Jens Axboe82a4be12011-10-01 12:40:32 -06001649 pfds[i].fd = client->fd;
1650 pfds[i].events = POLLIN;
1651 i++;
1652 }
1653
Jens Axboec2cb6862012-02-23 20:56:12 +01001654 if (!nr_clients)
1655 break;
1656
Jens Axboe82a4be12011-10-01 12:40:32 -06001657 assert(i == nr_clients);
1658
Jens Axboe5c2857f2011-10-04 13:14:32 +02001659 do {
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001660 struct timeval tv;
Jens Axboede54cfd2014-11-10 20:34:00 -07001661 int timeout;
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001662
Jens Axboe67bf9822013-01-10 11:23:19 +01001663 fio_gettime(&tv, NULL);
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001664 if (mtime_since(&eta_tv, &tv) >= 900) {
Jens Axboea5276612012-03-04 15:15:08 +01001665 request_client_etas(ops);
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001666 memcpy(&eta_tv, &tv, sizeof(tv));
Jens Axboe89c17072011-10-11 10:15:51 +02001667
Jens Axboea5276612012-03-04 15:15:08 +01001668 if (fio_check_clients_timed_out())
Jens Axboe89c17072011-10-11 10:15:51 +02001669 break;
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001670 }
1671
Jens Axboede54cfd2014-11-10 20:34:00 -07001672 check_trigger_file();
1673
1674 timeout = min(100u, ops->eta_msec);
1675
1676 ret = poll(pfds, nr_clients, timeout);
Jens Axboe5c2857f2011-10-04 13:14:32 +02001677 if (ret < 0) {
1678 if (errno == EINTR)
1679 continue;
1680 log_err("fio: poll clients: %s\n", strerror(errno));
1681 break;
1682 } else if (!ret)
Jens Axboeb66570d2011-10-01 11:11:35 -06001683 continue;
Jens Axboe5c2857f2011-10-04 13:14:32 +02001684 } while (ret <= 0);
Jens Axboeb66570d2011-10-01 11:11:35 -06001685
1686 for (i = 0; i < nr_clients; i++) {
1687 if (!(pfds[i].revents & POLLIN))
1688 continue;
1689
1690 client = find_client_by_fd(pfds[i].fd);
1691 if (!client) {
Jens Axboe65e1a122013-08-30 10:13:36 -06001692 log_err("fio: unknown client fd %ld\n", (long) pfds[i].fd);
Jens Axboeb66570d2011-10-01 11:11:35 -06001693 continue;
1694 }
Jens Axboea5276612012-03-04 15:15:08 +01001695 if (!fio_handle_client(client)) {
Jens Axboe28d3ab02011-10-05 20:45:37 +02001696 log_info("client: host=%s disconnected\n",
1697 client->hostname);
1698 remove_client(client);
Jens Axboe498c92c2011-10-17 09:14:42 +02001699 retval = 1;
Jens Axboe38990762011-10-17 13:31:33 +02001700 } else if (client->error)
Jens Axboe498c92c2011-10-17 09:14:42 +02001701 retval = 1;
Jens Axboe343cb4a2012-03-09 17:16:51 +01001702 fio_put_client(client);
Jens Axboeb66570d2011-10-01 11:11:35 -06001703 }
1704 }
1705
Castor Fu952b05e2013-10-31 11:00:34 -06001706 fio_client_json_fini();
1707
Jens Axboeb66570d2011-10-01 11:11:35 -06001708 free(pfds);
Jens Axboe498c92c2011-10-17 09:14:42 +02001709 return retval;
Jens Axboeb66570d2011-10-01 11:11:35 -06001710}