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 */ |
| 16 | uint32_t pad; |
| 17 | uint32_t pdu_len; /* length of post-cmd layload */ |
| 18 | uint32_t cmd_crc32; /* cmd checksum */ |
| 19 | uint32_t pdu_crc32; /* payload checksum */ |
| 20 | uint8_t payload[0]; /* payload */ |
| 21 | }; |
| 22 | |
| 23 | enum { |
| 24 | FIO_SERVER_VER = 1, |
| 25 | FIO_SERVER_VER1 = 1, |
| 26 | |
| 27 | FIO_SERVER_MAX_PDU = 4096, |
| 28 | |
| 29 | FIO_NET_CMD_QUIT = 1, |
| 30 | FIO_NET_CMD_JOB = 2, |
| 31 | FIO_NET_CMD_JOB_END = 3, |
| 32 | FIO_NET_CMD_ACK = 4, |
| 33 | FIO_NET_CMD_NAK = 5, |
Jens Axboe | 37db14f | 2011-09-30 17:00:42 -0600 | [diff] [blame] | 34 | FIO_NET_CMD_TEXT = 6, |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 35 | }; |
| 36 | |
Jens Axboe | 50d1697 | 2011-09-29 17:45:28 -0600 | [diff] [blame] | 37 | extern int fio_server(void); |
Jens Axboe | 142575e | 2011-09-30 17:35:45 -0600 | [diff] [blame] | 38 | extern int fio_server_text_output(const char *, unsigned int len); |
| 39 | extern int fio_server_log(const char *format, ...); |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 40 | |
| 41 | extern int fio_client_connect(const char *); |
| 42 | extern int fio_client_send_ini(const char *); |
Jens Axboe | 37db14f | 2011-09-30 17:00:42 -0600 | [diff] [blame] | 43 | extern int fio_handle_clients(void); |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 44 | |
| 45 | extern int fio_recv_data(int sk, void *p, unsigned int len); |
| 46 | extern int fio_send_data(int sk, const void *p, unsigned int len); |
| 47 | extern void fio_net_cmd_crc(struct fio_net_cmd *); |
Jens Axboe | 37db14f | 2011-09-30 17:00:42 -0600 | [diff] [blame] | 48 | extern struct fio_net_cmd *fio_net_cmd_read(int sk); |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 49 | |
Jens Axboe | 009b1be | 2011-09-29 18:27:02 -0600 | [diff] [blame] | 50 | extern int exit_backend; |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 51 | extern int fio_net_port; |
| 52 | |
| 53 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 54 | #define le16_to_cpu(x) (x) |
| 55 | #define le32_to_cpu(x) (x) |
| 56 | #define le64_to_cpu(x) (x) |
| 57 | #define cpu_to_le16(x) (x) |
| 58 | #define cpu_to_le32(x) (x) |
| 59 | #define cpu_to_le64(x) (x) |
| 60 | #elif __BYTE_ORDER == __BIG_ENDIAN |
| 61 | #define le16_to_cpu(x) __bswap_16(x) |
| 62 | #define le32_to_cpu(x) __bswap_32(x) |
| 63 | #define le64_to_cpu(x) __bswap_64(x) |
| 64 | #define cpu_to_le16(x) __bswap_16(x) |
| 65 | #define cpu_to_le32(x) __bswap_32(x) |
| 66 | #define cpu_to_le64(x) __bswap_64(x) |
| 67 | #else |
| 68 | #error "Endianness not detected" |
| 69 | #endif |
| 70 | |
Jens Axboe | 4d8f878 | 2011-09-30 22:24:17 -0600 | [diff] [blame^] | 71 | static inline void fio_init_net_cmd(struct fio_net_cmd *cmd, uint16_t opcode, |
| 72 | const void *pdu, uint32_t pdu_len) |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 73 | { |
| 74 | memset(cmd, 0, sizeof(*cmd)); |
Jens Axboe | 4d8f878 | 2011-09-30 22:24:17 -0600 | [diff] [blame^] | 75 | |
| 76 | cmd->version = cpu_to_le16(FIO_SERVER_VER1); |
| 77 | cmd->opcode = cpu_to_le16(FIO_NET_CMD_TEXT); |
| 78 | |
| 79 | if (pdu) { |
| 80 | cmd->pdu_len = cpu_to_le32(pdu_len); |
| 81 | memcpy(&cmd->payload, pdu, pdu_len); |
| 82 | } |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 83 | } |
Jens Axboe | 50d1697 | 2011-09-29 17:45:28 -0600 | [diff] [blame] | 84 | |
| 85 | #endif |