blob: 96b844cb6a825433ae55f48e18c7e6d09aa15207 [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
Castor Fu952b05e2013-10-31 11:00:34 -060092static void fio_client_json_init(void)
93{
94 if (output_format != FIO_OUTPUT_JSON)
95 return;
96 root = json_create_object();
97 json_object_add_value_string(root, "fio version", fio_version_string);
98 clients_array = json_create_array();
99 json_object_add_value_array(root, "client_stats", clients_array);
100 du_array = json_create_array();
101 json_object_add_value_array(root, "disk_util", du_array);
102}
103
104static void fio_client_json_fini(void)
105{
106 if (output_format != FIO_OUTPUT_JSON)
107 return;
108 json_print_object(root);
109 log_info("\n");
110 json_free_object(root);
111 root = NULL;
112 clients_array = NULL;
113 du_array = NULL;
114}
115
Jens Axboeb66570d2011-10-01 11:11:35 -0600116static struct fio_client *find_client_by_fd(int fd)
117{
Jens Axboe3c5f57e2011-10-06 12:37:50 +0200118 int bucket = hash_long(fd, FIO_CLIENT_HASH_BITS) & FIO_CLIENT_HASH_MASK;
Jens Axboeb66570d2011-10-01 11:11:35 -0600119 struct fio_client *client;
120 struct flist_head *entry;
121
Jens Axboebebe6392011-10-07 10:00:51 +0200122 flist_for_each(entry, &client_hash[bucket]) {
123 client = flist_entry(entry, struct fio_client, hash_list);
Jens Axboeb66570d2011-10-01 11:11:35 -0600124
Jens Axboee55f8f32012-03-06 15:42:31 +0100125 if (client->fd == fd) {
126 client->refs++;
Jens Axboeb66570d2011-10-01 11:11:35 -0600127 return client;
Jens Axboee55f8f32012-03-06 15:42:31 +0100128 }
Jens Axboeb66570d2011-10-01 11:11:35 -0600129 }
130
131 return NULL;
132}
133
Jens Axboe3af45202012-03-13 09:59:53 +0100134void fio_put_client(struct fio_client *client)
Jens Axboeb66570d2011-10-01 11:11:35 -0600135{
Jens Axboe5121a9a2012-03-05 13:32:47 +0100136 if (--client->refs)
137 return;
138
Jens Axboeb66570d2011-10-01 11:11:35 -0600139 free(client->hostname);
Jens Axboe81179ee2011-10-04 12:42:06 +0200140 if (client->argv)
141 free(client->argv);
Jens Axboeb5296dd2011-10-07 16:35:56 +0200142 if (client->name)
143 free(client->name);
Jens Axboe35899182014-10-07 20:56:28 -0600144 while (client->nr_files) {
145 struct client_file *cf = &client->files[--client->nr_files];
146
147 free(cf->file);
148 }
149 if (client->files)
150 free(client->files);
Jens Axboe81179ee2011-10-04 12:42:06 +0200151
Jens Axboe108fea72012-11-14 13:09:45 -0700152 if (!client->did_stat)
Jens Axboebfa8f5d2014-10-13 10:09:28 -0600153 sum_stat_clients--;
Jens Axboe108fea72012-11-14 13:09:45 -0700154
Jens Axboeb66570d2011-10-01 11:11:35 -0600155 free(client);
156}
Jens Axboe132159a2011-09-30 15:01:32 -0600157
Jens Axboe3af45202012-03-13 09:59:53 +0100158static void remove_client(struct fio_client *client)
Jens Axboe5121a9a2012-03-05 13:32:47 +0100159{
Jens Axboe3af45202012-03-13 09:59:53 +0100160 assert(client->refs);
161
162 dprint(FD_NET, "client: removed <%s>\n", client->hostname);
163
164 if (!flist_empty(&client->list))
165 flist_del_init(&client->list);
166
167 fio_client_remove_hash(client);
168
169 if (!flist_empty(&client->eta_list)) {
170 flist_del_init(&client->eta_list);
171 fio_client_dec_jobs_eta(client->eta_in_flight, client->ops->eta);
172 }
173
Jens Axboe1e0c1842012-03-20 15:15:00 +0100174 close(client->fd);
175 client->fd = -1;
176
Jens Axboe0cf3ece2012-03-21 10:15:20 +0100177 if (client->ops->removed)
178 client->ops->removed(client);
179
Jens Axboe3af45202012-03-13 09:59:53 +0100180 nr_clients--;
Jens Axboe3af45202012-03-13 09:59:53 +0100181 fio_put_client(client);
Jens Axboe5121a9a2012-03-05 13:32:47 +0100182}
183
Jens Axboe343cb4a2012-03-09 17:16:51 +0100184struct fio_client *fio_get_client(struct fio_client *client)
185{
186 client->refs++;
187 return client;
188}
189
Jens Axboefa2ea802011-10-08 21:07:29 +0200190static void __fio_client_add_cmd_option(struct fio_client *client,
191 const char *opt)
Jens Axboe81179ee2011-10-04 12:42:06 +0200192{
Jens Axboe39e8e012011-10-04 13:46:08 +0200193 int index;
194
195 index = client->argc++;
Jens Axboe81179ee2011-10-04 12:42:06 +0200196 client->argv = realloc(client->argv, sizeof(char *) * client->argc);
Jens Axboe39e8e012011-10-04 13:46:08 +0200197 client->argv[index] = strdup(opt);
198 dprint(FD_NET, "client: add cmd %d: %s\n", index, opt);
Jens Axboe81179ee2011-10-04 12:42:06 +0200199}
200
Jens Axboefa2ea802011-10-08 21:07:29 +0200201void fio_client_add_cmd_option(void *cookie, const char *opt)
Jens Axboe81179ee2011-10-04 12:42:06 +0200202{
Jens Axboebebe6392011-10-07 10:00:51 +0200203 struct fio_client *client = cookie;
Jens Axboe3f3a4542011-10-10 21:11:09 +0200204 struct flist_head *entry;
Jens Axboe81179ee2011-10-04 12:42:06 +0200205
Jens Axboebebe6392011-10-07 10:00:51 +0200206 if (!client || !opt)
Jens Axboefa2ea802011-10-08 21:07:29 +0200207 return;
Jens Axboe81179ee2011-10-04 12:42:06 +0200208
Jens Axboefa2ea802011-10-08 21:07:29 +0200209 __fio_client_add_cmd_option(client, opt);
Jens Axboe3f3a4542011-10-10 21:11:09 +0200210
211 /*
212 * Duplicate arguments to shared client group
213 */
214 flist_for_each(entry, &arg_list) {
215 client = flist_entry(entry, struct fio_client, arg_list);
216
217 __fio_client_add_cmd_option(client, opt);
218 }
Jens Axboe81179ee2011-10-04 12:42:06 +0200219}
220
Jens Axboea5276612012-03-04 15:15:08 +0100221struct fio_client *fio_client_add_explicit(struct client_ops *ops,
222 const char *hostname, int type,
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100223 int port)
224{
225 struct fio_client *client;
226
227 client = malloc(sizeof(*client));
228 memset(client, 0, sizeof(*client));
229
230 INIT_FLIST_HEAD(&client->list);
231 INIT_FLIST_HEAD(&client->hash_list);
232 INIT_FLIST_HEAD(&client->arg_list);
233 INIT_FLIST_HEAD(&client->eta_list);
234 INIT_FLIST_HEAD(&client->cmd_list);
235
236 client->hostname = strdup(hostname);
237
238 if (type == Fio_client_socket)
239 client->is_sock = 1;
240 else {
241 int ipv6;
242
243 ipv6 = type == Fio_client_ipv6;
Jens Axboe3aa3cee2014-01-24 18:56:56 -0800244 if (fio_server_parse_host(hostname, ipv6,
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100245 &client->addr.sin_addr,
246 &client->addr6.sin6_addr))
247 goto err;
248
249 client->port = port;
250 }
251
252 client->fd = -1;
Jens Axboea5276612012-03-04 15:15:08 +0100253 client->ops = ops;
Jens Axboe5121a9a2012-03-05 13:32:47 +0100254 client->refs = 1;
Jens Axboe46bcd492012-03-14 11:31:21 +0100255 client->type = ops->client_type;
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100256
257 __fio_client_add_cmd_option(client, "fio");
258
259 flist_add(&client->list, &client_list);
260 nr_clients++;
261 dprint(FD_NET, "client: added <%s>\n", client->hostname);
262 return client;
263err:
264 free(client);
265 return NULL;
266}
267
Jens Axboe35899182014-10-07 20:56:28 -0600268int fio_client_add_ini_file(void *cookie, const char *ini_file, int remote)
Jens Axboe14ea90e2012-08-26 17:33:34 +0200269{
270 struct fio_client *client = cookie;
Jens Axboe35899182014-10-07 20:56:28 -0600271 struct client_file *cf;
Jens Axboe14ea90e2012-08-26 17:33:34 +0200272 size_t new_size;
Jens Axboe35899182014-10-07 20:56:28 -0600273 void *new_files;
Jens Axboe14ea90e2012-08-26 17:33:34 +0200274
Jens Axboe722b5cd2014-10-14 19:56:25 -0600275 if (!client)
276 return 1;
277
Jens Axboe14ea90e2012-08-26 17:33:34 +0200278 dprint(FD_NET, "client <%s>: add ini %s\n", client->hostname, ini_file);
279
Jens Axboe35899182014-10-07 20:56:28 -0600280 new_size = (client->nr_files + 1) * sizeof(struct client_file);
281 new_files = realloc(client->files, new_size);
282 if (!new_files)
283 return 1;
284
285 client->files = new_files;
286 cf = &client->files[client->nr_files];
287 cf->file = strdup(ini_file);
288 cf->remote = remote;
289 client->nr_files++;
290 return 0;
Jens Axboe14ea90e2012-08-26 17:33:34 +0200291}
292
Jens Axboea5276612012-03-04 15:15:08 +0100293int fio_client_add(struct client_ops *ops, const char *hostname, void **cookie)
Jens Axboe132159a2011-09-30 15:01:32 -0600294{
Jens Axboe3f3a4542011-10-10 21:11:09 +0200295 struct fio_client *existing = *cookie;
Jens Axboeb66570d2011-10-01 11:11:35 -0600296 struct fio_client *client;
Jens Axboe132159a2011-09-30 15:01:32 -0600297
Jens Axboe3f3a4542011-10-10 21:11:09 +0200298 if (existing) {
299 /*
300 * We always add our "exec" name as the option, hence 1
301 * means empty.
302 */
303 if (existing->argc == 1)
304 flist_add_tail(&existing->arg_list, &arg_list);
305 else {
306 while (!flist_empty(&arg_list))
307 flist_del_init(arg_list.next);
308 }
309 }
310
Jens Axboeb66570d2011-10-01 11:11:35 -0600311 client = malloc(sizeof(*client));
Jens Axboea37f69b2011-10-01 12:24:21 -0600312 memset(client, 0, sizeof(*client));
Jens Axboe81179ee2011-10-04 12:42:06 +0200313
Jens Axboe3c5f57e2011-10-06 12:37:50 +0200314 INIT_FLIST_HEAD(&client->list);
Jens Axboebebe6392011-10-07 10:00:51 +0200315 INIT_FLIST_HEAD(&client->hash_list);
Jens Axboe3f3a4542011-10-10 21:11:09 +0200316 INIT_FLIST_HEAD(&client->arg_list);
Jens Axboe82c1ed32011-10-10 08:56:18 +0200317 INIT_FLIST_HEAD(&client->eta_list);
Jens Axboe89c17072011-10-11 10:15:51 +0200318 INIT_FLIST_HEAD(&client->cmd_list);
Jens Axboe3c5f57e2011-10-06 12:37:50 +0200319
Jens Axboebebe6392011-10-07 10:00:51 +0200320 if (fio_server_parse_string(hostname, &client->hostname,
321 &client->is_sock, &client->port,
Jens Axboe811826b2011-10-24 09:11:50 +0200322 &client->addr.sin_addr,
323 &client->addr6.sin6_addr,
324 &client->ipv6))
Jens Axboebebe6392011-10-07 10:00:51 +0200325 return -1;
326
Jens Axboea37f69b2011-10-01 12:24:21 -0600327 client->fd = -1;
Jens Axboea5276612012-03-04 15:15:08 +0100328 client->ops = ops;
Jens Axboe5121a9a2012-03-05 13:32:47 +0100329 client->refs = 1;
Jens Axboe46bcd492012-03-14 11:31:21 +0100330 client->type = ops->client_type;
Jens Axboe81179ee2011-10-04 12:42:06 +0200331
332 __fio_client_add_cmd_option(client, "fio");
333
Jens Axboea37f69b2011-10-01 12:24:21 -0600334 flist_add(&client->list, &client_list);
335 nr_clients++;
Jens Axboebebe6392011-10-07 10:00:51 +0200336 dprint(FD_NET, "client: added <%s>\n", client->hostname);
337 *cookie = client;
338 return 0;
Jens Axboea37f69b2011-10-01 12:24:21 -0600339}
340
Jens Axboede54cfd2014-11-10 20:34:00 -0700341static const char *server_name(struct fio_client *client, char *buf,
342 size_t bufsize)
343{
344 const char *from;
345
346 if (client->ipv6)
347 from = inet_ntop(AF_INET6, (struct sockaddr *) &client->addr6.sin6_addr, buf, bufsize);
348 else if (client->is_sock)
349 from = "sock";
350 else
351 from = inet_ntop(AF_INET, (struct sockaddr *) &client->addr.sin_addr, buf, bufsize);
352
353 return from;
354}
355
Jens Axboed824c3b2012-03-09 17:45:43 +0100356static void probe_client(struct fio_client *client)
357{
Jens Axboe3989b142013-04-12 13:13:24 +0200358 struct cmd_client_probe_pdu pdu;
359 uint64_t tag;
Jens Axboede54cfd2014-11-10 20:34:00 -0700360 char buf[64];
Jens Axboe3989b142013-04-12 13:13:24 +0200361
Jens Axboed824c3b2012-03-09 17:45:43 +0100362 dprint(FD_NET, "client: send probe\n");
363
Jens Axboe3989b142013-04-12 13:13:24 +0200364#ifdef CONFIG_ZLIB
365 pdu.flags = __le64_to_cpu(FIO_PROBE_FLAG_ZLIB);
366#else
367 pdu.flags = 0;
368#endif
369
Jens Axboede54cfd2014-11-10 20:34:00 -0700370 strcpy((char *) pdu.server, server_name(client, buf, sizeof(buf)));
371
Jens Axboe3989b142013-04-12 13:13:24 +0200372 fio_net_send_cmd(client->fd, FIO_NET_CMD_PROBE, &pdu, sizeof(pdu), &tag, &client->cmd_list);
Jens Axboed824c3b2012-03-09 17:45:43 +0100373}
374
Jens Axboe87aa8f12011-10-06 21:24:13 +0200375static int fio_client_connect_ip(struct fio_client *client)
Jens Axboea37f69b2011-10-01 12:24:21 -0600376{
Jens Axboe811826b2011-10-24 09:11:50 +0200377 struct sockaddr *addr;
Jens Axboe67bf9822013-01-10 11:23:19 +0100378 socklen_t socklen;
Jens Axboe811826b2011-10-24 09:11:50 +0200379 int fd, domain;
Jens Axboe132159a2011-09-30 15:01:32 -0600380
Jens Axboe811826b2011-10-24 09:11:50 +0200381 if (client->ipv6) {
382 client->addr6.sin6_family = AF_INET6;
383 client->addr6.sin6_port = htons(client->port);
384 domain = AF_INET6;
385 addr = (struct sockaddr *) &client->addr6;
386 socklen = sizeof(client->addr6);
387 } else {
388 client->addr.sin_family = AF_INET;
389 client->addr.sin_port = htons(client->port);
390 domain = AF_INET;
391 addr = (struct sockaddr *) &client->addr;
392 socklen = sizeof(client->addr);
393 }
Jens Axboe132159a2011-09-30 15:01:32 -0600394
Jens Axboe811826b2011-10-24 09:11:50 +0200395 fd = socket(domain, SOCK_STREAM, 0);
Jens Axboe132159a2011-09-30 15:01:32 -0600396 if (fd < 0) {
Jens Axboe25095e12012-03-09 17:09:55 +0100397 int ret = -errno;
398
Jens Axboe132159a2011-09-30 15:01:32 -0600399 log_err("fio: socket: %s\n", strerror(errno));
Jens Axboe25095e12012-03-09 17:09:55 +0100400 return ret;
Jens Axboe132159a2011-09-30 15:01:32 -0600401 }
402
Jens Axboe811826b2011-10-24 09:11:50 +0200403 if (connect(fd, addr, socklen) < 0) {
Jens Axboe25095e12012-03-09 17:09:55 +0100404 int ret = -errno;
405
Jens Axboe132159a2011-09-30 15:01:32 -0600406 log_err("fio: connect: %s\n", strerror(errno));
Jens Axboea7de0a12011-10-07 12:55:14 +0200407 log_err("fio: failed to connect to %s:%u\n", client->hostname,
408 client->port);
Jens Axboeb94cba42011-10-06 21:27:10 +0200409 close(fd);
Jens Axboe25095e12012-03-09 17:09:55 +0100410 return ret;
Jens Axboe132159a2011-09-30 15:01:32 -0600411 }
412
Jens Axboe87aa8f12011-10-06 21:24:13 +0200413 return fd;
414}
415
416static int fio_client_connect_sock(struct fio_client *client)
417{
418 struct sockaddr_un *addr = &client->addr_un;
Jens Axboe67bf9822013-01-10 11:23:19 +0100419 socklen_t len;
Jens Axboe87aa8f12011-10-06 21:24:13 +0200420 int fd;
421
422 memset(addr, 0, sizeof(*addr));
423 addr->sun_family = AF_UNIX;
Jens Axboe1cb96412014-04-14 08:50:33 -0600424 strncpy(addr->sun_path, client->hostname, sizeof(addr->sun_path) - 1);
Jens Axboe87aa8f12011-10-06 21:24:13 +0200425
426 fd = socket(AF_UNIX, SOCK_STREAM, 0);
427 if (fd < 0) {
Jens Axboe25095e12012-03-09 17:09:55 +0100428 int ret = -errno;
429
Jens Axboe87aa8f12011-10-06 21:24:13 +0200430 log_err("fio: socket: %s\n", strerror(errno));
Jens Axboe25095e12012-03-09 17:09:55 +0100431 return ret;
Jens Axboe87aa8f12011-10-06 21:24:13 +0200432 }
433
434 len = sizeof(addr->sun_family) + strlen(addr->sun_path) + 1;
435 if (connect(fd, (struct sockaddr *) addr, len) < 0) {
Jens Axboe25095e12012-03-09 17:09:55 +0100436 int ret = -errno;
437
Jens Axboe87aa8f12011-10-06 21:24:13 +0200438 log_err("fio: connect; %s\n", strerror(errno));
Jens Axboeb94cba42011-10-06 21:27:10 +0200439 close(fd);
Jens Axboe25095e12012-03-09 17:09:55 +0100440 return ret;
Jens Axboe87aa8f12011-10-06 21:24:13 +0200441 }
442
443 return fd;
444}
445
Jens Axboe2f99deb2012-03-09 14:37:29 +0100446int fio_client_connect(struct fio_client *client)
Jens Axboe87aa8f12011-10-06 21:24:13 +0200447{
448 int fd;
449
450 dprint(FD_NET, "client: connect to host %s\n", client->hostname);
451
Jens Axboe87aa8f12011-10-06 21:24:13 +0200452 if (client->is_sock)
453 fd = fio_client_connect_sock(client);
454 else
455 fd = fio_client_connect_ip(client);
456
Jens Axboe89c17072011-10-11 10:15:51 +0200457 dprint(FD_NET, "client: %s connected %d\n", client->hostname, fd);
458
Jens Axboe87aa8f12011-10-06 21:24:13 +0200459 if (fd < 0)
Jens Axboea1a3ed52012-03-09 17:00:01 +0100460 return fd;
Jens Axboe87aa8f12011-10-06 21:24:13 +0200461
Jens Axboeb66570d2011-10-01 11:11:35 -0600462 client->fd = fd;
Jens Axboebebe6392011-10-07 10:00:51 +0200463 fio_client_add_hash(client);
Jens Axboe81179ee2011-10-04 12:42:06 +0200464 client->state = Client_connected;
Jens Axboed824c3b2012-03-09 17:45:43 +0100465
466 probe_client(client);
Jens Axboe132159a2011-09-30 15:01:32 -0600467 return 0;
468}
469
Jens Axboe0cf3ece2012-03-21 10:15:20 +0100470int fio_client_terminate(struct fio_client *client)
Jens Axboe2f99deb2012-03-09 14:37:29 +0100471{
Jens Axboe0cf3ece2012-03-21 10:15:20 +0100472 return fio_net_send_quit(client->fd);
Jens Axboe2f99deb2012-03-09 14:37:29 +0100473}
474
Jens Axboecc0df002011-10-03 20:53:32 +0200475void fio_clients_terminate(void)
476{
477 struct flist_head *entry;
478 struct fio_client *client;
479
Jens Axboe60efd142011-10-04 13:30:11 +0200480 dprint(FD_NET, "client: terminate clients\n");
481
Jens Axboecc0df002011-10-03 20:53:32 +0200482 flist_for_each(entry, &client_list) {
483 client = flist_entry(entry, struct fio_client, list);
Jens Axboe2f99deb2012-03-09 14:37:29 +0100484 fio_client_terminate(client);
Jens Axboecc0df002011-10-03 20:53:32 +0200485 }
486}
487
488static void sig_int(int sig)
489{
Jens Axboebebe6392011-10-07 10:00:51 +0200490 dprint(FD_NET, "client: got signal %d\n", sig);
Jens Axboecc0df002011-10-03 20:53:32 +0200491 fio_clients_terminate();
492}
493
Jens Axboeb852e7c2012-03-30 10:30:35 +0200494static void sig_show_status(int sig)
495{
496 show_running_run_stats();
497}
498
Jens Axboecc0df002011-10-03 20:53:32 +0200499static void client_signal_handler(void)
500{
501 struct sigaction act;
502
503 memset(&act, 0, sizeof(act));
504 act.sa_handler = sig_int;
505 act.sa_flags = SA_RESTART;
506 sigaction(SIGINT, &act, NULL);
507
508 memset(&act, 0, sizeof(act));
509 act.sa_handler = sig_int;
510 act.sa_flags = SA_RESTART;
511 sigaction(SIGTERM, &act, NULL);
Jens Axboeb852e7c2012-03-30 10:30:35 +0200512
Bruce Cran2f694502012-10-10 16:34:13 +0100513/* Windows uses SIGBREAK as a quit signal from other applications */
514#ifdef WIN32
515 memset(&act, 0, sizeof(act));
516 act.sa_handler = sig_int;
517 act.sa_flags = SA_RESTART;
518 sigaction(SIGBREAK, &act, NULL);
519#endif
520
Jens Axboeb852e7c2012-03-30 10:30:35 +0200521 memset(&act, 0, sizeof(act));
522 act.sa_handler = sig_show_status;
523 act.sa_flags = SA_RESTART;
524 sigaction(SIGUSR1, &act, NULL);
Jens Axboecc0df002011-10-03 20:53:32 +0200525}
526
Jens Axboe81179ee2011-10-04 12:42:06 +0200527static int send_client_cmd_line(struct fio_client *client)
528{
Jens Axboefa2ea802011-10-08 21:07:29 +0200529 struct cmd_single_line_pdu *cslp;
530 struct cmd_line_pdu *clp;
531 unsigned long offset;
Jens Axboe7f868312011-10-10 09:55:21 +0200532 unsigned int *lens;
Jens Axboefa2ea802011-10-08 21:07:29 +0200533 void *pdu;
534 size_t mem;
Jens Axboe81179ee2011-10-04 12:42:06 +0200535 int i, ret;
536
Jens Axboe39e8e012011-10-04 13:46:08 +0200537 dprint(FD_NET, "client: send cmdline %d\n", client->argc);
Jens Axboe60efd142011-10-04 13:30:11 +0200538
Jens Axboe7f868312011-10-10 09:55:21 +0200539 lens = malloc(client->argc * sizeof(unsigned int));
540
Jens Axboefa2ea802011-10-08 21:07:29 +0200541 /*
542 * Find out how much mem we need
543 */
Jens Axboe7f868312011-10-10 09:55:21 +0200544 for (i = 0, mem = 0; i < client->argc; i++) {
545 lens[i] = strlen(client->argv[i]) + 1;
546 mem += lens[i];
547 }
Jens Axboe81179ee2011-10-04 12:42:06 +0200548
Jens Axboefa2ea802011-10-08 21:07:29 +0200549 /*
550 * We need one cmd_line_pdu, and argc number of cmd_single_line_pdu
551 */
552 mem += sizeof(*clp) + (client->argc * sizeof(*cslp));
553
554 pdu = malloc(mem);
555 clp = pdu;
556 offset = sizeof(*clp);
557
558 for (i = 0; i < client->argc; i++) {
Jens Axboe7f868312011-10-10 09:55:21 +0200559 uint16_t arg_len = lens[i];
Jens Axboefa2ea802011-10-08 21:07:29 +0200560
561 cslp = pdu + offset;
562 strcpy((char *) cslp->text, client->argv[i]);
563 cslp->len = cpu_to_le16(arg_len);
564 offset += sizeof(*cslp) + arg_len;
565 }
566
Jens Axboe7f868312011-10-10 09:55:21 +0200567 free(lens);
Jens Axboefa2ea802011-10-08 21:07:29 +0200568 clp->lines = cpu_to_le16(client->argc);
Jens Axboe46bcd492012-03-14 11:31:21 +0100569 clp->client_type = __cpu_to_le16(client->type);
Jens Axboe40c60512012-03-27 16:03:04 +0200570 ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOBLINE, pdu, mem, NULL, NULL);
Jens Axboe81179ee2011-10-04 12:42:06 +0200571 free(pdu);
572 return ret;
573}
574
Jens Axboea37f69b2011-10-01 12:24:21 -0600575int fio_clients_connect(void)
576{
577 struct fio_client *client;
578 struct flist_head *entry, *tmp;
579 int ret;
580
Bruce Cran93bcfd22012-02-20 20:18:19 +0100581#ifdef WIN32
582 WSADATA wsd;
Jens Axboe3c3ed072012-03-27 09:12:39 +0200583 WSAStartup(MAKEWORD(2, 2), &wsd);
Bruce Cran93bcfd22012-02-20 20:18:19 +0100584#endif
585
Jens Axboe60efd142011-10-04 13:30:11 +0200586 dprint(FD_NET, "client: connect all\n");
587
Jens Axboecc0df002011-10-03 20:53:32 +0200588 client_signal_handler();
589
Jens Axboea37f69b2011-10-01 12:24:21 -0600590 flist_for_each_safe(entry, tmp, &client_list) {
591 client = flist_entry(entry, struct fio_client, list);
592
593 ret = fio_client_connect(client);
Jens Axboe0b8f30a2011-10-04 10:31:53 +0200594 if (ret) {
Jens Axboea37f69b2011-10-01 12:24:21 -0600595 remove_client(client);
Jens Axboe0b8f30a2011-10-04 10:31:53 +0200596 continue;
597 }
598
Jens Axboe81179ee2011-10-04 12:42:06 +0200599 if (client->argc > 1)
600 send_client_cmd_line(client);
Jens Axboea37f69b2011-10-01 12:24:21 -0600601 }
602
603 return !nr_clients;
604}
605
Jens Axboeb9d2f302012-03-08 20:36:28 +0100606int fio_start_client(struct fio_client *client)
607{
608 dprint(FD_NET, "client: start %s\n", client->hostname);
609 return fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_RUN, 0, NULL);
610}
611
612int fio_start_all_clients(void)
613{
614 struct fio_client *client;
615 struct flist_head *entry, *tmp;
616 int ret;
617
618 dprint(FD_NET, "client: start all\n");
619
Castor Fu952b05e2013-10-31 11:00:34 -0600620 fio_client_json_init();
621
Jens Axboeb9d2f302012-03-08 20:36:28 +0100622 flist_for_each_safe(entry, tmp, &client_list) {
623 client = flist_entry(entry, struct fio_client, list);
624
625 ret = fio_start_client(client);
626 if (ret) {
627 remove_client(client);
628 continue;
629 }
630 }
631
632 return flist_empty(&client_list);
633}
634
Jens Axboe35899182014-10-07 20:56:28 -0600635static int __fio_client_send_remote_ini(struct fio_client *client,
636 const char *filename)
637{
638 struct cmd_load_file_pdu *pdu;
639 size_t p_size;
640 int ret;
641
642 dprint(FD_NET, "send remote ini %s to %s\n", filename, client->hostname);
643
Jens Axboe79ecc302014-10-07 22:02:21 -0600644 p_size = sizeof(*pdu) + strlen(filename) + 1;
Jens Axboe35899182014-10-07 20:56:28 -0600645 pdu = malloc(p_size);
Jens Axboe79ecc302014-10-07 22:02:21 -0600646 memset(pdu, 0, p_size);
Jens Axboe35899182014-10-07 20:56:28 -0600647 pdu->name_len = strlen(filename);
648 strcpy((char *) pdu->file, filename);
649 pdu->client_type = cpu_to_le16((uint16_t) client->type);
650
651 client->sent_job = 1;
652 ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_LOAD_FILE, pdu, p_size,NULL, NULL);
653 free(pdu);
654 return ret;
655}
656
Jens Axboe132159a2011-09-30 15:01:32 -0600657/*
658 * Send file contents to server backend. We could use sendfile(), but to remain
659 * more portable lets just read/write the darn thing.
660 */
Jens Axboe35899182014-10-07 20:56:28 -0600661static int __fio_client_send_local_ini(struct fio_client *client,
662 const char *filename)
Jens Axboe132159a2011-09-30 15:01:32 -0600663{
Jens Axboe46bcd492012-03-14 11:31:21 +0100664 struct cmd_job_pdu *pdu;
665 size_t p_size;
Jens Axboe132159a2011-09-30 15:01:32 -0600666 struct stat sb;
Jens Axboe46bcd492012-03-14 11:31:21 +0100667 char *p;
668 void *buf;
Jens Axboe132159a2011-09-30 15:01:32 -0600669 off_t len;
670 int fd, ret;
671
Jens Axboe46c48f12011-10-01 12:50:51 -0600672 dprint(FD_NET, "send ini %s to %s\n", filename, client->hostname);
673
Jens Axboe132159a2011-09-30 15:01:32 -0600674 fd = open(filename, O_RDONLY);
675 if (fd < 0) {
Jens Axboe0f7f9a92014-11-06 09:21:10 -0700676 ret = -errno;
Jens Axboee951bdc2011-10-05 21:58:45 +0200677 log_err("fio: job file <%s> open: %s\n", filename, strerror(errno));
Jens Axboe25095e12012-03-09 17:09:55 +0100678 return ret;
Jens Axboe132159a2011-09-30 15:01:32 -0600679 }
680
681 if (fstat(fd, &sb) < 0) {
Jens Axboe0f7f9a92014-11-06 09:21:10 -0700682 ret = -errno;
Jens Axboe132159a2011-09-30 15:01:32 -0600683 log_err("fio: job file stat: %s\n", strerror(errno));
Jens Axboeb94cba42011-10-06 21:27:10 +0200684 close(fd);
Jens Axboe25095e12012-03-09 17:09:55 +0100685 return ret;
Jens Axboe132159a2011-09-30 15:01:32 -0600686 }
687
Jens Axboe46bcd492012-03-14 11:31:21 +0100688 p_size = sb.st_size + sizeof(*pdu);
689 pdu = malloc(p_size);
690 buf = pdu->buf;
Jens Axboe132159a2011-09-30 15:01:32 -0600691
692 len = sb.st_size;
693 p = buf;
694 do {
695 ret = read(fd, p, len);
696 if (ret > 0) {
697 len -= ret;
698 if (!len)
699 break;
700 p += ret;
701 continue;
702 } else if (!ret)
703 break;
704 else if (errno == EAGAIN || errno == EINTR)
705 continue;
706 } while (1);
707
Jens Axboe0b8f30a2011-10-04 10:31:53 +0200708 if (len) {
709 log_err("fio: failed reading job file %s\n", filename);
Jens Axboeb94cba42011-10-06 21:27:10 +0200710 close(fd);
Hong Zhiguo03a22d92013-10-16 08:35:12 -0600711 free(pdu);
Jens Axboe0b8f30a2011-10-04 10:31:53 +0200712 return 1;
713 }
714
Jens Axboe46bcd492012-03-14 11:31:21 +0100715 pdu->buf_len = __cpu_to_le32(sb.st_size);
716 pdu->client_type = cpu_to_le32(client->type);
717
Jens Axboec2cb6862012-02-23 20:56:12 +0100718 client->sent_job = 1;
Jens Axboe40c60512012-03-27 16:03:04 +0200719 ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOB, pdu, p_size, NULL, NULL);
Jens Axboe46bcd492012-03-14 11:31:21 +0100720 free(pdu);
Jens Axboeb94cba42011-10-06 21:27:10 +0200721 close(fd);
Jens Axboe132159a2011-09-30 15:01:32 -0600722 return ret;
723}
Jens Axboe37db14f2011-09-30 17:00:42 -0600724
Jens Axboe35899182014-10-07 20:56:28 -0600725int fio_client_send_ini(struct fio_client *client, const char *filename,
726 int remote)
Jens Axboe9988ca72012-03-09 15:14:06 +0100727{
Jens Axboe25095e12012-03-09 17:09:55 +0100728 int ret;
729
Jens Axboe35899182014-10-07 20:56:28 -0600730 if (!remote)
731 ret = __fio_client_send_local_ini(client, filename);
732 else
733 ret = __fio_client_send_remote_ini(client, filename);
734
Jens Axboe3af45202012-03-13 09:59:53 +0100735 if (!ret)
736 client->sent_job = 1;
Jens Axboe9988ca72012-03-09 15:14:06 +0100737
Jens Axboe25095e12012-03-09 17:09:55 +0100738 return ret;
Jens Axboe9988ca72012-03-09 15:14:06 +0100739}
740
Jens Axboe35899182014-10-07 20:56:28 -0600741static int fio_client_send_cf(struct fio_client *client,
742 struct client_file *cf)
743{
744 return fio_client_send_ini(client, cf->file, cf->remote);
745}
746
Jens Axboea37f69b2011-10-01 12:24:21 -0600747int fio_clients_send_ini(const char *filename)
748{
749 struct fio_client *client;
750 struct flist_head *entry, *tmp;
751
752 flist_for_each_safe(entry, tmp, &client_list) {
753 client = flist_entry(entry, struct fio_client, list);
754
Jens Axboe35899182014-10-07 20:56:28 -0600755 if (client->nr_files) {
Jens Axboe14ea90e2012-08-26 17:33:34 +0200756 int i;
757
Jens Axboe35899182014-10-07 20:56:28 -0600758 for (i = 0; i < client->nr_files; i++) {
759 struct client_file *cf;
Jens Axboe14ea90e2012-08-26 17:33:34 +0200760
Jens Axboe35899182014-10-07 20:56:28 -0600761 cf = &client->files[i];
762
763 if (fio_client_send_cf(client, cf)) {
Jens Axboe14ea90e2012-08-26 17:33:34 +0200764 remove_client(client);
765 break;
766 }
767 }
Jens Axboe35899182014-10-07 20:56:28 -0600768 }
769 if (client->sent_job)
770 continue;
771 if (!filename || fio_client_send_ini(client, filename, 0))
Jens Axboe3af45202012-03-13 09:59:53 +0100772 remove_client(client);
Jens Axboea37f69b2011-10-01 12:24:21 -0600773 }
774
775 return !nr_clients;
776}
777
Jens Axboe40c60512012-03-27 16:03:04 +0200778int fio_client_update_options(struct fio_client *client,
779 struct thread_options *o, uint64_t *tag)
780{
781 struct cmd_add_job_pdu pdu;
782
783 pdu.thread_number = cpu_to_le32(client->thread_number);
784 pdu.groupid = cpu_to_le32(client->groupid);
785 convert_thread_options_to_net(&pdu.top, o);
Castor Fu952b05e2013-10-31 11:00:34 -0600786
Jens Axboe40c60512012-03-27 16:03:04 +0200787 return fio_net_send_cmd(client->fd, FIO_NET_CMD_UPDATE_JOB, &pdu, sizeof(pdu), tag, &client->cmd_list);
788}
789
Jens Axboea64e88d2011-10-03 14:20:01 +0200790static void convert_io_stat(struct io_stat *dst, struct io_stat *src)
791{
792 dst->max_val = le64_to_cpu(src->max_val);
793 dst->min_val = le64_to_cpu(src->min_val);
794 dst->samples = le64_to_cpu(src->samples);
Jens Axboe802ad4a2011-10-05 09:51:58 +0200795
796 /*
797 * Floats arrive as IEEE 754 encoded uint64_t, convert back to double
798 */
799 dst->mean.u.f = fio_uint64_to_double(le64_to_cpu(dst->mean.u.i));
800 dst->S.u.f = fio_uint64_to_double(le64_to_cpu(dst->S.u.i));
Jens Axboea64e88d2011-10-03 14:20:01 +0200801}
802
803static void convert_ts(struct thread_stat *dst, struct thread_stat *src)
804{
805 int i, j;
806
Jens Axboe2f122b12012-03-15 13:10:19 +0100807 dst->error = le32_to_cpu(src->error);
808 dst->thread_number = le32_to_cpu(src->thread_number);
809 dst->groupid = le32_to_cpu(src->groupid);
810 dst->pid = le32_to_cpu(src->pid);
811 dst->members = le32_to_cpu(src->members);
Jens Axboe771e58b2013-01-30 12:56:23 +0100812 dst->unified_rw_rep = le32_to_cpu(src->unified_rw_rep);
Jens Axboea64e88d2011-10-03 14:20:01 +0200813
Jens Axboe298921d2012-09-24 18:47:01 +0200814 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
Jens Axboea64e88d2011-10-03 14:20:01 +0200815 convert_io_stat(&dst->clat_stat[i], &src->clat_stat[i]);
816 convert_io_stat(&dst->slat_stat[i], &src->slat_stat[i]);
817 convert_io_stat(&dst->lat_stat[i], &src->lat_stat[i]);
818 convert_io_stat(&dst->bw_stat[i], &src->bw_stat[i]);
819 }
820
821 dst->usr_time = le64_to_cpu(src->usr_time);
822 dst->sys_time = le64_to_cpu(src->sys_time);
823 dst->ctx = le64_to_cpu(src->ctx);
824 dst->minf = le64_to_cpu(src->minf);
825 dst->majf = le64_to_cpu(src->majf);
826 dst->clat_percentiles = le64_to_cpu(src->clat_percentiles);
Jens Axboe623216d2014-11-07 18:47:41 -0700827 dst->percentile_precision = le64_to_cpu(src->percentile_precision);
Jens Axboe802ad4a2011-10-05 09:51:58 +0200828
829 for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) {
830 fio_fp64_t *fps = &src->percentile_list[i];
831 fio_fp64_t *fpd = &dst->percentile_list[i];
832
833 fpd->u.f = fio_uint64_to_double(le64_to_cpu(fps->u.i));
834 }
Jens Axboea64e88d2011-10-03 14:20:01 +0200835
836 for (i = 0; i < FIO_IO_U_MAP_NR; i++) {
837 dst->io_u_map[i] = le32_to_cpu(src->io_u_map[i]);
838 dst->io_u_submit[i] = le32_to_cpu(src->io_u_submit[i]);
839 dst->io_u_complete[i] = le32_to_cpu(src->io_u_complete[i]);
840 }
841
842 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) {
843 dst->io_u_lat_u[i] = le32_to_cpu(src->io_u_lat_u[i]);
844 dst->io_u_lat_m[i] = le32_to_cpu(src->io_u_lat_m[i]);
845 }
846
Jens Axboe298921d2012-09-24 18:47:01 +0200847 for (i = 0; i < DDIR_RWDIR_CNT; i++)
Jens Axboea64e88d2011-10-03 14:20:01 +0200848 for (j = 0; j < FIO_IO_U_PLAT_NR; j++)
849 dst->io_u_plat[i][j] = le32_to_cpu(src->io_u_plat[i][j]);
850
Jens Axboe78799de2013-01-29 20:53:52 +0100851 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
Jens Axboea64e88d2011-10-03 14:20:01 +0200852 dst->total_io_u[i] = le64_to_cpu(src->total_io_u[i]);
Jens Axboe93eee042011-10-03 21:08:48 +0200853 dst->short_io_u[i] = le64_to_cpu(src->short_io_u[i]);
Jens Axboe67e149c2014-10-09 13:27:44 -0600854 dst->drop_io_u[i] = le64_to_cpu(src->drop_io_u[i]);
Jens Axboea64e88d2011-10-03 14:20:01 +0200855 }
856
857 dst->total_submit = le64_to_cpu(src->total_submit);
858 dst->total_complete = le64_to_cpu(src->total_complete);
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 dst->io_bytes[i] = le64_to_cpu(src->io_bytes[i]);
862 dst->runtime[i] = le64_to_cpu(src->runtime[i]);
863 }
864
865 dst->total_run_time = le64_to_cpu(src->total_run_time);
866 dst->continue_on_error = le16_to_cpu(src->continue_on_error);
867 dst->total_err_count = le64_to_cpu(src->total_err_count);
Jens Axboeddcc0b62011-10-03 14:45:27 +0200868 dst->first_error = le32_to_cpu(src->first_error);
869 dst->kb_base = le32_to_cpu(src->kb_base);
Steven Noonanad705bc2013-04-08 15:05:25 -0700870 dst->unit_base = le32_to_cpu(src->unit_base);
Jens Axboe3e260a42013-12-09 12:38:53 -0700871
872 dst->latency_depth = le32_to_cpu(src->latency_depth);
873 dst->latency_target = le64_to_cpu(src->latency_target);
874 dst->latency_window = le64_to_cpu(src->latency_window);
875 dst->latency_percentile.u.f = fio_uint64_to_double(le64_to_cpu(src->latency_percentile.u.i));
Jens Axboea64e88d2011-10-03 14:20:01 +0200876}
877
878static void convert_gs(struct group_run_stats *dst, struct group_run_stats *src)
879{
880 int i;
881
Jens Axboe298921d2012-09-24 18:47:01 +0200882 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
Jens Axboea64e88d2011-10-03 14:20:01 +0200883 dst->max_run[i] = le64_to_cpu(src->max_run[i]);
884 dst->min_run[i] = le64_to_cpu(src->min_run[i]);
885 dst->max_bw[i] = le64_to_cpu(src->max_bw[i]);
886 dst->min_bw[i] = le64_to_cpu(src->min_bw[i]);
887 dst->io_kb[i] = le64_to_cpu(src->io_kb[i]);
888 dst->agg[i] = le64_to_cpu(src->agg[i]);
889 }
890
891 dst->kb_base = le32_to_cpu(src->kb_base);
Steven Noonanad705bc2013-04-08 15:05:25 -0700892 dst->unit_base = le32_to_cpu(src->unit_base);
Jens Axboea64e88d2011-10-03 14:20:01 +0200893 dst->groupid = le32_to_cpu(src->groupid);
Jens Axboe771e58b2013-01-30 12:56:23 +0100894 dst->unified_rw_rep = le32_to_cpu(src->unified_rw_rep);
Jens Axboea64e88d2011-10-03 14:20:01 +0200895}
896
Castor Fu952b05e2013-10-31 11:00:34 -0600897static void json_object_add_client_info(struct json_object *obj,
Castor Fu54bcda52014-08-22 17:16:44 -0500898 struct fio_client *client)
Castor Fu952b05e2013-10-31 11:00:34 -0600899{
Castor Fu54bcda52014-08-22 17:16:44 -0500900 const char *hostname = client->hostname ? client->hostname : "";
901
902 json_object_add_value_string(obj, "hostname", hostname);
Castor Fu952b05e2013-10-31 11:00:34 -0600903 json_object_add_value_int(obj, "port", client->port);
904}
905
Jens Axboe89e5fad2012-03-05 09:21:12 +0100906static void handle_ts(struct fio_client *client, struct fio_net_cmd *cmd)
Jens Axboea64e88d2011-10-03 14:20:01 +0200907{
908 struct cmd_ts_pdu *p = (struct cmd_ts_pdu *) cmd->payload;
Castor Fu952b05e2013-10-31 11:00:34 -0600909 struct json_object *tsobj;
Jens Axboea64e88d2011-10-03 14:20:01 +0200910
Castor Fu952b05e2013-10-31 11:00:34 -0600911 tsobj = show_thread_status(&p->ts, &p->rs);
Jens Axboe108fea72012-11-14 13:09:45 -0700912 client->did_stat = 1;
Castor Fu952b05e2013-10-31 11:00:34 -0600913 if (tsobj) {
914 json_object_add_client_info(tsobj, client);
915 json_array_add_value_object(clients_array, tsobj);
916 }
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200917
Jens Axboebfa8f5d2014-10-13 10:09:28 -0600918 if (sum_stat_clients <= 1)
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200919 return;
920
921 sum_thread_stats(&client_ts, &p->ts, sum_stat_nr);
922 sum_group_stats(&client_gs, &p->rs);
923
924 client_ts.members++;
Jens Axboe2f122b12012-03-15 13:10:19 +0100925 client_ts.thread_number = p->ts.thread_number;
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200926 client_ts.groupid = p->ts.groupid;
Jens Axboe771e58b2013-01-30 12:56:23 +0100927 client_ts.unified_rw_rep = p->ts.unified_rw_rep;
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200928
929 if (++sum_stat_nr == sum_stat_clients) {
930 strcpy(client_ts.name, "All clients");
Castor Fu952b05e2013-10-31 11:00:34 -0600931 tsobj = show_thread_status(&client_ts, &client_gs);
932 if (tsobj) {
933 json_object_add_client_info(tsobj, client);
934 json_array_add_value_object(clients_array, tsobj);
935 }
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200936 }
Jens Axboea64e88d2011-10-03 14:20:01 +0200937}
938
Jens Axboe89e5fad2012-03-05 09:21:12 +0100939static void handle_gs(struct fio_client *client, struct fio_net_cmd *cmd)
Jens Axboea64e88d2011-10-03 14:20:01 +0200940{
941 struct group_run_stats *gs = (struct group_run_stats *) cmd->payload;
942
Jens Axboea64e88d2011-10-03 14:20:01 +0200943 show_group_stats(gs);
944}
945
Jens Axboe3bf236c2012-03-03 20:35:50 +0100946static void handle_text(struct fio_client *client, struct fio_net_cmd *cmd)
947{
948 struct cmd_text_pdu *pdu = (struct cmd_text_pdu *) cmd->payload;
949 const char *buf = (const char *) pdu->buf;
950 const char *name;
951 int fio_unused ret;
952
953 name = client->name ? client->name : client->hostname;
954
955 if (!client->skip_newline)
956 fprintf(f_out, "<%s> ", name);
957 ret = fwrite(buf, pdu->buf_len, 1, f_out);
958 fflush(f_out);
959 client->skip_newline = strchr(buf, '\n') == NULL;
960}
961
Jens Axboed09a64a2011-10-13 11:38:56 +0200962static void convert_agg(struct disk_util_agg *agg)
963{
964 int i;
965
966 for (i = 0; i < 2; i++) {
967 agg->ios[i] = le32_to_cpu(agg->ios[i]);
968 agg->merges[i] = le32_to_cpu(agg->merges[i]);
969 agg->sectors[i] = le64_to_cpu(agg->sectors[i]);
970 agg->ticks[i] = le32_to_cpu(agg->ticks[i]);
971 }
972
973 agg->io_ticks = le32_to_cpu(agg->io_ticks);
974 agg->time_in_queue = le32_to_cpu(agg->time_in_queue);
975 agg->slavecount = le32_to_cpu(agg->slavecount);
Jens Axboe2b827fa2014-10-13 16:05:10 -0600976 agg->max_util.u.f = fio_uint64_to_double(le64_to_cpu(agg->max_util.u.i));
Jens Axboed09a64a2011-10-13 11:38:56 +0200977}
978
979static void convert_dus(struct disk_util_stat *dus)
980{
981 int i;
982
983 for (i = 0; i < 2; i++) {
Jens Axboea3b4cf72014-04-11 12:17:53 -0600984 dus->s.ios[i] = le32_to_cpu(dus->s.ios[i]);
985 dus->s.merges[i] = le32_to_cpu(dus->s.merges[i]);
986 dus->s.sectors[i] = le64_to_cpu(dus->s.sectors[i]);
987 dus->s.ticks[i] = le32_to_cpu(dus->s.ticks[i]);
Jens Axboed09a64a2011-10-13 11:38:56 +0200988 }
989
Jens Axboea3b4cf72014-04-11 12:17:53 -0600990 dus->s.io_ticks = le32_to_cpu(dus->s.io_ticks);
991 dus->s.time_in_queue = le32_to_cpu(dus->s.time_in_queue);
992 dus->s.msec = le64_to_cpu(dus->s.msec);
Jens Axboed09a64a2011-10-13 11:38:56 +0200993}
994
995static void handle_du(struct fio_client *client, struct fio_net_cmd *cmd)
996{
997 struct cmd_du_pdu *du = (struct cmd_du_pdu *) cmd->payload;
998
Jens Axboed09a64a2011-10-13 11:38:56 +0200999 if (!client->disk_stats_shown) {
1000 client->disk_stats_shown = 1;
1001 log_info("\nDisk stats (read/write):\n");
1002 }
1003
Castor Fu952b05e2013-10-31 11:00:34 -06001004 if (output_format == FIO_OUTPUT_JSON) {
1005 struct json_object *duobj;
1006 json_array_add_disk_util(&du->dus, &du->agg, du_array);
1007 duobj = json_array_last_value_object(du_array);
1008 json_object_add_client_info(duobj, client);
1009 } else
1010 print_disk_util(&du->dus, &du->agg, output_format == FIO_OUTPUT_TERSE);
Jens Axboed09a64a2011-10-13 11:38:56 +02001011}
1012
Jens Axboe3bf236c2012-03-03 20:35:50 +01001013static void convert_jobs_eta(struct jobs_eta *je)
Jens Axboecf451d12011-10-03 16:48:30 +02001014{
Jens Axboecf451d12011-10-03 16:48:30 +02001015 int i;
1016
1017 je->nr_running = le32_to_cpu(je->nr_running);
1018 je->nr_ramp = le32_to_cpu(je->nr_ramp);
1019 je->nr_pending = le32_to_cpu(je->nr_pending);
Jens Axboe714e85f2013-04-15 10:21:56 +02001020 je->nr_setting_up = le32_to_cpu(je->nr_setting_up);
Jens Axboecf451d12011-10-03 16:48:30 +02001021 je->files_open = le32_to_cpu(je->files_open);
Jens Axboecf451d12011-10-03 16:48:30 +02001022
Jens Axboe298921d2012-09-24 18:47:01 +02001023 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
1024 je->m_rate[i] = le32_to_cpu(je->m_rate[i]);
1025 je->t_rate[i] = le32_to_cpu(je->t_rate[i]);
1026 je->m_iops[i] = le32_to_cpu(je->m_iops[i]);
1027 je->t_iops[i] = le32_to_cpu(je->t_iops[i]);
Jens Axboe16725bb2013-04-11 12:43:05 +02001028 je->rate[i] = le32_to_cpu(je->rate[i]);
1029 je->iops[i] = le32_to_cpu(je->iops[i]);
Jens Axboecf451d12011-10-03 16:48:30 +02001030 }
1031
Jens Axboeb51eedb2011-10-09 12:13:39 +02001032 je->elapsed_sec = le64_to_cpu(je->elapsed_sec);
Jens Axboecf451d12011-10-03 16:48:30 +02001033 je->eta_sec = le64_to_cpu(je->eta_sec);
Jens Axboe8c621fb2012-03-08 12:30:48 +01001034 je->nr_threads = le32_to_cpu(je->nr_threads);
Jens Axboeb7f05eb2012-05-11 20:33:02 +02001035 je->is_pow2 = le32_to_cpu(je->is_pow2);
Jens Axboeed2c0a12013-04-11 12:55:16 +02001036 je->unit_base = le32_to_cpu(je->unit_base);
Jens Axboe48fbb462011-10-09 12:19:08 +02001037}
Jens Axboecf451d12011-10-03 16:48:30 +02001038
Jens Axboe3e47bd22012-02-29 13:45:02 +01001039void fio_client_sum_jobs_eta(struct jobs_eta *dst, struct jobs_eta *je)
Jens Axboe48fbb462011-10-09 12:19:08 +02001040{
Jens Axboe48fbb462011-10-09 12:19:08 +02001041 int i;
1042
1043 dst->nr_running += je->nr_running;
1044 dst->nr_ramp += je->nr_ramp;
1045 dst->nr_pending += je->nr_pending;
Jens Axboe714e85f2013-04-15 10:21:56 +02001046 dst->nr_setting_up += je->nr_setting_up;
Jens Axboe48fbb462011-10-09 12:19:08 +02001047 dst->files_open += je->files_open;
Jens Axboe48fbb462011-10-09 12:19:08 +02001048
Jens Axboe298921d2012-09-24 18:47:01 +02001049 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
Jens Axboe3e47bd22012-02-29 13:45:02 +01001050 dst->m_rate[i] += je->m_rate[i];
1051 dst->t_rate[i] += je->t_rate[i];
1052 dst->m_iops[i] += je->m_iops[i];
1053 dst->t_iops[i] += je->t_iops[i];
Jens Axboe16725bb2013-04-11 12:43:05 +02001054 dst->rate[i] += je->rate[i];
1055 dst->iops[i] += je->iops[i];
Jens Axboe48fbb462011-10-09 12:19:08 +02001056 }
1057
1058 dst->elapsed_sec += je->elapsed_sec;
1059
1060 if (je->eta_sec > dst->eta_sec)
1061 dst->eta_sec = je->eta_sec;
Jens Axboe8c621fb2012-03-08 12:30:48 +01001062
1063 dst->nr_threads += je->nr_threads;
Jens Axboe27b91552014-06-27 15:30:06 -06001064
1065 /*
1066 * This wont be correct for multiple strings, but at least it
1067 * works for the basic cases.
1068 */
1069 strcpy((char *) dst->run_str, (char *) je->run_str);
Jens Axboe48fbb462011-10-09 12:19:08 +02001070}
1071
Jens Axboea5276612012-03-04 15:15:08 +01001072void fio_client_dec_jobs_eta(struct client_eta *eta, client_eta_op eta_fn)
Jens Axboe82c1ed32011-10-10 08:56:18 +02001073{
1074 if (!--eta->pending) {
Jens Axboea5276612012-03-04 15:15:08 +01001075 eta_fn(&eta->eta);
Jens Axboe82c1ed32011-10-10 08:56:18 +02001076 free(eta);
1077 }
1078}
1079
Jens Axboe89c17072011-10-11 10:15:51 +02001080static void remove_reply_cmd(struct fio_client *client, struct fio_net_cmd *cmd)
1081{
Jens Axboe40c60512012-03-27 16:03:04 +02001082 struct fio_net_cmd_reply *reply = NULL;
Jens Axboe89c17072011-10-11 10:15:51 +02001083 struct flist_head *entry;
1084
1085 flist_for_each(entry, &client->cmd_list) {
Jens Axboe40c60512012-03-27 16:03:04 +02001086 reply = flist_entry(entry, struct fio_net_cmd_reply, list);
Jens Axboe89c17072011-10-11 10:15:51 +02001087
Jens Axboe40c60512012-03-27 16:03:04 +02001088 if (cmd->tag == (uintptr_t) reply)
Jens Axboe89c17072011-10-11 10:15:51 +02001089 break;
1090
Jens Axboe40c60512012-03-27 16:03:04 +02001091 reply = NULL;
Jens Axboe89c17072011-10-11 10:15:51 +02001092 }
1093
Jens Axboe40c60512012-03-27 16:03:04 +02001094 if (!reply) {
Jens Axboe4e0a8fa2013-04-15 11:40:57 +02001095 log_err("fio: client: unable to find matching tag (%llx)\n", (unsigned long long) cmd->tag);
Jens Axboe89c17072011-10-11 10:15:51 +02001096 return;
1097 }
1098
Jens Axboe40c60512012-03-27 16:03:04 +02001099 flist_del(&reply->list);
1100 cmd->tag = reply->saved_tag;
1101 free(reply);
1102}
1103
1104int fio_client_wait_for_reply(struct fio_client *client, uint64_t tag)
1105{
1106 do {
1107 struct fio_net_cmd_reply *reply = NULL;
1108 struct flist_head *entry;
1109
1110 flist_for_each(entry, &client->cmd_list) {
1111 reply = flist_entry(entry, struct fio_net_cmd_reply, list);
1112
1113 if (tag == (uintptr_t) reply)
1114 break;
1115
1116 reply = NULL;
1117 }
1118
1119 if (!reply)
1120 break;
1121
1122 usleep(1000);
1123 } while (1);
1124
1125 return 0;
Jens Axboe89c17072011-10-11 10:15:51 +02001126}
1127
Jens Axboe82c1ed32011-10-10 08:56:18 +02001128static void handle_eta(struct fio_client *client, struct fio_net_cmd *cmd)
Jens Axboe48fbb462011-10-09 12:19:08 +02001129{
1130 struct jobs_eta *je = (struct jobs_eta *) cmd->payload;
Jens Axboedf380932011-10-11 14:25:08 +02001131 struct client_eta *eta = (struct client_eta *) (uintptr_t) cmd->tag;
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001132
1133 dprint(FD_NET, "client: got eta tag %p, %d\n", eta, eta->pending);
Jens Axboe48fbb462011-10-09 12:19:08 +02001134
Jens Axboef77d2672011-10-10 14:36:07 +02001135 assert(client->eta_in_flight == eta);
1136
1137 client->eta_in_flight = NULL;
Jens Axboe82c1ed32011-10-10 08:56:18 +02001138 flist_del_init(&client->eta_list);
1139
Jens Axboe2f99deb2012-03-09 14:37:29 +01001140 if (client->ops->jobs_eta)
1141 client->ops->jobs_eta(client, je);
1142
Jens Axboe3e47bd22012-02-29 13:45:02 +01001143 fio_client_sum_jobs_eta(&eta->eta, je);
Jens Axboea5276612012-03-04 15:15:08 +01001144 fio_client_dec_jobs_eta(eta, client->ops->eta);
Jens Axboecf451d12011-10-03 16:48:30 +02001145}
1146
Jens Axboeb5296dd2011-10-07 16:35:56 +02001147static void handle_probe(struct fio_client *client, struct fio_net_cmd *cmd)
Jens Axboe2e03b4b2011-10-04 09:00:40 +02001148{
Jens Axboe3989b142013-04-12 13:13:24 +02001149 struct cmd_probe_reply_pdu *probe = (struct cmd_probe_reply_pdu *) cmd->payload;
Jens Axboed2333352011-10-11 15:07:23 +02001150 const char *os, *arch;
1151 char bit[16];
Jens Axboe2e03b4b2011-10-04 09:00:40 +02001152
Jens Axboecca84642011-10-07 12:47:57 +02001153 os = fio_get_os_string(probe->os);
1154 if (!os)
1155 os = "unknown";
1156
1157 arch = fio_get_arch_string(probe->arch);
1158 if (!arch)
1159 os = "unknown";
1160
Jens Axboed2333352011-10-11 15:07:23 +02001161 sprintf(bit, "%d-bit", probe->bpp * 8);
Jens Axboe3989b142013-04-12 13:13:24 +02001162 probe->flags = le64_to_cpu(probe->flags);
Jens Axboe38fdef22011-10-11 14:30:06 +02001163
Jens Axboe3989b142013-04-12 13:13:24 +02001164 log_info("hostname=%s, be=%u, %s, os=%s, arch=%s, fio=%s, flags=%lx\n",
Jens Axboe38fdef22011-10-11 14:30:06 +02001165 probe->hostname, probe->bigendian, bit, os, arch,
Jens Axboe3989b142013-04-12 13:13:24 +02001166 probe->fio_version, (unsigned long) probe->flags);
Jens Axboeb5296dd2011-10-07 16:35:56 +02001167
1168 if (!client->name)
1169 client->name = strdup((char *) probe->hostname);
Jens Axboe2e03b4b2011-10-04 09:00:40 +02001170}
1171
Jens Axboe11e950b2011-10-16 21:34:14 +02001172static void handle_start(struct fio_client *client, struct fio_net_cmd *cmd)
1173{
1174 struct cmd_start_pdu *pdu = (struct cmd_start_pdu *) cmd->payload;
1175
1176 client->state = Client_started;
1177 client->jobs = le32_to_cpu(pdu->jobs);
Jens Axboe30f8e312014-10-13 11:33:27 -06001178 client->nr_stat = le32_to_cpu(pdu->stat_outputs);
Jens Axboe108fea72012-11-14 13:09:45 -07001179
Jens Axboe30f8e312014-10-13 11:33:27 -06001180 sum_stat_clients += client->nr_stat;
Jens Axboe11e950b2011-10-16 21:34:14 +02001181}
1182
1183static void handle_stop(struct fio_client *client, struct fio_net_cmd *cmd)
1184{
Jens Axboe498c92c2011-10-17 09:14:42 +02001185 if (client->error)
1186 log_info("client <%s>: exited with error %d\n", client->hostname, client->error);
Jens Axboe11e950b2011-10-16 21:34:14 +02001187}
1188
Jens Axboe6b79c802012-03-08 10:51:36 +01001189static void convert_stop(struct fio_net_cmd *cmd)
1190{
1191 struct cmd_end_pdu *pdu = (struct cmd_end_pdu *) cmd->payload;
1192
1193 pdu->error = le32_to_cpu(pdu->error);
1194}
1195
Jens Axboe084d1c62012-03-03 20:28:07 +01001196static void convert_text(struct fio_net_cmd *cmd)
1197{
1198 struct cmd_text_pdu *pdu = (struct cmd_text_pdu *) cmd->payload;
1199
1200 pdu->level = le32_to_cpu(pdu->level);
1201 pdu->buf_len = le32_to_cpu(pdu->buf_len);
1202 pdu->log_sec = le64_to_cpu(pdu->log_sec);
1203 pdu->log_usec = le64_to_cpu(pdu->log_usec);
1204}
1205
Jens Axboe3989b142013-04-12 13:13:24 +02001206static struct cmd_iolog_pdu *convert_iolog_gz(struct fio_net_cmd *cmd,
1207 struct cmd_iolog_pdu *pdu)
Jens Axboe1b427252012-03-14 15:03:03 +01001208{
Jens Axboe3989b142013-04-12 13:13:24 +02001209#ifdef CONFIG_ZLIB
Jens Axboe1b427252012-03-14 15:03:03 +01001210 struct cmd_iolog_pdu *ret;
Jens Axboe1b427252012-03-14 15:03:03 +01001211 z_stream stream;
Jens Axboe3989b142013-04-12 13:13:24 +02001212 uint32_t nr_samples;
1213 size_t total;
Jens Axboe1b427252012-03-14 15:03:03 +01001214 void *p;
1215
1216 stream.zalloc = Z_NULL;
1217 stream.zfree = Z_NULL;
1218 stream.opaque = Z_NULL;
1219 stream.avail_in = 0;
1220 stream.next_in = Z_NULL;
1221
1222 if (inflateInit(&stream) != Z_OK)
1223 return NULL;
1224
1225 /*
Jens Axboef5ed7652012-03-14 16:28:07 +01001226 * Get header first, it's not compressed
Jens Axboe1b427252012-03-14 15:03:03 +01001227 */
Jens Axboef2b9a672014-07-01 08:47:11 -06001228 nr_samples = le64_to_cpu(pdu->nr_samples);
Jens Axboe1b427252012-03-14 15:03:03 +01001229
Jens Axboef2b9a672014-07-01 08:47:11 -06001230 total = nr_samples * __log_entry_sz(le32_to_cpu(pdu->log_offset));
Jens Axboef5ed7652012-03-14 16:28:07 +01001231 ret = malloc(total + sizeof(*pdu));
Jens Axboe1b427252012-03-14 15:03:03 +01001232 ret->nr_samples = nr_samples;
Jens Axboe3989b142013-04-12 13:13:24 +02001233
1234 memcpy(ret, pdu, sizeof(*pdu));
Jens Axboe1b427252012-03-14 15:03:03 +01001235
Jens Axboef5ed7652012-03-14 16:28:07 +01001236 p = (void *) ret + sizeof(*pdu);
1237
1238 stream.avail_in = cmd->pdu_len - sizeof(*pdu);
1239 stream.next_in = (void *) pdu + sizeof(*pdu);
Jens Axboe1b427252012-03-14 15:03:03 +01001240 while (stream.avail_in) {
1241 unsigned int this_chunk = 65536;
1242 unsigned int this_len;
1243 int err;
1244
1245 if (this_chunk > total)
1246 this_chunk = total;
1247
1248 stream.avail_out = this_chunk;
1249 stream.next_out = p;
1250 err = inflate(&stream, Z_NO_FLUSH);
Jens Axboe3c547fe2012-03-14 21:53:00 +01001251 /* may be Z_OK, or Z_STREAM_END */
1252 if (err < 0) {
Jens Axboe1b427252012-03-14 15:03:03 +01001253 log_err("fio: inflate error %d\n", err);
Jens Axboef5ed7652012-03-14 16:28:07 +01001254 free(ret);
1255 ret = NULL;
Jens Axboe3989b142013-04-12 13:13:24 +02001256 goto err;
Jens Axboe1b427252012-03-14 15:03:03 +01001257 }
1258
1259 this_len = this_chunk - stream.avail_out;
1260 p += this_len;
1261 total -= this_len;
1262 }
1263
Jens Axboe3989b142013-04-12 13:13:24 +02001264err:
1265 inflateEnd(&stream);
1266 return ret;
1267#else
1268 return NULL;
1269#endif
1270}
1271
1272/*
1273 * This has been compressed on the server side, since it can be big.
1274 * Uncompress here.
1275 */
1276static struct cmd_iolog_pdu *convert_iolog(struct fio_net_cmd *cmd)
1277{
1278 struct cmd_iolog_pdu *pdu = (struct cmd_iolog_pdu *) cmd->payload;
1279 struct cmd_iolog_pdu *ret;
Jens Axboeccefd5f2014-06-30 20:59:03 -06001280 uint64_t i;
1281 void *samples;
Jens Axboe3989b142013-04-12 13:13:24 +02001282
1283 /*
1284 * Convert if compressed and we support it. If it's not
1285 * compressed, we need not do anything.
1286 */
1287 if (le32_to_cpu(pdu->compressed)) {
1288#ifndef CONFIG_ZLIB
1289 log_err("fio: server sent compressed data by mistake\n");
1290 return NULL;
1291#endif
1292 ret = convert_iolog_gz(cmd, pdu);
1293 if (!ret) {
1294 log_err("fio: failed decompressing log\n");
1295 return NULL;
1296 }
1297 } else
1298 ret = pdu;
1299
Jens Axboeccefd5f2014-06-30 20:59:03 -06001300 ret->nr_samples = le64_to_cpu(ret->nr_samples);
Jens Axboe3989b142013-04-12 13:13:24 +02001301 ret->thread_number = le32_to_cpu(ret->thread_number);
Jens Axboe3989b142013-04-12 13:13:24 +02001302 ret->log_type = le32_to_cpu(ret->log_type);
1303 ret->compressed = le32_to_cpu(ret->compressed);
Jens Axboeccefd5f2014-06-30 20:59:03 -06001304 ret->log_offset = le32_to_cpu(ret->log_offset);
Jens Axboe3989b142013-04-12 13:13:24 +02001305
Jens Axboee8c4fb02014-07-01 16:07:59 -06001306 samples = &ret->samples[0];
Jens Axboef5ed7652012-03-14 16:28:07 +01001307 for (i = 0; i < ret->nr_samples; i++) {
Jens Axboeccefd5f2014-06-30 20:59:03 -06001308 struct io_sample *s;
Jens Axboef5ed7652012-03-14 16:28:07 +01001309
Jens Axboeccefd5f2014-06-30 20:59:03 -06001310 s = __get_sample(samples, ret->log_offset, i);
Jens Axboebac4af12014-07-03 13:42:28 -06001311 s->time = le64_to_cpu(s->time);
1312 s->val = le64_to_cpu(s->val);
1313 s->__ddir = le32_to_cpu(s->__ddir);
1314 s->bs = le32_to_cpu(s->bs);
Jens Axboeccefd5f2014-06-30 20:59:03 -06001315
1316 if (ret->log_offset) {
1317 struct io_sample_offset *so = (void *) s;
1318
1319 so->offset = le64_to_cpu(so->offset);
1320 }
Jens Axboef5ed7652012-03-14 16:28:07 +01001321 }
1322
Jens Axboe1b427252012-03-14 15:03:03 +01001323 return ret;
1324}
1325
Jens Axboede54cfd2014-11-10 20:34:00 -07001326static void sendfile_reply(int fd, struct cmd_sendfile_reply *rep,
1327 size_t size, uint64_t tag)
1328{
1329 rep->error = cpu_to_le32(rep->error);
1330 fio_net_send_cmd(fd, FIO_NET_CMD_SENDFILE, rep, size, &tag, NULL);
1331}
1332
1333static int read_data(int fd, void *data, size_t size)
1334{
1335 ssize_t ret;
1336
1337 while (size) {
1338 ret = read(fd, data, size);
1339 if (ret < 0)
1340 return errno;
1341 else if (!ret)
1342 break;
1343 else {
1344 data += ret;
1345 size -= ret;
1346 }
1347 }
1348
1349 if (size)
1350 return EAGAIN;
1351
1352 return 0;
1353}
1354
1355static int send_file(struct fio_client *client, struct cmd_sendfile *pdu,
1356 uint64_t tag)
1357{
1358 struct cmd_sendfile_reply *rep;
1359 struct stat sb;
1360 size_t size;
1361 int fd;
1362
1363 size = sizeof(*rep);
1364 rep = malloc(size);
1365
1366 if (stat((char *)pdu->path, &sb) < 0) {
1367fail:
1368 rep->error = errno;
1369 sendfile_reply(client->fd, rep, size, tag);
1370 free(rep);
1371 return 1;
1372 }
1373
1374 size += sb.st_size;
1375 rep = realloc(rep, size);
1376 rep->size = cpu_to_le32((uint32_t) sb.st_size);
1377
1378 fd = open((char *)pdu->path, O_RDONLY);
1379 if (fd == -1 )
1380 goto fail;
1381
1382 rep->error = read_data(fd, &rep->data, sb.st_size);
1383 sendfile_reply(client->fd, rep, size, tag);
1384 free(rep);
1385 close(fd);
1386 return 0;
1387}
1388
Jens Axboea5276612012-03-04 15:15:08 +01001389int fio_handle_client(struct fio_client *client)
Jens Axboe37db14f2011-09-30 17:00:42 -06001390{
Jens Axboea5276612012-03-04 15:15:08 +01001391 struct client_ops *ops = client->ops;
Jens Axboe37db14f2011-09-30 17:00:42 -06001392 struct fio_net_cmd *cmd;
1393
Jens Axboe60efd142011-10-04 13:30:11 +02001394 dprint(FD_NET, "client: handle %s\n", client->hostname);
1395
Jens Axboee951bdc2011-10-05 21:58:45 +02001396 cmd = fio_net_recv_cmd(client->fd);
1397 if (!cmd)
1398 return 0;
Jens Axboec2c94582011-10-05 20:31:30 +02001399
Jens Axboeb9d2f302012-03-08 20:36:28 +01001400 dprint(FD_NET, "client: got cmd op %s from %s (pdu=%u)\n",
1401 fio_server_op(cmd->opcode), client->hostname, cmd->pdu_len);
Jens Axboe46c48f12011-10-01 12:50:51 -06001402
Jens Axboee951bdc2011-10-05 21:58:45 +02001403 switch (cmd->opcode) {
1404 case FIO_NET_CMD_QUIT:
Jens Axboe3ec62ec2012-03-01 12:01:29 +01001405 if (ops->quit)
Jens Axboe35c0ba72012-03-14 10:56:40 +01001406 ops->quit(client, cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001407 remove_client(client);
Jens Axboee951bdc2011-10-05 21:58:45 +02001408 break;
Jens Axboe084d1c62012-03-03 20:28:07 +01001409 case FIO_NET_CMD_TEXT:
1410 convert_text(cmd);
Jens Axboe35c0ba72012-03-14 10:56:40 +01001411 ops->text(client, cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001412 break;
Jens Axboe3bf236c2012-03-03 20:35:50 +01001413 case FIO_NET_CMD_DU: {
1414 struct cmd_du_pdu *du = (struct cmd_du_pdu *) cmd->payload;
1415
1416 convert_dus(&du->dus);
1417 convert_agg(&du->agg);
1418
Stephen M. Camerondd366722012-02-24 08:17:30 +01001419 ops->disk_util(client, cmd);
Jens Axboed09a64a2011-10-13 11:38:56 +02001420 break;
Jens Axboe3bf236c2012-03-03 20:35:50 +01001421 }
1422 case FIO_NET_CMD_TS: {
1423 struct cmd_ts_pdu *p = (struct cmd_ts_pdu *) cmd->payload;
1424
1425 convert_ts(&p->ts, &p->ts);
1426 convert_gs(&p->rs, &p->rs);
1427
Jens Axboe89e5fad2012-03-05 09:21:12 +01001428 ops->thread_status(client, cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001429 break;
Jens Axboe3bf236c2012-03-03 20:35:50 +01001430 }
1431 case FIO_NET_CMD_GS: {
1432 struct group_run_stats *gs = (struct group_run_stats *) cmd->payload;
1433
1434 convert_gs(gs, gs);
1435
Jens Axboe89e5fad2012-03-05 09:21:12 +01001436 ops->group_stats(client, cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001437 break;
Jens Axboe3bf236c2012-03-03 20:35:50 +01001438 }
1439 case FIO_NET_CMD_ETA: {
1440 struct jobs_eta *je = (struct jobs_eta *) cmd->payload;
1441
Jens Axboe89c17072011-10-11 10:15:51 +02001442 remove_reply_cmd(client, cmd);
Jens Axboe3bf236c2012-03-03 20:35:50 +01001443 convert_jobs_eta(je);
Jens Axboea5276612012-03-04 15:15:08 +01001444 handle_eta(client, cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001445 break;
Jens Axboe3bf236c2012-03-03 20:35:50 +01001446 }
Jens Axboee951bdc2011-10-05 21:58:45 +02001447 case FIO_NET_CMD_PROBE:
Jens Axboe89c17072011-10-11 10:15:51 +02001448 remove_reply_cmd(client, cmd);
Stephen M. Camerondd366722012-02-24 08:17:30 +01001449 ops->probe(client, cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001450 break;
Jens Axboe5d7793a2012-03-08 19:59:16 +01001451 case FIO_NET_CMD_SERVER_START:
Jens Axboe01be0382011-10-15 14:43:41 +02001452 client->state = Client_running;
Jens Axboe85dd01e2012-03-12 14:33:16 +01001453 if (ops->job_start)
1454 ops->job_start(client, cmd);
Jens Axboe01be0382011-10-15 14:43:41 +02001455 break;
Jens Axboe85dd01e2012-03-12 14:33:16 +01001456 case FIO_NET_CMD_START: {
1457 struct cmd_start_pdu *pdu = (struct cmd_start_pdu *) cmd->payload;
1458
1459 pdu->jobs = le32_to_cpu(pdu->jobs);
1460 ops->start(client, cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001461 break;
Jens Axboe85dd01e2012-03-12 14:33:16 +01001462 }
Jens Axboe6b79c802012-03-08 10:51:36 +01001463 case FIO_NET_CMD_STOP: {
1464 struct cmd_end_pdu *pdu = (struct cmd_end_pdu *) cmd->payload;
1465
1466 convert_stop(cmd);
1467 client->state = Client_stopped;
Jens Axboe122c7722012-03-19 09:13:15 +01001468 client->error = le32_to_cpu(pdu->error);
1469 client->signal = le32_to_cpu(pdu->signal);
Jens Axboe6b79c802012-03-08 10:51:36 +01001470 ops->stop(client, cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001471 break;
Jens Axboe6b79c802012-03-08 10:51:36 +01001472 }
Jens Axboe40c60512012-03-27 16:03:04 +02001473 case FIO_NET_CMD_ADD_JOB: {
1474 struct cmd_add_job_pdu *pdu = (struct cmd_add_job_pdu *) cmd->payload;
1475
1476 client->thread_number = le32_to_cpu(pdu->thread_number);
1477 client->groupid = le32_to_cpu(pdu->groupid);
1478
Jens Axboe807f9972012-03-02 10:25:24 +01001479 if (ops->add_job)
1480 ops->add_job(client, cmd);
Jens Axboe807f9972012-03-02 10:25:24 +01001481 break;
Jens Axboe40c60512012-03-27 16:03:04 +02001482 }
Jens Axboe1b427252012-03-14 15:03:03 +01001483 case FIO_NET_CMD_IOLOG:
1484 if (ops->iolog) {
1485 struct cmd_iolog_pdu *pdu;
1486
1487 pdu = convert_iolog(cmd);
1488 ops->iolog(client, pdu);
1489 }
Jens Axboe1b427252012-03-14 15:03:03 +01001490 break;
Jens Axboe40c60512012-03-27 16:03:04 +02001491 case FIO_NET_CMD_UPDATE_JOB:
Jens Axboe40c60512012-03-27 16:03:04 +02001492 ops->update_job(client, cmd);
Jens Axboe649cee92012-03-28 09:15:32 +02001493 remove_reply_cmd(client, cmd);
Jens Axboe40c60512012-03-27 16:03:04 +02001494 break;
Jens Axboede54cfd2014-11-10 20:34:00 -07001495 case FIO_NET_CMD_VTRIGGER: {
1496 struct all_io_list *pdu = (struct all_io_list *) cmd->payload;
1497 char buf[64];
1498
1499 __verify_save_state(pdu, server_name(client, buf, sizeof(buf)));
1500 break;
1501 }
1502 case FIO_NET_CMD_SENDFILE: {
1503 struct cmd_sendfile *pdu = (struct cmd_sendfile *) cmd->payload;
1504 send_file(client, pdu, cmd->tag);
1505 break;
1506 }
Jens Axboee951bdc2011-10-05 21:58:45 +02001507 default:
Jens Axboe89c17072011-10-11 10:15:51 +02001508 log_err("fio: unknown client op: %s\n", fio_server_op(cmd->opcode));
Jens Axboee951bdc2011-10-05 21:58:45 +02001509 break;
Jens Axboe37db14f2011-09-30 17:00:42 -06001510 }
1511
Jens Axboede54cfd2014-11-10 20:34:00 -07001512 free(cmd);
Jens Axboee951bdc2011-10-05 21:58:45 +02001513 return 1;
Jens Axboe37db14f2011-09-30 17:00:42 -06001514}
Jens Axboeb66570d2011-10-01 11:11:35 -06001515
Jens Axboede54cfd2014-11-10 20:34:00 -07001516int fio_clients_send_trigger(const char *cmd)
1517{
1518 struct flist_head *entry;
1519 struct fio_client *client;
1520 size_t slen;
1521
1522 dprint(FD_NET, "client: send vtrigger: %s\n", cmd);
1523
1524 if (!cmd)
1525 slen = 0;
1526 else
1527 slen = strlen(cmd);
1528
1529 flist_for_each(entry, &client_list) {
1530 struct cmd_vtrigger_pdu *pdu;
1531
1532 client = flist_entry(entry, struct fio_client, list);
1533
1534 pdu = malloc(sizeof(*pdu) + slen);
1535 pdu->len = cpu_to_le16((uint16_t) slen);
1536 if (slen)
1537 memcpy(pdu->cmd, cmd, slen);
1538 fio_net_send_cmd(client->fd, FIO_NET_CMD_VTRIGGER, pdu,
1539 sizeof(*pdu) + slen, NULL, NULL);
1540 free(pdu);
1541 }
1542
1543 return 0;
1544}
1545
Jens Axboea5276612012-03-04 15:15:08 +01001546static void request_client_etas(struct client_ops *ops)
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001547{
1548 struct fio_client *client;
1549 struct flist_head *entry;
1550 struct client_eta *eta;
Jens Axboe82c1ed32011-10-10 08:56:18 +02001551 int skipped = 0;
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001552
1553 dprint(FD_NET, "client: request eta (%d)\n", nr_clients);
1554
Jens Axboe27b91552014-06-27 15:30:06 -06001555 eta = calloc(1, sizeof(*eta) + __THREAD_RUNSTR_SZ(REAL_MAX_JOBS));
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001556 eta->pending = nr_clients;
1557
1558 flist_for_each(entry, &client_list) {
1559 client = flist_entry(entry, struct fio_client, list);
1560
Jens Axboe82c1ed32011-10-10 08:56:18 +02001561 if (!flist_empty(&client->eta_list)) {
1562 skipped++;
1563 continue;
1564 }
Jens Axboe01be0382011-10-15 14:43:41 +02001565 if (client->state != Client_running)
1566 continue;
Jens Axboe82c1ed32011-10-10 08:56:18 +02001567
Jens Axboef77d2672011-10-10 14:36:07 +02001568 assert(!client->eta_in_flight);
Jens Axboe82c1ed32011-10-10 08:56:18 +02001569 flist_add_tail(&client->eta_list, &eta_list);
Jens Axboef77d2672011-10-10 14:36:07 +02001570 client->eta_in_flight = eta;
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001571 fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_SEND_ETA,
Jens Axboedf380932011-10-11 14:25:08 +02001572 (uintptr_t) eta, &client->cmd_list);
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001573 }
1574
Jens Axboe82c1ed32011-10-10 08:56:18 +02001575 while (skipped--)
Jens Axboea5276612012-03-04 15:15:08 +01001576 fio_client_dec_jobs_eta(eta, ops->eta);
Jens Axboe82c1ed32011-10-10 08:56:18 +02001577
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001578 dprint(FD_NET, "client: requested eta tag %p\n", eta);
1579}
1580
Jens Axboe89c17072011-10-11 10:15:51 +02001581static int client_check_cmd_timeout(struct fio_client *client,
1582 struct timeval *now)
1583{
Jens Axboe40c60512012-03-27 16:03:04 +02001584 struct fio_net_cmd_reply *reply;
Jens Axboe89c17072011-10-11 10:15:51 +02001585 struct flist_head *entry, *tmp;
1586 int ret = 0;
1587
1588 flist_for_each_safe(entry, tmp, &client->cmd_list) {
Jens Axboe40c60512012-03-27 16:03:04 +02001589 reply = flist_entry(entry, struct fio_net_cmd_reply, list);
Jens Axboe89c17072011-10-11 10:15:51 +02001590
Jens Axboe40c60512012-03-27 16:03:04 +02001591 if (mtime_since(&reply->tv, now) < FIO_NET_CLIENT_TIMEOUT)
Jens Axboe89c17072011-10-11 10:15:51 +02001592 continue;
1593
1594 log_err("fio: client %s, timeout on cmd %s\n", client->hostname,
Jens Axboe40c60512012-03-27 16:03:04 +02001595 fio_server_op(reply->opcode));
1596 flist_del(&reply->list);
1597 free(reply);
Jens Axboe89c17072011-10-11 10:15:51 +02001598 ret = 1;
1599 }
1600
1601 return flist_empty(&client->cmd_list) && ret;
1602}
1603
Jens Axboea5276612012-03-04 15:15:08 +01001604static int fio_check_clients_timed_out(void)
Jens Axboe89c17072011-10-11 10:15:51 +02001605{
1606 struct fio_client *client;
1607 struct flist_head *entry, *tmp;
1608 struct timeval tv;
1609 int ret = 0;
1610
Jens Axboe67bf9822013-01-10 11:23:19 +01001611 fio_gettime(&tv, NULL);
Jens Axboe89c17072011-10-11 10:15:51 +02001612
1613 flist_for_each_safe(entry, tmp, &client_list) {
1614 client = flist_entry(entry, struct fio_client, list);
1615
1616 if (flist_empty(&client->cmd_list))
1617 continue;
1618
1619 if (!client_check_cmd_timeout(client, &tv))
1620 continue;
1621
Jens Axboea5276612012-03-04 15:15:08 +01001622 if (client->ops->timed_out)
1623 client->ops->timed_out(client);
Jens Axboeed727a42012-03-02 12:14:40 +01001624 else
1625 log_err("fio: client %s timed out\n", client->hostname);
1626
Jens Axboe89c17072011-10-11 10:15:51 +02001627 remove_client(client);
1628 ret = 1;
1629 }
1630
1631 return ret;
1632}
1633
Stephen M. Camerondd366722012-02-24 08:17:30 +01001634int fio_handle_clients(struct client_ops *ops)
Jens Axboeb66570d2011-10-01 11:11:35 -06001635{
Jens Axboeb66570d2011-10-01 11:11:35 -06001636 struct pollfd *pfds;
Jens Axboe498c92c2011-10-17 09:14:42 +02001637 int i, ret = 0, retval = 0;
Jens Axboeb66570d2011-10-01 11:11:35 -06001638
Jens Axboe67bf9822013-01-10 11:23:19 +01001639 fio_gettime(&eta_tv, NULL);
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001640
Jens Axboeb66570d2011-10-01 11:11:35 -06001641 pfds = malloc(nr_clients * sizeof(struct pollfd));
1642
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001643 init_thread_stat(&client_ts);
1644 init_group_run_stat(&client_gs);
1645
Jens Axboeb66570d2011-10-01 11:11:35 -06001646 while (!exit_backend && nr_clients) {
Jens Axboec2cb6862012-02-23 20:56:12 +01001647 struct flist_head *entry, *tmp;
1648 struct fio_client *client;
1649
Jens Axboe82a4be12011-10-01 12:40:32 -06001650 i = 0;
Jens Axboec2cb6862012-02-23 20:56:12 +01001651 flist_for_each_safe(entry, tmp, &client_list) {
Jens Axboe82a4be12011-10-01 12:40:32 -06001652 client = flist_entry(entry, struct fio_client, list);
1653
Jens Axboea5276612012-03-04 15:15:08 +01001654 if (!client->sent_job && !client->ops->stay_connected &&
Jens Axboec2cb6862012-02-23 20:56:12 +01001655 flist_empty(&client->cmd_list)) {
1656 remove_client(client);
1657 continue;
1658 }
1659
Jens Axboe82a4be12011-10-01 12:40:32 -06001660 pfds[i].fd = client->fd;
1661 pfds[i].events = POLLIN;
1662 i++;
1663 }
1664
Jens Axboec2cb6862012-02-23 20:56:12 +01001665 if (!nr_clients)
1666 break;
1667
Jens Axboe82a4be12011-10-01 12:40:32 -06001668 assert(i == nr_clients);
1669
Jens Axboe5c2857f2011-10-04 13:14:32 +02001670 do {
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001671 struct timeval tv;
Jens Axboede54cfd2014-11-10 20:34:00 -07001672 int timeout;
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001673
Jens Axboe67bf9822013-01-10 11:23:19 +01001674 fio_gettime(&tv, NULL);
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001675 if (mtime_since(&eta_tv, &tv) >= 900) {
Jens Axboea5276612012-03-04 15:15:08 +01001676 request_client_etas(ops);
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001677 memcpy(&eta_tv, &tv, sizeof(tv));
Jens Axboe89c17072011-10-11 10:15:51 +02001678
Jens Axboea5276612012-03-04 15:15:08 +01001679 if (fio_check_clients_timed_out())
Jens Axboe89c17072011-10-11 10:15:51 +02001680 break;
Jens Axboeaf9c9fb2011-10-09 21:54:10 +02001681 }
1682
Jens Axboede54cfd2014-11-10 20:34:00 -07001683 check_trigger_file();
1684
1685 timeout = min(100u, ops->eta_msec);
1686
1687 ret = poll(pfds, nr_clients, timeout);
Jens Axboe5c2857f2011-10-04 13:14:32 +02001688 if (ret < 0) {
1689 if (errno == EINTR)
1690 continue;
1691 log_err("fio: poll clients: %s\n", strerror(errno));
1692 break;
1693 } else if (!ret)
Jens Axboeb66570d2011-10-01 11:11:35 -06001694 continue;
Jens Axboe5c2857f2011-10-04 13:14:32 +02001695 } while (ret <= 0);
Jens Axboeb66570d2011-10-01 11:11:35 -06001696
1697 for (i = 0; i < nr_clients; i++) {
1698 if (!(pfds[i].revents & POLLIN))
1699 continue;
1700
1701 client = find_client_by_fd(pfds[i].fd);
1702 if (!client) {
Jens Axboe65e1a122013-08-30 10:13:36 -06001703 log_err("fio: unknown client fd %ld\n", (long) pfds[i].fd);
Jens Axboeb66570d2011-10-01 11:11:35 -06001704 continue;
1705 }
Jens Axboea5276612012-03-04 15:15:08 +01001706 if (!fio_handle_client(client)) {
Jens Axboe28d3ab02011-10-05 20:45:37 +02001707 log_info("client: host=%s disconnected\n",
1708 client->hostname);
1709 remove_client(client);
Jens Axboe498c92c2011-10-17 09:14:42 +02001710 retval = 1;
Jens Axboe38990762011-10-17 13:31:33 +02001711 } else if (client->error)
Jens Axboe498c92c2011-10-17 09:14:42 +02001712 retval = 1;
Jens Axboe343cb4a2012-03-09 17:16:51 +01001713 fio_put_client(client);
Jens Axboeb66570d2011-10-01 11:11:35 -06001714 }
1715 }
1716
Castor Fu952b05e2013-10-31 11:00:34 -06001717 fio_client_json_fini();
1718
Jens Axboeb66570d2011-10-01 11:11:35 -06001719 free(pfds);
Jens Axboe498c92c2011-10-17 09:14:42 +02001720 return retval;
Jens Axboeb66570d2011-10-01 11:11:35 -06001721}