filesetup: make trim jobs respect --readonly during file open
[fio.git] / filesetup.c
index b246e0f951e99c6534ad201e960b5ba7262812ad..a2427a1a80bb0bea52aeee2cab761faac09a5cef 100644 (file)
@@ -490,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);
@@ -517,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;
        }
 
        /*
@@ -677,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);
        }