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 int sk; /* socket fd to talk to client */ 19 struct fio_sem lock; /* protects ref and below list */ 20 struct flist_head list; /* list of pending transmit work */ 21 struct fio_sem wait; /* wake backend when items added to list */ 22 struct fio_sem xmit; /* held while sending data */ 23 }; 24 25 /* 26 * On-wire encoding is little endian 27 */ 28 struct fio_net_cmd { 29 uint16_t version; /* protocol version */ 30 uint16_t opcode; /* command opcode */ 31 uint32_t flags; /* modifier flags */ 32 uint64_t tag; /* passed back on reply */ 33 uint32_t pdu_len; /* length of post-cmd layload */ 34 /* 35 * These must be immediately before the payload, anything before 36 * these fields are checksummed. 37 */ 38 uint16_t cmd_crc16; /* cmd checksum */ 39 uint16_t pdu_crc16; /* payload checksum */ 40 uint8_t payload[]; /* payload */ 41 }; 42 43 struct fio_net_cmd_reply { 44 struct flist_head list; 45 struct timespec ts; 46 uint64_t saved_tag; 47 uint16_t opcode; 48 }; 49 50 enum { 51 FIO_SERVER_VER = 95, 52 53 FIO_SERVER_MAX_FRAGMENT_PDU = 1024, 54 FIO_SERVER_MAX_CMD_MB = 2048, 55 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, 71 FIO_NET_CMD_RUN = 16, 72 FIO_NET_CMD_IOLOG = 17, 73 FIO_NET_CMD_UPDATE_JOB = 18, 74 FIO_NET_CMD_LOAD_FILE = 19, 75 FIO_NET_CMD_VTRIGGER = 20, 76 FIO_NET_CMD_SENDFILE = 21, 77 FIO_NET_CMD_JOB_OPT = 22, 78 FIO_NET_CMD_NR = 23, 79 80 FIO_NET_CMD_F_MORE = 1UL << 0, 81 82 /* crc does not include the crc fields */ 83 FIO_NET_CMD_CRC_SZ = sizeof(struct fio_net_cmd) - 84 2 * sizeof(uint16_t), 85 86 FIO_NET_NAME_MAX = 256, 87 88 FIO_NET_CLIENT_TIMEOUT = 5000, 89 90 FIO_PROBE_FLAG_ZLIB = 1UL << 0, 91 }; 92 93 struct cmd_sendfile { 94 uint8_t path[FIO_NET_NAME_MAX]; 95 }; 96 97 struct 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 */ 107 struct cmd_vtrigger_pdu { 108 uint16_t len; 109 uint8_t cmd[]; 110 }; 111 112 struct cmd_load_file_pdu { 113 uint16_t name_len; 114 uint16_t client_type; 115 uint8_t file[]; 116 }; 117 118 struct cmd_ts_pdu { 119 struct thread_stat ts; 120 struct group_run_stats rs; 121 }; 122 123 struct cmd_du_pdu { 124 struct disk_util_stat dus; 125 struct disk_util_agg agg; 126 }; 127 128 struct cmd_client_probe_pdu { 129 uint64_t flags; 130 uint8_t server[128]; 131 }; 132 133 struct cmd_probe_reply_pdu { 134 uint8_t hostname[64]; 135 uint8_t bigendian; 136 uint8_t fio_version[32]; 137 uint8_t os; 138 uint8_t arch; 139 uint8_t bpp; 140 uint32_t cpus; 141 uint64_t flags; 142 }; 143 144 struct cmd_single_line_pdu { 145 uint16_t len; 146 uint8_t text[]; 147 }; 148 149 struct cmd_line_pdu { 150 uint16_t lines; 151 uint16_t client_type; 152 struct cmd_single_line_pdu options[]; 153 }; 154 155 struct cmd_job_pdu { 156 uint32_t buf_len; 157 uint32_t client_type; 158 uint8_t buf[0]; 159 }; 160 161 struct cmd_start_pdu { 162 uint32_t jobs; 163 uint32_t stat_outputs; 164 }; 165 166 struct cmd_end_pdu { 167 uint32_t error; 168 uint32_t signal; 169 }; 170 171 struct cmd_add_job_pdu { 172 uint32_t thread_number; 173 uint32_t groupid; 174 struct thread_options_pack top; 175 }; 176 177 struct 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 185 enum { 186 XMIT_COMPRESSED = 1U, 187 STORE_COMPRESSED = 2U, 188 }; 189 190 struct cmd_iolog_pdu { 191 uint64_t nr_samples; 192 uint32_t thread_number; 193 uint32_t log_type; 194 uint32_t compressed; 195 uint32_t log_offset; 196 uint32_t log_prio; 197 uint32_t log_hist_coarseness; 198 uint8_t name[FIO_NET_NAME_MAX]; 199 struct io_sample samples[0]; 200 }; 201 202 struct cmd_job_option { 203 uint16_t global; 204 uint16_t truncated; 205 uint32_t groupid; 206 uint8_t name[64]; 207 uint8_t value[128]; 208 }; 209 210 extern int fio_start_server(char *); 211 extern int fio_server_text_output(int, const char *, size_t); 212 extern int fio_net_send_cmd(int, uint16_t, const void *, off_t, uint64_t *, struct flist_head *); 213 extern int fio_net_send_simple_cmd(int, uint16_t, uint64_t, struct flist_head *); 214 extern void fio_server_set_arg(const char *); 215 extern int fio_server_parse_string(const char *, char **, bool *, int *, struct in_addr *, struct in6_addr *, int *); 216 extern int fio_server_parse_host(const char *, int, struct in_addr *, struct in6_addr *); 217 extern const char *fio_server_op(unsigned int); 218 extern void fio_server_got_signal(int); 219 220 extern void fio_server_send_ts(struct thread_stat *, struct group_run_stats *); 221 extern void fio_server_send_gs(struct group_run_stats *); 222 extern void fio_server_send_du(void); 223 extern void fio_server_send_job_options(struct flist_head *, unsigned int); 224 extern int fio_server_get_verify_state(const char *, int, void **); 225 226 extern struct fio_net_cmd *fio_net_recv_cmd(int sk, bool wait); 227 228 extern int fio_send_iolog(struct thread_data *, struct io_log *, const char *); 229 extern void fio_server_send_add_job(struct thread_data *); 230 extern void fio_server_send_start(struct thread_data *); 231 extern int fio_net_send_quit(int sk); 232 233 extern int fio_server_create_sk_key(void); 234 extern void fio_server_destroy_sk_key(void); 235 236 extern bool exit_backend; 237 extern int fio_net_port; 238 239 #endif 240