Skip to content

Commit

Permalink
PM/hibernate: fix "swap breaks after hibernation failures"
Browse files Browse the repository at this point in the history
http://bugzilla.kernel.org/show_bug.cgi?id=12239

The image writing code dropped a reference to the current swap device.
This doesn't show up if the hibernation succeeds - because it doesn't
affect the image which gets resumed.  But it means multiple _failed_
hibernations end up freeing the swap device while it is still use!

swsusp_write() finds the block device for the swap file using swap_type_of().
It then uses blkdev_get() / blkdev_put() to open and close the block device.

Unfortunately, blkdev_get() assumes ownership of the inode of the block_device
passed to it.  So blkdev_put() calls iput() on the inode.  This is by design
and other callers expect this behaviour.  The fix is for swap_type_of() to take
a reference on the inode using bdget().

Signed-off-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Len Brown <lenb@kernel.org>
Cc: Greg KH <gregkh@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Alan Jenkins authored and torvalds committed Feb 21, 2009
1 parent eed3ee0 commit a1bb7d6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mm/swapfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ int swap_type_of(dev_t device, sector_t offset, struct block_device **bdev_p)

if (!bdev) {
if (bdev_p)
*bdev_p = sis->bdev;
*bdev_p = bdget(sis->bdev->bd_dev);

spin_unlock(&swap_lock);
return i;
Expand All @@ -647,7 +647,7 @@ int swap_type_of(dev_t device, sector_t offset, struct block_device **bdev_p)
struct swap_extent, list);
if (se->start_block == offset) {
if (bdev_p)
*bdev_p = sis->bdev;
*bdev_p = bdget(sis->bdev->bd_dev);

spin_unlock(&swap_lock);
bdput(bdev);
Expand Down

0 comments on commit a1bb7d6

Please sign in to comment.