blob: 344cdbf939a3e55fed9c7274133355e058f2a0d8 [file] [log] [blame]
Jens Axboedcefb582009-06-03 08:49:39 +02001#ifndef FIO_IOENGINE_H
2#define FIO_IOENGINE_H
3
Jens Axboea5f30272010-07-19 16:19:55 -06004#define FIO_IOOPS_VERSION 12
Jens Axboedcefb582009-06-03 08:49:39 +02005
6enum {
Radha Ramachandran0c412142009-11-03 21:45:31 +01007 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,
Jens Axboe38dad622010-07-20 14:46:00 -060011 IO_U_F_BUSY_OK = 1 << 4,
Jens Axboe0d29de82010-09-01 13:54:15 +020012 IO_U_F_TRIMMED = 1 << 5,
Jens Axboedcefb582009-06-03 08:49:39 +020013};
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;
34#endif
Jens Axboe79a43182010-09-07 13:28:58 +020035#ifdef FIO_HAVE_BINJECT
36 struct b_user_cmd buc;
37#endif
Jens Axboedcefb582009-06-03 08:49:39 +020038 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
Jens Axboe95228502010-07-14 08:42:03 +020057 /*
58 * Parameter related to pre-filled buffers and
59 * their size to handle variable block sizes.
60 */
61 unsigned long buf_filled_len;
62
Jens Axboedcefb582009-06-03 08:49:39 +020063 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
Jens Axboe2b4f4ab2009-06-03 08:50:36 +0200119enum 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 */
Jens Axboe9c0d2242009-07-01 12:26:28 +0200128 FIO_PIPEIO = 1 << 8, /* input/output no seekable */
Jens Axboe2b4f4ab2009-06-03 08:50:36 +0200129};
Jens Axboedcefb582009-06-03 08:49:39 +0200130
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 *);
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200156extern void clear_io_u(struct thread_data *, struct io_u *);
Jens Axboedcefb582009-06-03 08:49:39 +0200157extern void requeue_io_u(struct thread_data *, struct io_u **);
Jens Axboe581e7142009-06-09 12:47:16 +0200158extern 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 *);
Jens Axboedcefb582009-06-03 08:49:39 +0200160extern 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
Jens Axboe0a28ecd2010-03-09 21:40:38 +0100167int do_io_u_sync(struct thread_data *, struct io_u *);
Jens Axboea5f30272010-07-19 16:19:55 -0600168int do_io_u_trim(struct thread_data *, struct io_u *);
Jens Axboe44f29692010-03-09 20:09:44 +0100169
Jens Axboec592b9f2009-06-03 09:29:28 +0200170#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
Jens Axboedcefb582009-06-03 08:49:39 +0200189#endif