fix problem with yy_size_t vs int param to lexer_input
[fio.git] / ioengine.h
CommitLineData
dcefb588
JA
1#ifndef FIO_IOENGINE_H
2#define FIO_IOENGINE_H
3
41666588 4#include "compiler/compiler.h"
836fcc0f
JA
5#include "os/os.h"
6#include "log.h"
41666588 7#include "io_ddir.h"
ec41265e 8#include "debug.h"
41666588 9#include "file.h"
ec41265e 10
67bf9823
JA
11#ifdef CONFIG_LIBAIO
12#include <libaio.h>
13#endif
14#ifdef CONFIG_GUASI
15#include <guasi.h>
16#endif
17
43e82be7 18#define FIO_IOOPS_VERSION 21
dcefb588
JA
19
20enum {
0c41214f
RR
21 IO_U_F_FREE = 1 << 0,
22 IO_U_F_FLIGHT = 1 << 1,
f8b0bd10 23 IO_U_F_NO_FILE_PUT = 1 << 2,
0c41214f 24 IO_U_F_IN_CUR_DEPTH = 1 << 3,
38dad62d 25 IO_U_F_BUSY_OK = 1 << 4,
0d29de83 26 IO_U_F_TRIMMED = 1 << 5,
1ef2b6be 27 IO_U_F_BARRIER = 1 << 6,
82af2a7c 28 IO_U_F_VER_LIST = 1 << 7,
dcefb588
JA
29};
30
31/*
32 * The io unit
33 */
34struct io_u {
dcefb588
JA
35 struct timeval start_time;
36 struct timeval issue_time;
37
d72be545
JA
38 struct fio_file *file;
39 unsigned int flags;
40 enum fio_ddir ddir;
41
bcd5abfa
JA
42 /*
43 * For replay workloads, we may want to account as a different
44 * IO type than what is being submitted.
45 */
46 enum fio_ddir acct_ddir;
47
dcefb588
JA
48 /*
49 * Allocated/set buffer and length
50 */
dcefb588
JA
51 unsigned long buflen;
52 unsigned long long offset;
da0a7bd2 53 unsigned short numberio;
d72be545 54 void *buf;
dcefb588 55
7d9fb455
JA
56 /*
57 * Initial seed for generating the buffer contents
58 */
363cffa7 59 uint64_t rand_seed;
7d9fb455 60
dcefb588
JA
61 /*
62 * IO engine state, may be different from above when we get
63 * partial transfers / residual data counts
64 */
65 void *xfer_buf;
66 unsigned long xfer_buflen;
67
95228507
JA
68 /*
69 * Parameter related to pre-filled buffers and
70 * their size to handle variable block sizes.
71 */
72 unsigned long buf_filled_len;
73
f9401285
JA
74 struct io_piece *ipo;
75
225ba9e3
JA
76 unsigned int resid;
77 unsigned int error;
78
79 /*
80 * io engine private data
81 */
82 union {
83 unsigned int index;
84 unsigned int seen;
85 void *engine_data;
86 };
87
88 struct flist_head verify_list;
89
90 /*
91 * Callback for io completion
92 */
f8b0bd10 93 int (*end_io)(struct thread_data *, struct io_u **);
225ba9e3 94
2ae0b204
JA
95 union {
96#ifdef CONFIG_LIBAIO
97 struct iocb iocb;
98#endif
99#ifdef CONFIG_POSIXAIO
100 os_aiocb_t aiocb;
101#endif
102#ifdef FIO_HAVE_SGIO
103 struct sg_io_hdr hdr;
104#endif
105#ifdef CONFIG_GUASI
106 guasi_req_t greq;
107#endif
108#ifdef CONFIG_SOLARISAIO
109 aio_result_t resultp;
110#endif
111#ifdef FIO_HAVE_BINJECT
112 struct b_user_cmd buc;
113#endif
114#ifdef CONFIG_RDMA
115 struct ibv_mr *mr;
116#endif
117 void *mmap_data;
118 };
dcefb588
JA
119};
120
121/*
122 * io_ops->queue() return values
123 */
124enum {
125 FIO_Q_COMPLETED = 0, /* completed sync */
126 FIO_Q_QUEUED = 1, /* queued, will complete async */
127 FIO_Q_BUSY = 2, /* no more room, call ->commit() */
128};
129
130struct ioengine_ops {
131 struct flist_head list;
132 char name[16];
133 int version;
134 int flags;
135 int (*setup)(struct thread_data *);
136 int (*init)(struct thread_data *);
137 int (*prep)(struct thread_data *, struct io_u *);
138 int (*queue)(struct thread_data *, struct io_u *);
139 int (*commit)(struct thread_data *);
1f440ece 140 int (*getevents)(struct thread_data *, unsigned int, unsigned int, const struct timespec *);
dcefb588
JA
141 struct io_u *(*event)(struct thread_data *, int);
142 int (*cancel)(struct thread_data *, struct io_u *);
143 void (*cleanup)(struct thread_data *);
144 int (*open_file)(struct thread_data *, struct fio_file *);
145 int (*close_file)(struct thread_data *, struct fio_file *);
d9b100fc 146 int (*invalidate)(struct thread_data *, struct fio_file *);
38ef9c90 147 int (*unlink_file)(struct thread_data *, struct fio_file *);
dcefb588 148 int (*get_file_size)(struct thread_data *, struct fio_file *);
36d80bc7 149 void (*terminate)(struct thread_data *);
c73ed246
JA
150 int (*io_u_init)(struct thread_data *, struct io_u *);
151 void (*io_u_free)(struct thread_data *, struct io_u *);
de890a1e
SL
152 int option_struct_size;
153 struct fio_option *options;
dcefb588
JA
154 void *data;
155 void *dlhandle;
156};
157
2b4f4abe
JA
158enum fio_ioengine_flags {
159 FIO_SYNCIO = 1 << 0, /* io engine has synchronous ->queue */
160 FIO_RAWIO = 1 << 1, /* some sort of direct/raw io */
161 FIO_DISKLESSIO = 1 << 2, /* no disk involved */
162 FIO_NOEXTEND = 1 << 3, /* engine can't extend file */
93bcfd20 163 FIO_NODISKUTIL = 1 << 4, /* diskutil can't handle filename */
2b4f4abe
JA
164 FIO_UNIDIR = 1 << 5, /* engine is uni-directional */
165 FIO_NOIO = 1 << 6, /* thread does only pseudo IO */
36d80bc7
JA
166 FIO_PIPEIO = 1 << 7, /* input/output no seekable */
167 FIO_BARRIER = 1 << 8, /* engine supports barriers */
168 FIO_MEMALIGN = 1 << 9, /* engine wants aligned memory */
ad705bcb 169 FIO_BIT_BASED = 1 << 10, /* engine uses a bit base (e.g. uses Kbit as opposed to KB) */
5c57c084 170 FIO_FAKEIO = 1 << 11, /* engine pretends to do IO */
2b4f4abe 171};
dcefb588 172
a8075704
DG
173/*
174 * External engine defined symbol to fill in the engine ops structure
175 */
176typedef void (*get_ioengine_t)(struct ioengine_ops **);
177
dcefb588
JA
178/*
179 * io engine entry points
180 */
181extern int __must_check td_io_init(struct thread_data *);
182extern int __must_check td_io_prep(struct thread_data *, struct io_u *);
183extern int __must_check td_io_queue(struct thread_data *, struct io_u *);
184extern int __must_check td_io_sync(struct thread_data *, struct fio_file *);
1f440ece 185extern int __must_check td_io_getevents(struct thread_data *, unsigned int, unsigned int, const struct timespec *);
dcefb588
JA
186extern int __must_check td_io_commit(struct thread_data *);
187extern int __must_check td_io_open_file(struct thread_data *, struct fio_file *);
188extern int td_io_close_file(struct thread_data *, struct fio_file *);
38ef9c90 189extern int td_io_unlink_file(struct thread_data *, struct fio_file *);
dcefb588
JA
190extern int __must_check td_io_get_file_size(struct thread_data *, struct fio_file *);
191
192extern struct ioengine_ops *load_ioengine(struct thread_data *, const char *);
193extern void register_ioengine(struct ioengine_ops *);
194extern void unregister_ioengine(struct ioengine_ops *);
de890a1e 195extern void free_ioengine(struct thread_data *);
dcefb588
JA
196extern void close_ioengine(struct thread_data *);
197
de890a1e
SL
198extern int fio_show_ioengine_help(const char *engine);
199
dcefb588
JA
200/*
201 * io unit handling
202 */
dcefb588
JA
203extern struct io_u *__get_io_u(struct thread_data *);
204extern struct io_u *get_io_u(struct thread_data *);
205extern void put_io_u(struct thread_data *, struct io_u *);
f2bba182 206extern void clear_io_u(struct thread_data *, struct io_u *);
dcefb588 207extern void requeue_io_u(struct thread_data *, struct io_u **);
100f49f1
JA
208extern int __must_check io_u_sync_complete(struct thread_data *, struct io_u *, uint64_t *);
209extern int __must_check io_u_queued_complete(struct thread_data *, int, uint64_t *);
dcefb588 210extern void io_u_queued(struct thread_data *, struct io_u *);
002e7183 211extern void io_u_quiesce(struct thread_data *);
dcefb588
JA
212extern void io_u_log_error(struct thread_data *, struct io_u *);
213extern void io_u_mark_depth(struct thread_data *, unsigned int);
cc86c395 214extern void fill_io_buffer(struct thread_data *, void *, unsigned int, unsigned int);
9c42684e 215extern void io_u_fill_buffer(struct thread_data *td, struct io_u *, unsigned int, unsigned int);
dcefb588
JA
216void io_u_mark_complete(struct thread_data *, unsigned int);
217void io_u_mark_submit(struct thread_data *, unsigned int);
effd6ff0 218int queue_full(const struct thread_data *);
dcefb588 219
effd6ff0
JA
220int do_io_u_sync(const struct thread_data *, struct io_u *);
221int do_io_u_trim(const struct thread_data *, struct io_u *);
44f29692 222
c592b9fe
JA
223#ifdef FIO_INC_DEBUG
224static inline void dprint_io_u(struct io_u *io_u, const char *p)
225{
226 struct fio_file *f = io_u->file;
227
228 dprint(FD_IO, "%s: io_u %p: off=%llu/len=%lu/ddir=%d", p, io_u,
229 (unsigned long long) io_u->offset,
230 io_u->buflen, io_u->ddir);
231 if (fio_debug & (1 << FD_IO)) {
232 if (f)
233 log_info("/%s", f->file_name);
234
235 log_info("\n");
236 }
237}
238#else
239#define dprint_io_u(io_u, p)
240#endif
241
bcd5abfa
JA
242static inline enum fio_ddir acct_ddir(struct io_u *io_u)
243{
244 if (io_u->acct_ddir != -1)
245 return io_u->acct_ddir;
246
247 return io_u->ddir;
248}
249
dcefb588 250#endif