Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

block: Remove bi_idx hacks

Now that drivers have been converted to the new bvec_iter primitives,
there's no need to trim the bvec before we submit it; and we can't trim
it once we start sharing bvecs.

It used to be that passing a partially completed bio (i.e. one with
nonzero bi_idx) to generic_make_request() was a dangerous thing -
various drivers would choke on such things. But with immutable biovecs
and our new bio splitting that shares the biovecs, submitting partially
completed bios has to work (and should work, now that all the drivers
have been completed to the new primitives)

Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Cc: Jens Axboe <axboe@kernel.dk>

+2 -68
+2 -45
drivers/md/bcache/io.c
··· 11 11 12 12 #include <linux/blkdev.h> 13 13 14 - static void bch_bi_idx_hack_endio(struct bio *bio, int error) 15 - { 16 - struct bio *p = bio->bi_private; 17 - 18 - bio_endio(p, error); 19 - bio_put(bio); 20 - } 21 - 22 - static void bch_generic_make_request_hack(struct bio *bio) 23 - { 24 - if (bio->bi_iter.bi_idx) { 25 - struct bio_vec bv; 26 - struct bvec_iter iter; 27 - unsigned segs = bio_segments(bio); 28 - struct bio *clone = bio_alloc(GFP_NOIO, segs); 29 - 30 - bio_for_each_segment(bv, bio, iter) 31 - clone->bi_io_vec[clone->bi_vcnt++] = bv; 32 - 33 - clone->bi_iter.bi_sector = bio->bi_iter.bi_sector; 34 - clone->bi_bdev = bio->bi_bdev; 35 - clone->bi_rw = bio->bi_rw; 36 - clone->bi_vcnt = segs; 37 - clone->bi_iter.bi_size = bio->bi_iter.bi_size; 38 - 39 - clone->bi_private = bio; 40 - clone->bi_end_io = bch_bi_idx_hack_endio; 41 - 42 - bio = clone; 43 - } 44 - 45 - /* 46 - * Hack, since drivers that clone bios clone up to bi_max_vecs, but our 47 - * bios might have had more than that (before we split them per device 48 - * limitations). 49 - * 50 - * To be taken out once immutable bvec stuff is in. 51 - */ 52 - bio->bi_max_vecs = bio->bi_vcnt; 53 - 54 - generic_make_request(bio); 55 - } 56 - 57 14 /** 58 15 * bch_bio_split - split a bio 59 16 * @bio: bio to split ··· 179 222 n->bi_private = &s->cl; 180 223 181 224 closure_get(&s->cl); 182 - bch_generic_make_request_hack(n); 225 + generic_make_request(n); 183 226 } while (n != bio); 184 227 185 228 continue_at(&s->cl, bch_bio_submit_split_done, NULL); 186 229 submit: 187 - bch_generic_make_request_hack(bio); 230 + generic_make_request(bio); 188 231 } 189 232 190 233 /* Bios with headers */
-23
fs/bio.c
··· 1822 1822 { 1823 1823 /* 'bio' is a cloned bio which we need to trim to match 1824 1824 * the given offset and size. 1825 - * This requires adjusting bi_sector, bi_size, and bi_io_vec 1826 1825 */ 1827 - int i; 1828 - struct bio_vec *bvec; 1829 - int sofar = 0; 1830 1826 1831 1827 size <<= 9; 1832 1828 if (offset == 0 && size == bio->bi_iter.bi_size) ··· 1833 1837 bio_advance(bio, offset << 9); 1834 1838 1835 1839 bio->bi_iter.bi_size = size; 1836 - 1837 - /* avoid any complications with bi_idx being non-zero*/ 1838 - if (bio->bi_iter.bi_idx) { 1839 - memmove(bio->bi_io_vec, bio->bi_io_vec+bio->bi_iter.bi_idx, 1840 - (bio->bi_vcnt - bio->bi_iter.bi_idx) * 1841 - sizeof(struct bio_vec)); 1842 - bio->bi_vcnt -= bio->bi_iter.bi_idx; 1843 - bio->bi_iter.bi_idx = 0; 1844 - } 1845 - /* Make sure vcnt and last bv are not too big */ 1846 - bio_for_each_segment_all(bvec, bio, i) { 1847 - if (sofar + bvec->bv_len > size) 1848 - bvec->bv_len = size - sofar; 1849 - if (bvec->bv_len == 0) { 1850 - bio->bi_vcnt = i; 1851 - break; 1852 - } 1853 - sofar += bvec->bv_len; 1854 - } 1855 1840 } 1856 1841 EXPORT_SYMBOL_GPL(bio_trim); 1857 1842