Commit 7bf23687 authored by Rafael J. Wysocki's avatar Rafael J. Wysocki Committed by Linus Torvalds

[PATCH] swsusp: Do not fail if resume device is not set

In the kernels later than 2.6.19 there is a regression that makes swsusp
fail if the resume device is not explicitly specified.

It can be fixed by adding an additional parameter to
mm/swapfile.c:swap_type_of() allowing us to pass the (struct block_device
*) corresponding to the first available swap back to the caller.
Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
Acked-by: default avatarPavel Machek <pavel@ucw.cz>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 3223ea8c
...@@ -245,7 +245,7 @@ extern int swap_duplicate(swp_entry_t); ...@@ -245,7 +245,7 @@ extern int swap_duplicate(swp_entry_t);
extern int valid_swaphandles(swp_entry_t, unsigned long *); extern int valid_swaphandles(swp_entry_t, unsigned long *);
extern void swap_free(swp_entry_t); extern void swap_free(swp_entry_t);
extern void free_swap_and_cache(swp_entry_t); extern void free_swap_and_cache(swp_entry_t);
extern int swap_type_of(dev_t, sector_t); extern int swap_type_of(dev_t, sector_t, struct block_device **);
extern unsigned int count_swap_pages(int, int); extern unsigned int count_swap_pages(int, int);
extern sector_t map_swap_page(struct swap_info_struct *, pgoff_t); extern sector_t map_swap_page(struct swap_info_struct *, pgoff_t);
extern sector_t swapdev_block(int, pgoff_t); extern sector_t swapdev_block(int, pgoff_t);
......
...@@ -165,14 +165,15 @@ static int swsusp_swap_check(void) /* This is called before saving image */ ...@@ -165,14 +165,15 @@ static int swsusp_swap_check(void) /* This is called before saving image */
{ {
int res; int res;
res = swap_type_of(swsusp_resume_device, swsusp_resume_block); res = swap_type_of(swsusp_resume_device, swsusp_resume_block,
&resume_bdev);
if (res < 0) if (res < 0)
return res; return res;
root_swap = res; root_swap = res;
resume_bdev = open_by_devnum(swsusp_resume_device, FMODE_WRITE); res = blkdev_get(resume_bdev, FMODE_WRITE, O_RDWR);
if (IS_ERR(resume_bdev)) if (res)
return PTR_ERR(resume_bdev); return res;
res = set_blocksize(resume_bdev, PAGE_SIZE); res = set_blocksize(resume_bdev, PAGE_SIZE);
if (res < 0) if (res < 0)
......
...@@ -57,7 +57,7 @@ static int snapshot_open(struct inode *inode, struct file *filp) ...@@ -57,7 +57,7 @@ static int snapshot_open(struct inode *inode, struct file *filp)
memset(&data->handle, 0, sizeof(struct snapshot_handle)); memset(&data->handle, 0, sizeof(struct snapshot_handle));
if ((filp->f_flags & O_ACCMODE) == O_RDONLY) { if ((filp->f_flags & O_ACCMODE) == O_RDONLY) {
data->swap = swsusp_resume_device ? data->swap = swsusp_resume_device ?
swap_type_of(swsusp_resume_device, 0) : -1; swap_type_of(swsusp_resume_device, 0, NULL) : -1;
data->mode = O_RDONLY; data->mode = O_RDONLY;
} else { } else {
data->swap = -1; data->swap = -1;
...@@ -268,7 +268,8 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp, ...@@ -268,7 +268,8 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
* so we need to recode them * so we need to recode them
*/ */
if (old_decode_dev(arg)) { if (old_decode_dev(arg)) {
data->swap = swap_type_of(old_decode_dev(arg), 0); data->swap = swap_type_of(old_decode_dev(arg),
0, NULL);
if (data->swap < 0) if (data->swap < 0)
error = -ENODEV; error = -ENODEV;
} else { } else {
...@@ -365,7 +366,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp, ...@@ -365,7 +366,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
swdev = old_decode_dev(swap_area.dev); swdev = old_decode_dev(swap_area.dev);
if (swdev) { if (swdev) {
offset = swap_area.offset; offset = swap_area.offset;
data->swap = swap_type_of(swdev, offset); data->swap = swap_type_of(swdev, offset, NULL);
if (data->swap < 0) if (data->swap < 0)
error = -ENODEV; error = -ENODEV;
} else { } else {
......
...@@ -434,7 +434,7 @@ void free_swap_and_cache(swp_entry_t entry) ...@@ -434,7 +434,7 @@ void free_swap_and_cache(swp_entry_t entry)
* *
* This is needed for the suspend to disk (aka swsusp). * This is needed for the suspend to disk (aka swsusp).
*/ */
int swap_type_of(dev_t device, sector_t offset) int swap_type_of(dev_t device, sector_t offset, struct block_device **bdev_p)
{ {
struct block_device *bdev = NULL; struct block_device *bdev = NULL;
int i; int i;
...@@ -450,6 +450,9 @@ int swap_type_of(dev_t device, sector_t offset) ...@@ -450,6 +450,9 @@ int swap_type_of(dev_t device, sector_t offset)
continue; continue;
if (!bdev) { if (!bdev) {
if (bdev_p)
*bdev_p = sis->bdev;
spin_unlock(&swap_lock); spin_unlock(&swap_lock);
return i; return i;
} }
...@@ -459,6 +462,9 @@ int swap_type_of(dev_t device, sector_t offset) ...@@ -459,6 +462,9 @@ int swap_type_of(dev_t device, sector_t offset)
se = list_entry(sis->extent_list.next, se = list_entry(sis->extent_list.next,
struct swap_extent, list); struct swap_extent, list);
if (se->start_block == offset) { if (se->start_block == offset) {
if (bdev_p)
*bdev_p = sis->bdev;
spin_unlock(&swap_lock); spin_unlock(&swap_lock);
bdput(bdev); bdput(bdev);
return i; return i;
......
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