- if (!td->o.odirect && !td->o.sync_io && td->io_ops->data != NULL)
- flags |= FILE_FLAG_OVERLAPPED;
-
- if (td->o.odirect)
- flags |= FILE_FLAG_NO_BUFFERING;
- if (td->o.sync_io)
- flags |= FILE_FLAG_WRITE_THROUGH;
-
-
- if (td->o.td_ddir == TD_DDIR_READ ||
- td->o.td_ddir == TD_DDIR_WRITE)
- flags |= FILE_FLAG_SEQUENTIAL_SCAN;
- else
- flags |= FILE_FLAG_RANDOM_ACCESS;
-
- if (!td_write(td) || read_only)
- access = GENERIC_READ;
- else
- access = (GENERIC_READ | GENERIC_WRITE);
-
- if (td->o.create_on_open > 0)
- openmode = OPEN_ALWAYS;
- else
- openmode = OPEN_EXISTING;
-
- f->hFile = CreateFile(f->file_name, access, sharemode,
- NULL, openmode, flags, NULL);
-
- if (f->hFile == INVALID_HANDLE_VALUE) {
- PrintError(__func__);
- rc = 1;
- }
-
- /* Only set up the competion port and thread if we're not just
- * querying the device size */
- if (!rc && td->io_ops->data != NULL && !td->o.odirect && !td->o.sync_io) {
- struct thread_ctx *ctx;
- struct windowsaio_data *wd;
- hFile = CreateIoCompletionPort(f->hFile, NULL, 0, 0);
-
-
- wd = td->io_ops->data;
-
- if (!td->o.odirect && !td->o.sync_io)
- wd->useIOCP = 1;
- else
- wd->useIOCP = 0;
-
- wd->io_index = 0;
- wd->iothread_running = TRUE;
- /* Create a manual-reset event */
- wd->iothread_stopped = CreateEvent(NULL, TRUE, FALSE, NULL);
-
- if (wd->iothread_stopped == NULL)
- rc = 1;
-
- if (!rc) {
- for (i = 0; i < td->o.iodepth; i++) {
- /* Create a manual-reset event for putting in OVERLAPPED */
- wd->io_handles[i] = CreateEvent(NULL, TRUE, FALSE, NULL);
- if (wd->io_handles[i] == NULL) {
- PrintError(__func__);
- rc = 1;
- break;
- }
- }
- }
-
- 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) {
- PrintError(__func__);
- rc = 1;
- }
- }
-
- return rc;
-}
-
-static int fio_windowsaio_close_file(struct thread_data fio_unused *td, struct fio_file *f)
-{
- struct windowsaio_data *wd;
-
- dprint(FD_FILE, "fd close %s\n", f->file_name);
-
- if (td->io_ops->data != NULL) {
- wd = td->io_ops->data;
- wd->iothread_running = FALSE;
- WaitForSingleObject(wd->iothread_stopped, INFINITE);
- }
-
- if (f->hFile != INVALID_HANDLE_VALUE) {
- if (!CloseHandle(f->hFile))
- PrintError(__func__);
- }
-
- f->hFile = INVALID_HANDLE_VALUE;