2 * This file provides functions for block I/O operations on swap/file.
4 * Copyright (C) 1998,2001-2005 Pavel Machek <pavel@ucw.cz>
5 * Copyright (C) 2006 Rafael J. Wysocki <rjw@sisk.pl>
7 * This file is released under the GPLv2.
10 #include <linux/bio.h>
11 #include <linux/kernel.h>
12 #include <linux/pagemap.h>
13 #include <linux/swap.h>
18 * submit - submit BIO request.
20 * @off physical offset of page.
21 * @page: page we're reading or writing.
22 * @bio_chain: list of pending biod (for async reading)
24 * Straight from the textbook - allocate and initialize the bio.
25 * If we're reading, make sure the page is marked as dirty.
26 * Then submit it and, if @bio_chain == NULL, wait.
28 static int submit(int rw
, struct block_device
*bdev
, sector_t sector
,
29 struct page
*page
, struct bio
**bio_chain
)
31 const int bio_rw
= rw
| (1 << BIO_RW_SYNCIO
) | (1 << BIO_RW_UNPLUG
);
34 bio
= bio_alloc(__GFP_WAIT
| __GFP_HIGH
, 1);
35 bio
->bi_sector
= sector
;
37 bio
->bi_end_io
= end_swap_bio_read
;
39 if (bio_add_page(bio
, page
, PAGE_SIZE
, 0) < PAGE_SIZE
) {
40 printk(KERN_ERR
"PM: Adding page to bio failed at %llu\n",
41 (unsigned long long)sector
);
49 if (bio_chain
== NULL
) {
50 submit_bio(bio_rw
, bio
);
51 wait_on_page_locked(page
);
53 bio_set_pages_dirty(bio
);
57 get_page(page
); /* These pages are freed later */
58 bio
->bi_private
= *bio_chain
;
60 submit_bio(bio_rw
, bio
);
65 int hib_bio_read_page(pgoff_t page_off
, void *addr
, struct bio
**bio_chain
)
67 return submit(READ
, hib_resume_bdev
, page_off
* (PAGE_SIZE
>> 9),
68 virt_to_page(addr
), bio_chain
);
71 int hib_bio_write_page(pgoff_t page_off
, void *addr
, struct bio
**bio_chain
)
73 return submit(WRITE
, hib_resume_bdev
, page_off
* (PAGE_SIZE
>> 9),
74 virt_to_page(addr
), bio_chain
);
77 int hib_wait_on_bio_chain(struct bio
**bio_chain
)
83 if (bio_chain
== NULL
)
92 next_bio
= bio
->bi_private
;
93 page
= bio
->bi_io_vec
[0].bv_page
;
94 wait_on_page_locked(page
);
95 if (!PageUptodate(page
) || PageError(page
))