From 5a73db26d5ebd8137b1446f6bb14e2b4e4f48ea9 Mon Sep 17 00:00:00 2001
From: Justin Eno <jeno@micron.com>
Date: Tue, 27 Jan 2015 11:12:50 -0800
Subject: [PATCH] Better accommodate random writes larger than blockalign

fill_io_u() fails prematurely if the randomly-chosen offset satisfies
blockalign but not min_bs, i.e., the offset lies too near the end of
the target region.  This change honors both parameters.

Signed-off-by: Justin Eno <jeno@micron.com>
---
 io_u.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/io_u.c b/io_u.c
index 5971d78..b1aa8a8 100644
--- a/io_u.c
+++ b/io_u.c
@@ -55,6 +55,7 @@ static uint64_t last_block(struct thread_data *td, struct fio_file *f,
 {
 	uint64_t max_blocks;
 	uint64_t max_size;
+	uint64_t min_size;
 
 	assert(ddir_rw(ddir));
 
@@ -69,6 +70,12 @@ static uint64_t last_block(struct thread_data *td, struct fio_file *f,
 		max_size = td->o.zone_range;
 
 	max_blocks = max_size / (uint64_t) td->o.ba[ddir];
+	min_size = td->o.ba[ddir];
+	while (min_size < td->o.min_bs[ddir]) {
+		min_size += td->o.ba[ddir];
+	}
+
+	max_blocks = max_size / min_size;
 	if (!max_blocks)
 		return 0;
 
-- 
1.7.1

