blob: 7c2c1398386707cd7a8f477df90561eb45bbadc3 [file] [log] [blame]
chenhcb92c7f2014-04-02 13:01:01 -04001/*
2 * glusterfs engine
3 *
4 * IO engine using Glusterfs's gfapi async interface
5 *
6 */
7#include "gfapi.h"
chenhbf965e42014-04-02 14:01:11 -04008#define NOT_YET 1
chenhcb92c7f2014-04-02 13:01:01 -04009struct fio_gf_iou {
10 struct io_u *io_u;
11 int io_complete;
12};
13
14static struct io_u *fio_gf_event(struct thread_data *td, int event)
15{
16 struct gf_data *gf_data = td->io_ops->data;
Jens Axboe8f736fb2014-10-28 20:48:33 -060017
chenhcb92c7f2014-04-02 13:01:01 -040018 dprint(FD_IO, "%s\n", __FUNCTION__);
19 return gf_data->aio_events[event];
20}
21
22static int fio_gf_getevents(struct thread_data *td, unsigned int min,
Jens Axboe0cbbc392014-09-30 16:04:12 -060023 unsigned int max, const struct timespec *t)
chenhcb92c7f2014-04-02 13:01:01 -040024{
25 struct gf_data *g = td->io_ops->data;
26 unsigned int events = 0;
27 struct io_u *io_u;
Jens Axboe8f736fb2014-10-28 20:48:33 -060028 int i;
chenhcb92c7f2014-04-02 13:01:01 -040029
30 dprint(FD_IO, "%s\n", __FUNCTION__);
31 do {
32 io_u_qiter(&td->io_u_all, io_u, i) {
Jens Axboe8f736fb2014-10-28 20:48:33 -060033 struct fio_gf_iou *io;
34
chenhcb92c7f2014-04-02 13:01:01 -040035 if (!(io_u->flags & IO_U_F_FLIGHT))
36 continue;
37
Jens Axboe8f736fb2014-10-28 20:48:33 -060038 io = io_u->engine_data;
39 if (io->io_complete) {
chenhcb92c7f2014-04-02 13:01:01 -040040 io->io_complete = 0;
41 g->aio_events[events] = io_u;
42 events++;
chenhbf965e42014-04-02 14:01:11 -040043
Jens Axboe3b665462014-05-19 10:12:56 -060044 if (events >= max)
45 break;
chenhcb92c7f2014-04-02 13:01:01 -040046 }
47
48 }
49 if (events < min)
chenh54fe20f2014-04-08 13:02:26 -040050 usleep(100);
chenhcb92c7f2014-04-02 13:01:01 -040051 else
52 break;
53
54 } while (1);
55
56 return events;
57}
58
chenhbf965e42014-04-02 14:01:11 -040059static void fio_gf_io_u_free(struct thread_data *td, struct io_u *io_u)
chenhcb92c7f2014-04-02 13:01:01 -040060{
chenhbf965e42014-04-02 14:01:11 -040061 struct fio_gf_iou *io = io_u->engine_data;
62
63 if (io) {
Jens Axboe8f736fb2014-10-28 20:48:33 -060064 if (io->io_complete)
Jens Axboe3b665462014-05-19 10:12:56 -060065 log_err("incomplete IO found.\n");
chenhbf965e42014-04-02 14:01:11 -040066 io_u->engine_data = NULL;
67 free(io);
68 }
69}
70
71static int fio_gf_io_u_init(struct thread_data *td, struct io_u *io_u)
72{
chenhbf965e42014-04-02 14:01:11 -040073 dprint(FD_FILE, "%s\n", __FUNCTION__);
chenhcb92c7f2014-04-02 13:01:01 -040074
Jens Axboe3b665462014-05-19 10:12:56 -060075 if (!io_u->engine_data) {
Jens Axboe8f736fb2014-10-28 20:48:33 -060076 struct fio_gf_iou *io;
77
Jens Axboe3b665462014-05-19 10:12:56 -060078 io = malloc(sizeof(struct fio_gf_iou));
79 if (!io) {
80 td_verror(td, errno, "malloc");
81 return 1;
82 }
83 io->io_complete = 0;
84 io->io_u = io_u;
85 io_u->engine_data = io;
86 }
chenhcb92c7f2014-04-02 13:01:01 -040087 return 0;
88}
89
Jens Axboe3b665462014-05-19 10:12:56 -060090static void gf_async_cb(glfs_fd_t * fd, ssize_t ret, void *data)
chenhcb92c7f2014-04-02 13:01:01 -040091{
Jens Axboe8f736fb2014-10-28 20:48:33 -060092 struct io_u *io_u = data;
93 struct fio_gf_iou *iou = io_u->engine_data;
chenhcb92c7f2014-04-02 13:01:01 -040094
Jens Axboe3b665462014-05-19 10:12:56 -060095 dprint(FD_IO, "%s ret %lu\n", __FUNCTION__, ret);
96 iou->io_complete = 1;
chenhcb92c7f2014-04-02 13:01:01 -040097}
98
Jens Axboe3b665462014-05-19 10:12:56 -060099static int fio_gf_async_queue(struct thread_data fio_unused * td,
100 struct io_u *io_u)
chenhcb92c7f2014-04-02 13:01:01 -0400101{
102 struct gf_data *g = td->io_ops->data;
Jens Axboe8f736fb2014-10-28 20:48:33 -0600103 int r;
chenhcb92c7f2014-04-02 13:01:01 -0400104
Jens Axboe8f736fb2014-10-28 20:48:33 -0600105 dprint(FD_IO, "%s op %s\n", __FUNCTION__, io_ddir_name(io_u->ddir));
chenhbf965e42014-04-02 14:01:11 -0400106
chenhcb92c7f2014-04-02 13:01:01 -0400107 fio_ro_check(td, io_u);
108
109 if (io_u->ddir == DDIR_READ)
Jens Axboe3b665462014-05-19 10:12:56 -0600110 r = glfs_pread_async(g->fd, io_u->xfer_buf, io_u->xfer_buflen,
Jens Axboe8f736fb2014-10-28 20:48:33 -0600111 io_u->offset, 0, gf_async_cb, io_u);
chenhcb92c7f2014-04-02 13:01:01 -0400112 else if (io_u->ddir == DDIR_WRITE)
Jens Axboe3b665462014-05-19 10:12:56 -0600113 r = glfs_pwrite_async(g->fd, io_u->xfer_buf, io_u->xfer_buflen,
Jens Axboe8f736fb2014-10-28 20:48:33 -0600114 io_u->offset, 0, gf_async_cb, io_u);
Jens Axboe25393fa2014-10-28 20:40:21 -0600115#if defined(CONFIG_GF_TRIM)
116 else if (io_u->ddir == DDIR_TRIM)
117 r = glfs_discard_async(g->fd, io_u->offset, io_u->xfer_buflen,
118 gf_async_cb, io_u);
119#endif
Jens Axboea2f1c2d2014-12-10 08:12:56 -0700120 else if (io_u->ddir == DDIR_DATASYNC)
121 r = glfs_fdatasync_async(g->fd, gf_async_cb, io_u);
Jens Axboe8f736fb2014-10-28 20:48:33 -0600122 else if (io_u->ddir == DDIR_SYNC)
123 r = glfs_fsync_async(g->fd, gf_async_cb, io_u);
124 else
Jens Axboe045dd682015-01-05 08:50:26 -0700125 r = EINVAL;
Jens Axboe8f736fb2014-10-28 20:48:33 -0600126
Jens Axboe3b665462014-05-19 10:12:56 -0600127 if (r) {
Jens Axboe8f736fb2014-10-28 20:48:33 -0600128 log_err("glfs queue failed.\n");
Jens Axboe3b665462014-05-19 10:12:56 -0600129 io_u->error = r;
130 goto failed;
131 }
chenhcb92c7f2014-04-02 13:01:01 -0400132 return FIO_Q_QUEUED;
133
134failed:
135 io_u->error = r;
136 td_verror(td, io_u->error, "xfer");
137 return FIO_Q_COMPLETED;
138}
139
chenhbf965e42014-04-02 14:01:11 -0400140int fio_gf_async_setup(struct thread_data *td)
141{
Jens Axboe8f736fb2014-10-28 20:48:33 -0600142 struct gf_data *g;
143 int r;
Jens Axboe49fe93e2014-10-13 12:18:07 -0600144
chenhbf965e42014-04-02 14:01:11 -0400145#if defined(NOT_YET)
Jens Axboe49fe93e2014-10-13 12:18:07 -0600146 log_err("the async interface is still very experimental...\n");
chenhbf965e42014-04-02 14:01:11 -0400147#endif
Jens Axboe3b665462014-05-19 10:12:56 -0600148 r = fio_gf_setup(td);
Jens Axboe8f736fb2014-10-28 20:48:33 -0600149 if (r)
Jens Axboe3b665462014-05-19 10:12:56 -0600150 return r;
Jens Axboe8f736fb2014-10-28 20:48:33 -0600151
chenh54fe20f2014-04-08 13:02:26 -0400152 td->o.use_thread = 1;
Jens Axboe3b665462014-05-19 10:12:56 -0600153 g = td->io_ops->data;
Jens Axboe8f736fb2014-10-28 20:48:33 -0600154 g->aio_events = calloc(td->o.iodepth, sizeof(struct io_u *));
Jens Axboe3b665462014-05-19 10:12:56 -0600155 if (!g->aio_events) {
156 r = -ENOMEM;
157 fio_gf_cleanup(td);
158 return r;
159 }
chenhbf965e42014-04-02 14:01:11 -0400160
Jens Axboe3b665462014-05-19 10:12:56 -0600161 return r;
chenhbf965e42014-04-02 14:01:11 -0400162}
163
chenhcb92c7f2014-04-02 13:01:01 -0400164static struct ioengine_ops ioengine = {
Jens Axboe3b665462014-05-19 10:12:56 -0600165 .name = "gfapi_async",
166 .version = FIO_IOOPS_VERSION,
167 .init = fio_gf_async_setup,
168 .cleanup = fio_gf_cleanup,
Jens Axboe3b665462014-05-19 10:12:56 -0600169 .queue = fio_gf_async_queue,
170 .open_file = fio_gf_open_file,
171 .close_file = fio_gf_close_file,
Castor Fu9187a262014-08-19 09:28:53 -0700172 .unlink_file = fio_gf_unlink_file,
Jens Axboe3b665462014-05-19 10:12:56 -0600173 .get_file_size = fio_gf_get_file_size,
174 .getevents = fio_gf_getevents,
175 .event = fio_gf_event,
176 .io_u_init = fio_gf_io_u_init,
177 .io_u_free = fio_gf_io_u_free,
178 .options = gfapi_options,
chenhcb92c7f2014-04-02 13:01:01 -0400179 .option_struct_size = sizeof(struct gf_options),
Jens Axboe3b665462014-05-19 10:12:56 -0600180 .flags = FIO_DISKLESSIO,
chenhcb92c7f2014-04-02 13:01:01 -0400181};
182
183static void fio_init fio_gf_register(void)
184{
Jens Axboe3b665462014-05-19 10:12:56 -0600185 register_ioengine(&ioengine);
chenhcb92c7f2014-04-02 13:01:01 -0400186}
187
188static void fio_exit fio_gf_unregister(void)
189{
Jens Axboe3b665462014-05-19 10:12:56 -0600190 unregister_ioengine(&ioengine);
chenhcb92c7f2014-04-02 13:01:01 -0400191}