filesetup: limit rand map to the actual IO size, if needed
[fio.git] / filesetup.c
index 41809093ffd92b8eac8f5b2e5e89f16facfab12a..478bda8cb0331017b55574d8df67c09cd1151bed 100644 (file)
@@ -709,7 +709,7 @@ static unsigned long long get_fs_free_counts(struct thread_data *td)
        return ret;
 }
 
-unsigned long long get_start_offset(struct thread_data *td)
+uint64_t get_start_offset(struct thread_data *td)
 {
        return td->o.start_offset +
                (td->thread_number - 1) * td->o.offset_increment;
@@ -956,7 +956,9 @@ int init_random_map(struct thread_data *td)
                return 0;
 
        for_each_file(td, f, i) {
-               blocks = (f->real_file_size + td->o.rw_min_bs - 1) /
+               uint64_t file_size = min(f->real_file_size, f->io_size);
+
+               blocks = (file_size + td->o.rw_min_bs - 1) /
                                (unsigned long long) td->o.rw_min_bs;
                if (td->o.random_generator == FIO_RAND_GEN_LFSR) {
                        unsigned long seed;
@@ -1074,11 +1076,15 @@ int add_file(struct thread_data *td, const char *fname)
        fio_file_reset(f);
 
        if (td->files_size <= td->files_index) {
-               int new_size = td->o.nr_files + 1;
+               unsigned 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, new_size * sizeof(f));
+               if (td->files == NULL) {
+                       log_err("fio: realloc OOM\n");
+                       assert(0);
+               }
                td->files_size = new_size;
        }
        td->files[cur_files] = f;