Lines Matching refs:bio
7 #include <linux/bio.h>
18 struct request *prev_rq, struct bio *prev, struct bio *next)
26 * Don't merge if the 1st bio starts with non-zero offset, otherwise it
31 bio_get_first_bvec(prev_rq->bio, &pb);
42 * - if 'pb' ends unaligned, the next bio must include
53 static inline bool req_gap_back_merge(struct request *req, struct bio *bio)
55 return bio_will_gap(req->q, req, req->biotail, bio);
58 static inline bool req_gap_front_merge(struct request *req, struct bio *bio)
60 return bio_will_gap(req->q, NULL, bio, req->bio);
63 static struct bio *blk_bio_discard_split(struct request_queue *q,
64 struct bio *bio,
87 if (bio_sectors(bio) <= max_discard_sectors)
98 tmp = bio->bi_iter.bi_sector + split_sectors - alignment;
104 return bio_split(bio, split_sectors, GFP_NOIO, bs);
107 static struct bio *blk_bio_write_zeroes_split(struct request_queue *q,
108 struct bio *bio, struct bio_set *bs, unsigned *nsegs)
115 if (bio_sectors(bio) <= q->limits.max_write_zeroes_sectors)
118 return bio_split(bio, q->limits.max_write_zeroes_sectors, GFP_NOIO, bs);
121 static struct bio *blk_bio_write_same_split(struct request_queue *q,
122 struct bio *bio,
131 if (bio_sectors(bio) <= q->limits.max_write_same_sectors)
134 return bio_split(bio, q->limits.max_write_same_sectors, GFP_NOIO, bs);
138 * Return the maximum number of sectors from the start of a bio that may be
142 * requests that are submitted to a block device if the start of a bio is not
146 struct bio *bio)
148 unsigned sectors = blk_max_size_offset(q, bio->bi_iter.bi_sector, 0);
152 unsigned start_offset = bio->bi_iter.bi_sector & (pbs - 1);
180 * @q: [in] request queue associated with the bio associated with @bv
182 * @nsegs: [in,out] Number of segments in the bio being built. Incremented
184 * bio without exceeding @max_segs
185 * @sectors: [in,out] Number of sectors in the bio being built. Incremented
187 * bio without exceeding @max_sectors
191 * When splitting a bio, it can happen that a bvec is encountered that is too
194 * %true is returned if and only if appending the entire @bv to a bio with
195 * *@nsegs segments and *@sectors sectors would make that bio unacceptable for
228 * blk_bio_segment_split - split a bio in two bios
230 * @bio: [in] bio to be split
231 * @bs: [in] bio set to allocate the clone from
232 * @segs: [out] number of segments in the bio with the first half of the sectors
234 * Clone @bio, update the bi_iter of the clone to represent the first sectors
235 * of @bio and update @bio->bi_iter to represent the remaining sectors. The
236 * following is guaranteed for the cloned bio:
237 * - That it has at most get_max_io_size(@q, @bio) sectors.
240 * Except for discard requests the cloned bio will point at the bi_io_vec of
241 * the original bio. It is the responsibility of the caller to ensure that the
242 * original bio is not freed before the cloned bio. The caller is also
244 * split bio has finished.
246 static struct bio *blk_bio_segment_split(struct request_queue *q,
247 struct bio *bio,
254 const unsigned max_sectors = get_max_io_size(q, bio);
257 bio_for_each_bvec(bv, bio, iter) {
283 return bio_split(bio, sectors, GFP_NOIO, bs);
287 * __blk_queue_split - split a bio and submit the second half
288 * @bio: [in, out] bio to be split
289 * @nr_segs: [out] number of segments in the first bio
291 * Split a bio into two bios, chain the two bios, submit the second half and
292 * store a pointer to the first half in *@bio. If the second bio is still too
294 * function may allocate a new bio from @bio->bi_disk->queue->bio_split, it is
296 * @bio->bi_disk->queue->bio_split is only released after processing of the
297 * split bio has finished.
299 void __blk_queue_split(struct bio **bio, unsigned int *nr_segs)
301 struct request_queue *q = (*bio)->bi_disk->queue;
302 struct bio *split = NULL;
304 switch (bio_op(*bio)) {
307 split = blk_bio_discard_split(q, *bio, &q->bio_split, nr_segs);
310 split = blk_bio_write_zeroes_split(q, *bio, &q->bio_split,
314 split = blk_bio_write_same_split(q, *bio, &q->bio_split,
321 * the fact that bi_io_vec[0] is always valid if a bio has data.
327 (*bio)->bi_vcnt == 1 &&
328 ((*bio)->bi_io_vec[0].bv_len +
329 (*bio)->bi_io_vec[0].bv_offset) <= PAGE_SIZE) {
333 split = blk_bio_segment_split(q, *bio, &q->bio_split, nr_segs);
338 /* there isn't chance to merge the splitted bio */
341 bio_chain(split, *bio);
342 trace_block_split(q, split, (*bio)->bi_iter.bi_sector);
343 submit_bio_noacct(*bio);
344 *bio = split;
346 blk_throtl_charge_bio_split(*bio);
351 * blk_queue_split - split a bio and submit the second half
352 * @bio: [in, out] bio to be split
354 * Split a bio into two bios, chains the two bios, submit the second half and
355 * store a pointer to the first half in *@bio. Since this function may allocate
356 * a new bio from @bio->bi_disk->queue->bio_split, it is the responsibility of
357 * the caller to ensure that @bio->bi_disk->queue->bio_split is only released
358 * after processing of the split bio has finished.
360 void blk_queue_split(struct bio **bio)
364 __blk_queue_split(bio, &nr_segs);
375 if (!rq->bio)
378 switch (bio_op(rq->bio)) {
382 struct bio *bio = rq->bio;
384 for_each_bio(bio)
483 static int __blk_bios_map_sg(struct request_queue *q, struct bio *bio,
492 for_each_bio(bio) {
493 bio_for_each_bvec(bvec, bio, iter) {
496 * have done bio internal merge when adding pages
497 * to bio
510 if (likely(bio->bi_iter.bi_size)) {
530 else if (rq->bio && bio_op(rq->bio) == REQ_OP_WRITE_SAME)
531 nsegs = __blk_bvec_map_sg(bio_iovec(rq->bio), sglist, last_sg);
532 else if (rq->bio)
533 nsegs = __blk_bios_map_sg(q, rq->bio, sglist, last_sg);
555 static inline int ll_new_hw_segment(struct request *req, struct bio *bio,
558 if (!blk_cgroup_mergeable(req, bio))
561 if (blk_integrity_merge_bio(req->q, req, bio) == false)
583 int ll_back_merge_fn(struct request *req, struct bio *bio, unsigned int nr_segs)
585 if (req_gap_back_merge(req, bio))
588 integrity_req_gap_back_merge(req, bio))
590 if (!bio_crypt_ctx_back_mergeable(req, bio))
592 if (blk_rq_sectors(req) + bio_sectors(bio) >
598 return ll_new_hw_segment(req, bio, nr_segs);
601 static int ll_front_merge_fn(struct request *req, struct bio *bio,
604 if (req_gap_front_merge(req, bio))
607 integrity_req_gap_front_merge(req, bio))
609 if (!bio_crypt_ctx_front_mergeable(req, bio))
611 if (blk_rq_sectors(req) + bio_sectors(bio) >
612 blk_rq_get_max_sectors(req, bio->bi_iter.bi_sector)) {
617 return ll_new_hw_segment(req, bio, nr_segs);
627 if (blk_rq_sectors(req) + bio_sectors(next->bio) >
643 if (req_gap_back_merge(req, next->bio))
657 if (!blk_cgroup_mergeable(req, next->bio))
677 * which can be mixed are set in each bio and mark @rq as mixed
683 struct bio *bio;
691 * Distributes the attributs to each bio.
693 for (bio = rq->bio; bio; bio = bio->bi_next) {
694 WARN_ON_ONCE((bio->bi_opf & REQ_FAILFAST_MASK) &&
695 (bio->bi_opf & REQ_FAILFAST_MASK) != ff);
696 bio->bi_opf |= ff;
741 !blk_write_same_mergeable(req->bio, next->bio))
755 * If we are allowed to merge, then append bio list
796 req->biotail->bi_next = next->bio;
814 * ownership of bio passed from next to req, return 'next' for
817 next->bio = NULL;
854 bool blk_rq_merge_ok(struct request *rq, struct bio *bio)
856 if (!rq_mergeable(rq) || !bio_mergeable(bio))
859 if (req_op(rq) != bio_op(bio))
863 if (bio_data_dir(bio) != rq_data_dir(rq))
867 if (rq->rq_disk != bio->bi_disk)
871 if (!blk_cgroup_mergeable(rq, bio))
874 /* only merge integrity protected bio into ditto rq */
875 if (blk_integrity_merge_bio(rq->q, rq, bio) == false)
879 if (!bio_crypt_rq_ctx_compatible(rq, bio))
884 !blk_write_same_mergeable(rq->bio, bio))
891 if (rq->write_hint != bio->bi_write_hint)
894 if (rq->ioprio != bio_prio(bio))
900 enum elv_merge blk_try_merge(struct request *rq, struct bio *bio)
904 else if (blk_rq_pos(rq) + blk_rq_sectors(rq) == bio->bi_iter.bi_sector)
906 else if (blk_rq_pos(rq) - bio_sectors(bio) == bio->bi_iter.bi_sector)
928 struct bio *bio, unsigned int nr_segs)
930 const int ff = bio->bi_opf & REQ_FAILFAST_MASK;
932 if (!ll_back_merge_fn(req, bio, nr_segs))
935 trace_block_bio_backmerge(req->q, req, bio);
936 rq_qos_merge(req->q, req, bio);
941 req->biotail->bi_next = bio;
942 req->biotail = bio;
943 req->__data_len += bio->bi_iter.bi_size;
945 bio_crypt_free_ctx(bio);
952 struct bio *bio, unsigned int nr_segs)
954 const int ff = bio->bi_opf & REQ_FAILFAST_MASK;
956 if (!ll_front_merge_fn(req, bio, nr_segs))
959 trace_block_bio_frontmerge(req->q, req, bio);
960 rq_qos_merge(req->q, req, bio);
965 bio->bi_next = req->bio;
966 req->bio = bio;
968 req->__sector = bio->bi_iter.bi_sector;
969 req->__data_len += bio->bi_iter.bi_size;
971 bio_crypt_do_front_merge(req, bio);
978 struct request *req, struct bio *bio)
984 if (blk_rq_sectors(req) + bio_sectors(bio) >
988 rq_qos_merge(q, req, bio);
990 req->biotail->bi_next = bio;
991 req->biotail = bio;
992 req->__data_len += bio->bi_iter.bi_size;
1004 struct bio *bio,
1008 if (!blk_rq_merge_ok(rq, bio))
1011 switch (blk_try_merge(rq, bio)) {
1013 if (!sched_allow_merge || blk_mq_sched_allow_merge(q, rq, bio))
1014 return bio_attempt_back_merge(rq, bio, nr_segs);
1017 if (!sched_allow_merge || blk_mq_sched_allow_merge(q, rq, bio))
1018 return bio_attempt_front_merge(rq, bio, nr_segs);
1021 return bio_attempt_discard_merge(q, rq, bio);
1031 * @q: request_queue new bio is being queued at
1032 * @bio: new bio being queued
1033 * @nr_segs: number of segments in @bio
1038 * Determine whether @bio being queued on @q can be merged with a request
1051 bool blk_attempt_plug_merge(struct request_queue *q, struct bio *bio,
1058 plug = blk_mq_plug(q, bio);
1077 if (blk_attempt_bio_merge(q, rq, bio, nr_segs, false) ==
1086 * Iterate list of requests and see if we can merge this bio with any
1090 struct bio *bio, unsigned int nr_segs)
1099 switch (blk_attempt_bio_merge(q, rq, bio, nr_segs, true)) {
1114 bool blk_mq_sched_try_merge(struct request_queue *q, struct bio *bio,
1119 switch (elv_merge(q, &rq, bio)) {
1121 if (!blk_mq_sched_allow_merge(q, rq, bio))
1123 if (bio_attempt_back_merge(rq, bio, nr_segs) != BIO_MERGE_OK)
1130 if (!blk_mq_sched_allow_merge(q, rq, bio))
1132 if (bio_attempt_front_merge(rq, bio, nr_segs) != BIO_MERGE_OK)
1139 return bio_attempt_discard_merge(q, rq, bio) == BIO_MERGE_OK;