goto err;
}
+#ifdef FIO_HAVE_FALLOCATE
dprint(FD_FILE, "fallocate file %s, size %llu\n", f->file_name,
f->real_file_size);
r = posix_fallocate(f->fd, 0, f->real_file_size);
if (r < 0)
- td_verror(td, -r, "posix_fallocate");
+ log_err("fio: posix_fallocate fails: %s\n", strerror(-r));
+#endif
b = malloc(td->o.max_bs[DDIR_WRITE]);
memset(b, 0, td->o.max_bs[DDIR_WRITE]);
static unsigned long long get_rand_file_size(struct thread_data *td)
{
- unsigned long long ret, size_d;
+ unsigned long long ret, sized;
long r;
r = os_random_long(&td->file_size_state);
- size_d = td->o.file_size_high - td->o.file_size_low;
- ret = (unsigned long long) ((double) size_d * (r / (RAND_MAX + 1.0)));
+ sized = td->o.file_size_high - td->o.file_size_low;
+ ret = (unsigned long long) ((double) sized * (r / (OS_RAND_MAX + 1.0)));
ret += td->o.file_size_low;
ret -= (ret % td->o.rw_min_bs);
return ret;
{
struct stat st;
- if (fstat(f->fd, &st) == -1) {
+ if (stat(f->file_name, &st) == -1) {
td_verror(td, errno, "fstat");
return 1;
}
unsigned long long bytes;
int r;
+ if (td->io_ops->open_file(td, f)) {
+ log_err("fio: failed opening blockdev %s for size check\n",
+ f->file_name);
+ return 1;
+ }
+
r = blockdev_size(f->fd, &bytes);
if (r) {
td_verror(td, r, "blockdev_size");
- return 1;
+ goto err;
+ }
+
+ if (!bytes) {
+ log_err("%s: zero sized block device?\n", f->file_name);
+ goto err;
}
f->real_file_size = bytes;
return 0;
+err:
+ td->io_ops->close_file(td, f);
+ return 1;
}
static int get_file_size(struct thread_data *td, struct fio_file *f)
flags |= O_SYNC;
if (f->filetype != FIO_TYPE_FILE)
flags |= FIO_O_NOATIME;
+ if (td->o.create_on_open)
+ flags |= O_CREAT;
open_again:
if (td_write(td)) {
td_verror(td, __e, buf);
}
- if (get_file_size(td, f))
- goto err;
-
if (!from_hash && f->fd != -1) {
if (add_file_hash(f)) {
int ret;
}
return 0;
-err:
- close(f->fd);
- return 1;
}
-int open_files(struct thread_data *td)
+int generic_get_file_size(struct thread_data *td, struct fio_file *f)
{
- struct fio_file *f;
- unsigned int i;
- int err = 0;
-
- dprint(FD_FILE, "open files\n");
-
- for_each_file(td, f, i) {
- err = td_io_open_file(td, f);
- if (err) {
- if (td->error == EMFILE) {
- log_err("fio: limited open files to: %d\n",
- td->nr_open_files);
- td->o.open_files = td->nr_open_files;
- err = 0;
- clear_error(td);
- }
- break;
- }
-
- if (td->o.open_files == td->nr_open_files)
- break;
- }
-
- if (!err)
- return 0;
-
- for_each_file(td, f, i)
- td_io_close_file(td, f);
-
- return err;
+ return get_file_size(td, f);
}
/*
dprint(FD_FILE, "get file size for %p/%d/%p\n", f, i,
f->file_name);
- if (td->io_ops->open_file(td, f)) {
+ if (td_io_get_file_size(td, f)) {
if (td->error != ENOENT) {
log_err("%s\n", td->verror);
err = 1;
}
clear_error(td);
- } else {
- if (td->io_ops->close_file)
- td->io_ops->close_file(td, f);
}
if (f->real_file_size == -1ULL && td->o.size)
if (f->filetype == FIO_TYPE_FILE &&
(f->io_size + f->file_offset) > f->real_file_size &&
!(td->io_ops->flags & FIO_DISKLESSIO)) {
- need_extend++;
- extend_size += (f->io_size + f->file_offset);
+ if (!td->o.create_on_open) {
+ need_extend++;
+ extend_size += (f->io_size + f->file_offset);
+ } else
+ f->real_file_size = f->io_size + f->file_offset;
f->flags |= FIO_FILE_EXTEND;
}
}
*/
if (need_extend) {
temp_stall_ts = 1;
- log_info("%s: Laying out IO file(s) (%u file(s) / %LuMiB)\n",
- td->o.name, need_extend, extend_size >> 20);
+ if (!terse_output)
+ log_info("%s: Laying out IO file(s) (%u file(s) /"
+ " %LuMiB)\n", td->o.name, need_extend,
+ extend_size >> 20);
for_each_file(td, f, i) {
unsigned long long old_len, extend_len;
(unsigned long long) td->o.rw_min_bs;
num_maps = (blocks + BLOCKS_PER_MAP - 1) /
(unsigned long long) BLOCKS_PER_MAP;
- f->file_map = smalloc(num_maps * sizeof(long));
+ f->file_map = smalloc(num_maps * sizeof(int));
if (f->file_map) {
f->num_maps = num_maps;
continue;
}
td_io_close_file(td, f);
+ remove_file_hash(f);
sfree(f->file_name);
f->file_name = NULL;
dprint(FD_FILE, "add file %s\n", fname);
f = smalloc(sizeof(*f));
+ if (!f) {
+ log_err("fio: smalloc OOM\n");
+ assert(0);
+ }
+
f->fd = -1;
- dprint(FD_FILE, "resize file array to %d files\n", cur_files + 1);
+ if (td->files_size <= td->files_index) {
+ int new_size = td->o.nr_files + 1;
+
+ dprint(FD_FILE, "resize file array to %d files\n", new_size);
- td->files = realloc(td->files, (cur_files + 1) * sizeof(f));
+ td->files = realloc(td->files, new_size * sizeof(f));
+ td->files_size = new_size;
+ }
td->files[cur_files] = f;
/*
sprintf(file_name + len, "%s", fname);
f->file_name = smalloc_strdup(file_name);
-
+ if (!f->file_name) {
+ log_err("fio: smalloc OOM\n");
+ assert(0);
+ }
+
get_file_type(f);
switch (td->o.file_lock_mode) {
struct fio_file *__f;
__f = smalloc(sizeof(*__f));
-
- if (f->file_name)
+ if (!__f) {
+ log_err("fio: smalloc OOM\n");
+ assert(0);
+ }
+
+ if (f->file_name) {
__f->file_name = smalloc_strdup(f->file_name);
+ if (!__f->file_name) {
+ log_err("fio: smalloc OOM\n");
+ assert(0);
+ }
+
+ __f->filetype = f->filetype;
+ }
td->files[i] = __f;
}