Fix windows out-of-memory handling
authorBruce Cran <BCran@fusionio.com>
Thu, 6 Dec 2012 19:33:14 +0000 (20:33 +0100)
committerJens Axboe <axboe@kernel.dk>
Thu, 6 Dec 2012 19:33:14 +0000 (20:33 +0100)
Signed-off-by: Jens Axboe <axboe@kernel.dk>
engines/windowsaio.c
os/os-windows.h
os/windows/posix.c

index 96ec0f4b87622c6ba0873b1f8bc40f1a11f7c7c6..2f3fbef2e1eb01d481dadeb1d880bfd9613030bc 100644 (file)
@@ -48,9 +48,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)
        {
@@ -253,15 +253,27 @@ static int fio_windowsaio_open_file(struct thread_data *td, struct fio_file *f)
                struct windowsaio_data *wd;
 
                hFile = CreateIoCompletionPort(f->hFile, NULL, 0, 0);
+               if (hFile == INVALID_HANDLE_VALUE)
+                       rc = 1;
 
                wd = td->io_ops->data;
                wd->iothread_running = TRUE;
 
-               if (!rc) {
+               if (!rc)
                        ctx = malloc(sizeof(struct thread_ctx));
+
+               if (!rc && ctx == NULL)
+               {
+                       log_err("fio: out of memory in windowsaio\n");
+                       CloseHandle(hFile);
+                       CloseHandle(f->hFile);
+                       rc = 1;
+               }
+
+               if (!rc)
+               {
                        ctx->iocp = hFile;
                        ctx->wd = wd;
-
                        wd->iothread = CreateThread(NULL, 0, IoCompletionRoutine, ctx, 0, NULL);
                }
 
@@ -383,7 +395,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 +413,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 +446,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;
index 7b61d16cce5c46db3e692bad238d984423f2f470..ba9319536a04d9ce75d811c65d34fc0e19b79962 100644 (file)
@@ -23,6 +23,7 @@
 #define FIO_HAVE_FALLOCATE
 #define FIO_HAVE_GETTID
 #define FIO_HAVE_CLOCK_MONOTONIC
+#define FIO_HAVE_FADVISE
 #define FIO_USE_GENERIC_RAND
 
 #define FIO_PREFERRED_ENGINE           "windowsaio"
@@ -83,6 +84,7 @@ typedef DWORD_PTR os_cpu_mask_t;
 
 #define SIGCONT        0
 #define SIGUSR1        1
+#define SIGUSR2 2
 
 typedef int sigset_t;
 typedef int siginfo_t;
index 11500e480bf85a1c5b2f45c7defa2d63f81a56bb..f616e876ba79e70c84d862535861d43f848da72d 100755 (executable)
@@ -535,6 +535,11 @@ int getrusage(int who, struct rusage *r_usage)
        return 0;
 }
 
+int posix_fadvise(int fd, off_t offset, off_t len, int advice)
+{
+       return 0;
+}
+
 int posix_madvise(void *addr, size_t len, int advice)
 {
        log_err("%s is not implemented\n", __func__);