server: ensure payload larger than max is broken into pieces
[fio.git] / server.h
index c2cb9942774b8a3c11b4e930d560300b3df2ffa7..c85f1bcc36e090431423e9f39f7a143477b5510a 100644 (file)
--- a/server.h
+++ b/server.h
@@ -2,6 +2,7 @@
 #define FIO_SERVER_H
 
 #include <inttypes.h>
+#include <string.h>
 #include <endian.h>
 
 /*
@@ -12,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 */
 };
 
@@ -23,18 +23,25 @@ enum {
        FIO_SERVER_VER          = 1,
        FIO_SERVER_VER1         = 1,
 
-       FIO_SERVER_MAX_PDU      = 4096,
+       FIO_SERVER_MAX_PDU      = 64,
 
        FIO_NET_CMD_QUIT        = 1,
        FIO_NET_CMD_JOB         = 2,
-       FIO_NET_CMD_JOB_END     = 3,
-       FIO_NET_CMD_ACK         = 4,
-       FIO_NET_CMD_NAK         = 5,
-       FIO_NET_CMD_TEXT        = 6,
+       FIO_NET_CMD_ACK         = 3,
+       FIO_NET_CMD_NAK         = 4,
+       FIO_NET_CMD_TEXT        = 5,
+
+       FIO_NET_CMD_F_MORE      = 1,
+
+       /* 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);
-extern void fio_server_text_output(const char *, unsigned int len);
+extern int fio_server_text_output(const char *, unsigned int len);
+extern int fio_server_log(const char *format, ...);
+extern int fio_net_send_cmd(int, uint16_t, const char *, off_t);
 
 extern int fio_client_connect(const char *);
 extern int fio_client_send_ini(const char *);
@@ -66,10 +73,18 @@ extern int fio_net_port;
 #error "Endianness not detected"
 #endif
 
-static inline void fio_init_net_cmd(struct fio_net_cmd *cmd)
+static inline void fio_init_net_cmd(struct fio_net_cmd *cmd, uint16_t opcode,
+                                   const void *pdu, uint32_t pdu_len)
 {
        memset(cmd, 0, sizeof(*cmd));
-       cmd->version = cpu_to_le16(FIO_SERVER_VER1);
+
+       cmd->version    = cpu_to_le16(FIO_SERVER_VER1);
+       cmd->opcode     = cpu_to_le16(opcode);
+
+       if (pdu) {
+               cmd->pdu_len    = cpu_to_le32(pdu_len);
+               memcpy(&cmd->payload, pdu, pdu_len);
+       }
 }
 
 #endif