Commit da47ca23 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] rw_swap_page_sync fixes

Fix up the rw_swap_page_sync() gorrors by fully decoupling this function
from the VM - it is now just a helper function which reads a page from or
writes a page to swap.
parent 4875a601
...@@ -19,20 +19,17 @@ ...@@ -19,20 +19,17 @@
#include <linux/writeback.h> #include <linux/writeback.h>
#include <asm/pgtable.h> #include <asm/pgtable.h>
static struct bio * static struct bio *get_swap_bio(int gfp_flags, pgoff_t index,
get_swap_bio(int gfp_flags, struct page *page, bio_end_io_t end_io) struct page *page, bio_end_io_t end_io)
{ {
struct bio *bio; struct bio *bio;
bio = bio_alloc(gfp_flags, 1); bio = bio_alloc(gfp_flags, 1);
if (bio) { if (bio) {
struct swap_info_struct *sis; struct swap_info_struct *sis;
swp_entry_t entry; swp_entry_t entry = { .val = index, };
BUG_ON(!PageSwapCache(page));
entry.val = page->private;
sis = get_swap_info_struct(swp_type(entry)); sis = get_swap_info_struct(swp_type(entry));
bio->bi_sector = map_swap_page(sis, swp_offset(entry)) * bio->bi_sector = map_swap_page(sis, swp_offset(entry)) *
(PAGE_SIZE >> 9); (PAGE_SIZE >> 9);
bio->bi_bdev = sis->bdev; bio->bi_bdev = sis->bdev;
...@@ -94,7 +91,7 @@ int swap_writepage(struct page *page, struct writeback_control *wbc) ...@@ -94,7 +91,7 @@ int swap_writepage(struct page *page, struct writeback_control *wbc)
unlock_page(page); unlock_page(page);
goto out; goto out;
} }
bio = get_swap_bio(GFP_NOIO, page, end_swap_bio_write); bio = get_swap_bio(GFP_NOIO, page->private, page, end_swap_bio_write);
if (bio == NULL) { if (bio == NULL) {
set_page_dirty(page); set_page_dirty(page);
unlock_page(page); unlock_page(page);
...@@ -118,7 +115,7 @@ int swap_readpage(struct file *file, struct page *page) ...@@ -118,7 +115,7 @@ int swap_readpage(struct file *file, struct page *page)
BUG_ON(!PageLocked(page)); BUG_ON(!PageLocked(page));
ClearPageUptodate(page); ClearPageUptodate(page);
bio = get_swap_bio(GFP_KERNEL, page, end_swap_bio_read); bio = get_swap_bio(GFP_KERNEL, page->private, page, end_swap_bio_read);
if (bio == NULL) { if (bio == NULL) {
unlock_page(page); unlock_page(page);
ret = -ENOMEM; ret = -ENOMEM;
...@@ -131,36 +128,33 @@ int swap_readpage(struct file *file, struct page *page) ...@@ -131,36 +128,33 @@ int swap_readpage(struct file *file, struct page *page)
} }
#if defined(CONFIG_SOFTWARE_SUSPEND) || defined(CONFIG_PM_DISK) #if defined(CONFIG_SOFTWARE_SUSPEND) || defined(CONFIG_PM_DISK)
/* /*
* A scruffy utility function to read or write an arbitrary swap page * A scruffy utility function to read or write an arbitrary swap page
* and wait on the I/O. The caller must have a ref on the page. * and wait on the I/O. The caller must have a ref on the page.
*
* We use end_swap_bio_read() even for writes, because it happens to do what
* we want.
*/ */
int rw_swap_page_sync(int rw, swp_entry_t entry, struct page *page) int rw_swap_page_sync(int rw, swp_entry_t entry, struct page *page)
{ {
int ret; struct bio *bio;
unsigned long save_private; int ret = 0;
struct writeback_control swap_wbc = {
.sync_mode = WB_SYNC_ALL,
};
lock_page(page); lock_page(page);
SetPageSwapCache(page);
save_private = page->private;
page->private = entry.val;
if (rw == READ) { bio = get_swap_bio(GFP_KERNEL, entry.val, page, end_swap_bio_read);
ret = swap_readpage(NULL, page); if (bio == NULL) {
wait_on_page_locked(page); unlock_page(page);
} else { ret = -ENOMEM;
ret = swap_writepage(page, &swap_wbc); goto out;
wait_on_page_writeback(page);
} }
ClearPageSwapCache(page); submit_bio(rw | (1 << BIO_RW_SYNC), bio);
page->private = save_private; wait_on_page_locked(page);
if (ret == 0 && (!PageUptodate(page) || PageError(page)))
if (!PageUptodate(page) || PageError(page))
ret = -EIO; ret = -EIO;
out:
return ret; return ret;
} }
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment