Prev: [PATCH] Staging: saa7134-go7007: replace dma_sync_single with dma_sync_single_for_cpu
Next: [PATCH 2/7] perf trace: Correctly handle arrays
From: Jiaying Zhang on 13 May 2010 01:30 The currect blkdev_issue_discard() function assumes 512 sector size. We have seen some problem when using discard on a SSD that has larger sector size. The following patch adjusts the starting address and size of a discard request to be aligned with hwsect size. Signed-off-by: Jiaying Zhang <jiayingz(a)google.com> diff --git a/block/blk-barrier.c b/block/blk-barrier.c index 6d88544..576b7a1 100644 --- a/block/blk-barrier.c +++ b/block/blk-barrier.c @@ -376,14 +376,22 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector, DISCARD_BARRIER : DISCARD_NOBARRIER; struct bio *bio; struct page *page; + int hwsect_shift = blksize_bits(bdev_logical_block_size(bdev)) - 9; + int hwsect_mask = (1 << hwsect_shift) - 1; + sector_t end_sector; int ret = 0; if (!q) return -ENXIO; - if (!blk_queue_discard(q)) + if (!blk_queue_discard(q) || q->limits.max_discard_sectors == 0) return -EOPNOTSUPP; + if (hwsect_shift > 0) { + end_sector = (sector + nr_sects) & ~hwsect_mask; + sector = (sector + hwsect_mask) & ~hwsect_mask; + nr_sects = end_sector - sector; + } while (nr_sects && !ret) { unsigned int sector_size = q->limits.logical_block_size; unsigned int max_discard_sectors = -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo(a)vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ |