binject updates
[fio.git] / ioengine.h
CommitLineData
dcefb588
JA
1#ifndef FIO_IOENGINE_H
2#define FIO_IOENGINE_H
3
a5f3027c 4#define FIO_IOOPS_VERSION 12
dcefb588
JA
5
6enum {
0c41214f
RR
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,
38dad62d 11 IO_U_F_BUSY_OK = 1 << 4,
0d29de83 12 IO_U_F_TRIMMED = 1 << 5,
dcefb588
JA
13};
14
15/*
16 * The io unit
17 */
18struct 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;
79a43187
JA
34#endif
35#ifdef FIO_HAVE_BINJECT
36 struct b_user_cmd buc;
dcefb588
JA
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
95228507
JA
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
dcefb588
JA
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 */
92enum {
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
98struct 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
2b4f4abe
JA
119enum 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 */
9c0d2241 128 FIO_PIPEIO = 1 << 8, /* input/output no seekable */
2b4f4abe 129};
dcefb588
JA
130
131/*
132 * io engine entry points
133 */
134extern int __must_check td_io_init(struct thread_data *);
135extern int __must_check td_io_prep(struct thread_data *, struct io_u *);
136extern int __must_check td_io_queue(struct thread_data *, struct io_u *);
137extern int __must_check td_io_sync(struct thread_data *, struct fio_file *);
138extern int __must_check td_io_getevents(struct thread_data *, unsigned int, unsigned int, struct timespec *);
139extern int __must_check td_io_commit(struct thread_data *);
140extern int __must_check td_io_open_file(struct thread_data *, struct fio_file *);
141extern int td_io_close_file(struct thread_data *, struct fio_file *);
142extern int __must_check td_io_get_file_size(struct thread_data *, struct fio_file *);
143
144extern struct ioengine_ops *load_ioengine(struct thread_data *, const char *);
145extern void register_ioengine(struct ioengine_ops *);
146extern void unregister_ioengine(struct ioengine_ops *);
147extern void close_ioengine(struct thread_data *);
148
149/*
150 * io unit handling
151 */
152#define queue_full(td) flist_empty(&(td)->io_u_freelist)
153extern struct io_u *__get_io_u(struct thread_data *);
154extern struct io_u *get_io_u(struct thread_data *);
155extern void put_io_u(struct thread_data *, struct io_u *);
f2bba182 156extern void clear_io_u(struct thread_data *, struct io_u *);
dcefb588 157extern void requeue_io_u(struct thread_data *, struct io_u **);
581e7141
JA
158extern int __must_check io_u_sync_complete(struct thread_data *, struct io_u *, unsigned long *);
159extern int __must_check io_u_queued_complete(struct thread_data *, int, unsigned long *);
dcefb588
JA
160extern void io_u_queued(struct thread_data *, struct io_u *);
161extern void io_u_log_error(struct thread_data *, struct io_u *);
162extern void io_u_mark_depth(struct thread_data *, unsigned int);
163extern void io_u_fill_buffer(struct thread_data *td, struct io_u *, unsigned int);
164void io_u_mark_complete(struct thread_data *, unsigned int);
165void io_u_mark_submit(struct thread_data *, unsigned int);
166
0a28ecda 167int do_io_u_sync(struct thread_data *, struct io_u *);
a5f3027c 168int do_io_u_trim(struct thread_data *, struct io_u *);
44f29692 169
c592b9fe
JA
170#ifdef FIO_INC_DEBUG
171static 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
dcefb588 189#endif