+ 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;
+ log_info("%s: Laying out IO file(s) (%u files / %LuMiB)\n",
+ td->o.name, need_extend, extend_size >> 20);
+
+ for_each_file(td, f, i) {
+ if (!(f->flags & FIO_FILE_EXTEND))
+ continue;
+
+ assert(f->filetype == FIO_TYPE_FILE);
+ f->flags &= ~FIO_FILE_EXTEND;
+ f->real_file_size = (f->io_size + f->file_offset);
+ err = extend_file(td, f);
+ if (err)
+ break;
+ }
+ temp_stall_ts = 0;
+ }
+
+ if (err)
+ return err;
+
+ if (!td->o.zone_size)
+ td->o.zone_size = td->o.size;
+
+ 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 init_random_map(struct thread_data *td)
+{
+ int num_maps, blocks;
+ struct fio_file *f;
+ unsigned int i;
+
+ if (td->o.norandommap)
+ return 0;
+
+ for_each_file(td, f, i) {
+ blocks = (f->real_file_size + td->o.rw_min_bs - 1) / td->o.rw_min_bs;
+ num_maps = (blocks + BLOCKS_PER_MAP-1)/ BLOCKS_PER_MAP;
+ f->file_map = malloc(num_maps * sizeof(long));
+ if (!f->file_map) {
+ log_err("fio: failed allocating random map. If running a large number of jobs, try the 'norandommap' option\n");
+ return 1;
+ }
+ f->num_maps = num_maps;
+ memset(f->file_map, 0, num_maps * sizeof(long));
+ }
+
+ return 0;