From: Bart Van Assche <bart.vanassche@sandisk.com>
To: Jens Axboe <axboe@fb.com>
Cc: Jan Kara <jack@suse.cz>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
Mike Snitzer <snitzer@redhat.com>,
"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
device-mapper development <dm-devel@redhat.com>,
Dmitry Monakhov <dmonakhov@openvz.org>,
Christoph Hellwig <hch@lst.de>
Subject: [PATCH 1/6] block: Introduce blk_round_sect_down()
Date: Thu, 17 Dec 2015 12:39:40 +0100 [thread overview]
Message-ID: <56729EFC.1030400@sandisk.com> (raw)
In-Reply-To: <56729ECF.50906@sandisk.com>
Move the code for rounding down a sector into a new function.
Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Mike Snitzer <snitzer@redhat.com>
Cc: Martin K. Petersen <martin.petersen@oracle.com>
Cc: Dmitry Monakhov <dmonakhov@openvz.org>
---
block/blk-lib.c | 32 +++++++++++++++++++++++++-------
1 file changed, 25 insertions(+), 7 deletions(-)
diff --git a/block/blk-lib.c b/block/blk-lib.c
index 9ebf653..2f4c6b2 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -26,6 +26,26 @@ static void bio_batch_end_io(struct bio *bio)
bio_put(bio);
}
+/*
+ * Return the largest number that is less than or equal to @s and for which
+ * the remainder of the division by @granularity is @alignment.
+ */
+static sector_t blk_round_sect_down(sector_t s, u32 granularity, u32 alignment)
+{
+ sector_t tmp = s, res = s;
+ u32 remainder;
+
+ WARN_ON_ONCE(alignment >= granularity);
+
+ remainder = sector_div(tmp, granularity);
+ if (remainder == alignment)
+ return res;
+ res -= remainder - alignment;
+ if (remainder < alignment)
+ res -= granularity;
+ return min(res, s);
+}
+
/**
* blkdev_issue_discard - queue a discard
* @bdev: blockdev to issue discard for
@@ -73,7 +93,7 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
blk_start_plug(&plug);
while (nr_sects) {
unsigned int req_sects;
- sector_t end_sect, tmp;
+ sector_t end_sect;
bio = bio_alloc(gfp_mask, 1);
if (!bio) {
@@ -89,12 +109,10 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
* misaligned, stop the discard at the previous aligned sector.
*/
end_sect = sector + req_sects;
- tmp = end_sect;
- if (req_sects < nr_sects &&
- sector_div(tmp, granularity) != alignment) {
- end_sect = end_sect - alignment;
- sector_div(end_sect, granularity);
- end_sect = end_sect * granularity + alignment;
+ if (req_sects < nr_sects) {
+ end_sect = blk_round_sect_down(end_sect, granularity,
+ alignment);
+ WARN_ON_ONCE(end_sect < sector);
req_sects = end_sect - sector;
}
--
2.1.4
next prev parent reply other threads:[~2015-12-17 11:39 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-17 11:38 [PATCH v2 0/6] Make blkdev_issue_discard() submit aligned discard requests Bart Van Assche
2015-12-17 11:39 ` Bart Van Assche [this message]
2015-12-18 12:30 ` [PATCH 1/6] block: Introduce blk_round_sect_down() Christoph Hellwig
2015-12-17 11:40 ` [PATCH 2/6] block: Introduce bio_add_zero_pages() Bart Van Assche
2015-12-18 12:30 ` Christoph Hellwig
2015-12-17 11:41 ` [PATCH 3/6] block: Optimize __blkdev_issue_zeroout() Bart Van Assche
2015-12-17 14:18 ` Bart Van Assche
2015-12-17 11:41 ` [PATCH 4/6] block: Make blkdev_issue_discard() submit aligned discard requests Bart Van Assche
2015-12-17 11:42 ` [PATCH 5/6] brd: Split bio if needed Bart Van Assche
2015-12-17 11:43 ` [PATCH 6/6] brd: Accept non-aligned discard requests with size zero Bart Van Assche
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=56729EFC.1030400@sandisk.com \
--to=bart.vanassche@sandisk.com \
--cc=axboe@fb.com \
--cc=dm-devel@redhat.com \
--cc=dmonakhov@openvz.org \
--cc=hch@lst.de \
--cc=jack@suse.cz \
--cc=linux-block@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=snitzer@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox