diff options
author | Jiri Slaby <jslaby@suse.cz> | 2010-05-01 17:52:34 -0400 |
---|---|---|
committer | Rafael J. Wysocki <rjw@sisk.pl> | 2010-05-10 17:08:18 -0400 |
commit | 8a0d613fa12e1b7f7f71ca88ed7dc2a3de95121a (patch) | |
tree | 1012509bb830002ba7c41562c26ad211631a26c0 /kernel/power/swap.c | |
parent | d3c1b24c50e8b2bbc840322caf26c7eada594d21 (diff) |
PM / Hibernate: Separate block_io
Move block I/O operations to a separate file. It is because it will
be used later not only by the swap writer.
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Diffstat (limited to 'kernel/power/swap.c')
-rw-r--r-- | kernel/power/swap.c | 136 |
1 files changed, 25 insertions, 111 deletions
diff --git a/kernel/power/swap.c b/kernel/power/swap.c index 7f2a17e4067b..1b1ab6fcf386 100644 --- a/kernel/power/swap.c +++ b/kernel/power/swap.c | |||
@@ -145,93 +145,7 @@ int swsusp_swap_in_use(void) | |||
145 | */ | 145 | */ |
146 | 146 | ||
147 | static unsigned short root_swap = 0xffff; | 147 | static unsigned short root_swap = 0xffff; |
148 | static struct block_device *resume_bdev; | 148 | struct block_device *hib_resume_bdev; |
149 | |||
150 | /** | ||
151 | * submit - submit BIO request. | ||
152 | * @rw: READ or WRITE. | ||
153 | * @off physical offset of page. | ||
154 | * @page: page we're reading or writing. | ||
155 | * @bio_chain: list of pending biod (for async reading) | ||
156 | * | ||
157 | * Straight from the textbook - allocate and initialize the bio. | ||
158 | * If we're reading, make sure the page is marked as dirty. | ||
159 | * Then submit it and, if @bio_chain == NULL, wait. | ||
160 | */ | ||
161 | static int submit(int rw, pgoff_t page_off, struct page *page, | ||
162 | struct bio **bio_chain) | ||
163 | { | ||
164 | const int bio_rw = rw | (1 << BIO_RW_SYNCIO) | (1 << BIO_RW_UNPLUG); | ||
165 | struct bio *bio; | ||
166 | |||
167 | bio = bio_alloc(__GFP_WAIT | __GFP_HIGH, 1); | ||
168 | bio->bi_sector = page_off * (PAGE_SIZE >> 9); | ||
169 | bio->bi_bdev = resume_bdev; | ||
170 | bio->bi_end_io = end_swap_bio_read; | ||
171 | |||
172 | if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) { | ||
173 | printk(KERN_ERR "PM: Adding page to bio failed at %ld\n", | ||
174 | page_off); | ||
175 | bio_put(bio); | ||
176 | return -EFAULT; | ||
177 | } | ||
178 | |||
179 | lock_page(page); | ||
180 | bio_get(bio); | ||
181 | |||
182 | if (bio_chain == NULL) { | ||
183 | submit_bio(bio_rw, bio); | ||
184 | wait_on_page_locked(page); | ||
185 | if (rw == READ) | ||
186 | bio_set_pages_dirty(bio); | ||
187 | bio_put(bio); | ||
188 | } else { | ||
189 | if (rw == READ) | ||
190 | get_page(page); /* These pages are freed later */ | ||
191 | bio->bi_private = *bio_chain; | ||
192 | *bio_chain = bio; | ||
193 | submit_bio(bio_rw, bio); | ||
194 | } | ||
195 | return 0; | ||
196 | } | ||
197 | |||
198 | static int bio_read_page(pgoff_t page_off, void *addr, struct bio **bio_chain) | ||
199 | { | ||
200 | return submit(READ, page_off, virt_to_page(addr), bio_chain); | ||
201 | } | ||
202 | |||
203 | static int bio_write_page(pgoff_t page_off, void *addr, struct bio **bio_chain) | ||
204 | { | ||
205 | return submit(WRITE, page_off, virt_to_page(addr), bio_chain); | ||
206 | } | ||
207 | |||
208 | static int wait_on_bio_chain(struct bio **bio_chain) | ||
209 | { | ||
210 | struct bio *bio; | ||
211 | struct bio *next_bio; | ||
212 | int ret = 0; | ||
213 | |||
214 | if (bio_chain == NULL) | ||
215 | return 0; | ||
216 | |||
217 | bio = *bio_chain; | ||
218 | if (bio == NULL) | ||
219 | return 0; | ||
220 | while (bio) { | ||
221 | struct page *page; | ||
222 | |||
223 | next_bio = bio->bi_private; | ||
224 | page = bio->bi_io_vec[0].bv_page; | ||
225 | wait_on_page_locked(page); | ||
226 | if (!PageUptodate(page) || PageError(page)) | ||
227 | ret = -EIO; | ||
228 | put_page(page); | ||
229 | bio_put(bio); | ||
230 | bio = next_bio; | ||
231 | } | ||
232 | *bio_chain = NULL; | ||
233 | return ret; | ||
234 | } | ||
235 | 149 | ||
236 | /* | 150 | /* |
237 | * Saving part | 151 | * Saving part |
@@ -241,14 +155,14 @@ static int mark_swapfiles(sector_t start, unsigned int flags) | |||
241 | { | 155 | { |
242 | int error; | 156 | int error; |
243 | 157 | ||
244 | bio_read_page(swsusp_resume_block, swsusp_header, NULL); | 158 | hib_bio_read_page(swsusp_resume_block, swsusp_header, NULL); |
245 | if (!memcmp("SWAP-SPACE",swsusp_header->sig, 10) || | 159 | if (!memcmp("SWAP-SPACE",swsusp_header->sig, 10) || |
246 | !memcmp("SWAPSPACE2",swsusp_header->sig, 10)) { | 160 | !memcmp("SWAPSPACE2",swsusp_header->sig, 10)) { |
247 | memcpy(swsusp_header->orig_sig,swsusp_header->sig, 10); | 161 | memcpy(swsusp_header->orig_sig,swsusp_header->sig, 10); |
248 | memcpy(swsusp_header->sig,SWSUSP_SIG, 10); | 162 | memcpy(swsusp_header->sig,SWSUSP_SIG, 10); |
249 | swsusp_header->image = start; | 163 | swsusp_header->image = start; |
250 | swsusp_header->flags = flags; | 164 | swsusp_header->flags = flags; |
251 | error = bio_write_page(swsusp_resume_block, | 165 | error = hib_bio_write_page(swsusp_resume_block, |
252 | swsusp_header, NULL); | 166 | swsusp_header, NULL); |
253 | } else { | 167 | } else { |
254 | printk(KERN_ERR "PM: Swap header not found!\n"); | 168 | printk(KERN_ERR "PM: Swap header not found!\n"); |
@@ -267,18 +181,18 @@ static int swsusp_swap_check(void) /* This is called before saving image */ | |||
267 | int res; | 181 | int res; |
268 | 182 | ||
269 | res = swap_type_of(swsusp_resume_device, swsusp_resume_block, | 183 | res = swap_type_of(swsusp_resume_device, swsusp_resume_block, |
270 | &resume_bdev); | 184 | &hib_resume_bdev); |
271 | if (res < 0) | 185 | if (res < 0) |
272 | return res; | 186 | return res; |
273 | 187 | ||
274 | root_swap = res; | 188 | root_swap = res; |
275 | res = blkdev_get(resume_bdev, FMODE_WRITE); | 189 | res = blkdev_get(hib_resume_bdev, FMODE_WRITE); |
276 | if (res) | 190 | if (res) |
277 | return res; | 191 | return res; |
278 | 192 | ||
279 | res = set_blocksize(resume_bdev, PAGE_SIZE); | 193 | res = set_blocksize(hib_resume_bdev, PAGE_SIZE); |
280 | if (res < 0) | 194 | if (res < 0) |
281 | blkdev_put(resume_bdev, FMODE_WRITE); | 195 | blkdev_put(hib_resume_bdev, FMODE_WRITE); |
282 | 196 | ||
283 | return res; | 197 | return res; |
284 | } | 198 | } |
@@ -309,7 +223,7 @@ static int write_page(void *buf, sector_t offset, struct bio **bio_chain) | |||
309 | } else { | 223 | } else { |
310 | src = buf; | 224 | src = buf; |
311 | } | 225 | } |
312 | return bio_write_page(offset, src, bio_chain); | 226 | return hib_bio_write_page(offset, src, bio_chain); |
313 | } | 227 | } |
314 | 228 | ||
315 | /* | 229 | /* |
@@ -380,7 +294,7 @@ static int swap_write_page(struct swap_map_handle *handle, void *buf, | |||
380 | return error; | 294 | return error; |
381 | handle->cur->entries[handle->k++] = offset; | 295 | handle->cur->entries[handle->k++] = offset; |
382 | if (handle->k >= MAP_PAGE_ENTRIES) { | 296 | if (handle->k >= MAP_PAGE_ENTRIES) { |
383 | error = wait_on_bio_chain(bio_chain); | 297 | error = hib_wait_on_bio_chain(bio_chain); |
384 | if (error) | 298 | if (error) |
385 | goto out; | 299 | goto out; |
386 | offset = alloc_swapdev_block(root_swap); | 300 | offset = alloc_swapdev_block(root_swap); |
@@ -441,7 +355,7 @@ static int save_image(struct swap_map_handle *handle, | |||
441 | printk(KERN_CONT "\b\b\b\b%3d%%", nr_pages / m); | 355 | printk(KERN_CONT "\b\b\b\b%3d%%", nr_pages / m); |
442 | nr_pages++; | 356 | nr_pages++; |
443 | } | 357 | } |
444 | err2 = wait_on_bio_chain(&bio); | 358 | err2 = hib_wait_on_bio_chain(&bio); |
445 | do_gettimeofday(&stop); | 359 | do_gettimeofday(&stop); |
446 | if (!ret) | 360 | if (!ret) |
447 | ret = err2; | 361 | ret = err2; |
@@ -553,7 +467,7 @@ static int get_swap_reader(struct swap_map_handle *handle, sector_t start) | |||
553 | if (!handle->cur) | 467 | if (!handle->cur) |
554 | return -ENOMEM; | 468 | return -ENOMEM; |
555 | 469 | ||
556 | error = bio_read_page(start, handle->cur, NULL); | 470 | error = hib_bio_read_page(start, handle->cur, NULL); |
557 | if (error) { | 471 | if (error) { |
558 | release_swap_reader(handle); | 472 | release_swap_reader(handle); |
559 | return error; | 473 | return error; |
@@ -573,17 +487,17 @@ static int swap_read_page(struct swap_map_handle *handle, void *buf, | |||
573 | offset = handle->cur->entries[handle->k]; | 487 | offset = handle->cur->entries[handle->k]; |
574 | if (!offset) | 488 | if (!offset) |
575 | return -EFAULT; | 489 | return -EFAULT; |
576 | error = bio_read_page(offset, buf, bio_chain); | 490 | error = hib_bio_read_page(offset, buf, bio_chain); |
577 | if (error) | 491 | if (error) |
578 | return error; | 492 | return error; |
579 | if (++handle->k >= MAP_PAGE_ENTRIES) { | 493 | if (++handle->k >= MAP_PAGE_ENTRIES) { |
580 | error = wait_on_bio_chain(bio_chain); | 494 | error = hib_wait_on_bio_chain(bio_chain); |
581 | handle->k = 0; | 495 | handle->k = 0; |
582 | offset = handle->cur->next_swap; | 496 | offset = handle->cur->next_swap; |
583 | if (!offset) | 497 | if (!offset) |
584 | release_swap_reader(handle); | 498 | release_swap_reader(handle); |
585 | else if (!error) | 499 | else if (!error) |
586 | error = bio_read_page(offset, handle->cur, NULL); | 500 | error = hib_bio_read_page(offset, handle->cur, NULL); |
587 | } | 501 | } |
588 | return error; | 502 | return error; |
589 | } | 503 | } |
@@ -622,14 +536,14 @@ static int load_image(struct swap_map_handle *handle, | |||
622 | if (error) | 536 | if (error) |
623 | break; | 537 | break; |
624 | if (snapshot->sync_read) | 538 | if (snapshot->sync_read) |
625 | error = wait_on_bio_chain(&bio); | 539 | error = hib_wait_on_bio_chain(&bio); |
626 | if (error) | 540 | if (error) |
627 | break; | 541 | break; |
628 | if (!(nr_pages % m)) | 542 | if (!(nr_pages % m)) |
629 | printk("\b\b\b\b%3d%%", nr_pages / m); | 543 | printk("\b\b\b\b%3d%%", nr_pages / m); |
630 | nr_pages++; | 544 | nr_pages++; |
631 | } | 545 | } |
632 | err2 = wait_on_bio_chain(&bio); | 546 | err2 = hib_wait_on_bio_chain(&bio); |
633 | do_gettimeofday(&stop); | 547 | do_gettimeofday(&stop); |
634 | if (!error) | 548 | if (!error) |
635 | error = err2; | 549 | error = err2; |
@@ -686,11 +600,11 @@ int swsusp_check(void) | |||
686 | { | 600 | { |
687 | int error; | 601 | int error; |
688 | 602 | ||
689 | resume_bdev = open_by_devnum(swsusp_resume_device, FMODE_READ); | 603 | hib_resume_bdev = open_by_devnum(swsusp_resume_device, FMODE_READ); |
690 | if (!IS_ERR(resume_bdev)) { | 604 | if (!IS_ERR(hib_resume_bdev)) { |
691 | set_blocksize(resume_bdev, PAGE_SIZE); | 605 | set_blocksize(hib_resume_bdev, PAGE_SIZE); |
692 | memset(swsusp_header, 0, PAGE_SIZE); | 606 | memset(swsusp_header, 0, PAGE_SIZE); |
693 | error = bio_read_page(swsusp_resume_block, | 607 | error = hib_bio_read_page(swsusp_resume_block, |
694 | swsusp_header, NULL); | 608 | swsusp_header, NULL); |
695 | if (error) | 609 | if (error) |
696 | goto put; | 610 | goto put; |
@@ -698,7 +612,7 @@ int swsusp_check(void) | |||
698 | if (!memcmp(SWSUSP_SIG, swsusp_header->sig, 10)) { | 612 | if (!memcmp(SWSUSP_SIG, swsusp_header->sig, 10)) { |
699 | memcpy(swsusp_header->sig, swsusp_header->orig_sig, 10); | 613 | memcpy(swsusp_header->sig, swsusp_header->orig_sig, 10); |
700 | /* Reset swap signature now */ | 614 | /* Reset swap signature now */ |
701 | error = bio_write_page(swsusp_resume_block, | 615 | error = hib_bio_write_page(swsusp_resume_block, |
702 | swsusp_header, NULL); | 616 | swsusp_header, NULL); |
703 | } else { | 617 | } else { |
704 | error = -EINVAL; | 618 | error = -EINVAL; |
@@ -706,11 +620,11 @@ int swsusp_check(void) | |||
706 | 620 | ||
707 | put: | 621 | put: |
708 | if (error) | 622 | if (error) |
709 | blkdev_put(resume_bdev, FMODE_READ); | 623 | blkdev_put(hib_resume_bdev, FMODE_READ); |
710 | else | 624 | else |
711 | pr_debug("PM: Signature found, resuming\n"); | 625 | pr_debug("PM: Signature found, resuming\n"); |
712 | } else { | 626 | } else { |
713 | error = PTR_ERR(resume_bdev); | 627 | error = PTR_ERR(hib_resume_bdev); |
714 | } | 628 | } |
715 | 629 | ||
716 | if (error) | 630 | if (error) |
@@ -725,12 +639,12 @@ put: | |||
725 | 639 | ||
726 | void swsusp_close(fmode_t mode) | 640 | void swsusp_close(fmode_t mode) |
727 | { | 641 | { |
728 | if (IS_ERR(resume_bdev)) { | 642 | if (IS_ERR(hib_resume_bdev)) { |
729 | pr_debug("PM: Image device not initialised\n"); | 643 | pr_debug("PM: Image device not initialised\n"); |
730 | return; | 644 | return; |
731 | } | 645 | } |
732 | 646 | ||
733 | blkdev_put(resume_bdev, mode); | 647 | blkdev_put(hib_resume_bdev, mode); |
734 | } | 648 | } |
735 | 649 | ||
736 | static int swsusp_header_init(void) | 650 | static int swsusp_header_init(void) |