X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=filesetup.c;h=8f515923bcf9b25c725c9d9a3e94ed2ecb1711a3;hp=1350857ffb04d9f4ed1274298675f9a94adf44a8;hb=009b1be41b32bf7e32b441c6a22e3ae628ec9b89;hpb=1294c3ec7a02d20a98b105c1c41b23358afc67e4 diff --git a/filesetup.c b/filesetup.c index 1350857f..8f515923 100644 --- a/filesetup.c +++ b/filesetup.c @@ -13,6 +13,10 @@ #include "filehash.h" #include "os/os.h" +#ifdef FIO_HAVE_LINUX_FALLOCATE +#include +#endif + static int root_warn; static inline void clear_error(struct thread_data *td) @@ -67,17 +71,41 @@ static int extend_file(struct thread_data *td, struct fio_file *f) } #ifdef FIO_HAVE_FALLOCATE - if (td->o.fallocate && !td->o.fill_device) { - dprint(FD_FILE, "fallocate file %s size %llu\n", f->file_name, - f->real_file_size); - - r = posix_fallocate(f->fd, 0, f->real_file_size); - if (r > 0) { - log_err("fio: posix_fallocate fails: %s\n", - strerror(r)); + if (!td->o.fill_device) { + switch (td->o.fallocate_mode) { + case FIO_FALLOCATE_NONE: + break; + case FIO_FALLOCATE_POSIX: + dprint(FD_FILE, "posix_fallocate file %s size %llu\n", + f->file_name, f->real_file_size); + + r = posix_fallocate(f->fd, 0, f->real_file_size); + if (r > 0) { + log_err("fio: posix_fallocate fails: %s\n", + strerror(r)); + } + break; +#ifdef FIO_HAVE_LINUX_FALLOCATE + case FIO_FALLOCATE_KEEP_SIZE: + dprint(FD_FILE, + "fallocate(FALLOC_FL_KEEP_SIZE) " + "file %s size %llu\n", + f->file_name, f->real_file_size); + + r = fallocate(f->fd, FALLOC_FL_KEEP_SIZE, 0, + f->real_file_size); + if (r != 0) { + td_verror(td, errno, "fallocate"); + } + break; +#endif /* FIO_HAVE_LINUX_FALLOCATE */ + default: + log_err("fio: unknown fallocate mode: %d\n", + td->o.fallocate_mode); + assert(0); } } -#endif +#endif /* FIO_HAVE_FALLOCATE */ if (!new_layout) goto done; @@ -252,7 +280,6 @@ static int bdev_size(struct thread_data *td, struct fio_file *f) r = blockdev_size(f, &bytes); if (r) { td_verror(td, r, "blockdev_size"); - printf("fd is %d\n", f->fd); goto err; } @@ -504,7 +531,7 @@ open_again: if (!from_hash && f->fd != -1) { if (add_file_hash(f)) { - int ret; + int fio_unused ret; /* * OK to ignore, we haven't done anything with it @@ -732,6 +759,9 @@ int setup_files(struct thread_data *td) } } + 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;