block: Make generic_make_request handle arbitrary sized bios

The way the block layer is currently written, it goes to great lengths
to avoid having to split bios; upper layer code (such as bio_add_page())
checks what the underlying device can handle and tries to always create
bios that don't need to be split.

But this approach becomes unwieldy and eventually breaks down with
stacked devices and devices with dynamic limits, and it adds a lot of
complexity. If the block layer could split bios as needed, we could
eliminate a lot of complexity elsewhere - particularly in stacked
drivers. Code that creates bios can then create whatever size bios are
convenient, and more importantly stacked drivers don't have to deal with
both their own bio size limitations and the limitations of the
(potentially multiple) devices underneath them.  In the future this will
let us delete merge_bvec_fn and a bunch of other code.

We do this by adding calls to blk_queue_split() to the various
make_request functions that need it - a few can already handle arbitrary
size bios. Note that we add the call _after_ any call to blk_queue_bounce();
this means that blk_queue_split() and blk_recalc_rq_segments() don't need to be
concerned with bouncing affecting segment merging.

Some make_request_fns were simple enough to audit and verify they don't
need blk_queue_split() calls. The skipped ones are:

 * nfhd_make_request (arch/m68k/emu/nfblock.c)
 * axon_ram_make_request (arch/powerpc/sysdev/axonram.c)
 * simdisk_make_request (arch/xtensa/platforms/iss/simdisk.c)
 * brd_make_request (ramdisk - drivers/block/brd.c)
 * mtip_submit_request (drivers/block/mtip32xx/mtip32xx.c)
 * loop_make_request
 * null_queue_bio
 * bcache's make_request fns

Some others are almost certainly safe to remove now, but will be left for future
patches.

Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Rebased-on-3.18: Dongsu Park <dongsu.park@profitbricks.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Neil Brown <neilb@suse.de>
Cc: Alasdair Kergon <agk@redhat.com>
Cc: dm-devel@redhat.com
Cc: Lars Ellenberg <drbd-dev@lists.linbit.com>
Cc: drbd-user@lists.linbit.com
Cc: Asai Thambi S P <asamymuthupa@micron.com>
Cc: Sam Bradshaw <sbradshaw@micron.com>
Cc: Matthew Wilcox <willy@linux.intel.com>
Cc: linux-nvme@lists.infradead.org
Cc: Jiri Kosina <jkosina@suse.cz>
Cc: Geoff Levand <geoff@infradead.org>
Cc: Jim Paris <jim@jtan.com>
Cc: Joshua Morris <josh.h.morris@us.ibm.com>
Cc: Philip Kelleher <pjk1939@linux.vnet.ibm.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Nitin Gupta <ngupta@vflare.org>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Peng Tao <bergwolf@gmail.com>
block: Gut bio_add_page()

Since generic_make_request() can now handle arbitrary size bios, all we
have to do is make sure the bvec array doesn't overflow.

Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Cc: Jens Axboe <axboe@kernel.dk>
blk-lib.c: generic_make_request() handles large bios now

generic_make_request() will now do for us what the code in blk-lib.c was
doing manually, with the bio_batch stuff - we still need some looping in
case we're trying to discard/zeroout more than around a gigabyte, but
when we can submit that much at a time doing the submissions in parallel
really shouldn't matter.

Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Cc: Jens Axboe <axboe@kernel.dk>
bcache: generic_make_request() handles large bios now

So we get to delete our hacky workaround.

Signed-off-by: Kent Overstreet <kmo@daterainc.com>
btrfs: generic_make_request() handles arbitrary size bios now

So there's no need for btrfs to break up bios for device limits anymore

Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Cc: Chris Mason <clm@fb.com>
Cc: linux-btrfs@vger.kernel.org
btrfs: Convert to bio_for_each_segment()

This is going to be important for future (hopeful) block layer refactoring, and
using the standard primitives makes the code easier to audit.

Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Cc: Chris Mason <clm@fb.com>
Cc: linux-btrfs@vger.kernel.org
btrfs: convert manual iteration to immutable biovec iteration

Use the new API with immutable biovec and bvec_iter, instead of
old-fashioned traversal through bi_io_vec[].
Follow up of 9e96618c ("btrfs: Convert to bio_for_each_segment()").

Signed-off-by: Dongsu Park <dongsu.park@profitbricks.com>
block: convert to iov_iter

Use iov_iter backed by scatter-gather list, instead of sg_iovec.

Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Rebased-on-3.18: Dongsu Park <dongsu.park@profitbricks.com>
block: refactor __bio_copy_iov()

Rewrite __bio_copy_iov() to use copy_page_to_iter() or
copy_page_from_iter(), according to Al Viro's suggestions.

Signed-off-by: Kent Overstreet <kmo@daterainc.com>
block: separate out iov_count_pages() from bio_copy_user_iov()

Refactor bio_copy_user_iov() to call iov_count_pages().

Signed-off-by: Kent Overstreet <kmo@daterainc.com>
block: Add bio_get_user_pages()

This replaces some of the code that was in __bio_map_user_iov(), and
soon we're going to use this helper in the dio code.

Note that this relies on the recent change to make
generic_make_request() take arbitrary sized bios - we're not using
bio_add_page() here.

Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Cc: Jens Axboe <axboe@kernel.dk>
block: Make blk_queue_bounce() handle bios larger than BIO_MAX_PAGES

We'd like to eventually be able to handle bios with more than
BIO_MAX_PAGES segments; this shouldn't be too hard and it'll simplify
other code in the kernel.

The issue is code that clones the bio and must clone the biovec (i.e.
it can't use bio_clone_fast()) won't be able to allocate a bio with more
than BIO_MAX_PAGES - bio_alloc_bioset() always fails in that case.

Fortunately, it's easy to make blk_queue_bounce() just process part of
the bio if necessary, using bi_remaining to count the splits and punting
the rest back to generic_make_request().

Signed-off-by: Kent Overstreet <kmo@daterainc.com>
md: Use bio_copy_data()

Refactor sync_request_write() of md/raid10 to use bio_copy_data()
instead of open coding bio_vec iterations.

Signed-off-by: Kent Overstreet <kmo@daterainc.com>
raid5: kill bio_fits_rdev()

There's no point in calling bio_fits_rdev() only for ensuring aligned
read from rdev. As ->merge_bvec_fn() has now gone, let's completely
remove bio_fits_rdev().

Signed-off-by: Kent Overstreet <kmo@daterainc.com>
block: Kill merge_bvec_fn

As generic_make_request() is now able to handle arbitrarily sized bios,
it's no longer necessary for each individual block driver to define its
own ->merge_bvec_fn() callback. Remove every invocation completely.

Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Introduce blk_max_segment()

Signed-off-by: Kent Overstreet <kmo@daterainc.com>
nvme: convert nvme to blk_max_segment()

convert nvme driver to use blk_max_segment().

Signed-off-by: Kent Overstreet <kmo@daterainc.com>
convert integrity to new merging

Signed-off-by: Kent Overstreet <kmo@daterainc.com>
bio_add_page() conversions

Signed-off-by: Kent Overstreet <kmo@daterainc.com>
kill bio_get()

Signed-off-by: Kent Overstreet <kmo@daterainc.com>