Fix typo (READ/DDIR_READ).
[fio.git] / ioengine.h
1 #ifndef FIO_IOENGINE_H
2 #define FIO_IOENGINE_H
3
4 #ifdef CONFIG_LIBAIO
5 #include <libaio.h>
6 #endif
7 #ifdef CONFIG_GUASI
8 #include <guasi.h>
9 #endif
10
11 #define FIO_IOOPS_VERSION       14
12
13 enum {
14         IO_U_F_FREE             = 1 << 0,
15         IO_U_F_FLIGHT           = 1 << 1,
16         IO_U_F_FREE_DEF         = 1 << 2,
17         IO_U_F_IN_CUR_DEPTH     = 1 << 3,
18         IO_U_F_BUSY_OK          = 1 << 4,
19         IO_U_F_TRIMMED          = 1 << 5,
20         IO_U_F_BARRIER          = 1 << 6,
21         IO_U_F_VER_LIST         = 1 << 7,
22 };
23
24 /*
25  * The io unit
26  */
27 struct io_u {
28         union {
29 #ifdef CONFIG_LIBAIO
30                 struct iocb iocb;
31 #endif
32 #ifdef CONFIG_POSIXAIO
33                 os_aiocb_t aiocb;
34 #endif
35 #ifdef FIO_HAVE_SGIO
36                 struct sg_io_hdr hdr;
37 #endif
38 #ifdef CONFIG_GUASI
39                 guasi_req_t greq;
40 #endif
41 #ifdef CONFIG_SOLARISAIO
42                 aio_result_t resultp;
43 #endif
44 #ifdef FIO_HAVE_BINJECT
45                 struct b_user_cmd buc;
46 #endif
47 #ifdef CONFIG_RDMA
48                 struct ibv_mr *mr;
49 #endif
50                 void *mmap_data;
51         };
52         struct timeval start_time;
53         struct timeval issue_time;
54
55         struct fio_file *file;
56         unsigned int flags;
57         enum fio_ddir ddir;
58
59         /*
60          * Allocated/set buffer and length
61          */
62         unsigned long buflen;
63         unsigned long long offset;
64         void *buf;
65
66         /*
67          * Initial seed for generating the buffer contents
68          */
69         unsigned long rand_seed;
70
71         /*
72          * IO engine state, may be different from above when we get
73          * partial transfers / residual data counts
74          */
75         void *xfer_buf;
76         unsigned long xfer_buflen;
77
78         /*
79          * Parameter related to pre-filled buffers and
80          * their size to handle variable block sizes.
81          */
82         unsigned long buf_filled_len;
83
84         unsigned int resid;
85         unsigned int error;
86
87         /*
88          * io engine private data
89          */
90         union {
91                 unsigned int index;
92                 unsigned int seen;
93                 void *engine_data;
94         };
95
96         struct flist_head list;
97
98         /*
99          * Callback for io completion
100          */
101         int (*end_io)(struct thread_data *, struct io_u *);
102 };
103
104 /*
105  * io_ops->queue() return values
106  */
107 enum {
108         FIO_Q_COMPLETED = 0,            /* completed sync */
109         FIO_Q_QUEUED    = 1,            /* queued, will complete async */
110         FIO_Q_BUSY      = 2,            /* no more room, call ->commit() */
111 };
112
113 struct ioengine_ops {
114         struct flist_head list;
115         char name[16];
116         int version;
117         int flags;
118         int (*setup)(struct thread_data *);
119         int (*init)(struct thread_data *);
120         int (*prep)(struct thread_data *, struct io_u *);
121         int (*queue)(struct thread_data *, struct io_u *);
122         int (*commit)(struct thread_data *);
123         int (*getevents)(struct thread_data *, unsigned int, unsigned int, struct timespec *);
124         struct io_u *(*event)(struct thread_data *, int);
125         int (*cancel)(struct thread_data *, struct io_u *);
126         void (*cleanup)(struct thread_data *);
127         int (*open_file)(struct thread_data *, struct fio_file *);
128         int (*close_file)(struct thread_data *, struct fio_file *);
129         int (*get_file_size)(struct thread_data *, struct fio_file *);
130         void (*terminate)(struct thread_data *);
131         int (*io_u_init)(struct thread_data *, struct io_u *);
132         void (*io_u_free)(struct thread_data *, struct io_u *);
133         int option_struct_size;
134         struct fio_option *options;
135         void *data;
136         void *dlhandle;
137 };
138
139 enum fio_ioengine_flags {
140         FIO_SYNCIO      = 1 << 0,       /* io engine has synchronous ->queue */
141         FIO_RAWIO       = 1 << 1,       /* some sort of direct/raw io */
142         FIO_DISKLESSIO  = 1 << 2,       /* no disk involved */
143         FIO_NOEXTEND    = 1 << 3,       /* engine can't extend file */
144         FIO_NODISKUTIL  = 1 << 4,       /* diskutil can't handle filename */
145         FIO_UNIDIR      = 1 << 5,       /* engine is uni-directional */
146         FIO_NOIO        = 1 << 6,       /* thread does only pseudo IO */
147         FIO_PIPEIO      = 1 << 7,       /* input/output no seekable */
148         FIO_BARRIER     = 1 << 8,       /* engine supports barriers */
149         FIO_MEMALIGN    = 1 << 9,       /* engine wants aligned memory */
150 };
151
152 /*
153  * io engine entry points
154  */
155 extern int __must_check td_io_init(struct thread_data *);
156 extern int __must_check td_io_prep(struct thread_data *, struct io_u *);
157 extern int __must_check td_io_queue(struct thread_data *, struct io_u *);
158 extern int __must_check td_io_sync(struct thread_data *, struct fio_file *);
159 extern int __must_check td_io_getevents(struct thread_data *, unsigned int, unsigned int, struct timespec *);
160 extern int __must_check td_io_commit(struct thread_data *);
161 extern int __must_check td_io_open_file(struct thread_data *, struct fio_file *);
162 extern int td_io_close_file(struct thread_data *, struct fio_file *);
163 extern int __must_check td_io_get_file_size(struct thread_data *, struct fio_file *);
164
165 extern struct ioengine_ops *load_ioengine(struct thread_data *, const char *);
166 extern void register_ioengine(struct ioengine_ops *);
167 extern void unregister_ioengine(struct ioengine_ops *);
168 extern void free_ioengine(struct thread_data *);
169 extern void close_ioengine(struct thread_data *);
170
171 extern int fio_show_ioengine_help(const char *engine);
172
173 /*
174  * io unit handling
175  */
176 #define queue_full(td)  flist_empty(&(td)->io_u_freelist)
177 extern struct io_u *__get_io_u(struct thread_data *);
178 extern struct io_u *get_io_u(struct thread_data *);
179 extern void put_io_u(struct thread_data *, struct io_u *);
180 extern void clear_io_u(struct thread_data *, struct io_u *);
181 extern void requeue_io_u(struct thread_data *, struct io_u **);
182 extern int __must_check io_u_sync_complete(struct thread_data *, struct io_u *, unsigned long *);
183 extern int __must_check io_u_queued_complete(struct thread_data *, int, unsigned long *);
184 extern void io_u_queued(struct thread_data *, struct io_u *);
185 extern void io_u_log_error(struct thread_data *, struct io_u *);
186 extern void io_u_mark_depth(struct thread_data *, unsigned int);
187 extern void io_u_fill_buffer(struct thread_data *td, struct io_u *, unsigned int, unsigned int);
188 void io_u_mark_complete(struct thread_data *, unsigned int);
189 void io_u_mark_submit(struct thread_data *, unsigned int);
190
191 int do_io_u_sync(struct thread_data *, struct io_u *);
192 int do_io_u_trim(struct thread_data *, struct io_u *);
193
194 #ifdef FIO_INC_DEBUG
195 static inline void dprint_io_u(struct io_u *io_u, const char *p)
196 {
197         struct fio_file *f = io_u->file;
198
199         dprint(FD_IO, "%s: io_u %p: off=%llu/len=%lu/ddir=%d", p, io_u,
200                                         (unsigned long long) io_u->offset,
201                                         io_u->buflen, io_u->ddir);
202         if (fio_debug & (1 << FD_IO)) {
203                 if (f)
204                         log_info("/%s", f->file_name);
205
206                 log_info("\n");
207         }
208 }
209 #else
210 #define dprint_io_u(io_u, p)
211 #endif
212
213 #endif