]>
Commit | Line | Data |
---|---|---|
d6d48196 JA |
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> | |
9 | ||
10 | #include "blk.h" | |
11 | ||
1e428079 | 12 | static unsigned int __blk_recalc_rq_segments(struct request_queue *q, |
59247eae | 13 | struct bio *bio) |
d6d48196 | 14 | { |
7988613b KO |
15 | struct bio_vec bv, bvprv = { NULL }; |
16 | int cluster, high, highprv = 1; | |
1e428079 | 17 | unsigned int seg_size, nr_phys_segs; |
59247eae | 18 | struct bio *fbio, *bbio; |
7988613b | 19 | struct bvec_iter iter; |
d6d48196 | 20 | |
1e428079 JA |
21 | if (!bio) |
22 | return 0; | |
d6d48196 | 23 | |
1e428079 | 24 | fbio = bio; |
e692cb66 | 25 | cluster = blk_queue_cluster(q); |
5df97b91 | 26 | seg_size = 0; |
2c8919de | 27 | nr_phys_segs = 0; |
1e428079 | 28 | for_each_bio(bio) { |
7988613b | 29 | bio_for_each_segment(bv, bio, iter) { |
1e428079 JA |
30 | /* |
31 | * the trick here is making sure that a high page is | |
32 | * never considered part of another segment, since that | |
33 | * might change with the bounce page. | |
34 | */ | |
7988613b KO |
35 | high = page_to_pfn(bv.bv_page) > queue_bounce_pfn(q); |
36 | if (!high && !highprv && cluster) { | |
37 | if (seg_size + bv.bv_len | |
ae03bf63 | 38 | > queue_max_segment_size(q)) |
1e428079 | 39 | goto new_segment; |
7988613b | 40 | if (!BIOVEC_PHYS_MERGEABLE(&bvprv, &bv)) |
1e428079 | 41 | goto new_segment; |
7988613b | 42 | if (!BIOVEC_SEG_BOUNDARY(q, &bvprv, &bv)) |
1e428079 | 43 | goto new_segment; |
d6d48196 | 44 | |
7988613b | 45 | seg_size += bv.bv_len; |
1e428079 JA |
46 | bvprv = bv; |
47 | continue; | |
48 | } | |
d6d48196 | 49 | new_segment: |
1e428079 JA |
50 | if (nr_phys_segs == 1 && seg_size > |
51 | fbio->bi_seg_front_size) | |
52 | fbio->bi_seg_front_size = seg_size; | |
86771427 | 53 | |
1e428079 JA |
54 | nr_phys_segs++; |
55 | bvprv = bv; | |
7988613b | 56 | seg_size = bv.bv_len; |
1e428079 JA |
57 | highprv = high; |
58 | } | |
59247eae | 59 | bbio = bio; |
d6d48196 JA |
60 | } |
61 | ||
59247eae JA |
62 | if (nr_phys_segs == 1 && seg_size > fbio->bi_seg_front_size) |
63 | fbio->bi_seg_front_size = seg_size; | |
64 | if (seg_size > bbio->bi_seg_back_size) | |
65 | bbio->bi_seg_back_size = seg_size; | |
1e428079 JA |
66 | |
67 | return nr_phys_segs; | |
68 | } | |
69 | ||
70 | void blk_recalc_rq_segments(struct request *rq) | |
71 | { | |
59247eae | 72 | rq->nr_phys_segments = __blk_recalc_rq_segments(rq->q, rq->bio); |
d6d48196 JA |
73 | } |
74 | ||
75 | void blk_recount_segments(struct request_queue *q, struct bio *bio) | |
76 | { | |
d6d48196 | 77 | struct bio *nxt = bio->bi_next; |
1e428079 | 78 | |
d6d48196 | 79 | bio->bi_next = NULL; |
59247eae | 80 | bio->bi_phys_segments = __blk_recalc_rq_segments(q, bio); |
d6d48196 | 81 | bio->bi_next = nxt; |
d6d48196 JA |
82 | bio->bi_flags |= (1 << BIO_SEG_VALID); |
83 | } | |
84 | EXPORT_SYMBOL(blk_recount_segments); | |
85 | ||
86 | static int blk_phys_contig_segment(struct request_queue *q, struct bio *bio, | |
87 | struct bio *nxt) | |
88 | { | |
e692cb66 | 89 | if (!blk_queue_cluster(q)) |
d6d48196 JA |
90 | return 0; |
91 | ||
86771427 | 92 | if (bio->bi_seg_back_size + nxt->bi_seg_front_size > |
ae03bf63 | 93 | queue_max_segment_size(q)) |
d6d48196 JA |
94 | return 0; |
95 | ||
e17fc0a1 DW |
96 | if (!bio_has_data(bio)) |
97 | return 1; | |
98 | ||
99 | if (!BIOVEC_PHYS_MERGEABLE(__BVEC_END(bio), __BVEC_START(nxt))) | |
100 | return 0; | |
101 | ||
d6d48196 | 102 | /* |
e17fc0a1 | 103 | * bio and nxt are contiguous in memory; check if the queue allows |
d6d48196 JA |
104 | * these two to be merged into one |
105 | */ | |
106 | if (BIO_SEG_BOUNDARY(q, bio, nxt)) | |
107 | return 1; | |
108 | ||
109 | return 0; | |
110 | } | |
111 | ||
7988613b | 112 | static inline void |
963ab9e5 | 113 | __blk_segment_map_sg(struct request_queue *q, struct bio_vec *bvec, |
7988613b | 114 | struct scatterlist *sglist, struct bio_vec *bvprv, |
963ab9e5 AH |
115 | struct scatterlist **sg, int *nsegs, int *cluster) |
116 | { | |
117 | ||
118 | int nbytes = bvec->bv_len; | |
119 | ||
7988613b | 120 | if (*sg && *cluster) { |
963ab9e5 AH |
121 | if ((*sg)->length + nbytes > queue_max_segment_size(q)) |
122 | goto new_segment; | |
123 | ||
7988613b | 124 | if (!BIOVEC_PHYS_MERGEABLE(bvprv, bvec)) |
963ab9e5 | 125 | goto new_segment; |
7988613b | 126 | if (!BIOVEC_SEG_BOUNDARY(q, bvprv, bvec)) |
963ab9e5 AH |
127 | goto new_segment; |
128 | ||
129 | (*sg)->length += nbytes; | |
130 | } else { | |
131 | new_segment: | |
132 | if (!*sg) | |
133 | *sg = sglist; | |
134 | else { | |
135 | /* | |
136 | * If the driver previously mapped a shorter | |
137 | * list, we could see a termination bit | |
138 | * prematurely unless it fully inits the sg | |
139 | * table on each mapping. We KNOW that there | |
140 | * must be more entries here or the driver | |
141 | * would be buggy, so force clear the | |
142 | * termination bit to avoid doing a full | |
143 | * sg_init_table() in drivers for each command. | |
144 | */ | |
c8164d89 | 145 | sg_unmark_end(*sg); |
963ab9e5 AH |
146 | *sg = sg_next(*sg); |
147 | } | |
148 | ||
149 | sg_set_page(*sg, bvec->bv_page, nbytes, bvec->bv_offset); | |
150 | (*nsegs)++; | |
151 | } | |
7988613b | 152 | *bvprv = *bvec; |
963ab9e5 AH |
153 | } |
154 | ||
d6d48196 JA |
155 | /* |
156 | * map a request to scatterlist, return number of sg entries setup. Caller | |
157 | * must make sure sg can hold rq->nr_phys_segments entries | |
158 | */ | |
159 | int blk_rq_map_sg(struct request_queue *q, struct request *rq, | |
160 | struct scatterlist *sglist) | |
161 | { | |
7988613b | 162 | struct bio_vec bvec, bvprv; |
d6d48196 JA |
163 | struct req_iterator iter; |
164 | struct scatterlist *sg; | |
165 | int nsegs, cluster; | |
166 | ||
167 | nsegs = 0; | |
e692cb66 | 168 | cluster = blk_queue_cluster(q); |
d6d48196 JA |
169 | |
170 | /* | |
171 | * for each bio in rq | |
172 | */ | |
d6d48196 JA |
173 | sg = NULL; |
174 | rq_for_each_segment(bvec, rq, iter) { | |
7988613b | 175 | __blk_segment_map_sg(q, &bvec, sglist, &bvprv, &sg, |
963ab9e5 | 176 | &nsegs, &cluster); |
d6d48196 JA |
177 | } /* segments in rq */ |
178 | ||
f18573ab FT |
179 | |
180 | if (unlikely(rq->cmd_flags & REQ_COPY_USER) && | |
2e46e8b2 TH |
181 | (blk_rq_bytes(rq) & q->dma_pad_mask)) { |
182 | unsigned int pad_len = | |
183 | (q->dma_pad_mask & ~blk_rq_bytes(rq)) + 1; | |
f18573ab FT |
184 | |
185 | sg->length += pad_len; | |
186 | rq->extra_len += pad_len; | |
187 | } | |
188 | ||
2fb98e84 | 189 | if (q->dma_drain_size && q->dma_drain_needed(rq)) { |
7b6d91da | 190 | if (rq->cmd_flags & REQ_WRITE) |
db0a2e00 TH |
191 | memset(q->dma_drain_buffer, 0, q->dma_drain_size); |
192 | ||
d6d48196 JA |
193 | sg->page_link &= ~0x02; |
194 | sg = sg_next(sg); | |
195 | sg_set_page(sg, virt_to_page(q->dma_drain_buffer), | |
196 | q->dma_drain_size, | |
197 | ((unsigned long)q->dma_drain_buffer) & | |
198 | (PAGE_SIZE - 1)); | |
199 | nsegs++; | |
7a85f889 | 200 | rq->extra_len += q->dma_drain_size; |
d6d48196 JA |
201 | } |
202 | ||
203 | if (sg) | |
204 | sg_mark_end(sg); | |
205 | ||
206 | return nsegs; | |
207 | } | |
d6d48196 JA |
208 | EXPORT_SYMBOL(blk_rq_map_sg); |
209 | ||
85b9f66a AH |
210 | /** |
211 | * blk_bio_map_sg - map a bio to a scatterlist | |
212 | * @q: request_queue in question | |
213 | * @bio: bio being mapped | |
214 | * @sglist: scatterlist being mapped | |
215 | * | |
216 | * Note: | |
217 | * Caller must make sure sg can hold bio->bi_phys_segments entries | |
218 | * | |
219 | * Will return the number of sg entries setup | |
220 | */ | |
221 | int blk_bio_map_sg(struct request_queue *q, struct bio *bio, | |
222 | struct scatterlist *sglist) | |
223 | { | |
7988613b | 224 | struct bio_vec bvec, bvprv; |
85b9f66a AH |
225 | struct scatterlist *sg; |
226 | int nsegs, cluster; | |
7988613b | 227 | struct bvec_iter iter; |
85b9f66a AH |
228 | |
229 | nsegs = 0; | |
230 | cluster = blk_queue_cluster(q); | |
231 | ||
85b9f66a | 232 | sg = NULL; |
7988613b KO |
233 | bio_for_each_segment(bvec, bio, iter) { |
234 | __blk_segment_map_sg(q, &bvec, sglist, &bvprv, &sg, | |
85b9f66a AH |
235 | &nsegs, &cluster); |
236 | } /* segments in bio */ | |
237 | ||
238 | if (sg) | |
239 | sg_mark_end(sg); | |
240 | ||
241 | BUG_ON(bio->bi_phys_segments && nsegs > bio->bi_phys_segments); | |
242 | return nsegs; | |
243 | } | |
244 | EXPORT_SYMBOL(blk_bio_map_sg); | |
245 | ||
d6d48196 JA |
246 | static inline int ll_new_hw_segment(struct request_queue *q, |
247 | struct request *req, | |
248 | struct bio *bio) | |
249 | { | |
d6d48196 JA |
250 | int nr_phys_segs = bio_phys_segments(q, bio); |
251 | ||
13f05c8d MP |
252 | if (req->nr_phys_segments + nr_phys_segs > queue_max_segments(q)) |
253 | goto no_merge; | |
254 | ||
255 | if (bio_integrity(bio) && blk_integrity_merge_bio(q, req, bio)) | |
256 | goto no_merge; | |
d6d48196 JA |
257 | |
258 | /* | |
259 | * This will form the start of a new hw segment. Bump both | |
260 | * counters. | |
261 | */ | |
d6d48196 JA |
262 | req->nr_phys_segments += nr_phys_segs; |
263 | return 1; | |
13f05c8d MP |
264 | |
265 | no_merge: | |
266 | req->cmd_flags |= REQ_NOMERGE; | |
267 | if (req == q->last_merge) | |
268 | q->last_merge = NULL; | |
269 | return 0; | |
d6d48196 JA |
270 | } |
271 | ||
272 | int ll_back_merge_fn(struct request_queue *q, struct request *req, | |
273 | struct bio *bio) | |
274 | { | |
f31dc1cd MP |
275 | if (blk_rq_sectors(req) + bio_sectors(bio) > |
276 | blk_rq_get_max_sectors(req)) { | |
d6d48196 JA |
277 | req->cmd_flags |= REQ_NOMERGE; |
278 | if (req == q->last_merge) | |
279 | q->last_merge = NULL; | |
280 | return 0; | |
281 | } | |
2cdf79ca | 282 | if (!bio_flagged(req->biotail, BIO_SEG_VALID)) |
d6d48196 | 283 | blk_recount_segments(q, req->biotail); |
2cdf79ca | 284 | if (!bio_flagged(bio, BIO_SEG_VALID)) |
d6d48196 | 285 | blk_recount_segments(q, bio); |
d6d48196 JA |
286 | |
287 | return ll_new_hw_segment(q, req, bio); | |
288 | } | |
289 | ||
6728cb0e | 290 | int ll_front_merge_fn(struct request_queue *q, struct request *req, |
d6d48196 JA |
291 | struct bio *bio) |
292 | { | |
f31dc1cd MP |
293 | if (blk_rq_sectors(req) + bio_sectors(bio) > |
294 | blk_rq_get_max_sectors(req)) { | |
d6d48196 JA |
295 | req->cmd_flags |= REQ_NOMERGE; |
296 | if (req == q->last_merge) | |
297 | q->last_merge = NULL; | |
298 | return 0; | |
299 | } | |
2cdf79ca | 300 | if (!bio_flagged(bio, BIO_SEG_VALID)) |
d6d48196 | 301 | blk_recount_segments(q, bio); |
2cdf79ca | 302 | if (!bio_flagged(req->bio, BIO_SEG_VALID)) |
d6d48196 | 303 | blk_recount_segments(q, req->bio); |
d6d48196 JA |
304 | |
305 | return ll_new_hw_segment(q, req, bio); | |
306 | } | |
307 | ||
e7e24500 JA |
308 | /* |
309 | * blk-mq uses req->special to carry normal driver per-request payload, it | |
310 | * does not indicate a prepared command that we cannot merge with. | |
311 | */ | |
312 | static bool req_no_special_merge(struct request *req) | |
313 | { | |
314 | struct request_queue *q = req->q; | |
315 | ||
316 | return !q->mq_ops && req->special; | |
317 | } | |
318 | ||
d6d48196 JA |
319 | static int ll_merge_requests_fn(struct request_queue *q, struct request *req, |
320 | struct request *next) | |
321 | { | |
322 | int total_phys_segments; | |
86771427 FT |
323 | unsigned int seg_size = |
324 | req->biotail->bi_seg_back_size + next->bio->bi_seg_front_size; | |
d6d48196 JA |
325 | |
326 | /* | |
327 | * First check if the either of the requests are re-queued | |
328 | * requests. Can't merge them if they are. | |
329 | */ | |
e7e24500 | 330 | if (req_no_special_merge(req) || req_no_special_merge(next)) |
d6d48196 JA |
331 | return 0; |
332 | ||
333 | /* | |
334 | * Will it become too large? | |
335 | */ | |
f31dc1cd MP |
336 | if ((blk_rq_sectors(req) + blk_rq_sectors(next)) > |
337 | blk_rq_get_max_sectors(req)) | |
d6d48196 JA |
338 | return 0; |
339 | ||
340 | total_phys_segments = req->nr_phys_segments + next->nr_phys_segments; | |
86771427 FT |
341 | if (blk_phys_contig_segment(q, req->biotail, next->bio)) { |
342 | if (req->nr_phys_segments == 1) | |
343 | req->bio->bi_seg_front_size = seg_size; | |
344 | if (next->nr_phys_segments == 1) | |
345 | next->biotail->bi_seg_back_size = seg_size; | |
d6d48196 | 346 | total_phys_segments--; |
86771427 | 347 | } |
d6d48196 | 348 | |
8a78362c | 349 | if (total_phys_segments > queue_max_segments(q)) |
d6d48196 JA |
350 | return 0; |
351 | ||
13f05c8d MP |
352 | if (blk_integrity_rq(req) && blk_integrity_merge_rq(q, req, next)) |
353 | return 0; | |
354 | ||
d6d48196 JA |
355 | /* Merge is OK... */ |
356 | req->nr_phys_segments = total_phys_segments; | |
d6d48196 JA |
357 | return 1; |
358 | } | |
359 | ||
80a761fd TH |
360 | /** |
361 | * blk_rq_set_mixed_merge - mark a request as mixed merge | |
362 | * @rq: request to mark as mixed merge | |
363 | * | |
364 | * Description: | |
365 | * @rq is about to be mixed merged. Make sure the attributes | |
366 | * which can be mixed are set in each bio and mark @rq as mixed | |
367 | * merged. | |
368 | */ | |
369 | void blk_rq_set_mixed_merge(struct request *rq) | |
370 | { | |
371 | unsigned int ff = rq->cmd_flags & REQ_FAILFAST_MASK; | |
372 | struct bio *bio; | |
373 | ||
374 | if (rq->cmd_flags & REQ_MIXED_MERGE) | |
375 | return; | |
376 | ||
377 | /* | |
378 | * @rq will no longer represent mixable attributes for all the | |
379 | * contained bios. It will just track those of the first one. | |
380 | * Distributes the attributs to each bio. | |
381 | */ | |
382 | for (bio = rq->bio; bio; bio = bio->bi_next) { | |
383 | WARN_ON_ONCE((bio->bi_rw & REQ_FAILFAST_MASK) && | |
384 | (bio->bi_rw & REQ_FAILFAST_MASK) != ff); | |
385 | bio->bi_rw |= ff; | |
386 | } | |
387 | rq->cmd_flags |= REQ_MIXED_MERGE; | |
388 | } | |
389 | ||
26308eab JM |
390 | static void blk_account_io_merge(struct request *req) |
391 | { | |
392 | if (blk_do_io_stat(req)) { | |
393 | struct hd_struct *part; | |
394 | int cpu; | |
395 | ||
396 | cpu = part_stat_lock(); | |
09e099d4 | 397 | part = req->part; |
26308eab JM |
398 | |
399 | part_round_stats(cpu, part); | |
316d315b | 400 | part_dec_in_flight(part, rq_data_dir(req)); |
26308eab | 401 | |
6c23a968 | 402 | hd_struct_put(part); |
26308eab JM |
403 | part_stat_unlock(); |
404 | } | |
405 | } | |
406 | ||
d6d48196 JA |
407 | /* |
408 | * Has to be called with the request spinlock acquired | |
409 | */ | |
410 | static int attempt_merge(struct request_queue *q, struct request *req, | |
411 | struct request *next) | |
412 | { | |
413 | if (!rq_mergeable(req) || !rq_mergeable(next)) | |
414 | return 0; | |
415 | ||
f31dc1cd MP |
416 | if (!blk_check_merge_flags(req->cmd_flags, next->cmd_flags)) |
417 | return 0; | |
418 | ||
d6d48196 JA |
419 | /* |
420 | * not contiguous | |
421 | */ | |
83096ebf | 422 | if (blk_rq_pos(req) + blk_rq_sectors(req) != blk_rq_pos(next)) |
d6d48196 JA |
423 | return 0; |
424 | ||
425 | if (rq_data_dir(req) != rq_data_dir(next) | |
426 | || req->rq_disk != next->rq_disk | |
e7e24500 | 427 | || req_no_special_merge(next)) |
d6d48196 JA |
428 | return 0; |
429 | ||
4363ac7c MP |
430 | if (req->cmd_flags & REQ_WRITE_SAME && |
431 | !blk_write_same_mergeable(req->bio, next->bio)) | |
432 | return 0; | |
433 | ||
d6d48196 JA |
434 | /* |
435 | * If we are allowed to merge, then append bio list | |
436 | * from next to rq and release next. merge_requests_fn | |
437 | * will have updated segment counts, update sector | |
438 | * counts here. | |
439 | */ | |
440 | if (!ll_merge_requests_fn(q, req, next)) | |
441 | return 0; | |
442 | ||
80a761fd TH |
443 | /* |
444 | * If failfast settings disagree or any of the two is already | |
445 | * a mixed merge, mark both as mixed before proceeding. This | |
446 | * makes sure that all involved bios have mixable attributes | |
447 | * set properly. | |
448 | */ | |
449 | if ((req->cmd_flags | next->cmd_flags) & REQ_MIXED_MERGE || | |
450 | (req->cmd_flags & REQ_FAILFAST_MASK) != | |
451 | (next->cmd_flags & REQ_FAILFAST_MASK)) { | |
452 | blk_rq_set_mixed_merge(req); | |
453 | blk_rq_set_mixed_merge(next); | |
454 | } | |
455 | ||
d6d48196 JA |
456 | /* |
457 | * At this point we have either done a back merge | |
458 | * or front merge. We need the smaller start_time of | |
459 | * the merged requests to be the current request | |
460 | * for accounting purposes. | |
461 | */ | |
462 | if (time_after(req->start_time, next->start_time)) | |
463 | req->start_time = next->start_time; | |
464 | ||
465 | req->biotail->bi_next = next->bio; | |
466 | req->biotail = next->biotail; | |
467 | ||
a2dec7b3 | 468 | req->__data_len += blk_rq_bytes(next); |
d6d48196 JA |
469 | |
470 | elv_merge_requests(q, req, next); | |
471 | ||
42dad764 JM |
472 | /* |
473 | * 'next' is going away, so update stats accordingly | |
474 | */ | |
475 | blk_account_io_merge(next); | |
d6d48196 JA |
476 | |
477 | req->ioprio = ioprio_best(req->ioprio, next->ioprio); | |
ab780f1e JA |
478 | if (blk_rq_cpu_valid(next)) |
479 | req->cpu = next->cpu; | |
d6d48196 | 480 | |
1cd96c24 BH |
481 | /* owner-ship of bio passed from next to req */ |
482 | next->bio = NULL; | |
d6d48196 JA |
483 | __blk_put_request(q, next); |
484 | return 1; | |
485 | } | |
486 | ||
487 | int attempt_back_merge(struct request_queue *q, struct request *rq) | |
488 | { | |
489 | struct request *next = elv_latter_request(q, rq); | |
490 | ||
491 | if (next) | |
492 | return attempt_merge(q, rq, next); | |
493 | ||
494 | return 0; | |
495 | } | |
496 | ||
497 | int attempt_front_merge(struct request_queue *q, struct request *rq) | |
498 | { | |
499 | struct request *prev = elv_former_request(q, rq); | |
500 | ||
501 | if (prev) | |
502 | return attempt_merge(q, prev, rq); | |
503 | ||
504 | return 0; | |
505 | } | |
5e84ea3a JA |
506 | |
507 | int blk_attempt_req_merge(struct request_queue *q, struct request *rq, | |
508 | struct request *next) | |
509 | { | |
510 | return attempt_merge(q, rq, next); | |
511 | } | |
050c8ea8 TH |
512 | |
513 | bool blk_rq_merge_ok(struct request *rq, struct bio *bio) | |
514 | { | |
e2a60da7 | 515 | if (!rq_mergeable(rq) || !bio_mergeable(bio)) |
050c8ea8 TH |
516 | return false; |
517 | ||
f31dc1cd MP |
518 | if (!blk_check_merge_flags(rq->cmd_flags, bio->bi_rw)) |
519 | return false; | |
520 | ||
050c8ea8 TH |
521 | /* different data direction or already started, don't merge */ |
522 | if (bio_data_dir(bio) != rq_data_dir(rq)) | |
523 | return false; | |
524 | ||
525 | /* must be same device and not a special request */ | |
e7e24500 | 526 | if (rq->rq_disk != bio->bi_bdev->bd_disk || req_no_special_merge(rq)) |
050c8ea8 TH |
527 | return false; |
528 | ||
529 | /* only merge integrity protected bio into ditto rq */ | |
530 | if (bio_integrity(bio) != blk_integrity_rq(rq)) | |
531 | return false; | |
532 | ||
4363ac7c MP |
533 | /* must be using the same buffer */ |
534 | if (rq->cmd_flags & REQ_WRITE_SAME && | |
535 | !blk_write_same_mergeable(rq->bio, bio)) | |
536 | return false; | |
537 | ||
050c8ea8 TH |
538 | return true; |
539 | } | |
540 | ||
541 | int blk_try_merge(struct request *rq, struct bio *bio) | |
542 | { | |
4f024f37 | 543 | if (blk_rq_pos(rq) + blk_rq_sectors(rq) == bio->bi_iter.bi_sector) |
050c8ea8 | 544 | return ELEVATOR_BACK_MERGE; |
4f024f37 | 545 | else if (blk_rq_pos(rq) - bio_sectors(bio) == bio->bi_iter.bi_sector) |
050c8ea8 TH |
546 | return ELEVATOR_FRONT_MERGE; |
547 | return ELEVATOR_NO_MERGE; | |
548 | } |