Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 1 | /* |
| 2 | * linux/kernel/power/swap.c |
| 3 | * |
| 4 | * This file provides functions for reading the suspend image from |
| 5 | * and writing it to a swap partition. |
| 6 | * |
| 7 | * Copyright (C) 1998,2001-2005 Pavel Machek <pavel@suse.cz> |
| 8 | * Copyright (C) 2006 Rafael J. Wysocki <rjw@sisk.pl> |
| 9 | * |
| 10 | * This file is released under the GPLv2. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <linux/module.h> |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 15 | #include <linux/file.h> |
| 16 | #include <linux/utsname.h> |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 17 | #include <linux/delay.h> |
| 18 | #include <linux/bitops.h> |
| 19 | #include <linux/genhd.h> |
| 20 | #include <linux/device.h> |
| 21 | #include <linux/buffer_head.h> |
| 22 | #include <linux/bio.h> |
Andrew Morton | 546e0d2 | 2006-09-25 23:32:44 -0700 | [diff] [blame] | 23 | #include <linux/blkdev.h> |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 24 | #include <linux/swap.h> |
| 25 | #include <linux/swapops.h> |
| 26 | #include <linux/pm.h> |
| 27 | |
| 28 | #include "power.h" |
| 29 | |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 30 | #define SWSUSP_SIG "S1SUSPEND" |
| 31 | |
Vivek Goyal | 1b29c16 | 2007-05-02 19:27:07 +0200 | [diff] [blame] | 32 | struct swsusp_header { |
Rafael J. Wysocki | a634cc1 | 2007-07-19 01:47:30 -0700 | [diff] [blame] | 33 | char reserved[PAGE_SIZE - 20 - sizeof(sector_t) - sizeof(int)]; |
Rafael J. Wysocki | 3aef83e | 2006-12-06 20:34:10 -0800 | [diff] [blame] | 34 | sector_t image; |
Rafael J. Wysocki | a634cc1 | 2007-07-19 01:47:30 -0700 | [diff] [blame] | 35 | unsigned int flags; /* Flags to pass to the "boot" kernel */ |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 36 | char orig_sig[10]; |
| 37 | char sig[10]; |
Vivek Goyal | 1b29c16 | 2007-05-02 19:27:07 +0200 | [diff] [blame] | 38 | } __attribute__((packed)); |
| 39 | |
| 40 | static struct swsusp_header *swsusp_header; |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 41 | |
| 42 | /* |
Rafael J. Wysocki | 3fc6b34 | 2006-12-06 20:34:09 -0800 | [diff] [blame] | 43 | * General things |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 44 | */ |
| 45 | |
| 46 | static unsigned short root_swap = 0xffff; |
Rafael J. Wysocki | 3fc6b34 | 2006-12-06 20:34:09 -0800 | [diff] [blame] | 47 | static struct block_device *resume_bdev; |
| 48 | |
| 49 | /** |
| 50 | * submit - submit BIO request. |
| 51 | * @rw: READ or WRITE. |
| 52 | * @off physical offset of page. |
| 53 | * @page: page we're reading or writing. |
| 54 | * @bio_chain: list of pending biod (for async reading) |
| 55 | * |
| 56 | * Straight from the textbook - allocate and initialize the bio. |
| 57 | * If we're reading, make sure the page is marked as dirty. |
| 58 | * Then submit it and, if @bio_chain == NULL, wait. |
| 59 | */ |
| 60 | static int submit(int rw, pgoff_t page_off, struct page *page, |
| 61 | struct bio **bio_chain) |
| 62 | { |
| 63 | struct bio *bio; |
| 64 | |
Rafael J. Wysocki | 8594912 | 2006-12-06 20:34:19 -0800 | [diff] [blame] | 65 | bio = bio_alloc(__GFP_WAIT | __GFP_HIGH, 1); |
Rafael J. Wysocki | 3fc6b34 | 2006-12-06 20:34:09 -0800 | [diff] [blame] | 66 | if (!bio) |
| 67 | return -ENOMEM; |
| 68 | bio->bi_sector = page_off * (PAGE_SIZE >> 9); |
| 69 | bio->bi_bdev = resume_bdev; |
| 70 | bio->bi_end_io = end_swap_bio_read; |
| 71 | |
| 72 | if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) { |
Rafael J. Wysocki | 2397672 | 2007-12-08 02:09:43 +0100 | [diff] [blame] | 73 | printk(KERN_ERR "PM: Adding page to bio failed at %ld\n", |
| 74 | page_off); |
Rafael J. Wysocki | 3fc6b34 | 2006-12-06 20:34:09 -0800 | [diff] [blame] | 75 | bio_put(bio); |
| 76 | return -EFAULT; |
| 77 | } |
| 78 | |
| 79 | lock_page(page); |
| 80 | bio_get(bio); |
| 81 | |
| 82 | if (bio_chain == NULL) { |
| 83 | submit_bio(rw | (1 << BIO_RW_SYNC), bio); |
| 84 | wait_on_page_locked(page); |
| 85 | if (rw == READ) |
| 86 | bio_set_pages_dirty(bio); |
| 87 | bio_put(bio); |
| 88 | } else { |
| 89 | if (rw == READ) |
| 90 | get_page(page); /* These pages are freed later */ |
| 91 | bio->bi_private = *bio_chain; |
| 92 | *bio_chain = bio; |
| 93 | submit_bio(rw | (1 << BIO_RW_SYNC), bio); |
| 94 | } |
| 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | static int bio_read_page(pgoff_t page_off, void *addr, struct bio **bio_chain) |
| 99 | { |
| 100 | return submit(READ, page_off, virt_to_page(addr), bio_chain); |
| 101 | } |
| 102 | |
Rafael J. Wysocki | 3aef83e | 2006-12-06 20:34:10 -0800 | [diff] [blame] | 103 | static int bio_write_page(pgoff_t page_off, void *addr, struct bio **bio_chain) |
Rafael J. Wysocki | 3fc6b34 | 2006-12-06 20:34:09 -0800 | [diff] [blame] | 104 | { |
Rafael J. Wysocki | 3aef83e | 2006-12-06 20:34:10 -0800 | [diff] [blame] | 105 | return submit(WRITE, page_off, virt_to_page(addr), bio_chain); |
Rafael J. Wysocki | 3fc6b34 | 2006-12-06 20:34:09 -0800 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | static int wait_on_bio_chain(struct bio **bio_chain) |
| 109 | { |
| 110 | struct bio *bio; |
| 111 | struct bio *next_bio; |
| 112 | int ret = 0; |
| 113 | |
| 114 | if (bio_chain == NULL) |
| 115 | return 0; |
| 116 | |
| 117 | bio = *bio_chain; |
| 118 | if (bio == NULL) |
| 119 | return 0; |
| 120 | while (bio) { |
| 121 | struct page *page; |
| 122 | |
| 123 | next_bio = bio->bi_private; |
| 124 | page = bio->bi_io_vec[0].bv_page; |
| 125 | wait_on_page_locked(page); |
| 126 | if (!PageUptodate(page) || PageError(page)) |
| 127 | ret = -EIO; |
| 128 | put_page(page); |
| 129 | bio_put(bio); |
| 130 | bio = next_bio; |
| 131 | } |
| 132 | *bio_chain = NULL; |
| 133 | return ret; |
| 134 | } |
| 135 | |
Rafael J. Wysocki | 3fc6b34 | 2006-12-06 20:34:09 -0800 | [diff] [blame] | 136 | /* |
| 137 | * Saving part |
| 138 | */ |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 139 | |
Rafael J. Wysocki | a634cc1 | 2007-07-19 01:47:30 -0700 | [diff] [blame] | 140 | static int mark_swapfiles(sector_t start, unsigned int flags) |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 141 | { |
| 142 | int error; |
| 143 | |
Vivek Goyal | 1b29c16 | 2007-05-02 19:27:07 +0200 | [diff] [blame] | 144 | bio_read_page(swsusp_resume_block, swsusp_header, NULL); |
| 145 | if (!memcmp("SWAP-SPACE",swsusp_header->sig, 10) || |
| 146 | !memcmp("SWAPSPACE2",swsusp_header->sig, 10)) { |
| 147 | memcpy(swsusp_header->orig_sig,swsusp_header->sig, 10); |
| 148 | memcpy(swsusp_header->sig,SWSUSP_SIG, 10); |
| 149 | swsusp_header->image = start; |
Rafael J. Wysocki | a634cc1 | 2007-07-19 01:47:30 -0700 | [diff] [blame] | 150 | swsusp_header->flags = flags; |
Rafael J. Wysocki | 9a154d9 | 2006-12-06 20:34:12 -0800 | [diff] [blame] | 151 | error = bio_write_page(swsusp_resume_block, |
Vivek Goyal | 1b29c16 | 2007-05-02 19:27:07 +0200 | [diff] [blame] | 152 | swsusp_header, NULL); |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 153 | } else { |
Rafael J. Wysocki | 2397672 | 2007-12-08 02:09:43 +0100 | [diff] [blame] | 154 | printk(KERN_ERR "PM: Swap header not found!\n"); |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 155 | error = -ENODEV; |
| 156 | } |
| 157 | return error; |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * swsusp_swap_check - check if the resume device is a swap device |
| 162 | * and get its index (if so) |
| 163 | */ |
| 164 | |
| 165 | static int swsusp_swap_check(void) /* This is called before saving image */ |
| 166 | { |
Rafael J. Wysocki | 3aef83e | 2006-12-06 20:34:10 -0800 | [diff] [blame] | 167 | int res; |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 168 | |
Rafael J. Wysocki | 7bf2368 | 2007-01-05 16:36:28 -0800 | [diff] [blame] | 169 | res = swap_type_of(swsusp_resume_device, swsusp_resume_block, |
| 170 | &resume_bdev); |
Rafael J. Wysocki | 3aef83e | 2006-12-06 20:34:10 -0800 | [diff] [blame] | 171 | if (res < 0) |
| 172 | return res; |
| 173 | |
| 174 | root_swap = res; |
Al Viro | 572c489 | 2007-10-08 13:24:05 -0400 | [diff] [blame] | 175 | res = blkdev_get(resume_bdev, FMODE_WRITE); |
Rafael J. Wysocki | 7bf2368 | 2007-01-05 16:36:28 -0800 | [diff] [blame] | 176 | if (res) |
| 177 | return res; |
Rafael J. Wysocki | 3aef83e | 2006-12-06 20:34:10 -0800 | [diff] [blame] | 178 | |
| 179 | res = set_blocksize(resume_bdev, PAGE_SIZE); |
| 180 | if (res < 0) |
Al Viro | 9a1c354 | 2008-02-22 20:40:24 -0500 | [diff] [blame] | 181 | blkdev_put(resume_bdev, FMODE_WRITE); |
Rafael J. Wysocki | 3aef83e | 2006-12-06 20:34:10 -0800 | [diff] [blame] | 182 | |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 183 | return res; |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * write_page - Write one page to given swap location. |
| 188 | * @buf: Address we're writing. |
| 189 | * @offset: Offset of the swap page we're writing to. |
Andrew Morton | ab95416 | 2006-09-25 23:32:42 -0700 | [diff] [blame] | 190 | * @bio_chain: Link the next write BIO here |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 191 | */ |
| 192 | |
Rafael J. Wysocki | 3aef83e | 2006-12-06 20:34:10 -0800 | [diff] [blame] | 193 | static int write_page(void *buf, sector_t offset, struct bio **bio_chain) |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 194 | { |
Rafael J. Wysocki | 3aef83e | 2006-12-06 20:34:10 -0800 | [diff] [blame] | 195 | void *src; |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 196 | |
Rafael J. Wysocki | 3aef83e | 2006-12-06 20:34:10 -0800 | [diff] [blame] | 197 | if (!offset) |
| 198 | return -ENOSPC; |
Andrew Morton | ab95416 | 2006-09-25 23:32:42 -0700 | [diff] [blame] | 199 | |
Rafael J. Wysocki | 3aef83e | 2006-12-06 20:34:10 -0800 | [diff] [blame] | 200 | if (bio_chain) { |
Rafael J. Wysocki | 8594912 | 2006-12-06 20:34:19 -0800 | [diff] [blame] | 201 | src = (void *)__get_free_page(__GFP_WAIT | __GFP_HIGH); |
Rafael J. Wysocki | 3aef83e | 2006-12-06 20:34:10 -0800 | [diff] [blame] | 202 | if (src) { |
| 203 | memcpy(src, buf, PAGE_SIZE); |
| 204 | } else { |
| 205 | WARN_ON_ONCE(1); |
| 206 | bio_chain = NULL; /* Go synchronous */ |
| 207 | src = buf; |
Andrew Morton | ab95416 | 2006-09-25 23:32:42 -0700 | [diff] [blame] | 208 | } |
Rafael J. Wysocki | 3aef83e | 2006-12-06 20:34:10 -0800 | [diff] [blame] | 209 | } else { |
| 210 | src = buf; |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 211 | } |
Rafael J. Wysocki | 3aef83e | 2006-12-06 20:34:10 -0800 | [diff] [blame] | 212 | return bio_write_page(offset, src, bio_chain); |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | /* |
| 216 | * The swap map is a data structure used for keeping track of each page |
| 217 | * written to a swap partition. It consists of many swap_map_page |
| 218 | * structures that contain each an array of MAP_PAGE_SIZE swap entries. |
| 219 | * These structures are stored on the swap and linked together with the |
| 220 | * help of the .next_swap member. |
| 221 | * |
| 222 | * The swap map is created during suspend. The swap map pages are |
| 223 | * allocated and populated one at a time, so we only need one memory |
| 224 | * page to set up the entire structure. |
| 225 | * |
| 226 | * During resume we also only need to use one swap_map_page structure |
| 227 | * at a time. |
| 228 | */ |
| 229 | |
Rafael J. Wysocki | 3aef83e | 2006-12-06 20:34:10 -0800 | [diff] [blame] | 230 | #define MAP_PAGE_ENTRIES (PAGE_SIZE / sizeof(sector_t) - 1) |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 231 | |
| 232 | struct swap_map_page { |
Rafael J. Wysocki | 3aef83e | 2006-12-06 20:34:10 -0800 | [diff] [blame] | 233 | sector_t entries[MAP_PAGE_ENTRIES]; |
| 234 | sector_t next_swap; |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 235 | }; |
| 236 | |
| 237 | /** |
| 238 | * The swap_map_handle structure is used for handling swap in |
| 239 | * a file-alike way |
| 240 | */ |
| 241 | |
| 242 | struct swap_map_handle { |
| 243 | struct swap_map_page *cur; |
Rafael J. Wysocki | 3aef83e | 2006-12-06 20:34:10 -0800 | [diff] [blame] | 244 | sector_t cur_swap; |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 245 | unsigned int k; |
| 246 | }; |
| 247 | |
| 248 | static void release_swap_writer(struct swap_map_handle *handle) |
| 249 | { |
| 250 | if (handle->cur) |
| 251 | free_page((unsigned long)handle->cur); |
| 252 | handle->cur = NULL; |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | static int get_swap_writer(struct swap_map_handle *handle) |
| 256 | { |
| 257 | handle->cur = (struct swap_map_page *)get_zeroed_page(GFP_KERNEL); |
| 258 | if (!handle->cur) |
| 259 | return -ENOMEM; |
Rafael J. Wysocki | d1d241c | 2007-05-06 14:50:47 -0700 | [diff] [blame] | 260 | handle->cur_swap = alloc_swapdev_block(root_swap); |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 261 | if (!handle->cur_swap) { |
| 262 | release_swap_writer(handle); |
| 263 | return -ENOSPC; |
| 264 | } |
| 265 | handle->k = 0; |
| 266 | return 0; |
| 267 | } |
| 268 | |
Andrew Morton | ab95416 | 2006-09-25 23:32:42 -0700 | [diff] [blame] | 269 | static int swap_write_page(struct swap_map_handle *handle, void *buf, |
| 270 | struct bio **bio_chain) |
| 271 | { |
| 272 | int error = 0; |
Rafael J. Wysocki | 3aef83e | 2006-12-06 20:34:10 -0800 | [diff] [blame] | 273 | sector_t offset; |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 274 | |
| 275 | if (!handle->cur) |
| 276 | return -EINVAL; |
Rafael J. Wysocki | d1d241c | 2007-05-06 14:50:47 -0700 | [diff] [blame] | 277 | offset = alloc_swapdev_block(root_swap); |
Andrew Morton | ab95416 | 2006-09-25 23:32:42 -0700 | [diff] [blame] | 278 | error = write_page(buf, offset, bio_chain); |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 279 | if (error) |
| 280 | return error; |
| 281 | handle->cur->entries[handle->k++] = offset; |
| 282 | if (handle->k >= MAP_PAGE_ENTRIES) { |
Andrew Morton | ab95416 | 2006-09-25 23:32:42 -0700 | [diff] [blame] | 283 | error = wait_on_bio_chain(bio_chain); |
| 284 | if (error) |
| 285 | goto out; |
Rafael J. Wysocki | d1d241c | 2007-05-06 14:50:47 -0700 | [diff] [blame] | 286 | offset = alloc_swapdev_block(root_swap); |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 287 | if (!offset) |
| 288 | return -ENOSPC; |
| 289 | handle->cur->next_swap = offset; |
Andrew Morton | ab95416 | 2006-09-25 23:32:42 -0700 | [diff] [blame] | 290 | error = write_page(handle->cur, handle->cur_swap, NULL); |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 291 | if (error) |
Andrew Morton | ab95416 | 2006-09-25 23:32:42 -0700 | [diff] [blame] | 292 | goto out; |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 293 | memset(handle->cur, 0, PAGE_SIZE); |
| 294 | handle->cur_swap = offset; |
| 295 | handle->k = 0; |
| 296 | } |
Rafael J. Wysocki | 59a49335 | 2006-12-06 20:34:44 -0800 | [diff] [blame] | 297 | out: |
Andrew Morton | ab95416 | 2006-09-25 23:32:42 -0700 | [diff] [blame] | 298 | return error; |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | static int flush_swap_writer(struct swap_map_handle *handle) |
| 302 | { |
| 303 | if (handle->cur && handle->cur_swap) |
Andrew Morton | ab95416 | 2006-09-25 23:32:42 -0700 | [diff] [blame] | 304 | return write_page(handle->cur, handle->cur_swap, NULL); |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 305 | else |
| 306 | return -EINVAL; |
| 307 | } |
| 308 | |
| 309 | /** |
| 310 | * save_image - save the suspend image data |
| 311 | */ |
| 312 | |
| 313 | static int save_image(struct swap_map_handle *handle, |
| 314 | struct snapshot_handle *snapshot, |
Andrew Morton | 3a4f757 | 2006-09-25 23:32:41 -0700 | [diff] [blame] | 315 | unsigned int nr_to_write) |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 316 | { |
| 317 | unsigned int m; |
| 318 | int ret; |
| 319 | int error = 0; |
Andrew Morton | 3a4f757 | 2006-09-25 23:32:41 -0700 | [diff] [blame] | 320 | int nr_pages; |
Andrew Morton | ab95416 | 2006-09-25 23:32:42 -0700 | [diff] [blame] | 321 | int err2; |
| 322 | struct bio *bio; |
Andrew Morton | 3a4f757 | 2006-09-25 23:32:41 -0700 | [diff] [blame] | 323 | struct timeval start; |
| 324 | struct timeval stop; |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 325 | |
Rafael J. Wysocki | 2397672 | 2007-12-08 02:09:43 +0100 | [diff] [blame] | 326 | printk(KERN_INFO "PM: Saving image data pages (%u pages) ... ", |
| 327 | nr_to_write); |
Andrew Morton | 3a4f757 | 2006-09-25 23:32:41 -0700 | [diff] [blame] | 328 | m = nr_to_write / 100; |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 329 | if (!m) |
| 330 | m = 1; |
| 331 | nr_pages = 0; |
Andrew Morton | ab95416 | 2006-09-25 23:32:42 -0700 | [diff] [blame] | 332 | bio = NULL; |
Andrew Morton | 3a4f757 | 2006-09-25 23:32:41 -0700 | [diff] [blame] | 333 | do_gettimeofday(&start); |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 334 | do { |
| 335 | ret = snapshot_read_next(snapshot, PAGE_SIZE); |
| 336 | if (ret > 0) { |
Andrew Morton | ab95416 | 2006-09-25 23:32:42 -0700 | [diff] [blame] | 337 | error = swap_write_page(handle, data_of(*snapshot), |
| 338 | &bio); |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 339 | if (error) |
| 340 | break; |
| 341 | if (!(nr_pages % m)) |
| 342 | printk("\b\b\b\b%3d%%", nr_pages / m); |
| 343 | nr_pages++; |
| 344 | } |
| 345 | } while (ret > 0); |
Andrew Morton | ab95416 | 2006-09-25 23:32:42 -0700 | [diff] [blame] | 346 | err2 = wait_on_bio_chain(&bio); |
Andrew Morton | 3a4f757 | 2006-09-25 23:32:41 -0700 | [diff] [blame] | 347 | do_gettimeofday(&stop); |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 348 | if (!error) |
Andrew Morton | ab95416 | 2006-09-25 23:32:42 -0700 | [diff] [blame] | 349 | error = err2; |
| 350 | if (!error) |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 351 | printk("\b\b\b\bdone\n"); |
Rafael J. Wysocki | 0d3a9ab | 2006-12-06 20:34:32 -0800 | [diff] [blame] | 352 | swsusp_show_speed(&start, &stop, nr_to_write, "Wrote"); |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 353 | return error; |
| 354 | } |
| 355 | |
| 356 | /** |
| 357 | * enough_swap - Make sure we have enough swap to save the image. |
| 358 | * |
| 359 | * Returns TRUE or FALSE after checking the total amount of swap |
| 360 | * space avaiable from the resume partition. |
| 361 | */ |
| 362 | |
| 363 | static int enough_swap(unsigned int nr_pages) |
| 364 | { |
| 365 | unsigned int free_swap = count_swap_pages(root_swap, 1); |
| 366 | |
Rafael J. Wysocki | 2397672 | 2007-12-08 02:09:43 +0100 | [diff] [blame] | 367 | pr_debug("PM: Free swap pages: %u\n", free_swap); |
Rafael J. Wysocki | 940864d | 2006-09-25 23:32:55 -0700 | [diff] [blame] | 368 | return free_swap > nr_pages + PAGES_FOR_IO; |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | /** |
| 372 | * swsusp_write - Write entire image and metadata. |
Rafael J. Wysocki | a634cc1 | 2007-07-19 01:47:30 -0700 | [diff] [blame] | 373 | * @flags: flags to pass to the "boot" kernel in the image header |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 374 | * |
| 375 | * It is important _NOT_ to umount filesystems at this point. We want |
| 376 | * them synced (in case something goes wrong) but we DO not want to mark |
| 377 | * filesystem clean: it is not. (And it does not matter, if we resume |
| 378 | * correctly, we'll mark system clean, anyway.) |
| 379 | */ |
| 380 | |
Rafael J. Wysocki | a634cc1 | 2007-07-19 01:47:30 -0700 | [diff] [blame] | 381 | int swsusp_write(unsigned int flags) |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 382 | { |
| 383 | struct swap_map_handle handle; |
| 384 | struct snapshot_handle snapshot; |
| 385 | struct swsusp_info *header; |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 386 | int error; |
| 387 | |
Rafael J. Wysocki | 3aef83e | 2006-12-06 20:34:10 -0800 | [diff] [blame] | 388 | error = swsusp_swap_check(); |
| 389 | if (error) { |
Rafael J. Wysocki | 2397672 | 2007-12-08 02:09:43 +0100 | [diff] [blame] | 390 | printk(KERN_ERR "PM: Cannot find swap device, try " |
Andrew Morton | 546e0d2 | 2006-09-25 23:32:44 -0700 | [diff] [blame] | 391 | "swapon -a.\n"); |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 392 | return error; |
| 393 | } |
| 394 | memset(&snapshot, 0, sizeof(struct snapshot_handle)); |
| 395 | error = snapshot_read_next(&snapshot, PAGE_SIZE); |
Rafael J. Wysocki | 3aef83e | 2006-12-06 20:34:10 -0800 | [diff] [blame] | 396 | if (error < PAGE_SIZE) { |
| 397 | if (error >= 0) |
| 398 | error = -EFAULT; |
| 399 | |
| 400 | goto out; |
| 401 | } |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 402 | header = (struct swsusp_info *)data_of(snapshot); |
| 403 | if (!enough_swap(header->pages)) { |
Rafael J. Wysocki | 2397672 | 2007-12-08 02:09:43 +0100 | [diff] [blame] | 404 | printk(KERN_ERR "PM: Not enough free swap\n"); |
Rafael J. Wysocki | 3aef83e | 2006-12-06 20:34:10 -0800 | [diff] [blame] | 405 | error = -ENOSPC; |
| 406 | goto out; |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 407 | } |
| 408 | error = get_swap_writer(&handle); |
| 409 | if (!error) { |
Rafael J. Wysocki | 3aef83e | 2006-12-06 20:34:10 -0800 | [diff] [blame] | 410 | sector_t start = handle.cur_swap; |
| 411 | |
Andrew Morton | ab95416 | 2006-09-25 23:32:42 -0700 | [diff] [blame] | 412 | error = swap_write_page(&handle, header, NULL); |
Andrew Morton | 712f403 | 2006-07-10 04:45:00 -0700 | [diff] [blame] | 413 | if (!error) |
| 414 | error = save_image(&handle, &snapshot, |
| 415 | header->pages - 1); |
Rafael J. Wysocki | 3aef83e | 2006-12-06 20:34:10 -0800 | [diff] [blame] | 416 | |
Andrew Morton | 712f403 | 2006-07-10 04:45:00 -0700 | [diff] [blame] | 417 | if (!error) { |
| 418 | flush_swap_writer(&handle); |
Rafael J. Wysocki | 2397672 | 2007-12-08 02:09:43 +0100 | [diff] [blame] | 419 | printk(KERN_INFO "PM: S"); |
Rafael J. Wysocki | a634cc1 | 2007-07-19 01:47:30 -0700 | [diff] [blame] | 420 | error = mark_swapfiles(start, flags); |
Andrew Morton | 712f403 | 2006-07-10 04:45:00 -0700 | [diff] [blame] | 421 | printk("|\n"); |
| 422 | } |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 423 | } |
| 424 | if (error) |
Rafael J. Wysocki | d1d241c | 2007-05-06 14:50:47 -0700 | [diff] [blame] | 425 | free_all_swap_pages(root_swap); |
| 426 | |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 427 | release_swap_writer(&handle); |
Rafael J. Wysocki | 59a49335 | 2006-12-06 20:34:44 -0800 | [diff] [blame] | 428 | out: |
Al Viro | c2dd0da | 2007-10-08 13:21:10 -0400 | [diff] [blame] | 429 | swsusp_close(FMODE_WRITE); |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 430 | return error; |
| 431 | } |
| 432 | |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 433 | /** |
| 434 | * The following functions allow us to read data using a swap map |
| 435 | * in a file-alike way |
| 436 | */ |
| 437 | |
| 438 | static void release_swap_reader(struct swap_map_handle *handle) |
| 439 | { |
| 440 | if (handle->cur) |
| 441 | free_page((unsigned long)handle->cur); |
| 442 | handle->cur = NULL; |
| 443 | } |
| 444 | |
Rafael J. Wysocki | 3aef83e | 2006-12-06 20:34:10 -0800 | [diff] [blame] | 445 | static int get_swap_reader(struct swap_map_handle *handle, sector_t start) |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 446 | { |
| 447 | int error; |
| 448 | |
Rafael J. Wysocki | 3aef83e | 2006-12-06 20:34:10 -0800 | [diff] [blame] | 449 | if (!start) |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 450 | return -EINVAL; |
Rafael J. Wysocki | 3aef83e | 2006-12-06 20:34:10 -0800 | [diff] [blame] | 451 | |
Rafael J. Wysocki | 8594912 | 2006-12-06 20:34:19 -0800 | [diff] [blame] | 452 | handle->cur = (struct swap_map_page *)get_zeroed_page(__GFP_WAIT | __GFP_HIGH); |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 453 | if (!handle->cur) |
| 454 | return -ENOMEM; |
Rafael J. Wysocki | 3aef83e | 2006-12-06 20:34:10 -0800 | [diff] [blame] | 455 | |
| 456 | error = bio_read_page(start, handle->cur, NULL); |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 457 | if (error) { |
| 458 | release_swap_reader(handle); |
| 459 | return error; |
| 460 | } |
| 461 | handle->k = 0; |
| 462 | return 0; |
| 463 | } |
| 464 | |
Andrew Morton | 546e0d2 | 2006-09-25 23:32:44 -0700 | [diff] [blame] | 465 | static int swap_read_page(struct swap_map_handle *handle, void *buf, |
| 466 | struct bio **bio_chain) |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 467 | { |
Rafael J. Wysocki | 3aef83e | 2006-12-06 20:34:10 -0800 | [diff] [blame] | 468 | sector_t offset; |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 469 | int error; |
| 470 | |
| 471 | if (!handle->cur) |
| 472 | return -EINVAL; |
| 473 | offset = handle->cur->entries[handle->k]; |
| 474 | if (!offset) |
| 475 | return -EFAULT; |
Andrew Morton | 546e0d2 | 2006-09-25 23:32:44 -0700 | [diff] [blame] | 476 | error = bio_read_page(offset, buf, bio_chain); |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 477 | if (error) |
| 478 | return error; |
| 479 | if (++handle->k >= MAP_PAGE_ENTRIES) { |
Andrew Morton | 546e0d2 | 2006-09-25 23:32:44 -0700 | [diff] [blame] | 480 | error = wait_on_bio_chain(bio_chain); |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 481 | handle->k = 0; |
| 482 | offset = handle->cur->next_swap; |
| 483 | if (!offset) |
| 484 | release_swap_reader(handle); |
Andrew Morton | 546e0d2 | 2006-09-25 23:32:44 -0700 | [diff] [blame] | 485 | else if (!error) |
| 486 | error = bio_read_page(offset, handle->cur, NULL); |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 487 | } |
| 488 | return error; |
| 489 | } |
| 490 | |
| 491 | /** |
| 492 | * load_image - load the image using the swap map handle |
| 493 | * @handle and the snapshot handle @snapshot |
| 494 | * (assume there are @nr_pages pages to load) |
| 495 | */ |
| 496 | |
| 497 | static int load_image(struct swap_map_handle *handle, |
| 498 | struct snapshot_handle *snapshot, |
Andrew Morton | 546e0d2 | 2006-09-25 23:32:44 -0700 | [diff] [blame] | 499 | unsigned int nr_to_read) |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 500 | { |
| 501 | unsigned int m; |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 502 | int error = 0; |
Andrew Morton | 8c00249 | 2006-09-25 23:32:43 -0700 | [diff] [blame] | 503 | struct timeval start; |
| 504 | struct timeval stop; |
Andrew Morton | 546e0d2 | 2006-09-25 23:32:44 -0700 | [diff] [blame] | 505 | struct bio *bio; |
| 506 | int err2; |
| 507 | unsigned nr_pages; |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 508 | |
Rafael J. Wysocki | 2397672 | 2007-12-08 02:09:43 +0100 | [diff] [blame] | 509 | printk(KERN_INFO "PM: Loading image data pages (%u pages) ... ", |
| 510 | nr_to_read); |
Andrew Morton | 546e0d2 | 2006-09-25 23:32:44 -0700 | [diff] [blame] | 511 | m = nr_to_read / 100; |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 512 | if (!m) |
| 513 | m = 1; |
| 514 | nr_pages = 0; |
Andrew Morton | 546e0d2 | 2006-09-25 23:32:44 -0700 | [diff] [blame] | 515 | bio = NULL; |
Andrew Morton | 8c00249 | 2006-09-25 23:32:43 -0700 | [diff] [blame] | 516 | do_gettimeofday(&start); |
Andrew Morton | 546e0d2 | 2006-09-25 23:32:44 -0700 | [diff] [blame] | 517 | for ( ; ; ) { |
| 518 | error = snapshot_write_next(snapshot, PAGE_SIZE); |
| 519 | if (error <= 0) |
| 520 | break; |
| 521 | error = swap_read_page(handle, data_of(*snapshot), &bio); |
| 522 | if (error) |
| 523 | break; |
| 524 | if (snapshot->sync_read) |
| 525 | error = wait_on_bio_chain(&bio); |
| 526 | if (error) |
| 527 | break; |
| 528 | if (!(nr_pages % m)) |
| 529 | printk("\b\b\b\b%3d%%", nr_pages / m); |
| 530 | nr_pages++; |
| 531 | } |
| 532 | err2 = wait_on_bio_chain(&bio); |
Andrew Morton | 8c00249 | 2006-09-25 23:32:43 -0700 | [diff] [blame] | 533 | do_gettimeofday(&stop); |
Andrew Morton | 546e0d2 | 2006-09-25 23:32:44 -0700 | [diff] [blame] | 534 | if (!error) |
| 535 | error = err2; |
Con Kolivas | e655a25 | 2006-03-26 01:37:11 -0800 | [diff] [blame] | 536 | if (!error) { |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 537 | printk("\b\b\b\bdone\n"); |
Rafael J. Wysocki | 8357376 | 2006-12-06 20:34:18 -0800 | [diff] [blame] | 538 | snapshot_write_finalize(snapshot); |
Con Kolivas | e655a25 | 2006-03-26 01:37:11 -0800 | [diff] [blame] | 539 | if (!snapshot_image_loaded(snapshot)) |
| 540 | error = -ENODATA; |
| 541 | } |
Rafael J. Wysocki | 0d3a9ab | 2006-12-06 20:34:32 -0800 | [diff] [blame] | 542 | swsusp_show_speed(&start, &stop, nr_to_read, "Read"); |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 543 | return error; |
| 544 | } |
| 545 | |
Rafael J. Wysocki | a634cc1 | 2007-07-19 01:47:30 -0700 | [diff] [blame] | 546 | /** |
| 547 | * swsusp_read - read the hibernation image. |
| 548 | * @flags_p: flags passed by the "frozen" kernel in the image header should |
| 549 | * be written into this memeory location |
| 550 | */ |
| 551 | |
| 552 | int swsusp_read(unsigned int *flags_p) |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 553 | { |
| 554 | int error; |
| 555 | struct swap_map_handle handle; |
| 556 | struct snapshot_handle snapshot; |
| 557 | struct swsusp_info *header; |
| 558 | |
Rafael J. Wysocki | a634cc1 | 2007-07-19 01:47:30 -0700 | [diff] [blame] | 559 | *flags_p = swsusp_header->flags; |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 560 | if (IS_ERR(resume_bdev)) { |
Rafael J. Wysocki | 2397672 | 2007-12-08 02:09:43 +0100 | [diff] [blame] | 561 | pr_debug("PM: Image device not initialised\n"); |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 562 | return PTR_ERR(resume_bdev); |
| 563 | } |
| 564 | |
| 565 | memset(&snapshot, 0, sizeof(struct snapshot_handle)); |
| 566 | error = snapshot_write_next(&snapshot, PAGE_SIZE); |
| 567 | if (error < PAGE_SIZE) |
| 568 | return error < 0 ? error : -EFAULT; |
| 569 | header = (struct swsusp_info *)data_of(snapshot); |
Vivek Goyal | 1b29c16 | 2007-05-02 19:27:07 +0200 | [diff] [blame] | 570 | error = get_swap_reader(&handle, swsusp_header->image); |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 571 | if (!error) |
Andrew Morton | 546e0d2 | 2006-09-25 23:32:44 -0700 | [diff] [blame] | 572 | error = swap_read_page(&handle, header, NULL); |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 573 | if (!error) |
| 574 | error = load_image(&handle, &snapshot, header->pages - 1); |
| 575 | release_swap_reader(&handle); |
| 576 | |
Al Viro | 9a1c354 | 2008-02-22 20:40:24 -0500 | [diff] [blame] | 577 | blkdev_put(resume_bdev, FMODE_READ); |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 578 | |
| 579 | if (!error) |
Rafael J. Wysocki | 2397672 | 2007-12-08 02:09:43 +0100 | [diff] [blame] | 580 | pr_debug("PM: Image successfully loaded\n"); |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 581 | else |
Rafael J. Wysocki | 2397672 | 2007-12-08 02:09:43 +0100 | [diff] [blame] | 582 | pr_debug("PM: Error %d resuming\n", error); |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 583 | return error; |
| 584 | } |
| 585 | |
| 586 | /** |
| 587 | * swsusp_check - Check for swsusp signature in the resume device |
| 588 | */ |
| 589 | |
| 590 | int swsusp_check(void) |
| 591 | { |
| 592 | int error; |
| 593 | |
| 594 | resume_bdev = open_by_devnum(swsusp_resume_device, FMODE_READ); |
| 595 | if (!IS_ERR(resume_bdev)) { |
| 596 | set_blocksize(resume_bdev, PAGE_SIZE); |
OGAWA Hirofumi | 6373da1 | 2007-05-23 13:58:00 -0700 | [diff] [blame] | 597 | memset(swsusp_header, 0, PAGE_SIZE); |
Rafael J. Wysocki | 9a154d9 | 2006-12-06 20:34:12 -0800 | [diff] [blame] | 598 | error = bio_read_page(swsusp_resume_block, |
Vivek Goyal | 1b29c16 | 2007-05-02 19:27:07 +0200 | [diff] [blame] | 599 | swsusp_header, NULL); |
Rafael J. Wysocki | 9a154d9 | 2006-12-06 20:34:12 -0800 | [diff] [blame] | 600 | if (error) |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 601 | return error; |
Rafael J. Wysocki | 9a154d9 | 2006-12-06 20:34:12 -0800 | [diff] [blame] | 602 | |
Vivek Goyal | 1b29c16 | 2007-05-02 19:27:07 +0200 | [diff] [blame] | 603 | if (!memcmp(SWSUSP_SIG, swsusp_header->sig, 10)) { |
| 604 | memcpy(swsusp_header->sig, swsusp_header->orig_sig, 10); |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 605 | /* Reset swap signature now */ |
Rafael J. Wysocki | 9a154d9 | 2006-12-06 20:34:12 -0800 | [diff] [blame] | 606 | error = bio_write_page(swsusp_resume_block, |
Vivek Goyal | 1b29c16 | 2007-05-02 19:27:07 +0200 | [diff] [blame] | 607 | swsusp_header, NULL); |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 608 | } else { |
| 609 | return -EINVAL; |
| 610 | } |
| 611 | if (error) |
Al Viro | 9a1c354 | 2008-02-22 20:40:24 -0500 | [diff] [blame] | 612 | blkdev_put(resume_bdev, FMODE_READ); |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 613 | else |
Rafael J. Wysocki | 2397672 | 2007-12-08 02:09:43 +0100 | [diff] [blame] | 614 | pr_debug("PM: Signature found, resuming\n"); |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 615 | } else { |
| 616 | error = PTR_ERR(resume_bdev); |
| 617 | } |
| 618 | |
| 619 | if (error) |
Rafael J. Wysocki | 2397672 | 2007-12-08 02:09:43 +0100 | [diff] [blame] | 620 | pr_debug("PM: Error %d checking image file\n", error); |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 621 | |
| 622 | return error; |
| 623 | } |
| 624 | |
| 625 | /** |
| 626 | * swsusp_close - close swap device. |
| 627 | */ |
| 628 | |
Al Viro | c2dd0da | 2007-10-08 13:21:10 -0400 | [diff] [blame] | 629 | void swsusp_close(fmode_t mode) |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 630 | { |
| 631 | if (IS_ERR(resume_bdev)) { |
Rafael J. Wysocki | 2397672 | 2007-12-08 02:09:43 +0100 | [diff] [blame] | 632 | pr_debug("PM: Image device not initialised\n"); |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 633 | return; |
| 634 | } |
| 635 | |
Al Viro | 50c396d | 2008-11-30 01:47:12 -0500 | [diff] [blame] | 636 | blkdev_put(resume_bdev, mode); |
Rafael J. Wysocki | 61159a3 | 2006-03-23 03:00:00 -0800 | [diff] [blame] | 637 | } |
Vivek Goyal | 1b29c16 | 2007-05-02 19:27:07 +0200 | [diff] [blame] | 638 | |
| 639 | static int swsusp_header_init(void) |
| 640 | { |
| 641 | swsusp_header = (struct swsusp_header*) __get_free_page(GFP_KERNEL); |
| 642 | if (!swsusp_header) |
| 643 | panic("Could not allocate memory for swsusp_header\n"); |
| 644 | return 0; |
| 645 | } |
| 646 | |
| 647 | core_initcall(swsusp_header_init); |