io_u = flist_entry(entry, struct io_u, list);
flist_del(&io_u->list);
+
+ if (td->io_ops->io_u_free)
+ td->io_ops->io_u_free(td, io_u);
+
fio_memfree(io_u, sizeof(*io_u));
}
io_u->index = i;
io_u->flags = IO_U_F_FREE;
flist_add(&io_u->list, &td->io_u_freelist);
+
+ if (td->io_ops->io_u_init) {
+ int ret = td->io_ops->io_u_init(td, io_u);
+
+ if (ret) {
+ log_err("fio: failed to init engine data: %d\n", ret);
+ return 1;
+ }
+ }
+
p += max_bs;
}
OVERLAPPED o;
struct io_u *io_u;
BOOL io_complete;
- BOOL io_free;
};
struct windowsaio_data {
- struct fio_overlapped *ovls;
struct io_u **aio_events;
HANDLE iothread;
HANDLE iocomplete_event;
struct windowsaio_data *wd;
HANDLE hKernel32Dll;
int rc = 0;
- int i;
wd = malloc(sizeof(struct windowsaio_data));
if (wd != NULL)
rc = 1;
}
- if (!rc) {
- wd->ovls = malloc(td->o.iodepth * sizeof(struct fio_overlapped));
- if (wd->ovls == NULL)
- rc = 1;
- }
-
- if (!rc) {
- for (i = 0; i < td->o.iodepth; i++) {
- wd->ovls[i].io_free = TRUE;
- wd->ovls[i].io_complete = FALSE;
-
- wd->ovls[i].o.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
- if (wd->ovls[i].o.hEvent == NULL) {
- rc = 1;
- break;
- }
- }
- }
-
if (!rc) {
/* Create an auto-reset event */
wd->iocomplete_event = CreateEvent(NULL, FALSE, FALSE, NULL);
if (rc) {
if (wd != NULL) {
- if (wd->ovls != NULL)
- free(wd->ovls);
if (wd->aio_events != NULL)
free(wd->aio_events);
static void fio_windowsaio_cleanup(struct thread_data *td)
{
- int i;
struct windowsaio_data *wd;
wd = td->io_ops->data;
CloseHandle(wd->iothread);
CloseHandle(wd->iocomplete_event);
- for (i = 0; i < td->o.iodepth; i++) {
- CloseHandle(wd->ovls[i].o.hEvent);
- }
-
free(wd->aio_events);
- free(wd->ovls);
free(wd);
td->io_ops->data = NULL;
if (fov->io_complete) {
fov->io_complete = FALSE;
- fov->io_free = TRUE;
ResetEvent(fov->o.hEvent);
wd->aio_events[dequeued] = io_u;
dequeued++;
static int fio_windowsaio_queue(struct thread_data *td, struct io_u *io_u)
{
- LPOVERLAPPED lpOvl = NULL;
- struct windowsaio_data *wd;
+ struct fio_overlapped *o = io_u->engine_data;
+ LPOVERLAPPED lpOvl = &o->o;
DWORD iobytes;
BOOL success = FALSE;
- int index;
int rc = FIO_Q_COMPLETED;
fio_ro_check(td, io_u);
- wd = td->io_ops->data;
-
- for (index = 0; index < td->o.iodepth; index++) {
- if (wd->ovls[index].io_free)
- break;
- }
-
- assert(index < td->o.iodepth);
-
- wd->ovls[index].io_free = FALSE;
- wd->ovls[index].io_u = io_u;
- lpOvl = &wd->ovls[index].o;
lpOvl->Internal = STATUS_PENDING;
lpOvl->InternalHigh = 0;
lpOvl->Offset = io_u->offset & 0xFFFFFFFF;
lpOvl->OffsetHigh = io_u->offset >> 32;
- io_u->engine_data = &wd->ovls[index];
switch (io_u->ddir) {
case DDIR_WRITE:
return rc;
}
+static void fio_windowsaio_io_u_free(struct thread_data *td, struct io_u *io_u)
+{
+ struct fio_overlapped *o = io_u->engine_data;
+
+ if (o) {
+ CloseHandle(o->o.hEvent);
+ io_u->engine_data = NULL;
+ free(o);
+ }
+}
+
+static int fio_windowsaio_io_u_init(struct thread_data *td, struct io_u *io_u)
+{
+ struct fio_overlapped *o;
+
+ o = malloc(sizeof(*o));
+ o->io_complete = FALSE:
+ o->io_u = io_u;
+ o->o.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
+ if (!o->o.hEvent) {
+ free(o);
+ return 1;
+ }
+
+ io_u->engine_data = o;
+ return 0;
+}
+
static struct ioengine_ops ioengine = {
.name = "windowsaio",
.version = FIO_IOOPS_VERSION,
.cleanup = fio_windowsaio_cleanup,
.open_file = fio_windowsaio_open_file,
.close_file = fio_windowsaio_close_file,
- .get_file_size = generic_get_file_size
+ .get_file_size = generic_get_file_size,
+ .io_u_init = fio_windowsaio_io_u_init,
+ .io_u_free = fio_windowsaio_io_u_free,
};
static void fio_init fio_posixaio_register(void)