Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 1 | #include <unistd.h> |
| 2 | #include <fcntl.h> |
| 3 | #include <string.h> |
| 4 | #include <assert.h> |
Jens Axboe | bbf6b54 | 2007-03-13 15:28:55 +0100 | [diff] [blame] | 5 | #include <dirent.h> |
YAMAMOTO Takashi | d74ac84 | 2010-06-09 09:44:53 +0200 | [diff] [blame] | 6 | #include <libgen.h> |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 7 | #include <sys/stat.h> |
| 8 | #include <sys/mman.h> |
Jens Axboe | bbf6b54 | 2007-03-13 15:28:55 +0100 | [diff] [blame] | 9 | #include <sys/types.h> |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 10 | |
| 11 | #include "fio.h" |
Jens Axboe | f17c439 | 2008-03-01 18:40:46 +0100 | [diff] [blame] | 12 | #include "smalloc.h" |
Jens Axboe | 4906e0b | 2008-03-01 18:59:51 +0100 | [diff] [blame] | 13 | #include "filehash.h" |
Bruce Cran | ecc314b | 2011-01-04 10:59:30 +0100 | [diff] [blame] | 14 | #include "os/os.h" |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 15 | |
Eric Gouriou | a596f04 | 2011-06-17 09:11:45 +0200 | [diff] [blame] | 16 | #ifdef FIO_HAVE_LINUX_FALLOCATE |
| 17 | #include <linux/falloc.h> |
| 18 | #endif |
| 19 | |
Jens Axboe | 7172cfe | 2007-07-23 14:36:00 +0200 | [diff] [blame] | 20 | static int root_warn; |
| 21 | |
Jens Axboe | c592b9f | 2009-06-03 09:29:28 +0200 | [diff] [blame] | 22 | static inline void clear_error(struct thread_data *td) |
| 23 | { |
| 24 | td->error = 0; |
| 25 | td->verror[0] = '\0'; |
| 26 | } |
| 27 | |
Jens Axboe | 3baddf2 | 2008-04-04 11:10:30 +0200 | [diff] [blame] | 28 | /* |
| 29 | * Leaves f->fd open on success, caller must close |
| 30 | */ |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 31 | static int extend_file(struct thread_data *td, struct fio_file *f) |
Jens Axboe | 25205e9 | 2006-10-19 20:50:14 +0200 | [diff] [blame] | 32 | { |
Jens Axboe | ea44365 | 2007-03-29 14:52:13 +0200 | [diff] [blame] | 33 | int r, new_layout = 0, unlink_file = 0, flags; |
Jens Axboe | 25205e9 | 2006-10-19 20:50:14 +0200 | [diff] [blame] | 34 | unsigned long long left; |
| 35 | unsigned int bs; |
| 36 | char *b; |
Jens Axboe | b2a1519 | 2006-10-18 14:10:42 +0200 | [diff] [blame] | 37 | |
Jens Axboe | 4241ea8 | 2007-09-12 08:18:36 +0200 | [diff] [blame] | 38 | if (read_only) { |
| 39 | log_err("fio: refusing extend of file due to read-only\n"); |
| 40 | return 0; |
| 41 | } |
| 42 | |
Jens Axboe | 507a702 | 2007-03-27 15:52:46 +0200 | [diff] [blame] | 43 | /* |
| 44 | * check if we need to lay the file out complete again. fio |
| 45 | * does that for operations involving reads, or for writes |
| 46 | * where overwrite is set |
| 47 | */ |
Jens Axboe | ffdfabd | 2008-03-26 09:18:14 +0100 | [diff] [blame] | 48 | if (td_read(td) || (td_write(td) && td->o.overwrite) || |
| 49 | (td_write(td) && td->io_ops->flags & FIO_NOEXTEND)) |
Jens Axboe | 507a702 | 2007-03-27 15:52:46 +0200 | [diff] [blame] | 50 | new_layout = 1; |
Jens Axboe | ea44365 | 2007-03-29 14:52:13 +0200 | [diff] [blame] | 51 | if (td_write(td) && !td->o.overwrite) |
| 52 | unlink_file = 1; |
Jens Axboe | 507a702 | 2007-03-27 15:52:46 +0200 | [diff] [blame] | 53 | |
Jens Axboe | 6ae1f57 | 2008-02-21 10:20:00 +0100 | [diff] [blame] | 54 | if (unlink_file || new_layout) { |
Jens Axboe | bd199f2 | 2008-03-26 09:57:18 +0100 | [diff] [blame] | 55 | dprint(FD_FILE, "layout unlink %s\n", f->file_name); |
Zhang, Yanmin | 982016d | 2008-02-26 15:35:52 +0100 | [diff] [blame] | 56 | if ((unlink(f->file_name) < 0) && (errno != ENOENT)) { |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 57 | td_verror(td, errno, "unlink"); |
| 58 | return 1; |
| 59 | } |
| 60 | } |
| 61 | |
Jens Axboe | 507a702 | 2007-03-27 15:52:46 +0200 | [diff] [blame] | 62 | flags = O_WRONLY | O_CREAT; |
| 63 | if (new_layout) |
| 64 | flags |= O_TRUNC; |
| 65 | |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 66 | dprint(FD_FILE, "open file %s, flags %x\n", f->file_name, flags); |
Jens Axboe | 507a702 | 2007-03-27 15:52:46 +0200 | [diff] [blame] | 67 | f->fd = open(f->file_name, flags, 0644); |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 68 | if (f->fd < 0) { |
Jens Axboe | e1161c3 | 2007-02-22 19:36:48 +0100 | [diff] [blame] | 69 | td_verror(td, errno, "open"); |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 70 | return 1; |
| 71 | } |
| 72 | |
Jens Axboe | 7bc8c2c | 2010-01-28 11:31:31 +0100 | [diff] [blame] | 73 | #ifdef FIO_HAVE_FALLOCATE |
Eric Gouriou | a596f04 | 2011-06-17 09:11:45 +0200 | [diff] [blame] | 74 | if (!td->o.fill_device) { |
| 75 | switch (td->o.fallocate_mode) { |
| 76 | case FIO_FALLOCATE_NONE: |
| 77 | break; |
| 78 | case FIO_FALLOCATE_POSIX: |
| 79 | dprint(FD_FILE, "posix_fallocate file %s size %llu\n", |
| 80 | f->file_name, f->real_file_size); |
Jens Axboe | 7bc8c2c | 2010-01-28 11:31:31 +0100 | [diff] [blame] | 81 | |
Eric Gouriou | a596f04 | 2011-06-17 09:11:45 +0200 | [diff] [blame] | 82 | r = posix_fallocate(f->fd, 0, f->real_file_size); |
| 83 | if (r > 0) { |
| 84 | log_err("fio: posix_fallocate fails: %s\n", |
| 85 | strerror(r)); |
| 86 | } |
| 87 | break; |
| 88 | #ifdef FIO_HAVE_LINUX_FALLOCATE |
| 89 | case FIO_FALLOCATE_KEEP_SIZE: |
| 90 | dprint(FD_FILE, |
| 91 | "fallocate(FALLOC_FL_KEEP_SIZE) " |
| 92 | "file %s size %llu\n", |
| 93 | f->file_name, f->real_file_size); |
| 94 | |
| 95 | r = fallocate(f->fd, FALLOC_FL_KEEP_SIZE, 0, |
| 96 | f->real_file_size); |
| 97 | if (r != 0) { |
| 98 | td_verror(td, errno, "fallocate"); |
| 99 | } |
| 100 | break; |
| 101 | #endif /* FIO_HAVE_LINUX_FALLOCATE */ |
| 102 | default: |
| 103 | log_err("fio: unknown fallocate mode: %d\n", |
| 104 | td->o.fallocate_mode); |
| 105 | assert(0); |
Jens Axboe | 7bc8c2c | 2010-01-28 11:31:31 +0100 | [diff] [blame] | 106 | } |
| 107 | } |
Eric Gouriou | a596f04 | 2011-06-17 09:11:45 +0200 | [diff] [blame] | 108 | #endif /* FIO_HAVE_FALLOCATE */ |
Bruce Cran | 9b83656 | 2011-01-08 19:49:54 +0100 | [diff] [blame] | 109 | |
Shawn Lewis | fc74ac1 | 2008-01-11 09:45:11 +0100 | [diff] [blame] | 110 | if (!new_layout) |
| 111 | goto done; |
| 112 | |
Jens Axboe | 5e0074c | 2009-06-02 21:40:09 +0200 | [diff] [blame] | 113 | /* |
| 114 | * The size will be -1ULL when fill_device is used, so don't truncate |
| 115 | * or fallocate this file, just write it |
| 116 | */ |
| 117 | if (!td->o.fill_device) { |
| 118 | dprint(FD_FILE, "truncate file %s, size %llu\n", f->file_name, |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 119 | f->real_file_size); |
Jens Axboe | 5e0074c | 2009-06-02 21:40:09 +0200 | [diff] [blame] | 120 | if (ftruncate(f->fd, f->real_file_size) == -1) { |
| 121 | td_verror(td, errno, "ftruncate"); |
| 122 | goto err; |
| 123 | } |
Jens Axboe | 5e0074c | 2009-06-02 21:40:09 +0200 | [diff] [blame] | 124 | } |
Jens Axboe | 40f8298 | 2006-10-25 11:21:05 +0200 | [diff] [blame] | 125 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 126 | b = malloc(td->o.max_bs[DDIR_WRITE]); |
| 127 | memset(b, 0, td->o.max_bs[DDIR_WRITE]); |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 128 | |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 129 | left = f->real_file_size; |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 130 | while (left && !td->terminate) { |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 131 | bs = td->o.max_bs[DDIR_WRITE]; |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 132 | if (bs > left) |
| 133 | bs = left; |
| 134 | |
| 135 | r = write(f->fd, b, bs); |
| 136 | |
Jens Axboe | 5e0074c | 2009-06-02 21:40:09 +0200 | [diff] [blame] | 137 | if (r > 0) { |
| 138 | left -= r; |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 139 | continue; |
| 140 | } else { |
Jens Axboe | 5e0074c | 2009-06-02 21:40:09 +0200 | [diff] [blame] | 141 | if (r < 0) { |
| 142 | int __e = errno; |
| 143 | |
| 144 | if (__e == ENOSPC) { |
| 145 | if (td->o.fill_device) |
| 146 | break; |
| 147 | log_info("fio: ENOSPC on laying out " |
| 148 | "file, stopping\n"); |
| 149 | break; |
| 150 | } |
Jens Axboe | e1161c3 | 2007-02-22 19:36:48 +0100 | [diff] [blame] | 151 | td_verror(td, errno, "write"); |
Jens Axboe | 5e0074c | 2009-06-02 21:40:09 +0200 | [diff] [blame] | 152 | } else |
Jens Axboe | e1161c3 | 2007-02-22 19:36:48 +0100 | [diff] [blame] | 153 | td_verror(td, EIO, "write"); |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 154 | |
| 155 | break; |
| 156 | } |
| 157 | } |
| 158 | |
Jens Axboe | ffdfabd | 2008-03-26 09:18:14 +0100 | [diff] [blame] | 159 | if (td->terminate) { |
| 160 | dprint(FD_FILE, "terminate unlink %s\n", f->file_name); |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 161 | unlink(f->file_name); |
Jens Axboe | ffdfabd | 2008-03-26 09:18:14 +0100 | [diff] [blame] | 162 | } else if (td->o.create_fsync) { |
Jens Axboe | 98e1ac4 | 2008-03-06 11:56:48 +0100 | [diff] [blame] | 163 | if (fsync(f->fd) < 0) { |
| 164 | td_verror(td, errno, "fsync"); |
| 165 | goto err; |
| 166 | } |
| 167 | } |
Jens Axboe | 0d1cd20 | 2009-06-05 22:11:52 +0200 | [diff] [blame] | 168 | if (td->o.fill_device && !td_write(td)) { |
Jens Axboe | d6aed79 | 2009-06-03 08:41:15 +0200 | [diff] [blame] | 169 | fio_file_clear_size_known(f); |
Jens Axboe | 5e0074c | 2009-06-02 21:40:09 +0200 | [diff] [blame] | 170 | if (td_io_get_file_size(td, f)) |
| 171 | goto err; |
| 172 | if (f->io_size > f->real_file_size) |
| 173 | f->io_size = f->real_file_size; |
| 174 | } |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 175 | |
| 176 | free(b); |
Jens Axboe | 507a702 | 2007-03-27 15:52:46 +0200 | [diff] [blame] | 177 | done: |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 178 | return 0; |
| 179 | err: |
| 180 | close(f->fd); |
| 181 | f->fd = -1; |
| 182 | return 1; |
| 183 | } |
| 184 | |
Zhang, Yanmin | afad68f | 2009-05-20 11:30:55 +0200 | [diff] [blame] | 185 | static int pre_read_file(struct thread_data *td, struct fio_file *f) |
| 186 | { |
Jens Axboe | b0f6586 | 2009-05-20 11:52:15 +0200 | [diff] [blame] | 187 | int r, did_open = 0, old_runstate; |
Zhang, Yanmin | afad68f | 2009-05-20 11:30:55 +0200 | [diff] [blame] | 188 | unsigned long long left; |
| 189 | unsigned int bs; |
| 190 | char *b; |
| 191 | |
Jens Axboe | 9c0d224 | 2009-07-01 12:26:28 +0200 | [diff] [blame] | 192 | if (td->io_ops->flags & FIO_PIPEIO) |
| 193 | return 0; |
| 194 | |
Jens Axboe | d6aed79 | 2009-06-03 08:41:15 +0200 | [diff] [blame] | 195 | if (!fio_file_open(f)) { |
Jens Axboe | b0f6586 | 2009-05-20 11:52:15 +0200 | [diff] [blame] | 196 | if (td->io_ops->open_file(td, f)) { |
| 197 | log_err("fio: cannot pre-read, failed to open file\n"); |
| 198 | return 1; |
| 199 | } |
| 200 | did_open = 1; |
| 201 | } |
| 202 | |
| 203 | old_runstate = td->runstate; |
| 204 | td_set_runstate(td, TD_PRE_READING); |
| 205 | |
Zhang, Yanmin | afad68f | 2009-05-20 11:30:55 +0200 | [diff] [blame] | 206 | bs = td->o.max_bs[DDIR_READ]; |
| 207 | b = malloc(bs); |
| 208 | memset(b, 0, bs); |
| 209 | |
| 210 | lseek(f->fd, f->file_offset, SEEK_SET); |
| 211 | left = f->io_size; |
| 212 | |
| 213 | while (left && !td->terminate) { |
| 214 | if (bs > left) |
| 215 | bs = left; |
| 216 | |
| 217 | r = read(f->fd, b, bs); |
| 218 | |
| 219 | if (r == (int) bs) { |
| 220 | left -= bs; |
| 221 | continue; |
| 222 | } else { |
| 223 | td_verror(td, EIO, "pre_read"); |
| 224 | break; |
| 225 | } |
| 226 | } |
| 227 | |
Jens Axboe | b0f6586 | 2009-05-20 11:52:15 +0200 | [diff] [blame] | 228 | td_set_runstate(td, old_runstate); |
| 229 | |
| 230 | if (did_open) |
| 231 | td->io_ops->close_file(td, f); |
Zhang, Yanmin | afad68f | 2009-05-20 11:30:55 +0200 | [diff] [blame] | 232 | free(b); |
| 233 | return 0; |
| 234 | } |
| 235 | |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 236 | static unsigned long long get_rand_file_size(struct thread_data *td) |
Jens Axboe | 9c60ce6 | 2007-03-15 09:14:47 +0100 | [diff] [blame] | 237 | { |
Jens Axboe | dc873b6 | 2008-06-04 20:13:04 +0200 | [diff] [blame] | 238 | unsigned long long ret, sized; |
Jens Axboe | 1294c3e | 2011-05-11 08:15:18 +0200 | [diff] [blame] | 239 | unsigned long r; |
Jens Axboe | 9c60ce6 | 2007-03-15 09:14:47 +0100 | [diff] [blame] | 240 | |
Jens Axboe | 4c07ad8 | 2011-03-28 09:51:09 +0200 | [diff] [blame] | 241 | if (td->o.use_os_rand) { |
| 242 | r = os_random_long(&td->file_size_state); |
| 243 | sized = td->o.file_size_high - td->o.file_size_low; |
| 244 | ret = (unsigned long long) ((double) sized * (r / (OS_RAND_MAX + 1.0))); |
| 245 | } else { |
| 246 | r = __rand(&td->__file_size_state); |
| 247 | sized = td->o.file_size_high - td->o.file_size_low; |
| 248 | ret = (unsigned long long) ((double) sized * (r / (FRAND_MAX + 1.0))); |
| 249 | } |
| 250 | |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 251 | ret += td->o.file_size_low; |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 252 | ret -= (ret % td->o.rw_min_bs); |
Jens Axboe | 9c60ce6 | 2007-03-15 09:14:47 +0100 | [diff] [blame] | 253 | return ret; |
| 254 | } |
| 255 | |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 256 | static int file_size(struct thread_data *td, struct fio_file *f) |
| 257 | { |
| 258 | struct stat st; |
| 259 | |
Jens Axboe | df9c26b | 2009-03-05 10:13:58 +0100 | [diff] [blame] | 260 | if (stat(f->file_name, &st) == -1) { |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 261 | td_verror(td, errno, "fstat"); |
| 262 | return 1; |
| 263 | } |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 264 | |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 265 | f->real_file_size = st.st_size; |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 266 | return 0; |
| 267 | } |
| 268 | |
| 269 | static int bdev_size(struct thread_data *td, struct fio_file *f) |
| 270 | { |
Bruce Cran | 9b83656 | 2011-01-08 19:49:54 +0100 | [diff] [blame] | 271 | unsigned long long bytes = 0; |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 272 | int r; |
| 273 | |
Jens Axboe | df9c26b | 2009-03-05 10:13:58 +0100 | [diff] [blame] | 274 | if (td->io_ops->open_file(td, f)) { |
| 275 | log_err("fio: failed opening blockdev %s for size check\n", |
| 276 | f->file_name); |
| 277 | return 1; |
| 278 | } |
| 279 | |
Bruce Cran | ecc314b | 2011-01-04 10:59:30 +0100 | [diff] [blame] | 280 | r = blockdev_size(f, &bytes); |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 281 | if (r) { |
Jens Axboe | e1161c3 | 2007-02-22 19:36:48 +0100 | [diff] [blame] | 282 | td_verror(td, r, "blockdev_size"); |
Jens Axboe | df9c26b | 2009-03-05 10:13:58 +0100 | [diff] [blame] | 283 | goto err; |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 284 | } |
| 285 | |
Jens Axboe | 7ab077a | 2009-02-02 15:07:37 +0100 | [diff] [blame] | 286 | if (!bytes) { |
| 287 | log_err("%s: zero sized block device?\n", f->file_name); |
Jens Axboe | df9c26b | 2009-03-05 10:13:58 +0100 | [diff] [blame] | 288 | goto err; |
Jens Axboe | 7ab077a | 2009-02-02 15:07:37 +0100 | [diff] [blame] | 289 | } |
| 290 | |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 291 | f->real_file_size = bytes; |
Jens Axboe | 22a57ba | 2009-06-09 14:34:35 +0200 | [diff] [blame] | 292 | td->io_ops->close_file(td, f); |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 293 | return 0; |
Jens Axboe | df9c26b | 2009-03-05 10:13:58 +0100 | [diff] [blame] | 294 | err: |
| 295 | td->io_ops->close_file(td, f); |
| 296 | return 1; |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 297 | } |
| 298 | |
Jens Axboe | 4ccdccd | 2010-06-24 10:27:22 +0200 | [diff] [blame] | 299 | static int char_size(struct thread_data *td, struct fio_file *f) |
| 300 | { |
| 301 | #ifdef FIO_HAVE_CHARDEV_SIZE |
Bruce Cran | 9b83656 | 2011-01-08 19:49:54 +0100 | [diff] [blame] | 302 | unsigned long long bytes = 0; |
Jens Axboe | 4ccdccd | 2010-06-24 10:27:22 +0200 | [diff] [blame] | 303 | int r; |
| 304 | |
| 305 | if (td->io_ops->open_file(td, f)) { |
| 306 | log_err("fio: failed opening blockdev %s for size check\n", |
| 307 | f->file_name); |
| 308 | return 1; |
| 309 | } |
| 310 | |
Bruce Cran | ecc314b | 2011-01-04 10:59:30 +0100 | [diff] [blame] | 311 | r = chardev_size(f, &bytes); |
Jens Axboe | 4ccdccd | 2010-06-24 10:27:22 +0200 | [diff] [blame] | 312 | if (r) { |
| 313 | td_verror(td, r, "chardev_size"); |
| 314 | goto err; |
| 315 | } |
| 316 | |
| 317 | if (!bytes) { |
| 318 | log_err("%s: zero sized char device?\n", f->file_name); |
| 319 | goto err; |
| 320 | } |
| 321 | |
| 322 | f->real_file_size = bytes; |
| 323 | td->io_ops->close_file(td, f); |
| 324 | return 0; |
| 325 | err: |
| 326 | td->io_ops->close_file(td, f); |
| 327 | return 1; |
| 328 | #else |
| 329 | f->real_file_size = -1ULL; |
| 330 | return 0; |
| 331 | #endif |
| 332 | } |
| 333 | |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 334 | static int get_file_size(struct thread_data *td, struct fio_file *f) |
| 335 | { |
| 336 | int ret = 0; |
| 337 | |
Jens Axboe | d6aed79 | 2009-06-03 08:41:15 +0200 | [diff] [blame] | 338 | if (fio_file_size_known(f)) |
Jens Axboe | 409b341 | 2007-03-28 09:57:01 +0200 | [diff] [blame] | 339 | return 0; |
| 340 | |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 341 | if (f->filetype == FIO_TYPE_FILE) |
| 342 | ret = file_size(td, f); |
| 343 | else if (f->filetype == FIO_TYPE_BD) |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 344 | ret = bdev_size(td, f); |
Jens Axboe | 4ccdccd | 2010-06-24 10:27:22 +0200 | [diff] [blame] | 345 | else if (f->filetype == FIO_TYPE_CHAR) |
| 346 | ret = char_size(td, f); |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 347 | else |
| 348 | f->real_file_size = -1; |
| 349 | |
| 350 | if (ret) |
| 351 | return ret; |
| 352 | |
| 353 | if (f->file_offset > f->real_file_size) { |
Bruce Cran | 0f2152c | 2010-12-15 10:33:03 +0100 | [diff] [blame] | 354 | log_err("%s: offset extends end (%llu > %llu)\n", td->o.name, |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 355 | f->file_offset, f->real_file_size); |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 356 | return 1; |
| 357 | } |
| 358 | |
Jens Axboe | d6aed79 | 2009-06-03 08:41:15 +0200 | [diff] [blame] | 359 | fio_file_set_size_known(f); |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 360 | return 0; |
| 361 | } |
| 362 | |
Jens Axboe | 3baddf2 | 2008-04-04 11:10:30 +0200 | [diff] [blame] | 363 | static int __file_invalidate_cache(struct thread_data *td, struct fio_file *f, |
| 364 | unsigned long long off, |
| 365 | unsigned long long len) |
Jens Axboe | e5b401d | 2006-10-18 16:03:40 +0200 | [diff] [blame] | 366 | { |
| 367 | int ret = 0; |
| 368 | |
Jens Axboe | 5e0074c | 2009-06-02 21:40:09 +0200 | [diff] [blame] | 369 | if (len == -1ULL) |
Jens Axboe | 3baddf2 | 2008-04-04 11:10:30 +0200 | [diff] [blame] | 370 | len = f->io_size; |
| 371 | if (off == -1ULL) |
| 372 | off = f->file_offset; |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 373 | |
Jens Axboe | 0d1cd20 | 2009-06-05 22:11:52 +0200 | [diff] [blame] | 374 | if (len == -1ULL || off == -1ULL) |
| 375 | return 0; |
| 376 | |
Jens Axboe | 3baddf2 | 2008-04-04 11:10:30 +0200 | [diff] [blame] | 377 | dprint(FD_IO, "invalidate cache %s: %llu/%llu\n", f->file_name, off, |
| 378 | len); |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 379 | |
Jens Axboe | e5b401d | 2006-10-18 16:03:40 +0200 | [diff] [blame] | 380 | /* |
| 381 | * FIXME: add blockdev flushing too |
| 382 | */ |
Jens Axboe | a1c5807 | 2009-08-04 23:17:02 +0200 | [diff] [blame] | 383 | if (f->mmap_ptr) { |
Bruce Cran | 03e20d6 | 2011-01-02 20:14:54 +0100 | [diff] [blame] | 384 | ret = posix_madvise(f->mmap_ptr, f->mmap_sz, POSIX_MADV_DONTNEED); |
Jens Axboe | a1c5807 | 2009-08-04 23:17:02 +0200 | [diff] [blame] | 385 | #ifdef FIO_MADV_FREE |
Bruce Cran | 03e20d6 | 2011-01-02 20:14:54 +0100 | [diff] [blame] | 386 | (void) posix_madvise(f->mmap_ptr, f->mmap_sz, FIO_MADV_FREE); |
Jens Axboe | a1c5807 | 2009-08-04 23:17:02 +0200 | [diff] [blame] | 387 | #endif |
| 388 | } else if (f->filetype == FIO_TYPE_FILE) { |
Bruce Cran | ecc314b | 2011-01-04 10:59:30 +0100 | [diff] [blame] | 389 | ret = posix_fadvise(f->fd, off, len, POSIX_FADV_DONTNEED); |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 390 | } else if (f->filetype == FIO_TYPE_BD) { |
Bruce Cran | ecc314b | 2011-01-04 10:59:30 +0100 | [diff] [blame] | 391 | ret = blockdev_invalidate_cache(f); |
Jens Axboe | 7e0e25c | 2007-03-27 12:49:56 +0200 | [diff] [blame] | 392 | if (ret < 0 && errno == EACCES && geteuid()) { |
Jens Axboe | 7172cfe | 2007-07-23 14:36:00 +0200 | [diff] [blame] | 393 | if (!root_warn) { |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 394 | log_err("fio: only root may flush block " |
| 395 | "devices. Cache flush bypassed!\n"); |
Jens Axboe | 7172cfe | 2007-07-23 14:36:00 +0200 | [diff] [blame] | 396 | root_warn = 1; |
| 397 | } |
Jens Axboe | 7e0e25c | 2007-03-27 12:49:56 +0200 | [diff] [blame] | 398 | ret = 0; |
| 399 | } |
Jens Axboe | b5605e9 | 2007-04-16 20:42:33 +0200 | [diff] [blame] | 400 | } else if (f->filetype == FIO_TYPE_CHAR || f->filetype == FIO_TYPE_PIPE) |
Jens Axboe | e5b401d | 2006-10-18 16:03:40 +0200 | [diff] [blame] | 401 | ret = 0; |
| 402 | |
| 403 | if (ret < 0) { |
Jens Axboe | e1161c3 | 2007-02-22 19:36:48 +0100 | [diff] [blame] | 404 | td_verror(td, errno, "invalidate_cache"); |
Jens Axboe | e5b401d | 2006-10-18 16:03:40 +0200 | [diff] [blame] | 405 | return 1; |
Jens Axboe | 3baddf2 | 2008-04-04 11:10:30 +0200 | [diff] [blame] | 406 | } else if (ret > 0) { |
| 407 | td_verror(td, ret, "invalidate_cache"); |
| 408 | return 1; |
Jens Axboe | e5b401d | 2006-10-18 16:03:40 +0200 | [diff] [blame] | 409 | } |
| 410 | |
Jens Axboe | ad2da60 | 2007-02-26 12:33:27 +0100 | [diff] [blame] | 411 | return ret; |
Jens Axboe | 3baddf2 | 2008-04-04 11:10:30 +0200 | [diff] [blame] | 412 | |
| 413 | } |
| 414 | |
| 415 | int file_invalidate_cache(struct thread_data *td, struct fio_file *f) |
| 416 | { |
Jens Axboe | d6aed79 | 2009-06-03 08:41:15 +0200 | [diff] [blame] | 417 | if (!fio_file_open(f)) |
Jens Axboe | a5fb461 | 2008-05-28 10:54:01 +0200 | [diff] [blame] | 418 | return 0; |
| 419 | |
Jens Axboe | 5e0074c | 2009-06-02 21:40:09 +0200 | [diff] [blame] | 420 | return __file_invalidate_cache(td, f, -1ULL, -1ULL); |
Jens Axboe | e5b401d | 2006-10-18 16:03:40 +0200 | [diff] [blame] | 421 | } |
| 422 | |
Jens Axboe | 6977bcd | 2008-03-01 15:55:36 +0100 | [diff] [blame] | 423 | int generic_close_file(struct thread_data fio_unused *td, struct fio_file *f) |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 424 | { |
Jens Axboe | 6977bcd | 2008-03-01 15:55:36 +0100 | [diff] [blame] | 425 | int ret = 0; |
| 426 | |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 427 | dprint(FD_FILE, "fd close %s\n", f->file_name); |
Jens Axboe | 4906e0b | 2008-03-01 18:59:51 +0100 | [diff] [blame] | 428 | |
| 429 | remove_file_hash(f); |
| 430 | |
Jens Axboe | 6977bcd | 2008-03-01 15:55:36 +0100 | [diff] [blame] | 431 | if (close(f->fd) < 0) |
| 432 | ret = errno; |
| 433 | |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 434 | f->fd = -1; |
Jens Axboe | 6977bcd | 2008-03-01 15:55:36 +0100 | [diff] [blame] | 435 | return ret; |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 436 | } |
| 437 | |
Jens Axboe | 4d4e80f | 2008-03-04 10:18:56 +0100 | [diff] [blame] | 438 | static int file_lookup_open(struct fio_file *f, int flags) |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 439 | { |
Jens Axboe | 29c1349 | 2008-03-01 19:25:20 +0100 | [diff] [blame] | 440 | struct fio_file *__f; |
Jens Axboe | 4d4e80f | 2008-03-04 10:18:56 +0100 | [diff] [blame] | 441 | int from_hash; |
| 442 | |
| 443 | __f = lookup_file_hash(f->file_name); |
| 444 | if (__f) { |
Jens Axboe | 9efef3c | 2008-03-06 10:26:25 +0100 | [diff] [blame] | 445 | dprint(FD_FILE, "found file in hash %s\n", f->file_name); |
Jens Axboe | 4d4e80f | 2008-03-04 10:18:56 +0100 | [diff] [blame] | 446 | /* |
| 447 | * racy, need the __f->lock locked |
| 448 | */ |
| 449 | f->lock = __f->lock; |
| 450 | f->lock_owner = __f->lock_owner; |
| 451 | f->lock_batch = __f->lock_batch; |
| 452 | f->lock_ddir = __f->lock_ddir; |
Jens Axboe | 4d4e80f | 2008-03-04 10:18:56 +0100 | [diff] [blame] | 453 | from_hash = 1; |
| 454 | } else { |
Jens Axboe | 9efef3c | 2008-03-06 10:26:25 +0100 | [diff] [blame] | 455 | dprint(FD_FILE, "file not found in hash %s\n", f->file_name); |
Jens Axboe | 4d4e80f | 2008-03-04 10:18:56 +0100 | [diff] [blame] | 456 | from_hash = 0; |
| 457 | } |
| 458 | |
Jens Axboe | e8670ef | 2008-03-06 12:06:30 +0100 | [diff] [blame] | 459 | f->fd = open(f->file_name, flags, 0600); |
Jens Axboe | 4d4e80f | 2008-03-04 10:18:56 +0100 | [diff] [blame] | 460 | return from_hash; |
| 461 | } |
| 462 | |
| 463 | int generic_open_file(struct thread_data *td, struct fio_file *f) |
| 464 | { |
Jens Axboe | 6615982 | 2007-04-16 21:54:24 +0200 | [diff] [blame] | 465 | int is_std = 0; |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 466 | int flags = 0; |
Jens Axboe | 29c1349 | 2008-03-01 19:25:20 +0100 | [diff] [blame] | 467 | int from_hash = 0; |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 468 | |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 469 | dprint(FD_FILE, "fd open %s\n", f->file_name); |
| 470 | |
Jens Axboe | 6615982 | 2007-04-16 21:54:24 +0200 | [diff] [blame] | 471 | if (!strcmp(f->file_name, "-")) { |
| 472 | if (td_rw(td)) { |
| 473 | log_err("fio: can't read/write to stdin/out\n"); |
| 474 | return 1; |
| 475 | } |
| 476 | is_std = 1; |
Jens Axboe | ce98fa6 | 2007-04-17 13:27:32 +0200 | [diff] [blame] | 477 | |
| 478 | /* |
| 479 | * move output logging to stderr, if we are writing to stdout |
| 480 | */ |
| 481 | if (td_write(td)) |
| 482 | f_out = stderr; |
Jens Axboe | 6615982 | 2007-04-16 21:54:24 +0200 | [diff] [blame] | 483 | } |
| 484 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 485 | if (td->o.odirect) |
Jens Axboe | 2fd233b | 2007-03-02 08:44:25 +0100 | [diff] [blame] | 486 | flags |= OS_O_DIRECT; |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 487 | if (td->o.sync_io) |
Jens Axboe | 2fd233b | 2007-03-02 08:44:25 +0100 | [diff] [blame] | 488 | flags |= O_SYNC; |
Jens Axboe | ad92396 | 2007-10-11 21:41:41 +0200 | [diff] [blame] | 489 | if (f->filetype != FIO_TYPE_FILE) |
Jens Axboe | 5921e80 | 2008-05-30 15:02:38 +0200 | [diff] [blame] | 490 | flags |= FIO_O_NOATIME; |
Jens Axboe | 814452b | 2009-03-04 12:53:13 +0100 | [diff] [blame] | 491 | if (td->o.create_on_open) |
| 492 | flags |= O_CREAT; |
Jens Axboe | 7abf833 | 2006-11-23 15:01:19 +0100 | [diff] [blame] | 493 | |
Aaron Carroll | 056f345 | 2007-11-26 09:08:53 +0100 | [diff] [blame] | 494 | open_again: |
Jens Axboe | 660a1cb | 2007-04-17 15:37:47 +0200 | [diff] [blame] | 495 | if (td_write(td)) { |
Jens Axboe | 1730815 | 2008-03-07 13:42:31 +0100 | [diff] [blame] | 496 | if (!read_only) |
| 497 | flags |= O_RDWR; |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 498 | |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 499 | if (f->filetype == FIO_TYPE_FILE) |
Jens Axboe | 2fd233b | 2007-03-02 08:44:25 +0100 | [diff] [blame] | 500 | flags |= O_CREAT; |
Jens Axboe | 2fd233b | 2007-03-02 08:44:25 +0100 | [diff] [blame] | 501 | |
Jens Axboe | 6615982 | 2007-04-16 21:54:24 +0200 | [diff] [blame] | 502 | if (is_std) |
| 503 | f->fd = dup(STDOUT_FILENO); |
Jens Axboe | 4d4e80f | 2008-03-04 10:18:56 +0100 | [diff] [blame] | 504 | else |
| 505 | from_hash = file_lookup_open(f, flags); |
Jens Axboe | 2fd233b | 2007-03-02 08:44:25 +0100 | [diff] [blame] | 506 | } else { |
Jens Axboe | 4241ea8 | 2007-09-12 08:18:36 +0200 | [diff] [blame] | 507 | if (f->filetype == FIO_TYPE_CHAR && !read_only) |
Jens Axboe | 2fd233b | 2007-03-02 08:44:25 +0100 | [diff] [blame] | 508 | flags |= O_RDWR; |
| 509 | else |
| 510 | flags |= O_RDONLY; |
| 511 | |
Jens Axboe | 6615982 | 2007-04-16 21:54:24 +0200 | [diff] [blame] | 512 | if (is_std) |
| 513 | f->fd = dup(STDIN_FILENO); |
Jens Axboe | 4d4e80f | 2008-03-04 10:18:56 +0100 | [diff] [blame] | 514 | else |
| 515 | from_hash = file_lookup_open(f, flags); |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | if (f->fd == -1) { |
Jens Axboe | e4e3325 | 2007-03-21 13:07:54 +0100 | [diff] [blame] | 519 | char buf[FIO_VERROR_SIZE]; |
Jens Axboe | e1161c3 | 2007-02-22 19:36:48 +0100 | [diff] [blame] | 520 | int __e = errno; |
| 521 | |
Jens Axboe | 835d9b9 | 2009-06-09 15:23:38 +0200 | [diff] [blame] | 522 | if (__e == EPERM && (flags & FIO_O_NOATIME)) { |
Jens Axboe | 5921e80 | 2008-05-30 15:02:38 +0200 | [diff] [blame] | 523 | flags &= ~FIO_O_NOATIME; |
Aaron Carroll | 056f345 | 2007-11-26 09:08:53 +0100 | [diff] [blame] | 524 | goto open_again; |
| 525 | } |
| 526 | |
Jens Axboe | e8670ef | 2008-03-06 12:06:30 +0100 | [diff] [blame] | 527 | snprintf(buf, sizeof(buf) - 1, "open(%s)", f->file_name); |
Jens Axboe | e4e3325 | 2007-03-21 13:07:54 +0100 | [diff] [blame] | 528 | |
| 529 | td_verror(td, __e, buf); |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 530 | } |
| 531 | |
Jens Axboe | 29c1349 | 2008-03-01 19:25:20 +0100 | [diff] [blame] | 532 | if (!from_hash && f->fd != -1) { |
| 533 | if (add_file_hash(f)) { |
Jens Axboe | 3f0ca9b | 2011-05-24 21:36:24 +0200 | [diff] [blame] | 534 | int fio_unused ret; |
Jens Axboe | 29c1349 | 2008-03-01 19:25:20 +0100 | [diff] [blame] | 535 | |
| 536 | /* |
| 537 | * OK to ignore, we haven't done anything with it |
| 538 | */ |
| 539 | ret = generic_close_file(td, f); |
| 540 | goto open_again; |
| 541 | } |
| 542 | } |
Jens Axboe | 4906e0b | 2008-03-01 18:59:51 +0100 | [diff] [blame] | 543 | |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 544 | return 0; |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 545 | } |
| 546 | |
Jens Axboe | df9c26b | 2009-03-05 10:13:58 +0100 | [diff] [blame] | 547 | int generic_get_file_size(struct thread_data *td, struct fio_file *f) |
Jens Axboe | 21972cd | 2006-11-23 12:39:16 +0100 | [diff] [blame] | 548 | { |
Jens Axboe | df9c26b | 2009-03-05 10:13:58 +0100 | [diff] [blame] | 549 | return get_file_size(td, f); |
Jens Axboe | 21972cd | 2006-11-23 12:39:16 +0100 | [diff] [blame] | 550 | } |
| 551 | |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 552 | /* |
| 553 | * open/close all files, so that ->real_file_size gets set |
| 554 | */ |
Jens Axboe | bab3fd5 | 2007-04-02 10:34:18 +0200 | [diff] [blame] | 555 | static int get_file_sizes(struct thread_data *td) |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 556 | { |
| 557 | struct fio_file *f; |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 558 | unsigned int i; |
Jens Axboe | bab3fd5 | 2007-04-02 10:34:18 +0200 | [diff] [blame] | 559 | int err = 0; |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 560 | |
| 561 | for_each_file(td, f, i) { |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 562 | dprint(FD_FILE, "get file size for %p/%d/%p\n", f, i, |
| 563 | f->file_name); |
Jens Axboe | 9efef3c | 2008-03-06 10:26:25 +0100 | [diff] [blame] | 564 | |
Jens Axboe | 99a47c6 | 2009-04-07 22:20:56 +0200 | [diff] [blame] | 565 | if (td_io_get_file_size(td, f)) { |
Jens Axboe | 40b44f4 | 2007-04-11 12:43:35 +0200 | [diff] [blame] | 566 | if (td->error != ENOENT) { |
| 567 | log_err("%s\n", td->verror); |
| 568 | err = 1; |
| 569 | } |
Jens Axboe | 541d66d | 2007-03-27 19:50:11 +0200 | [diff] [blame] | 570 | clear_error(td); |
Jens Axboe | 07eb79d | 2007-04-12 13:02:38 +0200 | [diff] [blame] | 571 | } |
Jens Axboe | 409b341 | 2007-03-28 09:57:01 +0200 | [diff] [blame] | 572 | |
| 573 | if (f->real_file_size == -1ULL && td->o.size) |
| 574 | f->real_file_size = td->o.size / td->o.nr_files; |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 575 | } |
Jens Axboe | bab3fd5 | 2007-04-02 10:34:18 +0200 | [diff] [blame] | 576 | |
| 577 | return err; |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 578 | } |
| 579 | |
Jens Axboe | 2e3bd4c | 2010-05-17 12:29:57 +0200 | [diff] [blame] | 580 | struct fio_mount { |
| 581 | struct flist_head list; |
| 582 | const char *base; |
| 583 | char __base[256]; |
| 584 | unsigned int key; |
| 585 | }; |
| 586 | |
| 587 | /* |
| 588 | * Get free number of bytes for each file on each unique mount. |
| 589 | */ |
| 590 | static unsigned long long get_fs_free_counts(struct thread_data *td) |
| 591 | { |
| 592 | struct flist_head *n, *tmp; |
Jens Axboe | 68b0316 | 2010-06-24 09:22:41 +0200 | [diff] [blame] | 593 | unsigned long long ret = 0; |
Jens Axboe | 2e3bd4c | 2010-05-17 12:29:57 +0200 | [diff] [blame] | 594 | struct fio_mount *fm; |
| 595 | FLIST_HEAD(list); |
| 596 | struct fio_file *f; |
| 597 | unsigned int i; |
| 598 | |
| 599 | for_each_file(td, f, i) { |
| 600 | struct stat sb; |
| 601 | char buf[256]; |
| 602 | |
Jens Axboe | 4ccdccd | 2010-06-24 10:27:22 +0200 | [diff] [blame] | 603 | if (f->filetype == FIO_TYPE_BD || f->filetype == FIO_TYPE_CHAR) { |
| 604 | if (f->real_file_size != -1ULL) |
| 605 | ret += f->real_file_size; |
Jens Axboe | 68b0316 | 2010-06-24 09:22:41 +0200 | [diff] [blame] | 606 | continue; |
| 607 | } else if (f->filetype != FIO_TYPE_FILE) |
| 608 | continue; |
| 609 | |
Jens Axboe | 2e3bd4c | 2010-05-17 12:29:57 +0200 | [diff] [blame] | 610 | strcpy(buf, f->file_name); |
| 611 | |
| 612 | if (stat(buf, &sb) < 0) { |
| 613 | if (errno != ENOENT) |
| 614 | break; |
| 615 | strcpy(buf, "."); |
| 616 | if (stat(buf, &sb) < 0) |
| 617 | break; |
| 618 | } |
| 619 | |
| 620 | fm = NULL; |
| 621 | flist_for_each(n, &list) { |
| 622 | fm = flist_entry(n, struct fio_mount, list); |
| 623 | if (fm->key == sb.st_dev) |
| 624 | break; |
| 625 | |
| 626 | fm = NULL; |
| 627 | } |
| 628 | |
| 629 | if (fm) |
| 630 | continue; |
| 631 | |
| 632 | fm = malloc(sizeof(*fm)); |
| 633 | strcpy(fm->__base, buf); |
| 634 | fm->base = basename(fm->__base); |
| 635 | fm->key = sb.st_dev; |
| 636 | flist_add(&fm->list, &list); |
| 637 | } |
| 638 | |
Jens Axboe | 2e3bd4c | 2010-05-17 12:29:57 +0200 | [diff] [blame] | 639 | flist_for_each_safe(n, tmp, &list) { |
| 640 | unsigned long long sz; |
| 641 | |
| 642 | fm = flist_entry(n, struct fio_mount, list); |
| 643 | flist_del(&fm->list); |
| 644 | |
| 645 | sz = get_fs_size(fm->base); |
| 646 | if (sz && sz != -1ULL) |
| 647 | ret += sz; |
| 648 | |
| 649 | free(fm); |
| 650 | } |
| 651 | |
| 652 | return ret; |
| 653 | } |
| 654 | |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 655 | /* |
| 656 | * Open the files and setup files sizes, creating files if necessary. |
| 657 | */ |
| 658 | int setup_files(struct thread_data *td) |
| 659 | { |
| 660 | unsigned long long total_size, extend_size; |
| 661 | struct fio_file *f; |
| 662 | unsigned int i; |
Jens Axboe | 000b080 | 2007-03-27 15:56:10 +0200 | [diff] [blame] | 663 | int err = 0, need_extend; |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 664 | |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 665 | dprint(FD_FILE, "setup files\n"); |
| 666 | |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 667 | if (td->o.read_iolog_file) |
| 668 | return 0; |
| 669 | |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 670 | /* |
| 671 | * if ioengine defines a setup() method, it's responsible for |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 672 | * opening the files and setting f->real_file_size to indicate |
| 673 | * the valid range for that file. |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 674 | */ |
| 675 | if (td->io_ops->setup) |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 676 | err = td->io_ops->setup(td); |
| 677 | else |
Jens Axboe | bab3fd5 | 2007-04-02 10:34:18 +0200 | [diff] [blame] | 678 | err = get_file_sizes(td); |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 679 | |
Jens Axboe | f102706 | 2006-10-20 10:14:01 +0200 | [diff] [blame] | 680 | if (err) |
| 681 | return err; |
| 682 | |
Jens Axboe | 0a7eb12 | 2006-10-20 10:36:42 +0200 | [diff] [blame] | 683 | /* |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 684 | * check sizes. if the files/devices do not exist and the size |
| 685 | * isn't passed to fio, abort. |
Jens Axboe | 0a7eb12 | 2006-10-20 10:36:42 +0200 | [diff] [blame] | 686 | */ |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 687 | total_size = 0; |
| 688 | for_each_file(td, f, i) { |
| 689 | if (f->real_file_size == -1ULL) |
| 690 | total_size = -1ULL; |
| 691 | else |
| 692 | total_size += f->real_file_size; |
| 693 | } |
Jens Axboe | 0a7eb12 | 2006-10-20 10:36:42 +0200 | [diff] [blame] | 694 | |
Jens Axboe | 2e3bd4c | 2010-05-17 12:29:57 +0200 | [diff] [blame] | 695 | if (td->o.fill_device) |
| 696 | td->fill_device_size = get_fs_free_counts(td); |
| 697 | |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 698 | /* |
| 699 | * device/file sizes are zero and no size given, punt |
| 700 | */ |
Jens Axboe | 1f809d1 | 2007-10-25 18:34:02 +0200 | [diff] [blame] | 701 | if ((!total_size || total_size == -1ULL) && !td->o.size && |
Shawn Lewis | aa31f1f | 2008-01-11 09:45:11 +0100 | [diff] [blame] | 702 | !(td->io_ops->flags & FIO_NOIO) && !td->o.fill_device) { |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 703 | log_err("%s: you need to specify size=\n", td->o.name); |
Jens Axboe | e1161c3 | 2007-02-22 19:36:48 +0100 | [diff] [blame] | 704 | td_verror(td, EINVAL, "total_file_size"); |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 705 | return 1; |
| 706 | } |
| 707 | |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 708 | /* |
| 709 | * now file sizes are known, so we can set ->io_size. if size= is |
| 710 | * not given, ->io_size is just equal to ->real_file_size. if size |
| 711 | * is given, ->io_size is size / nr_files. |
| 712 | */ |
| 713 | extend_size = total_size = 0; |
| 714 | need_extend = 0; |
| 715 | for_each_file(td, f, i) { |
ljzhang,Yaxin Hu,Jianchao Tang | bcdedd0 | 2007-07-27 13:28:26 +0200 | [diff] [blame] | 716 | f->file_offset = td->o.start_offset; |
| 717 | |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 718 | if (!td->o.file_size_low) { |
| 719 | /* |
| 720 | * no file size range given, file size is equal to |
| 721 | * total size divided by number of files. if that is |
| 722 | * zero, set it to the real file size. |
| 723 | */ |
| 724 | f->io_size = td->o.size / td->o.nr_files; |
Jens Axboe | 65bdb10 | 2008-01-24 13:13:12 +0100 | [diff] [blame] | 725 | if (!f->io_size) |
Jens Axboe | 273f8c9 | 2008-01-25 14:02:15 +0100 | [diff] [blame] | 726 | f->io_size = f->real_file_size - f->file_offset; |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 727 | } else if (f->real_file_size < td->o.file_size_low || |
| 728 | f->real_file_size > td->o.file_size_high) { |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 729 | if (f->file_offset > td->o.file_size_low) |
ljzhang,Yaxin Hu,Jianchao Tang | bcdedd0 | 2007-07-27 13:28:26 +0200 | [diff] [blame] | 730 | goto err_offset; |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 731 | /* |
| 732 | * file size given. if it's fixed, use that. if it's a |
| 733 | * range, generate a random size in-between. |
| 734 | */ |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 735 | if (td->o.file_size_low == td->o.file_size_high) { |
| 736 | f->io_size = td->o.file_size_low |
| 737 | - f->file_offset; |
| 738 | } else { |
| 739 | f->io_size = get_rand_file_size(td) |
| 740 | - f->file_offset; |
| 741 | } |
Jens Axboe | 65bdb10 | 2008-01-24 13:13:12 +0100 | [diff] [blame] | 742 | } else |
ljzhang,Yaxin Hu,Jianchao Tang | bcdedd0 | 2007-07-27 13:28:26 +0200 | [diff] [blame] | 743 | f->io_size = f->real_file_size - f->file_offset; |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 744 | |
| 745 | if (f->io_size == -1ULL) |
| 746 | total_size = -1ULL; |
| 747 | else |
| 748 | total_size += f->io_size; |
| 749 | |
| 750 | if (f->filetype == FIO_TYPE_FILE && |
ljzhang,Yaxin Hu,Jianchao Tang | bcdedd0 | 2007-07-27 13:28:26 +0200 | [diff] [blame] | 751 | (f->io_size + f->file_offset) > f->real_file_size && |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 752 | !(td->io_ops->flags & FIO_DISKLESSIO)) { |
Jens Axboe | 814452b | 2009-03-04 12:53:13 +0100 | [diff] [blame] | 753 | if (!td->o.create_on_open) { |
| 754 | need_extend++; |
| 755 | extend_size += (f->io_size + f->file_offset); |
| 756 | } else |
| 757 | f->real_file_size = f->io_size + f->file_offset; |
Jens Axboe | d6aed79 | 2009-06-03 08:41:15 +0200 | [diff] [blame] | 758 | fio_file_set_extend(f); |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 759 | } |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 760 | } |
| 761 | |
Jens Axboe | 7bb5910 | 2011-07-12 19:47:03 +0200 | [diff] [blame] | 762 | if (td->o.size_percent) |
| 763 | total_size = (total_size * td->o.size_percent) / 100; |
| 764 | |
ljzhang,Yaxin Hu,Jianchao Tang | 2298290 | 2007-07-27 13:21:28 +0200 | [diff] [blame] | 765 | if (!td->o.size || td->o.size > total_size) |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 766 | td->o.size = total_size; |
| 767 | |
| 768 | /* |
| 769 | * See if we need to extend some files |
| 770 | */ |
| 771 | if (need_extend) { |
| 772 | temp_stall_ts = 1; |
Shaozhi Shawn Ye | a7ba8c5 | 2008-09-10 09:04:18 +0200 | [diff] [blame] | 773 | if (!terse_output) |
| 774 | log_info("%s: Laying out IO file(s) (%u file(s) /" |
Bruce Cran | 0f2152c | 2010-12-15 10:33:03 +0100 | [diff] [blame] | 775 | " %lluMB)\n", td->o.name, need_extend, |
Shaozhi Shawn Ye | a7ba8c5 | 2008-09-10 09:04:18 +0200 | [diff] [blame] | 776 | extend_size >> 20); |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 777 | |
| 778 | for_each_file(td, f, i) { |
Jens Axboe | 5e0074c | 2009-06-02 21:40:09 +0200 | [diff] [blame] | 779 | unsigned long long old_len = -1ULL, extend_len = -1ULL; |
Jens Axboe | 3baddf2 | 2008-04-04 11:10:30 +0200 | [diff] [blame] | 780 | |
Jens Axboe | d6aed79 | 2009-06-03 08:41:15 +0200 | [diff] [blame] | 781 | if (!fio_file_extend(f)) |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 782 | continue; |
| 783 | |
Jens Axboe | 409b341 | 2007-03-28 09:57:01 +0200 | [diff] [blame] | 784 | assert(f->filetype == FIO_TYPE_FILE); |
Jens Axboe | d6aed79 | 2009-06-03 08:41:15 +0200 | [diff] [blame] | 785 | fio_file_clear_extend(f); |
Jens Axboe | 5e0074c | 2009-06-02 21:40:09 +0200 | [diff] [blame] | 786 | if (!td->o.fill_device) { |
| 787 | old_len = f->real_file_size; |
Jens Axboe | 0b9d69e | 2009-09-11 22:29:54 +0200 | [diff] [blame] | 788 | extend_len = f->io_size + f->file_offset - |
| 789 | old_len; |
Jens Axboe | 5e0074c | 2009-06-02 21:40:09 +0200 | [diff] [blame] | 790 | } |
ljzhang,Yaxin Hu,Jianchao Tang | bcdedd0 | 2007-07-27 13:28:26 +0200 | [diff] [blame] | 791 | f->real_file_size = (f->io_size + f->file_offset); |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 792 | err = extend_file(td, f); |
| 793 | if (err) |
| 794 | break; |
Jens Axboe | 5e0074c | 2009-06-02 21:40:09 +0200 | [diff] [blame] | 795 | |
Jens Axboe | 3baddf2 | 2008-04-04 11:10:30 +0200 | [diff] [blame] | 796 | err = __file_invalidate_cache(td, f, old_len, |
| 797 | extend_len); |
| 798 | close(f->fd); |
| 799 | f->fd = -1; |
| 800 | if (err) |
| 801 | break; |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 802 | } |
| 803 | temp_stall_ts = 0; |
| 804 | } |
| 805 | |
| 806 | if (err) |
| 807 | return err; |
| 808 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 809 | if (!td->o.zone_size) |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 810 | td->o.zone_size = td->o.size; |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 811 | |
Jens Axboe | ea966f8 | 2007-09-03 10:09:37 +0200 | [diff] [blame] | 812 | /* |
| 813 | * iolog already set the total io size, if we read back |
| 814 | * stored entries. |
| 815 | */ |
| 816 | if (!td->o.read_iolog_file) |
| 817 | td->total_io_size = td->o.size * td->o.loops; |
Jens Axboe | 7bb48f8 | 2007-03-27 15:30:28 +0200 | [diff] [blame] | 818 | return 0; |
ljzhang,Yaxin Hu,Jianchao Tang | bcdedd0 | 2007-07-27 13:28:26 +0200 | [diff] [blame] | 819 | err_offset: |
| 820 | log_err("%s: you need to specify valid offset=\n", td->o.name); |
| 821 | return 1; |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 822 | } |
| 823 | |
Zhang, Yanmin | afad68f | 2009-05-20 11:30:55 +0200 | [diff] [blame] | 824 | int pre_read_files(struct thread_data *td) |
| 825 | { |
| 826 | struct fio_file *f; |
| 827 | unsigned int i; |
| 828 | |
| 829 | dprint(FD_FILE, "pre_read files\n"); |
| 830 | |
| 831 | for_each_file(td, f, i) { |
| 832 | pre_read_file(td, f); |
| 833 | } |
| 834 | |
| 835 | return 1; |
| 836 | } |
| 837 | |
Jens Axboe | 6872707 | 2007-03-15 20:49:25 +0100 | [diff] [blame] | 838 | int init_random_map(struct thread_data *td) |
| 839 | { |
Jens Axboe | 509eab1 | 2007-12-14 12:42:53 +0100 | [diff] [blame] | 840 | unsigned long long blocks, num_maps; |
Jens Axboe | 6872707 | 2007-03-15 20:49:25 +0100 | [diff] [blame] | 841 | struct fio_file *f; |
| 842 | unsigned int i; |
| 843 | |
Jens Axboe | de8dd11 | 2008-03-01 15:34:44 +0100 | [diff] [blame] | 844 | if (td->o.norandommap || !td_random(td)) |
Jens Axboe | 6872707 | 2007-03-15 20:49:25 +0100 | [diff] [blame] | 845 | return 0; |
| 846 | |
| 847 | for_each_file(td, f, i) { |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 848 | blocks = (f->real_file_size + td->o.rw_min_bs - 1) / |
| 849 | (unsigned long long) td->o.rw_min_bs; |
| 850 | num_maps = (blocks + BLOCKS_PER_MAP - 1) / |
| 851 | (unsigned long long) BLOCKS_PER_MAP; |
Jens Axboe | ceadd59 | 2012-02-02 08:41:28 +0100 | [diff] [blame] | 852 | if (num_maps == (unsigned long) num_maps) { |
| 853 | f->file_map = smalloc(num_maps * sizeof(unsigned long)); |
| 854 | if (f->file_map) { |
| 855 | f->num_maps = num_maps; |
| 856 | continue; |
| 857 | } |
| 858 | } else |
| 859 | f->file_map = NULL; |
| 860 | |
Jens Axboe | 2b386d2 | 2008-03-26 10:32:57 +0100 | [diff] [blame] | 861 | if (!td->o.softrandommap) { |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 862 | log_err("fio: failed allocating random map. If running" |
| 863 | " a large number of jobs, try the 'norandommap'" |
Jens Axboe | 2b386d2 | 2008-03-26 10:32:57 +0100 | [diff] [blame] | 864 | " option or set 'softrandommap'. Or give" |
| 865 | " a larger --alloc-size to fio.\n"); |
Jens Axboe | 6872707 | 2007-03-15 20:49:25 +0100 | [diff] [blame] | 866 | return 1; |
| 867 | } |
Jens Axboe | 303032a | 2008-03-26 10:11:10 +0100 | [diff] [blame] | 868 | |
| 869 | log_info("fio: file %s failed allocating random map. Running " |
| 870 | "job without.\n", f->file_name); |
| 871 | f->num_maps = 0; |
Jens Axboe | 6872707 | 2007-03-15 20:49:25 +0100 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | return 0; |
| 875 | } |
| 876 | |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 877 | void close_files(struct thread_data *td) |
| 878 | { |
Jens Axboe | 0ab8db8 | 2006-10-18 17:16:23 +0200 | [diff] [blame] | 879 | struct fio_file *f; |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 880 | unsigned int i; |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 881 | |
Jens Axboe | 2be3eec | 2009-06-10 09:05:13 +0200 | [diff] [blame] | 882 | for_each_file(td, f, i) { |
| 883 | if (fio_file_open(f)) |
| 884 | td_io_close_file(td, f); |
| 885 | } |
Jens Axboe | 24ffd2c | 2008-03-01 15:47:08 +0100 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | void close_and_free_files(struct thread_data *td) |
| 889 | { |
| 890 | struct fio_file *f; |
| 891 | unsigned int i; |
| 892 | |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 893 | dprint(FD_FILE, "close files\n"); |
| 894 | |
Jens Axboe | 0ab8db8 | 2006-10-18 17:16:23 +0200 | [diff] [blame] | 895 | for_each_file(td, f, i) { |
Jens Axboe | ffdfabd | 2008-03-26 09:18:14 +0100 | [diff] [blame] | 896 | if (td->o.unlink && f->filetype == FIO_TYPE_FILE) { |
| 897 | dprint(FD_FILE, "free unlink %s\n", f->file_name); |
Jens Axboe | 132ad46 | 2006-11-23 12:23:12 +0100 | [diff] [blame] | 898 | unlink(f->file_name); |
Jens Axboe | ffdfabd | 2008-03-26 09:18:14 +0100 | [diff] [blame] | 899 | } |
Jens Axboe | bdb4e2e | 2007-03-01 09:54:57 +0100 | [diff] [blame] | 900 | |
Jens Axboe | 22a57ba | 2009-06-09 14:34:35 +0200 | [diff] [blame] | 901 | if (fio_file_open(f)) |
| 902 | td_io_close_file(td, f); |
| 903 | |
Shaozhi Shawn Ye | b9fbcf2 | 2008-09-10 09:05:17 +0200 | [diff] [blame] | 904 | remove_file_hash(f); |
Jens Axboe | b3dc7f0 | 2007-03-09 12:52:15 +0100 | [diff] [blame] | 905 | |
Jens Axboe | f17c439 | 2008-03-01 18:40:46 +0100 | [diff] [blame] | 906 | sfree(f->file_name); |
Jens Axboe | fa1da86 | 2007-03-23 15:20:54 +0100 | [diff] [blame] | 907 | f->file_name = NULL; |
Jens Axboe | 61eb313 | 2010-03-31 20:05:59 +0200 | [diff] [blame] | 908 | sfree(f->file_map); |
| 909 | f->file_map = NULL; |
Jens Axboe | 78d99e6 | 2008-03-01 18:41:50 +0100 | [diff] [blame] | 910 | sfree(f); |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 911 | } |
Jens Axboe | b4a6a59 | 2006-10-20 13:54:47 +0200 | [diff] [blame] | 912 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 913 | td->o.filename = NULL; |
Jens Axboe | cade3ef | 2007-03-23 15:29:45 +0100 | [diff] [blame] | 914 | free(td->files); |
Jens Axboe | 9efef3c | 2008-03-06 10:26:25 +0100 | [diff] [blame] | 915 | td->files_index = 0; |
Jens Axboe | b4a6a59 | 2006-10-20 13:54:47 +0200 | [diff] [blame] | 916 | td->files = NULL; |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 917 | td->o.nr_files = 0; |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 918 | } |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 919 | |
Jens Axboe | e3bab46 | 2007-03-13 11:22:09 +0100 | [diff] [blame] | 920 | static void get_file_type(struct fio_file *f) |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 921 | { |
| 922 | struct stat sb; |
| 923 | |
Jens Axboe | 6615982 | 2007-04-16 21:54:24 +0200 | [diff] [blame] | 924 | if (!strcmp(f->file_name, "-")) |
| 925 | f->filetype = FIO_TYPE_PIPE; |
| 926 | else |
| 927 | f->filetype = FIO_TYPE_FILE; |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 928 | |
Jens Axboe | b30d395 | 2010-02-06 23:36:26 +0100 | [diff] [blame] | 929 | if (!stat(f->file_name, &sb)) { |
Bruce Cran | ecc314b | 2011-01-04 10:59:30 +0100 | [diff] [blame] | 930 | /* \\.\ is the device namespace in Windows, where every file is |
| 931 | * a block device */ |
| 932 | if (S_ISBLK(sb.st_mode) || strncmp(f->file_name, "\\\\.\\", 4) == 0) |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 933 | f->filetype = FIO_TYPE_BD; |
| 934 | else if (S_ISCHR(sb.st_mode)) |
| 935 | f->filetype = FIO_TYPE_CHAR; |
Jens Axboe | b5605e9 | 2007-04-16 20:42:33 +0200 | [diff] [blame] | 936 | else if (S_ISFIFO(sb.st_mode)) |
| 937 | f->filetype = FIO_TYPE_PIPE; |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 938 | } |
| 939 | } |
| 940 | |
Jens Axboe | f29b25a | 2007-07-23 08:56:43 +0200 | [diff] [blame] | 941 | int add_file(struct thread_data *td, const char *fname) |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 942 | { |
Jens Axboe | 7b4e4fe | 2007-03-13 12:51:40 +0100 | [diff] [blame] | 943 | int cur_files = td->files_index; |
Jens Axboe | bd0ee74 | 2007-03-23 14:26:23 +0100 | [diff] [blame] | 944 | char file_name[PATH_MAX]; |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 945 | struct fio_file *f; |
Jens Axboe | bd0ee74 | 2007-03-23 14:26:23 +0100 | [diff] [blame] | 946 | int len = 0; |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 947 | |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 948 | dprint(FD_FILE, "add file %s\n", fname); |
| 949 | |
Jens Axboe | f17c439 | 2008-03-01 18:40:46 +0100 | [diff] [blame] | 950 | f = smalloc(sizeof(*f)); |
Jens Axboe | c48c0be | 2008-07-31 19:55:02 +0200 | [diff] [blame] | 951 | if (!f) { |
| 952 | log_err("fio: smalloc OOM\n"); |
| 953 | assert(0); |
| 954 | } |
Jens Axboe | 0b9d69e | 2009-09-11 22:29:54 +0200 | [diff] [blame] | 955 | |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 956 | f->fd = -1; |
Jens Axboe | 38dad62 | 2010-07-20 14:46:00 -0600 | [diff] [blame] | 957 | fio_file_reset(f); |
Jens Axboe | bd0ee74 | 2007-03-23 14:26:23 +0100 | [diff] [blame] | 958 | |
Jens Axboe | fc99bc0 | 2009-03-04 15:27:42 +0100 | [diff] [blame] | 959 | if (td->files_size <= td->files_index) { |
Carl Henrik Lunde | 4b341fc | 2009-04-20 08:41:37 +0200 | [diff] [blame] | 960 | int new_size = td->o.nr_files + 1; |
Jens Axboe | 126d65c | 2008-03-01 18:04:31 +0100 | [diff] [blame] | 961 | |
Jens Axboe | fc99bc0 | 2009-03-04 15:27:42 +0100 | [diff] [blame] | 962 | dprint(FD_FILE, "resize file array to %d files\n", new_size); |
| 963 | |
| 964 | td->files = realloc(td->files, new_size * sizeof(f)); |
Jens Axboe | fc99bc0 | 2009-03-04 15:27:42 +0100 | [diff] [blame] | 965 | td->files_size = new_size; |
| 966 | } |
Jens Axboe | 8bb7679 | 2009-03-04 15:37:52 +0100 | [diff] [blame] | 967 | td->files[cur_files] = f; |
Jens Axboe | 126d65c | 2008-03-01 18:04:31 +0100 | [diff] [blame] | 968 | |
Jens Axboe | 07eb79d | 2007-04-12 13:02:38 +0200 | [diff] [blame] | 969 | /* |
| 970 | * init function, io engine may not be loaded yet |
| 971 | */ |
| 972 | if (td->io_ops && (td->io_ops->flags & FIO_DISKLESSIO)) |
| 973 | f->real_file_size = -1ULL; |
| 974 | |
Jens Axboe | bd0ee74 | 2007-03-23 14:26:23 +0100 | [diff] [blame] | 975 | if (td->o.directory) |
| 976 | len = sprintf(file_name, "%s/", td->o.directory); |
| 977 | |
| 978 | sprintf(file_name + len, "%s", fname); |
Jens Axboe | f17c439 | 2008-03-01 18:40:46 +0100 | [diff] [blame] | 979 | f->file_name = smalloc_strdup(file_name); |
Jens Axboe | c48c0be | 2008-07-31 19:55:02 +0200 | [diff] [blame] | 980 | if (!f->file_name) { |
| 981 | log_err("fio: smalloc OOM\n"); |
| 982 | assert(0); |
| 983 | } |
Jens Axboe | 0b9d69e | 2009-09-11 22:29:54 +0200 | [diff] [blame] | 984 | |
Jens Axboe | e3bab46 | 2007-03-13 11:22:09 +0100 | [diff] [blame] | 985 | get_file_type(f); |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 986 | |
Jens Axboe | 4d4e80f | 2008-03-04 10:18:56 +0100 | [diff] [blame] | 987 | switch (td->o.file_lock_mode) { |
| 988 | case FILE_LOCK_NONE: |
| 989 | break; |
| 990 | case FILE_LOCK_READWRITE: |
| 991 | f->lock = fio_mutex_rw_init(); |
| 992 | break; |
| 993 | case FILE_LOCK_EXCLUSIVE: |
| 994 | f->lock = fio_mutex_init(1); |
| 995 | break; |
| 996 | default: |
| 997 | log_err("fio: unknown lock mode: %d\n", td->o.file_lock_mode); |
| 998 | assert(0); |
| 999 | } |
Jens Axboe | 29c1349 | 2008-03-01 19:25:20 +0100 | [diff] [blame] | 1000 | |
Jens Axboe | 7b4e4fe | 2007-03-13 12:51:40 +0100 | [diff] [blame] | 1001 | td->files_index++; |
Jens Axboe | 1549441 | 2007-03-13 11:52:47 +0100 | [diff] [blame] | 1002 | if (f->filetype == FIO_TYPE_FILE) |
| 1003 | td->nr_normal_files++; |
Jens Axboe | f29b25a | 2007-07-23 08:56:43 +0200 | [diff] [blame] | 1004 | |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 1005 | dprint(FD_FILE, "file %p \"%s\" added at %d\n", f, f->file_name, |
| 1006 | cur_files); |
Jens Axboe | 9efef3c | 2008-03-06 10:26:25 +0100 | [diff] [blame] | 1007 | |
Jens Axboe | f29b25a | 2007-07-23 08:56:43 +0200 | [diff] [blame] | 1008 | return cur_files; |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 1009 | } |
Jens Axboe | 0ad920e | 2007-03-13 11:06:45 +0100 | [diff] [blame] | 1010 | |
Jens Axboe | 49ffb4a | 2010-08-24 15:01:37 +0200 | [diff] [blame] | 1011 | int add_file_exclusive(struct thread_data *td, const char *fname) |
| 1012 | { |
| 1013 | struct fio_file *f; |
| 1014 | unsigned int i; |
| 1015 | |
| 1016 | for_each_file(td, f, i) { |
| 1017 | if (!strcmp(f->file_name, fname)) |
| 1018 | return i; |
| 1019 | } |
| 1020 | |
| 1021 | return add_file(td, fname); |
| 1022 | } |
| 1023 | |
Jens Axboe | 0ad920e | 2007-03-13 11:06:45 +0100 | [diff] [blame] | 1024 | void get_file(struct fio_file *f) |
| 1025 | { |
Jens Axboe | 8172fe9 | 2008-02-01 21:51:02 +0100 | [diff] [blame] | 1026 | dprint(FD_FILE, "get file %s, ref=%d\n", f->file_name, f->references); |
Jens Axboe | d6aed79 | 2009-06-03 08:41:15 +0200 | [diff] [blame] | 1027 | assert(fio_file_open(f)); |
Jens Axboe | 0ad920e | 2007-03-13 11:06:45 +0100 | [diff] [blame] | 1028 | f->references++; |
| 1029 | } |
| 1030 | |
Jens Axboe | 6977bcd | 2008-03-01 15:55:36 +0100 | [diff] [blame] | 1031 | int put_file(struct thread_data *td, struct fio_file *f) |
Jens Axboe | 0ad920e | 2007-03-13 11:06:45 +0100 | [diff] [blame] | 1032 | { |
Jens Axboe | 98e1ac4 | 2008-03-06 11:56:48 +0100 | [diff] [blame] | 1033 | int f_ret = 0, ret = 0; |
Jens Axboe | 6977bcd | 2008-03-01 15:55:36 +0100 | [diff] [blame] | 1034 | |
Jens Axboe | 8172fe9 | 2008-02-01 21:51:02 +0100 | [diff] [blame] | 1035 | dprint(FD_FILE, "put file %s, ref=%d\n", f->file_name, f->references); |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 1036 | |
Jens Axboe | 22a57ba | 2009-06-09 14:34:35 +0200 | [diff] [blame] | 1037 | if (!fio_file_open(f)) { |
| 1038 | assert(f->fd == -1); |
Jens Axboe | 6977bcd | 2008-03-01 15:55:36 +0100 | [diff] [blame] | 1039 | return 0; |
Jens Axboe | 22a57ba | 2009-06-09 14:34:35 +0200 | [diff] [blame] | 1040 | } |
Jens Axboe | 0ad920e | 2007-03-13 11:06:45 +0100 | [diff] [blame] | 1041 | |
| 1042 | assert(f->references); |
| 1043 | if (--f->references) |
Jens Axboe | 6977bcd | 2008-03-01 15:55:36 +0100 | [diff] [blame] | 1044 | return 0; |
Jens Axboe | 0ad920e | 2007-03-13 11:06:45 +0100 | [diff] [blame] | 1045 | |
Jens Axboe | d424d4d | 2007-04-17 09:05:10 +0200 | [diff] [blame] | 1046 | if (should_fsync(td) && td->o.fsync_on_close) |
Jens Axboe | 98e1ac4 | 2008-03-06 11:56:48 +0100 | [diff] [blame] | 1047 | f_ret = fsync(f->fd); |
Jens Axboe | ebb1415 | 2007-03-13 14:42:15 +0100 | [diff] [blame] | 1048 | |
Jens Axboe | 0ad920e | 2007-03-13 11:06:45 +0100 | [diff] [blame] | 1049 | if (td->io_ops->close_file) |
Jens Axboe | 6977bcd | 2008-03-01 15:55:36 +0100 | [diff] [blame] | 1050 | ret = td->io_ops->close_file(td, f); |
Jens Axboe | 1020a13 | 2007-03-29 11:15:06 +0200 | [diff] [blame] | 1051 | |
Jens Axboe | 98e1ac4 | 2008-03-06 11:56:48 +0100 | [diff] [blame] | 1052 | if (!ret) |
Jens Axboe | a5fb461 | 2008-05-28 10:54:01 +0200 | [diff] [blame] | 1053 | ret = f_ret; |
Jens Axboe | 98e1ac4 | 2008-03-06 11:56:48 +0100 | [diff] [blame] | 1054 | |
Jens Axboe | 0ad920e | 2007-03-13 11:06:45 +0100 | [diff] [blame] | 1055 | td->nr_open_files--; |
Jens Axboe | d6aed79 | 2009-06-03 08:41:15 +0200 | [diff] [blame] | 1056 | fio_file_clear_open(f); |
Jens Axboe | 22a57ba | 2009-06-09 14:34:35 +0200 | [diff] [blame] | 1057 | assert(f->fd == -1); |
Jens Axboe | 6977bcd | 2008-03-01 15:55:36 +0100 | [diff] [blame] | 1058 | return ret; |
Jens Axboe | 0ad920e | 2007-03-13 11:06:45 +0100 | [diff] [blame] | 1059 | } |
Jens Axboe | bbf6b54 | 2007-03-13 15:28:55 +0100 | [diff] [blame] | 1060 | |
Jens Axboe | 4d4e80f | 2008-03-04 10:18:56 +0100 | [diff] [blame] | 1061 | void lock_file(struct thread_data *td, struct fio_file *f, enum fio_ddir ddir) |
Jens Axboe | b2bd2bd | 2008-03-01 18:19:52 +0100 | [diff] [blame] | 1062 | { |
Jens Axboe | 4d4e80f | 2008-03-04 10:18:56 +0100 | [diff] [blame] | 1063 | if (!f->lock || td->o.file_lock_mode == FILE_LOCK_NONE) |
| 1064 | return; |
Jens Axboe | 29c1349 | 2008-03-01 19:25:20 +0100 | [diff] [blame] | 1065 | |
Jens Axboe | 4d4e80f | 2008-03-04 10:18:56 +0100 | [diff] [blame] | 1066 | if (f->lock_owner == td && f->lock_batch--) |
| 1067 | return; |
| 1068 | |
| 1069 | if (td->o.file_lock_mode == FILE_LOCK_READWRITE) { |
| 1070 | if (ddir == DDIR_READ) |
| 1071 | fio_mutex_down_read(f->lock); |
| 1072 | else |
| 1073 | fio_mutex_down_write(f->lock); |
| 1074 | } else if (td->o.file_lock_mode == FILE_LOCK_EXCLUSIVE) |
| 1075 | fio_mutex_down(f->lock); |
| 1076 | |
| 1077 | f->lock_owner = td; |
| 1078 | f->lock_batch = td->o.lockfile_batch; |
| 1079 | f->lock_ddir = ddir; |
| 1080 | } |
| 1081 | |
| 1082 | void unlock_file(struct thread_data *td, struct fio_file *f) |
| 1083 | { |
| 1084 | if (!f->lock || td->o.file_lock_mode == FILE_LOCK_NONE) |
| 1085 | return; |
| 1086 | if (f->lock_batch) |
| 1087 | return; |
| 1088 | |
| 1089 | if (td->o.file_lock_mode == FILE_LOCK_READWRITE) { |
| 1090 | const int is_read = f->lock_ddir == DDIR_READ; |
| 1091 | int val = fio_mutex_getval(f->lock); |
| 1092 | |
| 1093 | if ((is_read && val == 1) || (!is_read && val == -1)) |
| 1094 | f->lock_owner = NULL; |
| 1095 | |
| 1096 | if (is_read) |
| 1097 | fio_mutex_up_read(f->lock); |
| 1098 | else |
| 1099 | fio_mutex_up_write(f->lock); |
| 1100 | } else if (td->o.file_lock_mode == FILE_LOCK_EXCLUSIVE) { |
| 1101 | int val = fio_mutex_getval(f->lock); |
| 1102 | |
| 1103 | if (val == 0) |
| 1104 | f->lock_owner = NULL; |
| 1105 | |
| 1106 | fio_mutex_up(f->lock); |
Jens Axboe | 29c1349 | 2008-03-01 19:25:20 +0100 | [diff] [blame] | 1107 | } |
Jens Axboe | b2bd2bd | 2008-03-01 18:19:52 +0100 | [diff] [blame] | 1108 | } |
| 1109 | |
Jens Axboe | 4d4e80f | 2008-03-04 10:18:56 +0100 | [diff] [blame] | 1110 | void unlock_file_all(struct thread_data *td, struct fio_file *f) |
Jens Axboe | b2bd2bd | 2008-03-01 18:19:52 +0100 | [diff] [blame] | 1111 | { |
Jens Axboe | 4d4e80f | 2008-03-04 10:18:56 +0100 | [diff] [blame] | 1112 | if (f->lock_owner != td) |
| 1113 | return; |
Jens Axboe | 29c1349 | 2008-03-01 19:25:20 +0100 | [diff] [blame] | 1114 | |
Jens Axboe | 4d4e80f | 2008-03-04 10:18:56 +0100 | [diff] [blame] | 1115 | f->lock_batch = 0; |
| 1116 | unlock_file(td, f); |
Jens Axboe | b2bd2bd | 2008-03-01 18:19:52 +0100 | [diff] [blame] | 1117 | } |
| 1118 | |
Jens Axboe | bbf6b54 | 2007-03-13 15:28:55 +0100 | [diff] [blame] | 1119 | static int recurse_dir(struct thread_data *td, const char *dirname) |
| 1120 | { |
| 1121 | struct dirent *dir; |
| 1122 | int ret = 0; |
| 1123 | DIR *D; |
| 1124 | |
| 1125 | D = opendir(dirname); |
| 1126 | if (!D) { |
Jens Axboe | 0ddb270 | 2007-03-27 19:43:53 +0200 | [diff] [blame] | 1127 | char buf[FIO_VERROR_SIZE]; |
| 1128 | |
| 1129 | snprintf(buf, FIO_VERROR_SIZE - 1, "opendir(%s)", dirname); |
| 1130 | td_verror(td, errno, buf); |
Jens Axboe | bbf6b54 | 2007-03-13 15:28:55 +0100 | [diff] [blame] | 1131 | return 1; |
| 1132 | } |
| 1133 | |
| 1134 | while ((dir = readdir(D)) != NULL) { |
| 1135 | char full_path[PATH_MAX]; |
| 1136 | struct stat sb; |
| 1137 | |
Jens Axboe | e85b2b8 | 2007-03-14 09:39:06 +0100 | [diff] [blame] | 1138 | if (!strcmp(dir->d_name, ".") || !strcmp(dir->d_name, "..")) |
| 1139 | continue; |
Jens Axboe | 96d32d5 | 2007-03-14 09:16:09 +0100 | [diff] [blame] | 1140 | |
Jens Axboe | bbf6b54 | 2007-03-13 15:28:55 +0100 | [diff] [blame] | 1141 | sprintf(full_path, "%s/%s", dirname, dir->d_name); |
| 1142 | |
| 1143 | if (lstat(full_path, &sb) == -1) { |
| 1144 | if (errno != ENOENT) { |
| 1145 | td_verror(td, errno, "stat"); |
| 1146 | return 1; |
| 1147 | } |
| 1148 | } |
| 1149 | |
| 1150 | if (S_ISREG(sb.st_mode)) { |
| 1151 | add_file(td, full_path); |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 1152 | td->o.nr_files++; |
Jens Axboe | bbf6b54 | 2007-03-13 15:28:55 +0100 | [diff] [blame] | 1153 | continue; |
| 1154 | } |
Jens Axboe | 0ddb270 | 2007-03-27 19:43:53 +0200 | [diff] [blame] | 1155 | if (!S_ISDIR(sb.st_mode)) |
| 1156 | continue; |
Jens Axboe | bbf6b54 | 2007-03-13 15:28:55 +0100 | [diff] [blame] | 1157 | |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 1158 | ret = recurse_dir(td, full_path); |
| 1159 | if (ret) |
Jens Axboe | bbf6b54 | 2007-03-13 15:28:55 +0100 | [diff] [blame] | 1160 | break; |
| 1161 | } |
| 1162 | |
| 1163 | closedir(D); |
| 1164 | return ret; |
| 1165 | } |
| 1166 | |
| 1167 | int add_dir_files(struct thread_data *td, const char *path) |
| 1168 | { |
Jens Axboe | 0ddb270 | 2007-03-27 19:43:53 +0200 | [diff] [blame] | 1169 | int ret = recurse_dir(td, path); |
| 1170 | |
| 1171 | if (!ret) |
| 1172 | log_info("fio: opendir added %d files\n", td->o.nr_files); |
| 1173 | |
| 1174 | return ret; |
Jens Axboe | bbf6b54 | 2007-03-13 15:28:55 +0100 | [diff] [blame] | 1175 | } |
Jens Axboe | cade3ef | 2007-03-23 15:29:45 +0100 | [diff] [blame] | 1176 | |
| 1177 | void dup_files(struct thread_data *td, struct thread_data *org) |
| 1178 | { |
| 1179 | struct fio_file *f; |
| 1180 | unsigned int i; |
Jens Axboe | 9efef3c | 2008-03-06 10:26:25 +0100 | [diff] [blame] | 1181 | |
| 1182 | dprint(FD_FILE, "dup files: %d\n", org->files_index); |
Jens Axboe | cade3ef | 2007-03-23 15:29:45 +0100 | [diff] [blame] | 1183 | |
| 1184 | if (!org->files) |
| 1185 | return; |
| 1186 | |
Jens Axboe | 9efef3c | 2008-03-06 10:26:25 +0100 | [diff] [blame] | 1187 | td->files = malloc(org->files_index * sizeof(f)); |
Jens Axboe | cade3ef | 2007-03-23 15:29:45 +0100 | [diff] [blame] | 1188 | |
Jens Axboe | 9efef3c | 2008-03-06 10:26:25 +0100 | [diff] [blame] | 1189 | for_each_file(org, f, i) { |
Jens Axboe | b0fe421 | 2008-03-01 18:22:27 +0100 | [diff] [blame] | 1190 | struct fio_file *__f; |
| 1191 | |
Jens Axboe | f17c439 | 2008-03-01 18:40:46 +0100 | [diff] [blame] | 1192 | __f = smalloc(sizeof(*__f)); |
Jens Axboe | c48c0be | 2008-07-31 19:55:02 +0200 | [diff] [blame] | 1193 | if (!__f) { |
| 1194 | log_err("fio: smalloc OOM\n"); |
| 1195 | assert(0); |
| 1196 | } |
Jens Axboe | 22a57ba | 2009-06-09 14:34:35 +0200 | [diff] [blame] | 1197 | __f->fd = -1; |
Jens Axboe | 38dad62 | 2010-07-20 14:46:00 -0600 | [diff] [blame] | 1198 | fio_file_reset(__f); |
Jens Axboe | 0b9d69e | 2009-09-11 22:29:54 +0200 | [diff] [blame] | 1199 | |
Aaron Carroll | bc3456f | 2008-06-25 09:20:37 +0200 | [diff] [blame] | 1200 | if (f->file_name) { |
Jens Axboe | f17c439 | 2008-03-01 18:40:46 +0100 | [diff] [blame] | 1201 | __f->file_name = smalloc_strdup(f->file_name); |
Jens Axboe | c48c0be | 2008-07-31 19:55:02 +0200 | [diff] [blame] | 1202 | if (!__f->file_name) { |
| 1203 | log_err("fio: smalloc OOM\n"); |
| 1204 | assert(0); |
| 1205 | } |
Jens Axboe | 0b9d69e | 2009-09-11 22:29:54 +0200 | [diff] [blame] | 1206 | |
Aaron Carroll | bc3456f | 2008-06-25 09:20:37 +0200 | [diff] [blame] | 1207 | __f->filetype = f->filetype; |
| 1208 | } |
Jens Axboe | b0fe421 | 2008-03-01 18:22:27 +0100 | [diff] [blame] | 1209 | |
| 1210 | td->files[i] = __f; |
Jens Axboe | cade3ef | 2007-03-23 15:29:45 +0100 | [diff] [blame] | 1211 | } |
| 1212 | } |
Jens Axboe | f29b25a | 2007-07-23 08:56:43 +0200 | [diff] [blame] | 1213 | |
| 1214 | /* |
| 1215 | * Returns the index that matches the filename, or -1 if not there |
| 1216 | */ |
| 1217 | int get_fileno(struct thread_data *td, const char *fname) |
| 1218 | { |
| 1219 | struct fio_file *f; |
| 1220 | unsigned int i; |
| 1221 | |
| 1222 | for_each_file(td, f, i) |
| 1223 | if (!strcmp(f->file_name, fname)) |
| 1224 | return i; |
| 1225 | |
| 1226 | return -1; |
| 1227 | } |
| 1228 | |
| 1229 | /* |
| 1230 | * For log usage, where we add/open/close files automatically |
| 1231 | */ |
| 1232 | void free_release_files(struct thread_data *td) |
| 1233 | { |
| 1234 | close_files(td); |
| 1235 | td->files_index = 0; |
| 1236 | td->nr_normal_files = 0; |
| 1237 | } |