From: Nigel Cunningham <nigel@tuxonice.net>
To: "Rafael J. Wysocki" <rjw@sisk.pl>,
Linux PM <linux-pm@lists.linux-foundation.org>,
LKML <linux-kernel@vger.kernel.org>,
TuxOnIce-devel <tuxonice-devel@tuxonice.net>
Subject: [PATCH 12/21] Hibernation: Extent save/load routines.
Date: Wed, 2 Jun 2010 22:19:11 +1000 [thread overview]
Message-ID: <1275481160-31150-13-git-send-email-nigel@tuxonice.net> (raw)
In-Reply-To: <1275481160-31150-1-git-send-email-nigel@tuxonice.net>
Add routines for saving and reloading a chain of extents. This will
be used to store the block extents in the image header, rather than
in swap map pages.
Signed-off-by: Nigel Cunningham <nigel@tuxonice.net>
---
kernel/power/extents.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++
kernel/power/extents.h | 5 +++
2 files changed, 80 insertions(+), 0 deletions(-)
diff --git a/kernel/power/extents.c b/kernel/power/extents.c
index 172322d..75d2fb4 100644
--- a/kernel/power/extents.c
+++ b/kernel/power/extents.c
@@ -14,6 +14,7 @@
#include <linux/slab.h>
#include "extents.h"
+#include "block_io.h"
int hib_extents_empty(struct hib_extent_state *pos)
{
@@ -123,3 +124,77 @@ void hib_extents_clear(struct hib_extent_state *pos)
kfree(ext);
}
}
+
+int hib_extents_storage_needed(struct hib_extent_state *pos)
+{
+ return sizeof(int) + pos->num_extents * 2 * sizeof(unsigned long);
+}
+
+int hib_extents_store(struct hib_extent_state *pos)
+{
+ struct rb_node *node;
+ struct hib_extent *ext;
+ int ret = hib_write_buffer((char *) &pos->num_extents, sizeof(int));
+
+ if (hib_extents_empty(pos))
+ return 0;
+
+ node = rb_first(&pos->root);
+ while (node) {
+ ext = container_of(node, struct hib_extent, node);
+ ret = hib_write_buffer((char *) &ext->start,
+ 2 * sizeof(unsigned long));
+ if (ret)
+ return ret;
+ node = rb_next(node);
+ }
+
+ return 0;
+}
+
+int hib_extents_load(struct hib_extent_state *pos, int bootstrap)
+{
+ struct rb_node **new = &(pos->root.rb_node);
+ struct rb_node *parent = NULL;
+ struct hib_extent *existing, *adding;
+ int i;
+ int ret = hib_read_buffer((char *) &pos->num_extents, sizeof(int));
+
+ if (!pos->num_extents)
+ return 0;
+
+ for (i = 0; i < pos->num_extents; i++) {
+ adding = kzalloc(sizeof(struct hib_extent), GFP_KERNEL);
+ if (!adding)
+ return -ENOMEM;
+
+ ret = hib_read_buffer((char *) &adding->start,
+ 2 * sizeof(unsigned long));
+ if (ret)
+ return ret;
+
+ /*
+ * No need for some of the checks from inserting above -
+ * they were done when preparing the image.
+ */
+ while (*new) {
+ existing = container_of(*new, struct hib_extent, node);
+ parent = *new;
+ if (adding->end < existing->start)
+ new = &((*new)->rb_left);
+ else
+ new = &((*new)->rb_right);
+ }
+ rb_link_node(&adding->node, parent, new);
+ rb_insert_color(&adding->node, &pos->root);
+
+ if (bootstrap && !i) {
+ hib_reset_extent_pos(§or_extents);
+
+ /* We have already read the first page */
+ hib_extent_next(§or_extents);
+ }
+ }
+
+ return 0;
+}
diff --git a/kernel/power/extents.h b/kernel/power/extents.h
index 0b69b8e..4288f9e 100644
--- a/kernel/power/extents.h
+++ b/kernel/power/extents.h
@@ -33,3 +33,8 @@ unsigned long hib_extent_next(struct hib_extent_state *pos);
int hib_extents_insert(struct hib_extent_state *pos, unsigned long value);
void hib_extents_clear(struct hib_extent_state *pos);
int hib_extents_empty(struct hib_extent_state *pos);
+
+/* Serialisation support */
+int hib_extents_storage_needed(struct hib_extent_state *pos);
+int hib_extents_store(struct hib_extent_state *pos);
+int hib_extents_load(struct hib_extent_state *pos, int bootstrap);
--
1.7.0.4
next prev parent reply other threads:[~2010-06-02 12:22 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-02 12:18 Nigel's current for-rafael queue Nigel Cunningham
2010-06-02 12:19 ` [PATCH 01/21] Hibernation: Swap iteration functions Nigel Cunningham
2010-06-02 12:19 ` [PATCH 02/21] Hibernation: Move root_swap declaration Nigel Cunningham
2010-06-02 12:19 ` [PATCH 03/21] Hibernation: Add mass swap allocation routine Nigel Cunningham
2010-06-02 12:19 ` [PATCH 04/21] Hibernation: Switch to preallocating swap Nigel Cunningham
2010-06-02 12:19 ` [PATCH 05/21] Hiberation: Fix speed display Nigel Cunningham
2010-06-02 12:19 ` [PATCH 06/21] Hibernation: Generic extents support Nigel Cunningham
2010-06-02 12:19 ` [PATCH 07/21] Hibernation: Iterate over sectors not swap entries Nigel Cunningham
2010-06-02 12:19 ` [PATCH 08/21] Hibernation: Stop passing swap_map_handle struct Nigel Cunningham
2010-06-02 12:19 ` [PATCH 09/21] Hibernation: Stop passing bio_chain around Nigel Cunningham
2010-06-02 12:19 ` [PATCH 10/21] Hibernation: Move block i/o fns to block_io.c Nigel Cunningham
2010-06-02 12:19 ` [PATCH 11/21] Hibernation: Partial page I/O support Nigel Cunningham
2010-06-02 12:19 ` Nigel Cunningham [this message]
2010-06-02 12:19 ` [PATCH 13/21] Hibernation: Store block extents at start of image Nigel Cunningham
2010-06-02 12:19 ` [PATCH 14/21] Hibernation: Use block extents for reading image Nigel Cunningham
2010-06-02 12:19 ` [PATCH 15/21] Remove first_sector from swap_map_handle Nigel Cunningham
2010-06-02 12:19 ` [PATCH 16/21] Hibernation: Replace bio chain Nigel Cunningham
2010-06-02 12:19 ` [PATCH 17/21] Hibernation: Remove swap_map_pages Nigel Cunningham
2010-06-02 12:19 ` [PATCH 18/21] Hibernation: Remove wait_on_bio_chain result Nigel Cunningham
2010-06-02 12:19 ` [PATCH 19/21] Hibernation: Prepare for handle.cur removal Nigel Cunningham
2010-06-02 12:19 ` [PATCH 20/21] Hibernation: Remove swap_map structure Nigel Cunningham
2010-06-02 12:19 ` [PATCH 21/21] Hibernation: Remove now-empty routines Nigel Cunningham
2010-08-03 6:55 ` Nigel's current for-rafael queue Pavel Machek
2010-08-03 7:00 ` 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=1275481160-31150-13-git-send-email-nigel@tuxonice.net \
--to=nigel@tuxonice.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@lists.linux-foundation.org \
--cc=rjw@sisk.pl \
--cc=tuxonice-devel@tuxonice.net \
/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;
as well as URLs for NNTP newsgroup(s).