[Suspend2][ 19/20] [Suspend2] Prepare an image.

From: Nigel Cunningham
Date: Mon Jun 26 2006 - 19:26:49 EST


Attempt to prepare everything for suspending. This section of the code does
most of the work - freezing processes, allocating storage, freeing memory
and so on. Once it is complete, we are either going to abort or jump
straight into writing the image.

Signed-off-by: Nigel Cunningham <nigel@xxxxxxxxxxxx>

kernel/power/prepare_image.c | 63 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 63 insertions(+), 0 deletions(-)

diff --git a/kernel/power/prepare_image.c b/kernel/power/prepare_image.c
index 893ba72..10159e5 100644
--- a/kernel/power/prepare_image.c
+++ b/kernel/power/prepare_image.c
@@ -622,3 +622,66 @@ static int eat_memory(void)
return 0;
}

+/* prepare_image
+ *
+ * Entry point to the whole image preparation section.
+ *
+ * We do four things:
+ * - Freeze processes;
+ * - Ensure image size constraints are met;
+ * - Complete all the preparation for saving the image,
+ * including allocation of storage. The only memory
+ * that should be needed when we're finished is that
+ * for actually storing the image (and we know how
+ * much is needed for that because the modules tell
+ * us).
+ * - Make sure that all dirty buffers are written out.
+ */
+#define MAX_TRIES 4
+int suspend_prepare_image(void)
+{
+ int result = 1, tries = 0;
+
+ are_frozen = 0;
+
+ header_space_allocated = 0;
+
+ if (attempt_to_freeze())
+ return 1;
+
+ if (!extra_pd1_pages_allowance)
+ get_extra_pd1_allowance();
+
+ storage_available = suspend_active_writer->storage_available();
+
+ if (!storage_available) {
+ printk(KERN_ERR "You need some storage available to be able to suspend.\n");
+ set_result_state(SUSPEND_ABORTED);
+ set_result_state(SUSPEND_NOSTORAGE_AVAILABLE);
+ return 1;
+ }
+
+ do {
+ suspend_prepare_status(CLEAR_BAR, "Preparing Image.");
+
+ if (eat_memory() || test_result_state(SUSPEND_ABORTED))
+ break;
+
+ result = update_image();
+
+ suspend_cond_pause(0, NULL);
+
+ tries++;
+
+ } while ((result) && (tries < MAX_TRIES) && (!test_result_state(SUSPEND_ABORTED)) &&
+ (!test_result_state(SUSPEND_UNABLE_TO_FREE_ENOUGH_MEMORY)));
+
+ if (tries == MAX_TRIES) {
+ abort_suspend("Unable to successfully prepare the image.\n");
+ display_stats(1, 0);
+ }
+
+ suspend_cond_pause(1, "Image preparation complete.");
+
+ 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 majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/