mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-25 05:04:09 +08:00
5f7136db82
It's often inconvenient to use BIO_MAX_PAGES due to min() requiring the sign to be the same. Introduce bio_max_segs() and change BIO_MAX_PAGES to be unsigned to make it easier for the users. Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
62 lines
1.3 KiB
C
62 lines
1.3 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* Copyright (c) 2019 Christoph Hellwig.
|
|
*/
|
|
#include "xfs.h"
|
|
|
|
static inline unsigned int bio_max_vecs(unsigned int count)
|
|
{
|
|
return bio_max_segs(howmany(count, PAGE_SIZE));
|
|
}
|
|
|
|
int
|
|
xfs_rw_bdev(
|
|
struct block_device *bdev,
|
|
sector_t sector,
|
|
unsigned int count,
|
|
char *data,
|
|
unsigned int op)
|
|
|
|
{
|
|
unsigned int is_vmalloc = is_vmalloc_addr(data);
|
|
unsigned int left = count;
|
|
int error;
|
|
struct bio *bio;
|
|
|
|
if (is_vmalloc && op == REQ_OP_WRITE)
|
|
flush_kernel_vmap_range(data, count);
|
|
|
|
bio = bio_alloc(GFP_KERNEL, bio_max_vecs(left));
|
|
bio_set_dev(bio, bdev);
|
|
bio->bi_iter.bi_sector = sector;
|
|
bio->bi_opf = op | REQ_META | REQ_SYNC;
|
|
|
|
do {
|
|
struct page *page = kmem_to_page(data);
|
|
unsigned int off = offset_in_page(data);
|
|
unsigned int len = min_t(unsigned, left, PAGE_SIZE - off);
|
|
|
|
while (bio_add_page(bio, page, len, off) != len) {
|
|
struct bio *prev = bio;
|
|
|
|
bio = bio_alloc(GFP_KERNEL, bio_max_vecs(left));
|
|
bio_copy_dev(bio, prev);
|
|
bio->bi_iter.bi_sector = bio_end_sector(prev);
|
|
bio->bi_opf = prev->bi_opf;
|
|
bio_chain(prev, bio);
|
|
|
|
submit_bio(prev);
|
|
}
|
|
|
|
data += len;
|
|
left -= len;
|
|
} while (left > 0);
|
|
|
|
error = submit_bio_wait(bio);
|
|
bio_put(bio);
|
|
|
|
if (is_vmalloc && op == REQ_OP_READ)
|
|
invalidate_kernel_vmap_range(data, count);
|
|
return error;
|
|
}
|