-static int create_files(struct thread_data *td)
-{
- struct fio_file *f;
- int err, need_create, can_extend;
- unsigned long long total_file_size, local_file_size, create_size;
- unsigned int i, new_files;
-
- new_files = 0;
- total_file_size = td->total_file_size;
- for_each_file(td, f, i) {
- unsigned long long s;
-
- f->file_offset = td->start_offset;
-
- if (f->filetype != FIO_TYPE_FILE)
- continue;
-
- if (f->flags & FIO_FILE_EXISTS) {
- s = f->file_size;
- if (s > total_file_size)
- s = total_file_size;
-
- total_file_size -= s;
- } else
- new_files++;
- }
-
- /*
- * unless specifically asked for overwrite, let normal io extend it
- */
- can_extend = !td->overwrite && !(td->io_ops->flags & FIO_NOEXTEND);
- if (can_extend)
- return 0;
-
- local_file_size = total_file_size;
- if (!local_file_size)
- local_file_size = -1;
-
- total_file_size = 0;
- need_create = 0;
- create_size = 0;
- for_each_file(td, f, i) {
- int file_there;
-
- if (f->filetype != FIO_TYPE_FILE)
- continue;
- if (f->flags & FIO_FILE_EXISTS) {
- total_file_size += f->file_size;
- continue;
- }
-
- if (!td->file_size_low)
- f->file_size = total_file_size / new_files;
- else {
- /*
- * If we don't have enough space left for a file
- * of the minimum size, bail.
- */
- if (local_file_size < td->file_size_low) {
- log_info("fio: limited to %d files\n", i);
- new_files -= (td->nr_files - i);
- td->nr_files = i;
- break;
- }
-
- f->file_size = set_rand_file_size(td, local_file_size);
- local_file_size -= f->file_size;
- }
-
- total_file_size += f->file_size;
- create_size += f->file_size;
- file_there = !file_ok(td, f);
-
- if (file_there && td_write(td) && !td->overwrite) {
- unlink(f->file_name);
- file_there = 0;
- }
-
- need_create += !file_there;
- }
-
- if (!need_create)
- return 0;
-
- if (!td->total_file_size && !total_file_size) {
- log_err("Need size for create\n");
- td_verror(td, EINVAL, "file_size");
- return 1;
- }
-
- temp_stall_ts = 1;
- log_info("%s: Laying out IO file(s) (%u files / %LuMiB)\n",
- td->name, new_files, create_size >> 20);
-
- err = 0;
- for_each_file(td, f, i) {
- /*
- * Only unlink files that we created.
- */
- f->flags &= ~FIO_FILE_UNLINK;
- if (file_ok(td, f)) {
- if (td->unlink)
- f->flags |= FIO_FILE_UNLINK;
-
- err = create_file(td, f);
- if (err)
- break;
- }
- }
-
- temp_stall_ts = 0;
- return err;
-}
-