diff options
author | Jiri Slaby <jslaby@suse.cz> | 2010-05-01 17:53:02 -0400 |
---|---|---|
committer | Rafael J. Wysocki <rjw@sisk.pl> | 2010-05-10 17:08:18 -0400 |
commit | 51fb352b2c586b29c7bba38178b3b5389a7fb074 (patch) | |
tree | 4ac159659111b67c1750181bfa04e69b822fbfa8 /kernel | |
parent | 8a0d613fa12e1b7f7f71ca88ed7dc2a3de95121a (diff) |
PM / Hibernate: Move the first_sector out of swsusp_write
The first sector knowledge is swap-only specific. Move it into the
swap handle. This will be needed for later non-swap specific code
moving into snapshot.c.
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Acked-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: "Rafael J. Wysocki" <rjw@sisk.pl>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/power/swap.c | 76 |
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 | |||
49 | struct 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 | |||
59 | struct 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 | |||
32 | struct swsusp_header { | 66 | struct 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 | ||
154 | static int mark_swapfiles(sector_t start, unsigned int flags) | 188 | static 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 | |||
246 | struct 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 | |||
256 | struct swap_map_handle { | ||
257 | struct swap_map_page *cur; | ||
258 | sector_t cur_swap; | ||
259 | unsigned int k; | ||
260 | }; | ||
261 | |||
262 | static void release_swap_writer(struct swap_map_handle *handle) | 263 | static 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 | } |