2 * linux/kernel/power/swsusp.c
4 * This file provides code to write suspend image to swap and read it back.
6 * Copyright (C) 1998-2001 Gabor Kuti <seasons@fornax.hu>
7 * Copyright (C) 1998,2001-2005 Pavel Machek <pavel@suse.cz>
9 * This file is released under the GPLv2.
11 * I'd like to thank the following people for their work:
13 * Pavel Machek <pavel@ucw.cz>:
14 * Modifications, defectiveness pointing, being with me at the very beginning,
15 * suspend to swap space, stop all tasks. Port to 2.4.18-ac and 2.5.17.
17 * Steve Doddi <dirk@loth.demon.co.uk>:
18 * Support the possibility of hardware state restoring.
20 * Raph <grey.havens@earthling.net>:
21 * Support for preserving states of network devices and virtual console
22 * (including X and svgatextmode)
24 * Kurt Garloff <garloff@suse.de>:
25 * Straightened the critical function in order to prevent compilers from
26 * playing tricks with local variables.
28 * Andreas Mohr <a.mohr@mailto.de>
30 * Alex Badea <vampire@go.ro>:
33 * Andreas Steinmetz <ast@domdv.de>:
34 * Added encrypted suspend option
36 * More state savers are welcome. Especially for the scsi layer...
38 * For TODOs,FIXMEs also look in Documentation/power/swsusp.txt
41 #include <linux/module.h>
43 #include <linux/suspend.h>
44 #include <linux/smp_lock.h>
45 #include <linux/file.h>
46 #include <linux/utsname.h>
47 #include <linux/version.h>
48 #include <linux/delay.h>
49 #include <linux/bitops.h>
50 #include <linux/spinlock.h>
51 #include <linux/genhd.h>
52 #include <linux/kernel.h>
53 #include <linux/major.h>
54 #include <linux/swap.h>
56 #include <linux/device.h>
57 #include <linux/buffer_head.h>
58 #include <linux/swapops.h>
59 #include <linux/bootmem.h>
60 #include <linux/syscalls.h>
61 #include <linux/highmem.h>
62 #include <linux/bio.h>
64 #include <asm/uaccess.h>
65 #include <asm/mmu_context.h>
66 #include <asm/pgtable.h>
67 #include <asm/tlbflush.h>
70 #include <linux/random.h>
71 #include <linux/crypto.h>
72 #include <asm/scatterlist.h>
80 extern char resume_file[];
82 /* Local variables that should not be affected by save */
83 unsigned int nr_copy_pages __nosavedata = 0;
85 /* Suspend pagedir is allocated before final copy, therefore it
86 must be freed after resume
88 Warning: this is even more evil than it seems. Pagedirs this file
89 talks about are completely different from page directories used by
92 suspend_pagedir_t *pagedir_nosave __nosavedata = NULL;
94 #define SWSUSP_SIG "S1SUSPEND"
96 static struct swsusp_header {
97 char reserved[PAGE_SIZE - 20 - MAXKEY - MAXIV - sizeof(swp_entry_t)];
98 u8 key_iv[MAXKEY+MAXIV];
99 swp_entry_t swsusp_info;
102 } __attribute__((packed, aligned(PAGE_SIZE))) swsusp_header;
104 static struct swsusp_info swsusp_info;
110 /* We memorize in swapfile_used what swap devices are used for suspension */
111 #define SWAPFILE_UNUSED 0
112 #define SWAPFILE_SUSPEND 1 /* This is the suspending device */
113 #define SWAPFILE_IGNORED 2 /* Those are other swap devices ignored for suspension */
115 static unsigned short swapfile_used[MAX_SWAPFILES];
116 static unsigned short root_swap;
118 static int write_page(unsigned long addr, swp_entry_t *loc);
119 static int bio_read_page(pgoff_t page_off, void *page);
121 static u8 key_iv[MAXKEY+MAXIV];
123 #ifdef CONFIG_SWSUSP_ENCRYPT
125 static int crypto_init(int mode, void **mem)
130 struct crypto_tfm *tfm;
132 modemsg = mode ? "suspend not possible" : "resume not possible";
134 tfm = crypto_alloc_tfm(CIPHER, CRYPTO_TFM_MODE_CBC);
136 printk(KERN_ERR "swsusp: no tfm, %s\n", modemsg);
141 if(MAXKEY < crypto_tfm_alg_min_keysize(tfm)) {
142 printk(KERN_ERR "swsusp: key buffer too small, %s\n", modemsg);
148 get_random_bytes(key_iv, MAXKEY+MAXIV);
150 len = crypto_tfm_alg_max_keysize(tfm);
154 if (crypto_cipher_setkey(tfm, key_iv, len)) {
155 printk(KERN_ERR "swsusp: key setup failure, %s\n", modemsg);
156 error = -EKEYREJECTED;
160 len = crypto_tfm_alg_ivsize(tfm);
163 printk(KERN_ERR "swsusp: iv buffer too small, %s\n", modemsg);
168 crypto_cipher_set_iv(tfm, key_iv+MAXKEY, len);
174 fail: crypto_free_tfm(tfm);
178 static __inline__ void crypto_exit(void *mem)
180 crypto_free_tfm((struct crypto_tfm *)mem);
183 static __inline__ int crypto_write(struct pbe *p, void *mem)
186 struct scatterlist src, dst;
188 src.page = virt_to_page(p->address);
190 src.length = PAGE_SIZE;
191 dst.page = virt_to_page((void *)&swsusp_header);
193 dst.length = PAGE_SIZE;
195 error = crypto_cipher_encrypt((struct crypto_tfm *)mem, &dst, &src,
199 error = write_page((unsigned long)&swsusp_header,
204 static __inline__ int crypto_read(struct pbe *p, void *mem)
207 struct scatterlist src, dst;
209 error = bio_read_page(swp_offset(p->swap_address), (void *)p->address);
212 src.length = PAGE_SIZE;
214 dst.length = PAGE_SIZE;
215 src.page = dst.page = virt_to_page((void *)p->address);
217 error = crypto_cipher_decrypt((struct crypto_tfm *)mem, &dst,
223 static __inline__ int crypto_init(int mode, void *mem)
228 static __inline__ void crypto_exit(void *mem)
232 static __inline__ int crypto_write(struct pbe *p, void *mem)
234 return write_page(p->address, &(p->swap_address));
237 static __inline__ int crypto_read(struct pbe *p, void *mem)
239 return bio_read_page(swp_offset(p->swap_address), (void *)p->address);
243 static int mark_swapfiles(swp_entry_t prev)
247 rw_swap_page_sync(READ,
248 swp_entry(root_swap, 0),
249 virt_to_page((unsigned long)&swsusp_header));
250 if (!memcmp("SWAP-SPACE",swsusp_header.sig, 10) ||
251 !memcmp("SWAPSPACE2",swsusp_header.sig, 10)) {
252 memcpy(swsusp_header.orig_sig,swsusp_header.sig, 10);
253 memcpy(swsusp_header.sig,SWSUSP_SIG, 10);
254 memcpy(swsusp_header.key_iv, key_iv, MAXKEY+MAXIV);
255 swsusp_header.swsusp_info = prev;
256 error = rw_swap_page_sync(WRITE,
257 swp_entry(root_swap, 0),
258 virt_to_page((unsigned long)
261 pr_debug("swsusp: Partition is not swap space.\n");
268 * Check whether the swap device is the specified resume
269 * device, irrespective of whether they are specified by
272 * (Thus, device inode aliasing is allowed. You can say /dev/hda4
273 * instead of /dev/ide/host0/bus0/target0/lun0/part4 [if using devfs]
274 * and they'll be considered the same device. This is *necessary* for
275 * devfs, since the resume code can only recognize the form /dev/hda4,
276 * but the suspend code would see the long name.)
278 static int is_resume_device(const struct swap_info_struct *swap_info)
280 struct file *file = swap_info->swap_file;
281 struct inode *inode = file->f_dentry->d_inode;
283 return S_ISBLK(inode->i_mode) &&
284 swsusp_resume_device == MKDEV(imajor(inode), iminor(inode));
287 static int swsusp_swap_check(void) /* This is called before saving image */
291 len=strlen(resume_file);
294 spin_lock(&swap_lock);
295 for (i=0; i<MAX_SWAPFILES; i++) {
296 if (!(swap_info[i].flags & SWP_WRITEOK)) {
297 swapfile_used[i]=SWAPFILE_UNUSED;
300 printk(KERN_WARNING "resume= option should be used to set suspend device" );
301 if (root_swap == 0xFFFF) {
302 swapfile_used[i] = SWAPFILE_SUSPEND;
305 swapfile_used[i] = SWAPFILE_IGNORED;
307 /* we ignore all swap devices that are not the resume_file */
308 if (is_resume_device(&swap_info[i])) {
309 swapfile_used[i] = SWAPFILE_SUSPEND;
312 swapfile_used[i] = SWAPFILE_IGNORED;
317 spin_unlock(&swap_lock);
318 return (root_swap != 0xffff) ? 0 : -ENODEV;
322 * This is called after saving image so modification
323 * will be lost after resume... and that's what we want.
324 * we make the device unusable. A new call to
325 * lock_swapdevices can unlock the devices.
327 static void lock_swapdevices(void)
331 spin_lock(&swap_lock);
332 for (i = 0; i< MAX_SWAPFILES; i++)
333 if (swapfile_used[i] == SWAPFILE_IGNORED) {
334 swap_info[i].flags ^= SWP_WRITEOK;
336 spin_unlock(&swap_lock);
340 * write_page - Write one page to a fresh swap location.
341 * @addr: Address we're writing.
342 * @loc: Place to store the entry we used.
344 * Allocate a new swap entry and 'sync' it. Note we discard -EIO
345 * errors. That is an artifact left over from swsusp. It did not
346 * check the return of rw_swap_page_sync() at all, since most pages
347 * written back to swap would return -EIO.
348 * This is a partial improvement, since we will at least return other
349 * errors, though we need to eventually fix the damn code.
351 static int write_page(unsigned long addr, swp_entry_t *loc)
356 entry = get_swap_page();
357 if (swp_offset(entry) &&
358 swapfile_used[swp_type(entry)] == SWAPFILE_SUSPEND) {
359 error = rw_swap_page_sync(WRITE, entry,
371 * data_free - Free the swap entries used by the saved image.
373 * Walk the list of used swap entries and free each one.
374 * This is only used for cleanup when suspend fails.
376 static void data_free(void)
381 for_each_pbe (p, pagedir_nosave) {
382 entry = p->swap_address;
391 * data_write - Write saved image to swap.
393 * Walk the list of pages in the image and sync each one to swap.
395 static int data_write(void)
397 int error = 0, i = 0;
398 unsigned int mod = nr_copy_pages / 100;
402 if ((error = crypto_init(1, &tfm)))
408 printk( "Writing data to swap (%d pages)... ", nr_copy_pages );
409 for_each_pbe (p, pagedir_nosave) {
411 printk( "\b\b\b\b%3d%%", i / mod );
412 if ((error = crypto_write(p, tfm))) {
418 printk("\b\b\b\bdone\n");
423 static void dump_info(void)
425 pr_debug(" swsusp: Version: %u\n",swsusp_info.version_code);
426 pr_debug(" swsusp: Num Pages: %ld\n",swsusp_info.num_physpages);
427 pr_debug(" swsusp: UTS Sys: %s\n",swsusp_info.uts.sysname);
428 pr_debug(" swsusp: UTS Node: %s\n",swsusp_info.uts.nodename);
429 pr_debug(" swsusp: UTS Release: %s\n",swsusp_info.uts.release);
430 pr_debug(" swsusp: UTS Version: %s\n",swsusp_info.uts.version);
431 pr_debug(" swsusp: UTS Machine: %s\n",swsusp_info.uts.machine);
432 pr_debug(" swsusp: UTS Domain: %s\n",swsusp_info.uts.domainname);
433 pr_debug(" swsusp: CPUs: %d\n",swsusp_info.cpus);
434 pr_debug(" swsusp: Image: %ld Pages\n",swsusp_info.image_pages);
435 pr_debug(" swsusp: Pagedir: %ld Pages\n",swsusp_info.pagedir_pages);
438 static void init_header(void)
440 memset(&swsusp_info, 0, sizeof(swsusp_info));
441 swsusp_info.version_code = LINUX_VERSION_CODE;
442 swsusp_info.num_physpages = num_physpages;
443 memcpy(&swsusp_info.uts, &system_utsname, sizeof(system_utsname));
445 swsusp_info.suspend_pagedir = pagedir_nosave;
446 swsusp_info.cpus = num_online_cpus();
447 swsusp_info.image_pages = nr_copy_pages;
450 static int close_swap(void)
456 error = write_page((unsigned long)&swsusp_info, &entry);
459 error = mark_swapfiles(entry);
466 * free_pagedir_entries - Free pages used by the page directory.
468 * This is used during suspend for error recovery.
471 static void free_pagedir_entries(void)
475 for (i = 0; i < swsusp_info.pagedir_pages; i++)
476 swap_free(swsusp_info.pagedir[i]);
481 * write_pagedir - Write the array of pages holding the page directory.
482 * @last: Last swap entry we write (needed for header).
485 static int write_pagedir(void)
491 printk( "Writing pagedir...");
492 for_each_pb_page (pbe, pagedir_nosave) {
493 if ((error = write_page((unsigned long)pbe, &swsusp_info.pagedir[n++])))
497 swsusp_info.pagedir_pages = n;
498 printk("done (%u pages)\n", n);
503 * write_suspend_image - Write entire image and metadata.
506 static int write_suspend_image(void)
511 if ((error = data_write()))
514 if ((error = write_pagedir()))
517 if ((error = close_swap()))
520 memset(key_iv, 0, MAXKEY+MAXIV);
523 free_pagedir_entries();
530 * enough_swap - Make sure we have enough swap to save the image.
532 * Returns TRUE or FALSE after checking the total amount of swap
535 * FIXME: si_swapinfo(&i) returns all swap devices information.
536 * We should only consider resume_device.
539 int enough_swap(unsigned int nr_pages)
544 pr_debug("swsusp: available swap: %lu pages\n", i.freeswap);
545 return i.freeswap > (nr_pages + PAGES_FOR_IO +
546 (nr_pages + PBES_PER_PAGE - 1) / PBES_PER_PAGE);
550 /* It is important _NOT_ to umount filesystems at this point. We want
551 * them synced (in case something goes wrong) but we DO not want to mark
552 * filesystem clean: it is not. (And it does not matter, if we resume
553 * correctly, we'll mark system clean, anyway.)
555 int swsusp_write(void)
560 error = write_suspend_image();
561 /* This will unlock ignored swap devices since writing is finished */
569 int swsusp_suspend(void)
572 if ((error = arch_prepare_suspend()))
575 /* At this point, device_suspend() has been called, but *not*
576 * device_power_down(). We *must* device_power_down() now.
577 * Otherwise, drivers for some devices (e.g. interrupt controllers)
578 * become desynchronized with the actual state of the hardware
579 * at resume time, and evil weirdness ensues.
581 if ((error = device_power_down(PMSG_FREEZE))) {
582 printk(KERN_ERR "Some devices failed to power down, aborting suspend\n");
587 if ((error = swsusp_swap_check())) {
588 printk(KERN_ERR "swsusp: cannot find swap device, try swapon -a.\n");
594 save_processor_state();
595 if ((error = swsusp_arch_suspend()))
596 printk(KERN_ERR "Error %d suspending\n", error);
597 /* Restore control flow magically appears here */
598 restore_processor_state();
605 int swsusp_resume(void)
609 if (device_power_down(PMSG_FREEZE))
610 printk(KERN_ERR "Some devices failed to power down, very bad\n");
611 /* We'll ignore saved state, but this gets preempt count (etc) right */
612 save_processor_state();
613 error = swsusp_arch_resume();
614 /* Code below is only ever reached in case of failure. Otherwise
615 * execution continues at place where swsusp_arch_suspend was called
618 /* The only reason why swsusp_arch_resume() can fail is memory being
619 * very tight, so we have to free it as soon as we can to avoid
620 * subsequent failures
623 restore_processor_state();
625 touch_softlockup_watchdog();
632 * On resume, for storing the PBE list and the image,
633 * we can only use memory pages that do not conflict with the pages
634 * which had been used before suspend.
636 * We don't know which pages are usable until we allocate them.
638 * Allocated but unusable (ie eaten) memory pages are marked so that
639 * swsusp_free() can release them
642 unsigned long get_safe_page(gfp_t gfp_mask)
647 m = get_zeroed_page(gfp_mask);
648 if (m && PageNosaveFree(virt_to_page(m)))
649 /* This is for swsusp_free() */
650 SetPageNosave(virt_to_page(m));
651 } while (m && PageNosaveFree(virt_to_page(m)));
653 /* This is for swsusp_free() */
654 SetPageNosave(virt_to_page(m));
655 SetPageNosaveFree(virt_to_page(m));
661 * check_pagedir - We ensure here that pages that the PBEs point to
662 * won't collide with pages where we're going to restore from the loaded
666 static int check_pagedir(struct pbe *pblist)
670 /* This is necessary, so that we can free allocated pages
673 for_each_pbe (p, pblist)
676 for_each_pbe (p, pblist) {
677 p->address = get_safe_page(GFP_ATOMIC);
685 * swsusp_pagedir_relocate - It is possible, that some memory pages
686 * occupied by the list of PBEs collide with pages where we're going to
687 * restore from the loaded pages later. We relocate them here.
690 static struct pbe *swsusp_pagedir_relocate(struct pbe *pblist)
693 unsigned long zone_pfn;
694 struct pbe *pbpage, *tail, *p;
698 if (!pblist) /* a sanity check */
701 pr_debug("swsusp: Relocating pagedir (%lu pages to check)\n",
702 swsusp_info.pagedir_pages);
704 /* Clear page flags */
706 for_each_zone (zone) {
707 for (zone_pfn = 0; zone_pfn < zone->spanned_pages; ++zone_pfn)
708 if (pfn_valid(zone_pfn + zone->zone_start_pfn))
709 ClearPageNosaveFree(pfn_to_page(zone_pfn +
710 zone->zone_start_pfn));
713 /* Mark orig addresses */
715 for_each_pbe (p, pblist)
716 SetPageNosaveFree(virt_to_page(p->orig_address));
718 tail = pblist + PB_PAGE_SKIP;
720 /* Relocate colliding pages */
722 for_each_pb_page (pbpage, pblist) {
723 if (PageNosaveFree(virt_to_page((unsigned long)pbpage))) {
724 m = (void *)get_safe_page(GFP_ATOMIC | __GFP_COLD);
727 memcpy(m, (void *)pbpage, PAGE_SIZE);
728 if (pbpage == pblist)
729 pblist = (struct pbe *)m;
731 tail->next = (struct pbe *)m;
732 pbpage = (struct pbe *)m;
734 /* We have to link the PBEs again */
735 for (p = pbpage; p < pbpage + PB_PAGE_SKIP; p++)
736 if (p->next) /* needed to save the end */
741 tail = pbpage + PB_PAGE_SKIP;
744 /* This is for swsusp_free() */
745 for_each_pb_page (pbpage, pblist) {
746 SetPageNosave(virt_to_page(pbpage));
747 SetPageNosaveFree(virt_to_page(pbpage));
750 printk("swsusp: Relocated %d pages\n", rel);
756 * Using bio to read from swap.
757 * This code requires a bit more work than just using buffer heads
758 * but, it is the recommended way for 2.5/2.6.
759 * The following are to signal the beginning and end of I/O. Bios
760 * finish asynchronously, while we want them to happen synchronously.
761 * A simple atomic_t, and a wait loop take care of this problem.
764 static atomic_t io_done = ATOMIC_INIT(0);
766 static int end_io(struct bio *bio, unsigned int num, int err)
768 if (!test_bit(BIO_UPTODATE, &bio->bi_flags))
769 panic("I/O error reading memory image");
770 atomic_set(&io_done, 0);
774 static struct block_device *resume_bdev;
777 * submit - submit BIO request.
778 * @rw: READ or WRITE.
779 * @off physical offset of page.
780 * @page: page we're reading or writing.
782 * Straight from the textbook - allocate and initialize the bio.
783 * If we're writing, make sure the page is marked as dirty.
784 * Then submit it and wait.
787 static int submit(int rw, pgoff_t page_off, void *page)
792 bio = bio_alloc(GFP_ATOMIC, 1);
795 bio->bi_sector = page_off * (PAGE_SIZE >> 9);
797 bio->bi_bdev = resume_bdev;
798 bio->bi_end_io = end_io;
800 if (bio_add_page(bio, virt_to_page(page), PAGE_SIZE, 0) < PAGE_SIZE) {
801 printk("swsusp: ERROR: adding page to bio at %ld\n",page_off);
807 bio_set_pages_dirty(bio);
809 atomic_set(&io_done, 1);
810 submit_bio(rw | (1 << BIO_RW_SYNC), bio);
811 while (atomic_read(&io_done))
819 static int bio_read_page(pgoff_t page_off, void *page)
821 return submit(READ, page_off, page);
824 static int bio_write_page(pgoff_t page_off, void *page)
826 return submit(WRITE, page_off, page);
830 * Sanity check if this image makes sense with this kernel/swap context
831 * I really don't think that it's foolproof but more than nothing..
834 static const char *sanity_check(void)
837 if (swsusp_info.version_code != LINUX_VERSION_CODE)
838 return "kernel version";
839 if (swsusp_info.num_physpages != num_physpages)
840 return "memory size";
841 if (strcmp(swsusp_info.uts.sysname,system_utsname.sysname))
842 return "system type";
843 if (strcmp(swsusp_info.uts.release,system_utsname.release))
844 return "kernel release";
845 if (strcmp(swsusp_info.uts.version,system_utsname.version))
847 if (strcmp(swsusp_info.uts.machine,system_utsname.machine))
850 /* We can't use number of online CPUs when we use hotplug to remove them ;-))) */
851 if (swsusp_info.cpus != num_possible_cpus())
852 return "number of cpus";
858 static int check_header(void)
860 const char *reason = NULL;
863 if ((error = bio_read_page(swp_offset(swsusp_header.swsusp_info), &swsusp_info)))
866 /* Is this same machine? */
867 if ((reason = sanity_check())) {
868 printk(KERN_ERR "swsusp: Resume mismatch: %s\n",reason);
871 nr_copy_pages = swsusp_info.image_pages;
875 static int check_sig(void)
879 memset(&swsusp_header, 0, sizeof(swsusp_header));
880 if ((error = bio_read_page(0, &swsusp_header)))
882 if (!memcmp(SWSUSP_SIG, swsusp_header.sig, 10)) {
883 memcpy(swsusp_header.sig, swsusp_header.orig_sig, 10);
884 memcpy(key_iv, swsusp_header.key_iv, MAXKEY+MAXIV);
885 memset(swsusp_header.key_iv, 0, MAXKEY+MAXIV);
888 * Reset swap signature now.
890 error = bio_write_page(0, &swsusp_header);
895 pr_debug("swsusp: Signature found, resuming\n");
900 * data_read - Read image pages from swap.
902 * You do not need to check for overlaps, check_pagedir()
906 static int data_read(struct pbe *pblist)
911 int mod = swsusp_info.image_pages / 100;
914 if ((error = crypto_init(0, &tfm)))
920 printk("swsusp: Reading image data (%lu pages): ",
921 swsusp_info.image_pages);
923 for_each_pbe (p, pblist) {
925 printk("\b\b\b\b%3d%%", i / mod);
927 if ((error = crypto_read(p, tfm))) {
934 printk("\b\b\b\bdone\n");
940 * read_pagedir - Read page backup list pages from swap
943 static int read_pagedir(struct pbe *pblist)
945 struct pbe *pbpage, *p;
952 printk("swsusp: Reading pagedir (%lu pages)\n",
953 swsusp_info.pagedir_pages);
955 for_each_pb_page (pbpage, pblist) {
956 unsigned long offset = swp_offset(swsusp_info.pagedir[i++]);
960 p = (pbpage + PB_PAGE_SKIP)->next;
961 error = bio_read_page(offset, (void *)pbpage);
962 (pbpage + PB_PAGE_SKIP)->next = p;
969 BUG_ON(i != swsusp_info.pagedir_pages);
975 static int check_suspend_image(void)
979 if ((error = check_sig()))
982 if ((error = check_header()))
988 static int read_suspend_image(void)
993 if (!(p = alloc_pagedir(nr_copy_pages)))
996 if ((error = read_pagedir(p)))
999 create_pbe_list(p, nr_copy_pages);
1001 if (!(pagedir_nosave = swsusp_pagedir_relocate(p)))
1004 /* Allocate memory for the image and read the data from swap */
1006 error = check_pagedir(pagedir_nosave);
1009 error = data_read(pagedir_nosave);
1015 * swsusp_check - Check for saved image in swap
1018 int swsusp_check(void)
1022 resume_bdev = open_by_devnum(swsusp_resume_device, FMODE_READ);
1023 if (!IS_ERR(resume_bdev)) {
1024 set_blocksize(resume_bdev, PAGE_SIZE);
1025 error = check_suspend_image();
1027 blkdev_put(resume_bdev);
1029 error = PTR_ERR(resume_bdev);
1032 pr_debug("swsusp: resume file found\n");
1034 pr_debug("swsusp: Error %d check for resume file\n", error);
1039 * swsusp_read - Read saved image from swap.
1042 int swsusp_read(void)
1046 if (IS_ERR(resume_bdev)) {
1047 pr_debug("swsusp: block device not initialised\n");
1048 return PTR_ERR(resume_bdev);
1051 error = read_suspend_image();
1052 blkdev_put(resume_bdev);
1053 memset(key_iv, 0, MAXKEY+MAXIV);
1056 pr_debug("swsusp: Reading resume file was successful\n");
1058 pr_debug("swsusp: Error %d resuming\n", error);
1063 * swsusp_close - close swap device.
1066 void swsusp_close(void)
1068 if (IS_ERR(resume_bdev)) {
1069 pr_debug("swsusp: block device not initialised\n");
1073 blkdev_put(resume_bdev);