2019-06-29 10:27:26 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 Christoph Hellwig.
|
|
|
|
*/
|
|
|
|
#include "xfs.h"
|
|
|
|
|
|
|
|
static inline unsigned int bio_max_vecs(unsigned int count)
|
|
|
|
{
|
2021-01-29 12:38:57 +08:00
|
|
|
return bio_max_segs(howmany(count, PAGE_SIZE));
|
2019-06-29 10:27:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
xfs_rw_bdev(
|
|
|
|
struct block_device *bdev,
|
|
|
|
sector_t sector,
|
|
|
|
unsigned int count,
|
|
|
|
char *data,
|
2022-07-15 02:07:28 +08:00
|
|
|
enum req_op op)
|
2019-06-29 10:27:26 +08:00
|
|
|
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
2022-01-24 17:11:05 +08:00
|
|
|
bio = bio_alloc(bdev, bio_max_vecs(left), op | REQ_META | REQ_SYNC,
|
|
|
|
GFP_KERNEL);
|
2019-06-29 10:27:26 +08:00
|
|
|
bio->bi_iter.bi_sector = sector;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2022-01-24 17:11:05 +08:00
|
|
|
bio = bio_alloc(prev->bi_bdev, bio_max_vecs(left),
|
|
|
|
prev->bi_opf, GFP_KERNEL);
|
2019-06-29 10:27:26 +08:00
|
|
|
bio->bi_iter.bi_sector = bio_end_sector(prev);
|
2019-07-09 23:58:28 +08:00
|
|
|
bio_chain(prev, bio);
|
2019-06-29 10:27:26 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|