Fix infinite loop in get_next_file_rr()
[fio.git] / filesetup.c
index 2da29d1510ad2ed5cccba9d6d38ccd7d15322ec8..40a16638f9ea798a9e4b5c0c97c37ee5e691da15 100644 (file)
@@ -244,8 +244,15 @@ int open_files(struct thread_data *td)
 
        for_each_file(td, f, i) {
                err = td_io_open_file(td, f);
-               if (err)
+               if (err) {
+                       if (td->error == EMFILE) {
+                               log_err("fio: limited open files to: %d\n", td->nr_open_files);
+                               td->o.open_files = td->nr_open_files;
+                               err = 0;
+                               clear_error(td);
+                       }
                        break;
+               }
 
                if (td->o.open_files == td->nr_open_files)
                        break;
@@ -263,25 +270,17 @@ int open_files(struct thread_data *td)
 /*
  * open/close all files, so that ->real_file_size gets set
  */
-static int get_file_sizes(struct thread_data *td)
+static void get_file_sizes(struct thread_data *td)
 {
        struct fio_file *f;
        unsigned int i;
-       int err = 0;
 
        for_each_file(td, f, i) {
-               err = td->io_ops->open_file(td, f);
-               if (err) {
-                       td->error = 0;
-                       memset(td->verror, 0, sizeof(td->verror));
-                       err = 0;
-                       continue;
-               }
-
-               td->io_ops->close_file(td, f);
+               if (td->io_ops->open_file(td, f))
+                       clear_error(td);
+               else
+                       td->io_ops->close_file(td, f);
        }
-
-       return err;
 }
 
 /*
@@ -292,7 +291,7 @@ int setup_files(struct thread_data *td)
        unsigned long long total_size, extend_size;
        struct fio_file *f;
        unsigned int i;
-       int err, need_extend;
+       int err = 0, need_extend;
 
        /*
         * if ioengine defines a setup() method, it's responsible for
@@ -302,7 +301,7 @@ int setup_files(struct thread_data *td)
        if (td->io_ops->setup)
                err = td->io_ops->setup(td);
        else
-               err = get_file_sizes(td);
+               get_file_sizes(td);
 
        if (err)
                return err;
@@ -528,7 +527,10 @@ static int recurse_dir(struct thread_data *td, const char *dirname)
 
        D = opendir(dirname);
        if (!D) {
-               td_verror(td, errno, "opendir");
+               char buf[FIO_VERROR_SIZE];
+
+               snprintf(buf, FIO_VERROR_SIZE - 1, "opendir(%s)", dirname);
+               td_verror(td, errno, buf);
                return 1;
        }
 
@@ -553,6 +555,8 @@ static int recurse_dir(struct thread_data *td, const char *dirname)
                        td->o.nr_files++;
                        continue;
                }
+               if (!S_ISDIR(sb.st_mode))
+                       continue;
 
                if ((ret = recurse_dir(td, full_path)) != 0)
                        break;
@@ -564,7 +568,12 @@ static int recurse_dir(struct thread_data *td, const char *dirname)
 
 int add_dir_files(struct thread_data *td, const char *path)
 {
-       return recurse_dir(td, path);
+       int ret = recurse_dir(td, path);
+
+       if (!ret)
+               log_info("fio: opendir added %d files\n", td->o.nr_files);
+
+       return ret;
 }
 
 void dup_files(struct thread_data *td, struct thread_data *org)