From: Nigel Cunningham <ncunningham@crca.org.au>
To: "Rafael J. Wysocki" <rjw@sisk.pl>,
pm list <linux-pm@lists.linux-foundation.org>,
LKML <linux-kernel@vger.kernel.org>,
TuxOnIce-devel <tuxonice-devel@tuxonice.net>
Subject: [PATCH 1/5] Swap iteration functions.
Date: Wed, 26 May 2010 17:09:56 +1000 [thread overview]
Message-ID: <4BFCC944.1010104@crca.org.au> (raw)
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@tuxonice.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 b0bb217..829f7b4 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -86,6 +86,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
reply other threads:[~2010-05-26 7:10 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=4BFCC944.1010104@crca.org.au \
--to=ncunningham@crca.org.au \
--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