Commit 51fb352b2c586b29c7bba38178b3b5389a7fb074

Authored by Jiri Slaby
Committed by Rafael J. Wysocki
1 parent 8a0d613fa1

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>

Showing 1 changed file with 38 additions and 38 deletions Side-by-side Diff

... ... @@ -29,6 +29,40 @@
29 29  
30 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 66 struct swsusp_header {
33 67 char reserved[PAGE_SIZE - 20 - sizeof(sector_t) - sizeof(int)];
34 68 sector_t image;
... ... @@ -151,7 +185,7 @@
151 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 190 int error;
157 191  
... ... @@ -160,7 +194,7 @@
160 194 !memcmp("SWAPSPACE2",swsusp_header->sig, 10)) {
161 195 memcpy(swsusp_header->orig_sig,swsusp_header->sig, 10);
162 196 memcpy(swsusp_header->sig,SWSUSP_SIG, 10);
163   - swsusp_header->image = start;
  197 + swsusp_header->image = handle->first_sector;
164 198 swsusp_header->flags = flags;
165 199 error = hib_bio_write_page(swsusp_resume_block,
166 200 swsusp_header, NULL);
... ... @@ -226,39 +260,6 @@
226 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 263 static void release_swap_writer(struct swap_map_handle *handle)
263 264 {
264 265 if (handle->cur)
... ... @@ -277,6 +278,7 @@
277 278 return -ENOSPC;
278 279 }
279 280 handle->k = 0;
  281 + handle->first_sector = handle->cur_swap;
280 282 return 0;
281 283 }
282 284  
... ... @@ -421,8 +423,6 @@
421 423 }
422 424 error = get_swap_writer(&handle);
423 425 if (!error) {
424   - sector_t start = handle.cur_swap;
425   -
426 426 error = swap_write_page(&handle, header, NULL);
427 427 if (!error)
428 428 error = save_image(&handle, &snapshot,
... ... @@ -431,7 +431,7 @@
431 431 if (!error) {
432 432 flush_swap_writer(&handle);
433 433 printk(KERN_INFO "PM: S");
434   - error = mark_swapfiles(start, flags);
  434 + error = mark_swapfiles(&handle, flags);
435 435 printk("|\n");
436 436 }
437 437 }