When opening a new file, check file limit not total number
[fio.git] / io_u.c
diff --git a/io_u.c b/io_u.c
index 10fa188dd9aa0eb6d7900cc6c6a151cafb337eba..8f0cdff718e70267c5a330b7aba9f439c09847ca 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -109,6 +109,9 @@ static int get_next_offset(struct thread_data *td, struct io_u *io_u)
                unsigned long long max_blocks = f->file_size / td->min_bs[ddir];
                int loops = 5;
 
                unsigned long long max_blocks = f->file_size / td->min_bs[ddir];
                int loops = 5;
 
+               if (!max_blocks)
+                       return 1;
+
                do {
                        r = os_random_long(&td->random_state);
                        b = ((max_blocks - 1) * r / (unsigned long long) (RAND_MAX+1.0));
                do {
                        r = os_random_long(&td->random_state);
                        b = ((max_blocks - 1) * r / (unsigned long long) (RAND_MAX+1.0));
@@ -478,13 +481,13 @@ set_file:
                 * probably not the right place to do this, but see
                 * if we need to open a new file
                 */
                 * probably not the right place to do this, but see
                 * if we need to open a new file
                 */
-               if (td->nr_open_files < td->nr_files &&
+               if (td->nr_open_files < td->open_files &&
                    td->open_files != td->nr_files) {
                        f = find_next_new_file(td);
 
                        if (!f || (ret = td_io_open_file(td, f))) {
                                put_io_u(td, io_u);
                    td->open_files != td->nr_files) {
                        f = find_next_new_file(td);
 
                        if (!f || (ret = td_io_open_file(td, f))) {
                                put_io_u(td, io_u);
-                               break;
+                               return NULL;
                        }
                        goto set_file;
                }
                        }
                        goto set_file;
                }