blob: 2da0c83edf2e75f1b4090bf574c6985eb68336d6 [file] [log] [blame]
Jens Axboe50d16972011-09-29 17:45:28 -06001#include <stdio.h>
2#include <stdlib.h>
Jens Axboe142575e2011-09-30 17:35:45 -06003#include <stdarg.h>
Jens Axboe50d16972011-09-29 17:45:28 -06004#include <unistd.h>
5#include <limits.h>
Jens Axboe50d16972011-09-29 17:45:28 -06006#include <errno.h>
7#include <fcntl.h>
8#include <sys/poll.h>
Jens Axboe50d16972011-09-29 17:45:28 -06009#include <sys/types.h>
10#include <sys/wait.h>
Jens Axboed05c4a02011-10-05 00:16:11 +020011#include <sys/socket.h>
Jens Axboe87aa8f12011-10-06 21:24:13 +020012#include <sys/stat.h>
13#include <sys/un.h>
Jens Axboe50d16972011-09-29 17:45:28 -060014#include <netinet/in.h>
15#include <arpa/inet.h>
16#include <netdb.h>
Jens Axboee46d8092011-10-03 09:11:02 +020017#include <syslog.h>
Jens Axboe9e22ecb2011-10-04 14:50:21 +020018#include <signal.h>
Jens Axboe1b427252012-03-14 15:03:03 +010019#include <zlib.h>
Jens Axboe50d16972011-09-29 17:45:28 -060020
21#include "fio.h"
Jens Axboe132159a2011-09-30 15:01:32 -060022#include "server.h"
Jens Axboefcee5ff2011-09-30 22:50:39 -060023#include "crc/crc16.h"
Jens Axboec7c6cb42011-10-13 14:12:40 +020024#include "lib/ieee754.h"
Jens Axboe50d16972011-09-29 17:45:28 -060025
Jens Axboe89cf1482011-10-07 10:10:18 +020026#include "fio_version.h"
27
Stephen M. Cameron5adc2442012-02-24 08:17:31 +010028int fio_net_port = FIO_NET_PORT;
Jens Axboe50d16972011-09-29 17:45:28 -060029
Jens Axboe009b1be2011-09-29 18:27:02 -060030int exit_backend = 0;
31
Jens Axboe46c48f12011-10-01 12:50:51 -060032static int server_fd = -1;
Jens Axboe87aa8f12011-10-06 21:24:13 +020033static char *fio_server_arg;
34static char *bind_sock;
35static struct sockaddr_in saddr_in;
Jens Axboe811826b2011-10-24 09:11:50 +020036static struct sockaddr_in6 saddr_in6;
Jens Axboe01be0382011-10-15 14:43:41 +020037static int first_cmd_check;
Jens Axboe811826b2011-10-24 09:11:50 +020038static int use_ipv6;
Jens Axboe37db14f2011-09-30 17:00:42 -060039
Jens Axboe89c17072011-10-11 10:15:51 +020040static const char *fio_server_ops[FIO_NET_CMD_NR] = {
41 "",
42 "QUIT",
43 "EXIT",
44 "JOB",
45 "JOBLINE",
46 "TEXT",
47 "TS",
48 "GS",
49 "SEND_ETA",
50 "ETA",
51 "PROBE",
52 "START",
Jens Axboed09a64a2011-10-13 11:38:56 +020053 "STOP",
54 "DISK_UTIL",
Jens Axboeb9d2f302012-03-08 20:36:28 +010055 "SERVER_START",
Jens Axboe807f9972012-03-02 10:25:24 +010056 "ADD_JOB",
Jens Axboeb9d2f302012-03-08 20:36:28 +010057 "CMD_RUN"
Jens Axboe89c17072011-10-11 10:15:51 +020058};
59
60const char *fio_server_op(unsigned int op)
61{
62 static char buf[32];
63
64 if (op < FIO_NET_CMD_NR)
65 return fio_server_ops[op];
66
67 sprintf(buf, "UNKNOWN/%d", op);
68 return buf;
69}
70
Jens Axboe5235f622012-03-14 21:25:51 +010071static ssize_t iov_total_len(const struct iovec *iov, int count)
Jens Axboe132159a2011-09-30 15:01:32 -060072{
Jens Axboe5235f622012-03-14 21:25:51 +010073 ssize_t ret = 0;
74
75 while (count--) {
76 ret += iov->iov_len;
77 iov++;
78 }
79
80 return ret;
81}
82
83static int fio_sendv_data(int sk, struct iovec *iov, int count)
84{
85 ssize_t total_len = iov_total_len(iov, count);
86 ssize_t ret;
Jens Axboe794d69c2011-10-01 08:48:50 -060087
Jens Axboe132159a2011-09-30 15:01:32 -060088 do {
Jens Axboe5235f622012-03-14 21:25:51 +010089 ret = writev(sk, iov, count);
Jens Axboe132159a2011-09-30 15:01:32 -060090 if (ret > 0) {
Jens Axboe5235f622012-03-14 21:25:51 +010091 total_len -= ret;
92 if (!total_len)
Jens Axboe132159a2011-09-30 15:01:32 -060093 break;
Jens Axboe5235f622012-03-14 21:25:51 +010094
95 while (ret) {
96 if (ret >= iov->iov_len) {
97 ret -= iov->iov_len;
98 iov++;
99 continue;
100 }
101 iov->iov_base += ret;
102 iov->iov_len -= ret;
103 ret = 0;
104 }
Jens Axboe132159a2011-09-30 15:01:32 -0600105 } else if (!ret)
106 break;
107 else if (errno == EAGAIN || errno == EINTR)
108 continue;
Jens Axboe7b821682011-10-11 12:16:32 +0200109 else
110 break;
Jens Axboe132159a2011-09-30 15:01:32 -0600111 } while (!exit_backend);
112
Jens Axboe5235f622012-03-14 21:25:51 +0100113 if (!total_len)
Jens Axboe132159a2011-09-30 15:01:32 -0600114 return 0;
115
Jens Axboe8b4e61b2012-03-09 17:10:54 +0100116 if (errno)
117 return -errno;
118
Jens Axboe132159a2011-09-30 15:01:32 -0600119 return 1;
120}
121
Jens Axboe5235f622012-03-14 21:25:51 +0100122int fio_send_data(int sk, const void *p, unsigned int len)
123{
124 struct iovec iov = { .iov_base = (void *) p, .iov_len = len };
125
126 assert(len <= sizeof(struct fio_net_cmd) + FIO_SERVER_MAX_FRAGMENT_PDU);
127
128 return fio_sendv_data(sk, &iov, 1);
129}
130
Jens Axboe132159a2011-09-30 15:01:32 -0600131int fio_recv_data(int sk, void *p, unsigned int len)
132{
133 do {
134 int ret = recv(sk, p, len, MSG_WAITALL);
135
136 if (ret > 0) {
137 len -= ret;
138 if (!len)
139 break;
140 p += ret;
141 continue;
142 } else if (!ret)
143 break;
144 else if (errno == EAGAIN || errno == EINTR)
145 continue;
Jens Axboe7b821682011-10-11 12:16:32 +0200146 else
147 break;
Jens Axboe132159a2011-09-30 15:01:32 -0600148 } while (!exit_backend);
149
150 if (!len)
151 return 0;
152
153 return -1;
154}
155
156static int verify_convert_cmd(struct fio_net_cmd *cmd)
157{
Jens Axboefcee5ff2011-09-30 22:50:39 -0600158 uint16_t crc;
Jens Axboe132159a2011-09-30 15:01:32 -0600159
Jens Axboefcee5ff2011-09-30 22:50:39 -0600160 cmd->cmd_crc16 = le16_to_cpu(cmd->cmd_crc16);
161 cmd->pdu_crc16 = le16_to_cpu(cmd->pdu_crc16);
Jens Axboe132159a2011-09-30 15:01:32 -0600162
Jens Axboe25dfa842012-02-29 10:01:34 +0100163 crc = fio_crc16(cmd, FIO_NET_CMD_CRC_SZ);
Jens Axboefcee5ff2011-09-30 22:50:39 -0600164 if (crc != cmd->cmd_crc16) {
Jens Axboe132159a2011-09-30 15:01:32 -0600165 log_err("fio: server bad crc on command (got %x, wanted %x)\n",
Jens Axboefcee5ff2011-09-30 22:50:39 -0600166 cmd->cmd_crc16, crc);
Jens Axboe132159a2011-09-30 15:01:32 -0600167 return 1;
168 }
169
170 cmd->version = le16_to_cpu(cmd->version);
171 cmd->opcode = le16_to_cpu(cmd->opcode);
172 cmd->flags = le32_to_cpu(cmd->flags);
Jens Axboeaf9c9fb2011-10-09 21:54:10 +0200173 cmd->tag = le64_to_cpu(cmd->tag);
Jens Axboe132159a2011-09-30 15:01:32 -0600174 cmd->pdu_len = le32_to_cpu(cmd->pdu_len);
175
176 switch (cmd->version) {
Jens Axboefa2ea802011-10-08 21:07:29 +0200177 case FIO_SERVER_VER:
Jens Axboe132159a2011-09-30 15:01:32 -0600178 break;
179 default:
180 log_err("fio: bad server cmd version %d\n", cmd->version);
181 return 1;
182 }
183
Jens Axboeb9d2f302012-03-08 20:36:28 +0100184 if (cmd->pdu_len > FIO_SERVER_MAX_FRAGMENT_PDU) {
Jens Axboe132159a2011-09-30 15:01:32 -0600185 log_err("fio: command payload too large: %u\n", cmd->pdu_len);
186 return 1;
187 }
188
189 return 0;
190}
191
Jens Axboea64e88d2011-10-03 14:20:01 +0200192/*
193 * Read (and defragment, if necessary) incoming commands
194 */
Jens Axboee951bdc2011-10-05 21:58:45 +0200195struct fio_net_cmd *fio_net_recv_cmd(int sk)
Jens Axboe132159a2011-09-30 15:01:32 -0600196{
Jens Axboea64e88d2011-10-03 14:20:01 +0200197 struct fio_net_cmd cmd, *cmdret = NULL;
198 size_t cmd_size = 0, pdu_offset = 0;
Jens Axboefcee5ff2011-09-30 22:50:39 -0600199 uint16_t crc;
Jens Axboea64e88d2011-10-03 14:20:01 +0200200 int ret, first = 1;
201 void *pdu = NULL;
Jens Axboe132159a2011-09-30 15:01:32 -0600202
Jens Axboea64e88d2011-10-03 14:20:01 +0200203 do {
204 ret = fio_recv_data(sk, &cmd, sizeof(cmd));
205 if (ret)
206 break;
Jens Axboe132159a2011-09-30 15:01:32 -0600207
Jens Axboea64e88d2011-10-03 14:20:01 +0200208 /* We have a command, verify it and swap if need be */
209 ret = verify_convert_cmd(&cmd);
210 if (ret)
211 break;
Jens Axboe132159a2011-09-30 15:01:32 -0600212
Jens Axboe0b8f30a2011-10-04 10:31:53 +0200213 if (first) {
214 /* if this is text, add room for \0 at the end */
215 cmd_size = sizeof(cmd) + cmd.pdu_len + 1;
216 assert(!cmdret);
217 } else
Jens Axboea64e88d2011-10-03 14:20:01 +0200218 cmd_size += cmd.pdu_len;
Jens Axboe132159a2011-09-30 15:01:32 -0600219
Jens Axboea64e88d2011-10-03 14:20:01 +0200220 cmdret = realloc(cmdret, cmd_size);
Jens Axboe132159a2011-09-30 15:01:32 -0600221
Jens Axboea64e88d2011-10-03 14:20:01 +0200222 if (first)
223 memcpy(cmdret, &cmd, sizeof(cmd));
Jens Axboe67f15dc2011-10-15 16:07:40 +0200224 else if (cmdret->opcode != cmd.opcode) {
225 log_err("fio: fragment opcode mismatch (%d != %d)\n",
226 cmdret->opcode, cmd.opcode);
227 ret = 1;
228 break;
229 }
Jens Axboea64e88d2011-10-03 14:20:01 +0200230
231 if (!cmd.pdu_len)
232 break;
233
234 /* There's payload, get it */
235 pdu = (void *) cmdret->payload + pdu_offset;
236 ret = fio_recv_data(sk, pdu, cmd.pdu_len);
237 if (ret)
238 break;
239
240 /* Verify payload crc */
Jens Axboe25dfa842012-02-29 10:01:34 +0100241 crc = fio_crc16(pdu, cmd.pdu_len);
Jens Axboea64e88d2011-10-03 14:20:01 +0200242 if (crc != cmd.pdu_crc16) {
243 log_err("fio: server bad crc on payload ");
244 log_err("(got %x, wanted %x)\n", cmd.pdu_crc16, crc);
245 ret = 1;
246 break;
247 }
248
249 pdu_offset += cmd.pdu_len;
Jens Axboe817f06b2011-10-03 15:03:08 +0200250 if (!first)
251 cmdret->pdu_len += cmd.pdu_len;
Jens Axboea64e88d2011-10-03 14:20:01 +0200252 first = 0;
253 } while (cmd.flags & FIO_NET_CMD_F_MORE);
254
255 if (ret) {
256 free(cmdret);
257 cmdret = NULL;
Jens Axboe0b8f30a2011-10-04 10:31:53 +0200258 } else if (cmdret) {
259 /* zero-terminate text input */
Jens Axboe084d1c62012-03-03 20:28:07 +0100260 if (cmdret->pdu_len) {
261 if (cmdret->opcode == FIO_NET_CMD_TEXT) {
262 struct cmd_text_pdu *pdu = (struct cmd_text_pdu *) cmdret->payload;
263 char *buf = (char *) pdu->buf;
Jens Axboe0b8f30a2011-10-04 10:31:53 +0200264
Jens Axboe084d1c62012-03-03 20:28:07 +0100265 buf[pdu->buf_len ] = '\0';
266 } else if (cmdret->opcode == FIO_NET_CMD_JOB) {
Jens Axboe46bcd492012-03-14 11:31:21 +0100267 struct cmd_job_pdu *pdu = (struct cmd_job_pdu *) cmdret->payload;
268 char *buf = (char *) pdu->buf;
269 int len = le32_to_cpu(pdu->buf_len);
Jens Axboe084d1c62012-03-03 20:28:07 +0100270
Jens Axboe46bcd492012-03-14 11:31:21 +0100271 buf[len] = '\0';
Jens Axboe084d1c62012-03-03 20:28:07 +0100272 }
Jens Axboe0b8f30a2011-10-04 10:31:53 +0200273 }
Jens Axboe084d1c62012-03-03 20:28:07 +0100274
Jens Axboe0b8f30a2011-10-04 10:31:53 +0200275 /* frag flag is internal */
Jens Axboea64e88d2011-10-03 14:20:01 +0200276 cmdret->flags &= ~FIO_NET_CMD_F_MORE;
Jens Axboe0b8f30a2011-10-04 10:31:53 +0200277 }
Jens Axboe132159a2011-09-30 15:01:32 -0600278
Jens Axboea64e88d2011-10-03 14:20:01 +0200279 return cmdret;
Jens Axboe132159a2011-09-30 15:01:32 -0600280}
281
Jens Axboe53bd8db2012-03-14 21:51:38 +0100282void fio_net_cmd_crc_pdu(struct fio_net_cmd *cmd, const void *pdu)
Jens Axboe132159a2011-09-30 15:01:32 -0600283{
284 uint32_t pdu_len;
285
Jens Axboe25dfa842012-02-29 10:01:34 +0100286 cmd->cmd_crc16 = __cpu_to_le16(fio_crc16(cmd, FIO_NET_CMD_CRC_SZ));
Jens Axboe132159a2011-09-30 15:01:32 -0600287
288 pdu_len = le32_to_cpu(cmd->pdu_len);
Jens Axboe1b427252012-03-14 15:03:03 +0100289 cmd->pdu_crc16 = __cpu_to_le16(fio_crc16(pdu, pdu_len));
290}
291
292void fio_net_cmd_crc(struct fio_net_cmd *cmd)
293{
294 fio_net_cmd_crc_pdu(cmd, cmd->payload);
Jens Axboe132159a2011-09-30 15:01:32 -0600295}
296
Jens Axboeaf9c9fb2011-10-09 21:54:10 +0200297int fio_net_send_cmd(int fd, uint16_t opcode, const void *buf, off_t size,
298 uint64_t tag)
Jens Axboe794d69c2011-10-01 08:48:50 -0600299{
Jens Axboe7f868312011-10-10 09:55:21 +0200300 struct fio_net_cmd *cmd = NULL;
301 size_t this_len, cur_len = 0;
Jens Axboe794d69c2011-10-01 08:48:50 -0600302 int ret;
303
304 do {
305 this_len = size;
Jens Axboeb9d2f302012-03-08 20:36:28 +0100306 if (this_len > FIO_SERVER_MAX_FRAGMENT_PDU)
307 this_len = FIO_SERVER_MAX_FRAGMENT_PDU;
Jens Axboe794d69c2011-10-01 08:48:50 -0600308
Jens Axboe7f868312011-10-10 09:55:21 +0200309 if (!cmd || cur_len < sizeof(*cmd) + this_len) {
310 if (cmd)
311 free(cmd);
312
313 cur_len = sizeof(*cmd) + this_len;
314 cmd = malloc(cur_len);
315 }
Jens Axboe794d69c2011-10-01 08:48:50 -0600316
Jens Axboeaf9c9fb2011-10-09 21:54:10 +0200317 fio_init_net_cmd(cmd, opcode, buf, this_len, tag);
Jens Axboe794d69c2011-10-01 08:48:50 -0600318
319 if (this_len < size)
Jens Axboeddcc0b62011-10-03 14:45:27 +0200320 cmd->flags = __cpu_to_le32(FIO_NET_CMD_F_MORE);
Jens Axboe794d69c2011-10-01 08:48:50 -0600321
322 fio_net_cmd_crc(cmd);
323
324 ret = fio_send_data(fd, cmd, sizeof(*cmd) + this_len);
Jens Axboe794d69c2011-10-01 08:48:50 -0600325 size -= this_len;
326 buf += this_len;
327 } while (!ret && size);
328
Jens Axboe7f868312011-10-10 09:55:21 +0200329 if (cmd)
330 free(cmd);
331
Jens Axboe794d69c2011-10-01 08:48:50 -0600332 return ret;
333}
334
Jens Axboe89c17072011-10-11 10:15:51 +0200335static int fio_net_send_simple_stack_cmd(int sk, uint16_t opcode, uint64_t tag)
Jens Axboe132159a2011-09-30 15:01:32 -0600336{
Jens Axboe178cde92011-10-05 22:14:31 +0200337 struct fio_net_cmd cmd;
Jens Axboe132159a2011-09-30 15:01:32 -0600338
Jens Axboeaf9c9fb2011-10-09 21:54:10 +0200339 fio_init_net_cmd(&cmd, opcode, NULL, 0, tag);
Jens Axboe132159a2011-09-30 15:01:32 -0600340 fio_net_cmd_crc(&cmd);
341
342 return fio_send_data(sk, &cmd, sizeof(cmd));
343}
344
Jens Axboe89c17072011-10-11 10:15:51 +0200345/*
346 * If 'list' is non-NULL, then allocate and store the sent command for
347 * later verification.
348 */
349int fio_net_send_simple_cmd(int sk, uint16_t opcode, uint64_t tag,
350 struct flist_head *list)
351{
352 struct fio_net_int_cmd *cmd;
353 int ret;
354
355 if (!list)
356 return fio_net_send_simple_stack_cmd(sk, opcode, tag);
357
358 cmd = malloc(sizeof(*cmd));
359
Jens Axboedf380932011-10-11 14:25:08 +0200360 fio_init_net_cmd(&cmd->cmd, opcode, NULL, 0, (uintptr_t) cmd);
Jens Axboe89c17072011-10-11 10:15:51 +0200361 fio_net_cmd_crc(&cmd->cmd);
362
363 INIT_FLIST_HEAD(&cmd->list);
364 gettimeofday(&cmd->tv, NULL);
365 cmd->saved_tag = tag;
366
367 ret = fio_send_data(sk, &cmd->cmd, sizeof(cmd->cmd));
368 if (ret) {
369 free(cmd);
370 return ret;
371 }
372
373 flist_add_tail(&cmd->list, list);
374 return 0;
375}
376
Jens Axboe9abea482011-10-04 13:21:54 +0200377static int fio_server_send_quit_cmd(void)
Jens Axboe437377e2011-10-01 08:31:30 -0600378{
Jens Axboe46c48f12011-10-01 12:50:51 -0600379 dprint(FD_NET, "server: sending quit\n");
Jens Axboe89c17072011-10-11 10:15:51 +0200380 return fio_net_send_simple_cmd(server_fd, FIO_NET_CMD_QUIT, 0, NULL);
Jens Axboe437377e2011-10-01 08:31:30 -0600381}
382
Jens Axboeb9d2f302012-03-08 20:36:28 +0100383static int handle_run_cmd(struct fio_net_cmd *cmd)
Jens Axboe132159a2011-09-30 15:01:32 -0600384{
Jens Axboe11e950b2011-10-16 21:34:14 +0200385 struct cmd_end_pdu epdu;
Jens Axboea64e88d2011-10-03 14:20:01 +0200386 int ret;
Jens Axboe132159a2011-09-30 15:01:32 -0600387
Jens Axboe2e1df072012-02-09 11:15:02 +0100388 ret = fio_backend();
Jens Axboe11e950b2011-10-16 21:34:14 +0200389
390 epdu.error = ret;
391 fio_net_send_cmd(server_fd, FIO_NET_CMD_STOP, &epdu, sizeof(epdu), 0);
392
Jens Axboe9abea482011-10-04 13:21:54 +0200393 fio_server_send_quit_cmd();
Jens Axboe81179ee2011-10-04 12:42:06 +0200394 reset_fio_state();
Jens Axboe8663ea62012-03-02 14:04:30 +0100395 first_cmd_check = 0;
Jens Axboe81179ee2011-10-04 12:42:06 +0200396 return ret;
397}
398
Jens Axboeb9d2f302012-03-08 20:36:28 +0100399static int handle_job_cmd(struct fio_net_cmd *cmd)
400{
Jens Axboe46bcd492012-03-14 11:31:21 +0100401 struct cmd_job_pdu *pdu = (struct cmd_job_pdu *) cmd->payload;
402 void *buf = pdu->buf;
Jens Axboeb9d2f302012-03-08 20:36:28 +0100403 struct cmd_start_pdu spdu;
404
Jens Axboe46bcd492012-03-14 11:31:21 +0100405 pdu->buf_len = le32_to_cpu(pdu->buf_len);
406 pdu->client_type = le32_to_cpu(pdu->client_type);
407
408 if (parse_jobs_ini(buf, 1, 0, pdu->client_type)) {
Jens Axboeb9d2f302012-03-08 20:36:28 +0100409 fio_server_send_quit_cmd();
410 return -1;
411 }
412
413 spdu.jobs = cpu_to_le32(thread_number);
414 fio_net_send_cmd(server_fd, FIO_NET_CMD_START, &spdu, sizeof(spdu), 0);
415 return 0;
416}
417
Jens Axboe81179ee2011-10-04 12:42:06 +0200418static int handle_jobline_cmd(struct fio_net_cmd *cmd)
419{
Jens Axboefa2ea802011-10-08 21:07:29 +0200420 void *pdu = cmd->payload;
421 struct cmd_single_line_pdu *cslp;
422 struct cmd_line_pdu *clp;
423 unsigned long offset;
Jens Axboeb9d2f302012-03-08 20:36:28 +0100424 struct cmd_start_pdu spdu;
Jens Axboefa2ea802011-10-08 21:07:29 +0200425 char **argv;
Jens Axboeb9d2f302012-03-08 20:36:28 +0100426 int i;
Jens Axboe81179ee2011-10-04 12:42:06 +0200427
Jens Axboefa2ea802011-10-08 21:07:29 +0200428 clp = pdu;
429 clp->lines = le16_to_cpu(clp->lines);
Jens Axboe46bcd492012-03-14 11:31:21 +0100430 clp->client_type = le16_to_cpu(clp->client_type);
Jens Axboefa2ea802011-10-08 21:07:29 +0200431 argv = malloc(clp->lines * sizeof(char *));
432 offset = sizeof(*clp);
Jens Axboe81179ee2011-10-04 12:42:06 +0200433
Jens Axboefa2ea802011-10-08 21:07:29 +0200434 dprint(FD_NET, "server: %d command line args\n", clp->lines);
Jens Axboe39e8e012011-10-04 13:46:08 +0200435
Jens Axboefa2ea802011-10-08 21:07:29 +0200436 for (i = 0; i < clp->lines; i++) {
437 cslp = pdu + offset;
438 argv[i] = (char *) cslp->text;
439
440 offset += sizeof(*cslp) + le16_to_cpu(cslp->len);
Jens Axboe39e8e012011-10-04 13:46:08 +0200441 dprint(FD_NET, "server: %d: %s\n", i, argv[i]);
442 }
Jens Axboe81179ee2011-10-04 12:42:06 +0200443
Jens Axboe46bcd492012-03-14 11:31:21 +0100444 if (parse_cmd_line(clp->lines, argv, clp->client_type)) {
Jens Axboee6d1c662011-10-05 20:41:06 +0200445 fio_server_send_quit_cmd();
Jens Axboefa2ea802011-10-08 21:07:29 +0200446 free(argv);
Jens Axboe81179ee2011-10-04 12:42:06 +0200447 return -1;
Jens Axboee6d1c662011-10-05 20:41:06 +0200448 }
Jens Axboe81179ee2011-10-04 12:42:06 +0200449
Jens Axboefa2ea802011-10-08 21:07:29 +0200450 free(argv);
451
Jens Axboeb9d2f302012-03-08 20:36:28 +0100452 spdu.jobs = cpu_to_le32(thread_number);
453 fio_net_send_cmd(server_fd, FIO_NET_CMD_START, &spdu, sizeof(spdu), 0);
454 return 0;
Jens Axboe132159a2011-09-30 15:01:32 -0600455}
456
Jens Axboec28e8e82011-10-04 08:57:39 +0200457static int handle_probe_cmd(struct fio_net_cmd *cmd)
458{
459 struct cmd_probe_pdu probe;
460
Jens Axboe89c17072011-10-11 10:15:51 +0200461 dprint(FD_NET, "server: sending probe reply\n");
462
Jens Axboec28e8e82011-10-04 08:57:39 +0200463 memset(&probe, 0, sizeof(probe));
464 gethostname((char *) probe.hostname, sizeof(probe.hostname));
Jens Axboe6eb24792011-10-04 15:00:30 +0200465#ifdef FIO_BIG_ENDIAN
466 probe.bigendian = 1;
467#endif
Jens Axboe81179ee2011-10-04 12:42:06 +0200468 probe.fio_major = FIO_MAJOR;
469 probe.fio_minor = FIO_MINOR;
470 probe.fio_patch = FIO_PATCH;
Jens Axboec28e8e82011-10-04 08:57:39 +0200471
Jens Axboecca84642011-10-07 12:47:57 +0200472 probe.os = FIO_OS;
473 probe.arch = FIO_ARCH;
474
Jens Axboe38fdef22011-10-11 14:30:06 +0200475 probe.bpp = sizeof(void *);
476
Jens Axboe89c17072011-10-11 10:15:51 +0200477 return fio_net_send_cmd(server_fd, FIO_NET_CMD_PROBE, &probe, sizeof(probe), cmd->tag);
Jens Axboeaf9c9fb2011-10-09 21:54:10 +0200478}
479
480static int handle_send_eta_cmd(struct fio_net_cmd *cmd)
481{
482 struct jobs_eta *je;
483 size_t size;
Jens Axboeaf9c9fb2011-10-09 21:54:10 +0200484 int i;
485
Jens Axboeb814fb22011-10-12 09:20:34 +0200486 if (!thread_number)
487 return 0;
488
489 size = sizeof(*je) + thread_number * sizeof(char) + 1;
Jens Axboe7f868312011-10-10 09:55:21 +0200490 je = malloc(size);
491 memset(je, 0, size);
Jens Axboeaf9c9fb2011-10-09 21:54:10 +0200492
493 if (!calc_thread_status(je, 1)) {
494 free(je);
495 return 0;
496 }
497
498 dprint(FD_NET, "server sending status\n");
499
500 je->nr_running = cpu_to_le32(je->nr_running);
501 je->nr_ramp = cpu_to_le32(je->nr_ramp);
502 je->nr_pending = cpu_to_le32(je->nr_pending);
503 je->files_open = cpu_to_le32(je->files_open);
Jens Axboeaf9c9fb2011-10-09 21:54:10 +0200504
505 for (i = 0; i < 2; i++) {
Jens Axboe3e47bd22012-02-29 13:45:02 +0100506 je->m_rate[i] = cpu_to_le32(je->m_rate[i]);
507 je->t_rate[i] = cpu_to_le32(je->t_rate[i]);
508 je->m_iops[i] = cpu_to_le32(je->m_iops[i]);
509 je->t_iops[i] = cpu_to_le32(je->t_iops[i]);
Jens Axboeaf9c9fb2011-10-09 21:54:10 +0200510 je->rate[i] = cpu_to_le32(je->rate[i]);
511 je->iops[i] = cpu_to_le32(je->iops[i]);
512 }
513
Jens Axboec1970b92012-03-06 15:37:40 +0100514 je->elapsed_sec = cpu_to_le64(je->elapsed_sec);
Jens Axboeaf9c9fb2011-10-09 21:54:10 +0200515 je->eta_sec = cpu_to_le64(je->eta_sec);
Jens Axboe8c621fb2012-03-08 12:30:48 +0100516 je->nr_threads = cpu_to_le32(je->nr_threads);
Jens Axboeaf9c9fb2011-10-09 21:54:10 +0200517
Jens Axboe7f868312011-10-10 09:55:21 +0200518 fio_net_send_cmd(server_fd, FIO_NET_CMD_ETA, je, size, cmd->tag);
Jens Axboeaf9c9fb2011-10-09 21:54:10 +0200519 free(je);
520 return 0;
Jens Axboec28e8e82011-10-04 08:57:39 +0200521}
522
Jens Axboe132159a2011-09-30 15:01:32 -0600523static int handle_command(struct fio_net_cmd *cmd)
524{
525 int ret;
526
Jens Axboe89c17072011-10-11 10:15:51 +0200527 dprint(FD_NET, "server: got op [%s], pdu=%u, tag=%lx\n",
528 fio_server_op(cmd->opcode), cmd->pdu_len, cmd->tag);
Jens Axboe46c48f12011-10-01 12:50:51 -0600529
Jens Axboe132159a2011-09-30 15:01:32 -0600530 switch (cmd->opcode) {
531 case FIO_NET_CMD_QUIT:
Jens Axboecc0df002011-10-03 20:53:32 +0200532 fio_terminate_threads(TERMINATE_ALL);
Jens Axboec28e8e82011-10-04 08:57:39 +0200533 return -1;
Jens Axboed7959182011-10-03 11:48:39 +0200534 case FIO_NET_CMD_EXIT:
Jens Axboe132159a2011-09-30 15:01:32 -0600535 exit_backend = 1;
Jens Axboec28e8e82011-10-04 08:57:39 +0200536 return -1;
Jens Axboe132159a2011-09-30 15:01:32 -0600537 case FIO_NET_CMD_JOB:
Jens Axboe0b8f30a2011-10-04 10:31:53 +0200538 ret = handle_job_cmd(cmd);
Jens Axboe132159a2011-09-30 15:01:32 -0600539 break;
Jens Axboe81179ee2011-10-04 12:42:06 +0200540 case FIO_NET_CMD_JOBLINE:
541 ret = handle_jobline_cmd(cmd);
542 break;
Jens Axboec28e8e82011-10-04 08:57:39 +0200543 case FIO_NET_CMD_PROBE:
544 ret = handle_probe_cmd(cmd);
545 break;
Jens Axboeaf9c9fb2011-10-09 21:54:10 +0200546 case FIO_NET_CMD_SEND_ETA:
547 ret = handle_send_eta_cmd(cmd);
548 break;
Jens Axboeb9d2f302012-03-08 20:36:28 +0100549 case FIO_NET_CMD_RUN:
550 ret = handle_run_cmd(cmd);
551 break;
Jens Axboe132159a2011-09-30 15:01:32 -0600552 default:
Jens Axboe89c17072011-10-11 10:15:51 +0200553 log_err("fio: unknown opcode: %s\n",fio_server_op(cmd->opcode));
Jens Axboe132159a2011-09-30 15:01:32 -0600554 ret = 1;
555 }
556
557 return ret;
558}
559
Jens Axboe70e0c312011-10-04 09:18:30 +0200560static int handle_connection(int sk, int block)
Jens Axboe132159a2011-09-30 15:01:32 -0600561{
562 struct fio_net_cmd *cmd = NULL;
563 int ret = 0;
564
565 /* read forever */
566 while (!exit_backend) {
Jens Axboee951bdc2011-10-05 21:58:45 +0200567 struct pollfd pfd = {
568 .fd = sk,
569 .events = POLLIN,
570 };
571
572 ret = 0;
573 do {
574 ret = poll(&pfd, 1, 100);
575 if (ret < 0) {
576 if (errno == EINTR)
577 break;
578 log_err("fio: poll: %s\n", strerror(errno));
579 break;
Jens Axboe19c65172011-10-05 22:05:37 +0200580 } else if (!ret) {
581 if (!block)
582 return 0;
Jens Axboee951bdc2011-10-05 21:58:45 +0200583 continue;
Jens Axboe19c65172011-10-05 22:05:37 +0200584 }
Jens Axboee951bdc2011-10-05 21:58:45 +0200585
586 if (pfd.revents & POLLIN)
587 break;
588 if (pfd.revents & (POLLERR|POLLHUP)) {
589 ret = 1;
590 break;
591 }
Jens Axboe19c65172011-10-05 22:05:37 +0200592 } while (!exit_backend);
Jens Axboee951bdc2011-10-05 21:58:45 +0200593
594 if (ret < 0)
595 break;
596
597 cmd = fio_net_recv_cmd(sk);
Jens Axboe132159a2011-09-30 15:01:32 -0600598 if (!cmd) {
Jens Axboec28e8e82011-10-04 08:57:39 +0200599 ret = -1;
Jens Axboe132159a2011-09-30 15:01:32 -0600600 break;
601 }
602
Jens Axboe132159a2011-09-30 15:01:32 -0600603 ret = handle_command(cmd);
604 if (ret)
605 break;
606
607 free(cmd);
Jens Axboec77a99e2011-10-01 16:26:42 -0400608 cmd = NULL;
Jens Axboe132159a2011-09-30 15:01:32 -0600609 }
610
611 if (cmd)
612 free(cmd);
613
614 return ret;
615}
616
Jens Axboecc0df002011-10-03 20:53:32 +0200617void fio_server_idle_loop(void)
618{
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100619 if (!first_cmd_check) {
Jens Axboe5d7793a2012-03-08 19:59:16 +0100620 fio_net_send_simple_cmd(server_fd, FIO_NET_CMD_SERVER_START, 0, NULL);
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100621 first_cmd_check = 1;
622 }
Jens Axboecc0df002011-10-03 20:53:32 +0200623 if (server_fd != -1)
Jens Axboe70e0c312011-10-04 09:18:30 +0200624 handle_connection(server_fd, 0);
Jens Axboecc0df002011-10-03 20:53:32 +0200625}
626
Jens Axboe50d16972011-09-29 17:45:28 -0600627static int accept_loop(int listen_sk)
628{
Jens Axboebb447a22011-10-04 15:06:42 +0200629 struct sockaddr_in addr;
Jens Axboe5ba13ea2011-10-04 23:50:28 +0200630 fio_socklen_t len = sizeof(addr);
Jens Axboe009b1be2011-09-29 18:27:02 -0600631 struct pollfd pfd;
Jens Axboe132159a2011-09-30 15:01:32 -0600632 int ret, sk, flags, exitval = 0;
Jens Axboe50d16972011-09-29 17:45:28 -0600633
Jens Axboe60efd142011-10-04 13:30:11 +0200634 dprint(FD_NET, "server enter accept loop\n");
635
Jens Axboe009b1be2011-09-29 18:27:02 -0600636 flags = fcntl(listen_sk, F_GETFL);
637 flags |= O_NONBLOCK;
638 fcntl(listen_sk, F_SETFL, flags);
Jens Axboe50d16972011-09-29 17:45:28 -0600639again:
Jens Axboe009b1be2011-09-29 18:27:02 -0600640 pfd.fd = listen_sk;
641 pfd.events = POLLIN;
642 do {
643 ret = poll(&pfd, 1, 100);
644 if (ret < 0) {
645 if (errno == EINTR)
646 break;
Jens Axboefcee5ff2011-09-30 22:50:39 -0600647 log_err("fio: poll: %s\n", strerror(errno));
Jens Axboe009b1be2011-09-29 18:27:02 -0600648 goto out;
649 } else if (!ret)
650 continue;
651
652 if (pfd.revents & POLLIN)
653 break;
654 } while (!exit_backend);
655
656 if (exit_backend)
657 goto out;
658
Jens Axboe6b976bf2011-10-04 15:07:43 +0200659 sk = accept(listen_sk, (struct sockaddr *) &addr, &len);
Jens Axboe50d16972011-09-29 17:45:28 -0600660 if (sk < 0) {
Jens Axboe690e09a2011-09-29 18:38:08 -0600661 log_err("fio: accept: %s\n", strerror(errno));
Jens Axboe50d16972011-09-29 17:45:28 -0600662 return -1;
663 }
664
Jens Axboebb447a22011-10-04 15:06:42 +0200665 dprint(FD_NET, "server: connect from %s\n", inet_ntoa(addr.sin_addr));
Jens Axboe46c48f12011-10-01 12:50:51 -0600666
Jens Axboe37db14f2011-09-30 17:00:42 -0600667 server_fd = sk;
668
Jens Axboe70e0c312011-10-04 09:18:30 +0200669 exitval = handle_connection(sk, 1);
Jens Axboe50d16972011-09-29 17:45:28 -0600670
Jens Axboe37db14f2011-09-30 17:00:42 -0600671 server_fd = -1;
Jens Axboe50d16972011-09-29 17:45:28 -0600672 close(sk);
Jens Axboe5c341e92011-09-29 18:00:35 -0600673
Jens Axboe009b1be2011-09-29 18:27:02 -0600674 if (!exit_backend)
Jens Axboe5c341e92011-09-29 18:00:35 -0600675 goto again;
676
Jens Axboe009b1be2011-09-29 18:27:02 -0600677out:
Jens Axboe132159a2011-09-30 15:01:32 -0600678 return exitval;
Jens Axboe50d16972011-09-29 17:45:28 -0600679}
680
Jens Axboe084d1c62012-03-03 20:28:07 +0100681int fio_server_text_output(int level, const char *buf, size_t len)
Jens Axboe37db14f2011-09-30 17:00:42 -0600682{
Jens Axboe084d1c62012-03-03 20:28:07 +0100683 struct cmd_text_pdu *pdu;
684 unsigned int tlen;
685 struct timeval tv;
Jens Axboe337d75a2011-10-01 12:36:32 -0600686
Jens Axboe084d1c62012-03-03 20:28:07 +0100687 if (server_fd == -1)
688 return log_local_buf(buf, len);
689
690 tlen = sizeof(*pdu) + len;
691 pdu = malloc(tlen);
692
693 pdu->level = __cpu_to_le32(level);
694 pdu->buf_len = __cpu_to_le32(len);
695
696 gettimeofday(&tv, NULL);
697 pdu->log_sec = __cpu_to_le64(tv.tv_sec);
698 pdu->log_usec = __cpu_to_le64(tv.tv_usec);
699
700 memcpy(pdu->buf, buf, len);
701
702 fio_net_send_cmd(server_fd, FIO_NET_CMD_TEXT, pdu, tlen, 0);
703 free(pdu);
704 return len;
Jens Axboe142575e2011-09-30 17:35:45 -0600705}
706
Jens Axboea64e88d2011-10-03 14:20:01 +0200707static void convert_io_stat(struct io_stat *dst, struct io_stat *src)
708{
709 dst->max_val = cpu_to_le64(src->max_val);
710 dst->min_val = cpu_to_le64(src->min_val);
711 dst->samples = cpu_to_le64(src->samples);
Jens Axboe802ad4a2011-10-05 09:51:58 +0200712
713 /*
714 * Encode to IEEE 754 for network transfer
715 */
716 dst->mean.u.i = __cpu_to_le64(fio_double_to_uint64(src->mean.u.f));
717 dst->S.u.i = __cpu_to_le64(fio_double_to_uint64(src->S.u.f));
Jens Axboea64e88d2011-10-03 14:20:01 +0200718}
719
720static void convert_gs(struct group_run_stats *dst, struct group_run_stats *src)
721{
722 int i;
723
724 for (i = 0; i < 2; i++) {
725 dst->max_run[i] = cpu_to_le64(src->max_run[i]);
726 dst->min_run[i] = cpu_to_le64(src->min_run[i]);
727 dst->max_bw[i] = cpu_to_le64(src->max_bw[i]);
728 dst->min_bw[i] = cpu_to_le64(src->min_bw[i]);
729 dst->io_kb[i] = cpu_to_le64(src->io_kb[i]);
730 dst->agg[i] = cpu_to_le64(src->agg[i]);
731 }
732
733 dst->kb_base = cpu_to_le32(src->kb_base);
734 dst->groupid = cpu_to_le32(src->groupid);
735}
736
737/*
738 * Send a CMD_TS, which packs struct thread_stat and group_run_stats
739 * into a single payload.
740 */
741void fio_server_send_ts(struct thread_stat *ts, struct group_run_stats *rs)
742{
743 struct cmd_ts_pdu p;
744 int i, j;
745
Jens Axboe60efd142011-10-04 13:30:11 +0200746 dprint(FD_NET, "server sending end stats\n");
747
Jens Axboe317b3c82011-10-03 21:47:27 +0200748 memset(&p, 0, sizeof(p));
749
Jens Axboea64e88d2011-10-03 14:20:01 +0200750 strcpy(p.ts.name, ts->name);
751 strcpy(p.ts.verror, ts->verror);
752 strcpy(p.ts.description, ts->description);
753
Jens Axboeddcc0b62011-10-03 14:45:27 +0200754 p.ts.error = cpu_to_le32(ts->error);
Jens Axboea64e88d2011-10-03 14:20:01 +0200755 p.ts.groupid = cpu_to_le32(ts->groupid);
Jens Axboeddcc0b62011-10-03 14:45:27 +0200756 p.ts.pid = cpu_to_le32(ts->pid);
Jens Axboea64e88d2011-10-03 14:20:01 +0200757 p.ts.members = cpu_to_le32(ts->members);
758
759 for (i = 0; i < 2; i++) {
760 convert_io_stat(&p.ts.clat_stat[i], &ts->clat_stat[i]);
761 convert_io_stat(&p.ts.slat_stat[i], &ts->slat_stat[i]);
762 convert_io_stat(&p.ts.lat_stat[i], &ts->lat_stat[i]);
763 convert_io_stat(&p.ts.bw_stat[i], &ts->bw_stat[i]);
764 }
765
766 p.ts.usr_time = cpu_to_le64(ts->usr_time);
767 p.ts.sys_time = cpu_to_le64(ts->sys_time);
768 p.ts.ctx = cpu_to_le64(ts->ctx);
769 p.ts.minf = cpu_to_le64(ts->minf);
770 p.ts.majf = cpu_to_le64(ts->majf);
771 p.ts.clat_percentiles = cpu_to_le64(ts->clat_percentiles);
Jens Axboe802ad4a2011-10-05 09:51:58 +0200772
773 for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) {
Jens Axboecfc03e42011-10-12 21:20:42 +0200774 fio_fp64_t *src = &ts->percentile_list[i];
775 fio_fp64_t *dst = &p.ts.percentile_list[i];
Jens Axboe802ad4a2011-10-05 09:51:58 +0200776
Jens Axboecfc03e42011-10-12 21:20:42 +0200777 dst->u.i = __cpu_to_le64(fio_double_to_uint64(src->u.f));
Jens Axboe802ad4a2011-10-05 09:51:58 +0200778 }
Jens Axboea64e88d2011-10-03 14:20:01 +0200779
780 for (i = 0; i < FIO_IO_U_MAP_NR; i++) {
781 p.ts.io_u_map[i] = cpu_to_le32(ts->io_u_map[i]);
782 p.ts.io_u_submit[i] = cpu_to_le32(ts->io_u_submit[i]);
783 p.ts.io_u_complete[i] = cpu_to_le32(ts->io_u_complete[i]);
784 }
785
786 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) {
787 p.ts.io_u_lat_u[i] = cpu_to_le32(ts->io_u_lat_u[i]);
788 p.ts.io_u_lat_m[i] = cpu_to_le32(ts->io_u_lat_m[i]);
789 }
790
791 for (i = 0; i < 2; i++)
792 for (j = 0; j < FIO_IO_U_PLAT_NR; j++)
793 p.ts.io_u_plat[i][j] = cpu_to_le32(ts->io_u_plat[i][j]);
794
795 for (i = 0; i < 3; i++) {
796 p.ts.total_io_u[i] = cpu_to_le64(ts->total_io_u[i]);
Jens Axboe93eee042011-10-03 21:08:48 +0200797 p.ts.short_io_u[i] = cpu_to_le64(ts->short_io_u[i]);
Jens Axboea64e88d2011-10-03 14:20:01 +0200798 }
799
Jens Axboe93eee042011-10-03 21:08:48 +0200800 p.ts.total_submit = cpu_to_le64(ts->total_submit);
Jens Axboea64e88d2011-10-03 14:20:01 +0200801 p.ts.total_complete = cpu_to_le64(ts->total_complete);
802
803 for (i = 0; i < 2; i++) {
804 p.ts.io_bytes[i] = cpu_to_le64(ts->io_bytes[i]);
805 p.ts.runtime[i] = cpu_to_le64(ts->runtime[i]);
806 }
807
808 p.ts.total_run_time = cpu_to_le64(ts->total_run_time);
809 p.ts.continue_on_error = cpu_to_le16(ts->continue_on_error);
810 p.ts.total_err_count = cpu_to_le64(ts->total_err_count);
Jens Axboeddcc0b62011-10-03 14:45:27 +0200811 p.ts.first_error = cpu_to_le32(ts->first_error);
812 p.ts.kb_base = cpu_to_le32(ts->kb_base);
Jens Axboea64e88d2011-10-03 14:20:01 +0200813
814 convert_gs(&p.rs, rs);
815
Jens Axboeaf9c9fb2011-10-09 21:54:10 +0200816 fio_net_send_cmd(server_fd, FIO_NET_CMD_TS, &p, sizeof(p), 0);
Jens Axboea64e88d2011-10-03 14:20:01 +0200817}
818
819void fio_server_send_gs(struct group_run_stats *rs)
820{
821 struct group_run_stats gs;
822
Jens Axboe60efd142011-10-04 13:30:11 +0200823 dprint(FD_NET, "server sending group run stats\n");
824
Jens Axboea64e88d2011-10-03 14:20:01 +0200825 convert_gs(&gs, rs);
Jens Axboeaf9c9fb2011-10-09 21:54:10 +0200826 fio_net_send_cmd(server_fd, FIO_NET_CMD_GS, &gs, sizeof(gs), 0);
Jens Axboecf451d12011-10-03 16:48:30 +0200827}
828
Jens Axboed09a64a2011-10-13 11:38:56 +0200829static void convert_agg(struct disk_util_agg *dst, struct disk_util_agg *src)
830{
831 int i;
832
833 for (i = 0; i < 2; i++) {
834 dst->ios[i] = cpu_to_le32(src->ios[i]);
835 dst->merges[i] = cpu_to_le32(src->merges[i]);
836 dst->sectors[i] = cpu_to_le64(src->sectors[i]);
837 dst->ticks[i] = cpu_to_le32(src->ticks[i]);
838 }
839
840 dst->io_ticks = cpu_to_le32(src->io_ticks);
841 dst->time_in_queue = cpu_to_le32(src->time_in_queue);
842 dst->slavecount = cpu_to_le32(src->slavecount);
843 dst->max_util.u.i = __cpu_to_le64(fio_double_to_uint64(src->max_util.u.f));
844}
845
846static void convert_dus(struct disk_util_stat *dst, struct disk_util_stat *src)
847{
848 int i;
849
850 strcpy((char *) dst->name, (char *) src->name);
851
852 for (i = 0; i < 2; i++) {
853 dst->ios[i] = cpu_to_le32(src->ios[i]);
854 dst->merges[i] = cpu_to_le32(src->merges[i]);
855 dst->sectors[i] = cpu_to_le64(src->sectors[i]);
856 dst->ticks[i] = cpu_to_le32(src->ticks[i]);
857 }
858
859 dst->io_ticks = cpu_to_le32(src->io_ticks);
860 dst->time_in_queue = cpu_to_le32(src->time_in_queue);
861 dst->msec = cpu_to_le64(src->msec);
862}
863
864void fio_server_send_du(void)
865{
866 struct disk_util *du;
867 struct flist_head *entry;
868 struct cmd_du_pdu pdu;
869
870 dprint(FD_NET, "server: sending disk_util %d\n", !flist_empty(&disk_list));
871
Jens Axboe0766d922011-10-13 12:02:08 +0200872 memset(&pdu, 0, sizeof(pdu));
873
Jens Axboed09a64a2011-10-13 11:38:56 +0200874 flist_for_each(entry, &disk_list) {
875 du = flist_entry(entry, struct disk_util, list);
876
877 convert_dus(&pdu.dus, &du->dus);
878 convert_agg(&pdu.agg, &du->agg);
879
880 fio_net_send_cmd(server_fd, FIO_NET_CMD_DU, &pdu, sizeof(pdu), 0);
881 }
882}
883
Jens Axboe53bd8db2012-03-14 21:51:38 +0100884/*
885 * Send a command with a separate PDU, not inlined in the command
886 */
887static int fio_send_cmd_ext_pdu(int sk, uint16_t opcode, const void *buf,
888 off_t size, uint64_t tag, uint32_t flags)
889{
890 struct fio_net_cmd cmd;
891 struct iovec iov[2];
892
893 iov[0].iov_base = &cmd;
894 iov[0].iov_len = sizeof(cmd);
895 iov[1].iov_base = (void *) buf;
896 iov[1].iov_len = size;
897
898 __fio_init_net_cmd(&cmd, opcode, size, tag);
899 cmd.flags = __cpu_to_le32(flags);
900 fio_net_cmd_crc_pdu(&cmd, buf);
901
902 return fio_sendv_data(server_fd, iov, 2);
903}
904
Jens Axboe1b427252012-03-14 15:03:03 +0100905int fio_send_iolog(struct thread_data *td, struct io_log *log, const char *name)
906{
Jens Axboef5ed7652012-03-14 16:28:07 +0100907 struct cmd_iolog_pdu pdu;
Jens Axboe1b427252012-03-14 15:03:03 +0100908 z_stream stream;
909 void *out_pdu;
Jens Axboe53bd8db2012-03-14 21:51:38 +0100910 int i, ret = 0;
Jens Axboe1b427252012-03-14 15:03:03 +0100911
Jens Axboef5ed7652012-03-14 16:28:07 +0100912 pdu.nr_samples = __cpu_to_le32(log->nr_samples);
913 pdu.log_type = cpu_to_le32(log->log_type);
914 strcpy((char *) pdu.name, name);
Jens Axboe1b427252012-03-14 15:03:03 +0100915
916 for (i = 0; i < log->nr_samples; i++) {
Jens Axboef5ed7652012-03-14 16:28:07 +0100917 struct io_sample *s = &log->log[i];
Jens Axboe1b427252012-03-14 15:03:03 +0100918
Jens Axboef5ed7652012-03-14 16:28:07 +0100919 s->time = cpu_to_le64(s->time);
920 s->val = cpu_to_le64(s->val);
921 s->ddir = cpu_to_le32(s->ddir);
922 s->bs = cpu_to_le32(s->bs);
Jens Axboe1b427252012-03-14 15:03:03 +0100923 }
924
925 /*
926 * Dirty - since the log is potentially huge, compress it into
927 * FIO_SERVER_MAX_FRAGMENT_PDU chunks and let the receiving
928 * side defragment it.
929 */
930 out_pdu = malloc(FIO_SERVER_MAX_FRAGMENT_PDU);
931
932 stream.zalloc = Z_NULL;
933 stream.zfree = Z_NULL;
934 stream.opaque = Z_NULL;
935
936 if (deflateInit(&stream, Z_DEFAULT_COMPRESSION) != Z_OK) {
Jens Axboe53bd8db2012-03-14 21:51:38 +0100937 ret = 1;
938 goto err;
Jens Axboe1b427252012-03-14 15:03:03 +0100939 }
940
941 /*
Jens Axboef5ed7652012-03-14 16:28:07 +0100942 * Send header first, it's not compressed.
Jens Axboe1b427252012-03-14 15:03:03 +0100943 */
Jens Axboe53bd8db2012-03-14 21:51:38 +0100944 ret = fio_send_cmd_ext_pdu(server_fd, FIO_NET_CMD_IOLOG, &pdu,
945 sizeof(pdu), 0, FIO_NET_CMD_F_MORE);
946 if (ret)
947 goto err_zlib;
Jens Axboe1b427252012-03-14 15:03:03 +0100948
Jens Axboef5ed7652012-03-14 16:28:07 +0100949 stream.next_in = (void *) log->log;
950 stream.avail_in = log->nr_samples * sizeof(struct io_sample);
Jens Axboe1b427252012-03-14 15:03:03 +0100951
952 do {
Jens Axboe53bd8db2012-03-14 21:51:38 +0100953 unsigned int this_len, flags = 0;
954 int ret;
Jens Axboe1b427252012-03-14 15:03:03 +0100955
956 stream.avail_out = FIO_SERVER_MAX_FRAGMENT_PDU;
957 stream.next_out = out_pdu;
Jens Axboef5ed7652012-03-14 16:28:07 +0100958 assert(deflate(&stream, Z_FINISH) == Z_OK);
Jens Axboe1b427252012-03-14 15:03:03 +0100959
960 this_len = FIO_SERVER_MAX_FRAGMENT_PDU - stream.avail_out;
961
Jens Axboe1b427252012-03-14 15:03:03 +0100962 if (stream.avail_in)
Jens Axboe53bd8db2012-03-14 21:51:38 +0100963 flags = FIO_NET_CMD_F_MORE;
Jens Axboe1b427252012-03-14 15:03:03 +0100964
Jens Axboe53bd8db2012-03-14 21:51:38 +0100965 ret = fio_send_cmd_ext_pdu(server_fd, FIO_NET_CMD_IOLOG,
966 out_pdu, this_len, 0, flags);
967 if (ret)
968 goto err_zlib;
Jens Axboe1b427252012-03-14 15:03:03 +0100969 } while (stream.avail_in);
970
Jens Axboe53bd8db2012-03-14 21:51:38 +0100971err_zlib:
Jens Axboe1b427252012-03-14 15:03:03 +0100972 deflateEnd(&stream);
Jens Axboe53bd8db2012-03-14 21:51:38 +0100973err:
974 free(out_pdu);
975 return ret;
Jens Axboe1b427252012-03-14 15:03:03 +0100976}
977
Jens Axboe807f9972012-03-02 10:25:24 +0100978void fio_server_send_add_job(struct thread_options *o, const char *ioengine)
979{
980 struct cmd_add_job_pdu pdu;
Jens Axboe807f9972012-03-02 10:25:24 +0100981
Jens Axboe731e30a2012-03-14 16:35:37 +0100982 memset(&pdu, 0, sizeof(pdu));
Jens Axboedcaeb602012-03-08 19:45:37 +0100983 convert_thread_options_to_net(&pdu.top, o);
Jens Axboe807f9972012-03-02 10:25:24 +0100984
985 fio_net_send_cmd(server_fd, FIO_NET_CMD_ADD_JOB, &pdu, sizeof(pdu), 0);
986}
987
Jens Axboe87aa8f12011-10-06 21:24:13 +0200988static int fio_init_server_ip(void)
Jens Axboe81179ee2011-10-04 12:42:06 +0200989{
Jens Axboe811826b2011-10-24 09:11:50 +0200990 struct sockaddr *addr;
991 fio_socklen_t socklen;
Jens Axboe87aa8f12011-10-06 21:24:13 +0200992 int sk, opt;
Jens Axboe81179ee2011-10-04 12:42:06 +0200993
Jens Axboe811826b2011-10-24 09:11:50 +0200994 if (use_ipv6)
995 sk = socket(AF_INET6, SOCK_STREAM, 0);
996 else
997 sk = socket(AF_INET, SOCK_STREAM, 0);
998
Jens Axboe81179ee2011-10-04 12:42:06 +0200999 if (sk < 0) {
1000 log_err("fio: socket: %s\n", strerror(errno));
1001 return -1;
1002 }
1003
1004 opt = 1;
1005 if (setsockopt(sk, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) {
1006 log_err("fio: setsockopt: %s\n", strerror(errno));
Jens Axboeb94cba42011-10-06 21:27:10 +02001007 close(sk);
Jens Axboe81179ee2011-10-04 12:42:06 +02001008 return -1;
1009 }
1010#ifdef SO_REUSEPORT
Jens Axboe6eb24792011-10-04 15:00:30 +02001011 if (setsockopt(sk, SOL_SOCKET, SO_REUSEPORT, &opt, sizeof(opt)) < 0) {
Jens Axboe81179ee2011-10-04 12:42:06 +02001012 log_err("fio: setsockopt: %s\n", strerror(errno));
Jens Axboeb94cba42011-10-06 21:27:10 +02001013 close(sk);
Jens Axboe81179ee2011-10-04 12:42:06 +02001014 return -1;
1015 }
1016#endif
1017
Jens Axboe811826b2011-10-24 09:11:50 +02001018 if (use_ipv6) {
1019 addr = (struct sockaddr *) &saddr_in6;
1020 socklen = sizeof(saddr_in6);
1021 saddr_in6.sin6_family = AF_INET6;
1022 } else {
1023 addr = (struct sockaddr *) &saddr_in;
1024 socklen = sizeof(saddr_in);
1025 saddr_in.sin_family = AF_INET;
1026 }
Jens Axboe81179ee2011-10-04 12:42:06 +02001027
Jens Axboe811826b2011-10-24 09:11:50 +02001028 if (bind(sk, addr, socklen) < 0) {
Jens Axboe81179ee2011-10-04 12:42:06 +02001029 log_err("fio: bind: %s\n", strerror(errno));
Jens Axboeb94cba42011-10-06 21:27:10 +02001030 close(sk);
Jens Axboe81179ee2011-10-04 12:42:06 +02001031 return -1;
1032 }
1033
Jens Axboe87aa8f12011-10-06 21:24:13 +02001034 return sk;
1035}
1036
1037static int fio_init_server_sock(void)
1038{
1039 struct sockaddr_un addr;
1040 fio_socklen_t len;
1041 mode_t mode;
1042 int sk;
1043
1044 sk = socket(AF_UNIX, SOCK_STREAM, 0);
1045 if (sk < 0) {
1046 log_err("fio: socket: %s\n", strerror(errno));
1047 return -1;
1048 }
1049
1050 mode = umask(000);
1051
1052 memset(&addr, 0, sizeof(addr));
1053 addr.sun_family = AF_UNIX;
1054 strcpy(addr.sun_path, bind_sock);
1055 unlink(bind_sock);
1056
1057 len = sizeof(addr.sun_family) + strlen(bind_sock) + 1;
1058
1059 if (bind(sk, (struct sockaddr *) &addr, len) < 0) {
1060 log_err("fio: bind: %s\n", strerror(errno));
Jens Axboeb94cba42011-10-06 21:27:10 +02001061 close(sk);
Jens Axboe87aa8f12011-10-06 21:24:13 +02001062 return -1;
1063 }
1064
1065 umask(mode);
1066 return sk;
1067}
1068
1069static int fio_init_server_connection(void)
1070{
Jens Axboebebe6392011-10-07 10:00:51 +02001071 char bind_str[128];
Jens Axboe87aa8f12011-10-06 21:24:13 +02001072 int sk;
1073
1074 dprint(FD_NET, "starting server\n");
1075
1076 if (!bind_sock)
1077 sk = fio_init_server_ip();
1078 else
1079 sk = fio_init_server_sock();
1080
1081 if (sk < 0)
1082 return sk;
1083
Jens Axboe811826b2011-10-24 09:11:50 +02001084 if (!bind_sock) {
1085 char *p, port[16];
1086 const void *src;
1087 int af;
1088
1089 if (use_ipv6) {
1090 af = AF_INET6;
1091 src = &saddr_in6.sin6_addr;
1092 } else {
1093 af = AF_INET;
1094 src = &saddr_in.sin_addr;
1095 }
1096
1097 p = (char *) inet_ntop(af, src, bind_str, sizeof(bind_str));
1098
1099 sprintf(port, ",%u", fio_net_port);
1100 if (p)
1101 strcat(p, port);
1102 else
1103 strcpy(bind_str, port);
1104 } else
Jens Axboebebe6392011-10-07 10:00:51 +02001105 strcpy(bind_str, bind_sock);
1106
1107 log_info("fio: server listening on %s\n", bind_str);
1108
Jens Axboe89c17072011-10-11 10:15:51 +02001109 if (listen(sk, 0) < 0) {
Jens Axboe81179ee2011-10-04 12:42:06 +02001110 log_err("fio: listen: %s\n", strerror(errno));
1111 return -1;
1112 }
1113
Jens Axboe87aa8f12011-10-06 21:24:13 +02001114 return sk;
1115}
1116
Jens Axboe3ec62ec2012-03-01 12:01:29 +01001117int fio_server_parse_host(const char *host, int *ipv6, struct in_addr *inp,
1118 struct in6_addr *inp6)
1119
1120{
1121 int ret = 0;
1122
1123 if (*ipv6)
1124 ret = inet_pton(AF_INET6, host, inp6);
1125 else
1126 ret = inet_pton(AF_INET, host, inp);
1127
1128 if (ret != 1) {
1129 struct hostent *hent;
1130
1131 hent = gethostbyname(host);
1132 if (!hent) {
1133 log_err("fio: failed to resolve <%s>\n", host);
1134 return 0;
1135 }
1136
1137 if (*ipv6) {
1138 if (hent->h_addrtype != AF_INET6) {
1139 log_info("fio: falling back to IPv4\n");
1140 *ipv6 = 0;
1141 } else
1142 memcpy(inp6, hent->h_addr_list[0], 16);
1143 }
1144 if (!*ipv6) {
1145 if (hent->h_addrtype != AF_INET) {
1146 log_err("fio: lookup type mismatch\n");
1147 return 0;
1148 }
1149 memcpy(inp, hent->h_addr_list[0], 4);
1150 }
1151 ret = 1;
1152 }
1153
1154 return !(ret == 1);
1155}
1156
Jens Axboe660a2bf2011-10-24 09:35:06 +02001157/*
1158 * Parse a host/ip/port string. Reads from 'str'.
1159 *
1160 * Outputs:
1161 *
1162 * For IPv4:
1163 * *ptr is the host, *port is the port, inp is the destination.
1164 * For IPv6:
1165 * *ptr is the host, *port is the port, inp6 is the dest, and *ipv6 is 1.
1166 * For local domain sockets:
1167 * *ptr is the filename, *is_sock is 1.
1168 */
Jens Axboebebe6392011-10-07 10:00:51 +02001169int fio_server_parse_string(const char *str, char **ptr, int *is_sock,
Jens Axboe811826b2011-10-24 09:11:50 +02001170 int *port, struct in_addr *inp,
1171 struct in6_addr *inp6, int *ipv6)
Jens Axboebebe6392011-10-07 10:00:51 +02001172{
Jens Axboe76867622011-10-25 09:52:51 +02001173 const char *host = str;
1174 char *portp;
Jens Axboe3ec62ec2012-03-01 12:01:29 +01001175 int lport = 0;
Jens Axboe76867622011-10-25 09:52:51 +02001176
Jens Axboebebe6392011-10-07 10:00:51 +02001177 *ptr = NULL;
1178 *is_sock = 0;
Jens Axboe6d2cf392011-10-07 13:19:28 +02001179 *port = fio_net_port;
Jens Axboe811826b2011-10-24 09:11:50 +02001180 *ipv6 = 0;
Jens Axboebebe6392011-10-07 10:00:51 +02001181
1182 if (!strncmp(str, "sock:", 5)) {
1183 *ptr = strdup(str + 5);
1184 *is_sock = 1;
Jens Axboebebe6392011-10-07 10:00:51 +02001185
Jens Axboe76867622011-10-25 09:52:51 +02001186 return 0;
1187 }
1188
1189 /*
1190 * Is it ip:<ip or host>:port
1191 */
1192 if (!strncmp(host, "ip:", 3))
1193 host += 3;
1194 else if (!strncmp(host, "ip4:", 4))
1195 host += 4;
1196 else if (!strncmp(host, "ip6:", 4)) {
1197 host += 4;
1198 *ipv6 = 1;
1199 } else if (host[0] == ':') {
1200 /* String is :port */
1201 host++;
1202 lport = atoi(host);
1203 if (!lport || lport > 65535) {
1204 log_err("fio: bad server port %u\n", port);
1205 return 1;
1206 }
1207 /* no hostname given, we are done */
1208 *port = lport;
1209 return 0;
1210 }
1211
1212 /*
1213 * If no port seen yet, check if there's a last ':' at the end
1214 */
1215 if (!lport) {
1216 portp = strchr(host, ',');
1217 if (portp) {
1218 *portp = '\0';
1219 portp++;
1220 lport = atoi(portp);
Jens Axboebebe6392011-10-07 10:00:51 +02001221 if (!lport || lport > 65535) {
1222 log_err("fio: bad server port %u\n", port);
1223 return 1;
1224 }
Jens Axboe76867622011-10-25 09:52:51 +02001225 }
1226 }
1227
1228 if (lport)
1229 *port = lport;
1230
1231 if (!strlen(host))
1232 return 0;
1233
1234 *ptr = strdup(host);
1235
Jens Axboe3ec62ec2012-03-01 12:01:29 +01001236 if (fio_server_parse_host(*ptr, ipv6, inp, inp6)) {
1237 free(*ptr);
1238 *ptr = NULL;
1239 return 1;
Jens Axboebebe6392011-10-07 10:00:51 +02001240 }
1241
1242 if (*port == 0)
1243 *port = fio_net_port;
1244
1245 return 0;
1246}
1247
Jens Axboe87aa8f12011-10-06 21:24:13 +02001248/*
1249 * Server arg should be one of:
1250 *
1251 * sock:/path/to/socket
1252 * ip:1.2.3.4
1253 * 1.2.3.4
1254 *
1255 * Where sock uses unix domain sockets, and ip binds the server to
1256 * a specific interface. If no arguments are given to the server, it
1257 * uses IP and binds to 0.0.0.0.
1258 *
1259 */
1260static int fio_handle_server_arg(void)
1261{
Jens Axboe6d2cf392011-10-07 13:19:28 +02001262 int port = fio_net_port;
Jens Axboea7de0a12011-10-07 12:55:14 +02001263 int is_sock, ret = 0;
Jens Axboebebe6392011-10-07 10:00:51 +02001264
Jens Axboe87aa8f12011-10-06 21:24:13 +02001265 saddr_in.sin_addr.s_addr = htonl(INADDR_ANY);
1266
1267 if (!fio_server_arg)
Jens Axboea7de0a12011-10-07 12:55:14 +02001268 goto out;
Jens Axboe87aa8f12011-10-06 21:24:13 +02001269
Jens Axboe4e5b8fb2011-10-07 10:03:44 +02001270 ret = fio_server_parse_string(fio_server_arg, &bind_sock, &is_sock,
Jens Axboe811826b2011-10-24 09:11:50 +02001271 &port, &saddr_in.sin_addr,
1272 &saddr_in6.sin6_addr, &use_ipv6);
Jens Axboe4e5b8fb2011-10-07 10:03:44 +02001273
1274 if (!is_sock && bind_sock) {
1275 free(bind_sock);
1276 bind_sock = NULL;
1277 }
1278
Jens Axboea7de0a12011-10-07 12:55:14 +02001279out:
Jens Axboe6d2cf392011-10-07 13:19:28 +02001280 fio_net_port = port;
1281 saddr_in.sin_port = htons(port);
Jens Axboe811826b2011-10-24 09:11:50 +02001282 saddr_in6.sin6_port = htons(port);
Jens Axboe4e5b8fb2011-10-07 10:03:44 +02001283 return ret;
Jens Axboe87aa8f12011-10-06 21:24:13 +02001284}
1285
1286static int fio_server(void)
1287{
1288 int sk, ret;
1289
1290 dprint(FD_NET, "starting server\n");
1291
1292 if (fio_handle_server_arg())
1293 return -1;
1294
1295 sk = fio_init_server_connection();
1296 if (sk < 0)
1297 return -1;
Jens Axboe81179ee2011-10-04 12:42:06 +02001298
1299 ret = accept_loop(sk);
Jens Axboe87aa8f12011-10-06 21:24:13 +02001300
Jens Axboe81179ee2011-10-04 12:42:06 +02001301 close(sk);
Jens Axboe87aa8f12011-10-06 21:24:13 +02001302
1303 if (fio_server_arg) {
1304 free(fio_server_arg);
1305 fio_server_arg = NULL;
1306 }
Jens Axboebebe6392011-10-07 10:00:51 +02001307 if (bind_sock)
1308 free(bind_sock);
Jens Axboe87aa8f12011-10-06 21:24:13 +02001309
Jens Axboe81179ee2011-10-04 12:42:06 +02001310 return ret;
1311}
1312
Jens Axboe7b821682011-10-11 12:16:32 +02001313void fio_server_got_signal(int signal)
Jens Axboe9abea482011-10-04 13:21:54 +02001314{
Jens Axboe7b821682011-10-11 12:16:32 +02001315 if (signal == SIGPIPE)
1316 server_fd = -1;
1317 else {
1318 log_info("\nfio: terminating on signal %d\n", signal);
1319 exit_backend = 1;
1320 }
Jens Axboe9abea482011-10-04 13:21:54 +02001321}
1322
Jens Axboe13755d92011-10-10 19:51:26 +02001323static int check_existing_pidfile(const char *pidfile)
1324{
1325 struct stat sb;
1326 char buf[16];
1327 pid_t pid;
1328 FILE *f;
1329
1330 if (stat(pidfile, &sb))
1331 return 0;
1332
1333 f = fopen(pidfile, "r");
1334 if (!f)
1335 return 0;
1336
Jens Axboebfc3b172011-10-10 21:16:55 +02001337 if (fread(buf, sb.st_size, 1, f) <= 0) {
Jens Axboe13755d92011-10-10 19:51:26 +02001338 fclose(f);
1339 return 1;
1340 }
1341 fclose(f);
1342
1343 pid = atoi(buf);
1344 if (kill(pid, SIGCONT) < 0)
Jens Axboeea5aa1b2011-10-11 11:45:35 +02001345 return errno != ESRCH;
Jens Axboe13755d92011-10-10 19:51:26 +02001346
1347 return 1;
1348}
1349
1350static int write_pid(pid_t pid, const char *pidfile)
Jens Axboe402668f2011-10-10 15:28:58 +02001351{
1352 FILE *fpid;
1353
1354 fpid = fopen(pidfile, "w");
1355 if (!fpid) {
1356 log_err("fio: failed opening pid file %s\n", pidfile);
Jens Axboe13755d92011-10-10 19:51:26 +02001357 return 1;
Jens Axboe402668f2011-10-10 15:28:58 +02001358 }
1359
1360 fprintf(fpid, "%u\n", (unsigned int) pid);
Jens Axboe13755d92011-10-10 19:51:26 +02001361 fclose(fpid);
1362 return 0;
Jens Axboe402668f2011-10-10 15:28:58 +02001363}
1364
1365/*
1366 * If pidfile is specified, background us.
1367 */
1368int fio_start_server(char *pidfile)
Jens Axboee46d8092011-10-03 09:11:02 +02001369{
1370 pid_t pid;
Jens Axboe402668f2011-10-10 15:28:58 +02001371 int ret;
Jens Axboee46d8092011-10-03 09:11:02 +02001372
Bruce Cran93bcfd22012-02-20 20:18:19 +01001373#if defined(WIN32)
Jens Axboe905c78b2012-03-06 19:34:22 +01001374 WSADATA wsd;
1375 WSAStartup(MAKEWORD(2,2), &wsd);
Bruce Cran93bcfd22012-02-20 20:18:19 +01001376#endif
1377
Jens Axboe402668f2011-10-10 15:28:58 +02001378 if (!pidfile)
Jens Axboee46d8092011-10-03 09:11:02 +02001379 return fio_server();
1380
Jens Axboe13755d92011-10-10 19:51:26 +02001381 if (check_existing_pidfile(pidfile)) {
1382 log_err("fio: pidfile %s exists and server appears alive\n",
1383 pidfile);
1384 return -1;
1385 }
1386
Jens Axboee46d8092011-10-03 09:11:02 +02001387 pid = fork();
1388 if (pid < 0) {
Jens Axboe13755d92011-10-10 19:51:26 +02001389 log_err("fio: failed server fork: %s", strerror(errno));
Jens Axboe402668f2011-10-10 15:28:58 +02001390 free(pidfile);
Jens Axboec28e8e82011-10-04 08:57:39 +02001391 return -1;
Jens Axboe402668f2011-10-10 15:28:58 +02001392 } else if (pid) {
Jens Axboe13755d92011-10-10 19:51:26 +02001393 int ret = write_pid(pid, pidfile);
1394
1395 exit(ret);
Jens Axboe402668f2011-10-10 15:28:58 +02001396 }
Jens Axboee46d8092011-10-03 09:11:02 +02001397
1398 setsid();
Jens Axboe13755d92011-10-10 19:51:26 +02001399 openlog("fio", LOG_NDELAY|LOG_NOWAIT|LOG_PID, LOG_USER);
1400 log_syslog = 1;
Jens Axboee46d8092011-10-03 09:11:02 +02001401 close(STDIN_FILENO);
1402 close(STDOUT_FILENO);
1403 close(STDERR_FILENO);
1404 f_out = NULL;
1405 f_err = NULL;
Jens Axboe402668f2011-10-10 15:28:58 +02001406
1407 ret = fio_server();
1408
1409 closelog();
1410 unlink(pidfile);
1411 free(pidfile);
1412 return ret;
Jens Axboee46d8092011-10-03 09:11:02 +02001413}
Jens Axboe87aa8f12011-10-06 21:24:13 +02001414
Jens Axboebebe6392011-10-07 10:00:51 +02001415void fio_server_set_arg(const char *arg)
Jens Axboe87aa8f12011-10-06 21:24:13 +02001416{
1417 fio_server_arg = strdup(arg);
1418}