Split mutex.c and .h each into three files
[fio.git] / engines / filecreate.c
CommitLineData
1216cc5a
JB
1/*
2 * filecreate engine
3 *
4 * IO engine that doesn't do any IO, just creates files and tracks the latency
5 * of the file creation.
6 */
7#include <stdio.h>
8#include <unistd.h>
9#include <fcntl.h>
10#include <errno.h>
11
12#include "../fio.h"
13#include "../filehash.h"
14
19ee42ac
JA
15struct fc_data {
16 enum fio_ddir stat_ddir;
17};
18
1216cc5a
JB
19static int open_file(struct thread_data *td, struct fio_file *f)
20{
0410e783 21 struct timespec start;
1216cc5a
JB
22 int do_lat = !td->o.disable_lat;
23
24 dprint(FD_FILE, "fd open %s\n", f->file_name);
25
26 if (f->filetype != FIO_TYPE_FILE) {
27 log_err("fio: only files are supported fallocate \n");
28 return 1;
29 }
30 if (!strcmp(f->file_name, "-")) {
31 log_err("fio: can't read/write to stdin/out\n");
32 return 1;
33 }
34
1216cc5a
JB
35 if (do_lat)
36 fio_gettime(&start, NULL);
1216cc5a 37
52582166 38 f->fd = open(f->file_name, O_CREAT|O_RDWR, 0600);
1216cc5a
JB
39
40 if (f->fd == -1) {
41 char buf[FIO_VERROR_SIZE];
42 int e = errno;
43
44 snprintf(buf, sizeof(buf), "open(%s)", f->file_name);
45 td_verror(td, e, buf);
52582166 46 return 1;
1216cc5a
JB
47 }
48
52582166 49 if (do_lat) {
19ee42ac 50 struct fc_data *data = td->io_ops_data;
0410e783 51 uint64_t nsec;
1216cc5a 52
0410e783 53 nsec = ntime_since_now(&start);
19ee42ac 54 add_clat_sample(td, data->stat_ddir, nsec, 0, 0);
1216cc5a
JB
55 }
56
57 return 0;
58}
59
60static int queue_io(struct thread_data *td, struct io_u fio_unused *io_u)
61{
62 return FIO_Q_COMPLETED;
63}
64
edc5fa12
JA
65/*
66 * Ensure that we at least have a block size worth of IO to do for each
67 * file. If the job file has td->o.size < nr_files * block_size, then
68 * fio won't do anything.
69 */
70static int get_file_size(struct thread_data *td, struct fio_file *f)
71{
72 f->real_file_size = td_min_bs(td);
73 return 0;
74}
75
19ee42ac
JA
76static int init(struct thread_data *td)
77{
78 struct fc_data *data;
79
80 data = calloc(1, sizeof(*data));
81
82 if (td_read(td))
83 data->stat_ddir = DDIR_READ;
84 else if (td_write(td))
85 data->stat_ddir = DDIR_WRITE;
86
87 td->io_ops_data = data;
88 return 0;
89}
90
91static void cleanup(struct thread_data *td)
92{
93 struct fc_data *data = td->io_ops_data;
94
95 free(data);
96}
97
1216cc5a
JB
98static struct ioengine_ops ioengine = {
99 .name = "filecreate",
100 .version = FIO_IOOPS_VERSION,
19ee42ac
JA
101 .init = init,
102 .cleanup = cleanup,
1216cc5a 103 .queue = queue_io,
edc5fa12
JA
104 .get_file_size = get_file_size,
105 .open_file = open_file,
1216cc5a 106 .close_file = generic_close_file,
132b1ee4 107 .flags = FIO_DISKLESSIO | FIO_SYNCIO | FIO_FAKEIO |
cb9bf647 108 FIO_NOSTATS | FIO_NOFILEHASH,
1216cc5a
JB
109};
110
111static void fio_init fio_filecreate_register(void)
112{
113 register_ioengine(&ioengine);
114}
115
116static void fio_exit fio_filecreate_unregister(void)
117{
118 unregister_ioengine(&ioengine);
119}