From 2b7106947bd3c9bbdde976fd2acdeb542f30f0c4 Mon Sep 17 00:00:00 2001 From: Krzysztof Mazur Date: Sat, 4 Feb 2012 12:26:19 +0100 Subject: [PATCH 63/84] lsbd: move sector rewrite to separate function Signed-off-by: Krzysztof Mazur --- drivers/block/lsbd.c | 49 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/drivers/block/lsbd.c b/drivers/block/lsbd.c index 67305ab..eb5c4c2 100644 --- a/drivers/block/lsbd.c +++ b/drivers/block/lsbd.c @@ -1813,6 +1813,36 @@ static int lsbd_sector_eq(struct lsbd *p, unsigned int a, unsigned b) return a == b; } +/* + * lsbd_rewrite_sector - rewrite LSBD sector + * + * The sector rewrite is straightforward. We read sector and perform + * normal write. We don't check if this logical sector is already in + * write queue. Because of this to provide proper ordering, the already + * queued sector must be written AFTER rewrite, the rewrite must have + * the highest priority - so the LSBD_QUEUE_MOVE is used. + */ +static void lsbd_rewrite_sector(struct lsbd *p, unsigned int block, + unsigned int sector, unsigned int sector_id) +{ + struct buffer_head *rbh; + int ret; + + rbh = lsbd_sread(p, block, sector); + if (rbh == NULL) + return; + + lsbd_debug(p, "rewrite %d from block %ld\n", sector_id, block); + lock_buffer(rbh); + ret = lsbd_queue_bh(p, rbh, sector_id, LSBD_QUEUE_MOVE); + if (ret) { + lsbd_debug(p, "rewrite error %d\n", sector_id); + unlock_buffer(rbh); + brelse(rbh); + lsbd_put_buffer(p, rbh); + } +} + /** * lsbd_clean_block - clean next LSBD block * @p: LSBD device @@ -1825,7 +1855,6 @@ static void lsbd_clean_block(struct lsbd *p) { unsigned long block = p->clean_block; struct buffer_head *bh; - struct buffer_head *rbh; struct lsbd_block *b; int ret; struct lsbd_sect *sects; @@ -1914,22 +1943,8 @@ retry: "lcache %d\n", block, i, sector_id, s, sector); - if (lsbd_sector_eq(p, sector, s)) { - rbh = lsbd_sread(p, block, i + 1); - if (rbh == NULL) - continue; - - lsbd_debug(p, "rewrite %d from block %ld\n", sector_id, - block); - lock_buffer(rbh); - ret = lsbd_queue_bh(p, rbh, sector_id, LSBD_QUEUE_MOVE); - if (ret) { - lsbd_debug(p, "rewrite error %d\n", sector_id); - unlock_buffer(rbh); - brelse(rbh); - lsbd_put_buffer(p, rbh); - } - } + if (lsbd_sector_eq(p, sector, s)) + lsbd_rewrite_sector(p, block, i + 1, sector_id); } brelse(bh); -- 1.8.4.652.g0d6e0ce