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