Jens Axboe | 50d1697 | 2011-09-29 17:45:28 -0600 | [diff] [blame] | 1 | #ifndef FIO_SERVER_H |
| 2 | #define FIO_SERVER_H |
| 3 | |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 4 | #include <inttypes.h> |
Jens Axboe | 142575e | 2011-09-30 17:35:45 -0600 | [diff] [blame] | 5 | #include <string.h> |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 6 | #include <endian.h> |
| 7 | |
| 8 | /* |
| 9 | * On-wire encoding is little endian |
| 10 | */ |
| 11 | struct fio_net_cmd { |
| 12 | uint16_t version; /* protocol version */ |
| 13 | uint16_t opcode; /* command opcode */ |
| 14 | uint32_t flags; /* modifier flags */ |
| 15 | uint64_t serial; /* serial number */ |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 16 | uint32_t pdu_len; /* length of post-cmd layload */ |
Jens Axboe | fcee5ff | 2011-09-30 22:50:39 -0600 | [diff] [blame] | 17 | uint16_t cmd_crc16; /* cmd checksum */ |
| 18 | uint16_t pdu_crc16; /* payload checksum */ |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 19 | uint8_t payload[0]; /* payload */ |
| 20 | }; |
| 21 | |
| 22 | enum { |
| 23 | FIO_SERVER_VER = 1, |
| 24 | FIO_SERVER_VER1 = 1, |
| 25 | |
Jens Axboe | 794d69c | 2011-10-01 08:48:50 -0600 | [diff] [blame] | 26 | FIO_SERVER_MAX_PDU = 64, |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 27 | |
| 28 | FIO_NET_CMD_QUIT = 1, |
Jens Axboe | d795918 | 2011-10-03 11:48:39 +0200 | [diff] [blame] | 29 | FIO_NET_CMD_EXIT = 2, |
| 30 | FIO_NET_CMD_JOB = 3, |
| 31 | FIO_NET_CMD_ACK = 4, |
| 32 | FIO_NET_CMD_NAK = 5, |
| 33 | FIO_NET_CMD_TEXT = 6, |
Jens Axboe | 794d69c | 2011-10-01 08:48:50 -0600 | [diff] [blame] | 34 | |
Jens Axboe | d795918 | 2011-10-03 11:48:39 +0200 | [diff] [blame] | 35 | FIO_NET_CMD_F_MORE = 1UL << 0, |
Jens Axboe | fcee5ff | 2011-09-30 22:50:39 -0600 | [diff] [blame] | 36 | |
| 37 | /* crc does not include the crc fields */ |
| 38 | FIO_NET_CMD_CRC_SZ = sizeof(struct fio_net_cmd) - |
| 39 | 2 * sizeof(uint16_t), |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 40 | }; |
| 41 | |
Jens Axboe | e46d809 | 2011-10-03 09:11:02 +0200 | [diff] [blame] | 42 | extern int fio_start_server(int); |
Jens Axboe | 142575e | 2011-09-30 17:35:45 -0600 | [diff] [blame] | 43 | extern int fio_server_text_output(const char *, unsigned int len); |
| 44 | extern int fio_server_log(const char *format, ...); |
Jens Axboe | 794d69c | 2011-10-01 08:48:50 -0600 | [diff] [blame] | 45 | extern int fio_net_send_cmd(int, uint16_t, const char *, off_t); |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 46 | |
Jens Axboe | a37f69b | 2011-10-01 12:24:21 -0600 | [diff] [blame] | 47 | extern int fio_clients_connect(void); |
| 48 | extern int fio_clients_send_ini(const char *); |
Jens Axboe | 37db14f | 2011-09-30 17:00:42 -0600 | [diff] [blame] | 49 | extern int fio_handle_clients(void); |
Jens Axboe | a37f69b | 2011-10-01 12:24:21 -0600 | [diff] [blame] | 50 | extern void fio_client_add(const char *); |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 51 | |
| 52 | extern int fio_recv_data(int sk, void *p, unsigned int len); |
| 53 | extern int fio_send_data(int sk, const void *p, unsigned int len); |
| 54 | extern void fio_net_cmd_crc(struct fio_net_cmd *); |
Jens Axboe | 37db14f | 2011-09-30 17:00:42 -0600 | [diff] [blame] | 55 | extern struct fio_net_cmd *fio_net_cmd_read(int sk); |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 56 | |
Jens Axboe | 009b1be | 2011-09-29 18:27:02 -0600 | [diff] [blame] | 57 | extern int exit_backend; |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 58 | extern int fio_net_port; |
| 59 | |
| 60 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 61 | #define le16_to_cpu(x) (x) |
| 62 | #define le32_to_cpu(x) (x) |
| 63 | #define le64_to_cpu(x) (x) |
| 64 | #define cpu_to_le16(x) (x) |
| 65 | #define cpu_to_le32(x) (x) |
| 66 | #define cpu_to_le64(x) (x) |
| 67 | #elif __BYTE_ORDER == __BIG_ENDIAN |
| 68 | #define le16_to_cpu(x) __bswap_16(x) |
| 69 | #define le32_to_cpu(x) __bswap_32(x) |
| 70 | #define le64_to_cpu(x) __bswap_64(x) |
| 71 | #define cpu_to_le16(x) __bswap_16(x) |
| 72 | #define cpu_to_le32(x) __bswap_32(x) |
| 73 | #define cpu_to_le64(x) __bswap_64(x) |
| 74 | #else |
| 75 | #error "Endianness not detected" |
| 76 | #endif |
| 77 | |
Jens Axboe | 4d8f878 | 2011-09-30 22:24:17 -0600 | [diff] [blame] | 78 | static inline void fio_init_net_cmd(struct fio_net_cmd *cmd, uint16_t opcode, |
| 79 | const void *pdu, uint32_t pdu_len) |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 80 | { |
| 81 | memset(cmd, 0, sizeof(*cmd)); |
Jens Axboe | 4d8f878 | 2011-09-30 22:24:17 -0600 | [diff] [blame] | 82 | |
| 83 | cmd->version = cpu_to_le16(FIO_SERVER_VER1); |
Jens Axboe | 82fa6b2 | 2011-09-30 22:29:08 -0600 | [diff] [blame] | 84 | cmd->opcode = cpu_to_le16(opcode); |
Jens Axboe | 4d8f878 | 2011-09-30 22:24:17 -0600 | [diff] [blame] | 85 | |
| 86 | if (pdu) { |
| 87 | cmd->pdu_len = cpu_to_le32(pdu_len); |
| 88 | memcpy(&cmd->payload, pdu, pdu_len); |
| 89 | } |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 90 | } |
Jens Axboe | 50d1697 | 2011-09-29 17:45:28 -0600 | [diff] [blame] | 91 | |
| 92 | #endif |