From 5231956401a9ca40c0a5c7804e3150c666d2d417 Mon Sep 17 00:00:00 2001 From: Krzysztof Mazur Date: Tue, 26 Jul 2011 19:22:25 +0200 Subject: [PATCH 49/84] lsbd: write proper entries count in last lcache The last lcache chunk was written with higher number of entries. This entries are usually skipped while reading because they have higher numbers than logical sector count. However after resizing of logical size those entries can be used producing strange mappings for first new sectors. --- drivers/block/lsbd.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/block/lsbd.c b/drivers/block/lsbd.c index 04dd929..e8b1c01 100644 --- a/drivers/block/lsbd.c +++ b/drivers/block/lsbd.c @@ -1806,6 +1806,9 @@ static int lsbd_write_lcache(struct lsbd *p, void *bp) p->cur_lcache = 0; chunk = (p->sector_size - 0x800) / sizeof(*cache); + if (chunk > p->lsectors - p->cur_lcache) + chunk = p->lsectors - p->cur_lcache; + b->lcache_offset = cpu_to_be32(0x800); b->lcache_base = cpu_to_be32(p->cur_lcache); b->lcache_chunk = cpu_to_be32(chunk); @@ -1815,8 +1818,6 @@ static int lsbd_write_lcache(struct lsbd *p, void *bp) for (i = 0; i < chunk; i++) { unsigned long long sector_id = p->cur_lcache + i; - if (sector_id >= p->lsectors) - break; cache[i] = cpu_to_be32(p->lcache[sector_id]); } read_unlock(&p->lcache_lock); -- 1.8.4.652.g0d6e0ce