server: switch to 16-bit crc
authorJens Axboe <axboe@kernel.dk>
Sat, 1 Oct 2011 04:50:39 +0000 (22:50 -0600)
committerJens Axboe <axboe@kernel.dk>
Sat, 1 Oct 2011 04:50:39 +0000 (22:50 -0600)
Good enough and we can kill the command padding

Signed-off-by: Jens Axboe <axboe@kernel.dk>
server.c
server.h

index 79c10410a316b05a21ccd83241e529bfa91e24f3..44f5fa019372666da7aca019096f09e2670345e6 100644 (file)
--- a/server.c
+++ b/server.c
@@ -15,7 +15,7 @@
 
 #include "fio.h"
 #include "server.h"
-#include "crc/crc32.h"
+#include "crc/crc16.h"
 
 int fio_net_port = 8765;
 
@@ -75,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;
        }
 
@@ -112,7 +112,7 @@ static int verify_convert_cmd(struct fio_net_cmd *cmd)
 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;
@@ -135,10 +135,10 @@ struct fio_net_cmd *fio_net_cmd_read(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;
        }
@@ -150,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)
@@ -176,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
@@ -285,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;
index d66782d532a6124c8364afec6e66ad29da584f44..73e00a5c13a93d496392b67f1d89e3ec9e0b8a6b 100644 (file)
--- a/server.h
+++ b/server.h
@@ -13,10 +13,9 @@ struct fio_net_cmd {
        uint16_t opcode;        /* command opcode */
        uint32_t flags;         /* modifier flags */
        uint64_t serial;        /* serial number */
-       uint32_t pad;
        uint32_t pdu_len;       /* length of post-cmd layload */
-       uint32_t cmd_crc32;     /* cmd checksum */
-       uint32_t pdu_crc32;     /* payload checksum */
+       uint16_t cmd_crc16;     /* cmd checksum */
+       uint16_t pdu_crc16;     /* payload checksum */
        uint8_t payload[0];     /* payload */
 };
 
@@ -32,6 +31,10 @@ enum {
        FIO_NET_CMD_ACK         = 4,
        FIO_NET_CMD_NAK         = 5,
        FIO_NET_CMD_TEXT        = 6,
+
+       /* crc does not include the crc fields */
+       FIO_NET_CMD_CRC_SZ      = sizeof(struct fio_net_cmd) -
+                                       2 * sizeof(uint16_t),
 };
 
 extern int fio_server(void);