summaryrefslogtreecommitdiffstats
path: root/block/blk.h
diff options
context:
space:
mode:
authorMing Lei <ming.lei@redhat.com>2018-10-29 20:57:17 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-11-13 11:08:16 -0800
commit14657efd3ad918f6779100e1047ea60d97a0d667 (patch)
treea9a99757bfd5696c0d57506c7be49f92cff7a56b /block/blk.h
parentcf8d0973c21123ae7f14f400b74aa89c6ff221bd (diff)
downloadlinux-stable-14657efd3ad918f6779100e1047ea60d97a0d667.tar.gz
linux-stable-14657efd3ad918f6779100e1047ea60d97a0d667.tar.bz2
linux-stable-14657efd3ad918f6779100e1047ea60d97a0d667.zip
block: make sure discard bio is aligned with logical block size
commit 1adfc5e4136f5967d591c399aff95b3b035f16b7 upstream. Obviously the created discard bio has to be aligned with logical block size. This patch introduces the helper of bio_allowed_max_sectors() for this purpose. Cc: stable@vger.kernel.org Cc: Mike Snitzer <snitzer@redhat.com> Cc: Christoph Hellwig <hch@lst.de> Cc: Xiao Ni <xni@redhat.com> Cc: Mariusz Dabrowski <mariusz.dabrowski@intel.com> Fixes: 744889b7cbb56a6 ("block: don't deal with discard limit in blkdev_issue_discard()") Fixes: a22c4d7e34402cc ("block: re-add discard_granularity and alignment checks") Reported-by: Rui Salvaterra <rsalvaterra@gmail.com> Tested-by: Rui Salvaterra <rsalvaterra@gmail.com> Signed-off-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'block/blk.h')
-rw-r--r--block/blk.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/block/blk.h b/block/blk.h
index 9db4e389582c..977d4b5d968d 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -329,6 +329,16 @@ static inline unsigned long blk_rq_deadline(struct request *rq)
}
/*
+ * The max size one bio can handle is UINT_MAX becasue bvec_iter.bi_size
+ * is defined as 'unsigned int', meantime it has to aligned to with logical
+ * block size which is the minimum accepted unit by hardware.
+ */
+static inline unsigned int bio_allowed_max_sectors(struct request_queue *q)
+{
+ return round_down(UINT_MAX, queue_logical_block_size(q)) >> 9;
+}
+
+/*
* Internal io_context interface
*/
void get_io_context(struct io_context *ioc);