swap.c 17 KB

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