From: Jens Axboe Date: Fri, 20 Jan 2006 11:38:29 +0000 (+0100) Subject: [PATCH] Fix offset/size setting problem X-Git-Tag: fio-1.2^0 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=838a3cd3b7587d3188dc0c75ec73ca068430f01b [PATCH] Fix offset/size setting problem 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. --- diff --git a/fio.c b/fio.c index ccceaa58..2fb7da9b 100644 --- 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 3b4937d2..bb5b8dd1 100644 --- 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;