[PATCH] Fix offset/size setting problem fio-1.2
authorJens Axboe <axboe@suse.de>
Fri, 20 Jan 2006 11:38:29 +0000 (12:38 +0100)
committerJens Axboe <axboe@suse.de>
Fri, 20 Jan 2006 11:38:29 +0000 (12:38 +0100)
Add ->real_file_size, as ->file_size is the io size. Otherwise we don't
know if an offset + size is valid. This fixes the bug of offset >= size,
if size is set smaller than the device/file size.

fio.c
fio.h

diff --git a/fio.c b/fio.c
index ccceaa58949464100fac0b7376037cde49e3d4a1..2fb7da9b76c22190e09e39efacd266572b29f63a 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -302,7 +302,7 @@ static int get_next_offset(struct thread_data *td, unsigned long long *offset)
                b = td->last_pos / td->min_bs;
 
        *offset = (b * td->min_bs) + td->file_offset;
-       if (*offset > td->file_size)
+       if (*offset > td->real_file_size)
                return 1;
 
        return 0;
@@ -628,8 +628,8 @@ static struct io_u *get_io_u(struct thread_data *td)
                return NULL;
        }
 
-       if (io_u->buflen + io_u->offset > td->file_size)
-               io_u->buflen = td->file_size - io_u->offset;
+       if (io_u->buflen + io_u->offset > td->real_file_size)
+               io_u->buflen = td->real_file_size - io_u->offset;
 
        if (!io_u->buflen) {
                put_io_u(td, io_u);
@@ -1203,8 +1203,10 @@ static int file_size(struct thread_data *td)
                return 1;
        }
 
-       if (!td->file_size)
-               td->file_size = st.st_size;
+       td->real_file_size = st.st_size;
+
+       if (!td->file_size || td->file_size > td->real_file_size)
+               td->file_size = td->real_file_size;
 
        return 0;
 }
@@ -1220,11 +1222,13 @@ static int bdev_size(struct thread_data *td)
                return 1;
        }
 
+       td->real_file_size = bytes;
+
        /*
         * no extend possibilities, so limit size to device size if too large
         */
-       if (!td->file_size || td->file_size > bytes)
-               td->file_size = bytes;
+       if (!td->file_size || td->file_size > td->real_file_size)
+               td->file_size = td->real_file_size;
 
        return 0;
 }
@@ -1241,12 +1245,12 @@ static int get_file_size(struct thread_data *td)
        if (ret)
                return ret;
 
-       if (td->file_offset > td->file_size) {
-               fprintf(stderr, "Client%d: offset larger than length (%Lu > %Lu)\n", td->thread_number, td->file_offset, td->file_size);
+       if (td->file_offset + td->file_size > td->real_file_size) {
+               fprintf(stderr, "Client%d: offset extends end (%Lu > %Lu)\n", td->thread_number, td->file_offset + td->file_size, td->real_file_size);
                return 1;
        }
 
-       td->io_size = td->file_size - td->file_offset;
+       td->io_size = td->file_size;
        if (td->io_size == 0) {
                fprintf(stderr, "Client%d: no io blocks\n", td->thread_number);
                td_verror(td, EINVAL);
diff --git a/fio.h b/fio.h
index 3b4937d2379a0a5126029daf01329b311a702655..bb5b8dd16fc584d155cecfd8af4ce57537e280f6 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -133,6 +133,7 @@ struct thread_data {
        unsigned int create_fsync;
        unsigned int loops;
        unsigned long long file_size;
+       unsigned long long real_file_size;
        unsigned long long file_offset;
        unsigned long long zone_size;
        unsigned long long zone_skip;