2 * Skeleton for a sample external io engine
4 * Should be compiled with:
6 * gcc -Wall -O2 -g -shared -rdynamic -fPIC -o engine.o engine.c
19 * The core of the module is identical to the ones included with fio,
20 * read those. You cannot use register_ioengine() and unregister_ioengine()
21 * for external modules, they should be gotten through dlsym()
25 * The ->event() hook is called to match an event number with an io_u.
26 * After the core has called ->getevents() and it has returned eg 3,
27 * the ->event() hook must return the 3 events that have completed for
28 * subsequent calls to ->event() with [0-2]. Required.
30 static struct io_u *fio_skeleton_event(struct thread_data *td, int event)
36 * The ->getevents() hook is used to reap completion events from an async
37 * io engine. It returns the number of completed events since the last call,
38 * which may then be retrieved by calling the ->event() hook with the event
41 static int fio_skeleton_getevents(struct thread_data *td, int min, int max,
48 * The ->cancel() hook attempts to cancel the io_u. Only relevant for
49 * async io engines, and need not be supported.
51 static int fio_skeleton_cancel(struct thread_data *td, struct io_u *io_u)
57 * The ->queue() hook is responsible for initiating io on the io_u
58 * being passed in. If the io engine is a synchronous one, io may complete
59 * before ->queue() returns. Required.
61 * The io engine must transfer in the direction noted by io_u->ddir
62 * to the buffer pointed to by io_u->xfer_buf for as many bytes as
63 * io_u->xfer_buflen. Residual data count may be set in io_u->residual
64 * for a short read/write.
66 static int fio_skeleton_queue(struct thread_data *td, struct io_u *io_u)
69 * Could return FIO_Q_QUEUED for a queued request,
70 * FIO_Q_COMPLETED for a completed request, and FIO_Q_BUSY
71 * if we could queue no more at this point (you'd have to
72 * define ->commit() to handle that.
74 return FIO_Q_COMPLETED;
78 * The ->prep() function is called for each io_u prior to being submitted
79 * with ->queue(). This hook allows the io engine to perform any
80 * preparatory actions on the io_u, before being submitted. Not required.
82 static int fio_skeleton_prep(struct thread_data *td, struct io_u *io_u)
88 * The init function is called once per thread/process, and should set up
89 * any structures that this io engine requires to keep track of io. Not
92 static int fio_skeleton_init(struct thread_data *td)
98 * This is paired with the ->init() funtion and is called when a thread is
99 * done doing io. Should tear down anything setup by the ->init() function.
102 static void fio_skeleton_cleanup(struct thread_data *td)
107 * Hook for opening the given file. Unless the engine has special
108 * needs, it usually just provides generic_file_open() as the handler.
110 static int fio_skeleton_open(struct thread_data *td, struct fio_file *f)
112 return generic_file_open(td, f);
116 * Hook for closing a file. See fio_skeleton_open().
118 static int fio_skeleton_close(struct thread_data *td, struct fio_file *f)
120 generic_file_close(td, f);
124 * Note that the structure is exported, so that fio can get it via
125 * dlsym(..., "ioengine");
127 struct ioengine_ops ioengine = {
128 .name = "engine_name",
129 .version = FIO_IOOPS_VERSION,
130 .init = fio_skeleton_init,
131 .prep = fio_skeleton_prep,
132 .queue = fio_skeleton_queue,
133 .cancel = fio_skeleton_cancel,
134 .getevents = fio_skeleton_getevents,
135 .event = fio_skeleton_event,
136 .cleanup = fio_skeleton_cleanup,
137 .open_file = fio_skeleton_open,
138 .close_file = fio_skeleton_close,