X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=engines%2Fwindowsaio.c;h=773f027c0e424000cbeaf1137fd44fb04e148798;hb=680b5abcb197f52382c8c568c6f1453b410e2b66;hp=96ec0f4b87622c6ba0873b1f8bc40f1a11f7c7c6;hpb=c73ed24623ad94a5254e8302298797aba2eb1e9a;p=fio.git diff --git a/engines/windowsaio.c b/engines/windowsaio.c index 96ec0f4b..773f027c 100644 --- a/engines/windowsaio.c +++ b/engines/windowsaio.c @@ -24,6 +24,7 @@ struct fio_overlapped { struct windowsaio_data { struct io_u **aio_events; + HANDLE iocp; HANDLE iothread; HANDLE iocomplete_event; CANCELIOEX pCancelIoEx; @@ -48,9 +49,9 @@ static DWORD WINAPI IoCompletionRoutine(LPVOID lpParameter); static int fio_windowsaio_init(struct thread_data *td); static int fio_windowsaio_open_file(struct thread_data *td, struct fio_file *f); static int fio_windowsaio_close_file(struct thread_data fio_unused *td, struct fio_file *f); -static int win_to_poxix_error(DWORD winerr); +static int win_to_posix_error(DWORD winerr); -static int win_to_poxix_error(DWORD winerr) +static int win_to_posix_error(DWORD winerr) { switch (winerr) { @@ -125,13 +126,6 @@ static int win_to_poxix_error(DWORD winerr) return winerr; } -int sync_file_range(int fd, off64_t offset, off64_t nbytes, - unsigned int flags) -{ - errno = ENOSYS; - return -1; -} - static int fio_windowsaio_init(struct thread_data *td) { struct windowsaio_data *wd; @@ -170,6 +164,41 @@ static int fio_windowsaio_init(struct thread_data *td) wd->pCancelIoEx = (CANCELIOEX)GetProcAddress(hKernel32Dll, "CancelIoEx"); td->io_ops->data = wd; + + if (!rc) { + struct thread_ctx *ctx; + struct windowsaio_data *wd; + HANDLE hFile; + + hFile = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 0); + if (hFile == INVALID_HANDLE_VALUE) + rc = 1; + + wd = td->io_ops->data; + wd->iothread_running = TRUE; + wd->iocp = hFile; + + if (!rc) + ctx = malloc(sizeof(struct thread_ctx)); + + if (!rc && ctx == NULL) + { + log_err("fio: out of memory in windowsaio\n"); + CloseHandle(hFile); + rc = 1; + } + + if (!rc) + { + ctx->iocp = hFile; + ctx->wd = wd; + wd->iothread = CreateThread(NULL, 0, IoCompletionRoutine, ctx, 0, NULL); + } + + if (rc || wd->iothread == NULL) + rc = 1; + } + return rc; } @@ -197,7 +226,6 @@ static void fio_windowsaio_cleanup(struct thread_data *td) static int fio_windowsaio_open_file(struct thread_data *td, struct fio_file *f) { int rc = 0; - HANDLE hFile; DWORD flags = FILE_FLAG_POSIX_SEMANTICS | FILE_FLAG_OVERLAPPED; DWORD sharemode = FILE_SHARE_READ | FILE_SHARE_WRITE; DWORD openmode = OPEN_ALWAYS; @@ -249,23 +277,11 @@ static int fio_windowsaio_open_file(struct thread_data *td, struct fio_file *f) /* Only set up the completion port and thread if we're not just * querying the device size */ if (!rc && td->io_ops->data != NULL) { - struct thread_ctx *ctx; struct windowsaio_data *wd; - hFile = CreateIoCompletionPort(f->hFile, NULL, 0, 0); - wd = td->io_ops->data; - wd->iothread_running = TRUE; - - if (!rc) { - ctx = malloc(sizeof(struct thread_ctx)); - ctx->iocp = hFile; - ctx->wd = wd; - wd->iothread = CreateThread(NULL, 0, IoCompletionRoutine, ctx, 0, NULL); - } - - if (rc || wd->iothread == NULL) + if (CreateIoCompletionPort(f->hFile, wd->iocp, 0, 0) == NULL) rc = 1; } @@ -383,7 +399,7 @@ static int fio_windowsaio_queue(struct thread_data *td, struct io_u *io_u) case DDIR_SYNC_FILE_RANGE: success = FlushFileBuffers(io_u->file->hFile); if (!success) - io_u->error = win_to_poxix_error(GetLastError()); + io_u->error = win_to_posix_error(GetLastError()); return FIO_Q_COMPLETED; break; @@ -401,7 +417,7 @@ static int fio_windowsaio_queue(struct thread_data *td, struct io_u *io_u) if (success || GetLastError() == ERROR_IO_PENDING) rc = FIO_Q_QUEUED; else { - io_u->error = win_to_poxix_error(GetLastError()); + io_u->error = win_to_posix_error(GetLastError()); io_u->resid = io_u->xfer_buflen; } @@ -434,7 +450,7 @@ static DWORD WINAPI IoCompletionRoutine(LPVOID lpParameter) io_u->error = 0; } else { io_u->resid = io_u->xfer_buflen; - io_u->error = win_to_poxix_error(GetLastError()); + io_u->error = win_to_posix_error(GetLastError()); } fov->io_complete = TRUE; @@ -481,7 +497,7 @@ 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_complete = FALSE; o->io_u = io_u; o->o.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); if (!o->o.hEvent) {