#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;
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)
return 1;
}
is_std = 1;
+
+ /*
+ * move output logging to stderr, if we are writing to stdout
+ */
+ if (td_write(td))
+ f_out = stderr;
}
if (td->o.odirect)
if (td->o.sync_io)
flags |= O_SYNC;
- if (td_write(td) || td_rw(td)) {
+ if (td_write(td)) {
flags |= O_RDWR;
if (f->filetype == FIO_TYPE_FILE)
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);
}
}
-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];
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++;
}
if (--f->references)
return;
- if (should_fsync(td) && td->o.fsync_on_close &&
- (f->filetype == FIO_TYPE_FILE || f->filetype == FIO_TYPE_BD))
+ if (should_fsync(td) && td->o.fsync_on_close)
fsync(f->fd);
if (td->io_ops->close_file)
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;
+}