4 * IO engine that doesn't do any IO, just stat files and tracks the latency
11 #include <sys/types.h>
15 #include "../optgroup.h"
16 #include "../oslib/statx.h"
19 enum fio_ddir stat_ddir;
22 struct filestat_options {
24 unsigned int stat_type;
28 FIO_FILESTAT_STAT = 1,
29 FIO_FILESTAT_LSTAT = 2,
30 FIO_FILESTAT_STATX = 3,
33 static struct fio_option options[] = {
38 .off1 = offsetof(struct filestat_options, stat_type),
39 .help = "Specify stat system call type to measure lookup/getattr performance",
43 .oval = FIO_FILESTAT_STAT,
44 .help = "Use stat(2)",
47 .oval = FIO_FILESTAT_LSTAT,
48 .help = "Use lstat(2)",
51 .oval = FIO_FILESTAT_STATX,
52 .help = "Use statx(2) if exists",
55 .category = FIO_OPT_C_ENGINE,
56 .group = FIO_OPT_G_FILESTAT,
63 static int stat_file(struct thread_data *td, struct fio_file *f)
65 struct filestat_options *o = td->eo;
66 struct timespec start;
67 int do_lat = !td->o.disable_lat;
70 struct statx statxbuf;
75 dprint(FD_FILE, "fd stat %s\n", f->file_name);
77 if (f->filetype != FIO_TYPE_FILE) {
78 log_err("fio: only files are supported\n");
81 if (!strcmp(f->file_name, "-")) {
82 log_err("fio: can't read/write to stdin/out\n");
87 fio_gettime(&start, NULL);
89 switch (o->stat_type){
90 case FIO_FILESTAT_STAT:
91 ret = stat(f->file_name, &statbuf);
93 case FIO_FILESTAT_LSTAT:
94 ret = lstat(f->file_name, &statbuf);
96 case FIO_FILESTAT_STATX:
98 abspath = realpath(f->file_name, NULL);
100 ret = statx(-1, abspath, 0, STATX_ALL, &statxbuf);
114 char buf[FIO_VERROR_SIZE];
117 snprintf(buf, sizeof(buf), "stat(%s) type=%u", f->file_name,
119 td_verror(td, e, buf);
124 struct fc_data *data = td->io_ops_data;
127 nsec = ntime_since_now(&start);
128 add_clat_sample(td, data->stat_ddir, nsec, 0, 0, 0, false);
134 static enum fio_q_status queue_io(struct thread_data *td, struct io_u fio_unused *io_u)
136 return FIO_Q_COMPLETED;
139 static int init(struct thread_data *td)
141 struct fc_data *data;
143 data = calloc(1, sizeof(*data));
146 data->stat_ddir = DDIR_READ;
147 else if (td_write(td))
148 data->stat_ddir = DDIR_WRITE;
150 td->io_ops_data = data;
154 static void cleanup(struct thread_data *td)
156 struct fc_data *data = td->io_ops_data;
161 static int stat_invalidate(struct thread_data *td, struct fio_file *f)
163 /* do nothing because file not opened */
167 static struct ioengine_ops ioengine = {
169 .version = FIO_IOOPS_VERSION,
173 .invalidate = stat_invalidate,
174 .get_file_size = generic_get_file_size,
175 .open_file = stat_file,
176 .flags = FIO_SYNCIO | FIO_FAKEIO |
177 FIO_NOSTATS | FIO_NOFILEHASH,
179 .option_struct_size = sizeof(struct filestat_options),
182 static void fio_init fio_filestat_register(void)
184 register_ioengine(&ioengine);
187 static void fio_exit fio_filestat_unregister(void)
189 unregister_ioengine(&ioengine);