block: Fix cloning of discard/write same bios
Subsystems (2)
PATCH 1/1 block: Fix cloning of discard/write same bios
Immutable biovecs changed the way bio segments are treated in such a way that bio_for_each_segment() cannot now do what we want for discard/write same bios, since bi_size means something completely different for them.
Fortunately discard and write same bios never have more than a single biovec, so bio_for_each_segment() is unnecessary and not terribly meaningful for them, but we still have to special case them in a few places.
--- fs/bio.c | 15 ++++++++++----- include/linux/bio.h | 11 +++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-)
fs/bio.c +10 -5
@@ -611,7 +611,6 @@ EXPORT_SYMBOL(bio_clone_fast);struct bio *bio_clone_bioset (struct bio *bio_src,gfp_t gfp_mask,struct bio_set *bs) { -unsigned nr_iovecs =0 ;struct bvec_iter iter;struct bio_vec bv;struct bio *bio;
@@ -638,10 +637,7 @@ struct bio *bio_clone_bioset(struct bio *bio_src, gfp_t gfp_mask,* __bio_clone_fast() anyways. */ -bio_for_each_segment (bv, bio_src, iter) - nr_iovecs++; - - bio =bio_alloc_bioset (gfp_mask, nr_iovecs, bs); + bio =bio_alloc_bioset (gfp_mask,bio_segments (bio_src), bs);if (!bio)return NULL ;
@@ -650,9 +646,18 @@ struct bio *bio_clone_bioset(struct bio *bio_src, gfp_t gfp_mask, bio->bi_iter.bi_sector = bio_src->bi_iter.bi_sector; bio->bi_iter.bi_size = bio_src->bi_iter.bi_size; +if (bio->bi_rw &REQ_DISCARD ) + goto integrity_clone; + +if (bio->bi_rw &REQ_WRITE_SAME ) { + bio->bi_io_vec[bio->bi_vcnt++] = bio_src->bi_io_vec[0 ]; + goto integrity_clone; + } +bio_for_each_segment (bv, bio_src, iter) bio->bi_io_vec[bio->bi_vcnt++] = bv; +integrity_clone:if (bio_integrity (bio_src)) {int ret;
include/linux/bio.h +11 -0
@@ -250,6 +250,17 @@ static inline unsigned bio_segments(struct bio *bio)struct bio_vec bv;struct bvec_iter iter; +/* +* We special case discard/write same, because they interpret bi_size +* differently: +*/ + +if (bio->bi_rw &REQ_DISCARD ) +return 1 ; + +if (bio->bi_rw &REQ_WRITE_SAME ) +return 1 ; +bio_for_each_segment (bv, bio, iter) segs++;
Signature · 1 line
1.8.5.3
Quoted 9 lines · Kent Overstreet
Immutable biovecs changed the way bio segments are treated in such a way that
bio_for_each_segment()cannot now do what we want for discard/write same bios, sincebi_sizemeans something completely different for them.Fortunately discard and write same bios never have more than a single biovec, so
bio_for_each_segment()is unnecessary and not terribly meaningful for them, but we still have to special case them in a few places.Signed-off-by Kent Overstreet <[email protected]>
I have confirmed this fixes the bug described here:
https://bugzilla.redhat.com/show_bug.cgi?id=1061339
Rich.
Quoted 72 lines
--- fs/bio.c | 15 ++++++++++----- include/linux/bio.h | 11 +++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-)fs/bio.c +10
-5@@ -611,7 +611,6 @@ EXPORT_SYMBOL(bio_clone_fast);struct bio *bio_clone_bioset (struct bio *bio_src,gfp_t gfp_mask,struct bio_set *bs) { -unsigned nr_iovecs =0 ;struct bvec_iter iter;struct bio_vec bv;struct bio *bio;@@ -638,10 +637,7 @@ struct bio *bio_clone_bioset(struct bio *bio_src, gfp_t gfp_mask,* __bio_clone_fast() anyways. */ -bio_for_each_segment (bv, bio_src, iter) - nr_iovecs++; - - bio =bio_alloc_bioset (gfp_mask, nr_iovecs, bs); + bio =bio_alloc_bioset (gfp_mask,bio_segments (bio_src), bs);if (!bio)return NULL ;@@ -650,9 +646,18 @@ struct bio *bio_clone_bioset(struct bio *bio_src, gfp_t gfp_mask, bio->bi_iter.bi_sector = bio_src->bi_iter.bi_sector; bio->bi_iter.bi_size = bio_src->bi_iter.bi_size; +if (bio->bi_rw &REQ_DISCARD ) + goto integrity_clone; + +if (bio->bi_rw &REQ_WRITE_SAME ) { + bio->bi_io_vec[bio->bi_vcnt++] = bio_src->bi_io_vec[0 ]; + goto integrity_clone; + } +bio_for_each_segment (bv, bio_src, iter) bio->bi_io_vec[bio->bi_vcnt++] = bv; +integrity_clone:if (bio_integrity (bio_src)) {int ret;include/linux/bio.h +11
-0@@ -250,6 +250,17 @@ static inline unsigned bio_segments(struct bio *bio)struct bio_vec bv;struct bvec_iter iter; +/* +* We special case discard/write same, because they interpret bi_size +* differently: +*/ + +if (bio->bi_rw &REQ_DISCARD ) +return 1 ; + +if (bio->bi_rw &REQ_WRITE_SAME ) +return 1 ; +bio_for_each_segment (bv, bio, iter) segs++;Signature · 1 line
1.8.5.3
Signature · 3 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming blog: http://rwmj.wordpress.com Fedora now supports 80 OCaml packages (the OPEN alternative to F#)
Jens Axboe
maintainerQuoted 9 lines · Richard W.M. Jones
Quoted 8 lines · Kent Overstreet
Immutable biovecs changed the way bio segments are treated in such a way that
bio_for_each_segment()cannot now do what we want for discard/write same bios, sincebi_sizemeans something completely different for them.Fortunately discard and write same bios never have more than a single biovec, so
bio_for_each_segment()is unnecessary and not terribly meaningful for them, but we still have to special case them in a few places.
Quoted 7 lines
Quoted 1 line
Signed-off-by Kent Overstreet <[email protected]>Tested-by Richard W.M. Jones <[email protected]>I have confirmed this fixes the bug described here:
Thanks, I have applied it for immediate inclusion.
Signature · 1 line
Jens Axboe