X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=filesetup.c;h=a2427a1a80bb0bea52aeee2cab761faac09a5cef;hp=1a187ff2648d35c933740852751cd147c2ec0a36;hb=5de1d4ba1e6ae82bb4ad559463801cb6b7096ac3;hpb=e0b3258bde6f39ab3a9d178b56526b65e0e32a8d diff --git a/filesetup.c b/filesetup.c index 1a187ff2..a2427a1a 100644 --- a/filesetup.c +++ b/filesetup.c @@ -5,8 +5,6 @@ #include #include #include -#include -#include #include "fio.h" #include "smalloc.h" @@ -15,6 +13,7 @@ #include "os/os.h" #include "hash.h" #include "lib/axmap.h" +#include "rwlock.h" #ifdef CONFIG_LINUX_FALLOCATE #include @@ -491,7 +490,6 @@ static int __file_invalidate_cache(struct thread_data *td, struct fio_file *f, } else if (td_ioengine_flagged(td, FIO_DISKLESSIO)) { dprint(FD_IO, "invalidate not supported by ioengine %s\n", td->io_ops->name); - ret = 0; } else if (f->filetype == FIO_TYPE_FILE) { dprint(FD_IO, "declare unneeded cache %s: %llu/%llu\n", f->file_name, off, len); @@ -518,14 +516,12 @@ static int __file_invalidate_cache(struct thread_data *td, struct fio_file *f, log_err("fio: only root may flush block " "devices. Cache flush bypassed!\n"); } - ret = 0; } if (ret < 0) errval = errno; } else if (f->filetype == FIO_TYPE_CHAR || f->filetype == FIO_TYPE_PIPE) { dprint(FD_IO, "invalidate not supported %s\n", f->file_name); - ret = 0; } /* @@ -678,7 +674,8 @@ open_again: from_hash = file_lookup_open(f, flags); } else if (td_trim(td)) { assert(!td_rw(td)); /* should have matched above */ - flags |= O_RDWR; + if (!read_only) + flags |= O_RDWR; from_hash = file_lookup_open(f, flags); } @@ -1609,8 +1606,9 @@ int add_file(struct thread_data *td, const char *fname, int numjob, int inc) f->file_name = strdup(file_name); else f->file_name = smalloc_strdup(file_name); - if (!f->file_name) - assert(0); + + /* can't handle smalloc failure from here */ + assert(f->file_name); get_file_type(f); @@ -1621,7 +1619,7 @@ int add_file(struct thread_data *td, const char *fname, int numjob, int inc) f->rwlock = fio_rwlock_init(); break; case FILE_LOCK_EXCLUSIVE: - f->lock = fio_mutex_init(FIO_MUTEX_UNLOCKED); + f->lock = fio_sem_init(FIO_SEM_UNLOCKED); break; default: log_err("fio: unknown lock mode: %d\n", td->o.file_lock_mode); @@ -1706,7 +1704,7 @@ void lock_file(struct thread_data *td, struct fio_file *f, enum fio_ddir ddir) else fio_rwlock_write(f->rwlock); } else if (td->o.file_lock_mode == FILE_LOCK_EXCLUSIVE) - fio_mutex_down(f->lock); + fio_sem_down(f->lock); td->file_locks[f->fileno] = td->o.file_lock_mode; } @@ -1719,7 +1717,7 @@ void unlock_file(struct thread_data *td, struct fio_file *f) if (td->o.file_lock_mode == FILE_LOCK_READWRITE) fio_rwlock_unlock(f->rwlock); else if (td->o.file_lock_mode == FILE_LOCK_EXCLUSIVE) - fio_mutex_up(f->lock); + fio_sem_up(f->lock); td->file_locks[f->fileno] = FILE_LOCK_NONE; } @@ -1815,9 +1813,9 @@ void dup_files(struct thread_data *td, struct thread_data *org) __f->file_name = strdup(f->file_name); else __f->file_name = smalloc_strdup(f->file_name); - if (!__f->file_name) - assert(0); + /* can't handle smalloc failure from here */ + assert(__f->file_name); __f->filetype = f->filetype; }