Commit | Line | Data |
---|---|---|
5561e9dd FS |
1 | /* |
2 | * file delete engine | |
3 | * | |
4 | * IO engine that doesn't do any IO, just delete files and track the latency | |
5 | * of the file deletion. | |
6 | */ | |
7 | #include <stdio.h> | |
8 | #include <fcntl.h> | |
9 | #include <errno.h> | |
10 | #include <sys/types.h> | |
11 | #include <unistd.h> | |
12 | #include "../fio.h" | |
13 | ||
14 | struct fc_data { | |
15 | enum fio_ddir stat_ddir; | |
16 | }; | |
17 | ||
18 | static int delete_file(struct thread_data *td, struct fio_file *f) | |
19 | { | |
20 | struct timespec start; | |
21 | int do_lat = !td->o.disable_lat; | |
22 | int ret; | |
23 | ||
24 | dprint(FD_FILE, "fd delete %s\n", f->file_name); | |
25 | ||
26 | if (f->filetype != FIO_TYPE_FILE) { | |
27 | log_err("fio: only files are supported\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 | ||
35 | if (do_lat) | |
36 | fio_gettime(&start, NULL); | |
37 | ||
38 | ret = unlink(f->file_name); | |
39 | ||
40 | if (ret == -1) { | |
41 | char buf[FIO_VERROR_SIZE]; | |
42 | int e = errno; | |
43 | ||
44 | snprintf(buf, sizeof(buf), "delete(%s)", f->file_name); | |
45 | td_verror(td, e, buf); | |
46 | return 1; | |
47 | } | |
48 | ||
49 | if (do_lat) { | |
50 | struct fc_data *data = td->io_ops_data; | |
51 | uint64_t nsec; | |
52 | ||
53 | nsec = ntime_since_now(&start); | |
03ec570f | 54 | add_clat_sample(td, data->stat_ddir, nsec, 0, 0, 0, false); |
5561e9dd FS |
55 | } |
56 | ||
57 | return 0; | |
58 | } | |
59 | ||
60 | ||
61 | static enum fio_q_status queue_io(struct thread_data *td, struct io_u fio_unused *io_u) | |
62 | { | |
63 | return FIO_Q_COMPLETED; | |
64 | } | |
65 | ||
66 | static int init(struct thread_data *td) | |
67 | { | |
68 | struct fc_data *data; | |
69 | ||
70 | data = calloc(1, sizeof(*data)); | |
71 | ||
72 | if (td_read(td)) | |
73 | data->stat_ddir = DDIR_READ; | |
74 | else if (td_write(td)) | |
75 | data->stat_ddir = DDIR_WRITE; | |
76 | ||
77 | td->io_ops_data = data; | |
78 | return 0; | |
79 | } | |
80 | ||
81 | static int delete_invalidate(struct thread_data *td, struct fio_file *f) | |
82 | { | |
83 | /* do nothing because file not opened */ | |
84 | return 0; | |
85 | } | |
86 | ||
87 | static void cleanup(struct thread_data *td) | |
88 | { | |
89 | struct fc_data *data = td->io_ops_data; | |
90 | ||
91 | free(data); | |
92 | } | |
93 | ||
94 | static struct ioengine_ops ioengine = { | |
95 | .name = "filedelete", | |
96 | .version = FIO_IOOPS_VERSION, | |
97 | .init = init, | |
98 | .invalidate = delete_invalidate, | |
99 | .cleanup = cleanup, | |
100 | .queue = queue_io, | |
101 | .get_file_size = generic_get_file_size, | |
102 | .open_file = delete_file, | |
103 | .flags = FIO_SYNCIO | FIO_FAKEIO | | |
104 | FIO_NOSTATS | FIO_NOFILEHASH, | |
105 | }; | |
106 | ||
107 | static void fio_init fio_filedelete_register(void) | |
108 | { | |
109 | register_ioengine(&ioengine); | |
110 | } | |
111 | ||
112 | static void fio_exit fio_filedelete_unregister(void) | |
113 | { | |
114 | unregister_ioengine(&ioengine); | |
115 | } |