[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1285566238-10966-4-git-send-email-nigel@tuxonice.net>
Date: Mon, 27 Sep 2010 15:43:38 +1000
From: Nigel Cunningham <nigel@...onice.net>
To: "Rafael J. Wysocki" <rjw@...k.pl>,
Linux PM <linux-pm@...ts.linux-foundation.org>,
LKML <linux-kernel@...r.kernel.org>,
TuxOnIce-devel <tuxonice-devel@...onice.net>
Subject: [PATCH 03/23] Hibernation: Swap iteration functions.
Add the data structure 'storage_position' and routines that allow
a caller to iterate over swap in sector order. Note that calling
reset_storage_pos only resets the position. next_swapdev_block
must also be called to get the address of the first (and subsequent
sectors).
Signed-off-by: Nigel Cunningham <nigel@...onice.net>
---
kernel/power/swap.c | 39 +++++++++++++++++++++++++++++++++++++++
1 files changed, 39 insertions(+), 0 deletions(-)
diff --git a/kernel/power/swap.c b/kernel/power/swap.c
index caf4db8..4e5f6e3 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -68,6 +68,45 @@ struct swsusp_extent {
static struct rb_root swsusp_extents = RB_ROOT;
+struct storage_position {
+ struct rb_node *node;
+ struct swsusp_extent *cur_ext;
+ unsigned long offset;
+};
+
+static struct storage_position pos;
+
+static void reset_storage_pos(void)
+{
+ pos.node = rb_first(&swsusp_extents);
+
+ if (!pos.node) {
+ pos.cur_ext = NULL;
+ pos.offset = 0;
+ return;
+ }
+
+ pos.cur_ext = container_of(pos.node, struct swsusp_extent, node);
+ pos.offset = pos.cur_ext->start;
+}
+
+static sector_t next_swapdev_block(void)
+{
+ if (!pos.node)
+ return 0;
+
+ if (pos.cur_ext->end >= pos.offset)
+ return pos.offset++;
+
+ pos.node = rb_next(pos.node);
+ if (!pos.node)
+ return 0;
+
+ pos.cur_ext = container_of(pos.node, struct swsusp_extent, node);
+ pos.offset = pos.cur_ext->start;
+ return pos.offset;
+}
+
static int swsusp_extents_insert(unsigned long swap_offset)
{
struct rb_node **new = &(swsusp_extents.rb_node);
--
1.7.0.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists