parse: get rid of raw option offsets
[fio.git] / ioengine.h
1 #ifndef FIO_IOENGINE_H
2 #define FIO_IOENGINE_H
3
4 #include "compiler/compiler.h"
5 #include "os/os.h"
6 #include "log.h"
7 #include "io_ddir.h"
8 #include "debug.h"
9 #include "file.h"
10
11 #ifdef CONFIG_LIBAIO
12 #include <libaio.h>
13 #endif
14 #ifdef CONFIG_GUASI
15 #include <guasi.h>
16 #endif
17
18 #define FIO_IOOPS_VERSION       17
19
20 enum {
21         IO_U_F_FREE             = 1 << 0,
22         IO_U_F_FLIGHT           = 1 << 1,
23         IO_U_F_FREE_DEF         = 1 << 2,
24         IO_U_F_IN_CUR_DEPTH     = 1 << 3,
25         IO_U_F_BUSY_OK          = 1 << 4,
26         IO_U_F_TRIMMED          = 1 << 5,
27         IO_U_F_BARRIER          = 1 << 6,
28         IO_U_F_VER_LIST         = 1 << 7,
29 };
30
31 /*
32  * The io unit
33  */
34 struct io_u {
35         struct timeval start_time;
36         struct timeval issue_time;
37
38         struct fio_file *file;
39         unsigned int flags;
40         enum fio_ddir ddir;
41
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
48         /*
49          * Allocated/set buffer and length
50          */
51         unsigned long buflen;
52         unsigned long long offset;
53         unsigned short numberio;
54         void *buf;
55
56         /*
57          * Initial seed for generating the buffer contents
58          */
59         uint64_t rand_seed;
60
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
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
74         struct io_piece *ipo;
75
76         union {
77 #ifdef CONFIG_LIBAIO
78                 struct iocb iocb;
79 #endif
80 #ifdef CONFIG_POSIXAIO
81                 os_aiocb_t aiocb;
82 #endif
83 #ifdef FIO_HAVE_SGIO
84                 struct sg_io_hdr hdr;
85 #endif
86 #ifdef CONFIG_GUASI
87                 guasi_req_t greq;
88 #endif
89 #ifdef CONFIG_SOLARISAIO
90                 aio_result_t resultp;
91 #endif
92 #ifdef FIO_HAVE_BINJECT
93                 struct b_user_cmd buc;
94 #endif
95 #ifdef CONFIG_RDMA
96                 struct ibv_mr *mr;
97 #endif
98                 void *mmap_data;
99         };
100
101         unsigned int resid;
102         unsigned int error;
103
104         /*
105          * io engine private data
106          */
107         union {
108                 unsigned int index;
109                 unsigned int seen;
110                 void *engine_data;
111         };
112
113         struct flist_head verify_list;
114
115         /*
116          * Callback for io completion
117          */
118         int (*end_io)(struct thread_data *, struct io_u *);
119 };
120
121 /*
122  * io_ops->queue() return values
123  */
124 enum {
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
130 struct 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 *);
140         int (*getevents)(struct thread_data *, unsigned int, unsigned int, struct timespec *);
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 *);
146         int (*get_file_size)(struct thread_data *, struct fio_file *);
147         void (*terminate)(struct thread_data *);
148         int (*io_u_init)(struct thread_data *, struct io_u *);
149         void (*io_u_free)(struct thread_data *, struct io_u *);
150         int option_struct_size;
151         struct fio_option *options;
152         void *data;
153         void *dlhandle;
154 };
155
156 enum fio_ioengine_flags {
157         FIO_SYNCIO      = 1 << 0,       /* io engine has synchronous ->queue */
158         FIO_RAWIO       = 1 << 1,       /* some sort of direct/raw io */
159         FIO_DISKLESSIO  = 1 << 2,       /* no disk involved */
160         FIO_NOEXTEND    = 1 << 3,       /* engine can't extend file */
161         FIO_NODISKUTIL  = 1 << 4,       /* diskutil can't handle filename */
162         FIO_UNIDIR      = 1 << 5,       /* engine is uni-directional */
163         FIO_NOIO        = 1 << 6,       /* thread does only pseudo IO */
164         FIO_PIPEIO      = 1 << 7,       /* input/output no seekable */
165         FIO_BARRIER     = 1 << 8,       /* engine supports barriers */
166         FIO_MEMALIGN    = 1 << 9,       /* engine wants aligned memory */
167         FIO_BIT_BASED   = 1 << 10,      /* engine uses a bit base (e.g. uses Kbit as opposed to KB) */
168 };
169
170 /*
171  * io engine entry points
172  */
173 extern int __must_check td_io_init(struct thread_data *);
174 extern int __must_check td_io_prep(struct thread_data *, struct io_u *);
175 extern int __must_check td_io_queue(struct thread_data *, struct io_u *);
176 extern int __must_check td_io_sync(struct thread_data *, struct fio_file *);
177 extern int __must_check td_io_getevents(struct thread_data *, unsigned int, unsigned int, struct timespec *);
178 extern int __must_check td_io_commit(struct thread_data *);
179 extern int __must_check td_io_open_file(struct thread_data *, struct fio_file *);
180 extern int td_io_close_file(struct thread_data *, struct fio_file *);
181 extern int __must_check td_io_get_file_size(struct thread_data *, struct fio_file *);
182
183 extern struct ioengine_ops *load_ioengine(struct thread_data *, const char *);
184 extern void register_ioengine(struct ioengine_ops *);
185 extern void unregister_ioengine(struct ioengine_ops *);
186 extern void free_ioengine(struct thread_data *);
187 extern void close_ioengine(struct thread_data *);
188
189 extern int fio_show_ioengine_help(const char *engine);
190
191 /*
192  * io unit handling
193  */
194 extern struct io_u *__get_io_u(struct thread_data *);
195 extern struct io_u *get_io_u(struct thread_data *);
196 extern void put_io_u(struct thread_data *, struct io_u *);
197 extern void clear_io_u(struct thread_data *, struct io_u *);
198 extern void requeue_io_u(struct thread_data *, struct io_u **);
199 extern int __must_check io_u_sync_complete(struct thread_data *, struct io_u *, uint64_t *);
200 extern int __must_check io_u_queued_complete(struct thread_data *, int, uint64_t *);
201 extern void io_u_queued(struct thread_data *, struct io_u *);
202 extern void io_u_quiesce(struct thread_data *);
203 extern void io_u_log_error(struct thread_data *, struct io_u *);
204 extern void io_u_mark_depth(struct thread_data *, unsigned int);
205 extern void fill_io_buffer(struct thread_data *, void *, unsigned int, unsigned int);
206 extern void io_u_fill_buffer(struct thread_data *td, struct io_u *, unsigned int, unsigned int);
207 void io_u_mark_complete(struct thread_data *, unsigned int);
208 void io_u_mark_submit(struct thread_data *, unsigned int);
209 int queue_full(struct thread_data *);
210
211 int do_io_u_sync(struct thread_data *, struct io_u *);
212 int do_io_u_trim(struct thread_data *, struct io_u *);
213
214 #ifdef FIO_INC_DEBUG
215 static inline void dprint_io_u(struct io_u *io_u, const char *p)
216 {
217         struct fio_file *f = io_u->file;
218
219         dprint(FD_IO, "%s: io_u %p: off=%llu/len=%lu/ddir=%d", p, io_u,
220                                         (unsigned long long) io_u->offset,
221                                         io_u->buflen, io_u->ddir);
222         if (fio_debug & (1 << FD_IO)) {
223                 if (f)
224                         log_info("/%s", f->file_name);
225
226                 log_info("\n");
227         }
228 }
229 #else
230 #define dprint_io_u(io_u, p)
231 #endif
232
233 static inline enum fio_ddir acct_ddir(struct io_u *io_u)
234 {
235         if (io_u->acct_ddir != -1)
236                 return io_u->acct_ddir;
237
238         return io_u->ddir;
239 }
240
241 #endif