blob: 08c365d916fecfa70e4422f6381e39d27e6575c4 [file] [log] [blame]
Jens Axboe53cdc682006-10-18 11:50:58 +02001#include <unistd.h>
2#include <fcntl.h>
3#include <string.h>
4#include <assert.h>
Jens Axboebbf6b542007-03-13 15:28:55 +01005#include <dirent.h>
Jens Axboe53cdc682006-10-18 11:50:58 +02006#include <sys/stat.h>
7#include <sys/mman.h>
Jens Axboebbf6b542007-03-13 15:28:55 +01008#include <sys/types.h>
Jens Axboe53cdc682006-10-18 11:50:58 +02009
10#include "fio.h"
Jens Axboef17c4392008-03-01 18:40:46 +010011#include "smalloc.h"
Jens Axboe4906e0b2008-03-01 18:59:51 +010012#include "filehash.h"
Jens Axboe53cdc682006-10-18 11:50:58 +020013
Jens Axboe7172cfe2007-07-23 14:36:00 +020014static int root_warn;
15
Jens Axboe7bb48f82007-03-27 15:30:28 +020016static int extend_file(struct thread_data *td, struct fio_file *f)
Jens Axboe25205e92006-10-19 20:50:14 +020017{
Jens Axboeea443652007-03-29 14:52:13 +020018 int r, new_layout = 0, unlink_file = 0, flags;
Jens Axboe25205e92006-10-19 20:50:14 +020019 unsigned long long left;
20 unsigned int bs;
21 char *b;
Jens Axboeb2a15192006-10-18 14:10:42 +020022
Jens Axboe4241ea82007-09-12 08:18:36 +020023 if (read_only) {
24 log_err("fio: refusing extend of file due to read-only\n");
25 return 0;
26 }
27
Jens Axboe507a7022007-03-27 15:52:46 +020028 /*
29 * check if we need to lay the file out complete again. fio
30 * does that for operations involving reads, or for writes
31 * where overwrite is set
32 */
33 if (td_read(td) || (td_write(td) && td->o.overwrite))
34 new_layout = 1;
Jens Axboeea443652007-03-29 14:52:13 +020035 if (td_write(td) && !td->o.overwrite)
36 unlink_file = 1;
Jens Axboe507a7022007-03-27 15:52:46 +020037
Jens Axboe6ae1f572008-02-21 10:20:00 +010038 if (unlink_file || new_layout) {
Zhang, Yanmin982016d2008-02-26 15:35:52 +010039 if ((unlink(f->file_name) < 0) && (errno != ENOENT)) {
Jens Axboe7bb48f82007-03-27 15:30:28 +020040 td_verror(td, errno, "unlink");
41 return 1;
42 }
43 }
44
Jens Axboe507a7022007-03-27 15:52:46 +020045 flags = O_WRONLY | O_CREAT;
46 if (new_layout)
47 flags |= O_TRUNC;
48
Jens Axboeee56ad52008-02-01 10:30:20 +010049 dprint(FD_FILE, "open file %s, flags %x\n", f->file_name, flags);
Jens Axboe507a7022007-03-27 15:52:46 +020050 f->fd = open(f->file_name, flags, 0644);
Jens Axboe53cdc682006-10-18 11:50:58 +020051 if (f->fd < 0) {
Jens Axboee1161c32007-02-22 19:36:48 +010052 td_verror(td, errno, "open");
Jens Axboe53cdc682006-10-18 11:50:58 +020053 return 1;
54 }
55
Shawn Lewisfc74ac12008-01-11 09:45:11 +010056 if (!new_layout)
57 goto done;
58
Jens Axboeee56ad52008-02-01 10:30:20 +010059 dprint(FD_FILE, "truncate file %s, size %llu\n", f->file_name,
60 f->real_file_size);
Jens Axboe7bb48f82007-03-27 15:30:28 +020061 if (ftruncate(f->fd, f->real_file_size) == -1) {
Jens Axboee1161c32007-02-22 19:36:48 +010062 td_verror(td, errno, "ftruncate");
Jens Axboe53cdc682006-10-18 11:50:58 +020063 goto err;
64 }
65
Jens Axboeee56ad52008-02-01 10:30:20 +010066 dprint(FD_FILE, "fallocate file %s, size %llu\n", f->file_name,
67 f->real_file_size);
Jens Axboe7bb48f82007-03-27 15:30:28 +020068 if (posix_fallocate(f->fd, 0, f->real_file_size) < 0) {
Jens Axboee1161c32007-02-22 19:36:48 +010069 td_verror(td, errno, "posix_fallocate");
Jens Axboe40f82982006-10-25 11:21:05 +020070 goto err;
71 }
72
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010073 b = malloc(td->o.max_bs[DDIR_WRITE]);
74 memset(b, 0, td->o.max_bs[DDIR_WRITE]);
Jens Axboe53cdc682006-10-18 11:50:58 +020075
Jens Axboe7bb48f82007-03-27 15:30:28 +020076 left = f->real_file_size;
Jens Axboe53cdc682006-10-18 11:50:58 +020077 while (left && !td->terminate) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010078 bs = td->o.max_bs[DDIR_WRITE];
Jens Axboe53cdc682006-10-18 11:50:58 +020079 if (bs > left)
80 bs = left;
81
82 r = write(f->fd, b, bs);
83
84 if (r == (int) bs) {
85 left -= bs;
86 continue;
87 } else {
88 if (r < 0)
Jens Axboee1161c32007-02-22 19:36:48 +010089 td_verror(td, errno, "write");
Jens Axboe53cdc682006-10-18 11:50:58 +020090 else
Jens Axboee1161c32007-02-22 19:36:48 +010091 td_verror(td, EIO, "write");
Jens Axboe53cdc682006-10-18 11:50:58 +020092
93 break;
94 }
95 }
96
97 if (td->terminate)
98 unlink(f->file_name);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010099 else if (td->o.create_fsync)
Jens Axboe53cdc682006-10-18 11:50:58 +0200100 fsync(f->fd);
101
102 free(b);
Jens Axboe507a7022007-03-27 15:52:46 +0200103done:
Jens Axboe53cdc682006-10-18 11:50:58 +0200104 close(f->fd);
105 f->fd = -1;
106 return 0;
107err:
108 close(f->fd);
109 f->fd = -1;
110 return 1;
111}
112
Jens Axboe7bb48f82007-03-27 15:30:28 +0200113static unsigned long long get_rand_file_size(struct thread_data *td)
Jens Axboe9c60ce62007-03-15 09:14:47 +0100114{
Jens Axboe9c60ce62007-03-15 09:14:47 +0100115 unsigned long long ret;
116 long r;
117
Jens Axboe9c60ce62007-03-15 09:14:47 +0100118 r = os_random_long(&td->file_size_state);
ljzhang,Yaxin Hu,Jianchao Tangd11a5312007-07-27 15:54:10 +0200119 ret = td->o.file_size_low + (unsigned long long) ((double) (td->o.file_size_high - td->o.file_size_low) * (r / (RAND_MAX + 1.0)));
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100120 ret -= (ret % td->o.rw_min_bs);
Jens Axboe9c60ce62007-03-15 09:14:47 +0100121 return ret;
122}
123
Jens Axboe53cdc682006-10-18 11:50:58 +0200124static int file_size(struct thread_data *td, struct fio_file *f)
125{
126 struct stat st;
127
Jens Axboe7bb48f82007-03-27 15:30:28 +0200128 if (fstat(f->fd, &st) == -1) {
129 td_verror(td, errno, "fstat");
130 return 1;
131 }
Jens Axboe53cdc682006-10-18 11:50:58 +0200132
Jens Axboe7bb48f82007-03-27 15:30:28 +0200133 f->real_file_size = st.st_size;
Jens Axboe53cdc682006-10-18 11:50:58 +0200134 return 0;
135}
136
137static int bdev_size(struct thread_data *td, struct fio_file *f)
138{
139 unsigned long long bytes;
140 int r;
141
142 r = blockdev_size(f->fd, &bytes);
143 if (r) {
Jens Axboee1161c32007-02-22 19:36:48 +0100144 td_verror(td, r, "blockdev_size");
Jens Axboe53cdc682006-10-18 11:50:58 +0200145 return 1;
146 }
147
148 f->real_file_size = bytes;
Jens Axboe53cdc682006-10-18 11:50:58 +0200149 return 0;
150}
151
152static int get_file_size(struct thread_data *td, struct fio_file *f)
153{
154 int ret = 0;
155
Jens Axboe409b3412007-03-28 09:57:01 +0200156 if (f->flags & FIO_SIZE_KNOWN)
157 return 0;
158
Jens Axboe7bb48f82007-03-27 15:30:28 +0200159 if (f->filetype == FIO_TYPE_FILE)
160 ret = file_size(td, f);
161 else if (f->filetype == FIO_TYPE_BD)
Jens Axboe53cdc682006-10-18 11:50:58 +0200162 ret = bdev_size(td, f);
163 else
164 f->real_file_size = -1;
165
166 if (ret)
167 return ret;
168
169 if (f->file_offset > f->real_file_size) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100170 log_err("%s: offset extends end (%Lu > %Lu)\n", td->o.name, f->file_offset, f->real_file_size);
Jens Axboe53cdc682006-10-18 11:50:58 +0200171 return 1;
172 }
173
Jens Axboe409b3412007-03-28 09:57:01 +0200174 f->flags |= FIO_SIZE_KNOWN;
Jens Axboe53cdc682006-10-18 11:50:58 +0200175 return 0;
176}
177
Jens Axboee5b401d2006-10-18 16:03:40 +0200178int file_invalidate_cache(struct thread_data *td, struct fio_file *f)
179{
180 int ret = 0;
181
Jens Axboeee56ad52008-02-01 10:30:20 +0100182 dprint(FD_IO, "invalidate cache (%d)\n", td->o.odirect);
183
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100184 if (td->o.odirect)
Jens Axboeb5af8292007-03-08 12:43:13 +0100185 return 0;
186
Jens Axboee5b401d2006-10-18 16:03:40 +0200187 /*
188 * FIXME: add blockdev flushing too
189 */
Jens Axboeb5af8292007-03-08 12:43:13 +0100190 if (f->mmap)
Jens Axboe7bb48f82007-03-27 15:30:28 +0200191 ret = madvise(f->mmap, f->io_size, MADV_DONTNEED);
Jens Axboe467d1b62007-03-15 14:11:10 +0100192 else if (f->filetype == FIO_TYPE_FILE)
Jens Axboe7bb48f82007-03-27 15:30:28 +0200193 ret = fadvise(f->fd, f->file_offset, f->io_size, POSIX_FADV_DONTNEED);
Jens Axboe7e0e25c2007-03-27 12:49:56 +0200194 else if (f->filetype == FIO_TYPE_BD) {
Jens Axboeb5af8292007-03-08 12:43:13 +0100195 ret = blockdev_invalidate_cache(f->fd);
Jens Axboe7e0e25c2007-03-27 12:49:56 +0200196 if (ret < 0 && errno == EACCES && geteuid()) {
Jens Axboe7172cfe2007-07-23 14:36:00 +0200197 if (!root_warn) {
198 log_err("fio: only root may flush block devices. Cache flush bypassed!\n");
199 root_warn = 1;
200 }
Jens Axboe7e0e25c2007-03-27 12:49:56 +0200201 ret = 0;
202 }
Jens Axboeb5605e92007-04-16 20:42:33 +0200203 } else if (f->filetype == FIO_TYPE_CHAR || f->filetype == FIO_TYPE_PIPE)
Jens Axboee5b401d2006-10-18 16:03:40 +0200204 ret = 0;
205
206 if (ret < 0) {
Jens Axboee1161c32007-02-22 19:36:48 +0100207 td_verror(td, errno, "invalidate_cache");
Jens Axboee5b401d2006-10-18 16:03:40 +0200208 return 1;
209 }
210
Jens Axboead2da602007-02-26 12:33:27 +0100211 return ret;
Jens Axboee5b401d2006-10-18 16:03:40 +0200212}
213
Jens Axboe6977bcd2008-03-01 15:55:36 +0100214int generic_close_file(struct thread_data fio_unused *td, struct fio_file *f)
Jens Axboe53cdc682006-10-18 11:50:58 +0200215{
Jens Axboe6977bcd2008-03-01 15:55:36 +0100216 int ret = 0;
217
Jens Axboeee56ad52008-02-01 10:30:20 +0100218 dprint(FD_FILE, "fd close %s\n", f->file_name);
Jens Axboe4906e0b2008-03-01 18:59:51 +0100219
220 remove_file_hash(f);
221
Jens Axboe6977bcd2008-03-01 15:55:36 +0100222 if (close(f->fd) < 0)
223 ret = errno;
224
Jens Axboeb5af8292007-03-08 12:43:13 +0100225 f->fd = -1;
Jens Axboe6977bcd2008-03-01 15:55:36 +0100226 return ret;
Jens Axboe53cdc682006-10-18 11:50:58 +0200227}
228
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100229static int file_lookup_open(struct fio_file *f, int flags)
Jens Axboe53cdc682006-10-18 11:50:58 +0200230{
Jens Axboe29c13492008-03-01 19:25:20 +0100231 struct fio_file *__f;
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100232 int from_hash;
233
234 __f = lookup_file_hash(f->file_name);
235 if (__f) {
Jens Axboe9efef3c2008-03-06 10:26:25 +0100236 dprint(FD_FILE, "found file in hash %s\n", f->file_name);
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100237 /*
238 * racy, need the __f->lock locked
239 */
240 f->lock = __f->lock;
241 f->lock_owner = __f->lock_owner;
242 f->lock_batch = __f->lock_batch;
243 f->lock_ddir = __f->lock_ddir;
244 f->fd = dup(__f->fd);
245 f->references++;
246 from_hash = 1;
247 } else {
Jens Axboe9efef3c2008-03-06 10:26:25 +0100248 dprint(FD_FILE, "file not found in hash %s\n", f->file_name);
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100249 f->fd = open(f->file_name, flags, 0600);
250 from_hash = 0;
251 }
252
253 return from_hash;
254}
255
256int generic_open_file(struct thread_data *td, struct fio_file *f)
257{
Jens Axboe66159822007-04-16 21:54:24 +0200258 int is_std = 0;
Jens Axboe53cdc682006-10-18 11:50:58 +0200259 int flags = 0;
Jens Axboe29c13492008-03-01 19:25:20 +0100260 int from_hash = 0;
Jens Axboe53cdc682006-10-18 11:50:58 +0200261
Jens Axboeee56ad52008-02-01 10:30:20 +0100262 dprint(FD_FILE, "fd open %s\n", f->file_name);
263
Jens Axboe66159822007-04-16 21:54:24 +0200264 if (!strcmp(f->file_name, "-")) {
265 if (td_rw(td)) {
266 log_err("fio: can't read/write to stdin/out\n");
267 return 1;
268 }
269 is_std = 1;
Jens Axboece98fa62007-04-17 13:27:32 +0200270
271 /*
272 * move output logging to stderr, if we are writing to stdout
273 */
274 if (td_write(td))
275 f_out = stderr;
Jens Axboe66159822007-04-16 21:54:24 +0200276 }
277
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100278 if (td->o.odirect)
Jens Axboe2fd233b2007-03-02 08:44:25 +0100279 flags |= OS_O_DIRECT;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100280 if (td->o.sync_io)
Jens Axboe2fd233b2007-03-02 08:44:25 +0100281 flags |= O_SYNC;
Jens Axboead923962007-10-11 21:41:41 +0200282 if (f->filetype != FIO_TYPE_FILE)
283 flags |= O_NOATIME;
Jens Axboe7abf8332006-11-23 15:01:19 +0100284
Aaron Carroll056f3452007-11-26 09:08:53 +0100285open_again:
Jens Axboe660a1cb2007-04-17 15:37:47 +0200286 if (td_write(td)) {
Jens Axboe4241ea82007-09-12 08:18:36 +0200287 assert(!read_only);
288
Jens Axboe2fd233b2007-03-02 08:44:25 +0100289 flags |= O_RDWR;
Jens Axboe53cdc682006-10-18 11:50:58 +0200290
Jens Axboeaf52b342007-03-13 10:07:47 +0100291 if (f->filetype == FIO_TYPE_FILE)
Jens Axboe2fd233b2007-03-02 08:44:25 +0100292 flags |= O_CREAT;
Jens Axboe2fd233b2007-03-02 08:44:25 +0100293
Jens Axboe66159822007-04-16 21:54:24 +0200294 if (is_std)
295 f->fd = dup(STDOUT_FILENO);
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100296 else
297 from_hash = file_lookup_open(f, flags);
Jens Axboe2fd233b2007-03-02 08:44:25 +0100298 } else {
Jens Axboe4241ea82007-09-12 08:18:36 +0200299 if (f->filetype == FIO_TYPE_CHAR && !read_only)
Jens Axboe2fd233b2007-03-02 08:44:25 +0100300 flags |= O_RDWR;
301 else
302 flags |= O_RDONLY;
303
Jens Axboe66159822007-04-16 21:54:24 +0200304 if (is_std)
305 f->fd = dup(STDIN_FILENO);
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100306 else
307 from_hash = file_lookup_open(f, flags);
Jens Axboe53cdc682006-10-18 11:50:58 +0200308 }
309
310 if (f->fd == -1) {
Jens Axboee4e33252007-03-21 13:07:54 +0100311 char buf[FIO_VERROR_SIZE];
Jens Axboee1161c32007-02-22 19:36:48 +0100312 int __e = errno;
313
Aaron Carroll056f3452007-11-26 09:08:53 +0100314 if (errno == EPERM && (flags & O_NOATIME)) {
315 flags &= ~O_NOATIME;
316 goto open_again;
317 }
318
Jens Axboee4e33252007-03-21 13:07:54 +0100319 snprintf(buf, sizeof(buf) - 1, "open(%s)", f->file_name);
320
321 td_verror(td, __e, buf);
Jens Axboe53cdc682006-10-18 11:50:58 +0200322 }
323
Jens Axboeb5af8292007-03-08 12:43:13 +0100324 if (get_file_size(td, f))
325 goto err;
326
Jens Axboe29c13492008-03-01 19:25:20 +0100327 if (!from_hash && f->fd != -1) {
328 if (add_file_hash(f)) {
329 int ret;
330
331 /*
332 * OK to ignore, we haven't done anything with it
333 */
334 ret = generic_close_file(td, f);
335 goto open_again;
336 }
337 }
Jens Axboe4906e0b2008-03-01 18:59:51 +0100338
Jens Axboe53cdc682006-10-18 11:50:58 +0200339 return 0;
Jens Axboeb5af8292007-03-08 12:43:13 +0100340err:
341 close(f->fd);
342 return 1;
343}
344
Jens Axboe21972cd2006-11-23 12:39:16 +0100345int open_files(struct thread_data *td)
346{
347 struct fio_file *f;
Jens Axboeaf52b342007-03-13 10:07:47 +0100348 unsigned int i;
349 int err = 0;
Jens Axboe21972cd2006-11-23 12:39:16 +0100350
Jens Axboeee56ad52008-02-01 10:30:20 +0100351 dprint(FD_FILE, "open files\n");
352
Jens Axboe21972cd2006-11-23 12:39:16 +0100353 for_each_file(td, f, i) {
Jens Axboeb5af8292007-03-08 12:43:13 +0100354 err = td_io_open_file(td, f);
Jens Axboe9bf27b42007-03-27 19:49:31 +0200355 if (err) {
356 if (td->error == EMFILE) {
357 log_err("fio: limited open files to: %d\n", td->nr_open_files);
358 td->o.open_files = td->nr_open_files;
359 err = 0;
360 clear_error(td);
361 }
Jens Axboe21972cd2006-11-23 12:39:16 +0100362 break;
Jens Axboe9bf27b42007-03-27 19:49:31 +0200363 }
Jens Axboeb5af8292007-03-08 12:43:13 +0100364
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100365 if (td->o.open_files == td->nr_open_files)
Jens Axboeb5af8292007-03-08 12:43:13 +0100366 break;
Jens Axboe21972cd2006-11-23 12:39:16 +0100367 }
368
Jens Axboe7abf8332006-11-23 15:01:19 +0100369 if (!err)
370 return 0;
371
Jens Axboebdb4e2e2007-03-01 09:54:57 +0100372 for_each_file(td, f, i)
Jens Axboeb5af8292007-03-08 12:43:13 +0100373 td_io_close_file(td, f);
Jens Axboe7abf8332006-11-23 15:01:19 +0100374
Jens Axboe21972cd2006-11-23 12:39:16 +0100375 return err;
376}
377
Jens Axboe7bb48f82007-03-27 15:30:28 +0200378/*
379 * open/close all files, so that ->real_file_size gets set
380 */
Jens Axboebab3fd52007-04-02 10:34:18 +0200381static int get_file_sizes(struct thread_data *td)
Jens Axboe53cdc682006-10-18 11:50:58 +0200382{
383 struct fio_file *f;
Jens Axboeaf52b342007-03-13 10:07:47 +0100384 unsigned int i;
Jens Axboebab3fd52007-04-02 10:34:18 +0200385 int err = 0;
Jens Axboe7bb48f82007-03-27 15:30:28 +0200386
387 for_each_file(td, f, i) {
Jens Axboe9efef3c2008-03-06 10:26:25 +0100388 dprint(FD_FILE, "get file size for %p/%d/%p\n", f, i, f->file_name);
389
Jens Axboebab3fd52007-04-02 10:34:18 +0200390 if (td->io_ops->open_file(td, f)) {
Jens Axboe40b44f42007-04-11 12:43:35 +0200391 if (td->error != ENOENT) {
392 log_err("%s\n", td->verror);
393 err = 1;
394 }
Jens Axboe541d66d2007-03-27 19:50:11 +0200395 clear_error(td);
Jens Axboe07eb79d2007-04-12 13:02:38 +0200396 } else {
397 if (td->io_ops->close_file)
398 td->io_ops->close_file(td, f);
399 }
Jens Axboe409b3412007-03-28 09:57:01 +0200400
401 if (f->real_file_size == -1ULL && td->o.size)
402 f->real_file_size = td->o.size / td->o.nr_files;
Jens Axboe7bb48f82007-03-27 15:30:28 +0200403 }
Jens Axboebab3fd52007-04-02 10:34:18 +0200404
405 return err;
Jens Axboe7bb48f82007-03-27 15:30:28 +0200406}
407
408/*
409 * Open the files and setup files sizes, creating files if necessary.
410 */
411int setup_files(struct thread_data *td)
412{
413 unsigned long long total_size, extend_size;
414 struct fio_file *f;
415 unsigned int i;
Jens Axboe000b0802007-03-27 15:56:10 +0200416 int err = 0, need_extend;
Jens Axboe53cdc682006-10-18 11:50:58 +0200417
Jens Axboeee56ad52008-02-01 10:30:20 +0100418 dprint(FD_FILE, "setup files\n");
419
Jens Axboe53cdc682006-10-18 11:50:58 +0200420 /*
421 * if ioengine defines a setup() method, it's responsible for
Jens Axboe7bb48f82007-03-27 15:30:28 +0200422 * opening the files and setting f->real_file_size to indicate
423 * the valid range for that file.
Jens Axboe53cdc682006-10-18 11:50:58 +0200424 */
425 if (td->io_ops->setup)
Jens Axboe7bb48f82007-03-27 15:30:28 +0200426 err = td->io_ops->setup(td);
427 else
Jens Axboebab3fd52007-04-02 10:34:18 +0200428 err = get_file_sizes(td);
Jens Axboe53cdc682006-10-18 11:50:58 +0200429
Jens Axboef1027062006-10-20 10:14:01 +0200430 if (err)
431 return err;
432
Jens Axboe0a7eb122006-10-20 10:36:42 +0200433 /*
Jens Axboe7bb48f82007-03-27 15:30:28 +0200434 * check sizes. if the files/devices do not exist and the size
435 * isn't passed to fio, abort.
Jens Axboe0a7eb122006-10-20 10:36:42 +0200436 */
Jens Axboe7bb48f82007-03-27 15:30:28 +0200437 total_size = 0;
438 for_each_file(td, f, i) {
439 if (f->real_file_size == -1ULL)
440 total_size = -1ULL;
441 else
442 total_size += f->real_file_size;
443 }
Jens Axboe0a7eb122006-10-20 10:36:42 +0200444
Jens Axboe7bb48f82007-03-27 15:30:28 +0200445 /*
446 * device/file sizes are zero and no size given, punt
447 */
Jens Axboe1f809d12007-10-25 18:34:02 +0200448 if ((!total_size || total_size == -1ULL) && !td->o.size &&
Shawn Lewisaa31f1f2008-01-11 09:45:11 +0100449 !(td->io_ops->flags & FIO_NOIO) && !td->o.fill_device) {
Jens Axboe7bb48f82007-03-27 15:30:28 +0200450 log_err("%s: you need to specify size=\n", td->o.name);
Jens Axboee1161c32007-02-22 19:36:48 +0100451 td_verror(td, EINVAL, "total_file_size");
Jens Axboe53cdc682006-10-18 11:50:58 +0200452 return 1;
453 }
454
Jens Axboe7bb48f82007-03-27 15:30:28 +0200455 /*
456 * now file sizes are known, so we can set ->io_size. if size= is
457 * not given, ->io_size is just equal to ->real_file_size. if size
458 * is given, ->io_size is size / nr_files.
459 */
460 extend_size = total_size = 0;
461 need_extend = 0;
462 for_each_file(td, f, i) {
ljzhang,Yaxin Hu,Jianchao Tangbcdedd02007-07-27 13:28:26 +0200463 f->file_offset = td->o.start_offset;
464
Jens Axboe7bb48f82007-03-27 15:30:28 +0200465 if (!td->o.file_size_low) {
466 /*
467 * no file size range given, file size is equal to
468 * total size divided by number of files. if that is
469 * zero, set it to the real file size.
470 */
471 f->io_size = td->o.size / td->o.nr_files;
Jens Axboe65bdb102008-01-24 13:13:12 +0100472 if (!f->io_size)
Jens Axboe273f8c92008-01-25 14:02:15 +0100473 f->io_size = f->real_file_size - f->file_offset;
Jens Axboe7bb48f82007-03-27 15:30:28 +0200474 } else if (f->real_file_size < td->o.file_size_low ||
475 f->real_file_size > td->o.file_size_high) {
ljzhang,Yaxin Hu,Jianchao Tangbcdedd02007-07-27 13:28:26 +0200476 if (f->file_offset > td->o.file_size_low)
477 goto err_offset;
Jens Axboe7bb48f82007-03-27 15:30:28 +0200478 /*
479 * file size given. if it's fixed, use that. if it's a
480 * range, generate a random size in-between.
481 */
482 if (td->o.file_size_low == td->o.file_size_high)
ljzhang,Yaxin Hu,Jianchao Tangbcdedd02007-07-27 13:28:26 +0200483 f->io_size = td->o.file_size_low - f->file_offset;
Jens Axboe7bb48f82007-03-27 15:30:28 +0200484 else
ljzhang,Yaxin Hu,Jianchao Tangbcdedd02007-07-27 13:28:26 +0200485 f->io_size = get_rand_file_size(td) - f->file_offset;
Jens Axboe65bdb102008-01-24 13:13:12 +0100486 } else
ljzhang,Yaxin Hu,Jianchao Tangbcdedd02007-07-27 13:28:26 +0200487 f->io_size = f->real_file_size - f->file_offset;
Jens Axboe7bb48f82007-03-27 15:30:28 +0200488
489 if (f->io_size == -1ULL)
490 total_size = -1ULL;
491 else
492 total_size += f->io_size;
493
494 if (f->filetype == FIO_TYPE_FILE &&
ljzhang,Yaxin Hu,Jianchao Tangbcdedd02007-07-27 13:28:26 +0200495 (f->io_size + f->file_offset) > f->real_file_size &&
Jens Axboe7bb48f82007-03-27 15:30:28 +0200496 !(td->io_ops->flags & FIO_DISKLESSIO)) {
497 need_extend++;
ljzhang,Yaxin Hu,Jianchao Tangbcdedd02007-07-27 13:28:26 +0200498 extend_size += (f->io_size + f->file_offset);
Jens Axboe7bb48f82007-03-27 15:30:28 +0200499 f->flags |= FIO_FILE_EXTEND;
ljzhang,Yaxin Hu,Jianchao Tangbcdedd02007-07-27 13:28:26 +0200500 }
Jens Axboe7bb48f82007-03-27 15:30:28 +0200501 }
502
ljzhang,Yaxin Hu,Jianchao Tang22982902007-07-27 13:21:28 +0200503 if (!td->o.size || td->o.size > total_size)
Jens Axboe7bb48f82007-03-27 15:30:28 +0200504 td->o.size = total_size;
505
506 /*
507 * See if we need to extend some files
508 */
509 if (need_extend) {
510 temp_stall_ts = 1;
Jens Axboef627d8a2007-08-24 10:24:09 +0200511 log_info("%s: Laying out IO file(s) (%u file(s) / %LuMiB)\n",
Jens Axboe7bb48f82007-03-27 15:30:28 +0200512 td->o.name, need_extend, extend_size >> 20);
513
514 for_each_file(td, f, i) {
515 if (!(f->flags & FIO_FILE_EXTEND))
516 continue;
517
Jens Axboe409b3412007-03-28 09:57:01 +0200518 assert(f->filetype == FIO_TYPE_FILE);
Jens Axboe7bb48f82007-03-27 15:30:28 +0200519 f->flags &= ~FIO_FILE_EXTEND;
ljzhang,Yaxin Hu,Jianchao Tangbcdedd02007-07-27 13:28:26 +0200520 f->real_file_size = (f->io_size + f->file_offset);
Jens Axboe7bb48f82007-03-27 15:30:28 +0200521 err = extend_file(td, f);
522 if (err)
523 break;
524 }
525 temp_stall_ts = 0;
526 }
527
528 if (err)
529 return err;
530
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100531 if (!td->o.zone_size)
Jens Axboe7bb48f82007-03-27 15:30:28 +0200532 td->o.zone_size = td->o.size;
Jens Axboe53cdc682006-10-18 11:50:58 +0200533
Jens Axboeea966f82007-09-03 10:09:37 +0200534 /*
535 * iolog already set the total io size, if we read back
536 * stored entries.
537 */
538 if (!td->o.read_iolog_file)
539 td->total_io_size = td->o.size * td->o.loops;
Jens Axboe7bb48f82007-03-27 15:30:28 +0200540 return 0;
ljzhang,Yaxin Hu,Jianchao Tangbcdedd02007-07-27 13:28:26 +0200541err_offset:
542 log_err("%s: you need to specify valid offset=\n", td->o.name);
543 return 1;
Jens Axboe53cdc682006-10-18 11:50:58 +0200544}
545
Jens Axboe68727072007-03-15 20:49:25 +0100546int init_random_map(struct thread_data *td)
547{
Jens Axboe509eab12007-12-14 12:42:53 +0100548 unsigned long long blocks, num_maps;
Jens Axboe68727072007-03-15 20:49:25 +0100549 struct fio_file *f;
550 unsigned int i;
551
Jens Axboede8dd112008-03-01 15:34:44 +0100552 if (td->o.norandommap || !td_random(td))
Jens Axboe68727072007-03-15 20:49:25 +0100553 return 0;
554
555 for_each_file(td, f, i) {
Jens Axboe509eab12007-12-14 12:42:53 +0100556 blocks = (f->real_file_size + td->o.rw_min_bs - 1) / (unsigned long long) td->o.rw_min_bs;
557 num_maps = (blocks + BLOCKS_PER_MAP-1)/ (unsigned long long) BLOCKS_PER_MAP;
Jens Axboef17c4392008-03-01 18:40:46 +0100558 f->file_map = smalloc(num_maps * sizeof(long));
Jens Axboe68727072007-03-15 20:49:25 +0100559 if (!f->file_map) {
560 log_err("fio: failed allocating random map. If running a large number of jobs, try the 'norandommap' option\n");
561 return 1;
562 }
563 f->num_maps = num_maps;
Jens Axboe68727072007-03-15 20:49:25 +0100564 }
565
566 return 0;
567}
568
Jens Axboe53cdc682006-10-18 11:50:58 +0200569void close_files(struct thread_data *td)
570{
Jens Axboe0ab8db82006-10-18 17:16:23 +0200571 struct fio_file *f;
Jens Axboeaf52b342007-03-13 10:07:47 +0100572 unsigned int i;
Jens Axboe53cdc682006-10-18 11:50:58 +0200573
Jens Axboe24ffd2c2008-03-01 15:47:08 +0100574 for_each_file(td, f, i)
575 td_io_close_file(td, f);
576}
577
578void close_and_free_files(struct thread_data *td)
579{
580 struct fio_file *f;
581 unsigned int i;
582
Jens Axboeee56ad52008-02-01 10:30:20 +0100583 dprint(FD_FILE, "close files\n");
584
Jens Axboe0ab8db82006-10-18 17:16:23 +0200585 for_each_file(td, f, i) {
Jens Axboea9b7b302007-04-19 16:31:16 +0200586 if (td->o.unlink && f->filetype == FIO_TYPE_FILE)
Jens Axboe132ad462006-11-23 12:23:12 +0100587 unlink(f->file_name);
Jens Axboebdb4e2e2007-03-01 09:54:57 +0100588
Jens Axboeb5af8292007-03-08 12:43:13 +0100589 td_io_close_file(td, f);
Jens Axboeb3dc7f02007-03-09 12:52:15 +0100590
Jens Axboef17c4392008-03-01 18:40:46 +0100591 sfree(f->file_name);
Jens Axboefa1da862007-03-23 15:20:54 +0100592 f->file_name = NULL;
593
Jens Axboec3439812007-03-20 13:54:53 +0100594 if (f->file_map) {
Jens Axboef17c4392008-03-01 18:40:46 +0100595 sfree(f->file_map);
Jens Axboec3439812007-03-20 13:54:53 +0100596 f->file_map = NULL;
597 }
Jens Axboe78d99e62008-03-01 18:41:50 +0100598 sfree(f);
Jens Axboe53cdc682006-10-18 11:50:58 +0200599 }
Jens Axboeb4a6a592006-10-20 13:54:47 +0200600
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100601 td->o.filename = NULL;
Jens Axboecade3ef2007-03-23 15:29:45 +0100602 free(td->files);
Jens Axboe9efef3c2008-03-06 10:26:25 +0100603 td->files_index = 0;
Jens Axboeb4a6a592006-10-20 13:54:47 +0200604 td->files = NULL;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100605 td->o.nr_files = 0;
Jens Axboe53cdc682006-10-18 11:50:58 +0200606}
Jens Axboeaf52b342007-03-13 10:07:47 +0100607
Jens Axboee3bab462007-03-13 11:22:09 +0100608static void get_file_type(struct fio_file *f)
Jens Axboeaf52b342007-03-13 10:07:47 +0100609{
610 struct stat sb;
611
Jens Axboe66159822007-04-16 21:54:24 +0200612 if (!strcmp(f->file_name, "-"))
613 f->filetype = FIO_TYPE_PIPE;
614 else
615 f->filetype = FIO_TYPE_FILE;
Jens Axboeaf52b342007-03-13 10:07:47 +0100616
Jens Axboee3bab462007-03-13 11:22:09 +0100617 if (!lstat(f->file_name, &sb)) {
Jens Axboeaf52b342007-03-13 10:07:47 +0100618 if (S_ISBLK(sb.st_mode))
619 f->filetype = FIO_TYPE_BD;
620 else if (S_ISCHR(sb.st_mode))
621 f->filetype = FIO_TYPE_CHAR;
Jens Axboeb5605e92007-04-16 20:42:33 +0200622 else if (S_ISFIFO(sb.st_mode))
623 f->filetype = FIO_TYPE_PIPE;
Jens Axboeaf52b342007-03-13 10:07:47 +0100624 }
625}
626
Jens Axboef29b25a2007-07-23 08:56:43 +0200627int add_file(struct thread_data *td, const char *fname)
Jens Axboeaf52b342007-03-13 10:07:47 +0100628{
Jens Axboe7b4e4fe2007-03-13 12:51:40 +0100629 int cur_files = td->files_index;
Jens Axboebd0ee742007-03-23 14:26:23 +0100630 char file_name[PATH_MAX];
Jens Axboeaf52b342007-03-13 10:07:47 +0100631 struct fio_file *f;
Jens Axboebd0ee742007-03-23 14:26:23 +0100632 int len = 0;
Jens Axboeaf52b342007-03-13 10:07:47 +0100633
Jens Axboeee56ad52008-02-01 10:30:20 +0100634 dprint(FD_FILE, "add file %s\n", fname);
635
Jens Axboef17c4392008-03-01 18:40:46 +0100636 f = smalloc(sizeof(*f));
Jens Axboeaf52b342007-03-13 10:07:47 +0100637 f->fd = -1;
Jens Axboebd0ee742007-03-23 14:26:23 +0100638
Jens Axboe9efef3c2008-03-06 10:26:25 +0100639 dprint(FD_FILE, "resize file array to %d files\n", cur_files + 1);
Jens Axboe126d65c2008-03-01 18:04:31 +0100640
Jens Axboe9efef3c2008-03-06 10:26:25 +0100641 td->files = realloc(td->files, (cur_files + 1) * sizeof(f));
Jens Axboe126d65c2008-03-01 18:04:31 +0100642 td->files[cur_files] = f;
643
Jens Axboe07eb79d2007-04-12 13:02:38 +0200644 /*
645 * init function, io engine may not be loaded yet
646 */
647 if (td->io_ops && (td->io_ops->flags & FIO_DISKLESSIO))
648 f->real_file_size = -1ULL;
649
Jens Axboebd0ee742007-03-23 14:26:23 +0100650 if (td->o.directory)
651 len = sprintf(file_name, "%s/", td->o.directory);
652
653 sprintf(file_name + len, "%s", fname);
Jens Axboef17c4392008-03-01 18:40:46 +0100654 f->file_name = smalloc_strdup(file_name);
Jens Axboeaf52b342007-03-13 10:07:47 +0100655
Jens Axboee3bab462007-03-13 11:22:09 +0100656 get_file_type(f);
Jens Axboeaf52b342007-03-13 10:07:47 +0100657
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100658 switch (td->o.file_lock_mode) {
659 case FILE_LOCK_NONE:
660 break;
661 case FILE_LOCK_READWRITE:
662 f->lock = fio_mutex_rw_init();
663 break;
664 case FILE_LOCK_EXCLUSIVE:
665 f->lock = fio_mutex_init(1);
666 break;
667 default:
668 log_err("fio: unknown lock mode: %d\n", td->o.file_lock_mode);
669 assert(0);
670 }
Jens Axboe29c13492008-03-01 19:25:20 +0100671
Jens Axboe7b4e4fe2007-03-13 12:51:40 +0100672 td->files_index++;
Jens Axboe15494412007-03-13 11:52:47 +0100673 if (f->filetype == FIO_TYPE_FILE)
674 td->nr_normal_files++;
Jens Axboef29b25a2007-07-23 08:56:43 +0200675
Jens Axboe9efef3c2008-03-06 10:26:25 +0100676 dprint(FD_FILE, "file %p \"%s\" added at %d\n", f, f->file_name, cur_files);
677
Jens Axboef29b25a2007-07-23 08:56:43 +0200678 return cur_files;
Jens Axboeaf52b342007-03-13 10:07:47 +0100679}
Jens Axboe0ad920e2007-03-13 11:06:45 +0100680
681void get_file(struct fio_file *f)
682{
Jens Axboe8172fe92008-02-01 21:51:02 +0100683 dprint(FD_FILE, "get file %s, ref=%d\n", f->file_name, f->references);
Jens Axboe97af62c2007-05-22 11:12:13 +0200684 assert(f->flags & FIO_FILE_OPEN);
Jens Axboe0ad920e2007-03-13 11:06:45 +0100685 f->references++;
686}
687
Jens Axboe6977bcd2008-03-01 15:55:36 +0100688int put_file(struct thread_data *td, struct fio_file *f)
Jens Axboe0ad920e2007-03-13 11:06:45 +0100689{
Jens Axboe6977bcd2008-03-01 15:55:36 +0100690 int ret = 0;
691
Jens Axboe8172fe92008-02-01 21:51:02 +0100692 dprint(FD_FILE, "put file %s, ref=%d\n", f->file_name, f->references);
Jens Axboeee56ad52008-02-01 10:30:20 +0100693
Jens Axboe0ad920e2007-03-13 11:06:45 +0100694 if (!(f->flags & FIO_FILE_OPEN))
Jens Axboe6977bcd2008-03-01 15:55:36 +0100695 return 0;
Jens Axboe0ad920e2007-03-13 11:06:45 +0100696
697 assert(f->references);
698 if (--f->references)
Jens Axboe6977bcd2008-03-01 15:55:36 +0100699 return 0;
Jens Axboe0ad920e2007-03-13 11:06:45 +0100700
Jens Axboed424d4d2007-04-17 09:05:10 +0200701 if (should_fsync(td) && td->o.fsync_on_close)
Jens Axboeebb14152007-03-13 14:42:15 +0100702 fsync(f->fd);
703
Jens Axboe0ad920e2007-03-13 11:06:45 +0100704 if (td->io_ops->close_file)
Jens Axboe6977bcd2008-03-01 15:55:36 +0100705 ret = td->io_ops->close_file(td, f);
Jens Axboe1020a132007-03-29 11:15:06 +0200706
Jens Axboe0ad920e2007-03-13 11:06:45 +0100707 td->nr_open_files--;
708 f->flags &= ~FIO_FILE_OPEN;
Jens Axboe6977bcd2008-03-01 15:55:36 +0100709 return ret;
Jens Axboe0ad920e2007-03-13 11:06:45 +0100710}
Jens Axboebbf6b542007-03-13 15:28:55 +0100711
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100712void lock_file(struct thread_data *td, struct fio_file *f, enum fio_ddir ddir)
Jens Axboeb2bd2bd2008-03-01 18:19:52 +0100713{
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100714 if (!f->lock || td->o.file_lock_mode == FILE_LOCK_NONE)
715 return;
Jens Axboe29c13492008-03-01 19:25:20 +0100716
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100717 if (f->lock_owner == td && f->lock_batch--)
718 return;
719
720 if (td->o.file_lock_mode == FILE_LOCK_READWRITE) {
721 if (ddir == DDIR_READ)
722 fio_mutex_down_read(f->lock);
723 else
724 fio_mutex_down_write(f->lock);
725 } else if (td->o.file_lock_mode == FILE_LOCK_EXCLUSIVE)
726 fio_mutex_down(f->lock);
727
728 f->lock_owner = td;
729 f->lock_batch = td->o.lockfile_batch;
730 f->lock_ddir = ddir;
731}
732
733void unlock_file(struct thread_data *td, struct fio_file *f)
734{
735 if (!f->lock || td->o.file_lock_mode == FILE_LOCK_NONE)
736 return;
737 if (f->lock_batch)
738 return;
739
740 if (td->o.file_lock_mode == FILE_LOCK_READWRITE) {
741 const int is_read = f->lock_ddir == DDIR_READ;
742 int val = fio_mutex_getval(f->lock);
743
744 if ((is_read && val == 1) || (!is_read && val == -1))
745 f->lock_owner = NULL;
746
747 if (is_read)
748 fio_mutex_up_read(f->lock);
749 else
750 fio_mutex_up_write(f->lock);
751 } else if (td->o.file_lock_mode == FILE_LOCK_EXCLUSIVE) {
752 int val = fio_mutex_getval(f->lock);
753
754 if (val == 0)
755 f->lock_owner = NULL;
756
757 fio_mutex_up(f->lock);
Jens Axboe29c13492008-03-01 19:25:20 +0100758 }
Jens Axboeb2bd2bd2008-03-01 18:19:52 +0100759}
760
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100761void unlock_file_all(struct thread_data *td, struct fio_file *f)
Jens Axboeb2bd2bd2008-03-01 18:19:52 +0100762{
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100763 if (f->lock_owner != td)
764 return;
Jens Axboe29c13492008-03-01 19:25:20 +0100765
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100766 f->lock_batch = 0;
767 unlock_file(td, f);
Jens Axboeb2bd2bd2008-03-01 18:19:52 +0100768}
769
Jens Axboebbf6b542007-03-13 15:28:55 +0100770static int recurse_dir(struct thread_data *td, const char *dirname)
771{
772 struct dirent *dir;
773 int ret = 0;
774 DIR *D;
775
776 D = opendir(dirname);
777 if (!D) {
Jens Axboe0ddb2702007-03-27 19:43:53 +0200778 char buf[FIO_VERROR_SIZE];
779
780 snprintf(buf, FIO_VERROR_SIZE - 1, "opendir(%s)", dirname);
781 td_verror(td, errno, buf);
Jens Axboebbf6b542007-03-13 15:28:55 +0100782 return 1;
783 }
784
785 while ((dir = readdir(D)) != NULL) {
786 char full_path[PATH_MAX];
787 struct stat sb;
788
Jens Axboee85b2b82007-03-14 09:39:06 +0100789 if (!strcmp(dir->d_name, ".") || !strcmp(dir->d_name, ".."))
790 continue;
Jens Axboe96d32d52007-03-14 09:16:09 +0100791
Jens Axboebbf6b542007-03-13 15:28:55 +0100792 sprintf(full_path, "%s/%s", dirname, dir->d_name);
793
794 if (lstat(full_path, &sb) == -1) {
795 if (errno != ENOENT) {
796 td_verror(td, errno, "stat");
797 return 1;
798 }
799 }
800
801 if (S_ISREG(sb.st_mode)) {
802 add_file(td, full_path);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100803 td->o.nr_files++;
Jens Axboebbf6b542007-03-13 15:28:55 +0100804 continue;
805 }
Jens Axboe0ddb2702007-03-27 19:43:53 +0200806 if (!S_ISDIR(sb.st_mode))
807 continue;
Jens Axboebbf6b542007-03-13 15:28:55 +0100808
Jens Axboebbf6b542007-03-13 15:28:55 +0100809 if ((ret = recurse_dir(td, full_path)) != 0)
810 break;
811 }
812
813 closedir(D);
814 return ret;
815}
816
817int add_dir_files(struct thread_data *td, const char *path)
818{
Jens Axboe0ddb2702007-03-27 19:43:53 +0200819 int ret = recurse_dir(td, path);
820
821 if (!ret)
822 log_info("fio: opendir added %d files\n", td->o.nr_files);
823
824 return ret;
Jens Axboebbf6b542007-03-13 15:28:55 +0100825}
Jens Axboecade3ef2007-03-23 15:29:45 +0100826
827void dup_files(struct thread_data *td, struct thread_data *org)
828{
829 struct fio_file *f;
830 unsigned int i;
Jens Axboe9efef3c2008-03-06 10:26:25 +0100831
832 dprint(FD_FILE, "dup files: %d\n", org->files_index);
Jens Axboecade3ef2007-03-23 15:29:45 +0100833
834 if (!org->files)
835 return;
836
Jens Axboe9efef3c2008-03-06 10:26:25 +0100837 td->files = malloc(org->files_index * sizeof(f));
Jens Axboecade3ef2007-03-23 15:29:45 +0100838
Jens Axboe9efef3c2008-03-06 10:26:25 +0100839 for_each_file(org, f, i) {
Jens Axboeb0fe4212008-03-01 18:22:27 +0100840 struct fio_file *__f;
841
Jens Axboef17c4392008-03-01 18:40:46 +0100842 __f = smalloc(sizeof(*__f));
Jens Axboeb0fe4212008-03-01 18:22:27 +0100843
Jens Axboecade3ef2007-03-23 15:29:45 +0100844 if (f->file_name)
Jens Axboef17c4392008-03-01 18:40:46 +0100845 __f->file_name = smalloc_strdup(f->file_name);
Jens Axboeb0fe4212008-03-01 18:22:27 +0100846
847 td->files[i] = __f;
Jens Axboecade3ef2007-03-23 15:29:45 +0100848 }
849}
Jens Axboef29b25a2007-07-23 08:56:43 +0200850
851/*
852 * Returns the index that matches the filename, or -1 if not there
853 */
854int get_fileno(struct thread_data *td, const char *fname)
855{
856 struct fio_file *f;
857 unsigned int i;
858
859 for_each_file(td, f, i)
860 if (!strcmp(f->file_name, fname))
861 return i;
862
863 return -1;
864}
865
866/*
867 * For log usage, where we add/open/close files automatically
868 */
869void free_release_files(struct thread_data *td)
870{
871 close_files(td);
872 td->files_index = 0;
873 td->nr_normal_files = 0;
874}