Handle short read at the end of file
authorJens Axboe <jens.axboe@oracle.com>
Wed, 28 Mar 2007 09:07:20 +0000 (11:07 +0200)
committerJens Axboe <jens.axboe@oracle.com>
Wed, 28 Mar 2007 09:07:20 +0000 (11:07 +0200)
Currently we don't issue an io operation if offset + buflen
is larger than the file size, but that means we don't reach
the last bit of a file if the size isn't block size aligned.
Instead handle a short read properly. It actually cleans up
the code as well.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
fio.c
io_u.c

diff --git a/fio.c b/fio.c
index 2f0d74012a93a04f0ef464020bebe3f2e913b859..ef63ce6e4e47b384da36024e50a2c2504aa16b79 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -452,8 +452,14 @@ static void do_io(struct thread_data *td)
 
                                io_u->xfer_buflen = io_u->resid;
                                io_u->xfer_buf += bytes;
 
                                io_u->xfer_buflen = io_u->resid;
                                io_u->xfer_buf += bytes;
+                               io_u->offset += bytes;
+
+                               if (io_u->offset == io_u->file->real_file_size)
+                                       goto sync_done;
+
                                requeue_io_u(td, &io_u);
                        } else {
                                requeue_io_u(td, &io_u);
                        } else {
+sync_done:
                                fio_gettime(&comp_time, NULL);
                                bytes_done = io_u_sync_complete(td, io_u);
                                if (bytes_done < 0)
                                fio_gettime(&comp_time, NULL);
                                bytes_done = io_u_sync_complete(td, io_u);
                                if (bytes_done < 0)
diff --git a/io_u.c b/io_u.c
index 691f7afe36cd9b2ffa5072b265b446c685a6264e..b0f43557d509ff1201f77e953883a4ca1562ec09 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -172,19 +172,6 @@ static unsigned int get_next_buflen(struct thread_data *td, struct io_u *io_u)
                        buflen = (buflen + td->o.min_bs[ddir] - 1) & ~(td->o.min_bs[ddir] - 1);
        }
 
                        buflen = (buflen + td->o.min_bs[ddir] - 1) & ~(td->o.min_bs[ddir] - 1);
        }
 
-       while (buflen + io_u->offset > f->real_file_size) {
-               if (buflen == td->o.min_bs[ddir]) {
-                       if (!td->o.odirect) {
-                               assert(io_u->offset <= f->real_file_size);
-                               buflen = f->real_file_size - io_u->offset;
-                               return buflen;
-                       }
-                       return 0;
-               }
-
-               buflen = td->o.min_bs[ddir];
-       }
-
        return buflen;
 }
 
        return buflen;
 }
 
@@ -584,15 +571,6 @@ set_file:
                f->last_pos += td->o.zone_skip;
        }
 
                f->last_pos += td->o.zone_skip;
        }
 
-       if (io_u->buflen + io_u->offset > f->real_file_size) {
-               if (td->io_ops->flags & FIO_RAWIO) {
-                       put_io_u(td, io_u);
-                       return NULL;
-               }
-
-               io_u->buflen = f->real_file_size - io_u->offset;
-       }
-
        if (io_u->ddir != DDIR_SYNC) {
                if (!io_u->buflen) {
                        put_io_u(td, io_u);
        if (io_u->ddir != DDIR_SYNC) {
                if (!io_u->buflen) {
                        put_io_u(td, io_u);