Commit | Line | Data |
---|---|---|
132159a5 JA |
1 | #include <stdio.h> |
2 | #include <stdlib.h> | |
3 | #include <unistd.h> | |
4 | #include <limits.h> | |
5 | #include <errno.h> | |
6 | #include <fcntl.h> | |
7 | #include <sys/poll.h> | |
8 | #include <sys/types.h> | |
9 | #include <sys/stat.h> | |
10 | #include <sys/wait.h> | |
d05c4a03 | 11 | #include <sys/socket.h> |
87aa8f19 | 12 | #include <sys/un.h> |
132159a5 JA |
13 | #include <netinet/in.h> |
14 | #include <arpa/inet.h> | |
15 | #include <netdb.h> | |
9e22ecb0 | 16 | #include <signal.h> |
132159a5 JA |
17 | |
18 | #include "fio.h" | |
dd366728 | 19 | #include "client.h" |
132159a5 | 20 | #include "server.h" |
b66570dc | 21 | #include "flist.h" |
3c5f57e3 | 22 | #include "hash.h" |
132159a5 | 23 | |
dd366728 SC |
24 | static void handle_du(struct fio_client *client, struct fio_net_cmd *cmd); |
25 | static void handle_ts(struct fio_net_cmd *cmd); | |
26 | static void handle_gs(struct fio_net_cmd *cmd); | |
27 | static void handle_eta(struct fio_client *client, struct fio_net_cmd *cmd); | |
28 | static void handle_probe(struct fio_client *client, struct fio_net_cmd *cmd); | |
084d1c6f | 29 | static void handle_text(struct fio_client *client, struct fio_net_cmd *cmd); |
dd366728 SC |
30 | |
31 | struct client_ops fio_client_ops = { | |
084d1c6f | 32 | .text_op = handle_text, |
0420ba6a JA |
33 | .disk_util = handle_du, |
34 | .thread_status = handle_ts, | |
35 | .group_stats = handle_gs, | |
36 | .eta = handle_eta, | |
37 | .probe = handle_probe, | |
dd366728 SC |
38 | }; |
39 | ||
af9c9fb3 | 40 | static struct timeval eta_tv; |
48fbb46e | 41 | |
81179eec | 42 | enum { |
5c2857f9 | 43 | Client_created = 0, |
81179eec JA |
44 | Client_connected = 1, |
45 | Client_started = 2, | |
01be038e JA |
46 | Client_running = 3, |
47 | Client_stopped = 4, | |
48 | Client_exited = 5, | |
b66570dc JA |
49 | }; |
50 | ||
51 | static FLIST_HEAD(client_list); | |
82c1ed38 | 52 | static FLIST_HEAD(eta_list); |
b66570dc | 53 | |
3f3a4542 JA |
54 | static FLIST_HEAD(arg_list); |
55 | ||
37f0c1ae JA |
56 | static struct thread_stat client_ts; |
57 | static struct group_run_stats client_gs; | |
58 | static int sum_stat_clients; | |
59 | static int sum_stat_nr; | |
60 | ||
3c5f57e3 JA |
61 | #define FIO_CLIENT_HASH_BITS 7 |
62 | #define FIO_CLIENT_HASH_SZ (1 << FIO_CLIENT_HASH_BITS) | |
63 | #define FIO_CLIENT_HASH_MASK (FIO_CLIENT_HASH_SZ - 1) | |
bebe6398 | 64 | static struct flist_head client_hash[FIO_CLIENT_HASH_SZ]; |
3c5f57e3 | 65 | |
bebe6398 | 66 | static void fio_client_add_hash(struct fio_client *client) |
3c5f57e3 JA |
67 | { |
68 | int bucket = hash_long(client->fd, FIO_CLIENT_HASH_BITS); | |
69 | ||
70 | bucket &= FIO_CLIENT_HASH_MASK; | |
bebe6398 | 71 | flist_add(&client->hash_list, &client_hash[bucket]); |
3c5f57e3 JA |
72 | } |
73 | ||
bebe6398 | 74 | static void fio_client_remove_hash(struct fio_client *client) |
3c5f57e3 | 75 | { |
bebe6398 JA |
76 | if (!flist_empty(&client->hash_list)) |
77 | flist_del_init(&client->hash_list); | |
3c5f57e3 JA |
78 | } |
79 | ||
80 | static void fio_init fio_client_hash_init(void) | |
81 | { | |
82 | int i; | |
83 | ||
bebe6398 JA |
84 | for (i = 0; i < FIO_CLIENT_HASH_SZ; i++) |
85 | INIT_FLIST_HEAD(&client_hash[i]); | |
3c5f57e3 JA |
86 | } |
87 | ||
b66570dc JA |
88 | static struct fio_client *find_client_by_fd(int fd) |
89 | { | |
3c5f57e3 | 90 | int bucket = hash_long(fd, FIO_CLIENT_HASH_BITS) & FIO_CLIENT_HASH_MASK; |
b66570dc JA |
91 | struct fio_client *client; |
92 | struct flist_head *entry; | |
93 | ||
bebe6398 JA |
94 | flist_for_each(entry, &client_hash[bucket]) { |
95 | client = flist_entry(entry, struct fio_client, hash_list); | |
b66570dc JA |
96 | |
97 | if (client->fd == fd) | |
98 | return client; | |
99 | } | |
100 | ||
101 | return NULL; | |
102 | } | |
103 | ||
b66570dc JA |
104 | static void remove_client(struct fio_client *client) |
105 | { | |
39e8e016 | 106 | dprint(FD_NET, "client: removed <%s>\n", client->hostname); |
b66570dc | 107 | flist_del(&client->list); |
3c5f57e3 | 108 | |
bebe6398 | 109 | fio_client_remove_hash(client); |
81179eec | 110 | |
82c1ed38 JA |
111 | if (!flist_empty(&client->eta_list)) { |
112 | flist_del_init(&client->eta_list); | |
3e47bd25 | 113 | fio_client_dec_jobs_eta(client->eta_in_flight, display_thread_status); |
82c1ed38 | 114 | } |
af9c9fb3 | 115 | |
b66570dc | 116 | free(client->hostname); |
81179eec JA |
117 | if (client->argv) |
118 | free(client->argv); | |
b5296ddb JA |
119 | if (client->name) |
120 | free(client->name); | |
81179eec | 121 | |
b66570dc | 122 | free(client); |
3c5f57e3 | 123 | nr_clients--; |
5fd0acbd | 124 | sum_stat_clients--; |
b66570dc | 125 | } |
132159a5 | 126 | |
fa2ea806 JA |
127 | static void __fio_client_add_cmd_option(struct fio_client *client, |
128 | const char *opt) | |
81179eec | 129 | { |
39e8e016 JA |
130 | int index; |
131 | ||
132 | index = client->argc++; | |
81179eec | 133 | client->argv = realloc(client->argv, sizeof(char *) * client->argc); |
39e8e016 JA |
134 | client->argv[index] = strdup(opt); |
135 | dprint(FD_NET, "client: add cmd %d: %s\n", index, opt); | |
81179eec JA |
136 | } |
137 | ||
fa2ea806 | 138 | void fio_client_add_cmd_option(void *cookie, const char *opt) |
81179eec | 139 | { |
bebe6398 | 140 | struct fio_client *client = cookie; |
3f3a4542 | 141 | struct flist_head *entry; |
81179eec | 142 | |
bebe6398 | 143 | if (!client || !opt) |
fa2ea806 | 144 | return; |
81179eec | 145 | |
fa2ea806 | 146 | __fio_client_add_cmd_option(client, opt); |
3f3a4542 JA |
147 | |
148 | /* | |
149 | * Duplicate arguments to shared client group | |
150 | */ | |
151 | flist_for_each(entry, &arg_list) { | |
152 | client = flist_entry(entry, struct fio_client, arg_list); | |
153 | ||
154 | __fio_client_add_cmd_option(client, opt); | |
155 | } | |
81179eec JA |
156 | } |
157 | ||
3ec62ec4 JA |
158 | struct fio_client *fio_client_add_explicit(const char *hostname, int type, |
159 | int port) | |
160 | { | |
161 | struct fio_client *client; | |
162 | ||
163 | client = malloc(sizeof(*client)); | |
164 | memset(client, 0, sizeof(*client)); | |
165 | ||
166 | INIT_FLIST_HEAD(&client->list); | |
167 | INIT_FLIST_HEAD(&client->hash_list); | |
168 | INIT_FLIST_HEAD(&client->arg_list); | |
169 | INIT_FLIST_HEAD(&client->eta_list); | |
170 | INIT_FLIST_HEAD(&client->cmd_list); | |
171 | ||
172 | client->hostname = strdup(hostname); | |
173 | ||
174 | if (type == Fio_client_socket) | |
175 | client->is_sock = 1; | |
176 | else { | |
177 | int ipv6; | |
178 | ||
179 | ipv6 = type == Fio_client_ipv6; | |
180 | if (fio_server_parse_host(hostname, &ipv6, | |
181 | &client->addr.sin_addr, | |
182 | &client->addr6.sin6_addr)) | |
183 | goto err; | |
184 | ||
185 | client->port = port; | |
186 | } | |
187 | ||
188 | client->fd = -1; | |
189 | ||
190 | __fio_client_add_cmd_option(client, "fio"); | |
191 | ||
192 | flist_add(&client->list, &client_list); | |
193 | nr_clients++; | |
194 | dprint(FD_NET, "client: added <%s>\n", client->hostname); | |
195 | return client; | |
196 | err: | |
197 | free(client); | |
198 | return NULL; | |
199 | } | |
200 | ||
bebe6398 | 201 | int fio_client_add(const char *hostname, void **cookie) |
132159a5 | 202 | { |
3f3a4542 | 203 | struct fio_client *existing = *cookie; |
b66570dc | 204 | struct fio_client *client; |
132159a5 | 205 | |
3f3a4542 JA |
206 | if (existing) { |
207 | /* | |
208 | * We always add our "exec" name as the option, hence 1 | |
209 | * means empty. | |
210 | */ | |
211 | if (existing->argc == 1) | |
212 | flist_add_tail(&existing->arg_list, &arg_list); | |
213 | else { | |
214 | while (!flist_empty(&arg_list)) | |
215 | flist_del_init(arg_list.next); | |
216 | } | |
217 | } | |
218 | ||
b66570dc | 219 | client = malloc(sizeof(*client)); |
a37f69b7 | 220 | memset(client, 0, sizeof(*client)); |
81179eec | 221 | |
3c5f57e3 | 222 | INIT_FLIST_HEAD(&client->list); |
bebe6398 | 223 | INIT_FLIST_HEAD(&client->hash_list); |
3f3a4542 | 224 | INIT_FLIST_HEAD(&client->arg_list); |
82c1ed38 | 225 | INIT_FLIST_HEAD(&client->eta_list); |
89c1707c | 226 | INIT_FLIST_HEAD(&client->cmd_list); |
3c5f57e3 | 227 | |
bebe6398 JA |
228 | if (fio_server_parse_string(hostname, &client->hostname, |
229 | &client->is_sock, &client->port, | |
811826be JA |
230 | &client->addr.sin_addr, |
231 | &client->addr6.sin6_addr, | |
232 | &client->ipv6)) | |
bebe6398 | 233 | return -1; |
87aa8f19 | 234 | |
bebe6398 | 235 | client->fd = -1; |
3c5f57e3 | 236 | |
81179eec JA |
237 | __fio_client_add_cmd_option(client, "fio"); |
238 | ||
a37f69b7 JA |
239 | flist_add(&client->list, &client_list); |
240 | nr_clients++; | |
bebe6398 JA |
241 | dprint(FD_NET, "client: added <%s>\n", client->hostname); |
242 | *cookie = client; | |
243 | return 0; | |
a37f69b7 JA |
244 | } |
245 | ||
87aa8f19 | 246 | static int fio_client_connect_ip(struct fio_client *client) |
a37f69b7 | 247 | { |
811826be JA |
248 | struct sockaddr *addr; |
249 | fio_socklen_t socklen; | |
250 | int fd, domain; | |
251 | ||
252 | if (client->ipv6) { | |
253 | client->addr6.sin6_family = AF_INET6; | |
254 | client->addr6.sin6_port = htons(client->port); | |
255 | domain = AF_INET6; | |
256 | addr = (struct sockaddr *) &client->addr6; | |
257 | socklen = sizeof(client->addr6); | |
258 | } else { | |
259 | client->addr.sin_family = AF_INET; | |
260 | client->addr.sin_port = htons(client->port); | |
261 | domain = AF_INET; | |
262 | addr = (struct sockaddr *) &client->addr; | |
263 | socklen = sizeof(client->addr); | |
264 | } | |
132159a5 | 265 | |
811826be | 266 | fd = socket(domain, SOCK_STREAM, 0); |
132159a5 JA |
267 | if (fd < 0) { |
268 | log_err("fio: socket: %s\n", strerror(errno)); | |
87aa8f19 | 269 | return -1; |
132159a5 JA |
270 | } |
271 | ||
811826be | 272 | if (connect(fd, addr, socklen) < 0) { |
132159a5 | 273 | log_err("fio: connect: %s\n", strerror(errno)); |
a7de0a11 JA |
274 | log_err("fio: failed to connect to %s:%u\n", client->hostname, |
275 | client->port); | |
b94cba47 | 276 | close(fd); |
87aa8f19 JA |
277 | return -1; |
278 | } | |
279 | ||
280 | return fd; | |
281 | } | |
282 | ||
283 | static int fio_client_connect_sock(struct fio_client *client) | |
284 | { | |
285 | struct sockaddr_un *addr = &client->addr_un; | |
286 | fio_socklen_t len; | |
287 | int fd; | |
288 | ||
289 | memset(addr, 0, sizeof(*addr)); | |
290 | addr->sun_family = AF_UNIX; | |
291 | strcpy(addr->sun_path, client->hostname); | |
292 | ||
293 | fd = socket(AF_UNIX, SOCK_STREAM, 0); | |
294 | if (fd < 0) { | |
295 | log_err("fio: socket: %s\n", strerror(errno)); | |
296 | return -1; | |
297 | } | |
298 | ||
299 | len = sizeof(addr->sun_family) + strlen(addr->sun_path) + 1; | |
300 | if (connect(fd, (struct sockaddr *) addr, len) < 0) { | |
301 | log_err("fio: connect; %s\n", strerror(errno)); | |
b94cba47 | 302 | close(fd); |
87aa8f19 | 303 | return -1; |
132159a5 JA |
304 | } |
305 | ||
87aa8f19 JA |
306 | return fd; |
307 | } | |
308 | ||
309 | static int fio_client_connect(struct fio_client *client) | |
310 | { | |
311 | int fd; | |
312 | ||
313 | dprint(FD_NET, "client: connect to host %s\n", client->hostname); | |
314 | ||
87aa8f19 JA |
315 | if (client->is_sock) |
316 | fd = fio_client_connect_sock(client); | |
317 | else | |
318 | fd = fio_client_connect_ip(client); | |
319 | ||
89c1707c JA |
320 | dprint(FD_NET, "client: %s connected %d\n", client->hostname, fd); |
321 | ||
87aa8f19 JA |
322 | if (fd < 0) |
323 | return 1; | |
324 | ||
b66570dc | 325 | client->fd = fd; |
bebe6398 | 326 | fio_client_add_hash(client); |
81179eec | 327 | client->state = Client_connected; |
132159a5 JA |
328 | return 0; |
329 | } | |
330 | ||
cc0df00a JA |
331 | void fio_clients_terminate(void) |
332 | { | |
333 | struct flist_head *entry; | |
334 | struct fio_client *client; | |
335 | ||
60efd14e JA |
336 | dprint(FD_NET, "client: terminate clients\n"); |
337 | ||
cc0df00a JA |
338 | flist_for_each(entry, &client_list) { |
339 | client = flist_entry(entry, struct fio_client, list); | |
340 | ||
89c1707c | 341 | fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_QUIT, 0, NULL); |
cc0df00a JA |
342 | } |
343 | } | |
344 | ||
345 | static void sig_int(int sig) | |
346 | { | |
bebe6398 | 347 | dprint(FD_NET, "client: got signal %d\n", sig); |
cc0df00a JA |
348 | fio_clients_terminate(); |
349 | } | |
350 | ||
351 | static void client_signal_handler(void) | |
352 | { | |
353 | struct sigaction act; | |
354 | ||
355 | memset(&act, 0, sizeof(act)); | |
356 | act.sa_handler = sig_int; | |
357 | act.sa_flags = SA_RESTART; | |
358 | sigaction(SIGINT, &act, NULL); | |
359 | ||
360 | memset(&act, 0, sizeof(act)); | |
361 | act.sa_handler = sig_int; | |
362 | act.sa_flags = SA_RESTART; | |
363 | sigaction(SIGTERM, &act, NULL); | |
364 | } | |
365 | ||
0b8f30a5 JA |
366 | static void probe_client(struct fio_client *client) |
367 | { | |
60efd14e JA |
368 | dprint(FD_NET, "client: send probe\n"); |
369 | ||
89c1707c | 370 | fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_PROBE, 0, &client->cmd_list); |
0b8f30a5 JA |
371 | } |
372 | ||
81179eec JA |
373 | static int send_client_cmd_line(struct fio_client *client) |
374 | { | |
fa2ea806 JA |
375 | struct cmd_single_line_pdu *cslp; |
376 | struct cmd_line_pdu *clp; | |
377 | unsigned long offset; | |
7f868316 | 378 | unsigned int *lens; |
fa2ea806 JA |
379 | void *pdu; |
380 | size_t mem; | |
81179eec JA |
381 | int i, ret; |
382 | ||
39e8e016 | 383 | dprint(FD_NET, "client: send cmdline %d\n", client->argc); |
60efd14e | 384 | |
7f868316 JA |
385 | lens = malloc(client->argc * sizeof(unsigned int)); |
386 | ||
fa2ea806 JA |
387 | /* |
388 | * Find out how much mem we need | |
389 | */ | |
7f868316 JA |
390 | for (i = 0, mem = 0; i < client->argc; i++) { |
391 | lens[i] = strlen(client->argv[i]) + 1; | |
392 | mem += lens[i]; | |
393 | } | |
fa2ea806 JA |
394 | |
395 | /* | |
396 | * We need one cmd_line_pdu, and argc number of cmd_single_line_pdu | |
397 | */ | |
398 | mem += sizeof(*clp) + (client->argc * sizeof(*cslp)); | |
399 | ||
400 | pdu = malloc(mem); | |
401 | clp = pdu; | |
402 | offset = sizeof(*clp); | |
403 | ||
404 | for (i = 0; i < client->argc; i++) { | |
7f868316 | 405 | uint16_t arg_len = lens[i]; |
fa2ea806 JA |
406 | |
407 | cslp = pdu + offset; | |
408 | strcpy((char *) cslp->text, client->argv[i]); | |
409 | cslp->len = cpu_to_le16(arg_len); | |
410 | offset += sizeof(*cslp) + arg_len; | |
411 | } | |
81179eec | 412 | |
7f868316 | 413 | free(lens); |
fa2ea806 | 414 | clp->lines = cpu_to_le16(client->argc); |
af9c9fb3 | 415 | ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOBLINE, pdu, mem, 0); |
81179eec JA |
416 | free(pdu); |
417 | return ret; | |
418 | } | |
419 | ||
a37f69b7 JA |
420 | int fio_clients_connect(void) |
421 | { | |
422 | struct fio_client *client; | |
423 | struct flist_head *entry, *tmp; | |
424 | int ret; | |
425 | ||
93bcfd20 BC |
426 | #ifdef WIN32 |
427 | WSADATA wsd; | |
428 | WSAStartup(MAKEWORD(2,2), &wsd); | |
429 | #endif | |
430 | ||
60efd14e JA |
431 | dprint(FD_NET, "client: connect all\n"); |
432 | ||
cc0df00a JA |
433 | client_signal_handler(); |
434 | ||
a37f69b7 JA |
435 | flist_for_each_safe(entry, tmp, &client_list) { |
436 | client = flist_entry(entry, struct fio_client, list); | |
437 | ||
438 | ret = fio_client_connect(client); | |
0b8f30a5 | 439 | if (ret) { |
a37f69b7 | 440 | remove_client(client); |
0b8f30a5 JA |
441 | continue; |
442 | } | |
443 | ||
444 | probe_client(client); | |
81179eec JA |
445 | |
446 | if (client->argc > 1) | |
447 | send_client_cmd_line(client); | |
a37f69b7 JA |
448 | } |
449 | ||
450 | return !nr_clients; | |
451 | } | |
452 | ||
132159a5 JA |
453 | /* |
454 | * Send file contents to server backend. We could use sendfile(), but to remain | |
455 | * more portable lets just read/write the darn thing. | |
456 | */ | |
a37f69b7 | 457 | static int fio_client_send_ini(struct fio_client *client, const char *filename) |
132159a5 JA |
458 | { |
459 | struct stat sb; | |
460 | char *p, *buf; | |
461 | off_t len; | |
462 | int fd, ret; | |
463 | ||
46c48f1f JA |
464 | dprint(FD_NET, "send ini %s to %s\n", filename, client->hostname); |
465 | ||
132159a5 JA |
466 | fd = open(filename, O_RDONLY); |
467 | if (fd < 0) { | |
e951bdc4 | 468 | log_err("fio: job file <%s> open: %s\n", filename, strerror(errno)); |
132159a5 JA |
469 | return 1; |
470 | } | |
471 | ||
472 | if (fstat(fd, &sb) < 0) { | |
473 | log_err("fio: job file stat: %s\n", strerror(errno)); | |
b94cba47 | 474 | close(fd); |
132159a5 JA |
475 | return 1; |
476 | } | |
477 | ||
478 | buf = malloc(sb.st_size); | |
479 | ||
480 | len = sb.st_size; | |
481 | p = buf; | |
482 | do { | |
483 | ret = read(fd, p, len); | |
484 | if (ret > 0) { | |
485 | len -= ret; | |
486 | if (!len) | |
487 | break; | |
488 | p += ret; | |
489 | continue; | |
490 | } else if (!ret) | |
491 | break; | |
492 | else if (errno == EAGAIN || errno == EINTR) | |
493 | continue; | |
494 | } while (1); | |
495 | ||
0b8f30a5 JA |
496 | if (len) { |
497 | log_err("fio: failed reading job file %s\n", filename); | |
b94cba47 | 498 | close(fd); |
c524ef72 | 499 | free(buf); |
0b8f30a5 JA |
500 | return 1; |
501 | } | |
502 | ||
c2cb6869 | 503 | client->sent_job = 1; |
af9c9fb3 | 504 | ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOB, buf, sb.st_size, 0); |
132159a5 | 505 | free(buf); |
b94cba47 | 506 | close(fd); |
132159a5 JA |
507 | return ret; |
508 | } | |
37db14fe | 509 | |
a37f69b7 JA |
510 | int fio_clients_send_ini(const char *filename) |
511 | { | |
512 | struct fio_client *client; | |
513 | struct flist_head *entry, *tmp; | |
514 | ||
515 | flist_for_each_safe(entry, tmp, &client_list) { | |
516 | client = flist_entry(entry, struct fio_client, list); | |
517 | ||
518 | if (fio_client_send_ini(client, filename)) | |
519 | remove_client(client); | |
c2cb6869 JA |
520 | |
521 | client->sent_job = 1; | |
a37f69b7 JA |
522 | } |
523 | ||
524 | return !nr_clients; | |
525 | } | |
526 | ||
a64e88da JA |
527 | static void convert_io_stat(struct io_stat *dst, struct io_stat *src) |
528 | { | |
529 | dst->max_val = le64_to_cpu(src->max_val); | |
530 | dst->min_val = le64_to_cpu(src->min_val); | |
531 | dst->samples = le64_to_cpu(src->samples); | |
802ad4a8 JA |
532 | |
533 | /* | |
534 | * Floats arrive as IEEE 754 encoded uint64_t, convert back to double | |
535 | */ | |
536 | dst->mean.u.f = fio_uint64_to_double(le64_to_cpu(dst->mean.u.i)); | |
537 | dst->S.u.f = fio_uint64_to_double(le64_to_cpu(dst->S.u.i)); | |
a64e88da JA |
538 | } |
539 | ||
540 | static void convert_ts(struct thread_stat *dst, struct thread_stat *src) | |
541 | { | |
542 | int i, j; | |
543 | ||
544 | dst->error = le32_to_cpu(src->error); | |
545 | dst->groupid = le32_to_cpu(src->groupid); | |
546 | dst->pid = le32_to_cpu(src->pid); | |
547 | dst->members = le32_to_cpu(src->members); | |
548 | ||
549 | for (i = 0; i < 2; i++) { | |
550 | convert_io_stat(&dst->clat_stat[i], &src->clat_stat[i]); | |
551 | convert_io_stat(&dst->slat_stat[i], &src->slat_stat[i]); | |
552 | convert_io_stat(&dst->lat_stat[i], &src->lat_stat[i]); | |
553 | convert_io_stat(&dst->bw_stat[i], &src->bw_stat[i]); | |
554 | } | |
555 | ||
556 | dst->usr_time = le64_to_cpu(src->usr_time); | |
557 | dst->sys_time = le64_to_cpu(src->sys_time); | |
558 | dst->ctx = le64_to_cpu(src->ctx); | |
559 | dst->minf = le64_to_cpu(src->minf); | |
560 | dst->majf = le64_to_cpu(src->majf); | |
561 | dst->clat_percentiles = le64_to_cpu(src->clat_percentiles); | |
802ad4a8 JA |
562 | |
563 | for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) { | |
564 | fio_fp64_t *fps = &src->percentile_list[i]; | |
565 | fio_fp64_t *fpd = &dst->percentile_list[i]; | |
566 | ||
567 | fpd->u.f = fio_uint64_to_double(le64_to_cpu(fps->u.i)); | |
568 | } | |
a64e88da JA |
569 | |
570 | for (i = 0; i < FIO_IO_U_MAP_NR; i++) { | |
571 | dst->io_u_map[i] = le32_to_cpu(src->io_u_map[i]); | |
572 | dst->io_u_submit[i] = le32_to_cpu(src->io_u_submit[i]); | |
573 | dst->io_u_complete[i] = le32_to_cpu(src->io_u_complete[i]); | |
574 | } | |
575 | ||
576 | for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) { | |
577 | dst->io_u_lat_u[i] = le32_to_cpu(src->io_u_lat_u[i]); | |
578 | dst->io_u_lat_m[i] = le32_to_cpu(src->io_u_lat_m[i]); | |
579 | } | |
580 | ||
581 | for (i = 0; i < 2; i++) | |
582 | for (j = 0; j < FIO_IO_U_PLAT_NR; j++) | |
583 | dst->io_u_plat[i][j] = le32_to_cpu(src->io_u_plat[i][j]); | |
584 | ||
585 | for (i = 0; i < 3; i++) { | |
586 | dst->total_io_u[i] = le64_to_cpu(src->total_io_u[i]); | |
93eee04a | 587 | dst->short_io_u[i] = le64_to_cpu(src->short_io_u[i]); |
a64e88da JA |
588 | } |
589 | ||
590 | dst->total_submit = le64_to_cpu(src->total_submit); | |
591 | dst->total_complete = le64_to_cpu(src->total_complete); | |
592 | ||
593 | for (i = 0; i < 2; i++) { | |
594 | dst->io_bytes[i] = le64_to_cpu(src->io_bytes[i]); | |
595 | dst->runtime[i] = le64_to_cpu(src->runtime[i]); | |
596 | } | |
597 | ||
598 | dst->total_run_time = le64_to_cpu(src->total_run_time); | |
599 | dst->continue_on_error = le16_to_cpu(src->continue_on_error); | |
600 | dst->total_err_count = le64_to_cpu(src->total_err_count); | |
ddcc0b69 JA |
601 | dst->first_error = le32_to_cpu(src->first_error); |
602 | dst->kb_base = le32_to_cpu(src->kb_base); | |
a64e88da JA |
603 | } |
604 | ||
605 | static void convert_gs(struct group_run_stats *dst, struct group_run_stats *src) | |
606 | { | |
607 | int i; | |
608 | ||
609 | for (i = 0; i < 2; i++) { | |
610 | dst->max_run[i] = le64_to_cpu(src->max_run[i]); | |
611 | dst->min_run[i] = le64_to_cpu(src->min_run[i]); | |
612 | dst->max_bw[i] = le64_to_cpu(src->max_bw[i]); | |
613 | dst->min_bw[i] = le64_to_cpu(src->min_bw[i]); | |
614 | dst->io_kb[i] = le64_to_cpu(src->io_kb[i]); | |
615 | dst->agg[i] = le64_to_cpu(src->agg[i]); | |
616 | } | |
617 | ||
618 | dst->kb_base = le32_to_cpu(src->kb_base); | |
619 | dst->groupid = le32_to_cpu(src->groupid); | |
620 | } | |
621 | ||
622 | static void handle_ts(struct fio_net_cmd *cmd) | |
623 | { | |
624 | struct cmd_ts_pdu *p = (struct cmd_ts_pdu *) cmd->payload; | |
625 | ||
a64e88da | 626 | show_thread_status(&p->ts, &p->rs); |
37f0c1ae JA |
627 | |
628 | if (sum_stat_clients == 1) | |
629 | return; | |
630 | ||
631 | sum_thread_stats(&client_ts, &p->ts, sum_stat_nr); | |
632 | sum_group_stats(&client_gs, &p->rs); | |
633 | ||
634 | client_ts.members++; | |
635 | client_ts.groupid = p->ts.groupid; | |
636 | ||
637 | if (++sum_stat_nr == sum_stat_clients) { | |
638 | strcpy(client_ts.name, "All clients"); | |
639 | show_thread_status(&client_ts, &client_gs); | |
640 | } | |
a64e88da JA |
641 | } |
642 | ||
643 | static void handle_gs(struct fio_net_cmd *cmd) | |
644 | { | |
645 | struct group_run_stats *gs = (struct group_run_stats *) cmd->payload; | |
646 | ||
a64e88da JA |
647 | show_group_stats(gs); |
648 | } | |
649 | ||
3bf236c0 JA |
650 | static void handle_text(struct fio_client *client, struct fio_net_cmd *cmd) |
651 | { | |
652 | struct cmd_text_pdu *pdu = (struct cmd_text_pdu *) cmd->payload; | |
653 | const char *buf = (const char *) pdu->buf; | |
654 | const char *name; | |
655 | int fio_unused ret; | |
656 | ||
657 | name = client->name ? client->name : client->hostname; | |
658 | ||
659 | if (!client->skip_newline) | |
660 | fprintf(f_out, "<%s> ", name); | |
661 | ret = fwrite(buf, pdu->buf_len, 1, f_out); | |
662 | fflush(f_out); | |
663 | client->skip_newline = strchr(buf, '\n') == NULL; | |
664 | } | |
665 | ||
d09a64a0 JA |
666 | static void convert_agg(struct disk_util_agg *agg) |
667 | { | |
668 | int i; | |
669 | ||
670 | for (i = 0; i < 2; i++) { | |
671 | agg->ios[i] = le32_to_cpu(agg->ios[i]); | |
672 | agg->merges[i] = le32_to_cpu(agg->merges[i]); | |
673 | agg->sectors[i] = le64_to_cpu(agg->sectors[i]); | |
674 | agg->ticks[i] = le32_to_cpu(agg->ticks[i]); | |
675 | } | |
676 | ||
677 | agg->io_ticks = le32_to_cpu(agg->io_ticks); | |
678 | agg->time_in_queue = le32_to_cpu(agg->time_in_queue); | |
679 | agg->slavecount = le32_to_cpu(agg->slavecount); | |
823ba54b | 680 | agg->max_util.u.f = fio_uint64_to_double(__le64_to_cpu(agg->max_util.u.i)); |
d09a64a0 JA |
681 | } |
682 | ||
683 | static void convert_dus(struct disk_util_stat *dus) | |
684 | { | |
685 | int i; | |
686 | ||
687 | for (i = 0; i < 2; i++) { | |
688 | dus->ios[i] = le32_to_cpu(dus->ios[i]); | |
689 | dus->merges[i] = le32_to_cpu(dus->merges[i]); | |
690 | dus->sectors[i] = le64_to_cpu(dus->sectors[i]); | |
691 | dus->ticks[i] = le32_to_cpu(dus->ticks[i]); | |
692 | } | |
693 | ||
694 | dus->io_ticks = le32_to_cpu(dus->io_ticks); | |
695 | dus->time_in_queue = le32_to_cpu(dus->time_in_queue); | |
696 | dus->msec = le64_to_cpu(dus->msec); | |
697 | } | |
698 | ||
699 | static void handle_du(struct fio_client *client, struct fio_net_cmd *cmd) | |
700 | { | |
701 | struct cmd_du_pdu *du = (struct cmd_du_pdu *) cmd->payload; | |
702 | ||
d09a64a0 JA |
703 | if (!client->disk_stats_shown) { |
704 | client->disk_stats_shown = 1; | |
705 | log_info("\nDisk stats (read/write):\n"); | |
706 | } | |
707 | ||
f2f788dd | 708 | print_disk_util(&du->dus, &du->agg, terse_output); |
d09a64a0 JA |
709 | } |
710 | ||
3bf236c0 | 711 | static void convert_jobs_eta(struct jobs_eta *je) |
cf451d1e | 712 | { |
cf451d1e JA |
713 | int i; |
714 | ||
715 | je->nr_running = le32_to_cpu(je->nr_running); | |
716 | je->nr_ramp = le32_to_cpu(je->nr_ramp); | |
717 | je->nr_pending = le32_to_cpu(je->nr_pending); | |
718 | je->files_open = le32_to_cpu(je->files_open); | |
cf451d1e JA |
719 | |
720 | for (i = 0; i < 2; i++) { | |
3e47bd25 JA |
721 | je->m_rate[i] = le32_to_cpu(je->m_rate[i]); |
722 | je->t_rate[i] = le32_to_cpu(je->t_rate[i]); | |
723 | je->m_iops[i] = le32_to_cpu(je->m_iops[i]); | |
724 | je->t_iops[i] = le32_to_cpu(je->t_iops[i]); | |
cf451d1e JA |
725 | je->rate[i] = le32_to_cpu(je->rate[i]); |
726 | je->iops[i] = le32_to_cpu(je->iops[i]); | |
727 | } | |
728 | ||
b51eedb7 | 729 | je->elapsed_sec = le64_to_cpu(je->elapsed_sec); |
cf451d1e | 730 | je->eta_sec = le64_to_cpu(je->eta_sec); |
48fbb46e JA |
731 | } |
732 | ||
3e47bd25 | 733 | void fio_client_sum_jobs_eta(struct jobs_eta *dst, struct jobs_eta *je) |
48fbb46e | 734 | { |
48fbb46e JA |
735 | int i; |
736 | ||
737 | dst->nr_running += je->nr_running; | |
738 | dst->nr_ramp += je->nr_ramp; | |
739 | dst->nr_pending += je->nr_pending; | |
740 | dst->files_open += je->files_open; | |
48fbb46e JA |
741 | |
742 | for (i = 0; i < 2; i++) { | |
3e47bd25 JA |
743 | dst->m_rate[i] += je->m_rate[i]; |
744 | dst->t_rate[i] += je->t_rate[i]; | |
745 | dst->m_iops[i] += je->m_iops[i]; | |
746 | dst->t_iops[i] += je->t_iops[i]; | |
48fbb46e JA |
747 | dst->rate[i] += je->rate[i]; |
748 | dst->iops[i] += je->iops[i]; | |
749 | } | |
750 | ||
751 | dst->elapsed_sec += je->elapsed_sec; | |
752 | ||
753 | if (je->eta_sec > dst->eta_sec) | |
754 | dst->eta_sec = je->eta_sec; | |
755 | } | |
756 | ||
3e47bd25 | 757 | void fio_client_dec_jobs_eta(struct client_eta *eta, void (*fn)(struct jobs_eta *)) |
82c1ed38 JA |
758 | { |
759 | if (!--eta->pending) { | |
3e47bd25 | 760 | fn(&eta->eta); |
82c1ed38 JA |
761 | free(eta); |
762 | } | |
763 | } | |
764 | ||
89c1707c JA |
765 | static void remove_reply_cmd(struct fio_client *client, struct fio_net_cmd *cmd) |
766 | { | |
767 | struct fio_net_int_cmd *icmd = NULL; | |
768 | struct flist_head *entry; | |
769 | ||
770 | flist_for_each(entry, &client->cmd_list) { | |
771 | icmd = flist_entry(entry, struct fio_net_int_cmd, list); | |
772 | ||
df380934 | 773 | if (cmd->tag == (uintptr_t) icmd) |
89c1707c JA |
774 | break; |
775 | ||
776 | icmd = NULL; | |
777 | } | |
778 | ||
779 | if (!icmd) { | |
780 | log_err("fio: client: unable to find matching tag\n"); | |
781 | return; | |
782 | } | |
783 | ||
784 | flist_del(&icmd->list); | |
785 | cmd->tag = icmd->saved_tag; | |
786 | free(icmd); | |
787 | } | |
788 | ||
82c1ed38 | 789 | static void handle_eta(struct fio_client *client, struct fio_net_cmd *cmd) |
48fbb46e JA |
790 | { |
791 | struct jobs_eta *je = (struct jobs_eta *) cmd->payload; | |
df380934 | 792 | struct client_eta *eta = (struct client_eta *) (uintptr_t) cmd->tag; |
af9c9fb3 JA |
793 | |
794 | dprint(FD_NET, "client: got eta tag %p, %d\n", eta, eta->pending); | |
cf451d1e | 795 | |
f77d2676 JA |
796 | assert(client->eta_in_flight == eta); |
797 | ||
798 | client->eta_in_flight = NULL; | |
82c1ed38 JA |
799 | flist_del_init(&client->eta_list); |
800 | ||
3e47bd25 JA |
801 | fio_client_sum_jobs_eta(&eta->eta, je); |
802 | fio_client_dec_jobs_eta(eta, display_thread_status); | |
cf451d1e JA |
803 | } |
804 | ||
b5296ddb | 805 | static void handle_probe(struct fio_client *client, struct fio_net_cmd *cmd) |
2e03b4b2 JA |
806 | { |
807 | struct cmd_probe_pdu *probe = (struct cmd_probe_pdu *) cmd->payload; | |
d2333358 JA |
808 | const char *os, *arch; |
809 | char bit[16]; | |
2e03b4b2 | 810 | |
cca84643 JA |
811 | os = fio_get_os_string(probe->os); |
812 | if (!os) | |
813 | os = "unknown"; | |
814 | ||
815 | arch = fio_get_arch_string(probe->arch); | |
816 | if (!arch) | |
817 | os = "unknown"; | |
818 | ||
d2333358 | 819 | sprintf(bit, "%d-bit", probe->bpp * 8); |
38fdef22 JA |
820 | |
821 | log_info("hostname=%s, be=%u, %s, os=%s, arch=%s, fio=%u.%u.%u\n", | |
822 | probe->hostname, probe->bigendian, bit, os, arch, | |
823 | probe->fio_major, probe->fio_minor, probe->fio_patch); | |
b5296ddb JA |
824 | |
825 | if (!client->name) | |
826 | client->name = strdup((char *) probe->hostname); | |
2e03b4b2 JA |
827 | } |
828 | ||
11e950bd JA |
829 | static void handle_start(struct fio_client *client, struct fio_net_cmd *cmd) |
830 | { | |
831 | struct cmd_start_pdu *pdu = (struct cmd_start_pdu *) cmd->payload; | |
832 | ||
833 | client->state = Client_started; | |
834 | client->jobs = le32_to_cpu(pdu->jobs); | |
835 | } | |
836 | ||
837 | static void handle_stop(struct fio_client *client, struct fio_net_cmd *cmd) | |
838 | { | |
839 | struct cmd_end_pdu *pdu = (struct cmd_end_pdu *) cmd->payload; | |
840 | ||
841 | client->state = Client_stopped; | |
842 | client->error = le32_to_cpu(pdu->error); | |
498c92c2 JA |
843 | |
844 | if (client->error) | |
845 | log_info("client <%s>: exited with error %d\n", client->hostname, client->error); | |
11e950bd JA |
846 | } |
847 | ||
084d1c6f JA |
848 | static void convert_text(struct fio_net_cmd *cmd) |
849 | { | |
850 | struct cmd_text_pdu *pdu = (struct cmd_text_pdu *) cmd->payload; | |
851 | ||
852 | pdu->level = le32_to_cpu(pdu->level); | |
853 | pdu->buf_len = le32_to_cpu(pdu->buf_len); | |
854 | pdu->log_sec = le64_to_cpu(pdu->log_sec); | |
855 | pdu->log_usec = le64_to_cpu(pdu->log_usec); | |
856 | } | |
857 | ||
3e47bd25 | 858 | int fio_handle_client(struct fio_client *client, struct client_ops *ops) |
37db14fe JA |
859 | { |
860 | struct fio_net_cmd *cmd; | |
861 | ||
60efd14e JA |
862 | dprint(FD_NET, "client: handle %s\n", client->hostname); |
863 | ||
e951bdc4 JA |
864 | cmd = fio_net_recv_cmd(client->fd); |
865 | if (!cmd) | |
866 | return 0; | |
c2c94585 | 867 | |
89c1707c JA |
868 | dprint(FD_NET, "client: got cmd op %s from %s\n", |
869 | fio_server_op(cmd->opcode), client->hostname); | |
46c48f1f | 870 | |
e951bdc4 JA |
871 | switch (cmd->opcode) { |
872 | case FIO_NET_CMD_QUIT: | |
3ec62ec4 JA |
873 | if (ops->quit) |
874 | ops->quit(client); | |
e951bdc4 JA |
875 | remove_client(client); |
876 | free(cmd); | |
877 | break; | |
084d1c6f JA |
878 | case FIO_NET_CMD_TEXT: |
879 | convert_text(cmd); | |
880 | ops->text_op(client, cmd); | |
e951bdc4 JA |
881 | free(cmd); |
882 | break; | |
3bf236c0 JA |
883 | case FIO_NET_CMD_DU: { |
884 | struct cmd_du_pdu *du = (struct cmd_du_pdu *) cmd->payload; | |
885 | ||
886 | convert_dus(&du->dus); | |
887 | convert_agg(&du->agg); | |
888 | ||
dd366728 | 889 | ops->disk_util(client, cmd); |
d09a64a0 JA |
890 | free(cmd); |
891 | break; | |
3bf236c0 JA |
892 | } |
893 | case FIO_NET_CMD_TS: { | |
894 | struct cmd_ts_pdu *p = (struct cmd_ts_pdu *) cmd->payload; | |
895 | ||
896 | convert_ts(&p->ts, &p->ts); | |
897 | convert_gs(&p->rs, &p->rs); | |
898 | ||
dd366728 | 899 | ops->thread_status(cmd); |
e951bdc4 JA |
900 | free(cmd); |
901 | break; | |
3bf236c0 JA |
902 | } |
903 | case FIO_NET_CMD_GS: { | |
904 | struct group_run_stats *gs = (struct group_run_stats *) cmd->payload; | |
905 | ||
906 | convert_gs(gs, gs); | |
907 | ||
dd366728 | 908 | ops->group_stats(cmd); |
e951bdc4 JA |
909 | free(cmd); |
910 | break; | |
3bf236c0 JA |
911 | } |
912 | case FIO_NET_CMD_ETA: { | |
913 | struct jobs_eta *je = (struct jobs_eta *) cmd->payload; | |
914 | ||
89c1707c | 915 | remove_reply_cmd(client, cmd); |
3bf236c0 | 916 | convert_jobs_eta(je); |
dd366728 | 917 | ops->eta(client, cmd); |
e951bdc4 JA |
918 | free(cmd); |
919 | break; | |
3bf236c0 | 920 | } |
e951bdc4 | 921 | case FIO_NET_CMD_PROBE: |
89c1707c | 922 | remove_reply_cmd(client, cmd); |
dd366728 | 923 | ops->probe(client, cmd); |
e951bdc4 JA |
924 | free(cmd); |
925 | break; | |
01be038e JA |
926 | case FIO_NET_CMD_RUN: |
927 | client->state = Client_running; | |
928 | free(cmd); | |
929 | break; | |
e951bdc4 | 930 | case FIO_NET_CMD_START: |
11e950bd | 931 | handle_start(client, cmd); |
e951bdc4 JA |
932 | free(cmd); |
933 | break; | |
934 | case FIO_NET_CMD_STOP: | |
11e950bd | 935 | handle_stop(client, cmd); |
e951bdc4 JA |
936 | free(cmd); |
937 | break; | |
807f9971 JA |
938 | case FIO_NET_CMD_ADD_JOB: |
939 | if (ops->add_job) | |
940 | ops->add_job(client, cmd); | |
941 | free(cmd); | |
942 | break; | |
e951bdc4 | 943 | default: |
89c1707c | 944 | log_err("fio: unknown client op: %s\n", fio_server_op(cmd->opcode)); |
e951bdc4 JA |
945 | free(cmd); |
946 | break; | |
37db14fe JA |
947 | } |
948 | ||
e951bdc4 | 949 | return 1; |
37db14fe | 950 | } |
b66570dc | 951 | |
af9c9fb3 JA |
952 | static void request_client_etas(void) |
953 | { | |
954 | struct fio_client *client; | |
955 | struct flist_head *entry; | |
956 | struct client_eta *eta; | |
82c1ed38 | 957 | int skipped = 0; |
af9c9fb3 JA |
958 | |
959 | dprint(FD_NET, "client: request eta (%d)\n", nr_clients); | |
960 | ||
af9c9fb3 JA |
961 | eta = malloc(sizeof(*eta)); |
962 | memset(&eta->eta, 0, sizeof(eta->eta)); | |
963 | eta->pending = nr_clients; | |
964 | ||
965 | flist_for_each(entry, &client_list) { | |
966 | client = flist_entry(entry, struct fio_client, list); | |
967 | ||
82c1ed38 JA |
968 | if (!flist_empty(&client->eta_list)) { |
969 | skipped++; | |
970 | continue; | |
971 | } | |
01be038e JA |
972 | if (client->state != Client_running) |
973 | continue; | |
82c1ed38 | 974 | |
f77d2676 | 975 | assert(!client->eta_in_flight); |
82c1ed38 | 976 | flist_add_tail(&client->eta_list, &eta_list); |
f77d2676 | 977 | client->eta_in_flight = eta; |
af9c9fb3 | 978 | fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_SEND_ETA, |
df380934 | 979 | (uintptr_t) eta, &client->cmd_list); |
af9c9fb3 JA |
980 | } |
981 | ||
82c1ed38 | 982 | while (skipped--) |
3e47bd25 | 983 | fio_client_dec_jobs_eta(eta, display_thread_status); |
82c1ed38 | 984 | |
af9c9fb3 JA |
985 | dprint(FD_NET, "client: requested eta tag %p\n", eta); |
986 | } | |
987 | ||
89c1707c JA |
988 | static int client_check_cmd_timeout(struct fio_client *client, |
989 | struct timeval *now) | |
990 | { | |
991 | struct fio_net_int_cmd *cmd; | |
992 | struct flist_head *entry, *tmp; | |
993 | int ret = 0; | |
994 | ||
995 | flist_for_each_safe(entry, tmp, &client->cmd_list) { | |
996 | cmd = flist_entry(entry, struct fio_net_int_cmd, list); | |
997 | ||
998 | if (mtime_since(&cmd->tv, now) < FIO_NET_CLIENT_TIMEOUT) | |
999 | continue; | |
1000 | ||
1001 | log_err("fio: client %s, timeout on cmd %s\n", client->hostname, | |
1002 | fio_server_op(cmd->cmd.opcode)); | |
1003 | flist_del(&cmd->list); | |
1004 | free(cmd); | |
1005 | ret = 1; | |
1006 | } | |
1007 | ||
1008 | return flist_empty(&client->cmd_list) && ret; | |
1009 | } | |
1010 | ||
ed727a46 | 1011 | static int fio_client_timed_out(struct client_ops *ops) |
89c1707c JA |
1012 | { |
1013 | struct fio_client *client; | |
1014 | struct flist_head *entry, *tmp; | |
1015 | struct timeval tv; | |
1016 | int ret = 0; | |
1017 | ||
1018 | gettimeofday(&tv, NULL); | |
1019 | ||
1020 | flist_for_each_safe(entry, tmp, &client_list) { | |
1021 | client = flist_entry(entry, struct fio_client, list); | |
1022 | ||
1023 | if (flist_empty(&client->cmd_list)) | |
1024 | continue; | |
1025 | ||
1026 | if (!client_check_cmd_timeout(client, &tv)) | |
1027 | continue; | |
1028 | ||
ed727a46 JA |
1029 | if (ops->timed_out) |
1030 | ops->timed_out(client); | |
1031 | else | |
1032 | log_err("fio: client %s timed out\n", client->hostname); | |
1033 | ||
89c1707c JA |
1034 | remove_client(client); |
1035 | ret = 1; | |
1036 | } | |
1037 | ||
1038 | return ret; | |
1039 | } | |
1040 | ||
dd366728 | 1041 | int fio_handle_clients(struct client_ops *ops) |
b66570dc | 1042 | { |
b66570dc | 1043 | struct pollfd *pfds; |
498c92c2 | 1044 | int i, ret = 0, retval = 0; |
b66570dc | 1045 | |
af9c9fb3 JA |
1046 | gettimeofday(&eta_tv, NULL); |
1047 | ||
b66570dc JA |
1048 | pfds = malloc(nr_clients * sizeof(struct pollfd)); |
1049 | ||
37f0c1ae JA |
1050 | sum_stat_clients = nr_clients; |
1051 | init_thread_stat(&client_ts); | |
1052 | init_group_run_stat(&client_gs); | |
1053 | ||
82a4be1b | 1054 | while (!exit_backend && nr_clients) { |
c2cb6869 JA |
1055 | struct flist_head *entry, *tmp; |
1056 | struct fio_client *client; | |
1057 | ||
82a4be1b | 1058 | i = 0; |
c2cb6869 | 1059 | flist_for_each_safe(entry, tmp, &client_list) { |
82a4be1b | 1060 | client = flist_entry(entry, struct fio_client, list); |
b66570dc | 1061 | |
3ec62ec4 | 1062 | if (!client->sent_job && !ops->stay_connected && |
c2cb6869 JA |
1063 | flist_empty(&client->cmd_list)) { |
1064 | remove_client(client); | |
1065 | continue; | |
1066 | } | |
1067 | ||
82a4be1b JA |
1068 | pfds[i].fd = client->fd; |
1069 | pfds[i].events = POLLIN; | |
1070 | i++; | |
1071 | } | |
1072 | ||
c2cb6869 JA |
1073 | if (!nr_clients) |
1074 | break; | |
1075 | ||
82a4be1b | 1076 | assert(i == nr_clients); |
b66570dc | 1077 | |
5c2857f9 | 1078 | do { |
af9c9fb3 JA |
1079 | struct timeval tv; |
1080 | ||
1081 | gettimeofday(&tv, NULL); | |
1082 | if (mtime_since(&eta_tv, &tv) >= 900) { | |
1083 | request_client_etas(); | |
1084 | memcpy(&eta_tv, &tv, sizeof(tv)); | |
89c1707c | 1085 | |
ed727a46 | 1086 | if (fio_client_timed_out(ops)) |
89c1707c | 1087 | break; |
af9c9fb3 JA |
1088 | } |
1089 | ||
5c2857f9 JA |
1090 | ret = poll(pfds, nr_clients, 100); |
1091 | if (ret < 0) { | |
1092 | if (errno == EINTR) | |
1093 | continue; | |
1094 | log_err("fio: poll clients: %s\n", strerror(errno)); | |
1095 | break; | |
1096 | } else if (!ret) | |
b66570dc | 1097 | continue; |
5c2857f9 | 1098 | } while (ret <= 0); |
b66570dc JA |
1099 | |
1100 | for (i = 0; i < nr_clients; i++) { | |
1101 | if (!(pfds[i].revents & POLLIN)) | |
1102 | continue; | |
1103 | ||
1104 | client = find_client_by_fd(pfds[i].fd); | |
1105 | if (!client) { | |
3c5f57e3 | 1106 | log_err("fio: unknown client fd %d\n", pfds[i].fd); |
b66570dc JA |
1107 | continue; |
1108 | } | |
3e47bd25 | 1109 | if (!fio_handle_client(client, ops)) { |
28d3ab07 JA |
1110 | log_info("client: host=%s disconnected\n", |
1111 | client->hostname); | |
1112 | remove_client(client); | |
498c92c2 | 1113 | retval = 1; |
38990764 | 1114 | } else if (client->error) |
498c92c2 | 1115 | retval = 1; |
b66570dc JA |
1116 | } |
1117 | } | |
1118 | ||
1119 | free(pfds); | |
498c92c2 | 1120 | return retval; |
b66570dc | 1121 | } |