summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@suse.de>2006-01-20 12:38:29 +0100
committerJens Axboe <axboe@suse.de>2006-01-20 12:38:29 +0100
commit838a3cd3b7587d3188dc0c75ec73ca068430f01b (patch)
tree3c9bdf596523d23c15f057a30947e22ceaeb02be
parent9104f874d726e84739d3b4008eee0f6ddfe96714 (diff)
downloadfio-838a3cd3b7587d3188dc0c75ec73ca068430f01b.tar.gz
fio-838a3cd3b7587d3188dc0c75ec73ca068430f01b.tar.bz2
[PATCH] Fix offset/size setting problemfio-1.2
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.
-rw-r--r--fio.c24
-rw-r--r--fio.h1
2 files changed, 15 insertions, 10 deletions
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;