From 7e9c8990f7714e8be7c3e1c4d9c5094a3497ed65 Mon Sep 17 00:00:00 2001 From: Petr Vandrovec Date: Thu, 9 Oct 2014 16:41:40 -0700 Subject: [PATCH] Do not silently discard WRITE_SAME requests When device does not support WRITE_SAME, after first failure block layer starts throwing away WRITE_SAME requests without warning anybody, leading to the data corruption. Let's do something about it - do not use EOPNOTSUPP error, as apparently that error code is special (use EREMOTEIO, AKA target failure, like when request hits hardware), and propagate inabiity to do WRITE_SAME to the top of stack, so we do not try to issue WRITE_SAME again and again. Signed-off-by: Petr Vandrovec --- block/blk-core.c | 2 +- block/blk-lib.c | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/block/blk-core.c b/block/blk-core.c index bf930f4..af6548c 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -1822,7 +1822,7 @@ generic_make_request_checks(struct bio *bio) } if (bio->bi_rw & REQ_WRITE_SAME && !bdev_write_same(bio->bi_bdev)) { - err = -EOPNOTSUPP; + err = -EREMOTEIO; goto end_io; } diff --git a/block/blk-lib.c b/block/blk-lib.c index 8411be3..f5ea9d2 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -298,6 +298,17 @@ int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, ZERO_PAGE(0))) return 0; + /* + * Should we do this or no? It propagates error through stacked + * block devices, like from sda to dm-0. I will assume that + * most users have homogenous environments, and so performance + * benefit of not issuing (and discarding) WRITE_SAME ever + * again outweighs performance loss from not using WRITE_SAME + * on disks in the set that support it. + * + * Do we need some lock? + */ + blk_queue_max_write_same_sectors(bdev_get_queue(bdev), 0); bdevname(bdev, bdn); pr_err("%s: WRITE SAME failed. Manually zeroing.\n", bdn); } -- 2.1.0