aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Overstreet <kmo@daterainc.com>2013-08-07 17:31:42 -0400
committerKent Overstreet <kmo@daterainc.com>2013-11-24 01:33:55 -0500
commite90abc8ec323c1fd2a25600097ef7ae1e91f39b0 (patch)
treec144139c73f2ef56a69c4721f66f8b8f166b6157
parentc8db444820a1e37ebdca38a0210bca85f832214f (diff)
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>
-rw-r--r--drivers/md/bcache/io.c47
-rw-r--r--fs/bio.c23
2 files changed, 2 insertions, 68 deletions
diff --git a/drivers/md/bcache/io.c b/drivers/md/bcache/io.c
index 6e04f3bb0286..0f0ab659914d 100644
--- a/drivers/md/bcache/io.c
+++ b/drivers/md/bcache/io.c
@@ -11,49 +11,6 @@
11 11
12#include <linux/blkdev.h> 12#include <linux/blkdev.h>
13 13
14static 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
22static 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 * bch_bio_split - split a bio 15 * bch_bio_split - split a bio
59 * @bio: bio to split 16 * @bio: bio to split
@@ -222,12 +179,12 @@ void bch_generic_make_request(struct bio *bio, struct bio_split_pool *p)
222 n->bi_private = &s->cl; 179 n->bi_private = &s->cl;
223 180
224 closure_get(&s->cl); 181 closure_get(&s->cl);
225 bch_generic_make_request_hack(n); 182 generic_make_request(n);
226 } while (n != bio); 183 } while (n != bio);
227 184
228 continue_at(&s->cl, bch_bio_submit_split_done, NULL); 185 continue_at(&s->cl, bch_bio_submit_split_done, NULL);
229submit: 186submit:
230 bch_generic_make_request_hack(bio); 187 generic_make_request(bio);
231} 188}
232 189
233/* Bios with headers */ 190/* Bios with headers */
diff --git a/fs/bio.c b/fs/bio.c
index 9cff939b1bc6..e6dfa06773ac 100644
--- a/fs/bio.c
+++ b/fs/bio.c
@@ -1822,11 +1822,7 @@ void bio_trim(struct bio *bio, int offset, int size)
1822{ 1822{
1823 /* 'bio' is a cloned bio which we need to trim to match 1823 /* 'bio' is a cloned bio which we need to trim to match
1824 * the given offset and size. 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 size <<= 9; 1827 size <<= 9;
1832 if (offset == 0 && size == bio->bi_iter.bi_size) 1828 if (offset == 0 && size == bio->bi_iter.bi_size)
@@ -1837,25 +1833,6 @@ void bio_trim(struct bio *bio, int offset, int size)
1837 bio_advance(bio, offset << 9); 1833 bio_advance(bio, offset << 9);
1838 1834
1839 bio->bi_iter.bi_size = size; 1835 bio->bi_iter.bi_size = size;
1840
1841 /* avoid any complications with bi_idx being non-zero*/
1842 if (bio->bi_iter.bi_idx) {
1843 memmove(bio->bi_io_vec, bio->bi_io_vec+bio->bi_iter.bi_idx,
1844 (bio->bi_vcnt - bio->bi_iter.bi_idx) *
1845 sizeof(struct bio_vec));
1846 bio->bi_vcnt -= bio->bi_iter.bi_idx;
1847 bio->bi_iter.bi_idx = 0;
1848 }
1849 /* Make sure vcnt and last bv are not too big */
1850 bio_for_each_segment_all(bvec, bio, i) {
1851 if (sofar + bvec->bv_len > size)
1852 bvec->bv_len = size - sofar;
1853 if (bvec->bv_len == 0) {
1854 bio->bi_vcnt = i;
1855 break;
1856 }
1857 sofar += bvec->bv_len;
1858 }
1859} 1836}
1860EXPORT_SYMBOL_GPL(bio_trim); 1837EXPORT_SYMBOL_GPL(bio_trim);
1861 1838