blk-merge.c (dad7758459bc6097115f5e783eda232f36b1ad99) blk-merge.c (ff9811b3cf2092fe6c39cf694e5e7f949f3b2c16)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Functions related to segment and merge handling
4 */
5#include <linux/kernel.h>
6#include <linux/module.h>
7#include <linux/bio.h>
8#include <linux/blkdev.h>

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

162 * variables.
163 */
164static bool bvec_split_segs(const struct request_queue *q,
165 const struct bio_vec *bv, unsigned *nsegs,
166 unsigned *sectors, unsigned max_segs)
167{
168 unsigned len = bv->bv_len;
169 unsigned total_len = 0;
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Functions related to segment and merge handling
4 */
5#include <linux/kernel.h>
6#include <linux/module.h>
7#include <linux/bio.h>
8#include <linux/blkdev.h>

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

162 * variables.
163 */
164static bool bvec_split_segs(const struct request_queue *q,
165 const struct bio_vec *bv, unsigned *nsegs,
166 unsigned *sectors, unsigned max_segs)
167{
168 unsigned len = bv->bv_len;
169 unsigned total_len = 0;
170 unsigned new_nsegs = 0, seg_size = 0;
170 unsigned seg_size = 0;
171
172 /*
173 * Multi-page bvec may be too big to hold in one segment, so the
174 * current bvec has to be splitted as multiple segments.
175 */
171
172 /*
173 * Multi-page bvec may be too big to hold in one segment, so the
174 * current bvec has to be splitted as multiple segments.
175 */
176 while (len && new_nsegs + *nsegs < max_segs) {
176 while (len && *nsegs < max_segs) {
177 seg_size = get_max_segment_size(q, bv->bv_offset + total_len);
178 seg_size = min(seg_size, len);
179
177 seg_size = get_max_segment_size(q, bv->bv_offset + total_len);
178 seg_size = min(seg_size, len);
179
180 new_nsegs++;
180 (*nsegs)++;
181 total_len += seg_size;
182 len -= seg_size;
183
184 if ((bv->bv_offset + total_len) & queue_virt_boundary(q))
185 break;
186 }
187
181 total_len += seg_size;
182 len -= seg_size;
183
184 if ((bv->bv_offset + total_len) & queue_virt_boundary(q))
185 break;
186 }
187
188 if (new_nsegs) {
189 *nsegs += new_nsegs;
190 if (sectors)
191 *sectors += total_len >> 9;
192 }
188 *sectors += total_len >> 9;
193
194 /* split in the middle of the bvec if len != 0 */
195 return !!len;
196}
197
198/**
199 * blk_bio_segment_split - split a bio in two bios
200 * @q: [in] request queue pointer

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

344
345 __blk_queue_split(q, bio, &nr_segs);
346}
347EXPORT_SYMBOL(blk_queue_split);
348
349unsigned int blk_recalc_rq_segments(struct request *rq)
350{
351 unsigned int nr_phys_segs = 0;
189
190 /* split in the middle of the bvec if len != 0 */
191 return !!len;
192}
193
194/**
195 * blk_bio_segment_split - split a bio in two bios
196 * @q: [in] request queue pointer

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

340
341 __blk_queue_split(q, bio, &nr_segs);
342}
343EXPORT_SYMBOL(blk_queue_split);
344
345unsigned int blk_recalc_rq_segments(struct request *rq)
346{
347 unsigned int nr_phys_segs = 0;
348 unsigned int nr_sectors = 0;
352 struct req_iterator iter;
353 struct bio_vec bv;
354
355 if (!rq->bio)
356 return 0;
357
358 switch (bio_op(rq->bio)) {
359 case REQ_OP_DISCARD:
360 case REQ_OP_SECURE_ERASE:
361 case REQ_OP_WRITE_ZEROES:
362 return 0;
363 case REQ_OP_WRITE_SAME:
364 return 1;
365 }
366
367 rq_for_each_bvec(bv, rq, iter)
349 struct req_iterator iter;
350 struct bio_vec bv;
351
352 if (!rq->bio)
353 return 0;
354
355 switch (bio_op(rq->bio)) {
356 case REQ_OP_DISCARD:
357 case REQ_OP_SECURE_ERASE:
358 case REQ_OP_WRITE_ZEROES:
359 return 0;
360 case REQ_OP_WRITE_SAME:
361 return 1;
362 }
363
364 rq_for_each_bvec(bv, rq, iter)
368 bvec_split_segs(rq->q, &bv, &nr_phys_segs, NULL, UINT_MAX);
365 bvec_split_segs(rq->q, &bv, &nr_phys_segs, &nr_sectors,
366 UINT_MAX);
369 return nr_phys_segs;
370}
371
372static inline struct scatterlist *blk_next_sg(struct scatterlist **sg,
373 struct scatterlist *sglist)
374{
375 if (!*sg)
376 return sglist;

--- 510 unchanged lines hidden ---
367 return nr_phys_segs;
368}
369
370static inline struct scatterlist *blk_next_sg(struct scatterlist **sg,
371 struct scatterlist *sglist)
372{
373 if (!*sg)
374 return sglist;

--- 510 unchanged lines hidden ---