blob: 0a4e77ef33e3aef63b597cc9af118d19b54a0fa9 [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"
11#include "os.h"
12
Jens Axboe25205e92006-10-19 20:50:14 +020013/*
14 * Check if the file exists and it's large enough.
15 */
16static int file_ok(struct thread_data *td, struct fio_file *f)
Jens Axboe53cdc682006-10-18 11:50:58 +020017{
Jens Axboeb2a15192006-10-18 14:10:42 +020018 struct stat st;
Jens Axboe53cdc682006-10-18 11:50:58 +020019
Jens Axboeaf52b342007-03-13 10:07:47 +010020 if (f->filetype != FIO_TYPE_FILE ||
Jens Axboeb5af8292007-03-08 12:43:13 +010021 (td->io_ops->flags & FIO_DISKLESSIO))
Jens Axboeb2a15192006-10-18 14:10:42 +020022 return 0;
23
Jens Axboefa01d132007-02-22 14:07:39 +010024 if (lstat(f->file_name, &st) == -1)
Jens Axboe25205e92006-10-19 20:50:14 +020025 return 1;
Jens Axboefa01d132007-02-22 14:07:39 +010026
27 /*
28 * if it's a special file, size is always ok for now
29 */
30 if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode))
31 return 0;
32 if (st.st_size < (off_t) f->file_size)
Jens Axboe25205e92006-10-19 20:50:14 +020033 return 1;
34
35 return 0;
36}
37
38static int create_file(struct thread_data *td, struct fio_file *f)
39{
40 unsigned long long left;
41 unsigned int bs;
42 char *b;
43 int r;
Jens Axboeb2a15192006-10-18 14:10:42 +020044
Jens Axboe53cdc682006-10-18 11:50:58 +020045 f->fd = open(f->file_name, O_WRONLY | O_CREAT | O_TRUNC, 0644);
46 if (f->fd < 0) {
Jens Axboee1161c32007-02-22 19:36:48 +010047 td_verror(td, errno, "open");
Jens Axboe53cdc682006-10-18 11:50:58 +020048 return 1;
49 }
50
51 if (ftruncate(f->fd, f->file_size) == -1) {
Jens Axboee1161c32007-02-22 19:36:48 +010052 td_verror(td, errno, "ftruncate");
Jens Axboe53cdc682006-10-18 11:50:58 +020053 goto err;
54 }
55
Jens Axboe40f82982006-10-25 11:21:05 +020056 if (posix_fallocate(f->fd, 0, f->file_size) < 0) {
Jens Axboee1161c32007-02-22 19:36:48 +010057 td_verror(td, errno, "posix_fallocate");
Jens Axboe40f82982006-10-25 11:21:05 +020058 goto err;
59 }
60
Jens Axboea00735e2006-11-03 08:58:08 +010061 b = malloc(td->max_bs[DDIR_WRITE]);
62 memset(b, 0, td->max_bs[DDIR_WRITE]);
Jens Axboe53cdc682006-10-18 11:50:58 +020063
64 left = f->file_size;
65 while (left && !td->terminate) {
Jens Axboea00735e2006-11-03 08:58:08 +010066 bs = td->max_bs[DDIR_WRITE];
Jens Axboe53cdc682006-10-18 11:50:58 +020067 if (bs > left)
68 bs = left;
69
70 r = write(f->fd, b, bs);
71
72 if (r == (int) bs) {
73 left -= bs;
74 continue;
75 } else {
76 if (r < 0)
Jens Axboee1161c32007-02-22 19:36:48 +010077 td_verror(td, errno, "write");
Jens Axboe53cdc682006-10-18 11:50:58 +020078 else
Jens Axboee1161c32007-02-22 19:36:48 +010079 td_verror(td, EIO, "write");
Jens Axboe53cdc682006-10-18 11:50:58 +020080
81 break;
82 }
83 }
84
85 if (td->terminate)
86 unlink(f->file_name);
87 else if (td->create_fsync)
88 fsync(f->fd);
89
90 free(b);
91 close(f->fd);
92 f->fd = -1;
93 return 0;
94err:
95 close(f->fd);
96 f->fd = -1;
97 return 1;
98}
99
100static int create_files(struct thread_data *td)
101{
102 struct fio_file *f;
Jens Axboeaf52b342007-03-13 10:07:47 +0100103 int err, need_create, can_extend;
104 unsigned int i;
Jens Axboe53cdc682006-10-18 11:50:58 +0200105
Jens Axboe15494412007-03-13 11:52:47 +0100106 for_each_file(td, f, i) {
107 if (f->filetype != FIO_TYPE_FILE)
108 continue;
109
110 f->file_size = td->total_file_size / td->nr_normal_files;
111 f->file_offset = td->start_offset;
112 }
Jens Axboef6971252006-11-15 10:00:31 +0100113
Jens Axboe53cdc682006-10-18 11:50:58 +0200114 /*
115 * unless specifically asked for overwrite, let normal io extend it
116 */
Jens Axboe02638822007-03-12 09:25:55 +0100117 can_extend = !td->overwrite && !(td->io_ops->flags & FIO_NOEXTEND);
118 if (can_extend)
Jens Axboe53cdc682006-10-18 11:50:58 +0200119 return 0;
Jens Axboe53cdc682006-10-18 11:50:58 +0200120
Jens Axboef1027062006-10-20 10:14:01 +0200121 need_create = 0;
Jens Axboeaf52b342007-03-13 10:07:47 +0100122 for_each_file(td, f, i) {
123 int file_there;
Jens Axboeeff68612007-01-14 05:56:44 +0100124
Jens Axboeaf52b342007-03-13 10:07:47 +0100125 if (f->filetype != FIO_TYPE_FILE)
126 continue;
Jens Axboeeff68612007-01-14 05:56:44 +0100127
Jens Axboeaf52b342007-03-13 10:07:47 +0100128 file_there = !file_ok(td, f);
129
130 if (file_there && td_write(td) && !td->overwrite) {
131 unlink(f->file_name);
132 file_there = 0;
Jens Axboeeff68612007-01-14 05:56:44 +0100133 }
Jens Axboeaf52b342007-03-13 10:07:47 +0100134
135 need_create += !file_there;
Jens Axboeeff68612007-01-14 05:56:44 +0100136 }
Jens Axboef1027062006-10-20 10:14:01 +0200137
138 if (!need_create)
139 return 0;
140
Jens Axboe53cdc682006-10-18 11:50:58 +0200141 if (!td->total_file_size) {
142 log_err("Need size for create\n");
Jens Axboee1161c32007-02-22 19:36:48 +0100143 td_verror(td, EINVAL, "file_size");
Jens Axboe53cdc682006-10-18 11:50:58 +0200144 return 1;
145 }
146
Jens Axboe25205e92006-10-19 20:50:14 +0200147 temp_stall_ts = 1;
Jens Axboe1e97cce2006-12-05 11:44:16 +0100148 fprintf(f_out, "%s: Laying out IO file(s) (%u x %LuMiB == %LuMiB)\n",
Jens Axboe15494412007-03-13 11:52:47 +0100149 td->name, td->nr_normal_files,
150 (td->total_file_size >> 20) / td->nr_normal_files,
Jens Axboe25205e92006-10-19 20:50:14 +0200151 td->total_file_size >> 20);
152
153 err = 0;
154 for_each_file(td, f, i) {
Jens Axboe9b031dc2006-12-15 16:01:54 +0100155 /*
156 * Only unlink files that we created.
157 */
Jens Axboef11bd942007-03-13 10:16:34 +0100158 f->flags &= ~FIO_FILE_UNLINK;
Jens Axboe25205e92006-10-19 20:50:14 +0200159 if (file_ok(td, f)) {
Jens Axboef11bd942007-03-13 10:16:34 +0100160 if (td->unlink)
161 f->flags |= FIO_FILE_UNLINK;
162
Jens Axboe25205e92006-10-19 20:50:14 +0200163 err = create_file(td, f);
164 if (err)
165 break;
166 }
167 }
168
Jens Axboe53cdc682006-10-18 11:50:58 +0200169 temp_stall_ts = 0;
170 return err;
171}
172
173static int file_size(struct thread_data *td, struct fio_file *f)
174{
175 struct stat st;
176
177 if (td->overwrite) {
178 if (fstat(f->fd, &st) == -1) {
Jens Axboee1161c32007-02-22 19:36:48 +0100179 td_verror(td, errno, "fstat");
Jens Axboe53cdc682006-10-18 11:50:58 +0200180 return 1;
181 }
182
183 f->real_file_size = st.st_size;
184
185 if (!f->file_size || f->file_size > f->real_file_size)
186 f->file_size = f->real_file_size;
Jens Axboe745508d2007-01-08 10:25:51 +0100187 } else
188 f->real_file_size = f->file_size;
Jens Axboe53cdc682006-10-18 11:50:58 +0200189
Jens Axboe53cdc682006-10-18 11:50:58 +0200190 return 0;
191}
192
193static int bdev_size(struct thread_data *td, struct fio_file *f)
194{
195 unsigned long long bytes;
196 int r;
197
198 r = blockdev_size(f->fd, &bytes);
199 if (r) {
Jens Axboee1161c32007-02-22 19:36:48 +0100200 td_verror(td, r, "blockdev_size");
Jens Axboe53cdc682006-10-18 11:50:58 +0200201 return 1;
202 }
203
204 f->real_file_size = bytes;
205
206 /*
207 * no extend possibilities, so limit size to device size if too large
208 */
209 if (!f->file_size || f->file_size > f->real_file_size)
210 f->file_size = f->real_file_size;
211
212 f->file_size -= f->file_offset;
213 return 0;
214}
215
216static int get_file_size(struct thread_data *td, struct fio_file *f)
217{
218 int ret = 0;
219
Jens Axboeaf52b342007-03-13 10:07:47 +0100220 if (f->filetype == FIO_TYPE_FILE)
Jens Axboe53cdc682006-10-18 11:50:58 +0200221 ret = file_size(td, f);
Jens Axboeaf52b342007-03-13 10:07:47 +0100222 else if (f->filetype == FIO_TYPE_BD)
Jens Axboe53cdc682006-10-18 11:50:58 +0200223 ret = bdev_size(td, f);
224 else
225 f->real_file_size = -1;
226
227 if (ret)
228 return ret;
229
230 if (f->file_offset > f->real_file_size) {
231 log_err("%s: offset extends end (%Lu > %Lu)\n", td->name, f->file_offset, f->real_file_size);
232 return 1;
233 }
234
Jens Axboe53cdc682006-10-18 11:50:58 +0200235 return 0;
236}
237
Jens Axboee5b401d2006-10-18 16:03:40 +0200238int file_invalidate_cache(struct thread_data *td, struct fio_file *f)
239{
240 int ret = 0;
241
Jens Axboeda86ccb2007-03-08 12:49:37 +0100242 if (td->odirect)
Jens Axboeb5af8292007-03-08 12:43:13 +0100243 return 0;
244
Jens Axboee5b401d2006-10-18 16:03:40 +0200245 /*
246 * FIXME: add blockdev flushing too
247 */
Jens Axboeb5af8292007-03-08 12:43:13 +0100248 if (f->mmap)
Jens Axboee5b401d2006-10-18 16:03:40 +0200249 ret = madvise(f->mmap, f->file_size, MADV_DONTNEED);
Jens Axboeaf52b342007-03-13 10:07:47 +0100250 else if (f->filetype == FIO_TYPE_FILE) {
Jens Axboeb5af8292007-03-08 12:43:13 +0100251 ret = fadvise(f->fd, f->file_offset, f->file_size, POSIX_FADV_DONTNEED);
Jens Axboeaf52b342007-03-13 10:07:47 +0100252 } else if (f->filetype == FIO_TYPE_BD) {
Jens Axboeb5af8292007-03-08 12:43:13 +0100253 ret = blockdev_invalidate_cache(f->fd);
Jens Axboeaf52b342007-03-13 10:07:47 +0100254 } else if (f->filetype == FIO_TYPE_CHAR)
Jens Axboee5b401d2006-10-18 16:03:40 +0200255 ret = 0;
256
257 if (ret < 0) {
Jens Axboee1161c32007-02-22 19:36:48 +0100258 td_verror(td, errno, "invalidate_cache");
Jens Axboee5b401d2006-10-18 16:03:40 +0200259 return 1;
260 }
261
Jens Axboead2da602007-02-26 12:33:27 +0100262 return ret;
Jens Axboee5b401d2006-10-18 16:03:40 +0200263}
264
Jens Axboeb5af8292007-03-08 12:43:13 +0100265void generic_close_file(struct thread_data fio_unused *td, struct fio_file *f)
Jens Axboe53cdc682006-10-18 11:50:58 +0200266{
Jens Axboeb5af8292007-03-08 12:43:13 +0100267 close(f->fd);
268 f->fd = -1;
Jens Axboe53cdc682006-10-18 11:50:58 +0200269}
270
Jens Axboeb5af8292007-03-08 12:43:13 +0100271int generic_open_file(struct thread_data *td, struct fio_file *f)
Jens Axboe53cdc682006-10-18 11:50:58 +0200272{
Jens Axboe53cdc682006-10-18 11:50:58 +0200273 int flags = 0;
274
Jens Axboe2fd233b2007-03-02 08:44:25 +0100275 if (td->odirect)
276 flags |= OS_O_DIRECT;
277 if (td->sync_io)
278 flags |= O_SYNC;
Jens Axboe7abf8332006-11-23 15:01:19 +0100279
Jens Axboe2fd233b2007-03-02 08:44:25 +0100280 if (td_write(td) || td_rw(td)) {
281 flags |= O_RDWR;
Jens Axboe53cdc682006-10-18 11:50:58 +0200282
Jens Axboeaf52b342007-03-13 10:07:47 +0100283 if (f->filetype == FIO_TYPE_FILE)
Jens Axboe2fd233b2007-03-02 08:44:25 +0100284 flags |= O_CREAT;
Jens Axboe2fd233b2007-03-02 08:44:25 +0100285
Jens Axboeb5af8292007-03-08 12:43:13 +0100286 f->fd = open(f->file_name, flags, 0600);
Jens Axboe2fd233b2007-03-02 08:44:25 +0100287 } else {
Jens Axboeaf52b342007-03-13 10:07:47 +0100288 if (f->filetype == FIO_TYPE_CHAR)
Jens Axboe2fd233b2007-03-02 08:44:25 +0100289 flags |= O_RDWR;
290 else
291 flags |= O_RDONLY;
292
Jens Axboeb5af8292007-03-08 12:43:13 +0100293 f->fd = open(f->file_name, flags);
Jens Axboe53cdc682006-10-18 11:50:58 +0200294 }
295
296 if (f->fd == -1) {
Jens Axboee1161c32007-02-22 19:36:48 +0100297 int __e = errno;
298
299 td_verror(td, __e, "open");
300 if (__e == EINVAL && td->odirect)
Jens Axboe9d80e112007-02-22 19:37:53 +0100301 log_err("fio: destination does not support O_DIRECT\n");
Jens Axboe53cdc682006-10-18 11:50:58 +0200302 return 1;
303 }
304
Jens Axboeb5af8292007-03-08 12:43:13 +0100305 if (get_file_size(td, f))
306 goto err;
307
Jens Axboe02638822007-03-12 09:25:55 +0100308 if (td->invalidate_cache && file_invalidate_cache(td, f))
Jens Axboeb5af8292007-03-08 12:43:13 +0100309 goto err;
310
311 if (!td_random(td)) {
312 if (fadvise(f->fd, f->file_offset, f->file_size, POSIX_FADV_SEQUENTIAL) < 0) {
313 td_verror(td, errno, "fadvise");
314 goto err;
315 }
316 } else {
317 if (fadvise(f->fd, f->file_offset, f->file_size, POSIX_FADV_RANDOM) < 0) {
318 td_verror(td, errno, "fadvise");
319 goto err;
320 }
Jens Axboebdb4e2e2007-03-01 09:54:57 +0100321 }
Jens Axboe53cdc682006-10-18 11:50:58 +0200322
323 return 0;
Jens Axboeb5af8292007-03-08 12:43:13 +0100324err:
325 close(f->fd);
326 return 1;
327}
328
Jens Axboe21972cd2006-11-23 12:39:16 +0100329int open_files(struct thread_data *td)
330{
331 struct fio_file *f;
Jens Axboeaf52b342007-03-13 10:07:47 +0100332 unsigned int i;
333 int err = 0;
Jens Axboe21972cd2006-11-23 12:39:16 +0100334
335 for_each_file(td, f, i) {
Jens Axboeb5af8292007-03-08 12:43:13 +0100336 err = td_io_open_file(td, f);
Jens Axboe21972cd2006-11-23 12:39:16 +0100337 if (err)
338 break;
Jens Axboeb5af8292007-03-08 12:43:13 +0100339
340 if (td->open_files == td->nr_open_files)
341 break;
Jens Axboe21972cd2006-11-23 12:39:16 +0100342 }
343
Jens Axboe7abf8332006-11-23 15:01:19 +0100344 if (!err)
345 return 0;
346
Jens Axboebdb4e2e2007-03-01 09:54:57 +0100347 for_each_file(td, f, i)
Jens Axboeb5af8292007-03-08 12:43:13 +0100348 td_io_close_file(td, f);
Jens Axboe7abf8332006-11-23 15:01:19 +0100349
Jens Axboe21972cd2006-11-23 12:39:16 +0100350 return err;
351}
352
Jens Axboe53cdc682006-10-18 11:50:58 +0200353int setup_files(struct thread_data *td)
354{
355 struct fio_file *f;
Jens Axboeaf52b342007-03-13 10:07:47 +0100356 unsigned int i;
357 int err;
Jens Axboe53cdc682006-10-18 11:50:58 +0200358
359 /*
360 * if ioengine defines a setup() method, it's responsible for
361 * setting up everything in the td->files[] area.
362 */
363 if (td->io_ops->setup)
364 return td->io_ops->setup(td);
365
366 if (create_files(td))
367 return 1;
368
Jens Axboe21972cd2006-11-23 12:39:16 +0100369 err = open_files(td);
Jens Axboef1027062006-10-20 10:14:01 +0200370 if (err)
371 return err;
372
Jens Axboe0a7eb122006-10-20 10:36:42 +0200373 /*
374 * Recalculate the total file size now that files are set up.
375 */
376 td->total_file_size = 0;
377 for_each_file(td, f, i)
378 td->total_file_size += f->file_size;
379
Jens Axboef1027062006-10-20 10:14:01 +0200380 td->io_size = td->total_file_size;
Jens Axboe53cdc682006-10-18 11:50:58 +0200381 if (td->io_size == 0) {
382 log_err("%s: no io blocks\n", td->name);
Jens Axboee1161c32007-02-22 19:36:48 +0100383 td_verror(td, EINVAL, "total_file_size");
Jens Axboe53cdc682006-10-18 11:50:58 +0200384 return 1;
385 }
386
387 if (!td->zone_size)
388 td->zone_size = td->io_size;
389
390 td->total_io_size = td->io_size * td->loops;
391
Jens Axboebdb4e2e2007-03-01 09:54:57 +0100392 for_each_file(td, f, i)
Jens Axboeb5af8292007-03-08 12:43:13 +0100393 td_io_close_file(td, f);
Jens Axboe21972cd2006-11-23 12:39:16 +0100394
395 return err;
Jens Axboe53cdc682006-10-18 11:50:58 +0200396}
397
398void close_files(struct thread_data *td)
399{
Jens Axboe0ab8db82006-10-18 17:16:23 +0200400 struct fio_file *f;
Jens Axboeaf52b342007-03-13 10:07:47 +0100401 unsigned int i;
Jens Axboe53cdc682006-10-18 11:50:58 +0200402
Jens Axboe0ab8db82006-10-18 17:16:23 +0200403 for_each_file(td, f, i) {
Jens Axboe1315a682007-03-13 11:25:07 +0100404 if (!f->file_name && (f->flags & FIO_FILE_UNLINK) &&
Jens Axboeaf52b342007-03-13 10:07:47 +0100405 f->filetype == FIO_TYPE_FILE) {
Jens Axboe132ad462006-11-23 12:23:12 +0100406 unlink(f->file_name);
Jens Axboe1315a682007-03-13 11:25:07 +0100407 free(f->file_name);
Jens Axboe132ad462006-11-23 12:23:12 +0100408 f->file_name = NULL;
409 }
Jens Axboebdb4e2e2007-03-01 09:54:57 +0100410
Jens Axboeb5af8292007-03-08 12:43:13 +0100411 td_io_close_file(td, f);
Jens Axboeb3dc7f02007-03-09 12:52:15 +0100412
413 if (f->file_map)
414 free(f->file_map);
Jens Axboe53cdc682006-10-18 11:50:58 +0200415 }
Jens Axboeb4a6a592006-10-20 13:54:47 +0200416
Jens Axboe132ad462006-11-23 12:23:12 +0100417 td->filename = NULL;
Jens Axboeb4a6a592006-10-20 13:54:47 +0200418 free(td->files);
419 td->files = NULL;
420 td->nr_files = 0;
Jens Axboe53cdc682006-10-18 11:50:58 +0200421}
Jens Axboeaf52b342007-03-13 10:07:47 +0100422
Jens Axboee3bab462007-03-13 11:22:09 +0100423static void get_file_type(struct fio_file *f)
Jens Axboeaf52b342007-03-13 10:07:47 +0100424{
425 struct stat sb;
426
427 f->filetype = FIO_TYPE_FILE;
428
Jens Axboee3bab462007-03-13 11:22:09 +0100429 if (!lstat(f->file_name, &sb)) {
Jens Axboeaf52b342007-03-13 10:07:47 +0100430 if (S_ISBLK(sb.st_mode))
431 f->filetype = FIO_TYPE_BD;
432 else if (S_ISCHR(sb.st_mode))
433 f->filetype = FIO_TYPE_CHAR;
434 }
435}
436
437void add_file(struct thread_data *td, const char *fname)
438{
Jens Axboe7b4e4fe2007-03-13 12:51:40 +0100439 int cur_files = td->files_index;
Jens Axboeaf52b342007-03-13 10:07:47 +0100440 struct fio_file *f;
441
442 td->files = realloc(td->files, (cur_files + 1) * sizeof(*f));
443
444 f = &td->files[cur_files];
445 memset(f, 0, sizeof(*f));
446 f->fd = -1;
Jens Axboecae61952007-03-13 11:12:14 +0100447 f->file_name = strdup(fname);
Jens Axboeaf52b342007-03-13 10:07:47 +0100448
Jens Axboee3bab462007-03-13 11:22:09 +0100449 get_file_type(f);
Jens Axboeaf52b342007-03-13 10:07:47 +0100450
Jens Axboe7b4e4fe2007-03-13 12:51:40 +0100451 td->files_index++;
Jens Axboe15494412007-03-13 11:52:47 +0100452 if (f->filetype == FIO_TYPE_FILE)
453 td->nr_normal_files++;
Jens Axboeaf52b342007-03-13 10:07:47 +0100454}
Jens Axboe0ad920e2007-03-13 11:06:45 +0100455
456void get_file(struct fio_file *f)
457{
458 f->references++;
459}
460
461void put_file(struct thread_data *td, struct fio_file *f)
462{
463 if (!(f->flags & FIO_FILE_OPEN))
464 return;
465
466 assert(f->references);
467 if (--f->references)
468 return;
469
Jens Axboeebb14152007-03-13 14:42:15 +0100470 if (should_fsync(td) && td->fsync_on_close)
471 fsync(f->fd);
472
Jens Axboe0ad920e2007-03-13 11:06:45 +0100473 if (td->io_ops->close_file)
474 td->io_ops->close_file(td, f);
475 td->nr_open_files--;
476 f->flags &= ~FIO_FILE_OPEN;
477}
Jens Axboebbf6b542007-03-13 15:28:55 +0100478
479static int recurse_dir(struct thread_data *td, const char *dirname)
480{
481 struct dirent *dir;
482 int ret = 0;
483 DIR *D;
484
485 D = opendir(dirname);
486 if (!D) {
487 td_verror(td, errno, "opendir");
488 return 1;
489 }
490
491 while ((dir = readdir(D)) != NULL) {
492 char full_path[PATH_MAX];
493 struct stat sb;
494
495 sprintf(full_path, "%s/%s", dirname, dir->d_name);
496
497 if (lstat(full_path, &sb) == -1) {
498 if (errno != ENOENT) {
499 td_verror(td, errno, "stat");
500 return 1;
501 }
502 }
503
504 if (S_ISREG(sb.st_mode)) {
505 add_file(td, full_path);
506 td->nr_files++;
507 continue;
508 }
509
510 if (!strcmp(dir->d_name, ".") || !strcmp(dir->d_name, ".."))
511 continue;
512
513 if ((ret = recurse_dir(td, full_path)) != 0)
514 break;
515 }
516
517 closedir(D);
518 return ret;
519}
520
521int add_dir_files(struct thread_data *td, const char *path)
522{
523 return recurse_dir(td, path);
524}