blob: 548676a782a99bd94519c40444e866214d1fd25b [file] [log] [blame]
Jens Axboeda51c052006-11-07 16:02:11 +01001/*
2 * Skeleton for a sample external io engine
3 *
4 * Should be compiled with:
5 *
6 * gcc -Wall -O2 -g -shared -rdynamic -fPIC -o engine.o engine.c
7 *
8 */
9#include <stdio.h>
10#include <stdlib.h>
11#include <unistd.h>
12#include <errno.h>
13#include <assert.h>
14
15#include "../fio.h"
Jens Axboeda51c052006-11-07 16:02:11 +010016
17/*
18 * The core of the module is identical to the ones included with fio,
19 * read those. You cannot use register_ioengine() and unregister_ioengine()
20 * for external modules, they should be gotten through dlsym()
21 */
22
23/*
Jens Axboe830a78b2006-11-08 09:58:59 +010024 * The ->event() hook is called to match an event number with an io_u.
25 * After the core has called ->getevents() and it has returned eg 3,
26 * the ->event() hook must return the 3 events that have completed for
27 * subsequent calls to ->event() with [0-2]. Required.
28 */
29static struct io_u *fio_skeleton_event(struct thread_data *td, int event)
30{
31 return NULL;
32}
33
34/*
35 * The ->getevents() hook is used to reap completion events from an async
36 * io engine. It returns the number of completed events since the last call,
37 * which may then be retrieved by calling the ->event() hook with the event
38 * numbers. Required.
39 */
Jens Axboee7d2e612007-12-11 10:49:39 +010040static int fio_skeleton_getevents(struct thread_data *td, unsigned int min,
41 unsigned int max, struct timespec *t)
Jens Axboe830a78b2006-11-08 09:58:59 +010042{
43 return 0;
44}
45
46/*
47 * The ->cancel() hook attempts to cancel the io_u. Only relevant for
48 * async io engines, and need not be supported.
49 */
50static int fio_skeleton_cancel(struct thread_data *td, struct io_u *io_u)
51{
52 return 0;
53}
54
55/*
56 * The ->queue() hook is responsible for initiating io on the io_u
57 * being passed in. If the io engine is a synchronous one, io may complete
58 * before ->queue() returns. Required.
Jens Axboee2a26d22007-02-06 20:17:21 +010059 *
60 * The io engine must transfer in the direction noted by io_u->ddir
61 * to the buffer pointed to by io_u->xfer_buf for as many bytes as
Bruce Cran03e20d62011-01-02 20:14:54 +010062 * io_u->xfer_buflen. Residual data count may be set in io_u->resid
Jens Axboe36167d82007-02-18 05:41:31 +010063 * for a short read/write.
Jens Axboe830a78b2006-11-08 09:58:59 +010064 */
65static int fio_skeleton_queue(struct thread_data *td, struct io_u *io_u)
66{
Jens Axboe36167d82007-02-18 05:41:31 +010067 /*
Jens Axboe7101d9c2007-09-12 13:12:39 +020068 * Double sanity check to catch errant write on a readonly setup
69 */
70 fio_ro_check(td, io_u);
71
72 /*
Jens Axboe36167d82007-02-18 05:41:31 +010073 * Could return FIO_Q_QUEUED for a queued request,
74 * FIO_Q_COMPLETED for a completed request, and FIO_Q_BUSY
75 * if we could queue no more at this point (you'd have to
76 * define ->commit() to handle that.
77 */
78 return FIO_Q_COMPLETED;
Jens Axboe830a78b2006-11-08 09:58:59 +010079}
80
81/*
82 * The ->prep() function is called for each io_u prior to being submitted
83 * with ->queue(). This hook allows the io engine to perform any
Jens Axboe34403fb2007-03-02 21:43:25 +010084 * preparatory actions on the io_u, before being submitted. Not required.
Jens Axboe830a78b2006-11-08 09:58:59 +010085 */
86static int fio_skeleton_prep(struct thread_data *td, struct io_u *io_u)
87{
88 return 0;
89}
90
91/*
92 * The init function is called once per thread/process, and should set up
93 * any structures that this io engine requires to keep track of io. Not
94 * required.
95 */
96static int fio_skeleton_init(struct thread_data *td)
97{
98 return 0;
99}
100
101/*
102 * This is paired with the ->init() funtion and is called when a thread is
103 * done doing io. Should tear down anything setup by the ->init() function.
104 * Not required.
105 */
106static void fio_skeleton_cleanup(struct thread_data *td)
107{
108}
109
110/*
Jens Axboeb5af8292007-03-08 12:43:13 +0100111 * Hook for opening the given file. Unless the engine has special
112 * needs, it usually just provides generic_file_open() as the handler.
113 */
114static int fio_skeleton_open(struct thread_data *td, struct fio_file *f)
115{
116 return generic_file_open(td, f);
117}
118
119/*
120 * Hook for closing a file. See fio_skeleton_open().
121 */
122static int fio_skeleton_close(struct thread_data *td, struct fio_file *f)
123{
124 generic_file_close(td, f);
125}
126
127/*
Jens Axboeda51c052006-11-07 16:02:11 +0100128 * Note that the structure is exported, so that fio can get it via
129 * dlsym(..., "ioengine");
130 */
131struct ioengine_ops ioengine = {
132 .name = "engine_name",
133 .version = FIO_IOOPS_VERSION,
134 .init = fio_skeleton_init,
135 .prep = fio_skeleton_prep,
136 .queue = fio_skeleton_queue,
Jens Axboe830a78b2006-11-08 09:58:59 +0100137 .cancel = fio_skeleton_cancel,
Jens Axboeda51c052006-11-07 16:02:11 +0100138 .getevents = fio_skeleton_getevents,
139 .event = fio_skeleton_event,
140 .cleanup = fio_skeleton_cleanup,
Jens Axboeb5af8292007-03-08 12:43:13 +0100141 .open_file = fio_skeleton_open,
142 .close_file = fio_skeleton_close,
Jens Axboeda51c052006-11-07 16:02:11 +0100143};