From eeff2fb53a99732d4c3a2eeb7806c7a6943c16fb Mon Sep 17 00:00:00 2001 From: Krzysztof Mazur Date: Wed, 18 May 2011 23:38:34 +0200 Subject: [PATCH 35/84] lsbd: fix data rewrite This patch fixes support for data rewrite. The rewrite code was broken since block to sector lcache change. --- drivers/block/lsbd.c | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/drivers/block/lsbd.c b/drivers/block/lsbd.c index 448a88d..fb34cb2 100644 --- a/drivers/block/lsbd.c +++ b/drivers/block/lsbd.c @@ -372,9 +372,11 @@ struct buffer_head *lsbd_getblk(struct lsbd *p, int block, unsigned int sector) bh->b_blocknr = block * p->sectors_per_block + sector; bh->b_rsector = (block * p->sectors_per_block + sector) * (p->sector_size >> 9); +#if 0 lsbd_debug(p, "getblk: %d.%d: mapped to physical sector %ld, %ld\n", block, sector, bh->b_blocknr, bh->b_rsector); +#endif return bh; } @@ -490,7 +492,7 @@ static int lsbd_block_verify_ok(struct lsbd *p, const struct lsbd_block *b) { u32 csum = lsbd_checksum(b, sizeof(*b) - 4); - lsbd_debug(p, "csum: %08x %08x\n", csum, be32_to_cpu(b->checksum)); +// lsbd_debug(p, "csum: %08x %08x\n", csum, be32_to_cpu(b->checksum)); return (be32_to_cpu(b->checksum) == csum); } @@ -505,7 +507,7 @@ static int lsbd_block_commit(struct lsbd *p, struct lsbd_block *b) { u32 csum = lsbd_checksum(b, sizeof(*b) - 4); - lsbd_debug(p, "commit: %08x\n", csum); +// lsbd_debug(p, "commit: %08x\n", csum); b->checksum = cpu_to_be32(csum); return 0; } @@ -1333,7 +1335,6 @@ static int lsbd_queue_bh(struct lsbd *p, struct buffer_head *bh, if (!move) { BUG_ON(current == p->tsk); - lsbd_debug(p, "%s: waiting on request\n", current->comm); down(&p->req_sem); } @@ -1358,7 +1359,7 @@ static int lsbd_queue_bh(struct lsbd *p, struct buffer_head *bh, return 0; } -#define lsbd_partition(x) ((x) & ((1 << PART_BITS) - 1)) +#define lsbd_minor_to_partition(x) ((x) & ((1 << PART_BITS) - 1)) /** * lsbd_read_mirrored - read from mirrored LSBD device @@ -1412,7 +1413,7 @@ static int lsbd_make_request(request_queue_t *q, int rw, struct buffer_head *bh) { struct lsbd *p = &lsbd_dev[MINOR(bh->b_rdev) >> PART_BITS]; - unsigned int partition = lsbd_partition(MINOR(bh->b_rdev)); + unsigned int partition = lsbd_minor_to_partition(MINOR(bh->b_rdev)); unsigned int lsector = LSBD_SECT_INVALID; /* @@ -1423,10 +1424,10 @@ static int lsbd_make_request(request_queue_t *q, int rw, unsigned int sector; lsector = bh->b_rsector >> 3; - lsbd_debug(p, "reading sector %d (%ld)\n", lsector, - bh->b_rsector); - lsbd_debug(p, "blocknr %ld, size %hd\n", bh->b_blocknr, - bh->b_size); +// lsbd_debug(p, "reading sector %d (%ld)\n", lsector, +// bh->b_rsector); +// lsbd_debug(p, "blocknr %ld, size %hd\n", bh->b_blocknr, +// bh->b_size); lsector = lsbd_map_sector(p, partition, lsector); if (lsector == LSBD_SECT_INVALID) { @@ -1435,7 +1436,8 @@ static int lsbd_make_request(request_queue_t *q, int rw, } sector = p->lcache[lsector]; - lsbd_debug(p, "mapped to sector %d\n", sector); + lsbd_debug(p, "read %d, mapped to %d\n", lsector, + sector); if (sector == LSBD_SECT_INVALID) { buffer_IO_error(bh); return 0; @@ -1581,23 +1583,33 @@ void lsbd_clean_block(struct lsbd *p) if (sectors > sectors_max) sectors = sectors_max; - sects = (void *) (bh->b_data + b->ptab_offset); + sects = (void *) (bh->b_data + ptab_offset); + + lsbd_debug(p, "ptab_offset %d\n", ptab_offset); + lsbd_debug(p, "cleaning block %ld: %ld sectors\n", block, sectors); for (i = 0; i < sectors; i++) { - unsigned int sector_id = be64_to_cpu(sects[i].id); - unsigned int s = block * p->sectors_per_block + i; + unsigned int sector_id = be32_to_cpu(sects[i].id); + unsigned int s = block * p->sectors_per_block + i + 1; if (sector_id >= p->lsectors) continue; + + lsbd_debug(p, "block %ld.%ld: logical %d, phys %d, " + "lcache %d\n", + block, i, sector_id, s, + (unsigned int) p->lcache[sector_id]); if (p->lcache[sector_id] == s) { rbh = lsbd_sread(p, block, i + 1); if (rbh == NULL) continue; - lsbd_debug(p, "rewritting sector %d\n", sector_id); + lsbd_debug(p, "rewrite %d from block %ld\n", sector_id, + block); lock_buffer(rbh); - ret = lsbd_queue_bh(p, rbh, s, LSBD_QUEUE_MOVE); + 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); -- 1.8.4.652.g0d6e0ce