From: Frank Mayhar <fmayhar@google.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-kernel <linux-kernel@vger.kernel.org>
Subject: [PATCH] block: Force sector and nr_sects to device alignment and granularity.
Date: Mon, 10 Mar 2014 11:01:32 -0700 [thread overview]
Message-ID: <1394474492.31499.177.camel@bobble.lax.corp.google.com> (raw)
block: Force sector and nr_sects to device alignment and granularity.
In blkdev_issue_discard(), rather than sending an improperly-
aligned discard to the device (where it may get an error),
adjust the start and length to the block device alignment and
granularity. Don't fail if this leaves nothing to discard.
Without this change, certain flash drivers can report invalid
trim parameters (and will fail the command). Per tytso, "given
that discards are advisory, any part of the storage stack is
free to drop discard requests silently."
Signed-off-by: Frank Mayhar <fmayhar@google.com>
Reviewed-by: "Theodore Ts'o" <tytso@mit.edu>
block/blk-lib.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/block/blk-lib.c b/block/blk-lib.c
index 97a733c..a4472cd 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -61,6 +61,21 @@ int blkdev_issue_discard(struct block_device *bdev,
sector_t sector,
alignment = (bdev_discard_alignment(bdev) >> 9) % granularity;
/*
+ * Force sector and nr_sects to block device alignment and
+ * granularity.
+ */
+ if (alignment && (sector % alignment)) {
+ sector_t adj = alignment - (sector % alignment);
+
+ sector += adj;
+ nr_sects -= adj;
+ }
+ if (nr_sects % granularity)
+ nr_sects -= nr_sects % granularity;
+ if (!nr_sects)
+ return ret;
+
+ /*
* Ensure that max_discard_sectors is of the proper
* granularity, so that requests stay aligned after a split.
*/
next reply other threads:[~2014-03-10 18:01 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-10 18:01 Frank Mayhar [this message]
2014-03-11 15:15 ` Jeff Moyer
2014-03-11 16:02 ` Frank Mayhar
2014-03-12 18:20 ` Jeff Moyer
2014-03-12 18:39 ` Frank Mayhar
2014-03-12 19:33 ` Jeff Moyer
2014-03-12 19:51 ` Frank Mayhar
2014-03-13 1:47 ` Martin K. Petersen
2014-03-14 17:17 ` Frank Mayhar
2014-03-14 20:26 ` Martin K. Petersen
2014-03-12 18:06 ` Frank Mayhar
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=1394474492.31499.177.camel@bobble.lax.corp.google.com \
--to=fmayhar@google.com \
--cc=axboe@kernel.dk \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®