[PATCH] Close files on error
authorJens Axboe <jens.axboe@oracle.com>
Thu, 23 Nov 2006 14:01:19 +0000 (15:01 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Thu, 23 Nov 2006 14:01:19 +0000 (15:01 +0100)
The error path doesn't close already opened files. Also set
O_SYNC regardless of file type.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
filesetup.c

index 4fa04ecd6310adcc88c69c53be3f88759557915b..50434e641b7af1cbc9617c50c75e27e1a2cde0f1 100644 (file)
@@ -317,18 +317,18 @@ static int setup_file(struct thread_data *td, struct fio_file *f)
 
        if (td->odirect)
                flags |= OS_O_DIRECT;
+       if (td->sync_io)
+               flags |= O_SYNC;
 
        if (td_write(td) || td_rw(td)) {
+               flags |= O_RDWR;
+
                if (td->filetype == FIO_TYPE_FILE) {
                        if (!td->overwrite)
                                flags |= O_TRUNC;
 
                        flags |= O_CREAT;
                }
-               if (td->sync_io)
-                       flags |= O_SYNC;
-
-               flags |= O_RDWR;
 
                f->fd = open(f->file_name, flags, 0600);
        } else {
@@ -362,6 +362,16 @@ int open_files(struct thread_data *td)
                        break;
        }
 
+       if (!err)
+               return 0;
+
+       for_each_file(td, f, i) {
+               if (f->fd != -1) {
+                       close(f->fd);
+                       f->fd = -1;
+               }
+       }
+
        return err;
 }