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