Initialisation and cleanup routines used when writing the image header.
Signed-off-by: Nigel Cunningham <[email protected]>
kernel/power/suspend_swap.c | 89 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 89 insertions(+), 0 deletions(-)
diff --git a/kernel/power/suspend_swap.c b/kernel/power/suspend_swap.c
index efd08ca..b005f8b 100644
--- a/kernel/power/suspend_swap.c
+++ b/kernel/power/suspend_swap.c
@@ -545,3 +545,92 @@ static int swapwriter_allocate_storage(i
return result;
}
+static int swapwriter_write_header_init(void)
+{
+ int i, result;
+ struct swap_info_struct *si;
+
+ suspend_header_bytes_used = 0;
+
+ suspend_extent_state_goto_start(&suspend_writer_posn);
+ /* Forward one page will be done prior to the read */
+
+ for (i = 0; i < MAX_SWAPFILES; i++) {
+ si = get_swap_info_struct(i);
+ if (si->swap_file)
+ devinfo[i].dev_t = si->bdev->bd_dev;
+ else
+ devinfo[i].dev_t = (dev_t) 0;
+ }
+
+ suspend_writer_buffer = (char *) get_zeroed_page(GFP_ATOMIC);
+ if (!suspend_writer_buffer) {
+ printk("Failed to get swapwriter buffer.\n");
+ return -ENOMEM;
+ }
+
+ suspend_writer_buffer_posn = 0;
+
+ /* Info needed to bootstrap goes at the start of the header.
+ * First we save the positions and devinfo, including the number
+ * of header pages. Then we save the structs containing data needed
+ * for reading the header pages back.
+ * Note that even if header pages take more than one page, when we
+ * read back the info, we will have restored the location of the
+ * next header page by the time we go to use it.
+ */
+
+ if ((result = suspend_bio_ops.rw_header_chunk(WRITE,
+ &swapwriterops,
+ (char *) &suspend_writer_posn_save,
+ sizeof(suspend_writer_posn_save))))
+ return result;
+
+ if ((result = suspend_bio_ops.rw_header_chunk(WRITE,
+ &swapwriterops,
+ (char *) &devinfo, sizeof(devinfo))))
+ return result;
+
+ for (i=0; i < MAX_SWAPFILES; i++)
+ suspend_serialise_extent_chain(&swapwriterops, &block_chain[i]);
+
+ return 0;
+}
+
+static int swapwriter_write_header_cleanup(void)
+{
+ int result;
+ struct swap_info_struct *si;
+
+ /* Write any unsaved data */
+ if (suspend_writer_buffer_posn)
+ suspend_bio_ops.write_header_chunk_finish();
+
+ suspend_bio_ops.finish_all_io();
+
+ suspend_extent_state_goto_start(&suspend_writer_posn);
+ suspend_bio_ops.forward_one_page();
+
+ /* Adjust swap header */
+ suspend_bio_ops.bdev_page_io(READ, resume_block_device,
+ resume_firstblock,
+ virt_to_page(suspend_writer_buffer));
+
+ si = get_swap_info_struct(suspend_writer_posn.current_chain);
+ result = prepare_signature(si->bdev->bd_dev,
+ suspend_writer_posn.current_offset,
+ ((union swap_header *) suspend_writer_buffer)->magic.magic);
+
+ if (!result)
+ suspend_bio_ops.bdev_page_io(WRITE, resume_block_device,
+ resume_firstblock,
+ virt_to_page(suspend_writer_buffer));
+
+ free_page((unsigned long) suspend_writer_buffer);
+ suspend_writer_buffer = NULL;
+
+ suspend_bio_ops.finish_all_io();
+
+ return result;
+}
+
--
Nigel Cunningham nigel at suspend2 dot net
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Stuff]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
[Linux Resources]