#include "crc/crc16.h"
#include "ieee754.h"
+#include "fio_version.h"
+
int fio_net_port = 8765;
int exit_backend = 0;
cmd->pdu_len = le32_to_cpu(cmd->pdu_len);
switch (cmd->version) {
- case FIO_SERVER_VER2:
+ case FIO_SERVER_VER:
break;
default:
log_err("fio: bad server cmd version %d\n", cmd->version);
static int handle_jobline_cmd(struct fio_net_cmd *cmd)
{
- struct cmd_line_pdu *pdu = (struct cmd_line_pdu *) cmd->payload;
- char *argv[FIO_NET_CMD_JOBLINE_ARGV];
+ void *pdu = cmd->payload;
+ struct cmd_single_line_pdu *cslp;
+ struct cmd_line_pdu *clp;
+ unsigned long offset;
+ char **argv;
int ret, i;
- pdu->argc = le16_to_cpu(pdu->argc);
+ clp = pdu;
+ clp->lines = le16_to_cpu(clp->lines);
+ argv = malloc(clp->lines * sizeof(char *));
+ offset = sizeof(*clp);
+
+ dprint(FD_NET, "server: %d command line args\n", clp->lines);
- dprint(FD_NET, "server: %d command line args\n", pdu->argc);
+ for (i = 0; i < clp->lines; i++) {
+ cslp = pdu + offset;
+ argv[i] = (char *) cslp->text;
- for (i = 0; i < pdu->argc; i++) {
- argv[i] = (char *) pdu->argv[i];
+ offset += sizeof(*cslp) + le16_to_cpu(cslp->len);
dprint(FD_NET, "server: %d: %s\n", i, argv[i]);
}
- if (parse_cmd_line(pdu->argc, argv)) {
+ if (parse_cmd_line(clp->lines, argv)) {
fio_server_send_quit_cmd();
+ free(argv);
return -1;
}
+ free(argv);
+
fio_net_send_simple_cmd(server_fd, FIO_NET_CMD_START, 0);
ret = exec_run();
probe.fio_minor = FIO_MINOR;
probe.fio_patch = FIO_PATCH;
+ probe.os = FIO_OS;
+ probe.arch = FIO_ARCH;
+
return fio_net_send_cmd(server_fd, FIO_NET_CMD_PROBE, &probe, sizeof(probe));
}
#endif
saddr_in.sin_family = AF_INET;
- saddr_in.sin_port = htons(fio_net_port);
if (bind(sk, (struct sockaddr *) &saddr_in, sizeof(saddr_in)) < 0) {
log_err("fio: bind: %s\n", strerror(errno));
static int fio_init_server_connection(void)
{
+ char bind_str[128];
int sk;
dprint(FD_NET, "starting server\n");
if (sk < 0)
return sk;
+ if (!bind_sock)
+ sprintf(bind_str, "%s:%u", inet_ntoa(saddr_in.sin_addr), fio_net_port);
+ else
+ strcpy(bind_str, bind_sock);
+
+ log_info("fio: server listening on %s\n", bind_str);
+
if (listen(sk, 1) < 0) {
log_err("fio: listen: %s\n", strerror(errno));
return -1;
return sk;
}
+int fio_server_parse_string(const char *str, char **ptr, int *is_sock,
+ int *port, struct in_addr *inp)
+{
+ *ptr = NULL;
+ *is_sock = 0;
+ *port = fio_net_port;
+
+ if (!strncmp(str, "sock:", 5)) {
+ *ptr = strdup(str + 5);
+ *is_sock = 1;
+ } else {
+ const char *host = str;
+ char *portp;
+ int lport = 0;
+
+ /*
+ * Is it ip:<ip or host>:port
+ */
+ if (!strncmp(host, "ip:", 3))
+ host += 3;
+ else if (host[0] == ':') {
+ /* String is :port */
+ host++;
+ lport = atoi(host);
+ if (!lport || lport > 65535) {
+ log_err("fio: bad server port %u\n", port);
+ return 1;
+ }
+ /* no hostname given, we are done */
+ *port = lport;
+ return 0;
+ }
+
+ /*
+ * If no port seen yet, check if there's a last ':' at the end
+ */
+ if (!lport) {
+ portp = strchr(host, ':');
+ if (portp) {
+ *portp = '\0';
+ portp++;
+ lport = atoi(portp);
+ if (!lport || lport > 65535) {
+ log_err("fio: bad server port %u\n", port);
+ return 1;
+ }
+ }
+ }
+
+ if (lport)
+ *port = lport;
+
+ *ptr = strdup(host);
+
+ if (inet_aton(host, inp) != 1) {
+ struct hostent *hent;
+
+ hent = gethostbyname(host);
+ if (!hent) {
+ free(*ptr);
+ *ptr = NULL;
+ return 1;
+ }
+
+ memcpy(inp, hent->h_addr, 4);
+ }
+ }
+
+ if (*port == 0)
+ *port = fio_net_port;
+
+ return 0;
+}
+
/*
* Server arg should be one of:
*
*/
static int fio_handle_server_arg(void)
{
+ int port = fio_net_port;
+ int is_sock, ret = 0;
+
saddr_in.sin_addr.s_addr = htonl(INADDR_ANY);
if (!fio_server_arg)
- return 0;
- if (!strncmp(fio_server_arg, "sock:", 5)) {
- bind_sock = fio_server_arg += 5;
- return 0;
- } else {
- char *host = fio_server_arg;
-
- if (!strncmp(host, "ip:", 3))
- host += 3;
+ goto out;
- if (inet_aton(host, &saddr_in.sin_addr) != 1) {
- struct hostent *hent;
+ ret = fio_server_parse_string(fio_server_arg, &bind_sock, &is_sock,
+ &port, &saddr_in.sin_addr);
- hent = gethostbyname(host);
- if (hent)
- memcpy(&saddr_in.sin_addr, hent->h_addr, 4);
- }
- return 0;
+ if (!is_sock && bind_sock) {
+ free(bind_sock);
+ bind_sock = NULL;
}
+
+out:
+ fio_net_port = port;
+ saddr_in.sin_port = htons(port);
+ return ret;
}
static int fio_server(void)
free(fio_server_arg);
fio_server_arg = NULL;
}
+ if (bind_sock)
+ free(bind_sock);
return ret;
}
return fio_server();
}
-void fio_server_add_arg(const char *arg)
+void fio_server_set_arg(const char *arg)
{
fio_server_arg = strdup(arg);
}