blk-merge.c (d975f309a8b250e67b66eabeb56be6989c783629) blk-merge.c (5014c311baa2b21384321fa4a9f617a92e3e56f0)
1/*
2 * Functions related to segment and merge handling
3 */
4#include <linux/kernel.h>
5#include <linux/module.h>
6#include <linux/bio.h>
7#include <linux/blkdev.h>
8#include <linux/scatterlist.h>

--- 53 unchanged lines hidden (view full) ---

62 return bio_split(bio, q->limits.max_write_same_sectors, GFP_NOIO, bs);
63}
64
65static struct bio *blk_bio_segment_split(struct request_queue *q,
66 struct bio *bio,
67 struct bio_set *bs)
68{
69 struct bio *split;
1/*
2 * Functions related to segment and merge handling
3 */
4#include <linux/kernel.h>
5#include <linux/module.h>
6#include <linux/bio.h>
7#include <linux/blkdev.h>
8#include <linux/scatterlist.h>

--- 53 unchanged lines hidden (view full) ---

62 return bio_split(bio, q->limits.max_write_same_sectors, GFP_NOIO, bs);
63}
64
65static struct bio *blk_bio_segment_split(struct request_queue *q,
66 struct bio *bio,
67 struct bio_set *bs)
68{
69 struct bio *split;
70 struct bio_vec bv, bvprv;
70 struct bio_vec bv, bvprv, *bvprvp = NULL;
71 struct bvec_iter iter;
72 unsigned seg_size = 0, nsegs = 0, sectors = 0;
71 struct bvec_iter iter;
72 unsigned seg_size = 0, nsegs = 0, sectors = 0;
73 int prev = 0;
74
75 bio_for_each_segment(bv, bio, iter) {
76 sectors += bv.bv_len >> 9;
77
78 if (sectors > queue_max_sectors(q))
79 goto split;
80
81 /*
82 * If the queue doesn't support SG gaps and adding this
83 * offset would create a gap, disallow it.
84 */
73
74 bio_for_each_segment(bv, bio, iter) {
75 sectors += bv.bv_len >> 9;
76
77 if (sectors > queue_max_sectors(q))
78 goto split;
79
80 /*
81 * If the queue doesn't support SG gaps and adding this
82 * offset would create a gap, disallow it.
83 */
85 if (prev && bvec_gap_to_prev(q, &bvprv, bv.bv_offset))
84 if (bvprvp && bvec_gap_to_prev(q, bvprvp, bv.bv_offset))
86 goto split;
87
85 goto split;
86
88 if (prev && blk_queue_cluster(q)) {
87 if (bvprvp && blk_queue_cluster(q)) {
89 if (seg_size + bv.bv_len > queue_max_segment_size(q))
90 goto new_segment;
88 if (seg_size + bv.bv_len > queue_max_segment_size(q))
89 goto new_segment;
91 if (!BIOVEC_PHYS_MERGEABLE(&bvprv, &bv))
90 if (!BIOVEC_PHYS_MERGEABLE(bvprvp, &bv))
92 goto new_segment;
91 goto new_segment;
93 if (!BIOVEC_SEG_BOUNDARY(q, &bvprv, &bv))
92 if (!BIOVEC_SEG_BOUNDARY(q, bvprvp, &bv))
94 goto new_segment;
95
96 seg_size += bv.bv_len;
97 bvprv = bv;
93 goto new_segment;
94
95 seg_size += bv.bv_len;
96 bvprv = bv;
98 prev = 1;
97 bvprvp = &bv;
99 continue;
100 }
101new_segment:
102 if (nsegs == queue_max_segments(q))
103 goto split;
104
105 nsegs++;
106 bvprv = bv;
98 continue;
99 }
100new_segment:
101 if (nsegs == queue_max_segments(q))
102 goto split;
103
104 nsegs++;
105 bvprv = bv;
107 prev = 1;
106 bvprvp = &bv;
108 seg_size = bv.bv_len;
109 }
110
111 return NULL;
112split:
113 split = bio_clone_bioset(bio, GFP_NOIO, bs);
114
115 split->bi_iter.bi_size -= iter.bi_size;

--- 615 unchanged lines hidden ---
107 seg_size = bv.bv_len;
108 }
109
110 return NULL;
111split:
112 split = bio_clone_bioset(bio, GFP_NOIO, bs);
113
114 split->bi_iter.bi_size -= iter.bi_size;

--- 615 unchanged lines hidden ---