4 * IO engine that doesn't do any IO, just delete files and track the latency
5 * of the file deletion.
10 #include <sys/types.h>
15 enum fio_ddir stat_ddir;
18 static int delete_file(struct thread_data *td, struct fio_file *f)
20 struct timespec start;
21 int do_lat = !td->o.disable_lat;
24 dprint(FD_FILE, "fd delete %s\n", f->file_name);
26 if (f->filetype != FIO_TYPE_FILE) {
27 log_err("fio: only files are supported\n");
30 if (!strcmp(f->file_name, "-")) {
31 log_err("fio: can't read/write to stdin/out\n");
36 fio_gettime(&start, NULL);
38 ret = unlink(f->file_name);
41 char buf[FIO_VERROR_SIZE];
44 snprintf(buf, sizeof(buf), "delete(%s)", f->file_name);
45 td_verror(td, e, buf);
50 struct fc_data *data = td->io_ops_data;
53 nsec = ntime_since_now(&start);
54 add_clat_sample(td, data->stat_ddir, nsec, 0, 0, 0, false);
61 static enum fio_q_status queue_io(struct thread_data *td, struct io_u fio_unused *io_u)
63 return FIO_Q_COMPLETED;
66 static int init(struct thread_data *td)
70 data = calloc(1, sizeof(*data));
73 data->stat_ddir = DDIR_READ;
74 else if (td_write(td))
75 data->stat_ddir = DDIR_WRITE;
77 td->io_ops_data = data;
81 static int delete_invalidate(struct thread_data *td, struct fio_file *f)
83 /* do nothing because file not opened */
87 static void cleanup(struct thread_data *td)
89 struct fc_data *data = td->io_ops_data;
94 static struct ioengine_ops ioengine = {
96 .version = FIO_IOOPS_VERSION,
98 .invalidate = delete_invalidate,
101 .get_file_size = generic_get_file_size,
102 .open_file = delete_file,
103 .flags = FIO_SYNCIO | FIO_FAKEIO |
104 FIO_NOSTATS | FIO_NOFILEHASH,
107 static void fio_init fio_filedelete_register(void)
109 register_ioengine(&ioengine);
112 static void fio_exit fio_filedelete_unregister(void)
114 unregister_ioengine(&ioengine);