13 #include <linux/prefetch.h>
15 #define PAGE_OFS(ofs) ((ofs) & (PAGE_SIZE-1))
17 static void request_complete(
struct bio *bio,
int err)
25 struct bio_vec bio_vec;
30 bio.bi_io_vec = &bio_vec;
31 bio_vec.bv_page =
page;
33 bio_vec.bv_offset = 0;
41 bio.bi_end_io = request_complete;
45 return test_bit(BIO_UPTODATE, &bio.bi_flags) ? 0 : -
EIO;
48 static int bdev_readpage(
void *_sb,
struct page *
page)
54 err = sync_request(page, bdev,
READ);
56 ClearPageUptodate(page);
59 SetPageUptodate(page);
68 static void writeseg_end_io(
struct bio *bio,
int err)
70 const int uptodate =
test_bit(BIO_UPTODATE, &bio->bi_flags);
71 struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1;
81 if (--bvec >= bio->bi_io_vec)
86 }
while (bvec >= bio->bi_io_vec);
99 unsigned int max_pages;
104 bio = bio_alloc(
GFP_NOFS, max_pages);
107 for (i = 0; i < nr_pages; i++) {
108 if (i >= max_pages) {
113 bio->bi_bdev = super->
s_bdev;
114 bio->bi_sector = ofs >> 9;
115 bio->bi_private =
sb;
116 bio->bi_end_io = writeseg_end_io;
125 bio = bio_alloc(
GFP_NOFS, max_pages);
130 bio->bi_io_vec[
i].bv_page =
page;
132 bio->bi_io_vec[
i].bv_offset = 0;
134 BUG_ON(PageWriteback(page));
135 set_page_writeback(page);
138 bio->bi_vcnt = nr_pages;
141 bio->bi_bdev = super->
s_bdev;
142 bio->bi_sector = ofs >> 9;
143 bio->bi_private =
sb;
144 bio->bi_end_io = writeseg_end_io;
150 static void bdev_writeseg(
struct super_block *sb,
u64 ofs,
size_t len)
174 static void erase_end_io(
struct bio *bio,
int err)
176 const int uptodate =
test_bit(BIO_UPTODATE, &bio->bi_flags);
182 BUG_ON(bio->bi_vcnt == 0);
193 unsigned int max_pages;
198 bio = bio_alloc(
GFP_NOFS, max_pages);
201 for (i = 0; i < nr_pages; i++) {
202 if (i >= max_pages) {
207 bio->bi_bdev = super->
s_bdev;
208 bio->bi_sector = ofs >> 9;
209 bio->bi_private =
sb;
210 bio->bi_end_io = erase_end_io;
219 bio = bio_alloc(
GFP_NOFS, max_pages);
224 bio->bi_io_vec[
i].bv_offset = 0;
226 bio->bi_vcnt = nr_pages;
229 bio->bi_bdev = super->
s_bdev;
230 bio->bi_sector = ofs >> 9;
231 bio->bi_private =
sb;
232 bio->bi_end_io = erase_end_io;
238 static int bdev_erase(
struct super_block *sb, loff_t to,
size_t len,
269 static struct page *bdev_find_first_sb(
struct super_block *sb,
u64 *ofs)
279 static struct page *bdev_find_last_sb(
struct super_block *sb,
u64 *ofs)
284 u64 pos = (super->
s_bdev->bd_inode->i_size & ~0xfffULL) - 0x1000;
291 static int bdev_write_sb(
struct super_block *sb,
struct page *page)
296 return sync_request(page, bdev,
WRITE);
310 .find_first_sb = bdev_find_first_sb,
311 .find_last_sb = bdev_find_last_sb,
312 .write_sb = bdev_write_sb,
313 .readpage = bdev_readpage,
314 .writeseg = bdev_writeseg,
316 .can_write_buf = bdev_can_write_buf,
318 .put_device = bdev_put_device,
329 return PTR_ERR(bdev);