+err:
+ close(f->fd);
+ return 1;
+}
+
+int reopen_file(struct thread_data *td, struct fio_file *f)
+{
+ f->last_free_lookup = 0;
+ f->last_completed_pos = 0;
+ f->last_pos = 0;
+
+ if (f->file_map)
+ memset(f->file_map, 0, f->num_maps * sizeof(long));
+
+ return td_io_open_file(td, f);
+}
+
+int open_files(struct thread_data *td)
+{
+ struct fio_file *f;
+ int i, err = 0;
+
+ for_each_file(td, f, i) {
+ err = td_io_open_file(td, f);
+ if (err)
+ break;
+
+ if (td->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;