Commit | Line | Data |
---|---|---|
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 |
13 | struct fc_data { |
14 | enum fio_ddir stat_ddir; | |
15 | }; | |
16 | ||
1216cc5a JB |
17 | static 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); |
19ee42ac | 52 | add_clat_sample(td, data->stat_ddir, nsec, 0, 0); |
1216cc5a JB |
53 | } |
54 | ||
55 | return 0; | |
56 | } | |
57 | ||
58 | static int queue_io(struct thread_data *td, struct io_u fio_unused *io_u) | |
59 | { | |
60 | return FIO_Q_COMPLETED; | |
61 | } | |
62 | ||
edc5fa12 JA |
63 | /* |
64 | * Ensure that we at least have a block size worth of IO to do for each | |
65 | * file. If the job file has td->o.size < nr_files * block_size, then | |
66 | * fio won't do anything. | |
67 | */ | |
68 | static int get_file_size(struct thread_data *td, struct fio_file *f) | |
69 | { | |
70 | f->real_file_size = td_min_bs(td); | |
71 | return 0; | |
72 | } | |
73 | ||
19ee42ac JA |
74 | static int init(struct thread_data *td) |
75 | { | |
76 | struct fc_data *data; | |
77 | ||
78 | data = calloc(1, sizeof(*data)); | |
79 | ||
80 | if (td_read(td)) | |
81 | data->stat_ddir = DDIR_READ; | |
82 | else if (td_write(td)) | |
83 | data->stat_ddir = DDIR_WRITE; | |
84 | ||
85 | td->io_ops_data = data; | |
86 | return 0; | |
87 | } | |
88 | ||
89 | static void cleanup(struct thread_data *td) | |
90 | { | |
91 | struct fc_data *data = td->io_ops_data; | |
92 | ||
93 | free(data); | |
94 | } | |
95 | ||
1216cc5a JB |
96 | static struct ioengine_ops ioengine = { |
97 | .name = "filecreate", | |
98 | .version = FIO_IOOPS_VERSION, | |
19ee42ac JA |
99 | .init = init, |
100 | .cleanup = cleanup, | |
1216cc5a | 101 | .queue = queue_io, |
edc5fa12 JA |
102 | .get_file_size = get_file_size, |
103 | .open_file = open_file, | |
1216cc5a | 104 | .close_file = generic_close_file, |
132b1ee4 | 105 | .flags = FIO_DISKLESSIO | FIO_SYNCIO | FIO_FAKEIO | |
cb9bf647 | 106 | FIO_NOSTATS | FIO_NOFILEHASH, |
1216cc5a JB |
107 | }; |
108 | ||
109 | static void fio_init fio_filecreate_register(void) | |
110 | { | |
111 | register_ioengine(&ioengine); | |
112 | } | |
113 | ||
114 | static void fio_exit fio_filecreate_unregister(void) | |
115 | { | |
116 | unregister_ioengine(&ioengine); | |
117 | } |