2fd7f52ca714231119010f27df6006dd48a72551
[fio.git] / ioengines.h
1 #ifndef FIO_IOENGINE_H
2 #define FIO_IOENGINE_H
3
4 #include <stddef.h>
5
6 #include "compiler/compiler.h"
7 #include "flist.h"
8 #include "io_u.h"
9 #include "zbd_types.h"
10 #include "fdp.h"
11
12 #define FIO_IOOPS_VERSION       33
13
14 #ifndef CONFIG_DYNAMIC_ENGINES
15 #define FIO_STATIC      static
16 #else
17 #define FIO_STATIC
18 #endif
19
20 /*
21  * io_ops->queue() return values
22  */
23 enum fio_q_status {
24         FIO_Q_COMPLETED = 0,            /* completed sync */
25         FIO_Q_QUEUED    = 1,            /* queued, will complete async */
26         FIO_Q_BUSY      = 2,            /* no more room, call ->commit() */
27 };
28
29 struct ioengine_ops {
30         struct flist_head list;
31         const char *name;
32         int version;
33         int flags;
34         void *dlhandle;
35         int (*setup)(struct thread_data *);
36         int (*init)(struct thread_data *);
37         int (*post_init)(struct thread_data *);
38         int (*prep)(struct thread_data *, struct io_u *);
39         enum fio_q_status (*queue)(struct thread_data *, struct io_u *);
40         int (*commit)(struct thread_data *);
41         int (*getevents)(struct thread_data *, unsigned int, unsigned int, const struct timespec *);
42         struct io_u *(*event)(struct thread_data *, int);
43         char *(*errdetails)(struct io_u *);
44         int (*cancel)(struct thread_data *, struct io_u *);
45         void (*cleanup)(struct thread_data *);
46         int (*open_file)(struct thread_data *, struct fio_file *);
47         int (*close_file)(struct thread_data *, struct fio_file *);
48         int (*invalidate)(struct thread_data *, struct fio_file *);
49         int (*unlink_file)(struct thread_data *, struct fio_file *);
50         int (*get_file_size)(struct thread_data *, struct fio_file *);
51         int (*prepopulate_file)(struct thread_data *, struct fio_file *);
52         void (*terminate)(struct thread_data *);
53         int (*iomem_alloc)(struct thread_data *, size_t);
54         void (*iomem_free)(struct thread_data *);
55         int (*io_u_init)(struct thread_data *, struct io_u *);
56         void (*io_u_free)(struct thread_data *, struct io_u *);
57         int (*get_zoned_model)(struct thread_data *td,
58                                struct fio_file *f, enum zbd_zoned_model *);
59         int (*report_zones)(struct thread_data *, struct fio_file *,
60                             uint64_t, struct zbd_zone *, unsigned int);
61         int (*reset_wp)(struct thread_data *, struct fio_file *,
62                         uint64_t, uint64_t);
63         int (*get_max_open_zones)(struct thread_data *, struct fio_file *,
64                                   unsigned int *);
65         int (*get_max_active_zones)(struct thread_data *, struct fio_file *,
66                                     unsigned int *);
67         int (*finish_zone)(struct thread_data *, struct fio_file *,
68                            uint64_t, uint64_t);
69         int (*fdp_fetch_ruhs)(struct thread_data *, struct fio_file *,
70                               struct fio_ruhs_info *);
71         int option_struct_size;
72         struct fio_option *options;
73 };
74
75 enum fio_ioengine_flags {
76         FIO_SYNCIO      = 1 << 0,       /* io engine has synchronous ->queue */
77         FIO_RAWIO       = 1 << 1,       /* some sort of direct/raw io */
78         FIO_DISKLESSIO  = 1 << 2,       /* no disk involved */
79         FIO_NOEXTEND    = 1 << 3,       /* engine can't extend file */
80         FIO_NODISKUTIL  = 1 << 4,       /* diskutil can't handle filename */
81         FIO_UNIDIR      = 1 << 5,       /* engine is uni-directional */
82         FIO_NOIO        = 1 << 6,       /* thread does only pseudo IO */
83         FIO_PIPEIO      = 1 << 7,       /* input/output no seekable */
84         FIO_BARRIER     = 1 << 8,       /* engine supports barriers */
85         FIO_MEMALIGN    = 1 << 9,       /* engine wants aligned memory */
86         FIO_BIT_BASED   = 1 << 10,      /* engine uses a bit base (e.g. uses Kbit as opposed to KB) */
87         FIO_FAKEIO      = 1 << 11,      /* engine pretends to do IO */
88         FIO_NOSTATS     = 1 << 12,      /* don't do IO stats */
89         FIO_NOFILEHASH  = 1 << 13,      /* doesn't hash the files for lookup later. */
90         FIO_ASYNCIO_SYNC_TRIM
91                         = 1 << 14,      /* io engine has async ->queue except for trim */
92         FIO_NO_OFFLOAD  = 1 << 15,      /* no async offload */
93         FIO_ASYNCIO_SETS_ISSUE_TIME
94                         = 1 << 16,      /* async ioengine with commit function that sets issue_time */
95         FIO_SKIPPABLE_IOMEM_ALLOC
96                         = 1 << 17,      /* skip iomem_alloc & iomem_free if job sets mem/iomem */
97         FIO_RO_NEEDS_RW_OPEN
98                         = 1 << 18,      /* open files in rw mode even if we have a read job; only
99                                            affects ioengines using generic_open_file */
100         FIO_MULTI_RANGE_TRIM
101                         = 1 << 19,      /* ioengine supports trim with more than one range */
102 };
103
104 /*
105  * External engine defined symbol to fill in the engine ops structure
106  */
107 typedef void (*get_ioengine_t)(struct ioengine_ops **);
108
109 /*
110  * io engine entry points
111  */
112 extern int __must_check td_io_init(struct thread_data *);
113 extern int __must_check td_io_prep(struct thread_data *, struct io_u *);
114 extern enum fio_q_status __must_check td_io_queue(struct thread_data *, struct io_u *);
115 extern int __must_check td_io_getevents(struct thread_data *, unsigned int, unsigned int, const struct timespec *);
116 extern void td_io_commit(struct thread_data *);
117 extern int __must_check td_io_open_file(struct thread_data *, struct fio_file *);
118 extern int td_io_close_file(struct thread_data *, struct fio_file *);
119 extern int td_io_unlink_file(struct thread_data *, struct fio_file *);
120 extern int __must_check td_io_get_file_size(struct thread_data *, struct fio_file *);
121
122 extern struct ioengine_ops *load_ioengine(struct thread_data *);
123 extern void register_ioengine(struct ioengine_ops *);
124 extern void unregister_ioengine(struct ioengine_ops *);
125 extern void free_ioengine(struct thread_data *);
126 extern void close_ioengine(struct thread_data *);
127
128 extern int fio_show_ioengine_help(const char *engine);
129
130 #endif