X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=server.c;h=fe93ffbebda4840e46683187bdd4efc567e048a4;hp=f393873f44486f949ff397408a31cdd53e431a07;hb=bdab4441a476b8597001026445707daa1109aec2;hpb=132159a5a062cabfe963b3d57e82a80741bf5506 diff --git a/server.c b/server.c index f393873f..fe93ffbe 100644 --- a/server.c +++ b/server.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -14,7 +15,7 @@ #include "fio.h" #include "server.h" -#include "crc/crc32.h" +#include "crc/crc16.h" int fio_net_port = 8765; @@ -24,6 +25,8 @@ static char *job_buf; static unsigned int job_cur_len; static unsigned int job_max_len; +static int server_fd; + int fio_send_data(int sk, const void *p, unsigned int len) { do { @@ -72,15 +75,15 @@ int fio_recv_data(int sk, void *p, unsigned int len) static int verify_convert_cmd(struct fio_net_cmd *cmd) { - uint32_t crc; + uint16_t crc; - cmd->cmd_crc32 = le32_to_cpu(cmd->cmd_crc32); - cmd->pdu_crc32 = le32_to_cpu(cmd->pdu_crc32); + cmd->cmd_crc16 = le16_to_cpu(cmd->cmd_crc16); + cmd->pdu_crc16 = le16_to_cpu(cmd->pdu_crc16); - crc = crc32(cmd, sizeof(*cmd) - 2 * sizeof(uint32_t)); - if (crc != cmd->cmd_crc32) { + crc = crc16(cmd, FIO_NET_CMD_CRC_SZ); + if (crc != cmd->cmd_crc16) { log_err("fio: server bad crc on command (got %x, wanted %x)\n", - cmd->cmd_crc32, crc); + cmd->cmd_crc16, crc); return 1; } @@ -106,10 +109,10 @@ static int verify_convert_cmd(struct fio_net_cmd *cmd) return 0; } -static struct fio_net_cmd *read_command(int sk) +struct fio_net_cmd *fio_net_cmd_read(int sk) { struct fio_net_cmd cmd, *ret = NULL; - uint32_t crc; + uint16_t crc; if (fio_recv_data(sk, &cmd, sizeof(cmd))) return NULL; @@ -132,15 +135,14 @@ static struct fio_net_cmd *read_command(int sk) } /* Verify payload crc */ - crc = crc32(ret->payload, ret->pdu_len); - if (crc != ret->pdu_crc32) { + crc = crc16(ret->payload, ret->pdu_len); + if (crc != ret->pdu_crc16) { log_err("fio: server bad crc on payload (got %x, wanted %x)\n", - ret->pdu_crc32, crc); + ret->pdu_crc16, crc); free(ret); return NULL; } - return ret; } @@ -148,12 +150,11 @@ void fio_net_cmd_crc(struct fio_net_cmd *cmd) { uint32_t pdu_len; - cmd->cmd_crc32 = cpu_to_le32(crc32(cmd, - sizeof(*cmd) - 2 * sizeof(uint32_t))); + cmd->cmd_crc16 = cpu_to_le16(crc16(cmd, FIO_NET_CMD_CRC_SZ)); pdu_len = le32_to_cpu(cmd->pdu_len); if (pdu_len) - cmd->pdu_crc32 = cpu_to_le32(crc32(cmd->payload, pdu_len)); + cmd->pdu_crc16 = cpu_to_le16(crc16(cmd->payload, pdu_len)); } static int send_simple_command(int sk, uint16_t opcode, uint64_t serial) @@ -161,7 +162,7 @@ static int send_simple_command(int sk, uint16_t opcode, uint64_t serial) struct fio_net_cmd cmd = { .version = cpu_to_le16(FIO_SERVER_VER1), .opcode = cpu_to_le16(opcode), - .serial = cpu_to_le16(serial), + .serial = cpu_to_le64(serial), }; fio_net_cmd_crc(&cmd); @@ -174,7 +175,11 @@ static int send_simple_command(int sk, uint16_t opcode, uint64_t serial) */ static int ack_command(int sk, struct fio_net_cmd *cmd) { +#if 0 return send_simple_command(sk, FIO_NET_CMD_ACK, cmd->serial); +#else + return 0; +#endif } #if 0 @@ -242,7 +247,7 @@ static int handle_connection(int sk) /* read forever */ while (!exit_backend) { - cmd = read_command(sk); + cmd = fio_net_cmd_read(sk); if (!cmd) { ret = 1; break; @@ -283,7 +288,7 @@ again: if (ret < 0) { if (errno == EINTR) break; - perror("poll"); + log_err("fio: poll: %s\n", strerror(errno)); goto out; } else if (!ret) continue; @@ -301,8 +306,11 @@ again: return -1; } + server_fd = sk; + exitval = handle_connection(sk); + server_fd = -1; close(sk); if (!exit_backend) @@ -361,3 +369,30 @@ int fio_server(void) close(sk); return ret; } + +int fio_server_text_output(const char *buf, unsigned int len) +{ + struct fio_net_cmd *cmd; + int size = sizeof(*cmd) + len; + + cmd = malloc(size); + fio_init_net_cmd(cmd, FIO_NET_CMD_TEXT, buf, len); + fio_net_cmd_crc(cmd); + + fio_send_data(server_fd, cmd, size); + free(cmd); + return size; +} + +int fio_server_log(const char *format, ...) +{ + char buffer[1024]; + va_list args; + size_t len; + + va_start(args, format); + len = vsnprintf(buffer, sizeof(buffer), format, args); + va_end(args); + + return fio_server_text_output(buffer, len); +}