static int pre_read_file(struct thread_data *td, struct fio_file *f)
{
- int r, did_open = 0, old_runstate;
+ int ret = 0, r, did_open = 0, old_runstate;
unsigned long long left;
unsigned int bs;
char *b;
b = malloc(bs);
memset(b, 0, bs);
- lseek(f->fd, f->file_offset, SEEK_SET);
+ if (lseek(f->fd, f->file_offset, SEEK_SET) < 0) {
+ td_verror(td, errno, "lseek");
+ log_err("fio: failed to lseek pre-read file\n");
+ ret = 1;
+ goto error;
+ }
+
left = f->io_size;
while (left && !td->terminate) {
}
}
+error:
td_restore_runstate(td, old_runstate);
if (did_open)
td->io_ops->close_file(td, f);
+
free(b);
- return 0;
+ return ret;
}
static unsigned long long get_rand_file_size(struct thread_data *td)
fio_file_hash_unlock();
}
+static struct fio_file *alloc_new_file(struct thread_data *td)
+{
+ struct fio_file *f;
+
+ f = smalloc(sizeof(*f));
+ if (!f) {
+ log_err("fio: smalloc OOM\n");
+ assert(0);
+ return NULL;
+ }
+
+ f->fd = -1;
+ f->shadow_fd = -1;
+ fio_file_reset(td, f);
+ return f;
+}
+
int add_file(struct thread_data *td, const char *fname, int numjob, int inc)
{
int cur_files = td->files_index;
if (numjob && is_already_allocated(file_name))
return 0;
- f = smalloc(sizeof(*f));
- if (!f) {
- log_err("fio: smalloc OOM\n");
- assert(0);
- }
-
- f->fd = -1;
- f->shadow_fd = -1;
- fio_file_reset(td, f);
+ f = alloc_new_file(td);
if (td->files_size <= td->files_index) {
unsigned int new_size = td->o.nr_files + 1;
for_each_file(org, f, i) {
struct fio_file *__f;
- __f = smalloc(sizeof(*__f));
- if (!__f) {
- log_err("fio: smalloc OOM\n");
- assert(0);
- }
- __f->fd = -1;
- __f->shadow_fd = -1;
- fio_file_reset(td, __f);
+ __f = alloc_new_file(td);
if (f->file_name) {
__f->file_name = smalloc_strdup(f->file_name);