Fix crash with file locking and dup'ed files
[fio.git] / filesetup.c
index 7d3a0613b8296eb5a5f2d08c268a261fd8b1561c..d1702e29c75bf1b1f73dd0d2dc3ade1ac35f9e12 100644 (file)
@@ -121,8 +121,10 @@ static int extend_file(struct thread_data *td, struct fio_file *f)
                dprint(FD_FILE, "truncate file %s, size %llu\n", f->file_name,
                                        (unsigned long long) f->real_file_size);
                if (ftruncate(f->fd, f->real_file_size) == -1) {
-                       td_verror(td, errno, "ftruncate");
-                       goto err;
+                       if (errno != EFBIG) {
+                               td_verror(td, errno, "ftruncate");
+                               goto err;
+                       }
                }
        }
 
@@ -444,6 +446,7 @@ int generic_close_file(struct thread_data fio_unused *td, struct fio_file *f)
                f->shadow_fd = -1;
        }
 
+       f->engine_data = 0;
        return ret;
 }
 
@@ -518,6 +521,13 @@ int generic_open_file(struct thread_data *td, struct fio_file *f)
                goto skip_flags;
        if (td->o.odirect)
                flags |= OS_O_DIRECT;
+       if (td->o.oatomic) {
+               if (!FIO_O_ATOMIC) {
+                       td_verror(td, EINVAL, "OS does not support atomic IO");
+                       return 1;
+               }
+               flags |= OS_O_DIRECT | FIO_O_ATOMIC;
+       }
        if (td->o.sync_io)
                flags |= O_SYNC;
        if (td->o.create_on_open)
@@ -583,7 +593,7 @@ open_again:
                         * work-around a "feature" on Linux, where a close of
                         * an fd that has been opened for write will trigger
                         * udev to call blkid to check partitions, fs id, etc.
-                        * That polutes the device cache, which can slow down
+                        * That pollutes the device cache, which can slow down
                         * unbuffered accesses.
                         */
                        if (f->shadow_fd == -1)
@@ -1040,6 +1050,7 @@ void close_and_free_files(struct thread_data *td)
        td->files_index = 0;
        td->files = NULL;
        td->file_locks = NULL;
+       td->o.file_lock_mode = FILE_LOCK_NONE;
        td->o.nr_files = 0;
 }
 
@@ -1232,6 +1243,8 @@ void unlock_file(struct thread_data *td, struct fio_file *f)
 
 void unlock_file_all(struct thread_data *td, struct fio_file *f)
 {
+       if (td->o.file_lock_mode == FILE_LOCK_NONE)
+               return;
        if (td->file_locks[f->fileno] != FILE_LOCK_NONE)
                unlock_file(td, f);
 }
@@ -1330,6 +1343,11 @@ void dup_files(struct thread_data *td, struct thread_data *org)
                        __f->filetype = f->filetype;
                }
 
+               if (td->o.file_lock_mode == FILE_LOCK_EXCLUSIVE)
+                       __f->lock = f->lock;
+               else if (td->o.file_lock_mode == FILE_LOCK_READWRITE)
+                       __f->rwlock = f->rwlock;
+
                td->files[i] = __f;
        }
 }