#include "filehash.h"
#include "os/os.h"
+#ifdef FIO_HAVE_LINUX_FALLOCATE
+#include <linux/falloc.h>
+#endif
+
static int root_warn;
static inline void clear_error(struct thread_data *td)
}
#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;
static unsigned long long get_rand_file_size(struct thread_data *td)
{
unsigned long long ret, sized;
- long r;
+ unsigned long r;
if (td->o.use_os_rand) {
r = os_random_long(&td->file_size_state);
r = blockdev_size(f, &bytes);
if (r) {
td_verror(td, r, "blockdev_size");
- printf("fd is %d\n", f->fd);
goto err;
}
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
}
}
+ 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;