aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/power
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/power')
-rw-r--r--kernel/power/swap.c76
1 files changed, 38 insertions, 38 deletions
diff --git a/kernel/power/swap.c b/kernel/power/swap.c
index 1b1ab6fcf386..63e80628a326 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -29,6 +29,40 @@
29 29
30#define SWSUSP_SIG "S1SUSPEND" 30#define SWSUSP_SIG "S1SUSPEND"
31 31
32/*
33 * The swap map is a data structure used for keeping track of each page
34 * written to a swap partition. It consists of many swap_map_page
35 * structures that contain each an array of MAP_PAGE_SIZE swap entries.
36 * These structures are stored on the swap and linked together with the
37 * help of the .next_swap member.
38 *
39 * The swap map is created during suspend. The swap map pages are
40 * allocated and populated one at a time, so we only need one memory
41 * page to set up the entire structure.
42 *
43 * During resume we also only need to use one swap_map_page structure
44 * at a time.
45 */
46
47#define MAP_PAGE_ENTRIES (PAGE_SIZE / sizeof(sector_t) - 1)
48
49struct swap_map_page {
50 sector_t entries[MAP_PAGE_ENTRIES];
51 sector_t next_swap;
52};
53
54/**
55 * The swap_map_handle structure is used for handling swap in
56 * a file-alike way
57 */
58
59struct swap_map_handle {
60 struct swap_map_page *cur;
61 sector_t cur_swap;
62 sector_t first_sector;
63 unsigned int k;
64};
65
32struct swsusp_header { 66struct swsusp_header {
33 char reserved[PAGE_SIZE - 20 - sizeof(sector_t) - sizeof(int)]; 67 char reserved[PAGE_SIZE - 20 - sizeof(sector_t) - sizeof(int)];
34 sector_t image; 68 sector_t image;
@@ -151,7 +185,7 @@ struct block_device *hib_resume_bdev;
151 * Saving part 185 * Saving part
152 */ 186 */
153 187
154static int mark_swapfiles(sector_t start, unsigned int flags) 188static int mark_swapfiles(struct swap_map_handle *handle, unsigned int flags)
155{ 189{
156 int error; 190 int error;
157 191
@@ -160,7 +194,7 @@ static int mark_swapfiles(sector_t start, unsigned int flags)
160 !memcmp("SWAPSPACE2",swsusp_header->sig, 10)) { 194 !memcmp("SWAPSPACE2",swsusp_header->sig, 10)) {
161 memcpy(swsusp_header->orig_sig,swsusp_header->sig, 10); 195 memcpy(swsusp_header->orig_sig,swsusp_header->sig, 10);
162 memcpy(swsusp_header->sig,SWSUSP_SIG, 10); 196 memcpy(swsusp_header->sig,SWSUSP_SIG, 10);
163 swsusp_header->image = start; 197 swsusp_header->image = handle->first_sector;
164 swsusp_header->flags = flags; 198 swsusp_header->flags = flags;
165 error = hib_bio_write_page(swsusp_resume_block, 199 error = hib_bio_write_page(swsusp_resume_block,
166 swsusp_header, NULL); 200 swsusp_header, NULL);
@@ -226,39 +260,6 @@ static int write_page(void *buf, sector_t offset, struct bio **bio_chain)
226 return hib_bio_write_page(offset, src, bio_chain); 260 return hib_bio_write_page(offset, src, bio_chain);
227} 261}
228 262
229/*
230 * The swap map is a data structure used for keeping track of each page
231 * written to a swap partition. It consists of many swap_map_page
232 * structures that contain each an array of MAP_PAGE_SIZE swap entries.
233 * These structures are stored on the swap and linked together with the
234 * help of the .next_swap member.
235 *
236 * The swap map is created during suspend. The swap map pages are
237 * allocated and populated one at a time, so we only need one memory
238 * page to set up the entire structure.
239 *
240 * During resume we also only need to use one swap_map_page structure
241 * at a time.
242 */
243
244#define MAP_PAGE_ENTRIES (PAGE_SIZE / sizeof(sector_t) - 1)
245
246struct swap_map_page {
247 sector_t entries[MAP_PAGE_ENTRIES];
248 sector_t next_swap;
249};
250
251/**
252 * The swap_map_handle structure is used for handling swap in
253 * a file-alike way
254 */
255
256struct swap_map_handle {
257 struct swap_map_page *cur;
258 sector_t cur_swap;
259 unsigned int k;
260};
261
262static void release_swap_writer(struct swap_map_handle *handle) 263static void release_swap_writer(struct swap_map_handle *handle)
263{ 264{
264 if (handle->cur) 265 if (handle->cur)
@@ -277,6 +278,7 @@ static int get_swap_writer(struct swap_map_handle *handle)
277 return -ENOSPC; 278 return -ENOSPC;
278 } 279 }
279 handle->k = 0; 280 handle->k = 0;
281 handle->first_sector = handle->cur_swap;
280 return 0; 282 return 0;
281} 283}
282 284
@@ -421,8 +423,6 @@ int swsusp_write(unsigned int flags)
421 } 423 }
422 error = get_swap_writer(&handle); 424 error = get_swap_writer(&handle);
423 if (!error) { 425 if (!error) {
424 sector_t start = handle.cur_swap;
425
426 error = swap_write_page(&handle, header, NULL); 426 error = swap_write_page(&handle, header, NULL);
427 if (!error) 427 if (!error)
428 error = save_image(&handle, &snapshot, 428 error = save_image(&handle, &snapshot,
@@ -431,7 +431,7 @@ int swsusp_write(unsigned int flags)
431 if (!error) { 431 if (!error) {
432 flush_swap_writer(&handle); 432 flush_swap_writer(&handle);
433 printk(KERN_INFO "PM: S"); 433 printk(KERN_INFO "PM: S");
434 error = mark_swapfiles(start, flags); 434 error = mark_swapfiles(&handle, flags);
435 printk("|\n"); 435 printk("|\n");
436 } 436 }
437 } 437 }