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