[PATCH] Fix stack overflow
[fio.git] / engines / skeleton_external.c
1 /*
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"
16 #include "../os.h"
17
18 /*
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()
22  */
23
24 /*
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.
29  */
30 static struct io_u *fio_skeleton_event(struct thread_data *td, int event)
31 {
32         return NULL;
33 }
34
35 /*
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
39  * numbers. Required.
40  */
41 static int fio_skeleton_getevents(struct thread_data *td, int min, int max,
42                                   struct timespec *t)
43 {
44         return 0;
45 }
46
47 /*
48  * The ->cancel() hook attempts to cancel the io_u. Only relevant for
49  * async io engines, and need not be supported.
50  */
51 static int fio_skeleton_cancel(struct thread_data *td, struct io_u *io_u)
52 {
53         return 0;
54 }
55
56 /*
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.
60  *
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. Should return 0 for io_u complete, < 0 for
65  * an error, and > 0 for the number of bytes transferred.
66  */
67 static int fio_skeleton_queue(struct thread_data *td, struct io_u *io_u)
68 {
69         return 0;
70 }
71
72 /*
73  * The ->prep() function is called for each io_u prior to being submitted
74  * with ->queue(). This hook allows the io engine to perform any
75  * preperatory actions on the io_u, before being submitted. Not required.
76  */
77 static int fio_skeleton_prep(struct thread_data *td, struct io_u *io_u)
78 {
79         return 0;
80 }
81
82 /*
83  * The init function is called once per thread/process, and should set up
84  * any structures that this io engine requires to keep track of io. Not
85  * required.
86  */
87 static int fio_skeleton_init(struct thread_data *td)
88 {
89         return 0;
90 }
91
92 /*
93  * This is paired with the ->init() funtion and is called when a thread is
94  * done doing io. Should tear down anything setup by the ->init() function.
95  * Not required.
96  */
97 static void fio_skeleton_cleanup(struct thread_data *td)
98 {
99 }
100
101 /*
102  * Note that the structure is exported, so that fio can get it via
103  * dlsym(..., "ioengine");
104  */
105 struct ioengine_ops ioengine = {
106         .name           = "engine_name",
107         .version        = FIO_IOOPS_VERSION,
108         .init           = fio_skeleton_init,
109         .prep           = fio_skeleton_prep,
110         .queue          = fio_skeleton_queue,
111         .cancel         = fio_skeleton_cancel,
112         .getevents      = fio_skeleton_getevents,
113         .event          = fio_skeleton_event,
114         .cleanup        = fio_skeleton_cleanup,
115 };