From da3758bfa36ee05e25e73f33760f17750bd0687c Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 17 Jun 2010 21:27:11 +0200 Subject: [PATCH] Ensure we never overlap with existing blocks Signed-off-by: Jens Axboe --- io_u.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/io_u.c b/io_u.c index bffacb40..f451d1a7 100644 --- a/io_u.c +++ b/io_u.c @@ -54,11 +54,8 @@ static void mark_random_map(struct thread_data *td, struct io_u *io_u) * If we have a mixed random workload, we may * encounter blocks we already did IO to. */ - if ((td->o.ddir_nr == 1) && !random_map_free(f, block)) { - if (!blocks) - blocks = 1; + if ((td->o.ddir_nr == 1) && !random_map_free(f, block)) break; - } idx = RAND_MAP_IDX(f, block); bit = RAND_MAP_BIT(f, block); @@ -69,10 +66,20 @@ static void mark_random_map(struct thread_data *td, struct io_u *io_u) if (this_blocks + bit > BLOCKS_PER_MAP) this_blocks = BLOCKS_PER_MAP - bit; - if (this_blocks == BLOCKS_PER_MAP) - mask = -1U; - else - mask = ((1U << this_blocks) - 1) << bit; + do { + if (this_blocks == BLOCKS_PER_MAP) + mask = -1U; + else + mask = ((1U << this_blocks) - 1) << bit; + + if (!(f->file_map[idx] & mask)) + break; + + this_blocks--; + } while (this_blocks); + + if (!this_blocks) + break; f->file_map[idx] |= mask; nr_blocks -= this_blocks; -- 2.25.1