+ if (td->o.size_percent)
+ total_size = (total_size * td->o.size_percent) / 100;
+
+ if (!td->o.size || td->o.size > total_size)
+ td->o.size = total_size;
+
+ /*
+ * See if we need to extend some files
+ */
+ if (need_extend) {
+ temp_stall_ts = 1;
+ if (!terse_output)
+ log_info("%s: Laying out IO file(s) (%u file(s) /"
+ " %lluMB)\n", td->o.name, need_extend,
+ extend_size >> 20);
+
+ for_each_file(td, f, i) {
+ unsigned long long old_len = -1ULL, extend_len = -1ULL;
+
+ if (!fio_file_extend(f))
+ continue;
+
+ assert(f->filetype == FIO_TYPE_FILE);
+ fio_file_clear_extend(f);
+ if (!td->o.fill_device) {
+ old_len = f->real_file_size;
+ extend_len = f->io_size + f->file_offset -
+ old_len;
+ }
+ f->real_file_size = (f->io_size + f->file_offset);
+ err = extend_file(td, f);
+ if (err)
+ break;
+
+ err = __file_invalidate_cache(td, f, old_len,
+ extend_len);
+ close(f->fd);
+ f->fd = -1;
+ if (err)
+ break;
+ }
+ temp_stall_ts = 0;
+ }
+
+ if (err)
+ return err;
+
+ if (!td->o.zone_size)
+ td->o.zone_size = td->o.size;
+
+ /*
+ * iolog already set the total io size, if we read back
+ * stored entries.
+ */
+ if (!td->o.read_iolog_file)
+ td->total_io_size = td->o.size * td->o.loops;
+ return 0;
+err_offset:
+ log_err("%s: you need to specify valid offset=\n", td->o.name);
+ return 1;
+}
+
+int pre_read_files(struct thread_data *td)
+{
+ struct fio_file *f;
+ unsigned int i;
+
+ dprint(FD_FILE, "pre_read files\n");
+
+ for_each_file(td, f, i) {
+ pre_read_file(td, f);
+ }
+
+ return 1;
+}
+
+int init_random_map(struct thread_data *td)
+{
+ unsigned long long blocks, num_maps;
+ struct fio_file *f;
+ unsigned int i;
+
+ if (td->o.norandommap || !td_random(td))
+ return 0;
+
+ for_each_file(td, f, i) {
+ blocks = (f->real_file_size + td->o.rw_min_bs - 1) /
+ (unsigned long long) td->o.rw_min_bs;
+ num_maps = (blocks + BLOCKS_PER_MAP - 1) /
+ (unsigned long long) BLOCKS_PER_MAP;
+ if (num_maps == (unsigned long) num_maps) {
+ f->file_map = smalloc(num_maps * sizeof(unsigned long));
+ if (f->file_map) {
+ f->num_maps = num_maps;
+ continue;
+ }
+ } else
+ f->file_map = NULL;
+
+ if (!td->o.softrandommap) {
+ log_err("fio: failed allocating random map. If running"
+ " a large number of jobs, try the 'norandommap'"
+ " option or set 'softrandommap'. Or give"
+ " a larger --alloc-size to fio.\n");
+ return 1;
+ }
+
+ log_info("fio: file %s failed allocating random map. Running "
+ "job without.\n", f->file_name);
+ f->num_maps = 0;
+ }
+
+ return 0;