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