aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorKent Overstreet <kmo@daterainc.com>2013-11-23 21:21:01 -0500
committerKent Overstreet <kmo@daterainc.com>2013-11-24 01:33:57 -0500
commit20d0189b1012a37d2533a87fb451f7852f2418d1 (patch)
tree5ceaa6cfc0e1f1cec423c6c9f5de72d49f2d63a1 /fs
parentee67891bf132612feb7b999ee1f3350b40867cb4 (diff)
block: Introduce new bio_split()
The new bio_split() can split arbitrary bios - it's not restricted to single page bios, like the old bio_split() (previously renamed to bio_pair_split()). It also has different semantics - it doesn't allocate a struct bio_pair, leaving it up to the caller to handle completions. Then convert the existing bio_pair_split() users to the new bio_split() - and also nvme, which was open coding bio splitting. (We have to take that BUG_ON() out of bio_integrity_trim() because this bio_split() needs to use it, and there's no reason it has to be used on bios marked as cloned; BIO_CLONED doesn't seem to have clearly documented semantics anyways.) Signed-off-by: Kent Overstreet <kmo@daterainc.com> Cc: Jens Axboe <axboe@kernel.dk> Cc: Martin K. Petersen <martin.petersen@oracle.com> Cc: Matthew Wilcox <matthew.r.wilcox@intel.com> Cc: Keith Busch <keith.busch@intel.com> Cc: Vishal Verma <vishal.l.verma@intel.com> Cc: Jiri Kosina <jkosina@suse.cz> Cc: Neil Brown <neilb@suse.de>
Diffstat (limited to 'fs')
-rw-r--r--fs/bio.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/fs/bio.c b/fs/bio.c
index a3e753f4d5a6..7b062befac82 100644
--- a/fs/bio.c
+++ b/fs/bio.c
@@ -1793,6 +1793,42 @@ void bio_endio_nodec(struct bio *bio, int error)
1793} 1793}
1794EXPORT_SYMBOL(bio_endio_nodec); 1794EXPORT_SYMBOL(bio_endio_nodec);
1795 1795
1796/**
1797 * bio_split - split a bio
1798 * @bio: bio to split
1799 * @sectors: number of sectors to split from the front of @bio
1800 * @gfp: gfp mask
1801 * @bs: bio set to allocate from
1802 *
1803 * Allocates and returns a new bio which represents @sectors from the start of
1804 * @bio, and updates @bio to represent the remaining sectors.
1805 *
1806 * The newly allocated bio will point to @bio's bi_io_vec; it is the caller's
1807 * responsibility to ensure that @bio is not freed before the split.
1808 */
1809struct bio *bio_split(struct bio *bio, int sectors,
1810 gfp_t gfp, struct bio_set *bs)
1811{
1812 struct bio *split = NULL;
1813
1814 BUG_ON(sectors <= 0);
1815 BUG_ON(sectors >= bio_sectors(bio));
1816
1817 split = bio_clone_fast(bio, gfp, bs);
1818 if (!split)
1819 return NULL;
1820
1821 split->bi_iter.bi_size = sectors << 9;
1822
1823 if (bio_integrity(split))
1824 bio_integrity_trim(split, 0, sectors);
1825
1826 bio_advance(bio, split->bi_iter.bi_size);
1827
1828 return split;
1829}
1830EXPORT_SYMBOL(bio_split);
1831
1796void bio_pair_release(struct bio_pair *bp) 1832void bio_pair_release(struct bio_pair *bp)
1797{ 1833{
1798 if (atomic_dec_and_test(&bp->cnt)) { 1834 if (atomic_dec_and_test(&bp->cnt)) {