From: Nigel Cunningham <nigel@suspend2.net>
To: linux-kernel@vger.kernel.org
Subject: [Suspend2][ 17/28] [Suspend2] Swapwriter read image header init/cleanup.
Date: Tue, 27 Jun 2006 08:42:04 +1000 [thread overview]
Message-ID: <20060626224202.4975.63796.stgit@nigel.suspend2.net> (raw)
In-Reply-To: <20060626224105.4975.90758.stgit@nigel.suspend2.net>
Initialisation and clean up routines for reading the image header.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/suspend_swap.c | 116 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 116 insertions(+), 0 deletions(-)
diff --git a/kernel/power/suspend_swap.c b/kernel/power/suspend_swap.c
index b005f8b..9d806a5 100644
--- a/kernel/power/suspend_swap.c
+++ b/kernel/power/suspend_swap.c
@@ -634,3 +634,119 @@ static int swapwriter_write_header_clean
return result;
}
+/* ------------------------- HEADER READING ------------------------- */
+
+/*
+ * read_header_init()
+ *
+ * Description:
+ * 1. Attempt to read the device specified with resume2=.
+ * 2. Check the contents of the swap header for our signature.
+ * 3. Warn, ignore, reset and/or continue as appropriate.
+ * 4. If continuing, read the swapwriter configuration section
+ * of the header and set up block device info so we can read
+ * the rest of the header & image.
+ *
+ * Returns:
+ * May not return if user choose to reboot at a warning.
+ * -EINVAL if cannot resume at this time. Booting should continue
+ * normally.
+ */
+
+static int swapwriter_read_header_init(void)
+{
+ int i;
+
+ BUG_ON(!resume_block_device);
+ BUG_ON(!resume_dev_t);
+
+ suspend_header_bytes_used = 0;
+
+ suspend_writer_buffer = (char *) get_zeroed_page(GFP_ATOMIC);
+
+ BUG_ON(!suspend_writer_buffer);
+
+ if (!header_dev_t) {
+ printk("read_header_init called when we haven't "
+ "verified there is an image!\n");
+ return -EINVAL;
+ }
+
+ /*
+ * If the header is not on the resume_dev_t, get the resume device first.
+ */
+ if (header_dev_t != resume_dev_t) {
+ header_block_device = open_bdev(MAX_SWAPFILES + 1,
+ header_dev_t);
+
+ if (IS_ERR(header_block_device))
+ return PTR_ERR(header_block_device);
+ } else
+ header_block_device = resume_block_device;
+
+ /*
+ * Read swapwriter configuration.
+ * Headerblock size taken into account already.
+ */
+ suspend_bio_ops.bdev_page_io(READ, header_block_device,
+ headerblock << 3,
+ virt_to_page((unsigned long) suspend_writer_buffer));
+
+ memcpy(&suspend_writer_posn_save, suspend_writer_buffer, 3 * sizeof(struct extent_iterate_saved_state));
+
+ suspend_writer_buffer_posn = 3 * sizeof(struct extent_iterate_saved_state);
+ suspend_header_bytes_used += 3 * sizeof(struct extent_iterate_saved_state);
+
+ memcpy(&devinfo, suspend_writer_buffer + suspend_writer_buffer_posn, sizeof(devinfo));
+
+ suspend_writer_buffer_posn += sizeof(devinfo);
+ suspend_header_bytes_used += sizeof(devinfo);
+
+ /* Restore device info */
+ for (i = 0; i < MAX_SWAPFILES; i++) {
+ dev_t thisdevice = devinfo[i].dev_t;
+ struct block_device *result;
+
+ devinfo[i].bdev = NULL;
+
+ if (!thisdevice)
+ continue;
+
+ if (thisdevice == resume_dev_t) {
+ devinfo[i].bdev = resume_block_device;
+ bdev_info_list[i] = bdev_info_list[MAX_SWAPFILES];
+ BUG_ON(!bdev_info_list[i]);
+ bdev_info_list[MAX_SWAPFILES] = NULL;
+ continue;
+ }
+
+ if (thisdevice == header_dev_t) {
+ devinfo[i].bdev = header_block_device;
+ bdev_info_list[i] = bdev_info_list[MAX_SWAPFILES + 1];
+ BUG_ON(!bdev_info_list[i]);
+ bdev_info_list[MAX_SWAPFILES + 1] = NULL;
+ continue;
+ }
+
+ result = open_bdev(i, thisdevice);
+ if (IS_ERR(result)) {
+ close_bdevs();
+ return PTR_ERR(result);
+ }
+ }
+
+ suspend_extent_state_goto_start(&suspend_writer_posn);
+ suspend_bio_ops.set_extra_page_forward();
+
+ for (i = 0; i < MAX_SWAPFILES; i++)
+ suspend_load_extent_chain(&block_chain[i]);
+
+ return 0;
+}
+
+static int swapwriter_read_header_cleanup(void)
+{
+ free_page((unsigned long) suspend_writer_buffer);
+ return 0;
+}
+
--
Nigel Cunningham nigel at suspend2 dot net
next prev parent reply other threads:[~2006-06-26 22:47 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-06-26 22:41 [Suspend2][ 00/28] Swapwriter Nigel Cunningham
2006-06-26 22:41 ` [Suspend2][ 01/28] [Suspend2] Swapwriter.c header Nigel Cunningham
2006-06-26 22:41 ` [Suspend2][ 02/28] [Suspend2] Close a bdev used by the swapwriter Nigel Cunningham
2006-06-26 22:41 ` [Suspend2][ 03/28] [Suspend2] Close bdevs opened " Nigel Cunningham
2006-06-26 22:41 ` [Suspend2][ 04/28] [Suspend2] Open bdev for swapwriter use Nigel Cunningham
2006-06-26 22:41 ` [Suspend2][ 05/28] [Suspend2] Enable/disable swapfile Nigel Cunningham
2006-06-26 22:41 ` [Suspend2][ 06/28] [Suspend2] Try to parse resume2= for swapwriter Nigel Cunningham
2006-06-26 22:41 ` [Suspend2][ 07/28] [Suspend2] Reset swapwriter when not resuming Nigel Cunningham
2006-06-26 22:41 ` [Suspend2][ 08/28] [Suspend2] Parse swapwriter signature Nigel Cunningham
2006-06-26 22:41 ` [Suspend2][ 09/28] [Suspend2] Prepare " Nigel Cunningham
2006-06-26 22:41 ` [Suspend2][ 10/28] [Suspend2] Allocate swapwriter header space Nigel Cunningham
2006-06-26 22:41 ` [Suspend2][ 11/28] [Suspend2] Get block chains for swapwriter Nigel Cunningham
2006-06-26 22:41 ` [Suspend2][ 12/28] [Suspend2] Swapwriter storage allocated and available Nigel Cunningham
2006-06-26 22:41 ` [Suspend2][ 13/28] [Suspend2] Initialise/cleanup swapwriter Nigel Cunningham
2006-06-26 22:41 ` [Suspend2][ 14/28] [Suspend2] Release swapwriter storage Nigel Cunningham
2006-06-26 22:41 ` [Suspend2][ 15/28] [Suspend2] Allocate " Nigel Cunningham
2006-06-26 22:42 ` [Suspend2][ 16/28] [Suspend2] Initialise/cleanup writing the header Nigel Cunningham
2006-06-26 22:42 ` Nigel Cunningham [this message]
2006-06-26 22:42 ` [Suspend2][ 18/28] [Suspend2] Invalidate swapwriter image Nigel Cunningham
2006-06-26 22:42 ` [Suspend2][ 19/28] [Suspend2] Swapwriter memory needed Nigel Cunningham
2006-06-26 22:42 ` [Suspend2][ 20/28] [Suspend2] Get swapwriter debug info Nigel Cunningham
2006-06-26 22:42 ` [Suspend2][ 21/28] [Suspend2] Get swapwriter image storage needed Nigel Cunningham
2006-06-26 22:42 ` [Suspend2][ 22/28] [Suspend2] Does a swapwriter image exist? Nigel Cunningham
2006-06-26 22:42 ` [Suspend2][ 23/28] [Suspend2] Swapwriter mark resume attempted Nigel Cunningham
2006-06-26 22:42 ` [Suspend2][ 24/28] [Suspend2] Swapwriter parse resume2= Nigel Cunningham
2006-06-26 22:42 ` [Suspend2][ 25/28] [Suspend2] Read resume2= values for currently enabled swap Nigel Cunningham
2006-06-26 22:42 ` [Suspend2][ 26/28] [Suspend2] Swapwriter proc entries Nigel Cunningham
2006-06-26 22:42 ` [Suspend2][ 27/28] [Suspend2] Swapwriter ops Nigel Cunningham
2006-06-26 22:42 ` [Suspend2][ 28/28] [Suspend2] Swapwriter load and unload routines Nigel Cunningham
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060626224202.4975.63796.stgit@nigel.suspend2.net \
--to=nigel@suspend2.net \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®