Merge branch 's3_crypto' of github.com:hualongfeng/fio
[fio.git] / server.h
1 #ifndef FIO_SERVER_H
2 #define FIO_SERVER_H
3
4 #include <inttypes.h>
5 #include <string.h>
6 #include <sys/time.h>
7 #include <netinet/in.h>
8
9 #include "stat.h"
10 #include "diskutil.h"
11
12 #define FIO_NET_PORT 8765
13
14 struct sk_out {
15         unsigned int refs;      /* frees sk_out when it drops to zero.
16                                  * protected by below ->lock */
17
18 #ifdef WIN32
19         HANDLE hProcess;                /* process handle of handle_connection_process*/
20 #endif
21         int sk;                 /* socket fd to talk to client */
22         struct fio_sem lock;    /* protects ref and below list */
23         struct flist_head list; /* list of pending transmit work */
24         struct fio_sem wait;    /* wake backend when items added to list */
25         struct fio_sem xmit;    /* held while sending data */
26 };
27
28 /*
29  * On-wire encoding is little endian
30  */
31 struct fio_net_cmd {
32         uint16_t version;       /* protocol version */
33         uint16_t opcode;        /* command opcode */
34         uint32_t flags;         /* modifier flags */
35         uint64_t tag;           /* passed back on reply */
36         uint32_t pdu_len;       /* length of post-cmd layload */
37         /*
38          * These must be immediately before the payload, anything before
39          * these fields are checksummed.
40          */
41         uint16_t cmd_crc16;     /* cmd checksum */
42         uint16_t pdu_crc16;     /* payload checksum */
43         uint8_t payload[];      /* payload */
44 };
45
46 struct fio_net_cmd_reply {
47         struct flist_head list;
48         struct timespec ts;
49         uint64_t saved_tag;
50         uint16_t opcode;
51 };
52
53 enum {
54         FIO_SERVER_VER                  = 97,
55
56         FIO_SERVER_MAX_FRAGMENT_PDU     = 1024,
57         FIO_SERVER_MAX_CMD_MB           = 2048,
58
59         FIO_NET_CMD_QUIT                = 1,
60         FIO_NET_CMD_EXIT                = 2,
61         FIO_NET_CMD_JOB                 = 3,
62         FIO_NET_CMD_JOBLINE             = 4,
63         FIO_NET_CMD_TEXT                = 5,
64         FIO_NET_CMD_TS                  = 6,
65         FIO_NET_CMD_GS                  = 7,
66         FIO_NET_CMD_SEND_ETA            = 8,
67         FIO_NET_CMD_ETA                 = 9,
68         FIO_NET_CMD_PROBE               = 10,
69         FIO_NET_CMD_START               = 11,
70         FIO_NET_CMD_STOP                = 12,
71         FIO_NET_CMD_DU                  = 13,
72         FIO_NET_CMD_SERVER_START        = 14,
73         FIO_NET_CMD_ADD_JOB             = 15,
74         FIO_NET_CMD_RUN                 = 16,
75         FIO_NET_CMD_IOLOG               = 17,
76         FIO_NET_CMD_UPDATE_JOB          = 18,
77         FIO_NET_CMD_LOAD_FILE           = 19,
78         FIO_NET_CMD_VTRIGGER            = 20,
79         FIO_NET_CMD_SENDFILE            = 21,
80         FIO_NET_CMD_JOB_OPT             = 22,
81         FIO_NET_CMD_NR                  = 23,
82
83         FIO_NET_CMD_F_MORE              = 1UL << 0,
84
85         /* crc does not include the crc fields */
86         FIO_NET_CMD_CRC_SZ              = sizeof(struct fio_net_cmd) -
87                                                 2 * sizeof(uint16_t),
88
89         FIO_NET_NAME_MAX                = 256,
90
91         FIO_NET_CLIENT_TIMEOUT          = 5000,
92
93         FIO_PROBE_FLAG_ZLIB             = 1UL << 0,
94 };
95
96 struct cmd_sendfile {
97         uint8_t path[FIO_NET_NAME_MAX];
98 };
99
100 struct cmd_sendfile_reply {
101         uint32_t size;
102         uint32_t error;
103         uint8_t data[0];
104 };
105
106 /*
107  * Client sends this to server on VTRIGGER, server sends back a full
108  * all_io_list structure.
109  */
110 struct cmd_vtrigger_pdu {
111         uint16_t len;
112         uint8_t cmd[];
113 };
114
115 struct cmd_load_file_pdu {
116         uint16_t name_len;
117         uint16_t client_type;
118         uint8_t file[];
119 };
120
121 struct cmd_ts_pdu {
122         struct thread_stat ts;
123         struct group_run_stats rs;
124 };
125
126 struct cmd_du_pdu {
127         struct disk_util_stat dus;
128         struct disk_util_agg agg;
129 };
130
131 struct cmd_client_probe_pdu {
132         uint64_t flags;
133         uint8_t server[128];
134 };
135
136 struct cmd_probe_reply_pdu {
137         uint8_t hostname[64];
138         uint8_t bigendian;
139         uint8_t fio_version[32];
140         uint8_t os;
141         uint8_t arch;
142         uint8_t bpp;
143         uint32_t cpus;
144         uint64_t flags;
145 };
146
147 struct cmd_single_line_pdu {
148         uint16_t len;
149         uint8_t text[];
150 };
151
152 struct cmd_line_pdu {
153         uint16_t lines;
154         uint16_t client_type;
155         struct cmd_single_line_pdu options[];
156 };
157
158 struct cmd_job_pdu {
159         uint32_t buf_len;
160         uint32_t client_type;
161         uint8_t buf[0];
162 };
163
164 struct cmd_start_pdu {
165         uint32_t jobs;
166         uint32_t stat_outputs;
167 };
168
169 struct cmd_end_pdu {
170         uint32_t error;
171         uint32_t signal;
172 };
173
174 struct cmd_add_job_pdu {
175         uint32_t thread_number;
176         uint32_t groupid;
177         struct thread_options_pack top;
178 };
179
180 struct cmd_text_pdu {
181         uint32_t level;
182         uint32_t buf_len;
183         uint64_t log_sec;
184         uint64_t log_usec;
185         uint8_t buf[0];
186 };
187
188 enum {
189         XMIT_COMPRESSED         = 1U,
190         STORE_COMPRESSED        = 2U,
191 };
192
193 struct cmd_iolog_pdu {
194         uint64_t nr_samples;
195         uint32_t thread_number;
196         uint32_t log_type;
197         uint32_t compressed;
198         uint32_t log_offset;
199         uint32_t log_prio;
200         uint32_t log_hist_coarseness;
201         uint8_t name[FIO_NET_NAME_MAX];
202         struct io_sample samples[0];
203 };
204
205 struct cmd_job_option {
206         uint16_t global;
207         uint16_t truncated;
208         uint32_t groupid;
209         uint8_t name[64];
210         uint8_t value[128];
211 };
212
213 extern int fio_start_server(char *);
214 extern int fio_server_text_output(int, const char *, size_t);
215 extern int fio_net_send_cmd(int, uint16_t, const void *, off_t, uint64_t *, struct flist_head *);
216 extern int fio_net_send_simple_cmd(int, uint16_t, uint64_t, struct flist_head *);
217 extern void fio_server_set_arg(const char *);
218 extern void fio_server_internal_set(const char *);
219 extern int fio_server_parse_string(const char *, char **, bool *, int *, struct in_addr *, struct in6_addr *, int *);
220 extern int fio_server_parse_host(const char *, int, struct in_addr *, struct in6_addr *);
221 extern const char *fio_server_op(unsigned int);
222 extern void fio_server_got_signal(int);
223
224 extern void fio_server_send_ts(struct thread_stat *, struct group_run_stats *);
225 extern void fio_server_send_gs(struct group_run_stats *);
226 extern void fio_server_send_du(void);
227 extern void fio_server_send_job_options(struct flist_head *, unsigned int);
228 extern int fio_server_get_verify_state(const char *, int, void **);
229 extern bool fio_server_poll_fd(int fd, short events, int timeout);
230
231 extern struct fio_net_cmd *fio_net_recv_cmd(int sk, bool wait);
232
233 extern int fio_send_iolog(struct thread_data *, struct io_log *, const char *);
234 extern void fio_server_send_add_job(struct thread_data *);
235 extern void fio_server_send_start(struct thread_data *);
236 extern int fio_net_send_quit(int sk);
237
238 extern int fio_server_create_sk_key(void);
239 extern void fio_server_destroy_sk_key(void);
240
241 extern bool exit_backend;
242 extern int fio_net_port;
243
244 #endif