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> |
| 5 | #include <endian.h> |
| 6 | |
| 7 | /* |
| 8 | * On-wire encoding is little endian |
| 9 | */ |
| 10 | struct fio_net_cmd { |
| 11 | uint16_t version; /* protocol version */ |
| 12 | uint16_t opcode; /* command opcode */ |
| 13 | uint32_t flags; /* modifier flags */ |
| 14 | uint64_t serial; /* serial number */ |
| 15 | uint32_t pad; |
| 16 | uint32_t pdu_len; /* length of post-cmd layload */ |
| 17 | uint32_t cmd_crc32; /* cmd checksum */ |
| 18 | uint32_t pdu_crc32; /* payload checksum */ |
| 19 | uint8_t payload[0]; /* payload */ |
| 20 | }; |
| 21 | |
| 22 | enum { |
| 23 | FIO_SERVER_VER = 1, |
| 24 | FIO_SERVER_VER1 = 1, |
| 25 | |
| 26 | FIO_SERVER_MAX_PDU = 4096, |
| 27 | |
| 28 | FIO_NET_CMD_QUIT = 1, |
| 29 | FIO_NET_CMD_JOB = 2, |
| 30 | FIO_NET_CMD_JOB_END = 3, |
| 31 | FIO_NET_CMD_ACK = 4, |
| 32 | FIO_NET_CMD_NAK = 5, |
| 33 | }; |
| 34 | |
Jens Axboe | 50d1697 | 2011-09-29 17:45:28 -0600 | [diff] [blame] | 35 | extern int fio_server(void); |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame^] | 36 | |
| 37 | extern int fio_client_connect(const char *); |
| 38 | extern int fio_client_send_ini(const char *); |
| 39 | |
| 40 | extern int fio_recv_data(int sk, void *p, unsigned int len); |
| 41 | extern int fio_send_data(int sk, const void *p, unsigned int len); |
| 42 | extern void fio_net_cmd_crc(struct fio_net_cmd *); |
| 43 | |
Jens Axboe | 009b1be | 2011-09-29 18:27:02 -0600 | [diff] [blame] | 44 | extern int exit_backend; |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame^] | 45 | extern int fio_net_port; |
| 46 | |
| 47 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 48 | #define le16_to_cpu(x) (x) |
| 49 | #define le32_to_cpu(x) (x) |
| 50 | #define le64_to_cpu(x) (x) |
| 51 | #define cpu_to_le16(x) (x) |
| 52 | #define cpu_to_le32(x) (x) |
| 53 | #define cpu_to_le64(x) (x) |
| 54 | #elif __BYTE_ORDER == __BIG_ENDIAN |
| 55 | #define le16_to_cpu(x) __bswap_16(x) |
| 56 | #define le32_to_cpu(x) __bswap_32(x) |
| 57 | #define le64_to_cpu(x) __bswap_64(x) |
| 58 | #define cpu_to_le16(x) __bswap_16(x) |
| 59 | #define cpu_to_le32(x) __bswap_32(x) |
| 60 | #define cpu_to_le64(x) __bswap_64(x) |
| 61 | #else |
| 62 | #error "Endianness not detected" |
| 63 | #endif |
| 64 | |
| 65 | static inline void fio_init_net_cmd(struct fio_net_cmd *cmd) |
| 66 | { |
| 67 | memset(cmd, 0, sizeof(*cmd)); |
| 68 | cmd->version = cpu_to_le16(FIO_SERVER_VER1); |
| 69 | } |
Jens Axboe | 50d1697 | 2011-09-29 17:45:28 -0600 | [diff] [blame] | 70 | |
| 71 | #endif |