Only do the root warning once per thread
[fio.git] / filesetup.c
index faeefaf308fa3e32107375fed6ac68faf65fe594..b742f82501f019befc3fbccdff382151d8a0f5af 100644 (file)
@@ -9,6 +9,8 @@
 
 #include "fio.h"
 
+static int root_warn;
+
 static int extend_file(struct thread_data *td, struct fio_file *f)
 {
        int r, new_layout = 0, unlink_file = 0, flags;
@@ -178,7 +180,10 @@ int file_invalidate_cache(struct thread_data *td, struct fio_file *f)
        else if (f->filetype == FIO_TYPE_BD) {
                ret = blockdev_invalidate_cache(f->fd);
                if (ret < 0 && errno == EACCES && geteuid()) {
-                       log_err("fio: only root may flush block devices. Cache flush bypassed!\n");
+                       if (!root_warn) {
+                               log_err("fio: only root may flush block devices. Cache flush bypassed!\n");
+                               root_warn = 1;
+                       }
                        ret = 0;
                }
        } else if (f->filetype == FIO_TYPE_CHAR || f->filetype == FIO_TYPE_PIPE)
@@ -474,8 +479,7 @@ void close_files(struct thread_data *td)
        unsigned int i;
 
        for_each_file(td, f, i) {
-               if ((f->flags & FIO_FILE_UNLINK) &&
-                   f->filetype == FIO_TYPE_FILE)
+               if (td->o.unlink && f->filetype == FIO_TYPE_FILE)
                        unlink(f->file_name);
 
                td_io_close_file(td, f);
@@ -514,7 +518,7 @@ static void get_file_type(struct fio_file *f)
        }
 }
 
-void add_file(struct thread_data *td, const char *fname)
+int add_file(struct thread_data *td, const char *fname)
 {
        int cur_files = td->files_index;
        char file_name[PATH_MAX];
@@ -544,10 +548,13 @@ void add_file(struct thread_data *td, const char *fname)
        td->files_index++;
        if (f->filetype == FIO_TYPE_FILE)
                td->nr_normal_files++;
+
+       return cur_files;
 }
 
 void get_file(struct fio_file *f)
 {
+       assert(f->flags & FIO_FILE_OPEN);
        f->references++;
 }
 
@@ -645,3 +652,28 @@ void dup_files(struct thread_data *td, struct thread_data *org)
                        f->file_name = strdup(f->file_name);
        }
 }
+
+/*
+ * Returns the index that matches the filename, or -1 if not there
+ */
+int get_fileno(struct thread_data *td, const char *fname)
+{
+       struct fio_file *f;
+       unsigned int i;
+
+       for_each_file(td, f, i)
+               if (!strcmp(f->file_name, fname))
+                       return i;
+
+       return -1;
+}
+
+/*
+ * For log usage, where we add/open/close files automatically
+ */
+void free_release_files(struct thread_data *td)
+{
+       close_files(td);
+       td->files_index = 0;
+       td->nr_normal_files = 0;
+}