files between threads in a job or several jobs, specify
a filename for each of them to override the default. If
the ioengine used is 'net', the filename is the host and
- port to connect to in the format of =host:port.
+ port to connect to in the format of =host:port. If the
+ ioengine is file based, you can specify a number of files
+ by seperating the names with a ':' colon. So if you wanted
+ a job to open /dev/sda and /dev/sdb as the two working files,
+ you would use filename=/dev/sda:/dev/sdb
rw=str Type of io pattern. Accepted values are:
static int fio_cpuio_setup(struct thread_data fio_unused *td)
{
struct fio_file *f;
- int i;
+ unsigned int i;
td->total_file_size = -1;
td->io_size = td->total_file_size;
unsigned short port;
struct fio_file *f;
char host[64], buf[128];
+ unsigned int i;
char *sep;
- int ret, i;
+ int ret;
if (!td->total_file_size) {
log_err("fio: need size= set\n");
static int fio_null_setup(struct thread_data *td)
{
struct fio_file *f;
- int i;
+ unsigned int i;
if (!td->total_file_size) {
log_err("fio: need size= set\n");
*/
struct fio_file *f = &td->files[0];
struct sgio_data *sd = td->io_ops->data;
- int left = max, ret, events, i, r = 0;
+ int left = max, ret, r = 0;
void *buf = sd->sgbuf;
+ unsigned int i, events;
/*
* Fill in the file descriptors
{
struct fio_file *f = io_u->file;
- if (td->filetype == FIO_TYPE_BD)
+ if (f->filetype == FIO_TYPE_BD)
return fio_sgio_ioctl_doio(td, f, io_u);
return fio_sgio_rw_doio(f, io_u, sync);
struct sgio_data *sd = td->io_ops->data;
unsigned int bs;
- if (td->filetype == FIO_TYPE_BD) {
+ if (f->filetype == FIO_TYPE_BD) {
if (ioctl(f->fd, BLKSSZGET, &bs) < 0) {
td_verror(td, errno, "ioctl");
return 1;
}
- } else if (td->filetype == FIO_TYPE_CHAR) {
+ } else if (f->filetype == FIO_TYPE_CHAR) {
int version, ret;
if (ioctl(f->fd, SG_GET_VERSION_NUM, &version) < 0) {
sd->bs = bs;
- if (td->filetype == FIO_TYPE_BD) {
+ if (f->filetype == FIO_TYPE_BD) {
td->io_ops->getevents = NULL;
td->io_ops->event = NULL;
}
{
struct stat st;
- if (td->filetype != FIO_TYPE_FILE ||
+ if (f->filetype != FIO_TYPE_FILE ||
(td->io_ops->flags & FIO_DISKLESSIO))
return 0;
static int create_files(struct thread_data *td)
{
struct fio_file *f;
- int i, err, need_create, can_extend;
+ int err, need_create, can_extend;
+ unsigned int i;
for_each_file(td, f, i)
f->file_size = td->total_file_size / td->nr_files;
return 0;
need_create = 0;
- if (td->filetype == FIO_TYPE_FILE) {
- for_each_file(td, f, i) {
- int file_there = !file_ok(td, f);
+ for_each_file(td, f, i) {
+ int file_there;
+
+ if (f->filetype != FIO_TYPE_FILE)
+ continue;
- if (file_there && td_write(td) && !td->overwrite) {
- unlink(f->file_name);
- file_there = 0;
- }
+ file_there = !file_ok(td, f);
- need_create += !file_there;
+ if (file_there && td_write(td) && !td->overwrite) {
+ unlink(f->file_name);
+ file_there = 0;
}
+
+ need_create += !file_there;
}
if (!need_create)
{
int ret = 0;
- if (td->filetype == FIO_TYPE_FILE)
+ if (f->filetype == FIO_TYPE_FILE)
ret = file_size(td, f);
- else if (td->filetype == FIO_TYPE_BD)
+ else if (f->filetype == FIO_TYPE_BD)
ret = bdev_size(td, f);
else
f->real_file_size = -1;
*/
if (f->mmap)
ret = madvise(f->mmap, f->file_size, MADV_DONTNEED);
- else if (td->filetype == FIO_TYPE_FILE) {
+ else if (f->filetype == FIO_TYPE_FILE) {
ret = fadvise(f->fd, f->file_offset, f->file_size, POSIX_FADV_DONTNEED);
- } else if (td->filetype == FIO_TYPE_BD) {
+ } else if (f->filetype == FIO_TYPE_BD) {
ret = blockdev_invalidate_cache(f->fd);
- } else if (td->filetype == FIO_TYPE_CHAR)
+ } else if (f->filetype == FIO_TYPE_CHAR)
ret = 0;
if (ret < 0) {
if (td_write(td) || td_rw(td)) {
flags |= O_RDWR;
- if (td->filetype == FIO_TYPE_FILE)
+ if (f->filetype == FIO_TYPE_FILE)
flags |= O_CREAT;
f->fd = open(f->file_name, flags, 0600);
} else {
- if (td->filetype == FIO_TYPE_CHAR)
+ if (f->filetype == FIO_TYPE_CHAR)
flags |= O_RDWR;
else
flags |= O_RDONLY;
int open_files(struct thread_data *td)
{
struct fio_file *f;
- int i, err = 0;
+ unsigned int i;
+ int err = 0;
for_each_file(td, f, i) {
err = td_io_open_file(td, f);
int setup_files(struct thread_data *td)
{
struct fio_file *f;
- int err, i;
+ unsigned int i;
+ int err;
/*
* if ioengine defines a setup() method, it's responsible for
void close_files(struct thread_data *td)
{
struct fio_file *f;
- int i;
+ unsigned int i;
for_each_file(td, f, i) {
if (!td->filename && f->unlink &&
- td->filetype == FIO_TYPE_FILE) {
+ f->filetype == FIO_TYPE_FILE) {
unlink(f->file_name);
- free(f->file_name);
f->file_name = NULL;
}
td->files = NULL;
td->nr_files = 0;
}
+
+static void get_file_type(struct thread_data *td, struct fio_file *f)
+{
+ struct stat sb;
+
+ f->filetype = FIO_TYPE_FILE;
+
+ if (!lstat(td->filename, &sb)) {
+ if (S_ISBLK(sb.st_mode))
+ f->filetype = FIO_TYPE_BD;
+ else if (S_ISCHR(sb.st_mode))
+ f->filetype = FIO_TYPE_CHAR;
+ }
+}
+
+void add_file(struct thread_data *td, const char *fname)
+{
+ int cur_files = td->open_files;
+ struct fio_file *f;
+
+ td->files = realloc(td->files, (cur_files + 1) * sizeof(*f));
+
+ f = &td->files[cur_files];
+ memset(f, 0, sizeof(*f));
+ f->fd = -1;
+ f->file_name = fname;
+
+ get_file_type(td, f);
+
+ td->open_files++;
+ td->nr_uniq_files = td->open_files;
+}
{
struct fio_file *f;
struct io_u *io_u;
- int ret, i, min_events;
+ int ret, min_events;
+ unsigned int i;
/*
* sync io first and invalidate cache, to make sure we really
{
struct timeval s;
unsigned long usec;
- int i, ret = 0;
+ unsigned int i;
+ int ret = 0;
td_set_runstate(td, TD_RUNNING);
static int clear_io_state(struct thread_data *td)
{
struct fio_file *f;
- int i, ret;
+ unsigned int i;
+ int ret;
td->ts.stat_io_bytes[0] = td->ts.stat_io_bytes[1] = 0;
td->this_io_bytes[0] = td->this_io_bytes[1] = 0;
* this structure holds state information for a single file.
*/
struct fio_file {
+ enum fio_filetype filetype;
+
/*
* A file may not be a file descriptor, let the io engine decide
*/
unsigned long file_data;
int fd;
};
- char *file_name;
+ const char *file_name;
void *mmap;
unsigned long long file_size;
unsigned long long real_file_size;
int thread_number;
int groupid;
struct thread_stat ts;
- enum fio_filetype filetype;
struct fio_file *files;
unsigned int nr_files;
unsigned int nr_open_files;
extern int __must_check file_invalidate_cache(struct thread_data *, struct fio_file *);
extern int __must_check generic_open_file(struct thread_data *, struct fio_file *);
extern void generic_close_file(struct thread_data *, struct fio_file *);
+extern void add_file(struct thread_data *, const char *);
/*
* ETA/status stuff
#define for_each_td(td, i) \
for ((i) = 0, (td) = &threads[0]; (i) < (int) thread_number; (i)++, (td)++)
#define for_each_file(td, f, i) \
- for ((i) = 0, (f) = &(td)->files[0]; (i) < (int) (td)->open_files; (i)++, (f)++)
+ for ((i) = 0, (f) = &(td)->files[0]; (i) < (td)->open_files; (i)++, (f)++)
#define fio_assert(td, cond) do { \
if (!(cond)) { \
static int str_exitall_cb(void);
static int str_cpumask_cb(void *, unsigned int *);
static int str_fst_cb(void *, const char *);
+static int str_filename_cb(void *, const char *);
+static int str_directory_cb(void *, const char *);
#define __stringify_1(x) #x
#define __stringify(x) __stringify_1(x)
.name = "directory",
.type = FIO_OPT_STR_STORE,
.off1 = td_var_offset(directory),
+ .cb = str_directory_cb,
.help = "Directory to store files in",
},
{
.name = "filename",
.type = FIO_OPT_STR_STORE,
.off1 = td_var_offset(filename),
- .help = "Force the use of a specific file",
+ .cb = str_filename_cb,
+ .help = "File(s) to use for the workload",
},
{
.name = "rw",
if (td->bs_unaligned && (td->odirect || td->io_ops->flags & FIO_RAWIO))
log_err("fio: bs_unaligned may not work with raw io\n");
- /*
- * O_DIRECT and char doesn't mix, clear that flag if necessary.
- */
- if (td->filetype == FIO_TYPE_CHAR && td->odirect)
- td->odirect = 0;
-
/*
* thinktime_spin must be less than thinktime
*/
{
const char *ddir_str[] = { NULL, "read", "write", "rw", NULL,
"randread", "randwrite", "randrw" };
- struct stat sb;
- int numjobs, i;
+ unsigned int i;
struct fio_file *f;
const char *engine;
- int fn_given;
+ char fname[PATH_MAX];
+ int numjobs;
/*
* the def_thread is just for options, it's not a real job
if (td->odirect)
td->io_ops->flags |= FIO_RAWIO;
- fn_given = (long) td->filename;
- if (!td->filename)
+ if (!td->filename) {
td->filename = strdup(jobname);
- td->filetype = FIO_TYPE_FILE;
- if (!lstat(td->filename, &sb)) {
- if (S_ISBLK(sb.st_mode))
- td->filetype = FIO_TYPE_BD;
- else if (S_ISCHR(sb.st_mode))
- td->filetype = FIO_TYPE_CHAR;
+ for (i = 0; i < td->nr_files; i++) {
+ sprintf(fname, "%s.%d.%d", td->filename, td->thread_number, i);
+ add_file(td, fname);
+ }
}
fixup_options(td);
- if (fn_given)
- td->nr_uniq_files = 1;
- else
- td->nr_uniq_files = td->open_files;
-
- if (td->filetype == FIO_TYPE_FILE) {
- char tmp[PATH_MAX];
- int len = 0;
-
- if (td->directory && td->directory[0] != '\0') {
- if (lstat(td->directory, &sb) < 0) {
- log_err("fio: %s is not a directory\n", td->directory);
- td_verror(td, errno, "lstat");
- return 1;
- }
- if (!S_ISDIR(sb.st_mode)) {
- log_err("fio: %s is not a directory\n", td->directory);
- return 1;
- }
- len = sprintf(tmp, "%s/", td->directory);
- }
-
- td->files = malloc(sizeof(struct fio_file) * td->open_files);
-
- for_each_file(td, f, i) {
- memset(f, 0, sizeof(*f));
- f->fd = -1;
-
- if (fn_given)
- sprintf(tmp + len, "%s", td->filename);
- else
- sprintf(tmp + len, "%s.%d.%d", td->filename, td->thread_number, i);
- f->file_name = strdup(tmp);
+ for_each_file(td, f, i) {
+ if (td->directory && f->filetype == FIO_TYPE_FILE) {
+ sprintf(fname, "%s/%s", td->directory, f->file_name);
+ f->file_name = strdup(fname);
}
- } else {
- td->open_files = td->nr_files = 1;
- td->files = malloc(sizeof(struct fio_file));
- f = &td->files[0];
-
- memset(f, 0, sizeof(*f));
- f->fd = -1;
- f->file_name = strdup(td->filename);
- }
- for_each_file(td, f, i) {
f->file_size = td->total_file_size / td->nr_files;
f->file_offset = td->start_offset;
}
int init_random_state(struct thread_data *td)
{
unsigned long seeds[5];
- int fd, num_maps, blocks, i;
+ int fd, num_maps, blocks;
struct fio_file *f;
+ unsigned int i;
if (td->io_ops->flags & FIO_DISKLESSIO)
return 0;
return 0;
}
+static int str_filename_cb(void *data, const char *input)
+{
+ struct thread_data *td = data;
+ char *fname, *str;
+
+ str = strdup(input);
+ while ((fname = strsep(&str, ":")) != NULL)
+ add_file(td, fname);
+
+ return 0;
+}
+
+static int str_directory_cb(void *data, const char fio_unused *str)
+{
+ struct thread_data *td = data;
+ struct stat sb;
+
+ if (lstat(td->directory, &sb) < 0) {
+ log_err("fio: %s is not a directory\n", td->directory);
+ td_verror(td, errno, "lstat");
+ return 1;
+ }
+ if (!S_ISDIR(sb.st_mode)) {
+ log_err("fio: %s is not a directory\n", td->directory);
+ return 1;
+ }
+
+ return 0;
+}
+
/*
* This is our [ini] type file parser.
*/
}
break;
}
- case FIO_OPT_STR_STORE:
+ case FIO_OPT_STR_STORE: {
+ fio_opt_str_fn *fn = o->cb;
+
cp = td_var(data, o->off1);
*cp = strdup(ptr);
+ if (fn) {
+ ret = fn(data, ptr);
+ if (ret) {
+ free(*cp);
+ *cp = NULL;
+ }
+ }
break;
+ }
case FIO_OPT_RANGE: {
char tmp[128];
char *p1, *p2;
}
if (!o->cb && !o->off1)
fprintf(stderr, "Option %s: neither cb nor offset given\n", o->name);
- if (o->type == FIO_OPT_STR)
+ if (o->type == FIO_OPT_STR || o->type == FIO_OPT_STR_STORE)
continue;
if (o->cb && (o->off1 || o->off2 || o->off3 || o->off4))
fprintf(stderr, "Option %s: both cb and offset given\n", o->name);