server: ensure each connection sets up its own sk_out
[fio.git] / server.c
... / ...
CommitLineData
1#include <stdio.h>
2#include <stdlib.h>
3#include <stdarg.h>
4#include <unistd.h>
5#include <limits.h>
6#include <errno.h>
7#include <sys/poll.h>
8#include <sys/types.h>
9#include <sys/wait.h>
10#include <sys/socket.h>
11#include <sys/stat.h>
12#include <sys/un.h>
13#include <sys/uio.h>
14#include <netinet/in.h>
15#include <arpa/inet.h>
16#include <netdb.h>
17#include <syslog.h>
18#include <signal.h>
19#ifdef CONFIG_ZLIB
20#include <zlib.h>
21#endif
22
23#include "fio.h"
24#include "options.h"
25#include "server.h"
26#include "crc/crc16.h"
27#include "lib/ieee754.h"
28#include "verify.h"
29#include "smalloc.h"
30
31int fio_net_port = FIO_NET_PORT;
32
33int exit_backend = 0;
34
35enum {
36 SK_F_FREE = 1,
37 SK_F_COPY = 2,
38 SK_F_SIMPLE = 4,
39 SK_F_VEC = 8,
40};
41
42struct sk_entry {
43 struct flist_head list; /* link on sk_out->list */
44 int flags; /* SK_F_* */
45 int opcode; /* Actual command fields */
46 void *buf;
47 off_t size;
48 uint64_t *tagptr;
49 struct flist_head next; /* Other sk_entry's, if linked command */
50};
51
52struct sk_out {
53 unsigned int refs;
54
55 int sk;
56 struct fio_mutex *lock;
57 struct flist_head list;
58 struct fio_mutex *wait;
59};
60
61static char *fio_server_arg;
62static char *bind_sock;
63static struct sockaddr_in saddr_in;
64static struct sockaddr_in6 saddr_in6;
65static int use_ipv6;
66#ifdef CONFIG_ZLIB
67static unsigned int has_zlib = 1;
68#else
69static unsigned int has_zlib = 0;
70#endif
71static unsigned int use_zlib;
72static char me[128];
73
74static pthread_key_t sk_out_key;
75
76struct fio_fork_item {
77 struct flist_head list;
78 int exitval;
79 int signal;
80 int exited;
81 pid_t pid;
82};
83
84struct cmd_reply {
85 struct fio_mutex lock;
86 void *data;
87 size_t size;
88 int error;
89};
90
91static const char *fio_server_ops[FIO_NET_CMD_NR] = {
92 "",
93 "QUIT",
94 "EXIT",
95 "JOB",
96 "JOBLINE",
97 "TEXT",
98 "TS",
99 "GS",
100 "SEND_ETA",
101 "ETA",
102 "PROBE",
103 "START",
104 "STOP",
105 "DISK_UTIL",
106 "SERVER_START",
107 "ADD_JOB",
108 "RUN",
109 "IOLOG",
110 "UPDATE_JOB",
111 "LOAD_FILE",
112 "VTRIGGER",
113 "SENDFILE",
114};
115
116static void sk_lock(struct sk_out *sk_out)
117{
118 fio_mutex_down(sk_out->lock);
119}
120
121static void sk_unlock(struct sk_out *sk_out)
122{
123 fio_mutex_up(sk_out->lock);
124}
125
126void sk_out_assign(struct sk_out *sk_out)
127{
128 if (!sk_out)
129 return;
130
131 sk_lock(sk_out);
132 sk_out->refs++;
133 sk_unlock(sk_out);
134 pthread_setspecific(sk_out_key, sk_out);
135}
136
137static void sk_out_free(struct sk_out *sk_out)
138{
139 fio_mutex_remove(sk_out->lock);
140 fio_mutex_remove(sk_out->wait);
141 sfree(sk_out);
142}
143
144static int __sk_out_drop(struct sk_out *sk_out)
145{
146 if (sk_out) {
147 int refs;
148
149 sk_lock(sk_out);
150 refs = --sk_out->refs;
151 sk_unlock(sk_out);
152
153 if (!refs) {
154 sk_out_free(sk_out);
155 return 0;
156 }
157 }
158
159 return 1;
160}
161
162void sk_out_drop(void)
163{
164 struct sk_out *sk_out;
165
166 sk_out = pthread_getspecific(sk_out_key);
167 if (!__sk_out_drop(sk_out))
168 pthread_setspecific(sk_out_key, NULL);
169}
170
171const char *fio_server_op(unsigned int op)
172{
173 static char buf[32];
174
175 if (op < FIO_NET_CMD_NR)
176 return fio_server_ops[op];
177
178 sprintf(buf, "UNKNOWN/%d", op);
179 return buf;
180}
181
182static ssize_t iov_total_len(const struct iovec *iov, int count)
183{
184 ssize_t ret = 0;
185
186 while (count--) {
187 ret += iov->iov_len;
188 iov++;
189 }
190
191 return ret;
192}
193
194static int fio_sendv_data(int sk, struct iovec *iov, int count)
195{
196 ssize_t total_len = iov_total_len(iov, count);
197 ssize_t ret;
198
199 do {
200 ret = writev(sk, iov, count);
201 if (ret > 0) {
202 total_len -= ret;
203 if (!total_len)
204 break;
205
206 while (ret) {
207 if (ret >= iov->iov_len) {
208 ret -= iov->iov_len;
209 iov++;
210 continue;
211 }
212 iov->iov_base += ret;
213 iov->iov_len -= ret;
214 ret = 0;
215 }
216 } else if (!ret)
217 break;
218 else if (errno == EAGAIN || errno == EINTR)
219 continue;
220 else
221 break;
222 } while (!exit_backend);
223
224 if (!total_len)
225 return 0;
226
227 return 1;
228}
229
230int fio_send_data(int sk, const void *p, unsigned int len)
231{
232 struct iovec iov = { .iov_base = (void *) p, .iov_len = len };
233
234 assert(len <= sizeof(struct fio_net_cmd) + FIO_SERVER_MAX_FRAGMENT_PDU);
235
236 return fio_sendv_data(sk, &iov, 1);
237}
238
239int fio_recv_data(int sk, void *p, unsigned int len)
240{
241 do {
242 int ret = recv(sk, p, len, MSG_WAITALL);
243
244 if (ret > 0) {
245 len -= ret;
246 if (!len)
247 break;
248 p += ret;
249 continue;
250 } else if (!ret)
251 break;
252 else if (errno == EAGAIN || errno == EINTR)
253 continue;
254 else
255 break;
256 } while (!exit_backend);
257
258 if (!len)
259 return 0;
260
261 return -1;
262}
263
264static int verify_convert_cmd(struct fio_net_cmd *cmd)
265{
266 uint16_t crc;
267
268 cmd->cmd_crc16 = le16_to_cpu(cmd->cmd_crc16);
269 cmd->pdu_crc16 = le16_to_cpu(cmd->pdu_crc16);
270
271 crc = fio_crc16(cmd, FIO_NET_CMD_CRC_SZ);
272 if (crc != cmd->cmd_crc16) {
273 log_err("fio: server bad crc on command (got %x, wanted %x)\n",
274 cmd->cmd_crc16, crc);
275 return 1;
276 }
277
278 cmd->version = le16_to_cpu(cmd->version);
279 cmd->opcode = le16_to_cpu(cmd->opcode);
280 cmd->flags = le32_to_cpu(cmd->flags);
281 cmd->tag = le64_to_cpu(cmd->tag);
282 cmd->pdu_len = le32_to_cpu(cmd->pdu_len);
283
284 switch (cmd->version) {
285 case FIO_SERVER_VER:
286 break;
287 default:
288 log_err("fio: bad server cmd version %d\n", cmd->version);
289 return 1;
290 }
291
292 if (cmd->pdu_len > FIO_SERVER_MAX_FRAGMENT_PDU) {
293 log_err("fio: command payload too large: %u\n", cmd->pdu_len);
294 return 1;
295 }
296
297 return 0;
298}
299
300/*
301 * Read (and defragment, if necessary) incoming commands
302 */
303struct fio_net_cmd *fio_net_recv_cmd(int sk)
304{
305 struct fio_net_cmd cmd, *tmp, *cmdret = NULL;
306 size_t cmd_size = 0, pdu_offset = 0;
307 uint16_t crc;
308 int ret, first = 1;
309 void *pdu = NULL;
310
311 do {
312 ret = fio_recv_data(sk, &cmd, sizeof(cmd));
313 if (ret)
314 break;
315
316 /* We have a command, verify it and swap if need be */
317 ret = verify_convert_cmd(&cmd);
318 if (ret)
319 break;
320
321 if (first) {
322 /* if this is text, add room for \0 at the end */
323 cmd_size = sizeof(cmd) + cmd.pdu_len + 1;
324 assert(!cmdret);
325 } else
326 cmd_size += cmd.pdu_len;
327
328 if (cmd_size / 1024 > FIO_SERVER_MAX_CMD_MB * 1024) {
329 log_err("fio: cmd+pdu too large (%llu)\n", (unsigned long long) cmd_size);
330 ret = 1;
331 break;
332 }
333
334 tmp = realloc(cmdret, cmd_size);
335 if (!tmp) {
336 log_err("fio: server failed allocating cmd\n");
337 ret = 1;
338 break;
339 }
340 cmdret = tmp;
341
342 if (first)
343 memcpy(cmdret, &cmd, sizeof(cmd));
344 else if (cmdret->opcode != cmd.opcode) {
345 log_err("fio: fragment opcode mismatch (%d != %d)\n",
346 cmdret->opcode, cmd.opcode);
347 ret = 1;
348 break;
349 }
350
351 if (!cmd.pdu_len)
352 break;
353
354 /* There's payload, get it */
355 pdu = (void *) cmdret->payload + pdu_offset;
356 ret = fio_recv_data(sk, pdu, cmd.pdu_len);
357 if (ret)
358 break;
359
360 /* Verify payload crc */
361 crc = fio_crc16(pdu, cmd.pdu_len);
362 if (crc != cmd.pdu_crc16) {
363 log_err("fio: server bad crc on payload ");
364 log_err("(got %x, wanted %x)\n", cmd.pdu_crc16, crc);
365 ret = 1;
366 break;
367 }
368
369 pdu_offset += cmd.pdu_len;
370 if (!first)
371 cmdret->pdu_len += cmd.pdu_len;
372 first = 0;
373 } while (cmd.flags & FIO_NET_CMD_F_MORE);
374
375 if (ret) {
376 free(cmdret);
377 cmdret = NULL;
378 } else if (cmdret) {
379 /* zero-terminate text input */
380 if (cmdret->pdu_len) {
381 if (cmdret->opcode == FIO_NET_CMD_TEXT) {
382 struct cmd_text_pdu *__pdu = (struct cmd_text_pdu *) cmdret->payload;
383 char *buf = (char *) __pdu->buf;
384
385 buf[__pdu->buf_len] = '\0';
386 } else if (cmdret->opcode == FIO_NET_CMD_JOB) {
387 struct cmd_job_pdu *__pdu = (struct cmd_job_pdu *) cmdret->payload;
388 char *buf = (char *) __pdu->buf;
389 int len = le32_to_cpu(__pdu->buf_len);
390
391 buf[len] = '\0';
392 }
393 }
394
395 /* frag flag is internal */
396 cmdret->flags &= ~FIO_NET_CMD_F_MORE;
397 }
398
399 return cmdret;
400}
401
402static void add_reply(uint64_t tag, struct flist_head *list)
403{
404 struct fio_net_cmd_reply *reply;
405
406 reply = (struct fio_net_cmd_reply *) (uintptr_t) tag;
407 flist_add_tail(&reply->list, list);
408}
409
410static uint64_t alloc_reply(uint64_t tag, uint16_t opcode)
411{
412 struct fio_net_cmd_reply *reply;
413
414 reply = calloc(1, sizeof(*reply));
415 INIT_FLIST_HEAD(&reply->list);
416 fio_gettime(&reply->tv, NULL);
417 reply->saved_tag = tag;
418 reply->opcode = opcode;
419
420 return (uintptr_t) reply;
421}
422
423static void free_reply(uint64_t tag)
424{
425 struct fio_net_cmd_reply *reply;
426
427 reply = (struct fio_net_cmd_reply *) (uintptr_t) tag;
428 free(reply);
429}
430
431void fio_net_cmd_crc_pdu(struct fio_net_cmd *cmd, const void *pdu)
432{
433 uint32_t pdu_len;
434
435 cmd->cmd_crc16 = __cpu_to_le16(fio_crc16(cmd, FIO_NET_CMD_CRC_SZ));
436
437 pdu_len = le32_to_cpu(cmd->pdu_len);
438 cmd->pdu_crc16 = __cpu_to_le16(fio_crc16(pdu, pdu_len));
439}
440
441void fio_net_cmd_crc(struct fio_net_cmd *cmd)
442{
443 fio_net_cmd_crc_pdu(cmd, cmd->payload);
444}
445
446int fio_net_send_cmd(int fd, uint16_t opcode, const void *buf, off_t size,
447 uint64_t *tagptr, struct flist_head *list)
448{
449 struct fio_net_cmd *cmd = NULL;
450 size_t this_len, cur_len = 0;
451 uint64_t tag;
452 int ret;
453
454 if (list) {
455 assert(tagptr);
456 tag = *tagptr = alloc_reply(*tagptr, opcode);
457 } else
458 tag = tagptr ? *tagptr : 0;
459
460 do {
461 this_len = size;
462 if (this_len > FIO_SERVER_MAX_FRAGMENT_PDU)
463 this_len = FIO_SERVER_MAX_FRAGMENT_PDU;
464
465 if (!cmd || cur_len < sizeof(*cmd) + this_len) {
466 if (cmd)
467 free(cmd);
468
469 cur_len = sizeof(*cmd) + this_len;
470 cmd = malloc(cur_len);
471 }
472
473 fio_init_net_cmd(cmd, opcode, buf, this_len, tag);
474
475 if (this_len < size)
476 cmd->flags = __cpu_to_le32(FIO_NET_CMD_F_MORE);
477
478 fio_net_cmd_crc(cmd);
479
480 ret = fio_send_data(fd, cmd, sizeof(*cmd) + this_len);
481 size -= this_len;
482 buf += this_len;
483 } while (!ret && size);
484
485 if (list) {
486 if (ret)
487 free_reply(tag);
488 else
489 add_reply(tag, list);
490 }
491
492 if (cmd)
493 free(cmd);
494
495 return ret;
496}
497
498struct sk_entry *fio_net_prep_cmd(uint16_t opcode, void *buf, off_t size,
499 uint64_t *tagptr, int flags)
500{
501 struct sk_entry *entry;
502
503 entry = smalloc(sizeof(*entry));
504 INIT_FLIST_HEAD(&entry->next);
505 entry->opcode = opcode;
506 if (flags & SK_F_COPY) {
507 entry->buf = smalloc(size);
508 memcpy(entry->buf, buf, size);
509 } else
510 entry->buf = buf;
511 entry->size = size;
512 entry->tagptr = tagptr;
513 entry->flags = flags;
514
515 return entry;
516}
517
518static void fio_net_queue_entry(struct sk_entry *entry)
519{
520 struct sk_out *sk_out = pthread_getspecific(sk_out_key);
521
522 sk_lock(sk_out);
523 flist_add_tail(&entry->list, &sk_out->list);
524 sk_unlock(sk_out);
525
526 fio_mutex_up(sk_out->wait);
527}
528
529static int fio_net_queue_cmd(uint16_t opcode, void *buf, off_t size,
530 uint64_t *tagptr, int flags)
531{
532 struct sk_entry *entry;
533
534 entry = fio_net_prep_cmd(opcode, buf, size, tagptr, flags);
535 fio_net_queue_entry(entry);
536 return 0;
537}
538
539static int fio_net_send_simple_stack_cmd(int sk, uint16_t opcode, uint64_t tag)
540{
541 struct fio_net_cmd cmd;
542
543 fio_init_net_cmd(&cmd, opcode, NULL, 0, tag);
544 fio_net_cmd_crc(&cmd);
545
546 return fio_send_data(sk, &cmd, sizeof(cmd));
547}
548
549/*
550 * If 'list' is non-NULL, then allocate and store the sent command for
551 * later verification.
552 */
553int fio_net_send_simple_cmd(int sk, uint16_t opcode, uint64_t tag,
554 struct flist_head *list)
555{
556 int ret;
557
558 if (list)
559 tag = alloc_reply(tag, opcode);
560
561 ret = fio_net_send_simple_stack_cmd(sk, opcode, tag);
562 if (ret) {
563 if (list)
564 free_reply(tag);
565
566 return ret;
567 }
568
569 if (list)
570 add_reply(tag, list);
571
572 return 0;
573}
574
575static int fio_net_queue_quit(void)
576{
577 dprint(FD_NET, "server: sending quit\n");
578
579 return fio_net_queue_cmd(FIO_NET_CMD_QUIT, NULL, 0, 0, SK_F_SIMPLE);
580}
581
582int fio_net_send_quit(int sk)
583{
584 dprint(FD_NET, "server: sending quit\n");
585
586 return fio_net_send_simple_cmd(sk, FIO_NET_CMD_QUIT, 0, NULL);
587}
588
589static int fio_net_send_ack(struct fio_net_cmd *cmd, int error, int signal)
590{
591 struct cmd_end_pdu epdu;
592 uint64_t tag = 0;
593
594 if (cmd)
595 tag = cmd->tag;
596
597 epdu.error = __cpu_to_le32(error);
598 epdu.signal = __cpu_to_le32(signal);
599 return fio_net_queue_cmd(FIO_NET_CMD_STOP, &epdu, sizeof(epdu), &tag, SK_F_COPY);
600}
601
602static int fio_net_queue_stop(int error, int signal)
603{
604 dprint(FD_NET, "server: sending stop (%d, %d)\n", error, signal);
605 return fio_net_send_ack(NULL, error, signal);
606}
607
608static void fio_server_add_fork_item(pid_t pid, struct flist_head *list)
609{
610 struct fio_fork_item *ffi;
611
612 ffi = malloc(sizeof(*ffi));
613 ffi->exitval = 0;
614 ffi->signal = 0;
615 ffi->exited = 0;
616 ffi->pid = pid;
617 flist_add_tail(&ffi->list, list);
618}
619
620static void fio_server_add_conn_pid(struct flist_head *conn_list, pid_t pid)
621{
622 dprint(FD_NET, "server: forked off connection job (pid=%u)\n", (int) pid);
623 fio_server_add_fork_item(pid, conn_list);
624}
625
626static void fio_server_add_job_pid(struct flist_head *job_list, pid_t pid)
627{
628 dprint(FD_NET, "server: forked off job job (pid=%u)\n", (int) pid);
629 fio_server_add_fork_item(pid, job_list);
630}
631
632static void fio_server_check_fork_item(struct fio_fork_item *ffi)
633{
634 int ret, status;
635
636 ret = waitpid(ffi->pid, &status, WNOHANG);
637 if (ret < 0) {
638 if (errno == ECHILD) {
639 log_err("fio: connection pid %u disappeared\n", (int) ffi->pid);
640 ffi->exited = 1;
641 } else
642 log_err("fio: waitpid: %s\n", strerror(errno));
643 } else if (ret == ffi->pid) {
644 if (WIFSIGNALED(status)) {
645 ffi->signal = WTERMSIG(status);
646 ffi->exited = 1;
647 }
648 if (WIFEXITED(status)) {
649 if (WEXITSTATUS(status))
650 ffi->exitval = WEXITSTATUS(status);
651 ffi->exited = 1;
652 }
653 }
654}
655
656static void fio_server_fork_item_done(struct fio_fork_item *ffi, bool stop)
657{
658 dprint(FD_NET, "pid %u exited, sig=%u, exitval=%d\n", (int) ffi->pid, ffi->signal, ffi->exitval);
659
660 /*
661 * Fold STOP and QUIT...
662 */
663 if (stop) {
664 fio_net_queue_stop(ffi->exitval, ffi->signal);
665 fio_net_queue_quit();
666 }
667
668 flist_del(&ffi->list);
669 free(ffi);
670}
671
672static void fio_server_check_fork_items(struct flist_head *list, bool stop)
673{
674 struct flist_head *entry, *tmp;
675 struct fio_fork_item *ffi;
676
677 flist_for_each_safe(entry, tmp, list) {
678 ffi = flist_entry(entry, struct fio_fork_item, list);
679
680 fio_server_check_fork_item(ffi);
681
682 if (ffi->exited)
683 fio_server_fork_item_done(ffi, stop);
684 }
685}
686
687static void fio_server_check_jobs(struct flist_head *job_list)
688{
689 fio_server_check_fork_items(job_list, true);
690}
691
692static void fio_server_check_conns(struct flist_head *conn_list)
693{
694 fio_server_check_fork_items(conn_list, false);
695}
696
697static int handle_load_file_cmd(struct fio_net_cmd *cmd)
698{
699 struct cmd_load_file_pdu *pdu = (struct cmd_load_file_pdu *) cmd->payload;
700 void *file_name = pdu->file;
701 struct cmd_start_pdu spdu;
702
703 dprint(FD_NET, "server: loading local file %s\n", (char *) file_name);
704
705 pdu->name_len = le16_to_cpu(pdu->name_len);
706 pdu->client_type = le16_to_cpu(pdu->client_type);
707
708 if (parse_jobs_ini(file_name, 0, 0, pdu->client_type)) {
709 fio_net_queue_quit();
710 return -1;
711 }
712
713 spdu.jobs = cpu_to_le32(thread_number);
714 spdu.stat_outputs = cpu_to_le32(stat_number);
715 fio_net_queue_cmd(FIO_NET_CMD_START, &spdu, sizeof(spdu), NULL, SK_F_COPY);
716 return 0;
717}
718
719static int handle_run_cmd(struct sk_out *sk_out, struct flist_head *job_list,
720 struct fio_net_cmd *cmd)
721{
722 pid_t pid;
723 int ret;
724
725 fio_time_init();
726 set_genesis_time();
727
728 pid = fork();
729 if (pid) {
730 fio_server_add_job_pid(job_list, pid);
731 return 0;
732 }
733
734 ret = fio_backend(sk_out);
735 free_threads_shm();
736 _exit(ret);
737}
738
739static int handle_job_cmd(struct fio_net_cmd *cmd)
740{
741 struct cmd_job_pdu *pdu = (struct cmd_job_pdu *) cmd->payload;
742 void *buf = pdu->buf;
743 struct cmd_start_pdu spdu;
744
745 pdu->buf_len = le32_to_cpu(pdu->buf_len);
746 pdu->client_type = le32_to_cpu(pdu->client_type);
747
748 if (parse_jobs_ini(buf, 1, 0, pdu->client_type)) {
749 fio_net_queue_quit();
750 return -1;
751 }
752
753 spdu.jobs = cpu_to_le32(thread_number);
754 spdu.stat_outputs = cpu_to_le32(stat_number);
755
756 fio_net_queue_cmd(FIO_NET_CMD_START, &spdu, sizeof(spdu), NULL, SK_F_COPY);
757 return 0;
758}
759
760static int handle_jobline_cmd(struct fio_net_cmd *cmd)
761{
762 void *pdu = cmd->payload;
763 struct cmd_single_line_pdu *cslp;
764 struct cmd_line_pdu *clp;
765 unsigned long offset;
766 struct cmd_start_pdu spdu;
767 char **argv;
768 int i;
769
770 clp = pdu;
771 clp->lines = le16_to_cpu(clp->lines);
772 clp->client_type = le16_to_cpu(clp->client_type);
773 argv = malloc(clp->lines * sizeof(char *));
774 offset = sizeof(*clp);
775
776 dprint(FD_NET, "server: %d command line args\n", clp->lines);
777
778 for (i = 0; i < clp->lines; i++) {
779 cslp = pdu + offset;
780 argv[i] = (char *) cslp->text;
781
782 offset += sizeof(*cslp) + le16_to_cpu(cslp->len);
783 dprint(FD_NET, "server: %d: %s\n", i, argv[i]);
784 }
785
786 if (parse_cmd_line(clp->lines, argv, clp->client_type)) {
787 fio_net_queue_quit();
788 free(argv);
789 return -1;
790 }
791
792 free(argv);
793
794 spdu.jobs = cpu_to_le32(thread_number);
795 spdu.stat_outputs = cpu_to_le32(stat_number);
796
797 fio_net_queue_cmd(FIO_NET_CMD_START, &spdu, sizeof(spdu), NULL, SK_F_COPY);
798 return 0;
799}
800
801static int handle_probe_cmd(struct fio_net_cmd *cmd)
802{
803 struct cmd_client_probe_pdu *pdu = (struct cmd_client_probe_pdu *) cmd->payload;
804 struct cmd_probe_reply_pdu probe;
805 uint64_t tag = cmd->tag;
806
807 dprint(FD_NET, "server: sending probe reply\n");
808
809 strcpy(me, (char *) pdu->server);
810
811 memset(&probe, 0, sizeof(probe));
812 gethostname((char *) probe.hostname, sizeof(probe.hostname));
813#ifdef CONFIG_BIG_ENDIAN
814 probe.bigendian = 1;
815#endif
816 strncpy((char *) probe.fio_version, fio_version_string, sizeof(probe.fio_version));
817
818 probe.os = FIO_OS;
819 probe.arch = FIO_ARCH;
820 probe.bpp = sizeof(void *);
821 probe.cpus = __cpu_to_le32(cpus_online());
822
823 /*
824 * If the client supports compression and we do too, then enable it
825 */
826 if (has_zlib && le64_to_cpu(pdu->flags) & FIO_PROBE_FLAG_ZLIB) {
827 probe.flags = __cpu_to_le64(FIO_PROBE_FLAG_ZLIB);
828 use_zlib = 1;
829 } else {
830 probe.flags = 0;
831 use_zlib = 0;
832 }
833
834 return fio_net_queue_cmd(FIO_NET_CMD_PROBE, &probe, sizeof(probe), &tag, SK_F_COPY);
835}
836
837static int handle_send_eta_cmd(struct fio_net_cmd *cmd)
838{
839 struct jobs_eta *je;
840 uint64_t tag = cmd->tag;
841 size_t size;
842 int i;
843
844 dprint(FD_NET, "server sending status\n");
845
846 /*
847 * Fake ETA return if we don't have a local one, otherwise the client
848 * will end up timing out waiting for a response to the ETA request
849 */
850 je = get_jobs_eta(true, &size);
851 if (!je) {
852 size = sizeof(*je);
853 je = calloc(1, size);
854 } else {
855 je->nr_running = cpu_to_le32(je->nr_running);
856 je->nr_ramp = cpu_to_le32(je->nr_ramp);
857 je->nr_pending = cpu_to_le32(je->nr_pending);
858 je->nr_setting_up = cpu_to_le32(je->nr_setting_up);
859 je->files_open = cpu_to_le32(je->files_open);
860
861 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
862 je->m_rate[i] = cpu_to_le32(je->m_rate[i]);
863 je->t_rate[i] = cpu_to_le32(je->t_rate[i]);
864 je->m_iops[i] = cpu_to_le32(je->m_iops[i]);
865 je->t_iops[i] = cpu_to_le32(je->t_iops[i]);
866 je->rate[i] = cpu_to_le32(je->rate[i]);
867 je->iops[i] = cpu_to_le32(je->iops[i]);
868 }
869
870 je->elapsed_sec = cpu_to_le64(je->elapsed_sec);
871 je->eta_sec = cpu_to_le64(je->eta_sec);
872 je->nr_threads = cpu_to_le32(je->nr_threads);
873 je->is_pow2 = cpu_to_le32(je->is_pow2);
874 je->unit_base = cpu_to_le32(je->unit_base);
875 }
876
877 fio_net_queue_cmd(FIO_NET_CMD_ETA, je, size, &tag, SK_F_FREE);
878 return 0;
879}
880
881static int send_update_job_reply(uint64_t __tag, int error)
882{
883 uint64_t tag = __tag;
884 uint32_t pdu_error;
885
886 pdu_error = __cpu_to_le32(error);
887 return fio_net_queue_cmd(FIO_NET_CMD_UPDATE_JOB, &pdu_error, sizeof(pdu_error), &tag, SK_F_COPY);
888}
889
890static int handle_update_job_cmd(struct fio_net_cmd *cmd)
891{
892 struct cmd_add_job_pdu *pdu = (struct cmd_add_job_pdu *) cmd->payload;
893 struct thread_data *td;
894 uint32_t tnumber;
895
896 tnumber = le32_to_cpu(pdu->thread_number);
897
898 dprint(FD_NET, "server: updating options for job %u\n", tnumber);
899
900 if (!tnumber || tnumber > thread_number) {
901 send_update_job_reply(cmd->tag, ENODEV);
902 return 0;
903 }
904
905 td = &threads[tnumber - 1];
906 convert_thread_options_to_cpu(&td->o, &pdu->top);
907 send_update_job_reply(cmd->tag, 0);
908 return 0;
909}
910
911static int handle_trigger_cmd(struct fio_net_cmd *cmd)
912{
913 struct cmd_vtrigger_pdu *pdu = (struct cmd_vtrigger_pdu *) cmd->payload;
914 char *buf = (char *) pdu->cmd;
915 struct all_io_list *rep;
916 size_t sz;
917
918 pdu->len = le16_to_cpu(pdu->len);
919 buf[pdu->len] = '\0';
920
921 rep = get_all_io_list(IO_LIST_ALL, &sz);
922 if (!rep) {
923 struct all_io_list state;
924
925 state.threads = cpu_to_le64((uint64_t) 0);
926 fio_net_queue_cmd(FIO_NET_CMD_VTRIGGER, &state, sizeof(state), NULL, SK_F_COPY);
927 } else
928 fio_net_queue_cmd(FIO_NET_CMD_VTRIGGER, rep, sz, NULL, SK_F_FREE);
929
930 exec_trigger(buf);
931 return 0;
932}
933
934static int handle_command(struct sk_out *sk_out, struct flist_head *job_list,
935 struct fio_net_cmd *cmd)
936{
937 int ret;
938
939 dprint(FD_NET, "server: got op [%s], pdu=%u, tag=%llx\n",
940 fio_server_op(cmd->opcode), cmd->pdu_len,
941 (unsigned long long) cmd->tag);
942
943 switch (cmd->opcode) {
944 case FIO_NET_CMD_QUIT:
945 fio_terminate_threads(TERMINATE_ALL);
946 ret = 0;
947 break;
948 case FIO_NET_CMD_EXIT:
949 exit_backend = 1;
950 return -1;
951 case FIO_NET_CMD_LOAD_FILE:
952 ret = handle_load_file_cmd(cmd);
953 break;
954 case FIO_NET_CMD_JOB:
955 ret = handle_job_cmd(cmd);
956 break;
957 case FIO_NET_CMD_JOBLINE:
958 ret = handle_jobline_cmd(cmd);
959 break;
960 case FIO_NET_CMD_PROBE:
961 ret = handle_probe_cmd(cmd);
962 break;
963 case FIO_NET_CMD_SEND_ETA:
964 ret = handle_send_eta_cmd(cmd);
965 break;
966 case FIO_NET_CMD_RUN:
967 ret = handle_run_cmd(sk_out, job_list, cmd);
968 break;
969 case FIO_NET_CMD_UPDATE_JOB:
970 ret = handle_update_job_cmd(cmd);
971 break;
972 case FIO_NET_CMD_VTRIGGER:
973 ret = handle_trigger_cmd(cmd);
974 break;
975 case FIO_NET_CMD_SENDFILE: {
976 struct cmd_sendfile_reply *in;
977 struct cmd_reply *rep;
978
979 rep = (struct cmd_reply *) (uintptr_t) cmd->tag;
980
981 in = (struct cmd_sendfile_reply *) cmd->payload;
982 in->size = le32_to_cpu(in->size);
983 in->error = le32_to_cpu(in->error);
984 if (in->error) {
985 ret = 1;
986 rep->error = in->error;
987 } else {
988 ret = 0;
989 rep->data = smalloc(in->size);
990 if (!rep->data) {
991 ret = 1;
992 rep->error = ENOMEM;
993 } else {
994 rep->size = in->size;
995 memcpy(rep->data, in->data, in->size);
996 }
997 }
998 fio_mutex_up(&rep->lock);
999 break;
1000 }
1001 default:
1002 log_err("fio: unknown opcode: %s\n", fio_server_op(cmd->opcode));
1003 ret = 1;
1004 }
1005
1006 return ret;
1007}
1008
1009/*
1010 * Send a command with a separate PDU, not inlined in the command
1011 */
1012static int fio_send_cmd_ext_pdu(int sk, uint16_t opcode, const void *buf,
1013 off_t size, uint64_t tag, uint32_t flags)
1014{
1015 struct fio_net_cmd cmd;
1016 struct iovec iov[2];
1017
1018 iov[0].iov_base = (void *) &cmd;
1019 iov[0].iov_len = sizeof(cmd);
1020 iov[1].iov_base = (void *) buf;
1021 iov[1].iov_len = size;
1022
1023 __fio_init_net_cmd(&cmd, opcode, size, tag);
1024 cmd.flags = __cpu_to_le32(flags);
1025 fio_net_cmd_crc_pdu(&cmd, buf);
1026
1027 return fio_sendv_data(sk, iov, 2);
1028}
1029
1030static void finish_entry(struct sk_entry *entry)
1031{
1032 if (entry->flags & SK_F_FREE)
1033 free(entry->buf);
1034 else if (entry->flags & SK_F_COPY)
1035 sfree(entry->buf);
1036
1037 sfree(entry);
1038}
1039
1040static void entry_set_flags_tag(struct sk_entry *entry, struct flist_head *list,
1041 unsigned int *flags, uint64_t *tag)
1042{
1043 if (!flist_empty(list))
1044 *flags = FIO_NET_CMD_F_MORE;
1045 else
1046 *flags = 0;
1047
1048 if (entry->tagptr)
1049 *tag = *entry->tagptr;
1050 else
1051 *tag = 0;
1052}
1053
1054static int send_vec_entry(struct sk_out *sk_out, struct sk_entry *first)
1055{
1056 unsigned int flags;
1057 uint64_t tag;
1058 int ret;
1059
1060 entry_set_flags_tag(first, &first->next, &flags, &tag);
1061
1062 ret = fio_send_cmd_ext_pdu(sk_out->sk, first->opcode, first->buf, first->size, tag, flags);
1063
1064 while (!flist_empty(&first->next)) {
1065 struct sk_entry *next;
1066
1067 next = flist_first_entry(&first->next, struct sk_entry, list);
1068 flist_del_init(&next->list);
1069
1070 entry_set_flags_tag(next, &first->next, &flags, &tag);
1071
1072 ret += fio_send_cmd_ext_pdu(sk_out->sk, next->opcode, next->buf, next->size, tag, flags);
1073 finish_entry(next);
1074 }
1075
1076 return ret;
1077}
1078
1079static int handle_sk_entry(struct sk_out *sk_out, struct sk_entry *entry)
1080{
1081 int ret;
1082
1083 if (entry->flags & SK_F_VEC)
1084 ret = send_vec_entry(sk_out, entry);
1085 if (entry->flags & SK_F_SIMPLE) {
1086 uint64_t tag = 0;
1087
1088 if (entry->tagptr)
1089 tag = *entry->tagptr;
1090
1091 ret = fio_net_send_simple_cmd(sk_out->sk, entry->opcode, tag, NULL);
1092 } else
1093 ret = fio_net_send_cmd(sk_out->sk, entry->opcode, entry->buf, entry->size, entry->tagptr, NULL);
1094
1095 if (ret)
1096 log_err("fio: failed handling cmd %s\n", fio_server_op(entry->opcode));
1097
1098 finish_entry(entry);
1099 return ret;
1100}
1101
1102static int handle_xmits(struct sk_out *sk_out)
1103{
1104 struct sk_entry *entry;
1105 FLIST_HEAD(list);
1106 int ret = 0;
1107
1108 sk_lock(sk_out);
1109 if (flist_empty(&sk_out->list)) {
1110 sk_unlock(sk_out);
1111 return 0;
1112 }
1113
1114 flist_splice_init(&sk_out->list, &list);
1115 sk_unlock(sk_out);
1116
1117 while (!flist_empty(&list)) {
1118 entry = flist_entry(list.next, struct sk_entry, list);
1119 flist_del(&entry->list);
1120 ret += handle_sk_entry(sk_out, entry);
1121 }
1122
1123 return ret;
1124}
1125
1126static int handle_connection(struct sk_out *sk_out)
1127{
1128 struct fio_net_cmd *cmd = NULL;
1129 FLIST_HEAD(job_list);
1130 int ret = 0;
1131
1132 reset_fio_state();
1133
1134 /* read forever */
1135 while (!exit_backend) {
1136 struct pollfd pfd = {
1137 .fd = sk_out->sk,
1138 .events = POLLIN,
1139 };
1140
1141 ret = 0;
1142 do {
1143 int timeout = 1000;
1144
1145 if (!flist_empty(&job_list))
1146 timeout = 100;
1147
1148 handle_xmits(sk_out);
1149
1150 ret = poll(&pfd, 1, 0);
1151 if (ret < 0) {
1152 if (errno == EINTR)
1153 break;
1154 log_err("fio: poll: %s\n", strerror(errno));
1155 break;
1156 } else if (!ret) {
1157 fio_server_check_jobs(&job_list);
1158 fio_mutex_down_timeout(sk_out->wait, timeout);
1159 continue;
1160 }
1161
1162 if (pfd.revents & POLLIN)
1163 break;
1164 if (pfd.revents & (POLLERR|POLLHUP)) {
1165 ret = 1;
1166 break;
1167 }
1168 } while (!exit_backend);
1169
1170 fio_server_check_jobs(&job_list);
1171
1172 if (ret < 0)
1173 break;
1174
1175 cmd = fio_net_recv_cmd(sk_out->sk);
1176 if (!cmd) {
1177 ret = -1;
1178 break;
1179 }
1180
1181 ret = handle_command(sk_out, &job_list, cmd);
1182 if (ret)
1183 break;
1184
1185 free(cmd);
1186 cmd = NULL;
1187 }
1188
1189 if (cmd)
1190 free(cmd);
1191
1192 handle_xmits(sk_out);
1193
1194 close(sk_out->sk);
1195 __sk_out_drop(sk_out);
1196 _exit(ret);
1197}
1198
1199/* get the address on this host bound by the input socket,
1200 * whether it is ipv6 or ipv4 */
1201
1202int get_my_addr_str(int sk)
1203{
1204 struct sockaddr_in6 myaddr6 = { 0, };
1205 struct sockaddr_in myaddr4 = { 0, };
1206 struct sockaddr *sockaddr_p;
1207 char *net_addr;
1208 socklen_t len;
1209 int ret;
1210
1211 if (use_ipv6) {
1212 len = sizeof(myaddr6);
1213 sockaddr_p = (struct sockaddr * )&myaddr6;
1214 net_addr = (char * )&myaddr6.sin6_addr;
1215 } else {
1216 len = sizeof(myaddr4);
1217 sockaddr_p = (struct sockaddr * )&myaddr4;
1218 net_addr = (char * )&myaddr4.sin_addr;
1219 }
1220
1221 ret = getsockname(sk, sockaddr_p, &len);
1222 if (ret) {
1223 log_err("fio: getsockaddr: %s\n", strerror(errno));
1224 return -1;
1225 }
1226
1227 if (!inet_ntop(use_ipv6?AF_INET6:AF_INET, net_addr, client_sockaddr_str, INET6_ADDRSTRLEN - 1)) {
1228 log_err("inet_ntop: failed to convert addr to string\n");
1229 return -1;
1230 }
1231
1232 dprint(FD_NET, "fio server bound to addr %s\n", client_sockaddr_str);
1233 return 0;
1234}
1235
1236static int accept_loop(struct sk_out *sk_out, int listen_sk)
1237{
1238 struct sockaddr_in addr;
1239 struct sockaddr_in6 addr6;
1240 socklen_t len = use_ipv6 ? sizeof(addr6) : sizeof(addr);
1241 struct pollfd pfd;
1242 int ret = 0, sk, exitval = 0;
1243 FLIST_HEAD(conn_list);
1244
1245 dprint(FD_NET, "server enter accept loop\n");
1246
1247 fio_set_fd_nonblocking(listen_sk, "server");
1248
1249 while (!exit_backend) {
1250 const char *from;
1251 char buf[64];
1252 pid_t pid;
1253
1254 pfd.fd = listen_sk;
1255 pfd.events = POLLIN;
1256 do {
1257 int timeout = 1000;
1258
1259 if (!flist_empty(&conn_list))
1260 timeout = 100;
1261
1262 ret = poll(&pfd, 1, timeout);
1263 if (ret < 0) {
1264 if (errno == EINTR)
1265 break;
1266 log_err("fio: poll: %s\n", strerror(errno));
1267 break;
1268 } else if (!ret) {
1269 fio_server_check_conns(&conn_list);
1270 continue;
1271 }
1272
1273 if (pfd.revents & POLLIN)
1274 break;
1275 } while (!exit_backend);
1276
1277 fio_server_check_conns(&conn_list);
1278
1279 if (exit_backend || ret < 0)
1280 break;
1281
1282 if (use_ipv6)
1283 sk = accept(listen_sk, (struct sockaddr *) &addr6, &len);
1284 else
1285 sk = accept(listen_sk, (struct sockaddr *) &addr, &len);
1286
1287 if (sk < 0) {
1288 log_err("fio: accept: %s\n", strerror(errno));
1289 return -1;
1290 }
1291
1292 if (use_ipv6)
1293 from = inet_ntop(AF_INET6, (struct sockaddr *) &addr6.sin6_addr, buf, sizeof(buf));
1294 else
1295 from = inet_ntop(AF_INET, (struct sockaddr *) &addr.sin_addr, buf, sizeof(buf));
1296
1297 dprint(FD_NET, "server: connect from %s\n", from);
1298
1299 sk_out = smalloc(sizeof(*sk_out));
1300 sk_out->sk = sk;
1301 INIT_FLIST_HEAD(&sk_out->list);
1302 sk_out->lock = fio_mutex_init(FIO_MUTEX_UNLOCKED);
1303 sk_out->wait = fio_mutex_init(FIO_MUTEX_LOCKED);
1304
1305 pid = fork();
1306 if (pid) {
1307 close(sk);
1308 fio_server_add_conn_pid(&conn_list, pid);
1309 continue;
1310 }
1311
1312 /* exits */
1313 get_my_addr_str(sk); /* if error, it's already logged, non-fatal */
1314 sk_out_assign(sk_out);
1315 handle_connection(sk_out);
1316 }
1317
1318 return exitval;
1319}
1320
1321int fio_server_text_output(int level, const char *buf, size_t len)
1322{
1323 struct sk_out *sk_out = pthread_getspecific(sk_out_key);
1324 struct cmd_text_pdu *pdu;
1325 unsigned int tlen;
1326 struct timeval tv;
1327
1328 if (!sk_out || sk_out->sk == -1)
1329 return -1;
1330
1331 tlen = sizeof(*pdu) + len;
1332 pdu = malloc(tlen);
1333
1334 pdu->level = __cpu_to_le32(level);
1335 pdu->buf_len = __cpu_to_le32(len);
1336
1337 gettimeofday(&tv, NULL);
1338 pdu->log_sec = __cpu_to_le64(tv.tv_sec);
1339 pdu->log_usec = __cpu_to_le64(tv.tv_usec);
1340
1341 memcpy(pdu->buf, buf, len);
1342
1343 fio_net_queue_cmd(FIO_NET_CMD_TEXT, pdu, tlen, NULL, SK_F_COPY);
1344 free(pdu);
1345 return len;
1346}
1347
1348static void convert_io_stat(struct io_stat *dst, struct io_stat *src)
1349{
1350 dst->max_val = cpu_to_le64(src->max_val);
1351 dst->min_val = cpu_to_le64(src->min_val);
1352 dst->samples = cpu_to_le64(src->samples);
1353
1354 /*
1355 * Encode to IEEE 754 for network transfer
1356 */
1357 dst->mean.u.i = cpu_to_le64(fio_double_to_uint64(src->mean.u.f));
1358 dst->S.u.i = cpu_to_le64(fio_double_to_uint64(src->S.u.f));
1359}
1360
1361static void convert_gs(struct group_run_stats *dst, struct group_run_stats *src)
1362{
1363 int i;
1364
1365 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
1366 dst->max_run[i] = cpu_to_le64(src->max_run[i]);
1367 dst->min_run[i] = cpu_to_le64(src->min_run[i]);
1368 dst->max_bw[i] = cpu_to_le64(src->max_bw[i]);
1369 dst->min_bw[i] = cpu_to_le64(src->min_bw[i]);
1370 dst->io_kb[i] = cpu_to_le64(src->io_kb[i]);
1371 dst->agg[i] = cpu_to_le64(src->agg[i]);
1372 }
1373
1374 dst->kb_base = cpu_to_le32(src->kb_base);
1375 dst->unit_base = cpu_to_le32(src->unit_base);
1376 dst->groupid = cpu_to_le32(src->groupid);
1377 dst->unified_rw_rep = cpu_to_le32(src->unified_rw_rep);
1378}
1379
1380/*
1381 * Send a CMD_TS, which packs struct thread_stat and group_run_stats
1382 * into a single payload.
1383 */
1384void fio_server_send_ts(struct thread_stat *ts, struct group_run_stats *rs)
1385{
1386 struct cmd_ts_pdu p;
1387 int i, j;
1388
1389 dprint(FD_NET, "server sending end stats\n");
1390
1391 memset(&p, 0, sizeof(p));
1392
1393 strncpy(p.ts.name, ts->name, FIO_JOBNAME_SIZE - 1);
1394 strncpy(p.ts.verror, ts->verror, FIO_VERROR_SIZE - 1);
1395 strncpy(p.ts.description, ts->description, FIO_JOBDESC_SIZE - 1);
1396
1397 p.ts.error = cpu_to_le32(ts->error);
1398 p.ts.thread_number = cpu_to_le32(ts->thread_number);
1399 p.ts.groupid = cpu_to_le32(ts->groupid);
1400 p.ts.pid = cpu_to_le32(ts->pid);
1401 p.ts.members = cpu_to_le32(ts->members);
1402 p.ts.unified_rw_rep = cpu_to_le32(ts->unified_rw_rep);
1403
1404 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
1405 convert_io_stat(&p.ts.clat_stat[i], &ts->clat_stat[i]);
1406 convert_io_stat(&p.ts.slat_stat[i], &ts->slat_stat[i]);
1407 convert_io_stat(&p.ts.lat_stat[i], &ts->lat_stat[i]);
1408 convert_io_stat(&p.ts.bw_stat[i], &ts->bw_stat[i]);
1409 }
1410
1411 p.ts.usr_time = cpu_to_le64(ts->usr_time);
1412 p.ts.sys_time = cpu_to_le64(ts->sys_time);
1413 p.ts.ctx = cpu_to_le64(ts->ctx);
1414 p.ts.minf = cpu_to_le64(ts->minf);
1415 p.ts.majf = cpu_to_le64(ts->majf);
1416 p.ts.clat_percentiles = cpu_to_le64(ts->clat_percentiles);
1417 p.ts.percentile_precision = cpu_to_le64(ts->percentile_precision);
1418
1419 for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) {
1420 fio_fp64_t *src = &ts->percentile_list[i];
1421 fio_fp64_t *dst = &p.ts.percentile_list[i];
1422
1423 dst->u.i = cpu_to_le64(fio_double_to_uint64(src->u.f));
1424 }
1425
1426 for (i = 0; i < FIO_IO_U_MAP_NR; i++) {
1427 p.ts.io_u_map[i] = cpu_to_le32(ts->io_u_map[i]);
1428 p.ts.io_u_submit[i] = cpu_to_le32(ts->io_u_submit[i]);
1429 p.ts.io_u_complete[i] = cpu_to_le32(ts->io_u_complete[i]);
1430 }
1431
1432 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) {
1433 p.ts.io_u_lat_u[i] = cpu_to_le32(ts->io_u_lat_u[i]);
1434 p.ts.io_u_lat_m[i] = cpu_to_le32(ts->io_u_lat_m[i]);
1435 }
1436
1437 for (i = 0; i < DDIR_RWDIR_CNT; i++)
1438 for (j = 0; j < FIO_IO_U_PLAT_NR; j++)
1439 p.ts.io_u_plat[i][j] = cpu_to_le32(ts->io_u_plat[i][j]);
1440
1441 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
1442 p.ts.total_io_u[i] = cpu_to_le64(ts->total_io_u[i]);
1443 p.ts.short_io_u[i] = cpu_to_le64(ts->short_io_u[i]);
1444 p.ts.drop_io_u[i] = cpu_to_le64(ts->drop_io_u[i]);
1445 }
1446
1447 p.ts.total_submit = cpu_to_le64(ts->total_submit);
1448 p.ts.total_complete = cpu_to_le64(ts->total_complete);
1449
1450 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
1451 p.ts.io_bytes[i] = cpu_to_le64(ts->io_bytes[i]);
1452 p.ts.runtime[i] = cpu_to_le64(ts->runtime[i]);
1453 }
1454
1455 p.ts.total_run_time = cpu_to_le64(ts->total_run_time);
1456 p.ts.continue_on_error = cpu_to_le16(ts->continue_on_error);
1457 p.ts.total_err_count = cpu_to_le64(ts->total_err_count);
1458 p.ts.first_error = cpu_to_le32(ts->first_error);
1459 p.ts.kb_base = cpu_to_le32(ts->kb_base);
1460 p.ts.unit_base = cpu_to_le32(ts->unit_base);
1461
1462 p.ts.latency_depth = cpu_to_le32(ts->latency_depth);
1463 p.ts.latency_target = cpu_to_le64(ts->latency_target);
1464 p.ts.latency_window = cpu_to_le64(ts->latency_window);
1465 p.ts.latency_percentile.u.i = cpu_to_le64(fio_double_to_uint64(ts->latency_percentile.u.f));
1466
1467 p.ts.nr_block_infos = le64_to_cpu(ts->nr_block_infos);
1468 for (i = 0; i < p.ts.nr_block_infos; i++)
1469 p.ts.block_infos[i] = le32_to_cpu(ts->block_infos[i]);
1470
1471 convert_gs(&p.rs, rs);
1472
1473 fio_net_queue_cmd(FIO_NET_CMD_TS, &p, sizeof(p), NULL, SK_F_COPY);
1474}
1475
1476void fio_server_send_gs(struct group_run_stats *rs)
1477{
1478 struct group_run_stats gs;
1479
1480 dprint(FD_NET, "server sending group run stats\n");
1481
1482 convert_gs(&gs, rs);
1483 fio_net_queue_cmd(FIO_NET_CMD_GS, &gs, sizeof(gs), NULL, SK_F_COPY);
1484}
1485
1486static void convert_agg(struct disk_util_agg *dst, struct disk_util_agg *src)
1487{
1488 int i;
1489
1490 for (i = 0; i < 2; i++) {
1491 dst->ios[i] = cpu_to_le64(src->ios[i]);
1492 dst->merges[i] = cpu_to_le64(src->merges[i]);
1493 dst->sectors[i] = cpu_to_le64(src->sectors[i]);
1494 dst->ticks[i] = cpu_to_le64(src->ticks[i]);
1495 }
1496
1497 dst->io_ticks = cpu_to_le64(src->io_ticks);
1498 dst->time_in_queue = cpu_to_le64(src->time_in_queue);
1499 dst->slavecount = cpu_to_le32(src->slavecount);
1500 dst->max_util.u.i = cpu_to_le64(fio_double_to_uint64(src->max_util.u.f));
1501}
1502
1503static void convert_dus(struct disk_util_stat *dst, struct disk_util_stat *src)
1504{
1505 int i;
1506
1507 dst->name[FIO_DU_NAME_SZ - 1] = '\0';
1508 strncpy((char *) dst->name, (char *) src->name, FIO_DU_NAME_SZ - 1);
1509
1510 for (i = 0; i < 2; i++) {
1511 dst->s.ios[i] = cpu_to_le64(src->s.ios[i]);
1512 dst->s.merges[i] = cpu_to_le64(src->s.merges[i]);
1513 dst->s.sectors[i] = cpu_to_le64(src->s.sectors[i]);
1514 dst->s.ticks[i] = cpu_to_le64(src->s.ticks[i]);
1515 }
1516
1517 dst->s.io_ticks = cpu_to_le64(src->s.io_ticks);
1518 dst->s.time_in_queue = cpu_to_le64(src->s.time_in_queue);
1519 dst->s.msec = cpu_to_le64(src->s.msec);
1520}
1521
1522void fio_server_send_du(void)
1523{
1524 struct disk_util *du;
1525 struct flist_head *entry;
1526 struct cmd_du_pdu pdu;
1527
1528 dprint(FD_NET, "server: sending disk_util %d\n", !flist_empty(&disk_list));
1529
1530 memset(&pdu, 0, sizeof(pdu));
1531
1532 flist_for_each(entry, &disk_list) {
1533 du = flist_entry(entry, struct disk_util, list);
1534
1535 convert_dus(&pdu.dus, &du->dus);
1536 convert_agg(&pdu.agg, &du->agg);
1537
1538 fio_net_queue_cmd(FIO_NET_CMD_DU, &pdu, sizeof(pdu), NULL, SK_F_COPY);
1539 }
1540}
1541
1542static int fio_send_iolog_gz(struct sk_entry *first, struct io_log *log)
1543{
1544 int ret = 0;
1545#ifdef CONFIG_ZLIB
1546 struct sk_entry *entry;
1547 z_stream stream;
1548 void *out_pdu;
1549
1550 /*
1551 * Dirty - since the log is potentially huge, compress it into
1552 * FIO_SERVER_MAX_FRAGMENT_PDU chunks and let the receiving
1553 * side defragment it.
1554 */
1555 out_pdu = malloc(FIO_SERVER_MAX_FRAGMENT_PDU);
1556
1557 stream.zalloc = Z_NULL;
1558 stream.zfree = Z_NULL;
1559 stream.opaque = Z_NULL;
1560
1561 if (deflateInit(&stream, Z_DEFAULT_COMPRESSION) != Z_OK) {
1562 ret = 1;
1563 goto err;
1564 }
1565
1566 stream.next_in = (void *) log->log;
1567 stream.avail_in = log->nr_samples * log_entry_sz(log);
1568
1569 do {
1570 unsigned int this_len;
1571
1572 stream.avail_out = FIO_SERVER_MAX_FRAGMENT_PDU;
1573 stream.next_out = out_pdu;
1574 ret = deflate(&stream, Z_FINISH);
1575 /* may be Z_OK, or Z_STREAM_END */
1576 if (ret < 0)
1577 goto err_zlib;
1578
1579 this_len = FIO_SERVER_MAX_FRAGMENT_PDU - stream.avail_out;
1580
1581 entry = fio_net_prep_cmd(FIO_NET_CMD_IOLOG, out_pdu, this_len,
1582 NULL, SK_F_FREE | SK_F_VEC);
1583 flist_add_tail(&entry->list, &first->next);
1584 } while (stream.avail_in);
1585
1586err_zlib:
1587 deflateEnd(&stream);
1588err:
1589 free(out_pdu);
1590#endif
1591 return ret;
1592}
1593
1594int fio_send_iolog(struct thread_data *td, struct io_log *log, const char *name)
1595{
1596 struct cmd_iolog_pdu pdu;
1597 struct sk_entry *first;
1598 int i, ret = 0;
1599
1600 pdu.nr_samples = cpu_to_le64(log->nr_samples);
1601 pdu.thread_number = cpu_to_le32(td->thread_number);
1602 pdu.log_type = cpu_to_le32(log->log_type);
1603 pdu.compressed = cpu_to_le32(use_zlib);
1604
1605 strncpy((char *) pdu.name, name, FIO_NET_NAME_MAX);
1606 pdu.name[FIO_NET_NAME_MAX - 1] = '\0';
1607
1608 for (i = 0; i < log->nr_samples; i++) {
1609 struct io_sample *s = get_sample(log, i);
1610
1611 s->time = cpu_to_le64(s->time);
1612 s->val = cpu_to_le64(s->val);
1613 s->__ddir = cpu_to_le32(s->__ddir);
1614 s->bs = cpu_to_le32(s->bs);
1615
1616 if (log->log_offset) {
1617 struct io_sample_offset *so = (void *) s;
1618
1619 so->offset = cpu_to_le64(so->offset);
1620 }
1621 }
1622
1623 /*
1624 * Assemble header entry first
1625 */
1626 first = fio_net_prep_cmd(FIO_NET_CMD_IOLOG, &pdu, sizeof(pdu), NULL, SK_F_COPY | SK_F_VEC);
1627
1628 /*
1629 * Now append actual log entries. Compress if we can, otherwise just
1630 * plain text output.
1631 */
1632 if (use_zlib)
1633 ret = fio_send_iolog_gz(first, log);
1634 else {
1635 struct sk_entry *entry;
1636
1637 entry = fio_net_prep_cmd(FIO_NET_CMD_IOLOG, log->log,
1638 log->nr_samples * log_entry_sz(log),
1639 NULL, SK_F_FREE | SK_F_VEC);
1640 flist_add_tail(&entry->list, &first->next);
1641 }
1642
1643 return ret;
1644}
1645
1646void fio_server_send_add_job(struct thread_data *td)
1647{
1648 struct cmd_add_job_pdu pdu;
1649
1650 memset(&pdu, 0, sizeof(pdu));
1651 pdu.thread_number = cpu_to_le32(td->thread_number);
1652 pdu.groupid = cpu_to_le32(td->groupid);
1653 convert_thread_options_to_net(&pdu.top, &td->o);
1654
1655 fio_net_queue_cmd(FIO_NET_CMD_ADD_JOB, &pdu, sizeof(pdu), NULL, SK_F_COPY);
1656}
1657
1658void fio_server_send_start(struct thread_data *td)
1659{
1660 struct sk_out *sk_out = pthread_getspecific(sk_out_key);
1661
1662 assert(sk_out->sk != -1);
1663
1664 fio_net_queue_cmd(FIO_NET_CMD_SERVER_START, NULL, 0, 0, SK_F_SIMPLE);
1665}
1666
1667int fio_server_get_verify_state(const char *name, int threadnumber,
1668 void **datap, int *version)
1669{
1670 struct thread_io_list *s;
1671 struct cmd_sendfile out;
1672 struct cmd_reply *rep;
1673 uint64_t tag;
1674 void *data;
1675
1676 dprint(FD_NET, "server: request verify state\n");
1677
1678 rep = smalloc(sizeof(*rep));
1679 if (!rep) {
1680 log_err("fio: smalloc pool too small\n");
1681 return 1;
1682 }
1683
1684 __fio_mutex_init(&rep->lock, FIO_MUTEX_LOCKED);
1685 rep->data = NULL;
1686 rep->error = 0;
1687
1688 verify_state_gen_name((char *) out.path, sizeof(out.path), name, me,
1689 threadnumber);
1690 tag = (uint64_t) (uintptr_t) rep;
1691 fio_net_queue_cmd(FIO_NET_CMD_SENDFILE, &out, sizeof(out), &tag, SK_F_COPY);
1692
1693 /*
1694 * Wait for the backend to receive the reply
1695 */
1696 if (fio_mutex_down_timeout(&rep->lock, 10000)) {
1697 log_err("fio: timed out waiting for reply\n");
1698 goto fail;
1699 }
1700
1701 if (rep->error) {
1702 log_err("fio: failure on receiving state file: %s\n", strerror(rep->error));
1703fail:
1704 *datap = NULL;
1705 sfree(rep);
1706 fio_net_queue_quit();
1707 return 1;
1708 }
1709
1710 /*
1711 * The format is verify_state_hdr, then thread_io_list. Verify
1712 * the header, and the thread_io_list checksum
1713 */
1714 s = rep->data + sizeof(struct verify_state_hdr);
1715 if (verify_state_hdr(rep->data, s, version))
1716 goto fail;
1717
1718 /*
1719 * Don't need the header from now, copy just the thread_io_list
1720 */
1721 rep->size -= sizeof(struct verify_state_hdr);
1722 data = malloc(rep->size);
1723 memcpy(data, s, rep->size);
1724 *datap = data;
1725
1726 sfree(rep->data);
1727 __fio_mutex_remove(&rep->lock);
1728 sfree(rep);
1729 return 0;
1730}
1731
1732static int fio_init_server_ip(void)
1733{
1734 struct sockaddr *addr;
1735 socklen_t socklen;
1736 char buf[80];
1737 const char *str;
1738 int sk, opt;
1739
1740 if (use_ipv6)
1741 sk = socket(AF_INET6, SOCK_STREAM, 0);
1742 else
1743 sk = socket(AF_INET, SOCK_STREAM, 0);
1744
1745 if (sk < 0) {
1746 log_err("fio: socket: %s\n", strerror(errno));
1747 return -1;
1748 }
1749
1750 opt = 1;
1751 if (setsockopt(sk, SOL_SOCKET, SO_REUSEADDR, (void *)&opt, sizeof(opt)) < 0) {
1752 log_err("fio: setsockopt(REUSEADDR): %s\n", strerror(errno));
1753 close(sk);
1754 return -1;
1755 }
1756#ifdef SO_REUSEPORT
1757 if (setsockopt(sk, SOL_SOCKET, SO_REUSEPORT, &opt, sizeof(opt)) < 0) {
1758 log_err("fio: setsockopt(REUSEPORT): %s\n", strerror(errno));
1759 close(sk);
1760 return -1;
1761 }
1762#endif
1763
1764 if (use_ipv6) {
1765 const void *src = &saddr_in6.sin6_addr;
1766
1767 addr = (struct sockaddr *) &saddr_in6;
1768 socklen = sizeof(saddr_in6);
1769 saddr_in6.sin6_family = AF_INET6;
1770 str = inet_ntop(AF_INET6, src, buf, sizeof(buf));
1771 } else {
1772 const void *src = &saddr_in.sin_addr;
1773
1774 addr = (struct sockaddr *) &saddr_in;
1775 socklen = sizeof(saddr_in);
1776 saddr_in.sin_family = AF_INET;
1777 str = inet_ntop(AF_INET, src, buf, sizeof(buf));
1778 }
1779
1780 if (bind(sk, addr, socklen) < 0) {
1781 log_err("fio: bind: %s\n", strerror(errno));
1782 log_info("fio: failed with IPv%c %s\n", use_ipv6 ? '6' : '4', str);
1783 close(sk);
1784 return -1;
1785 }
1786
1787 return sk;
1788}
1789
1790static int fio_init_server_sock(void)
1791{
1792 struct sockaddr_un addr;
1793 socklen_t len;
1794 mode_t mode;
1795 int sk;
1796
1797 sk = socket(AF_UNIX, SOCK_STREAM, 0);
1798 if (sk < 0) {
1799 log_err("fio: socket: %s\n", strerror(errno));
1800 return -1;
1801 }
1802
1803 mode = umask(000);
1804
1805 memset(&addr, 0, sizeof(addr));
1806 addr.sun_family = AF_UNIX;
1807 strncpy(addr.sun_path, bind_sock, sizeof(addr.sun_path) - 1);
1808
1809 len = sizeof(addr.sun_family) + strlen(bind_sock) + 1;
1810
1811 if (bind(sk, (struct sockaddr *) &addr, len) < 0) {
1812 log_err("fio: bind: %s\n", strerror(errno));
1813 close(sk);
1814 return -1;
1815 }
1816
1817 umask(mode);
1818 return sk;
1819}
1820
1821static int fio_init_server_connection(void)
1822{
1823 char bind_str[128];
1824 int sk;
1825
1826 dprint(FD_NET, "starting server\n");
1827
1828 if (!bind_sock)
1829 sk = fio_init_server_ip();
1830 else
1831 sk = fio_init_server_sock();
1832
1833 if (sk < 0)
1834 return sk;
1835
1836 memset(bind_str, 0, sizeof(bind_str));
1837
1838 if (!bind_sock) {
1839 char *p, port[16];
1840 const void *src;
1841 int af;
1842
1843 if (use_ipv6) {
1844 af = AF_INET6;
1845 src = &saddr_in6.sin6_addr;
1846 } else {
1847 af = AF_INET;
1848 src = &saddr_in.sin_addr;
1849 }
1850
1851 p = (char *) inet_ntop(af, src, bind_str, sizeof(bind_str));
1852
1853 sprintf(port, ",%u", fio_net_port);
1854 if (p)
1855 strcat(p, port);
1856 else
1857 strncpy(bind_str, port, sizeof(bind_str) - 1);
1858 } else
1859 strncpy(bind_str, bind_sock, sizeof(bind_str) - 1);
1860
1861 log_info("fio: server listening on %s\n", bind_str);
1862
1863 if (listen(sk, 0) < 0) {
1864 log_err("fio: listen: %s\n", strerror(errno));
1865 close(sk);
1866 return -1;
1867 }
1868
1869 return sk;
1870}
1871
1872int fio_server_parse_host(const char *host, int ipv6, struct in_addr *inp,
1873 struct in6_addr *inp6)
1874
1875{
1876 int ret = 0;
1877
1878 if (ipv6)
1879 ret = inet_pton(AF_INET6, host, inp6);
1880 else
1881 ret = inet_pton(AF_INET, host, inp);
1882
1883 if (ret != 1) {
1884 struct addrinfo hints, *res;
1885
1886 memset(&hints, 0, sizeof(hints));
1887 hints.ai_family = ipv6 ? AF_INET6 : AF_INET;
1888 hints.ai_socktype = SOCK_STREAM;
1889
1890 ret = getaddrinfo(host, NULL, &hints, &res);
1891 if (ret) {
1892 log_err("fio: failed to resolve <%s> (%s)\n", host,
1893 gai_strerror(ret));
1894 return 1;
1895 }
1896
1897 if (ipv6)
1898 memcpy(inp6, &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr, sizeof(*inp6));
1899 else
1900 memcpy(inp, &((struct sockaddr_in *) res->ai_addr)->sin_addr, sizeof(*inp));
1901
1902 ret = 1;
1903 freeaddrinfo(res);
1904 }
1905
1906 return !(ret == 1);
1907}
1908
1909/*
1910 * Parse a host/ip/port string. Reads from 'str'.
1911 *
1912 * Outputs:
1913 *
1914 * For IPv4:
1915 * *ptr is the host, *port is the port, inp is the destination.
1916 * For IPv6:
1917 * *ptr is the host, *port is the port, inp6 is the dest, and *ipv6 is 1.
1918 * For local domain sockets:
1919 * *ptr is the filename, *is_sock is 1.
1920 */
1921int fio_server_parse_string(const char *str, char **ptr, int *is_sock,
1922 int *port, struct in_addr *inp,
1923 struct in6_addr *inp6, int *ipv6)
1924{
1925 const char *host = str;
1926 char *portp;
1927 int lport = 0;
1928
1929 *ptr = NULL;
1930 *is_sock = 0;
1931 *port = fio_net_port;
1932 *ipv6 = 0;
1933
1934 if (!strncmp(str, "sock:", 5)) {
1935 *ptr = strdup(str + 5);
1936 *is_sock = 1;
1937
1938 return 0;
1939 }
1940
1941 /*
1942 * Is it ip:<ip or host>:port
1943 */
1944 if (!strncmp(host, "ip:", 3))
1945 host += 3;
1946 else if (!strncmp(host, "ip4:", 4))
1947 host += 4;
1948 else if (!strncmp(host, "ip6:", 4)) {
1949 host += 4;
1950 *ipv6 = 1;
1951 } else if (host[0] == ':') {
1952 /* String is :port */
1953 host++;
1954 lport = atoi(host);
1955 if (!lport || lport > 65535) {
1956 log_err("fio: bad server port %u\n", lport);
1957 return 1;
1958 }
1959 /* no hostname given, we are done */
1960 *port = lport;
1961 return 0;
1962 }
1963
1964 /*
1965 * If no port seen yet, check if there's a last ',' at the end
1966 */
1967 if (!lport) {
1968 portp = strchr(host, ',');
1969 if (portp) {
1970 *portp = '\0';
1971 portp++;
1972 lport = atoi(portp);
1973 if (!lport || lport > 65535) {
1974 log_err("fio: bad server port %u\n", lport);
1975 return 1;
1976 }
1977 }
1978 }
1979
1980 if (lport)
1981 *port = lport;
1982
1983 if (!strlen(host))
1984 return 0;
1985
1986 *ptr = strdup(host);
1987
1988 if (fio_server_parse_host(*ptr, *ipv6, inp, inp6)) {
1989 free(*ptr);
1990 *ptr = NULL;
1991 return 1;
1992 }
1993
1994 if (*port == 0)
1995 *port = fio_net_port;
1996
1997 return 0;
1998}
1999
2000/*
2001 * Server arg should be one of:
2002 *
2003 * sock:/path/to/socket
2004 * ip:1.2.3.4
2005 * 1.2.3.4
2006 *
2007 * Where sock uses unix domain sockets, and ip binds the server to
2008 * a specific interface. If no arguments are given to the server, it
2009 * uses IP and binds to 0.0.0.0.
2010 *
2011 */
2012static int fio_handle_server_arg(void)
2013{
2014 int port = fio_net_port;
2015 int is_sock, ret = 0;
2016
2017 saddr_in.sin_addr.s_addr = htonl(INADDR_ANY);
2018
2019 if (!fio_server_arg)
2020 goto out;
2021
2022 ret = fio_server_parse_string(fio_server_arg, &bind_sock, &is_sock,
2023 &port, &saddr_in.sin_addr,
2024 &saddr_in6.sin6_addr, &use_ipv6);
2025
2026 if (!is_sock && bind_sock) {
2027 free(bind_sock);
2028 bind_sock = NULL;
2029 }
2030
2031out:
2032 fio_net_port = port;
2033 saddr_in.sin_port = htons(port);
2034 saddr_in6.sin6_port = htons(port);
2035 return ret;
2036}
2037
2038static void sig_int(int sig)
2039{
2040 if (bind_sock)
2041 unlink(bind_sock);
2042}
2043
2044static void set_sig_handlers(void)
2045{
2046 struct sigaction act;
2047
2048 memset(&act, 0, sizeof(act));
2049 act.sa_handler = sig_int;
2050 act.sa_flags = SA_RESTART;
2051 sigaction(SIGINT, &act, NULL);
2052}
2053
2054static int fio_server(void)
2055{
2056 struct sk_out *sk_out;
2057 int sk, ret;
2058
2059 dprint(FD_NET, "starting server\n");
2060
2061 if (fio_handle_server_arg())
2062 return -1;
2063
2064 sk = fio_init_server_connection();
2065 if (sk < 0)
2066 return -1;
2067
2068 set_sig_handlers();
2069
2070 if (pthread_key_create(&sk_out_key, NULL))
2071 log_err("fio: can't create sk_out backend key\n");
2072
2073 ret = accept_loop(sk_out, sk);
2074
2075 close(sk);
2076
2077 if (fio_server_arg) {
2078 free(fio_server_arg);
2079 fio_server_arg = NULL;
2080 }
2081 if (bind_sock)
2082 free(bind_sock);
2083
2084 return ret;
2085}
2086
2087void fio_server_got_signal(int signal)
2088{
2089 struct sk_out *sk_out = pthread_getspecific(sk_out_key);
2090
2091 assert(sk_out);
2092
2093 if (signal == SIGPIPE)
2094 sk_out->sk = -1;
2095 else {
2096 log_info("\nfio: terminating on signal %d\n", signal);
2097 exit_backend = 1;
2098 }
2099}
2100
2101static int check_existing_pidfile(const char *pidfile)
2102{
2103 struct stat sb;
2104 char buf[16];
2105 pid_t pid;
2106 FILE *f;
2107
2108 if (stat(pidfile, &sb))
2109 return 0;
2110
2111 f = fopen(pidfile, "r");
2112 if (!f)
2113 return 0;
2114
2115 if (fread(buf, sb.st_size, 1, f) <= 0) {
2116 fclose(f);
2117 return 1;
2118 }
2119 fclose(f);
2120
2121 pid = atoi(buf);
2122 if (kill(pid, SIGCONT) < 0)
2123 return errno != ESRCH;
2124
2125 return 1;
2126}
2127
2128static int write_pid(pid_t pid, const char *pidfile)
2129{
2130 FILE *fpid;
2131
2132 fpid = fopen(pidfile, "w");
2133 if (!fpid) {
2134 log_err("fio: failed opening pid file %s\n", pidfile);
2135 return 1;
2136 }
2137
2138 fprintf(fpid, "%u\n", (unsigned int) pid);
2139 fclose(fpid);
2140 return 0;
2141}
2142
2143/*
2144 * If pidfile is specified, background us.
2145 */
2146int fio_start_server(char *pidfile)
2147{
2148 pid_t pid;
2149 int ret;
2150
2151#if defined(WIN32)
2152 WSADATA wsd;
2153 WSAStartup(MAKEWORD(2, 2), &wsd);
2154#endif
2155
2156 if (!pidfile)
2157 return fio_server();
2158
2159 if (check_existing_pidfile(pidfile)) {
2160 log_err("fio: pidfile %s exists and server appears alive\n",
2161 pidfile);
2162 free(pidfile);
2163 return -1;
2164 }
2165
2166 pid = fork();
2167 if (pid < 0) {
2168 log_err("fio: failed server fork: %s", strerror(errno));
2169 free(pidfile);
2170 return -1;
2171 } else if (pid) {
2172 ret = write_pid(pid, pidfile);
2173 free(pidfile);
2174 _exit(ret);
2175 }
2176
2177 setsid();
2178 openlog("fio", LOG_NDELAY|LOG_NOWAIT|LOG_PID, LOG_USER);
2179 log_syslog = 1;
2180 close(STDIN_FILENO);
2181 close(STDOUT_FILENO);
2182 close(STDERR_FILENO);
2183 f_out = NULL;
2184 f_err = NULL;
2185
2186 ret = fio_server();
2187
2188 closelog();
2189 unlink(pidfile);
2190 free(pidfile);
2191 return ret;
2192}
2193
2194void fio_server_set_arg(const char *arg)
2195{
2196 fio_server_arg = strdup(arg);
2197}