[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1304345841-20063-3-git-send-email-lczerner@redhat.com>
Date: Mon, 2 May 2011 16:17:21 +0200
From: Lukas Czerner <lczerner@...hat.com>
To: linux-fsdevel@...r.kernel.org
Cc: linux-kernel@...r.kernel.org, Lukas Czerner <lczerner@...hat.com>,
Dmitry Monakhov <dmonakhov@...nvz.org>,
Jens Axboe <jaxboe@...ionio.com>
Subject: [PATCH 3/3] blkdev: honor discard_granularity in blkdev_issue_discard()
As Jeff Moyer pointed out we do not honor discard granularity while
submitting REQ_DISCARD bios of size smaller than max_discard_sectors.
That fact might have unwanted consequences of device ignoring the
request, or even worse if device firmware is buggy.
This commit changes the behaviour so all discard bios smaller than
max_discard_sectors are aligned properly wrt discard_granularity.
Signed-off-by: Lukas Czerner <lczerner@...hat.com>
Reported-by: Jeff Moyer <jmoyer@...hat.com>
CC: Dmitry Monakhov <dmonakhov@...nvz.org>
CC: Jens Axboe <jaxboe@...ionio.com>
---
block/blk-lib.c | 10 ++++------
1 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/block/blk-lib.c b/block/blk-lib.c
index d7a98d3..4019036 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -46,7 +46,7 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
DECLARE_COMPLETION_ONSTACK(wait);
struct request_queue *q = bdev_get_queue(bdev);
int type = REQ_WRITE | REQ_DISCARD;
- unsigned int max_discard_sectors;
+ unsigned int max_discard_sectors, disc_sects;
struct bio_batch bb;
struct bio *bio;
int ret = 0;
@@ -57,16 +57,14 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
if (!blk_queue_discard(q))
return -EOPNOTSUPP;
+ disc_sects = q->limits.discard_granularity >> 9;
/*
* Ensure that max_discard_sectors is of the proper
* granularity
*/
max_discard_sectors = min(q->limits.max_discard_sectors, UINT_MAX >> 9);
- if (q->limits.discard_granularity) {
- unsigned int disc_sects = q->limits.discard_granularity >> 9;
-
+ if (q->limits.discard_granularity)
max_discard_sectors &= ~(disc_sects - 1);
- }
if (flags & BLKDEV_DISCARD_SECURE) {
if (!blk_queue_secdiscard(q))
@@ -95,7 +93,7 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
nr_sects -= max_discard_sectors;
sector += max_discard_sectors;
} else {
- bio->bi_size = nr_sects << 9;
+ bio->bi_size = ((nr_sects & ~(disc_sects - 1)) << 9);
nr_sects = 0;
}
--
1.7.4.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists