aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJens Axboe <axboe@fb.com>2014-06-24 18:22:24 -0400
committerJens Axboe <axboe@fb.com>2014-06-24 18:22:24 -0400
commit66cb45aa41315d1d9972cada354fbdf7870d7714 (patch)
tree5ca5ef3c31f24a7a11989d8a6a163eed9aaf9528
parent3a4b0eda8e4b27e6aca86f9f4d327c1070815e30 (diff)
block: add support for limiting gaps in SG lists
Another restriction inherited for NVMe - those devices don't support SG lists that have "gaps" in them. Gaps refers to cases where the previous SG entry doesn't end on a page boundary. For NVMe, all SG entries must start at offset 0 (except the first) and end on a page boundary (except the last). Signed-off-by: Jens Axboe <axboe@fb.com>
-rw-r--r--block/bio.c8
-rw-r--r--block/blk-merge.c10
-rw-r--r--include/linux/bio.h9
-rw-r--r--include/linux/blkdev.h1
4 files changed, 28 insertions, 0 deletions
diff --git a/block/bio.c b/block/bio.c
index 8c2e55e39a1b..0ec61c9e536c 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -746,6 +746,14 @@ static int __bio_add_page(struct request_queue *q, struct bio *bio, struct page
746 746
747 goto done; 747 goto done;
748 } 748 }
749
750 /*
751 * If the queue doesn't support SG gaps and adding this
752 * offset would create a gap, disallow it.
753 */
754 if (q->queue_flags & (1 << QUEUE_FLAG_SG_GAPS) &&
755 bvec_gap_to_prev(prev, offset))
756 return 0;
749 } 757 }
750 758
751 if (bio->bi_vcnt >= bio->bi_max_vecs) 759 if (bio->bi_vcnt >= bio->bi_max_vecs)
diff --git a/block/blk-merge.c b/block/blk-merge.c
index b3bf0df0f4c2..54535831f1e1 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -568,6 +568,8 @@ int blk_attempt_req_merge(struct request_queue *q, struct request *rq,
568 568
569bool blk_rq_merge_ok(struct request *rq, struct bio *bio) 569bool blk_rq_merge_ok(struct request *rq, struct bio *bio)
570{ 570{
571 struct request_queue *q = rq->q;
572
571 if (!rq_mergeable(rq) || !bio_mergeable(bio)) 573 if (!rq_mergeable(rq) || !bio_mergeable(bio))
572 return false; 574 return false;
573 575
@@ -591,6 +593,14 @@ bool blk_rq_merge_ok(struct request *rq, struct bio *bio)
591 !blk_write_same_mergeable(rq->bio, bio)) 593 !blk_write_same_mergeable(rq->bio, bio))
592 return false; 594 return false;
593 595
596 if (q->queue_flags & (1 << QUEUE_FLAG_SG_GAPS)) {
597 struct bio_vec *bprev;
598
599 bprev = &rq->biotail->bi_io_vec[bio->bi_vcnt - 1];
600 if (bvec_gap_to_prev(bprev, bio->bi_io_vec[0].bv_offset))
601 return false;
602 }
603
594 return true; 604 return true;
595} 605}
596 606
diff --git a/include/linux/bio.h b/include/linux/bio.h
index f91decbca96b..d2633ee099d9 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -186,6 +186,15 @@ static inline void *bio_data(struct bio *bio)
186#define BIOVEC_SEG_BOUNDARY(q, b1, b2) \ 186#define BIOVEC_SEG_BOUNDARY(q, b1, b2) \
187 __BIO_SEG_BOUNDARY(bvec_to_phys((b1)), bvec_to_phys((b2)) + (b2)->bv_len, queue_segment_boundary((q))) 187 __BIO_SEG_BOUNDARY(bvec_to_phys((b1)), bvec_to_phys((b2)) + (b2)->bv_len, queue_segment_boundary((q)))
188 188
189/*
190 * Check if adding a bio_vec after bprv with offset would create a gap in
191 * the SG list. Most drivers don't care about this, but some do.
192 */
193static inline bool bvec_gap_to_prev(struct bio_vec *bprv, unsigned int offset)
194{
195 return offset || ((bprv->bv_offset + bprv->bv_len) & (PAGE_SIZE - 1));
196}
197
189#define bio_io_error(bio) bio_endio((bio), -EIO) 198#define bio_io_error(bio) bio_endio((bio), -EIO)
190 199
191/* 200/*
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 713f8b62b435..8699bcf5f099 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -512,6 +512,7 @@ struct request_queue {
512#define QUEUE_FLAG_DEAD 19 /* queue tear-down finished */ 512#define QUEUE_FLAG_DEAD 19 /* queue tear-down finished */
513#define QUEUE_FLAG_INIT_DONE 20 /* queue is initialized */ 513#define QUEUE_FLAG_INIT_DONE 20 /* queue is initialized */
514#define QUEUE_FLAG_NO_SG_MERGE 21 /* don't attempt to merge SG segments*/ 514#define QUEUE_FLAG_NO_SG_MERGE 21 /* don't attempt to merge SG segments*/
515#define QUEUE_FLAG_SG_GAPS 22 /* queue doesn't support SG gaps */
515 516
516#define QUEUE_FLAG_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \ 517#define QUEUE_FLAG_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \
517 (1 << QUEUE_FLAG_STACKABLE) | \ 518 (1 << QUEUE_FLAG_STACKABLE) | \