Make oslib/strlcat.c a stand-alone library
[fio.git] / io_u.h
1 #ifndef FIO_IO_U
2 #define FIO_IO_U
3
4 #include "compiler/compiler.h"
5 #include "os/os.h"
6 #include "log.h"
7 #include "io_ddir.h"
8 #include "debug.h"
9 #include "file.h"
10 #include "workqueue.h"
11
12 #ifdef CONFIG_LIBAIO
13 #include <libaio.h>
14 #endif
15 #ifdef CONFIG_GUASI
16 #include <guasi.h>
17 #endif
18
19 enum {
20         IO_U_F_FREE             = 1 << 0,
21         IO_U_F_FLIGHT           = 1 << 1,
22         IO_U_F_NO_FILE_PUT      = 1 << 2,
23         IO_U_F_IN_CUR_DEPTH     = 1 << 3,
24         IO_U_F_BUSY_OK          = 1 << 4,
25         IO_U_F_TRIMMED          = 1 << 5,
26         IO_U_F_BARRIER          = 1 << 6,
27         IO_U_F_VER_LIST         = 1 << 7,
28 };
29
30 /*
31  * The io unit
32  */
33 struct io_u {
34         struct timeval start_time;
35         struct timeval issue_time;
36
37         struct fio_file *file;
38         unsigned int flags;
39         enum fio_ddir ddir;
40
41         /*
42          * For replay workloads, we may want to account as a different
43          * IO type than what is being submitted.
44          */
45         enum fio_ddir acct_ddir;
46
47         /*
48          * Write generation
49          */
50         unsigned short numberio;
51
52         /*
53          * Allocated/set buffer and length
54          */
55         unsigned long buflen;
56         unsigned long long offset;
57         void *buf;
58
59         /*
60          * Initial seed for generating the buffer contents
61          */
62         uint64_t rand_seed;
63
64         /*
65          * IO engine state, may be different from above when we get
66          * partial transfers / residual data counts
67          */
68         void *xfer_buf;
69         unsigned long xfer_buflen;
70
71         /*
72          * Parameter related to pre-filled buffers and
73          * their size to handle variable block sizes.
74          */
75         unsigned long buf_filled_len;
76
77         struct io_piece *ipo;
78
79         unsigned int resid;
80         unsigned int error;
81
82         /*
83          * io engine private data
84          */
85         union {
86                 unsigned int index;
87                 unsigned int seen;
88                 void *engine_data;
89         };
90
91         union {
92                 struct flist_head verify_list;
93                 struct workqueue_work work;
94         };
95
96         /*
97          * Callback for io completion
98          */
99         int (*end_io)(struct thread_data *, struct io_u **);
100
101         union {
102 #ifdef CONFIG_LIBAIO
103                 struct iocb iocb;
104 #endif
105 #ifdef CONFIG_POSIXAIO
106                 os_aiocb_t aiocb;
107 #endif
108 #ifdef FIO_HAVE_SGIO
109                 struct sg_io_hdr hdr;
110 #endif
111 #ifdef CONFIG_GUASI
112                 guasi_req_t greq;
113 #endif
114 #ifdef CONFIG_SOLARISAIO
115                 aio_result_t resultp;
116 #endif
117 #ifdef FIO_HAVE_BINJECT
118                 struct b_user_cmd buc;
119 #endif
120 #ifdef CONFIG_RDMA
121                 struct ibv_mr *mr;
122 #endif
123                 void *mmap_data;
124         };
125 };
126
127 /*
128  * io unit handling
129  */
130 extern struct io_u *__get_io_u(struct thread_data *);
131 extern struct io_u *get_io_u(struct thread_data *);
132 extern void put_io_u(struct thread_data *, struct io_u *);
133 extern void clear_io_u(struct thread_data *, struct io_u *);
134 extern void requeue_io_u(struct thread_data *, struct io_u **);
135 extern int __must_check io_u_sync_complete(struct thread_data *, struct io_u *);
136 extern int __must_check io_u_queued_complete(struct thread_data *, int);
137 extern void io_u_queued(struct thread_data *, struct io_u *);
138 extern int io_u_quiesce(struct thread_data *);
139 extern void io_u_log_error(struct thread_data *, struct io_u *);
140 extern void io_u_mark_depth(struct thread_data *, unsigned int);
141 extern void fill_io_buffer(struct thread_data *, void *, unsigned int, unsigned int);
142 extern void io_u_fill_buffer(struct thread_data *td, struct io_u *, unsigned int, unsigned int);
143 void io_u_mark_complete(struct thread_data *, unsigned int);
144 void io_u_mark_submit(struct thread_data *, unsigned int);
145 bool queue_full(const struct thread_data *);
146
147 int do_io_u_sync(const struct thread_data *, struct io_u *);
148 int do_io_u_trim(const struct thread_data *, struct io_u *);
149
150 #ifdef FIO_INC_DEBUG
151 static inline void dprint_io_u(struct io_u *io_u, const char *p)
152 {
153         struct fio_file *f = io_u->file;
154
155         dprint(FD_IO, "%s: io_u %p: off=%llu/len=%lu/ddir=%d", p, io_u,
156                                         (unsigned long long) io_u->offset,
157                                         io_u->buflen, io_u->ddir);
158         if (f)
159                 dprint(FD_IO, "/%s", f->file_name);
160         dprint(FD_IO, "\n");
161 }
162 #else
163 #define dprint_io_u(io_u, p)
164 #endif
165
166 static inline enum fio_ddir acct_ddir(struct io_u *io_u)
167 {
168         if (io_u->acct_ddir != -1)
169                 return io_u->acct_ddir;
170
171         return io_u->ddir;
172 }
173
174 #define io_u_clear(td, io_u, val)       \
175         td_flags_clear((td), &(io_u->flags), (val))
176 #define io_u_set(td, io_u, val)         \
177         td_flags_set((td), &(io_u)->flags, (val))
178
179 #endif