blob: 8e6852a528c22b3ec63bb6cf0a466c85a59c426e [file] [log] [blame]
Jens Axboe50d16972011-09-29 17:45:28 -06001#ifndef FIO_SERVER_H
2#define FIO_SERVER_H
3
Jens Axboe132159a2011-09-30 15:01:32 -06004#include <inttypes.h>
Jens Axboe142575e2011-09-30 17:35:45 -06005#include <string.h>
Jens Axboe132159a2011-09-30 15:01:32 -06006#include <endian.h>
7
8/*
9 * On-wire encoding is little endian
10 */
11struct 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 Axboe132159a2011-09-30 15:01:32 -060016 uint32_t pdu_len; /* length of post-cmd layload */
Jens Axboefcee5ff2011-09-30 22:50:39 -060017 uint16_t cmd_crc16; /* cmd checksum */
18 uint16_t pdu_crc16; /* payload checksum */
Jens Axboe132159a2011-09-30 15:01:32 -060019 uint8_t payload[0]; /* payload */
20};
21
22enum {
23 FIO_SERVER_VER = 1,
24 FIO_SERVER_VER1 = 1,
25
Jens Axboe794d69c2011-10-01 08:48:50 -060026 FIO_SERVER_MAX_PDU = 64,
Jens Axboe132159a2011-09-30 15:01:32 -060027
28 FIO_NET_CMD_QUIT = 1,
29 FIO_NET_CMD_JOB = 2,
Jens Axboe794d69c2011-10-01 08:48:50 -060030 FIO_NET_CMD_ACK = 3,
31 FIO_NET_CMD_NAK = 4,
32 FIO_NET_CMD_TEXT = 5,
33
34 FIO_NET_CMD_F_MORE = 1,
Jens Axboefcee5ff2011-09-30 22:50:39 -060035
36 /* crc does not include the crc fields */
37 FIO_NET_CMD_CRC_SZ = sizeof(struct fio_net_cmd) -
38 2 * sizeof(uint16_t),
Jens Axboe132159a2011-09-30 15:01:32 -060039};
40
Jens Axboe50d16972011-09-29 17:45:28 -060041extern int fio_server(void);
Jens Axboe142575e2011-09-30 17:35:45 -060042extern int fio_server_text_output(const char *, unsigned int len);
43extern int fio_server_log(const char *format, ...);
Jens Axboe794d69c2011-10-01 08:48:50 -060044extern int fio_net_send_cmd(int, uint16_t, const char *, off_t);
Jens Axboe132159a2011-09-30 15:01:32 -060045
Jens Axboea37f69b2011-10-01 12:24:21 -060046extern int fio_clients_connect(void);
47extern int fio_clients_send_ini(const char *);
Jens Axboe37db14f2011-09-30 17:00:42 -060048extern int fio_handle_clients(void);
Jens Axboea37f69b2011-10-01 12:24:21 -060049extern void fio_client_add(const char *);
Jens Axboe132159a2011-09-30 15:01:32 -060050
51extern int fio_recv_data(int sk, void *p, unsigned int len);
52extern int fio_send_data(int sk, const void *p, unsigned int len);
53extern void fio_net_cmd_crc(struct fio_net_cmd *);
Jens Axboe37db14f2011-09-30 17:00:42 -060054extern struct fio_net_cmd *fio_net_cmd_read(int sk);
Jens Axboe132159a2011-09-30 15:01:32 -060055
Jens Axboe009b1be2011-09-29 18:27:02 -060056extern int exit_backend;
Jens Axboe132159a2011-09-30 15:01:32 -060057extern int fio_net_port;
58
59#if __BYTE_ORDER == __LITTLE_ENDIAN
60#define le16_to_cpu(x) (x)
61#define le32_to_cpu(x) (x)
62#define le64_to_cpu(x) (x)
63#define cpu_to_le16(x) (x)
64#define cpu_to_le32(x) (x)
65#define cpu_to_le64(x) (x)
66#elif __BYTE_ORDER == __BIG_ENDIAN
67#define le16_to_cpu(x) __bswap_16(x)
68#define le32_to_cpu(x) __bswap_32(x)
69#define le64_to_cpu(x) __bswap_64(x)
70#define cpu_to_le16(x) __bswap_16(x)
71#define cpu_to_le32(x) __bswap_32(x)
72#define cpu_to_le64(x) __bswap_64(x)
73#else
74#error "Endianness not detected"
75#endif
76
Jens Axboe4d8f8782011-09-30 22:24:17 -060077static inline void fio_init_net_cmd(struct fio_net_cmd *cmd, uint16_t opcode,
78 const void *pdu, uint32_t pdu_len)
Jens Axboe132159a2011-09-30 15:01:32 -060079{
80 memset(cmd, 0, sizeof(*cmd));
Jens Axboe4d8f8782011-09-30 22:24:17 -060081
82 cmd->version = cpu_to_le16(FIO_SERVER_VER1);
Jens Axboe82fa6b22011-09-30 22:29:08 -060083 cmd->opcode = cpu_to_le16(opcode);
Jens Axboe4d8f8782011-09-30 22:24:17 -060084
85 if (pdu) {
86 cmd->pdu_len = cpu_to_le32(pdu_len);
87 memcpy(&cmd->payload, pdu, pdu_len);
88 }
Jens Axboe132159a2011-09-30 15:01:32 -060089}
Jens Axboe50d16972011-09-29 17:45:28 -060090
91#endif