X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=server.c;h=a2db9dd5ccfdd5352894e0a1a4451d1ece22ebe6;hp=5e94696eb6aa6ee79d34668723b3981f1384d4dd;hb=3ec62ec45ce971b76dd3029412dfd3d0c6221384;hpb=25dfa848abbb6c35b4d45fabd5a8e82cb77fb285 diff --git a/server.c b/server.c index 5e94696e..a2db9dd5 100644 --- a/server.c +++ b/server.c @@ -24,7 +24,7 @@ #include "fio_version.h" -int fio_net_port = 8765; +int fio_net_port = FIO_NET_PORT; int exit_backend = 0; @@ -443,12 +443,12 @@ static int handle_send_eta_cmd(struct fio_net_cmd *cmd) je->nr_ramp = cpu_to_le32(je->nr_ramp); je->nr_pending = cpu_to_le32(je->nr_pending); je->files_open = cpu_to_le32(je->files_open); - je->m_rate = cpu_to_le32(je->m_rate); - je->t_rate = cpu_to_le32(je->t_rate); - je->m_iops = cpu_to_le32(je->m_iops); - je->t_iops = cpu_to_le32(je->t_iops); for (i = 0; i < 2; i++) { + je->m_rate[i] = cpu_to_le32(je->m_rate[i]); + je->t_rate[i] = cpu_to_le32(je->t_rate[i]); + je->m_iops[i] = cpu_to_le32(je->m_iops[i]); + je->t_iops[i] = cpu_to_le32(je->t_iops[i]); je->rate[i] = cpu_to_le32(je->rate[i]); je->iops[i] = cpu_to_le32(je->iops[i]); } @@ -554,8 +554,10 @@ static int handle_connection(int sk, int block) void fio_server_idle_loop(void) { - if (!first_cmd_check) + if (!first_cmd_check) { fio_net_send_simple_cmd(server_fd, FIO_NET_CMD_RUN, 0, NULL); + first_cmd_check = 1; + } if (server_fd != -1) handle_connection(server_fd, 0); } @@ -943,6 +945,46 @@ static int fio_init_server_connection(void) return sk; } +int fio_server_parse_host(const char *host, int *ipv6, struct in_addr *inp, + struct in6_addr *inp6) + +{ + int ret = 0; + + if (*ipv6) + ret = inet_pton(AF_INET6, host, inp6); + else + ret = inet_pton(AF_INET, host, inp); + + if (ret != 1) { + struct hostent *hent; + + hent = gethostbyname(host); + if (!hent) { + log_err("fio: failed to resolve <%s>\n", host); + return 0; + } + + if (*ipv6) { + if (hent->h_addrtype != AF_INET6) { + log_info("fio: falling back to IPv4\n"); + *ipv6 = 0; + } else + memcpy(inp6, hent->h_addr_list[0], 16); + } + if (!*ipv6) { + if (hent->h_addrtype != AF_INET) { + log_err("fio: lookup type mismatch\n"); + return 0; + } + memcpy(inp, hent->h_addr_list[0], 4); + } + ret = 1; + } + + return !(ret == 1); +} + /* * Parse a host/ip/port string. Reads from 'str'. * @@ -961,7 +1003,7 @@ int fio_server_parse_string(const char *str, char **ptr, int *is_sock, { const char *host = str; char *portp; - int ret, lport = 0; + int lport = 0; *ptr = NULL; *is_sock = 0; @@ -1022,38 +1064,10 @@ int fio_server_parse_string(const char *str, char **ptr, int *is_sock, *ptr = strdup(host); - if (*ipv6) - ret = inet_pton(AF_INET6, host, inp6); - else - ret = inet_pton(AF_INET, host, inp); - - if (ret != 1) { - struct hostent *hent; - - hent = gethostbyname(host); - if (!hent) { - log_err("fio: failed to resolve <%s>\n", host); - free(*ptr); - *ptr = NULL; - return 1; - } - - if (*ipv6) { - if (hent->h_addrtype != AF_INET6) { - log_info("fio: falling back to IPv4\n"); - *ipv6 = 0; - } else - memcpy(inp6, hent->h_addr_list[0], 16); - } - if (!*ipv6) { - if (hent->h_addrtype != AF_INET) { - log_err("fio: lookup type mismatch\n"); - free(*ptr); - *ptr = NULL; - return 1; - } - memcpy(inp, hent->h_addr_list[0], 4); - } + if (fio_server_parse_host(*ptr, ipv6, inp, inp6)) { + free(*ptr); + *ptr = NULL; + return 1; } if (*port == 0)