swap.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. /*
  2. * linux/kernel/power/swap.c
  3. *
  4. * This file provides functions for reading the suspend image from
  5. * and writing it to a swap partition.
  6. *
  7. * Copyright (C) 1998,2001-2005 Pavel Machek <pavel@suse.cz>
  8. * Copyright (C) 2006 Rafael J. Wysocki <rjw@sisk.pl>
  9. *
  10. * This file is released under the GPLv2.
  11. *
  12. */
  13. #include <linux/module.h>
  14. #include <linux/file.h>
  15. #include <linux/delay.h>
  16. #include <linux/bitops.h>
  17. #include <linux/genhd.h>
  18. #include <linux/device.h>
  19. #include <linux/buffer_head.h>
  20. #include <linux/bio.h>
  21. #include <linux/blkdev.h>
  22. #include <linux/swap.h>
  23. #include <linux/swapops.h>
  24. #include <linux/pm.h>
  25. #include "power.h"
  26. #define SWSUSP_SIG "S1SUSPEND"
  27. struct swsusp_header {
  28. char reserved[PAGE_SIZE - 20 - sizeof(sector_t) - sizeof(int)];
  29. sector_t image;
  30. unsigned int flags; /* Flags to pass to the "boot" kernel */
  31. char orig_sig[10];
  32. char sig[10];
  33. } __attribute__((packed));
  34. static struct swsusp_header *swsusp_header;
  35. /**
  36. * The following functions are used for tracing the allocated
  37. * swap pages, so that they can be freed in case of an error.
  38. */
  39. struct swsusp_extent {
  40. struct rb_node node;
  41. unsigned long start;
  42. unsigned long end;
  43. };
  44. static struct rb_root swsusp_extents = RB_ROOT;
  45. static int swsusp_extents_insert(unsigned long swap_offset)
  46. {
  47. struct rb_node **new = &(swsusp_extents.rb_node);
  48. struct rb_node *parent = NULL;
  49. struct swsusp_extent *ext;
  50. /* Figure out where to put the new node */
  51. while (*new) {
  52. ext = container_of(*new, struct swsusp_extent, node);
  53. parent = *new;
  54. if (swap_offset < ext->start) {
  55. /* Try to merge */
  56. if (swap_offset == ext->start - 1) {
  57. ext->start--;
  58. return 0;
  59. }
  60. new = &((*new)->rb_left);
  61. } else if (swap_offset > ext->end) {
  62. /* Try to merge */
  63. if (swap_offset == ext->end + 1) {
  64. ext->end++;
  65. return 0;
  66. }
  67. new = &((*new)->rb_right);
  68. } else {
  69. /* It already is in the tree */
  70. return -EINVAL;
  71. }
  72. }
  73. /* Add the new node and rebalance the tree. */
  74. ext = kzalloc(sizeof(struct swsusp_extent), GFP_KERNEL);
  75. if (!ext)
  76. return -ENOMEM;
  77. ext->start = swap_offset;
  78. ext->end = swap_offset;
  79. rb_link_node(&ext->node, parent, new);
  80. rb_insert_color(&ext->node, &swsusp_extents);
  81. return 0;
  82. }
  83. /**
  84. * alloc_swapdev_block - allocate a swap page and register that it has
  85. * been allocated, so that it can be freed in case of an error.
  86. */
  87. sector_t alloc_swapdev_block(int swap)
  88. {
  89. unsigned long offset;
  90. offset = swp_offset(get_swap_page_of_type(swap));
  91. if (offset) {
  92. if (swsusp_extents_insert(offset))
  93. swap_free(swp_entry(swap, offset));
  94. else
  95. return swapdev_block(swap, offset);
  96. }
  97. return 0;
  98. }
  99. /**
  100. * free_all_swap_pages - free swap pages allocated for saving image data.
  101. * It also frees the extents used to register which swap entres had been
  102. * allocated.
  103. */
  104. void free_all_swap_pages(int swap)
  105. {
  106. struct rb_node *node;
  107. while ((node = swsusp_extents.rb_node)) {
  108. struct swsusp_extent *ext;
  109. unsigned long offset;
  110. ext = container_of(node, struct swsusp_extent, node);
  111. rb_erase(node, &swsusp_extents);
  112. for (offset = ext->start; offset <= ext->end; offset++)
  113. swap_free(swp_entry(swap, offset));
  114. kfree(ext);
  115. }
  116. }
  117. int swsusp_swap_in_use(void)
  118. {
  119. return (swsusp_extents.rb_node != NULL);
  120. }
  121. /*
  122. * General things
  123. */
  124. static unsigned short root_swap = 0xffff;
  125. static struct block_device *resume_bdev;
  126. /**
  127. * submit - submit BIO request.
  128. * @rw: READ or WRITE.
  129. * @off physical offset of page.
  130. * @page: page we're reading or writing.
  131. * @bio_chain: list of pending biod (for async reading)
  132. *
  133. * Straight from the textbook - allocate and initialize the bio.
  134. * If we're reading, make sure the page is marked as dirty.
  135. * Then submit it and, if @bio_chain == NULL, wait.
  136. */
  137. static int submit(int rw, pgoff_t page_off, struct page *page,
  138. struct bio **bio_chain)
  139. {
  140. const int bio_rw = rw | (1 << BIO_RW_SYNCIO) | (1 << BIO_RW_UNPLUG);
  141. struct bio *bio;
  142. bio = bio_alloc(__GFP_WAIT | __GFP_HIGH, 1);
  143. bio->bi_sector = page_off * (PAGE_SIZE >> 9);
  144. bio->bi_bdev = resume_bdev;
  145. bio->bi_end_io = end_swap_bio_read;
  146. if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) {
  147. printk(KERN_ERR "PM: Adding page to bio failed at %ld\n",
  148. page_off);
  149. bio_put(bio);
  150. return -EFAULT;
  151. }
  152. lock_page(page);
  153. bio_get(bio);
  154. if (bio_chain == NULL) {
  155. submit_bio(bio_rw, bio);
  156. wait_on_page_locked(page);
  157. if (rw == READ)
  158. bio_set_pages_dirty(bio);
  159. bio_put(bio);
  160. } else {
  161. if (rw == READ)
  162. get_page(page); /* These pages are freed later */
  163. bio->bi_private = *bio_chain;
  164. *bio_chain = bio;
  165. submit_bio(bio_rw, bio);
  166. }
  167. return 0;
  168. }
  169. static int bio_read_page(pgoff_t page_off, void *addr, struct bio **bio_chain)
  170. {
  171. return submit(READ, page_off, virt_to_page(addr), bio_chain);
  172. }
  173. static int bio_write_page(pgoff_t page_off, void *addr, struct bio **bio_chain)
  174. {
  175. return submit(WRITE, page_off, virt_to_page(addr), bio_chain);
  176. }
  177. static int wait_on_bio_chain(struct bio **bio_chain)
  178. {
  179. struct bio *bio;
  180. struct bio *next_bio;
  181. int ret = 0;
  182. if (bio_chain == NULL)
  183. return 0;
  184. bio = *bio_chain;
  185. if (bio == NULL)
  186. return 0;
  187. while (bio) {
  188. struct page *page;
  189. next_bio = bio->bi_private;
  190. page = bio->bi_io_vec[0].bv_page;
  191. wait_on_page_locked(page);
  192. if (!PageUptodate(page) || PageError(page))
  193. ret = -EIO;
  194. put_page(page);
  195. bio_put(bio);
  196. bio = next_bio;
  197. }
  198. *bio_chain = NULL;
  199. return ret;
  200. }
  201. /*
  202. * Saving part
  203. */
  204. static int mark_swapfiles(sector_t start, unsigned int flags)
  205. {
  206. int error;
  207. bio_read_page(swsusp_resume_block, swsusp_header, NULL);
  208. if (!memcmp("SWAP-SPACE",swsusp_header->sig, 10) ||
  209. !memcmp("SWAPSPACE2",swsusp_header->sig, 10)) {
  210. memcpy(swsusp_header->orig_sig,swsusp_header->sig, 10);
  211. memcpy(swsusp_header->sig,SWSUSP_SIG, 10);
  212. swsusp_header->image = start;
  213. swsusp_header->flags = flags;
  214. error = bio_write_page(swsusp_resume_block,
  215. swsusp_header, NULL);
  216. } else {
  217. printk(KERN_ERR "PM: Swap header not found!\n");
  218. error = -ENODEV;
  219. }
  220. return error;
  221. }
  222. /**
  223. * swsusp_swap_check - check if the resume device is a swap device
  224. * and get its index (if so)
  225. */
  226. static int swsusp_swap_check(void) /* This is called before saving image */
  227. {
  228. int res;
  229. res = swap_type_of(swsusp_resume_device, swsusp_resume_block,
  230. &resume_bdev);
  231. if (res < 0)
  232. return res;
  233. root_swap = res;
  234. res = blkdev_get(resume_bdev, FMODE_WRITE);
  235. if (res)
  236. return res;
  237. res = set_blocksize(resume_bdev, PAGE_SIZE);
  238. if (res < 0)
  239. blkdev_put(resume_bdev, FMODE_WRITE);
  240. return res;
  241. }
  242. /**
  243. * write_page - Write one page to given swap location.
  244. * @buf: Address we're writing.
  245. * @offset: Offset of the swap page we're writing to.
  246. * @bio_chain: Link the next write BIO here
  247. */
  248. static int write_page(void *buf, sector_t offset, struct bio **bio_chain)
  249. {
  250. void *src;
  251. if (!offset)
  252. return -ENOSPC;
  253. if (bio_chain) {
  254. src = (void *)__get_free_page(__GFP_WAIT | __GFP_HIGH);
  255. if (src) {
  256. memcpy(src, buf, PAGE_SIZE);
  257. } else {
  258. WARN_ON_ONCE(1);
  259. bio_chain = NULL; /* Go synchronous */
  260. src = buf;
  261. }
  262. } else {
  263. src = buf;
  264. }
  265. return bio_write_page(offset, src, bio_chain);
  266. }
  267. /*
  268. * The swap map is a data structure used for keeping track of each page
  269. * written to a swap partition. It consists of many swap_map_page
  270. * structures that contain each an array of MAP_PAGE_SIZE swap entries.
  271. * These structures are stored on the swap and linked together with the
  272. * help of the .next_swap member.
  273. *
  274. * The swap map is created during suspend. The swap map pages are
  275. * allocated and populated one at a time, so we only need one memory
  276. * page to set up the entire structure.
  277. *
  278. * During resume we also only need to use one swap_map_page structure
  279. * at a time.
  280. */
  281. #define MAP_PAGE_ENTRIES (PAGE_SIZE / sizeof(sector_t) - 1)
  282. struct swap_map_page {
  283. sector_t entries[MAP_PAGE_ENTRIES];
  284. sector_t next_swap;
  285. };
  286. /**
  287. * The swap_map_handle structure is used for handling swap in
  288. * a file-alike way
  289. */
  290. struct swap_map_handle {
  291. struct swap_map_page *cur;
  292. sector_t cur_swap;
  293. unsigned int k;
  294. };
  295. static void release_swap_writer(struct swap_map_handle *handle)
  296. {
  297. if (handle->cur)
  298. free_page((unsigned long)handle->cur);
  299. handle->cur = NULL;
  300. }
  301. static int get_swap_writer(struct swap_map_handle *handle)
  302. {
  303. handle->cur = (struct swap_map_page *)get_zeroed_page(GFP_KERNEL);
  304. if (!handle->cur)
  305. return -ENOMEM;
  306. handle->cur_swap = alloc_swapdev_block(root_swap);
  307. if (!handle->cur_swap) {
  308. release_swap_writer(handle);
  309. return -ENOSPC;
  310. }
  311. handle->k = 0;
  312. return 0;
  313. }
  314. static int swap_write_page(struct swap_map_handle *handle, void *buf,
  315. struct bio **bio_chain)
  316. {
  317. int error = 0;
  318. sector_t offset;
  319. if (!handle->cur)
  320. return -EINVAL;
  321. offset = alloc_swapdev_block(root_swap);
  322. error = write_page(buf, offset, bio_chain);
  323. if (error)
  324. return error;
  325. handle->cur->entries[handle->k++] = offset;
  326. if (handle->k >= MAP_PAGE_ENTRIES) {
  327. error = wait_on_bio_chain(bio_chain);
  328. if (error)
  329. goto out;
  330. offset = alloc_swapdev_block(root_swap);
  331. if (!offset)
  332. return -ENOSPC;
  333. handle->cur->next_swap = offset;
  334. error = write_page(handle->cur, handle->cur_swap, NULL);
  335. if (error)
  336. goto out;
  337. memset(handle->cur, 0, PAGE_SIZE);
  338. handle->cur_swap = offset;
  339. handle->k = 0;
  340. }
  341. out:
  342. return error;
  343. }
  344. static int flush_swap_writer(struct swap_map_handle *handle)
  345. {
  346. if (handle->cur && handle->cur_swap)
  347. return write_page(handle->cur, handle->cur_swap, NULL);
  348. else
  349. return -EINVAL;
  350. }
  351. /**
  352. * save_image - save the suspend image data
  353. */
  354. static int save_image(struct swap_map_handle *handle,
  355. struct snapshot_handle *snapshot,
  356. unsigned int nr_to_write)
  357. {
  358. unsigned int m;
  359. int ret;
  360. int nr_pages;
  361. int err2;
  362. struct bio *bio;
  363. struct timeval start;
  364. struct timeval stop;
  365. printk(KERN_INFO "PM: Saving image data pages (%u pages) ... ",
  366. nr_to_write);
  367. m = nr_to_write / 100;
  368. if (!m)
  369. m = 1;
  370. nr_pages = 0;
  371. bio = NULL;
  372. do_gettimeofday(&start);
  373. while (1) {
  374. ret = snapshot_read_next(snapshot, PAGE_SIZE);
  375. if (ret <= 0)
  376. break;
  377. ret = swap_write_page(handle, data_of(*snapshot), &bio);
  378. if (ret)
  379. break;
  380. if (!(nr_pages % m))
  381. printk(KERN_CONT "\b\b\b\b%3d%%", nr_pages / m);
  382. nr_pages++;
  383. }
  384. err2 = wait_on_bio_chain(&bio);
  385. do_gettimeofday(&stop);
  386. if (!ret)
  387. ret = err2;
  388. if (!ret)
  389. printk(KERN_CONT "\b\b\b\bdone\n");
  390. else
  391. printk(KERN_CONT "\n");
  392. swsusp_show_speed(&start, &stop, nr_to_write, "Wrote");
  393. return ret;
  394. }
  395. /**
  396. * enough_swap - Make sure we have enough swap to save the image.
  397. *
  398. * Returns TRUE or FALSE after checking the total amount of swap
  399. * space avaiable from the resume partition.
  400. */
  401. static int enough_swap(unsigned int nr_pages)
  402. {
  403. unsigned int free_swap = count_swap_pages(root_swap, 1);
  404. pr_debug("PM: Free swap pages: %u\n", free_swap);
  405. return free_swap > nr_pages + PAGES_FOR_IO;
  406. }
  407. /**
  408. * swsusp_write - Write entire image and metadata.
  409. * @flags: flags to pass to the "boot" kernel in the image header
  410. *
  411. * It is important _NOT_ to umount filesystems at this point. We want
  412. * them synced (in case something goes wrong) but we DO not want to mark
  413. * filesystem clean: it is not. (And it does not matter, if we resume
  414. * correctly, we'll mark system clean, anyway.)
  415. */
  416. int swsusp_write(unsigned int flags)
  417. {
  418. struct swap_map_handle handle;
  419. struct snapshot_handle snapshot;
  420. struct swsusp_info *header;
  421. int error;
  422. error = swsusp_swap_check();
  423. if (error) {
  424. printk(KERN_ERR "PM: Cannot find swap device, try "
  425. "swapon -a.\n");
  426. return error;
  427. }
  428. memset(&snapshot, 0, sizeof(struct snapshot_handle));
  429. error = snapshot_read_next(&snapshot, PAGE_SIZE);
  430. if (error < PAGE_SIZE) {
  431. if (error >= 0)
  432. error = -EFAULT;
  433. goto out;
  434. }
  435. header = (struct swsusp_info *)data_of(snapshot);
  436. if (!enough_swap(header->pages)) {
  437. printk(KERN_ERR "PM: Not enough free swap\n");
  438. error = -ENOSPC;
  439. goto out;
  440. }
  441. error = get_swap_writer(&handle);
  442. if (!error) {
  443. sector_t start = handle.cur_swap;
  444. error = swap_write_page(&handle, header, NULL);
  445. if (!error)
  446. error = save_image(&handle, &snapshot,
  447. header->pages - 1);
  448. if (!error) {
  449. flush_swap_writer(&handle);
  450. printk(KERN_INFO "PM: S");
  451. error = mark_swapfiles(start, flags);
  452. printk("|\n");
  453. }
  454. }
  455. if (error)
  456. free_all_swap_pages(root_swap);
  457. release_swap_writer(&handle);
  458. out:
  459. swsusp_close(FMODE_WRITE);
  460. return error;
  461. }
  462. /**
  463. * The following functions allow us to read data using a swap map
  464. * in a file-alike way
  465. */
  466. static void release_swap_reader(struct swap_map_handle *handle)
  467. {
  468. if (handle->cur)
  469. free_page((unsigned long)handle->cur);
  470. handle->cur = NULL;
  471. }
  472. static int get_swap_reader(struct swap_map_handle *handle, sector_t start)
  473. {
  474. int error;
  475. if (!start)
  476. return -EINVAL;
  477. handle->cur = (struct swap_map_page *)get_zeroed_page(__GFP_WAIT | __GFP_HIGH);
  478. if (!handle->cur)
  479. return -ENOMEM;
  480. error = bio_read_page(start, handle->cur, NULL);
  481. if (error) {
  482. release_swap_reader(handle);
  483. return error;
  484. }
  485. handle->k = 0;
  486. return 0;
  487. }
  488. static int swap_read_page(struct swap_map_handle *handle, void *buf,
  489. struct bio **bio_chain)
  490. {
  491. sector_t offset;
  492. int error;
  493. if (!handle->cur)
  494. return -EINVAL;
  495. offset = handle->cur->entries[handle->k];
  496. if (!offset)
  497. return -EFAULT;
  498. error = bio_read_page(offset, buf, bio_chain);
  499. if (error)
  500. return error;
  501. if (++handle->k >= MAP_PAGE_ENTRIES) {
  502. error = wait_on_bio_chain(bio_chain);
  503. handle->k = 0;
  504. offset = handle->cur->next_swap;
  505. if (!offset)
  506. release_swap_reader(handle);
  507. else if (!error)
  508. error = bio_read_page(offset, handle->cur, NULL);
  509. }
  510. return error;
  511. }
  512. /**
  513. * load_image - load the image using the swap map handle
  514. * @handle and the snapshot handle @snapshot
  515. * (assume there are @nr_pages pages to load)
  516. */
  517. static int load_image(struct swap_map_handle *handle,
  518. struct snapshot_handle *snapshot,
  519. unsigned int nr_to_read)
  520. {
  521. unsigned int m;
  522. int error = 0;
  523. struct timeval start;
  524. struct timeval stop;
  525. struct bio *bio;
  526. int err2;
  527. unsigned nr_pages;
  528. printk(KERN_INFO "PM: Loading image data pages (%u pages) ... ",
  529. nr_to_read);
  530. m = nr_to_read / 100;
  531. if (!m)
  532. m = 1;
  533. nr_pages = 0;
  534. bio = NULL;
  535. do_gettimeofday(&start);
  536. for ( ; ; ) {
  537. error = snapshot_write_next(snapshot, PAGE_SIZE);
  538. if (error <= 0)
  539. break;
  540. error = swap_read_page(handle, data_of(*snapshot), &bio);
  541. if (error)
  542. break;
  543. if (snapshot->sync_read)
  544. error = wait_on_bio_chain(&bio);
  545. if (error)
  546. break;
  547. if (!(nr_pages % m))
  548. printk("\b\b\b\b%3d%%", nr_pages / m);
  549. nr_pages++;
  550. }
  551. err2 = wait_on_bio_chain(&bio);
  552. do_gettimeofday(&stop);
  553. if (!error)
  554. error = err2;
  555. if (!error) {
  556. printk("\b\b\b\bdone\n");
  557. snapshot_write_finalize(snapshot);
  558. if (!snapshot_image_loaded(snapshot))
  559. error = -ENODATA;
  560. } else
  561. printk("\n");
  562. swsusp_show_speed(&start, &stop, nr_to_read, "Read");
  563. return error;
  564. }
  565. /**
  566. * swsusp_read - read the hibernation image.
  567. * @flags_p: flags passed by the "frozen" kernel in the image header should
  568. * be written into this memeory location
  569. */
  570. int swsusp_read(unsigned int *flags_p)
  571. {
  572. int error;
  573. struct swap_map_handle handle;
  574. struct snapshot_handle snapshot;
  575. struct swsusp_info *header;
  576. *flags_p = swsusp_header->flags;
  577. if (IS_ERR(resume_bdev)) {
  578. pr_debug("PM: Image device not initialised\n");
  579. return PTR_ERR(resume_bdev);
  580. }
  581. memset(&snapshot, 0, sizeof(struct snapshot_handle));
  582. error = snapshot_write_next(&snapshot, PAGE_SIZE);
  583. if (error < PAGE_SIZE)
  584. return error < 0 ? error : -EFAULT;
  585. header = (struct swsusp_info *)data_of(snapshot);
  586. error = get_swap_reader(&handle, swsusp_header->image);
  587. if (!error)
  588. error = swap_read_page(&handle, header, NULL);
  589. if (!error)
  590. error = load_image(&handle, &snapshot, header->pages - 1);
  591. release_swap_reader(&handle);
  592. if (!error)
  593. pr_debug("PM: Image successfully loaded\n");
  594. else
  595. pr_debug("PM: Error %d resuming\n", error);
  596. return error;
  597. }
  598. /**
  599. * swsusp_check - Check for swsusp signature in the resume device
  600. */
  601. int swsusp_check(void)
  602. {
  603. int error;
  604. resume_bdev = open_by_devnum(swsusp_resume_device, FMODE_READ);
  605. if (!IS_ERR(resume_bdev)) {
  606. set_blocksize(resume_bdev, PAGE_SIZE);
  607. memset(swsusp_header, 0, PAGE_SIZE);
  608. error = bio_read_page(swsusp_resume_block,
  609. swsusp_header, NULL);
  610. if (error)
  611. goto put;
  612. if (!memcmp(SWSUSP_SIG, swsusp_header->sig, 10)) {
  613. memcpy(swsusp_header->sig, swsusp_header->orig_sig, 10);
  614. /* Reset swap signature now */
  615. error = bio_write_page(swsusp_resume_block,
  616. swsusp_header, NULL);
  617. } else {
  618. error = -EINVAL;
  619. }
  620. put:
  621. if (error)
  622. blkdev_put(resume_bdev, FMODE_READ);
  623. else
  624. pr_debug("PM: Signature found, resuming\n");
  625. } else {
  626. error = PTR_ERR(resume_bdev);
  627. }
  628. if (error)
  629. pr_debug("PM: Error %d checking image file\n", error);
  630. return error;
  631. }
  632. /**
  633. * swsusp_close - close swap device.
  634. */
  635. void swsusp_close(fmode_t mode)
  636. {
  637. if (IS_ERR(resume_bdev)) {
  638. pr_debug("PM: Image device not initialised\n");
  639. return;
  640. }
  641. blkdev_put(resume_bdev, mode);
  642. }
  643. static int swsusp_header_init(void)
  644. {
  645. swsusp_header = (struct swsusp_header*) __get_free_page(GFP_KERNEL);
  646. if (!swsusp_header)
  647. panic("Could not allocate memory for swsusp_header\n");
  648. return 0;
  649. }
  650. core_initcall(swsusp_header_init);