From e2d8f105229be8304e9a01c6a8a096571ba7d28e Mon Sep 17 00:00:00 2001 From: Nigel Cunningham Date: Tue, 8 May 2007 21:03:17 +1000 Subject: [PATCH] Further image preparation work. Separate out the test for whether everything necessary for suspending is done into a new function (image_not_ready) and use it in checking whether to do the image preparation again and to check whether we succeeded in preparing the image after finishing the loop. Having done this, we can modify update_image to not have a return value and not drop out if we fail to get enough storage or such like. Signed-off-by: Nigel Cunningham --- kernel/power/prepare_image.c | 100 +++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 60 deletions(-) diff --git a/kernel/power/prepare_image.c b/kernel/power/prepare_image.c index 64b8bc3c276..fc7e7b4de61 100644 --- a/kernel/power/prepare_image.c +++ b/kernel/power/prepare_image.c @@ -38,7 +38,7 @@ static int num_nosave = 0; static int header_space_allocated = 0; -static int storage_allocated = 0; +static int main_storage_allocated = 0; static int storage_available = 0; int extra_pd1_pages_allowance = MIN_EXTRA_PAGES_ALLOWANCE; @@ -294,6 +294,26 @@ static int amount_needed(int use_image_size_limit) return max(highpages_ps1_to_free() + lowpages_ps1_to_free(), any_to_free(use_image_size_limit)); } + +static int image_not_ready(int use_image_size_limit) +{ + suspend_message(SUSPEND_EAT_MEMORY, SUSPEND_LOW, 1, + "Amount still needed (%d) > 0:%d. Header: %d < %d: %d," + " Storage allocd: %d < %d: %d.\n", + amount_needed(1), + (amount_needed(1) > 0), + header_space_allocated, header_storage_needed(), + header_space_allocated < header_storage_needed(), + main_storage_allocated, + main_storage_needed(1, 1), + main_storage_allocated < main_storage_needed(1, 1)); + + suspend_cond_pause(0, NULL); + + return ((amount_needed(use_image_size_limit) > 0) || + header_space_allocated < header_storage_needed() || + main_storage_allocated < main_storage_needed(1, 1)); +} static void display_stats(int always, int sub_extra_pd1_allow) { @@ -505,9 +525,9 @@ void suspend_recalculate_image_contents(int atomic_copy) * * Allocate [more] memory and storage for the image. */ -static int update_image(void) +static void update_image(void) { - int result2, param_used, wanted, got; + int result, param_used, wanted, got; suspend_recalculate_image_contents(0); @@ -520,26 +540,12 @@ static int update_image(void) suspend_message(SUSPEND_EAT_MEMORY, SUSPEND_LOW, 1, "Want %d extra pages for pageset1, got %d.\n", wanted, got); - return 1; + return; } } thaw_kernel_threads(); - param_used = main_storage_needed(1, 0); - if ((result2 = suspendActiveAllocator->allocate_storage(param_used))) { - suspend_message(SUSPEND_EAT_MEMORY, SUSPEND_LOW, 1, - "Allocate storage returned %d. Still need to get more" - " storage space for the image proper.\n", - result2); - storage_allocated = suspendActiveAllocator->storage_allocated(); - if (freeze_processes()) { - set_result_state(SUSPEND_FREEZING_FAILED); - set_result_state(SUSPEND_ABORTED); - } - return 1; - } - /* * Allocate remaining storage space, if possible, up to the * maximum we know we'll need. It's okay to allocate the @@ -554,50 +560,26 @@ static int update_image(void) suspendActiveAllocator->allocate_storage( min(storage_available, main_storage_needed(0, 0))); - storage_allocated = suspendActiveAllocator->storage_allocated(); - - /* Allocate the header storage after allocating main storage - * so that the overhead for metadata doesn't change the amount - * of storage needed for the header itself. - */ + main_storage_allocated = suspendActiveAllocator->storage_allocated(); param_used = header_storage_needed(); - result2 = suspendActiveAllocator->allocate_header_space(param_used); + result = suspendActiveAllocator->allocate_header_space(param_used); + + if (result) + suspend_message(SUSPEND_EAT_MEMORY, SUSPEND_LOW, 1, + "Still need to get more storage space for header.\n"); + else + header_space_allocated = param_used; if (freeze_processes()) { set_result_state(SUSPEND_FREEZING_FAILED); set_result_state(SUSPEND_ABORTED); } - if (result2) { - suspend_message(SUSPEND_EAT_MEMORY, SUSPEND_LOW, 1, - "Still need to get more storage space for header.\n"); - return 1; - } - - header_space_allocated = param_used; - allocate_checksum_pages(); suspend_recalculate_image_contents(0); - - suspend_message(SUSPEND_EAT_MEMORY, SUSPEND_LOW, 1, - "Amount still needed (%d) > 0:%d. Header: %d < %d: %d," - " Storage allocd: %d < %d: %d.\n", - amount_needed(1), - (amount_needed(1) > 0), - header_space_allocated, header_storage_needed(), - header_space_allocated < header_storage_needed(), - storage_allocated, - main_storage_needed(1, 1), - storage_allocated < main_storage_needed(1, 1)); - - suspend_cond_pause(0, NULL); - - return ((amount_needed(1) > 0) || - header_space_allocated < header_storage_needed() || - storage_allocated < main_storage_needed(1, 1)); } /* attempt_to_freeze @@ -749,7 +731,7 @@ int suspend_prepare_image(void) int result = 1, tries = 1; header_space_allocated = 0; - storage_allocated = 0; + main_storage_allocated = 0; if (attempt_to_freeze()) return 1; @@ -774,24 +756,22 @@ int suspend_prepare_image(void) if (test_result_state(SUSPEND_ABORTED)) break; - result = update_image(); + update_image(); - suspend_cond_pause(0, NULL); - tries++; - } while (result && tries <= MAX_TRIES && + } while (image_not_ready(1) && tries <= MAX_TRIES && !test_result_state(SUSPEND_ABORTED)); - if (result || !test_result_state(SUSPEND_ABORTED)) { - if (amount_needed(0) > 0) { + result = image_not_ready(0); + + if (!test_result_state(SUSPEND_ABORTED)) { + if (result) { display_stats(1, 0); abort_suspend(SUSPEND_UNABLE_TO_PREPARE_IMAGE, "Unable to successfully prepare the image.\n"); - } else { - result = 0; + } else suspend_cond_pause(1, "Image preparation complete."); - } } return result; -- 2.11.4.GIT