X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=io_u.c;h=c78865636b1f52f159bf8ef7d6846deb5fec5ef1;hb=f4c4f4d74bf101a685f3f9839144c52c4ed29e30;hp=e96d495658c7b127b065f92d934f6b76d01cfa3a;hpb=e291dc123a8a6eaaa6a45b52aed947dfa80834f2;p=fio.git diff --git a/io_u.c b/io_u.c index e96d4956..c7886563 100644 --- a/io_u.c +++ b/io_u.c @@ -109,12 +109,12 @@ 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; - 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)); + if (!max_blocks) + b = 0; + else + b = ((max_blocks - 1) * r / (unsigned long long) (RAND_MAX+1.0)); if (td->norandommap) break; rb = b + (f->file_offset / td->min_bs[ddir]); @@ -154,8 +154,14 @@ static unsigned int get_next_buflen(struct thread_data *td, struct io_u *io_u) } while (buflen + io_u->offset > f->real_file_size) { - if (buflen == td->min_bs[ddir]) + if (buflen == td->min_bs[ddir]) { + if (!td->odirect) { + assert(io_u->offset <= f->real_file_size); + buflen = f->real_file_size - io_u->offset; + return buflen; + } return 0; + } buflen = td->min_bs[ddir]; } @@ -481,7 +487,7 @@ set_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);