Skip to content

Commit ab89e8e

Browse files
Kanchan Joshiaxboe
authored andcommitted
block: factor out blk_rq_map_bio_alloc helper
Move bio allocation logic from bio_map_user_iov to a new helper blk_rq_map_bio_alloc. It is named so because functionality is opposite of what is done inside blk_mq_map_bio_put. This is a prep patch. Signed-off-by: Kanchan Joshi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 32f1c71 commit ab89e8e

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

block/blk-map.c

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -241,31 +241,42 @@ static void blk_mq_map_bio_put(struct bio *bio)
241241
}
242242
}
243243

244-
static int bio_map_user_iov(struct request *rq, struct iov_iter *iter,
245-
gfp_t gfp_mask)
244+
static struct bio *blk_rq_map_bio_alloc(struct request *rq,
245+
unsigned int nr_vecs, gfp_t gfp_mask)
246246
{
247-
unsigned int max_sectors = queue_max_hw_sectors(rq->q);
248-
unsigned int nr_vecs = iov_iter_npages(iter, BIO_MAX_VECS);
249247
struct bio *bio;
250-
int ret;
251-
int j;
252-
253-
if (!iov_iter_count(iter))
254-
return -EINVAL;
255248

256249
if (rq->cmd_flags & REQ_POLLED) {
257250
blk_opf_t opf = rq->cmd_flags | REQ_ALLOC_CACHE;
258251

259252
bio = bio_alloc_bioset(NULL, nr_vecs, opf, gfp_mask,
260253
&fs_bio_set);
261254
if (!bio)
262-
return -ENOMEM;
255+
return NULL;
263256
} else {
264257
bio = bio_kmalloc(nr_vecs, gfp_mask);
265258
if (!bio)
266-
return -ENOMEM;
259+
return NULL;
267260
bio_init(bio, NULL, bio->bi_inline_vecs, nr_vecs, req_op(rq));
268261
}
262+
return bio;
263+
}
264+
265+
static int bio_map_user_iov(struct request *rq, struct iov_iter *iter,
266+
gfp_t gfp_mask)
267+
{
268+
unsigned int max_sectors = queue_max_hw_sectors(rq->q);
269+
unsigned int nr_vecs = iov_iter_npages(iter, BIO_MAX_VECS);
270+
struct bio *bio;
271+
int ret;
272+
int j;
273+
274+
if (!iov_iter_count(iter))
275+
return -EINVAL;
276+
277+
bio = blk_rq_map_bio_alloc(rq, nr_vecs, gfp_mask);
278+
if (bio == NULL)
279+
return -ENOMEM;
269280

270281
while (iov_iter_count(iter)) {
271282
struct page **pages, *stack_pages[UIO_FASTIOV];

0 commit comments

Comments
 (0)