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