lfsr: ensure we don't generate an offset + buflen that exceeds the max size

Currently we check for the max value, but that doesn't always
work since it may not fit the minimum block size (even if it
is guaranteed to be smaller than the max offset). Pass in the
last valid block.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/io_u.c b/io_u.c
index 91d1290..94fd123 100644
--- a/io_u.c
+++ b/io_u.c
@@ -49,11 +49,11 @@
 		io_u->buflen = nr_blocks * min_bs;
 }
 
-static unsigned long long last_block(struct thread_data *td, struct fio_file *f,
-				     enum fio_ddir ddir)
+static uint64_t last_block(struct thread_data *td, struct fio_file *f,
+			   enum fio_ddir ddir)
 {
-	unsigned long long max_blocks;
-	unsigned long long max_size;
+	uint64_t max_blocks;
+	uint64_t max_size;
 
 	assert(ddir_rw(ddir));
 
@@ -77,14 +77,14 @@
 static int __get_next_rand_offset(struct thread_data *td, struct fio_file *f,
 				  enum fio_ddir ddir, unsigned long long *b)
 {
-	unsigned long long r;
+	unsigned long long r, lastb;
+
+	lastb = last_block(td, f, ddir);
+	if (!lastb)
+		return 1;
 
 	if (td->o.random_generator == FIO_RAND_GEN_TAUSWORTHE) {
-		unsigned long long rmax, lastb;
-
-		lastb = last_block(td, f, ddir);
-		if (!lastb)
-			return 1;
+		unsigned long long rmax;
 
 		rmax = td->o.use_os_rand ? OS_RAND_MAX : FRAND_MAX;
 
@@ -102,7 +102,7 @@
 	} else {
 		uint64_t off = 0;
 
-		if (lfsr_next(&f->lfsr, &off))
+		if (lfsr_next(&f->lfsr, &off, lastb))
 			return 1;
 
 		*b = off;