From: Lukas Czerner <lczerner@redhat.com>
To: linux-fsdevel@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Lukas Czerner <lczerner@redhat.com>,
Dmitry Monakhov <dmonakhov@openvz.org>,
Jens Axboe <jaxboe@fusionio.com>
Subject: [PATCH 3/3] blkdev: honor discard_granularity in blkdev_issue_discard()
Date: Mon, 2 May 2011 16:17:21 +0200 [thread overview]
Message-ID: <1304345841-20063-3-git-send-email-lczerner@redhat.com> (raw)
In-Reply-To: <1304345841-20063-1-git-send-email-lczerner@redhat.com>
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@redhat.com>
Reported-by: Jeff Moyer <jmoyer@redhat.com>
CC: Dmitry Monakhov <dmonakhov@openvz.org>
CC: Jens Axboe <jaxboe@fusionio.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
next prev parent reply other threads:[~2011-05-02 14:18 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-02 14:17 [PATCH 1/3] blkdev: Submit discard bio in batches in blkdev_issue_discard() Lukas Czerner
2011-05-02 14:17 ` [PATCH 2/3] blkdev: Simple cleanup in blkdev_issue_zeroout() Lukas Czerner
2011-05-02 14:17 ` Lukas Czerner [this message]
2011-05-02 14:38 ` [PATCH 3/3] blkdev: honor discard_granularity in blkdev_issue_discard() Martin K. Petersen
2011-05-02 16:10 ` Jeff Moyer
2011-05-02 17:07 ` Martin K. Petersen
2011-05-02 23:21 ` Dave Chinner
2011-05-02 16:23 ` [PATCH 1/3] blkdev: Submit discard bio in batches " Jens Axboe
2011-05-03 9:30 ` Lukas Czerner
2011-05-03 9:30 ` Lukas Czerner
2011-05-03 9:57 ` Christoph Hellwig
2011-05-07 1:23 ` Jens Axboe
2011-05-05 15:20 ` Lukas Czerner
2011-05-05 15:20 ` Lukas Czerner
2011-05-07 1:24 ` Jens Axboe
2011-05-09 14:30 ` Christoph Hellwig
2011-05-05 15:12 ` [PATCH] blkdev: Do not return -EOPNOTSUPP if discard is supported Lukas Czerner
2011-05-07 1:30 ` Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1304345841-20063-3-git-send-email-lczerner@redhat.com \
--to=lczerner@redhat.com \
--cc=dmonakhov@openvz.org \
--cc=jaxboe@fusionio.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.