diff options
author | Martin K. Petersen <martin.petersen@oracle.com> | 2010-09-10 14:50:10 -0400 |
---|---|---|
committer | Jens Axboe <axboe@carl.home.kernel.dk> | 2010-09-10 14:50:10 -0400 |
commit | 13f05c8d8e98bbdce89158bfdb2e380940695a88 (patch) | |
tree | 055215e7e2b1bdc684ead64daa61b30b35eaa3c5 /block | |
parent | c8bf1336824ebd698d37b71763e1c43190f2229a (diff) |
block/scsi: Provide a limit on the number of integrity segments
Some controllers have a hardware limit on the number of protection
information scatter-gather list segments they can handle.
Introduce a max_integrity_segments limit in the block layer and provide
a new scsi_host_template setting that allows HBA drivers to provide a
value suitable for the hardware.
Add support for honoring the integrity segment limit when merging both
bios and requests.
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Jens Axboe <axboe@carl.home.kernel.dk>
Diffstat (limited to 'block')
-rw-r--r-- | block/blk-integrity.c | 93 | ||||
-rw-r--r-- | block/blk-merge.c | 23 | ||||
-rw-r--r-- | block/blk-settings.c | 3 | ||||
-rw-r--r-- | block/blk-sysfs.c | 11 | ||||
-rw-r--r-- | block/blk.h | 8 |
5 files changed, 100 insertions, 38 deletions
diff --git a/block/blk-integrity.c b/block/blk-integrity.c index edce1ef7933d..885cbb59967e 100644 --- a/block/blk-integrity.c +++ b/block/blk-integrity.c | |||
@@ -32,24 +32,37 @@ static struct kmem_cache *integrity_cachep; | |||
32 | 32 | ||
33 | /** | 33 | /** |
34 | * blk_rq_count_integrity_sg - Count number of integrity scatterlist elements | 34 | * blk_rq_count_integrity_sg - Count number of integrity scatterlist elements |
35 | * @rq: request with integrity metadata attached | 35 | * @q: request queue |
36 | * @bio: bio with integrity metadata attached | ||
36 | * | 37 | * |
37 | * Description: Returns the number of elements required in a | 38 | * Description: Returns the number of elements required in a |
38 | * scatterlist corresponding to the integrity metadata in a request. | 39 | * scatterlist corresponding to the integrity metadata in a bio. |
39 | */ | 40 | */ |
40 | int blk_rq_count_integrity_sg(struct request *rq) | 41 | int blk_rq_count_integrity_sg(struct request_queue *q, struct bio *bio) |
41 | { | 42 | { |
42 | struct bio_vec *iv, *ivprv; | 43 | struct bio_vec *iv, *ivprv = NULL; |
43 | struct req_iterator iter; | 44 | unsigned int segments = 0; |
44 | unsigned int segments; | 45 | unsigned int seg_size = 0; |
46 | unsigned int i = 0; | ||
45 | 47 | ||
46 | ivprv = NULL; | 48 | bio_for_each_integrity_vec(iv, bio, i) { |
47 | segments = 0; | ||
48 | 49 | ||
49 | rq_for_each_integrity_segment(iv, rq, iter) { | 50 | if (ivprv) { |
51 | if (!BIOVEC_PHYS_MERGEABLE(ivprv, iv)) | ||
52 | goto new_segment; | ||
53 | |||
54 | if (!BIOVEC_SEG_BOUNDARY(q, ivprv, iv)) | ||
55 | goto new_segment; | ||
56 | |||
57 | if (seg_size + iv->bv_len > queue_max_segment_size(q)) | ||
58 | goto new_segment; | ||
50 | 59 | ||
51 | if (!ivprv || !BIOVEC_PHYS_MERGEABLE(ivprv, iv)) | 60 | seg_size += iv->bv_len; |
61 | } else { | ||
62 | new_segment: | ||
52 | segments++; | 63 | segments++; |
64 | seg_size = iv->bv_len; | ||
65 | } | ||
53 | 66 | ||
54 | ivprv = iv; | 67 | ivprv = iv; |
55 | } | 68 | } |
@@ -60,30 +73,34 @@ EXPORT_SYMBOL(blk_rq_count_integrity_sg); | |||
60 | 73 | ||
61 | /** | 74 | /** |
62 | * blk_rq_map_integrity_sg - Map integrity metadata into a scatterlist | 75 | * blk_rq_map_integrity_sg - Map integrity metadata into a scatterlist |
63 | * @rq: request with integrity metadata attached | 76 | * @q: request queue |
77 | * @bio: bio with integrity metadata attached | ||
64 | * @sglist: target scatterlist | 78 | * @sglist: target scatterlist |
65 | * | 79 | * |
66 | * Description: Map the integrity vectors in request into a | 80 | * Description: Map the integrity vectors in request into a |
67 | * scatterlist. The scatterlist must be big enough to hold all | 81 | * scatterlist. The scatterlist must be big enough to hold all |
68 | * elements. I.e. sized using blk_rq_count_integrity_sg(). | 82 | * elements. I.e. sized using blk_rq_count_integrity_sg(). |
69 | */ | 83 | */ |
70 | int blk_rq_map_integrity_sg(struct request *rq, struct scatterlist *sglist) | 84 | int blk_rq_map_integrity_sg(struct request_queue *q, struct bio *bio, |
85 | struct scatterlist *sglist) | ||
71 | { | 86 | { |
72 | struct bio_vec *iv, *ivprv; | 87 | struct bio_vec *iv, *ivprv = NULL; |
73 | struct req_iterator iter; | 88 | struct scatterlist *sg = NULL; |
74 | struct scatterlist *sg; | 89 | unsigned int segments = 0; |
75 | unsigned int segments; | 90 | unsigned int i = 0; |
76 | 91 | ||
77 | ivprv = NULL; | 92 | bio_for_each_integrity_vec(iv, bio, i) { |
78 | sg = NULL; | ||
79 | segments = 0; | ||
80 | |||
81 | rq_for_each_integrity_segment(iv, rq, iter) { | ||
82 | 93 | ||
83 | if (ivprv) { | 94 | if (ivprv) { |
84 | if (!BIOVEC_PHYS_MERGEABLE(ivprv, iv)) | 95 | if (!BIOVEC_PHYS_MERGEABLE(ivprv, iv)) |
85 | goto new_segment; | 96 | goto new_segment; |
86 | 97 | ||
98 | if (!BIOVEC_SEG_BOUNDARY(q, ivprv, iv)) | ||
99 | goto new_segment; | ||
100 | |||
101 | if (sg->length + iv->bv_len > queue_max_segment_size(q)) | ||
102 | goto new_segment; | ||
103 | |||
87 | sg->length += iv->bv_len; | 104 | sg->length += iv->bv_len; |
88 | } else { | 105 | } else { |
89 | new_segment: | 106 | new_segment: |
@@ -162,6 +179,40 @@ int blk_integrity_compare(struct gendisk *gd1, struct gendisk *gd2) | |||
162 | } | 179 | } |
163 | EXPORT_SYMBOL(blk_integrity_compare); | 180 | EXPORT_SYMBOL(blk_integrity_compare); |
164 | 181 | ||
182 | int blk_integrity_merge_rq(struct request_queue *q, struct request *req, | ||
183 | struct request *next) | ||
184 | { | ||
185 | if (blk_integrity_rq(req) != blk_integrity_rq(next)) | ||
186 | return -1; | ||
187 | |||
188 | if (req->nr_integrity_segments + next->nr_integrity_segments > | ||
189 | q->limits.max_integrity_segments) | ||
190 | return -1; | ||
191 | |||
192 | return 0; | ||
193 | } | ||
194 | EXPORT_SYMBOL(blk_integrity_merge_rq); | ||
195 | |||
196 | int blk_integrity_merge_bio(struct request_queue *q, struct request *req, | ||
197 | struct bio *bio) | ||
198 | { | ||
199 | int nr_integrity_segs; | ||
200 | struct bio *next = bio->bi_next; | ||
201 | |||
202 | bio->bi_next = NULL; | ||
203 | nr_integrity_segs = blk_rq_count_integrity_sg(q, bio); | ||
204 | bio->bi_next = next; | ||
205 | |||
206 | if (req->nr_integrity_segments + nr_integrity_segs > | ||
207 | q->limits.max_integrity_segments) | ||
208 | return -1; | ||
209 | |||
210 | req->nr_integrity_segments += nr_integrity_segs; | ||
211 | |||
212 | return 0; | ||
213 | } | ||
214 | EXPORT_SYMBOL(blk_integrity_merge_bio); | ||
215 | |||
165 | struct integrity_sysfs_entry { | 216 | struct integrity_sysfs_entry { |
166 | struct attribute attr; | 217 | struct attribute attr; |
167 | ssize_t (*show)(struct blk_integrity *, char *); | 218 | ssize_t (*show)(struct blk_integrity *, char *); |
diff --git a/block/blk-merge.c b/block/blk-merge.c index 3b0cd4249671..6a725461654d 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c | |||
@@ -205,12 +205,11 @@ static inline int ll_new_hw_segment(struct request_queue *q, | |||
205 | { | 205 | { |
206 | int nr_phys_segs = bio_phys_segments(q, bio); | 206 | int nr_phys_segs = bio_phys_segments(q, bio); |
207 | 207 | ||
208 | if (req->nr_phys_segments + nr_phys_segs > queue_max_segments(q)) { | 208 | if (req->nr_phys_segments + nr_phys_segs > queue_max_segments(q)) |
209 | req->cmd_flags |= REQ_NOMERGE; | 209 | goto no_merge; |
210 | if (req == q->last_merge) | 210 | |
211 | q->last_merge = NULL; | 211 | if (bio_integrity(bio) && blk_integrity_merge_bio(q, req, bio)) |
212 | return 0; | 212 | goto no_merge; |
213 | } | ||
214 | 213 | ||
215 | /* | 214 | /* |
216 | * This will form the start of a new hw segment. Bump both | 215 | * This will form the start of a new hw segment. Bump both |
@@ -218,6 +217,12 @@ static inline int ll_new_hw_segment(struct request_queue *q, | |||
218 | */ | 217 | */ |
219 | req->nr_phys_segments += nr_phys_segs; | 218 | req->nr_phys_segments += nr_phys_segs; |
220 | return 1; | 219 | return 1; |
220 | |||
221 | no_merge: | ||
222 | req->cmd_flags |= REQ_NOMERGE; | ||
223 | if (req == q->last_merge) | ||
224 | q->last_merge = NULL; | ||
225 | return 0; | ||
221 | } | 226 | } |
222 | 227 | ||
223 | int ll_back_merge_fn(struct request_queue *q, struct request *req, | 228 | int ll_back_merge_fn(struct request_queue *q, struct request *req, |
@@ -301,6 +306,9 @@ static int ll_merge_requests_fn(struct request_queue *q, struct request *req, | |||
301 | if (total_phys_segments > queue_max_segments(q)) | 306 | if (total_phys_segments > queue_max_segments(q)) |
302 | return 0; | 307 | return 0; |
303 | 308 | ||
309 | if (blk_integrity_rq(req) && blk_integrity_merge_rq(q, req, next)) | ||
310 | return 0; | ||
311 | |||
304 | /* Merge is OK... */ | 312 | /* Merge is OK... */ |
305 | req->nr_phys_segments = total_phys_segments; | 313 | req->nr_phys_segments = total_phys_segments; |
306 | return 1; | 314 | return 1; |
@@ -372,9 +380,6 @@ static int attempt_merge(struct request_queue *q, struct request *req, | |||
372 | || next->special) | 380 | || next->special) |
373 | return 0; | 381 | return 0; |
374 | 382 | ||
375 | if (blk_integrity_rq(req) != blk_integrity_rq(next)) | ||
376 | return 0; | ||
377 | |||
378 | /* | 383 | /* |
379 | * If we are allowed to merge, then append bio list | 384 | * If we are allowed to merge, then append bio list |
380 | * from next to rq and release next. merge_requests_fn | 385 | * from next to rq and release next. merge_requests_fn |
diff --git a/block/blk-settings.c b/block/blk-settings.c index 8d592b559bd3..f8f2ddf20613 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c | |||
@@ -111,6 +111,7 @@ EXPORT_SYMBOL_GPL(blk_queue_lld_busy); | |||
111 | void blk_set_default_limits(struct queue_limits *lim) | 111 | void blk_set_default_limits(struct queue_limits *lim) |
112 | { | 112 | { |
113 | lim->max_segments = BLK_MAX_SEGMENTS; | 113 | lim->max_segments = BLK_MAX_SEGMENTS; |
114 | lim->max_integrity_segments = 0; | ||
114 | lim->seg_boundary_mask = BLK_SEG_BOUNDARY_MASK; | 115 | lim->seg_boundary_mask = BLK_SEG_BOUNDARY_MASK; |
115 | lim->max_segment_size = BLK_MAX_SEGMENT_SIZE; | 116 | lim->max_segment_size = BLK_MAX_SEGMENT_SIZE; |
116 | lim->max_sectors = BLK_DEF_MAX_SECTORS; | 117 | lim->max_sectors = BLK_DEF_MAX_SECTORS; |
@@ -509,6 +510,8 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, | |||
509 | b->seg_boundary_mask); | 510 | b->seg_boundary_mask); |
510 | 511 | ||
511 | t->max_segments = min_not_zero(t->max_segments, b->max_segments); | 512 | t->max_segments = min_not_zero(t->max_segments, b->max_segments); |
513 | t->max_integrity_segments = min_not_zero(t->max_integrity_segments, | ||
514 | b->max_integrity_segments); | ||
512 | 515 | ||
513 | t->max_segment_size = min_not_zero(t->max_segment_size, | 516 | t->max_segment_size = min_not_zero(t->max_segment_size, |
514 | b->max_segment_size); | 517 | b->max_segment_size); |
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index 001ab18078f5..b014f7739e98 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c | |||
@@ -112,6 +112,11 @@ static ssize_t queue_max_segments_show(struct request_queue *q, char *page) | |||
112 | return queue_var_show(queue_max_segments(q), (page)); | 112 | return queue_var_show(queue_max_segments(q), (page)); |
113 | } | 113 | } |
114 | 114 | ||
115 | static ssize_t queue_max_integrity_segments_show(struct request_queue *q, char *page) | ||
116 | { | ||
117 | return queue_var_show(q->limits.max_integrity_segments, (page)); | ||
118 | } | ||
119 | |||
115 | static ssize_t queue_max_segment_size_show(struct request_queue *q, char *page) | 120 | static ssize_t queue_max_segment_size_show(struct request_queue *q, char *page) |
116 | { | 121 | { |
117 | if (test_bit(QUEUE_FLAG_CLUSTER, &q->queue_flags)) | 122 | if (test_bit(QUEUE_FLAG_CLUSTER, &q->queue_flags)) |
@@ -288,6 +293,11 @@ static struct queue_sysfs_entry queue_max_segments_entry = { | |||
288 | .show = queue_max_segments_show, | 293 | .show = queue_max_segments_show, |
289 | }; | 294 | }; |
290 | 295 | ||
296 | static struct queue_sysfs_entry queue_max_integrity_segments_entry = { | ||
297 | .attr = {.name = "max_integrity_segments", .mode = S_IRUGO }, | ||
298 | .show = queue_max_integrity_segments_show, | ||
299 | }; | ||
300 | |||
291 | static struct queue_sysfs_entry queue_max_segment_size_entry = { | 301 | static struct queue_sysfs_entry queue_max_segment_size_entry = { |
292 | .attr = {.name = "max_segment_size", .mode = S_IRUGO }, | 302 | .attr = {.name = "max_segment_size", .mode = S_IRUGO }, |
293 | .show = queue_max_segment_size_show, | 303 | .show = queue_max_segment_size_show, |
@@ -375,6 +385,7 @@ static struct attribute *default_attrs[] = { | |||
375 | &queue_max_hw_sectors_entry.attr, | 385 | &queue_max_hw_sectors_entry.attr, |
376 | &queue_max_sectors_entry.attr, | 386 | &queue_max_sectors_entry.attr, |
377 | &queue_max_segments_entry.attr, | 387 | &queue_max_segments_entry.attr, |
388 | &queue_max_integrity_segments_entry.attr, | ||
378 | &queue_max_segment_size_entry.attr, | 389 | &queue_max_segment_size_entry.attr, |
379 | &queue_iosched_entry.attr, | 390 | &queue_iosched_entry.attr, |
380 | &queue_hw_sector_size_entry.attr, | 391 | &queue_hw_sector_size_entry.attr, |
diff --git a/block/blk.h b/block/blk.h index 6e7dc87141e4..6738831ba447 100644 --- a/block/blk.h +++ b/block/blk.h | |||
@@ -132,14 +132,6 @@ static inline int queue_congestion_off_threshold(struct request_queue *q) | |||
132 | return q->nr_congestion_off; | 132 | return q->nr_congestion_off; |
133 | } | 133 | } |
134 | 134 | ||
135 | #if defined(CONFIG_BLK_DEV_INTEGRITY) | ||
136 | |||
137 | #define rq_for_each_integrity_segment(bvl, _rq, _iter) \ | ||
138 | __rq_for_each_bio(_iter.bio, _rq) \ | ||
139 | bip_for_each_vec(bvl, _iter.bio->bi_integrity, _iter.i) | ||
140 | |||
141 | #endif /* BLK_DEV_INTEGRITY */ | ||
142 | |||
143 | static inline int blk_cpu_to_group(int cpu) | 135 | static inline int blk_cpu_to_group(int cpu) |
144 | { | 136 | { |
145 | #ifdef CONFIG_SCHED_MC | 137 | #ifdef CONFIG_SCHED_MC |