diff options
author | Ming Lei <ming.lei@redhat.com> | 2019-04-22 22:51:04 -0400 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2019-04-23 09:57:07 -0400 |
commit | 551879a48f01826fd86568d7bd1e774cb0de3295 (patch) | |
tree | 5278aedd731a02b77f5dbc3fc23553e34f8728a0 /block/bio.c | |
parent | 6c88d73515c444323c57fba9069456b819700e79 (diff) |
block: clarify that bio_add_page() and related helpers can add multi pages
bio_add_page() and __bio_add_page() are capable of adding pages into
bio, and now we have at least two such usages alreay:
- __bio_iov_bvec_add_pages()
- nvmet_bdev_execute_rw().
So update comments on these two helpers.
The thing is a bit special for __bio_try_merge_page(), given the caller
needs to know if the new added page is same with the last added page,
then it isn't safe to pass multi-page in case that 'same_page' is true,
so adds warning on potential misuse, and updates comment on
__bio_try_merge_page().
Cc: linux-xfs@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block/bio.c')
-rw-r--r-- | block/bio.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/block/bio.c b/block/bio.c index 5959141d4e46..c81ed2dfee53 100644 --- a/block/bio.c +++ b/block/bio.c | |||
@@ -667,6 +667,8 @@ static inline bool page_is_mergeable(const struct bio_vec *bv, | |||
667 | return false; | 667 | return false; |
668 | } | 668 | } |
669 | 669 | ||
670 | WARN_ON_ONCE(same_page && (len + off) > PAGE_SIZE); | ||
671 | |||
670 | return true; | 672 | return true; |
671 | } | 673 | } |
672 | 674 | ||
@@ -786,9 +788,9 @@ EXPORT_SYMBOL(bio_add_pc_page); | |||
786 | /** | 788 | /** |
787 | * __bio_try_merge_page - try appending data to an existing bvec. | 789 | * __bio_try_merge_page - try appending data to an existing bvec. |
788 | * @bio: destination bio | 790 | * @bio: destination bio |
789 | * @page: page to add | 791 | * @page: start page to add |
790 | * @len: length of the data to add | 792 | * @len: length of the data to add |
791 | * @off: offset of the data in @page | 793 | * @off: offset of the data relative to @page |
792 | * @same_page: if %true only merge if the new data is in the same physical | 794 | * @same_page: if %true only merge if the new data is in the same physical |
793 | * page as the last segment of the bio. | 795 | * page as the last segment of the bio. |
794 | * | 796 | * |
@@ -796,6 +798,8 @@ EXPORT_SYMBOL(bio_add_pc_page); | |||
796 | * a useful optimisation for file systems with a block size smaller than the | 798 | * a useful optimisation for file systems with a block size smaller than the |
797 | * page size. | 799 | * page size. |
798 | * | 800 | * |
801 | * Warn if (@len, @off) crosses pages in case that @same_page is true. | ||
802 | * | ||
799 | * Return %true on success or %false on failure. | 803 | * Return %true on success or %false on failure. |
800 | */ | 804 | */ |
801 | bool __bio_try_merge_page(struct bio *bio, struct page *page, | 805 | bool __bio_try_merge_page(struct bio *bio, struct page *page, |
@@ -818,11 +822,11 @@ bool __bio_try_merge_page(struct bio *bio, struct page *page, | |||
818 | EXPORT_SYMBOL_GPL(__bio_try_merge_page); | 822 | EXPORT_SYMBOL_GPL(__bio_try_merge_page); |
819 | 823 | ||
820 | /** | 824 | /** |
821 | * __bio_add_page - add page to a bio in a new segment | 825 | * __bio_add_page - add page(s) to a bio in a new segment |
822 | * @bio: destination bio | 826 | * @bio: destination bio |
823 | * @page: page to add | 827 | * @page: start page to add |
824 | * @len: length of the data to add | 828 | * @len: length of the data to add, may cross pages |
825 | * @off: offset of the data in @page | 829 | * @off: offset of the data relative to @page, may cross pages |
826 | * | 830 | * |
827 | * Add the data at @page + @off to @bio as a new bvec. The caller must ensure | 831 | * Add the data at @page + @off to @bio as a new bvec. The caller must ensure |
828 | * that @bio has space for another bvec. | 832 | * that @bio has space for another bvec. |
@@ -845,13 +849,13 @@ void __bio_add_page(struct bio *bio, struct page *page, | |||
845 | EXPORT_SYMBOL_GPL(__bio_add_page); | 849 | EXPORT_SYMBOL_GPL(__bio_add_page); |
846 | 850 | ||
847 | /** | 851 | /** |
848 | * bio_add_page - attempt to add page to bio | 852 | * bio_add_page - attempt to add page(s) to bio |
849 | * @bio: destination bio | 853 | * @bio: destination bio |
850 | * @page: page to add | 854 | * @page: start page to add |
851 | * @len: vec entry length | 855 | * @len: vec entry length, may cross pages |
852 | * @offset: vec entry offset | 856 | * @offset: vec entry offset relative to @page, may cross pages |
853 | * | 857 | * |
854 | * Attempt to add a page to the bio_vec maplist. This will only fail | 858 | * Attempt to add page(s) to the bio_vec maplist. This will only fail |
855 | * if either bio->bi_vcnt == bio->bi_max_vecs or it's a cloned bio. | 859 | * if either bio->bi_vcnt == bio->bi_max_vecs or it's a cloned bio. |
856 | */ | 860 | */ |
857 | int bio_add_page(struct bio *bio, struct page *page, | 861 | int bio_add_page(struct bio *bio, struct page *page, |