mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [Suspend2][ 00/11 Module support.
@ 2006-06-26 16:53 Nigel Cunningham
  2006-06-26 16:53 ` [Suspend2][ 01/11] [Suspend2] Modules.c header Nigel Cunningham
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: Nigel Cunningham @ 2006-06-26 16:53 UTC (permalink / raw)
  To: linux-kernel


Add utility routines for registering and iterating over modules
that Suspend2 uses. A suspend2 module is a distinct part of the
code - the user interface support, storage manager support,
swapwriter, filewriter and low-level I/O code are all treated
as separate modules.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Suspend2][ 01/11] [Suspend2] Modules.c header.
  2006-06-26 16:53 [Suspend2][ 00/11 Module support Nigel Cunningham
@ 2006-06-26 16:53 ` Nigel Cunningham
  2006-06-26 16:53 ` [Suspend2][ 02/11] [Suspend2] Get header storage needed for module data Nigel Cunningham
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Nigel Cunningham @ 2006-06-26 16:53 UTC (permalink / raw)
  To: linux-kernel

Header of modules.c file, which contains routines specifically related to
the interaction between Suspend2's core code and the modules that implement
encryption, compression, i/o and the like.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

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

diff --git a/kernel/power/modules.c b/kernel/power/modules.c
new file mode 100644
index 0000000..f337208
--- /dev/null
+++ b/kernel/power/modules.c
@@ -0,0 +1,18 @@
+/*
+ * kernel/power/modules.c
+ *
+ * Copyright (C) 2004-2006 Nigel Cunningham <nigel@suspend2.net>
+ *
+ */
+
+#include <linux/suspend.h>
+#include <linux/module.h>
+#include "suspend2.h"
+#include "modules.h"
+#include "ui.h"
+
+struct list_head suspend_filters, suspend_writers, suspend_modules;
+struct suspend_module_ops *suspend_active_writer;
+static int suspend_num_filters;
+int suspend_num_writers, suspend_num_modules;
+       

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Suspend2][ 02/11] [Suspend2] Get header storage needed for module data.
  2006-06-26 16:53 [Suspend2][ 00/11 Module support Nigel Cunningham
  2006-06-26 16:53 ` [Suspend2][ 01/11] [Suspend2] Modules.c header Nigel Cunningham
@ 2006-06-26 16:53 ` Nigel Cunningham
  2006-06-26 16:53 ` [Suspend2][ 03/11] [Suspend2] Get memory needed for Suspend2 modules Nigel Cunningham
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Nigel Cunningham @ 2006-06-26 16:53 UTC (permalink / raw)
  To: linux-kernel

Get the amount of space in the image header required by modules to store
their data. Modules store in image header configuration needed to resume,
such as the name of the cryptoapi modules used for encryption and
compression. The writer may store additional information for bootstrapping,
such as where to find the header's pages on disk, which is not included in
this value. This is only the space required in the image header proper.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

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

diff --git a/kernel/power/modules.c b/kernel/power/modules.c
index f337208..60c7c7b 100644
--- a/kernel/power/modules.c
+++ b/kernel/power/modules.c
@@ -16,3 +16,36 @@ struct suspend_module_ops *suspend_activ
 static int suspend_num_filters;
 int suspend_num_writers, suspend_num_modules;
        
+/*
+ * suspend_header_storage_for_modules
+ *
+ * Returns the amount of space needed to store configuration
+ * data needed by the modules prior to copying back the original
+ * kernel. We can exclude data for pageset2 because it will be
+ * available anyway once the kernel is copied back.
+ */
+unsigned long suspend_header_storage_for_modules(void)
+{
+	struct suspend_module_ops *this_module;
+	unsigned long bytes = 0;
+	
+	list_for_each_entry(this_module, &suspend_modules, module_list) {
+		this_module->header_requested = 0;
+		this_module->header_used = 0;
+		if (this_module->disabled ||
+		    (this_module->type == WRITER_MODULE &&
+		     suspend_active_writer != this_module))
+			continue;
+		if (this_module->storage_needed) {
+			int this = this_module->storage_needed() +
+				sizeof(struct suspend_module_header) +
+				sizeof(int);
+			this_module->header_requested = this;
+			bytes += this;
+		}
+	}
+
+	/* One more for the empty terminator */
+	return bytes + sizeof(struct suspend_module_header);
+}
+

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Suspend2][ 03/11] [Suspend2] Get memory needed for Suspend2 modules.
  2006-06-26 16:53 [Suspend2][ 00/11 Module support Nigel Cunningham
  2006-06-26 16:53 ` [Suspend2][ 01/11] [Suspend2] Modules.c header Nigel Cunningham
  2006-06-26 16:53 ` [Suspend2][ 02/11] [Suspend2] Get header storage needed for module data Nigel Cunningham
@ 2006-06-26 16:53 ` Nigel Cunningham
  2006-06-26 16:53 ` [Suspend2][ 04/11] [Suspend2] Find a suspend2 module given its name Nigel Cunningham
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Nigel Cunningham @ 2006-06-26 16:53 UTC (permalink / raw)
  To: linux-kernel

Determine how much free memory should be available for Suspend2 modules to
do their work while reading and writing the image.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

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

diff --git a/kernel/power/modules.c b/kernel/power/modules.c
index 60c7c7b..ff9b9d7 100644
--- a/kernel/power/modules.c
+++ b/kernel/power/modules.c
@@ -49,3 +49,25 @@ unsigned long suspend_header_storage_for
 	return bytes + sizeof(struct suspend_module_header);
 }
 
+/*
+ * suspend_memory_for_modules
+ *
+ * Returns the amount of memory requested by modules for
+ * doing their work during the cycle.
+ */
+
+unsigned long suspend_memory_for_modules(void)
+{
+	unsigned long bytes = 0;
+	struct suspend_module_ops *this_module;
+
+	list_for_each_entry(this_module, &suspend_modules, module_list) {
+		if (this_module->disabled)
+			continue;
+		if (this_module->memory_needed)
+			bytes += this_module->memory_needed();
+	}
+
+	return ((bytes + PAGE_SIZE - 1) >> PAGE_SHIFT);
+}
+

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Suspend2][ 04/11] [Suspend2] Find a suspend2 module given its name
  2006-06-26 16:53 [Suspend2][ 00/11 Module support Nigel Cunningham
                   ` (2 preceding siblings ...)
  2006-06-26 16:53 ` [Suspend2][ 03/11] [Suspend2] Get memory needed for Suspend2 modules Nigel Cunningham
@ 2006-06-26 16:53 ` Nigel Cunningham
  2006-06-26 16:53 ` [Suspend2][ 05/11] [Suspend2] Get debugging info from modules Nigel Cunningham
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Nigel Cunningham @ 2006-06-26 16:53 UTC (permalink / raw)
  To: linux-kernel

Given the name of a Suspend2 module, return a pointer to it's struct
suspend_module_ops.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

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

diff --git a/kernel/power/modules.c b/kernel/power/modules.c
index ff9b9d7..c18b5fb 100644
--- a/kernel/power/modules.c
+++ b/kernel/power/modules.c
@@ -71,3 +71,22 @@ unsigned long suspend_memory_for_modules
 	return ((bytes + PAGE_SIZE - 1) >> PAGE_SHIFT);
 }
 
+/* suspend_find_module_given_name
+ * Functionality :	Return a module (if found), given a pointer
+ * 			to its name
+ */
+
+struct suspend_module_ops *suspend_find_module_given_name(char *name)
+{
+	struct suspend_module_ops *this_module, *found_module = NULL;
+	
+	list_for_each_entry(this_module, &suspend_modules, module_list) {
+		if (!strcmp(name, this_module->name)) {
+			found_module = this_module;
+			break;
+		}			
+	}
+
+	return found_module;
+}
+

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Suspend2][ 05/11] [Suspend2] Get debugging info from modules.
  2006-06-26 16:53 [Suspend2][ 00/11 Module support Nigel Cunningham
                   ` (3 preceding siblings ...)
  2006-06-26 16:53 ` [Suspend2][ 04/11] [Suspend2] Find a suspend2 module given its name Nigel Cunningham
@ 2006-06-26 16:53 ` Nigel Cunningham
  2006-06-26 16:53 ` [Suspend2][ 06/11] [Suspend2] Register and unregister suspend2 modules Nigel Cunningham
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Nigel Cunningham @ 2006-06-26 16:53 UTC (permalink / raw)
  To: linux-kernel

Fill a buffer with debugging information from the suspend2 modules. It is
assumed that this information will never exceed a page in total. If this
did happen, the data would be truncated.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

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

diff --git a/kernel/power/modules.c b/kernel/power/modules.c
index c18b5fb..50607f5 100644
--- a/kernel/power/modules.c
+++ b/kernel/power/modules.c
@@ -90,3 +90,29 @@ struct suspend_module_ops *suspend_find_
 	return found_module;
 }
 
+/*
+ * suspend_print_module_debug_info
+ * Functionality   : Get debugging info from modules into a buffer.
+ */
+int suspend_print_module_debug_info(char *buffer, int buffer_size)
+{
+	struct suspend_module_ops *this_module;
+	int len = 0;
+
+	list_for_each_entry(this_module, &suspend_modules, module_list) {
+		if (this_module->disabled)
+			continue;
+		if (this_module->print_debug_info) {
+			int result;
+			result = this_module->print_debug_info(buffer + len, 
+					buffer_size - len);
+			len += result;
+		}
+	}
+
+	/* Ensure null terminated */
+	buffer[buffer_size] = 0;
+
+	return len;
+}
+

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Suspend2][ 06/11] [Suspend2] Register and unregister suspend2 modules.
  2006-06-26 16:53 [Suspend2][ 00/11 Module support Nigel Cunningham
                   ` (4 preceding siblings ...)
  2006-06-26 16:53 ` [Suspend2][ 05/11] [Suspend2] Get debugging info from modules Nigel Cunningham
@ 2006-06-26 16:53 ` Nigel Cunningham
  2006-06-26 16:53 ` [Suspend2][ 07/11] [Suspend2] Move a suspend2 module to the tail of its list Nigel Cunningham
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Nigel Cunningham @ 2006-06-26 16:53 UTC (permalink / raw)
  To: linux-kernel

Routines for suspend2 modules to use at boot or module load/unload.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

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

diff --git a/kernel/power/modules.c b/kernel/power/modules.c
index 50607f5..6305fa2 100644
--- a/kernel/power/modules.c
+++ b/kernel/power/modules.c
@@ -116,3 +116,74 @@ int suspend_print_module_debug_info(char
 	return len;
 }
 
+/*
+ * suspend_register_module
+ *
+ * Register a module.
+ */
+int suspend_register_module(struct suspend_module_ops *module)
+{
+	if (suspend_find_module_given_name(module->name))
+		return -EBUSY;
+
+	switch (module->type) {
+		case FILTER_MODULE:
+			list_add_tail(&module->type_list,
+					&suspend_filters);
+			suspend_num_filters++;
+			break;
+
+		case WRITER_MODULE:
+			list_add_tail(&module->type_list,
+					&suspend_writers);
+			suspend_num_writers++;
+			break;
+
+		case MISC_MODULE:
+			break;
+
+		default:
+			printk("Hmmm. Module '%s' has an invalid type."
+				" It has been ignored.\n", module->name);
+			return -EINVAL;
+	}
+	list_add_tail(&module->module_list, &suspend_modules);
+	suspend_num_modules++;
+
+	return 0;	
+}
+
+/*
+ * suspend_unregister_module
+ *
+ * Remove a module.
+ */
+void suspend_unregister_module(struct suspend_module_ops *module)
+{
+	switch (module->type) {
+		case FILTER_MODULE:
+			list_del(&module->type_list);
+			suspend_num_filters--;
+			break;
+
+		case WRITER_MODULE:
+			list_del(&module->type_list);
+			suspend_num_writers--;
+			if (suspend_active_writer == module) {
+				suspend_active_writer = NULL;
+				clear_suspend_state(SUSPEND_CAN_RESUME);
+				clear_suspend_state(SUSPEND_CAN_SUSPEND);
+			}
+			break;
+		
+		case MISC_MODULE:
+			break;
+
+		default:
+			printk("Hmmm. Module '%s' has an invalid type."
+				" It has been ignored.\n", module->name);
+			return;
+	}
+	list_del(&module->module_list);
+	suspend_num_modules--;
+}

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Suspend2][ 07/11] [Suspend2] Move a suspend2 module to the tail of its list.
  2006-06-26 16:53 [Suspend2][ 00/11 Module support Nigel Cunningham
                   ` (5 preceding siblings ...)
  2006-06-26 16:53 ` [Suspend2][ 06/11] [Suspend2] Register and unregister suspend2 modules Nigel Cunningham
@ 2006-06-26 16:53 ` Nigel Cunningham
  2006-06-26 16:53 ` [Suspend2][ 08/11] [Suspend2] Initialise and cleanup routines for suspend2 modules Nigel Cunningham
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Nigel Cunningham @ 2006-06-26 16:53 UTC (permalink / raw)
  To: linux-kernel

When suspend2 modules are built as kernel modules, they may be loaded in a
different order when resuming to the order used when suspending. This could
result in decryption and decompression being done in the wrong order. We
avoid this by remembering the order used when suspending, and reordering at
resume-time to match. This routine provides the primitive used in that
reordering.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

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

diff --git a/kernel/power/modules.c b/kernel/power/modules.c
index 6305fa2..af237b6 100644
--- a/kernel/power/modules.c
+++ b/kernel/power/modules.c
@@ -187,3 +187,38 @@ void suspend_unregister_module(struct su
 	list_del(&module->module_list);
 	suspend_num_modules--;
 }
+
+/*
+ * suspend_move_module_tail
+ *
+ * Rearrange modules when reloading the config.
+ */
+void suspend_move_module_tail(struct suspend_module_ops *module)
+{
+	switch (module->type) {
+		case FILTER_MODULE:
+			if (suspend_num_filters > 1)
+				list_move_tail(&module->type_list,
+						&suspend_filters);
+			break;
+
+		case WRITER_MODULE:
+			if (suspend_num_writers > 1)
+				list_move_tail(&module->type_list,
+						&suspend_writers);
+			break;
+		
+		case MISC_MODULE:
+			break;
+		default:
+			printk("Hmmm. Module '%s' has an invalid type."
+				" It has been ignored.\n", module->name);
+			return;
+	}
+	if ((suspend_num_filters + suspend_num_writers) > 1)
+		list_move_tail(&module->module_list, &suspend_modules);
+}
+
+	return len;
+}
+

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Suspend2][ 08/11] [Suspend2] Initialise and cleanup routines for suspend2 modules.
  2006-06-26 16:53 [Suspend2][ 00/11 Module support Nigel Cunningham
                   ` (6 preceding siblings ...)
  2006-06-26 16:53 ` [Suspend2][ 07/11] [Suspend2] Move a suspend2 module to the tail of its list Nigel Cunningham
@ 2006-06-26 16:53 ` Nigel Cunningham
  2006-06-26 16:53 ` [Suspend2][ 09/11] [Suspend2] Get next suspend2 module in the pipeline Nigel Cunningham
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Nigel Cunningham @ 2006-06-26 16:53 UTC (permalink / raw)
  To: linux-kernel

Routines to iterate through the list of suspend2 modules, calling their
initialisation and cleanup routines.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

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

diff --git a/kernel/power/modules.c b/kernel/power/modules.c
index af237b6..cd171a8 100644
--- a/kernel/power/modules.c
+++ b/kernel/power/modules.c
@@ -219,6 +219,55 @@ void suspend_move_module_tail(struct sus
 		list_move_tail(&module->module_list, &suspend_modules);
 }
 
+/*
+ * suspend_initialise_modules
+ *
+ * Get ready to do some work!
+ */
+int suspend_initialise_modules(int starting_cycle)
+{
+	struct suspend_module_ops *this_module;
+	int result;
+	
+	list_for_each_entry(this_module, &suspend_modules, module_list) {
+		if (this_module->disabled)
+			continue;
+		if (this_module->initialise) {
+			suspend_message(SUSPEND_MEMORY, SUSPEND_MEDIUM, 1,
+				"Initialising module %s.\n",
+				this_module->name);
+			if ((result = this_module->initialise(starting_cycle))) {
+				printk("%s didn't initialise okay.\n",
+						this_module->name);
+				return result;
+			}
+		}
+	}
+
+	return 0;
+}
+
+/* 
+ * suspend_cleanup_modules
+ *
+ * Tell modules the work is done.
+ */
+void suspend_cleanup_modules(int finishing_cycle)
+{
+	struct suspend_module_ops *this_module;
+	
+	list_for_each_entry(this_module, &suspend_modules, module_list) {
+		if (this_module->disabled)
+			continue;
+		if (this_module->cleanup) {
+			suspend_message(SUSPEND_MEMORY, SUSPEND_MEDIUM, 1,
+				"Cleaning up module %s.\n",
+				this_module->name);
+			this_module->cleanup(finishing_cycle);
+		}
+	}
+}
+
 	return len;
 }
 

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Suspend2][ 09/11] [Suspend2] Get next suspend2 module in the pipeline.
  2006-06-26 16:53 [Suspend2][ 00/11 Module support Nigel Cunningham
                   ` (7 preceding siblings ...)
  2006-06-26 16:53 ` [Suspend2][ 08/11] [Suspend2] Initialise and cleanup routines for suspend2 modules Nigel Cunningham
@ 2006-06-26 16:53 ` Nigel Cunningham
  2006-06-26 16:53 ` [Suspend2][ 10/11] [Suspend2] Get and put references to Suspend2 modules Nigel Cunningham
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Nigel Cunningham @ 2006-06-26 16:53 UTC (permalink / raw)
  To: linux-kernel

Suspend2 modules are strung together in a pipeline. This function enables
one module in the pipeline to find out what the next module is, so that it
can pass its output to that module when writing, and request data from it
when reading.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

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

diff --git a/kernel/power/modules.c b/kernel/power/modules.c
index cd171a8..d7c2076 100644
--- a/kernel/power/modules.c
+++ b/kernel/power/modules.c
@@ -268,6 +268,26 @@ void suspend_cleanup_modules(int finishi
 	}
 }
 
+/*
+ * suspend_get_next_filter
+ *
+ * Get the next filter in the pipeline.
+ */
+struct suspend_module_ops *suspend_get_next_filter(struct suspend_module_ops *filter_sought)
+{
+	struct suspend_module_ops *last_filter = NULL, *this_filter = NULL;
+
+	list_for_each_entry(this_filter, &suspend_filters, type_list) {
+		if (this_filter->disabled)
+			continue;
+		if ((last_filter == filter_sought) || (!filter_sought))
+			return this_filter;
+		last_filter = this_filter;
+	}
+
+	return suspend_active_writer;
+}
+
 	return len;
 }
 

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Suspend2][ 10/11] [Suspend2] Get and put references to Suspend2 modules.
  2006-06-26 16:53 [Suspend2][ 00/11 Module support Nigel Cunningham
                   ` (8 preceding siblings ...)
  2006-06-26 16:53 ` [Suspend2][ 09/11] [Suspend2] Get next suspend2 module in the pipeline Nigel Cunningham
@ 2006-06-26 16:53 ` Nigel Cunningham
  2006-06-26 16:53 ` [Suspend2][ 11/11] [Suspend2] Header file for " Nigel Cunningham
  2006-06-26 21:15 ` [Suspend2][ 00/11 Module support Rafael J. Wysocki
  11 siblings, 0 replies; 13+ messages in thread
From: Nigel Cunningham @ 2006-06-26 16:53 UTC (permalink / raw)
  To: linux-kernel

Functions to get and put references to suspend2 modules, to stop them being
unloaded while in use.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

 kernel/power/modules.c |   36 +++++++++++++++++++++++++++++++++++-
 1 files changed, 35 insertions(+), 1 deletions(-)

diff --git a/kernel/power/modules.c b/kernel/power/modules.c
index d7c2076..5c5cbf0 100644
--- a/kernel/power/modules.c
+++ b/kernel/power/modules.c
@@ -288,6 +288,40 @@ struct suspend_module_ops *suspend_get_n
 	return suspend_active_writer;
 }
 
-	return len;
+/* suspend_get_modules
+ * 
+ * Take a reference to modules so they can't go away under us.
+ */
+
+int suspend_get_modules(void)
+{
+	struct suspend_module_ops *this_module;
+	
+	list_for_each_entry(this_module, &suspend_modules, module_list) {
+		if (!try_module_get(this_module->module)) {
+			/* Failed! Reverse gets and return error */
+			struct suspend_module_ops *this_module2;
+			list_for_each_entry(this_module2, &suspend_modules, module_list) {
+				if (this_module == this_module2)
+					return -EINVAL;
+				module_put(this_module2->module);
+			}
+		}
+	}
+
+	return 0;
+}
+
+/* suspend_put_modules
+ *
+ * Release our references to modules we used.
+ */
+
+void suspend_put_modules(void)
+{
+	struct suspend_module_ops *this_module;
+	
+	list_for_each_entry(this_module, &suspend_modules, module_list)
+		module_put(this_module->module);
 }
 

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Suspend2][ 11/11] [Suspend2] Header file for Suspend2 modules.
  2006-06-26 16:53 [Suspend2][ 00/11 Module support Nigel Cunningham
                   ` (9 preceding siblings ...)
  2006-06-26 16:53 ` [Suspend2][ 10/11] [Suspend2] Get and put references to Suspend2 modules Nigel Cunningham
@ 2006-06-26 16:53 ` Nigel Cunningham
  2006-06-26 21:15 ` [Suspend2][ 00/11 Module support Rafael J. Wysocki
  11 siblings, 0 replies; 13+ messages in thread
From: Nigel Cunningham @ 2006-06-26 16:53 UTC (permalink / raw)
  To: linux-kernel

Header file, defining structures, enums, lists and routines related to
Suspend2 modules.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

 kernel/power/modules.h |  160 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 160 insertions(+), 0 deletions(-)

diff --git a/kernel/power/modules.h b/kernel/power/modules.h
new file mode 100644
index 0000000..f04edb6
--- /dev/null
+++ b/kernel/power/modules.h
@@ -0,0 +1,160 @@
+/*
+ * kernel/power/modules.h
+ *
+ * Copyright (C) 2004-2006 Nigel Cunningham <nigel@suspend2.net>
+ *
+ * This file is released under the GPLv2.
+ *
+ * It contains declarations for modules. Modules are additions to
+ * suspend2 that provide facilities such as image compression or
+ * encryption, backends for storage of the image and user interfaces.
+ *
+ */
+
+#ifndef SUSPEND_MODULES_H
+#define SUSPEND_MODULES_H
+
+/* This is the maximum size we store in the image header for a module name */
+#define SUSPEND_MAX_MODULE_NAME_LENGTH 30
+
+/* Per-module metadata */
+struct suspend_module_header {
+	char name[SUSPEND_MAX_MODULE_NAME_LENGTH];
+	int disabled;
+	int type;
+	int index;
+	int data_length;
+	unsigned long signature;
+};
+
+extern int suspend_num_modules, suspend_num_writers;
+
+enum {
+	FILTER_MODULE,
+	WRITER_MODULE,
+	MISC_MODULE /* Block writer, eg. */
+};
+
+enum {
+	SUSPEND_ASYNC,
+	SUSPEND_SYNC
+};
+
+struct suspend_module_ops {
+	/* Functions common to all modules */
+	int type;
+	char *name;
+	struct module *module;
+	int disabled;
+	struct list_head module_list;
+
+	/* List of filters or writers */
+	struct list_head list, type_list;
+
+	/*
+	 * Requirements for memory and storage in
+	 * the image header..
+	 */
+	unsigned long (*memory_needed) (void);
+	unsigned long (*storage_needed) (void);
+
+	unsigned long header_requested, header_used;
+	
+	/* 
+	 * Debug info
+	 */
+	int (*print_debug_info) (char *buffer, int size);
+	int (*save_config_info) (char *buffer);
+	void (*load_config_info) (char *buffer, int len);
+
+	/* 
+	 * Initialise & cleanup - general routines called
+	 * at the start and end of a cycle.
+	 */
+	int (*initialise) (int starting_cycle);
+	void (*cleanup) (int finishing_cycle);
+
+	/* 
+	 * Calls for allocating storage (writers only).
+	 *
+	 * Header space is allocated separately. Note that allocation
+	 * of space for the header might result in allocated space 
+	 * being stolen from the main pool if there is no unallocated
+	 * space. We have to be able to allocate enough space for
+	 * the header. We can eat memory to ensure there is enough
+	 * for the main pool.
+	 */
+
+	int (*storage_available) (void);
+	int (*allocate_header_space) (int space_requested);
+	int (*allocate_storage) (int space_requested);
+	int (*storage_allocated) (void);
+	int (*release_storage) (void);
+	
+	/*
+	 * Routines used in image I/O.
+	 */
+	int (*rw_init) (int rw, int stream_number);
+	int (*rw_cleanup) (int rw);
+	int (*write_chunk) (struct page *buffer_page);
+	int (*read_chunk) (struct page *buffer_page, int sync);
+
+	/* Reset module if image exists but reading aborted */
+	void (*noresume_reset) (void);
+
+	/* Read and write the metadata */	
+	int (*write_header_init) (void);
+	int (*write_header_cleanup) (void);
+
+	int (*read_header_init) (void);
+	int (*read_header_cleanup) (void);
+
+	int (*rw_header_chunk) (int rw, struct suspend_module_ops *owner,
+			char *buffer_start, int buffer_size);
+	
+	/* Attempt to parse an image location */
+	int (*parse_sig_location) (char *buffer, int only_writer);
+
+	/* Determine whether image exists that we can restore */
+	int (*image_exists) (void);
+	
+	/* Mark the image as having tried to resume */
+	void (*mark_resume_attempted) (void);
+
+	/* Destroy image if one exists */
+	int (*invalidate_image) (void);
+	
+};
+
+extern struct suspend_module_ops *suspend_active_writer;
+extern struct list_head suspend_filters, suspend_writers, suspend_modules;
+
+extern void suspend_prepare_console_modules(void);
+extern void suspend_cleanup_console_modules(void);
+
+extern struct suspend_module_ops *suspend_find_module_given_name(char *name),
+	*suspend_get_next_filter(struct suspend_module_ops *);
+
+extern int suspend_register_module(struct suspend_module_ops *module);
+extern void suspend_move_module_tail(struct suspend_module_ops *module);
+
+extern unsigned long suspend_header_storage_for_modules(void);
+extern unsigned long suspend_memory_for_modules(void);
+
+extern int suspend_print_module_debug_info(char *buffer, int buffer_size);
+extern int suspend_register_module(struct suspend_module_ops *module);
+extern void suspend_unregister_module(struct suspend_module_ops *module);
+
+extern int suspend_initialise_modules(int starting_cycle);
+extern void suspend_cleanup_modules(int finishing_cycle);
+
+int suspend_get_modules(void);
+void suspend_put_modules(void);
+
+static inline void suspend_initialise_module_lists(void) {
+	INIT_LIST_HEAD(&suspend_filters);
+	INIT_LIST_HEAD(&suspend_writers);
+	INIT_LIST_HEAD(&suspend_modules);
+}
+
+#endif

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Suspend2][ 00/11 Module support.
  2006-06-26 16:53 [Suspend2][ 00/11 Module support Nigel Cunningham
                   ` (10 preceding siblings ...)
  2006-06-26 16:53 ` [Suspend2][ 11/11] [Suspend2] Header file for " Nigel Cunningham
@ 2006-06-26 21:15 ` Rafael J. Wysocki
  11 siblings, 0 replies; 13+ messages in thread
From: Rafael J. Wysocki @ 2006-06-26 21:15 UTC (permalink / raw)
  To: Nigel Cunningham; +Cc: linux-kernel

On Monday 26 June 2006 18:53, Nigel Cunningham wrote:
> 
> Add utility routines for registering and iterating over modules
> that Suspend2 uses. A suspend2 module is a distinct part of the
> code - the user interface support, storage manager support,
> swapwriter, filewriter and low-level I/O code are all treated
> as separate modules.

Could you please put all of the changes in kernel/power/modules.c into one
patch?  It's quite difficult to review them now, at least for me.

Greetings,
Rafael

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2006-06-26 21:14 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-26 16:53 [Suspend2][ 00/11 Module support Nigel Cunningham
2006-06-26 16:53 ` [Suspend2][ 01/11] [Suspend2] Modules.c header Nigel Cunningham
2006-06-26 16:53 ` [Suspend2][ 02/11] [Suspend2] Get header storage needed for module data Nigel Cunningham
2006-06-26 16:53 ` [Suspend2][ 03/11] [Suspend2] Get memory needed for Suspend2 modules Nigel Cunningham
2006-06-26 16:53 ` [Suspend2][ 04/11] [Suspend2] Find a suspend2 module given its name Nigel Cunningham
2006-06-26 16:53 ` [Suspend2][ 05/11] [Suspend2] Get debugging info from modules Nigel Cunningham
2006-06-26 16:53 ` [Suspend2][ 06/11] [Suspend2] Register and unregister suspend2 modules Nigel Cunningham
2006-06-26 16:53 ` [Suspend2][ 07/11] [Suspend2] Move a suspend2 module to the tail of its list Nigel Cunningham
2006-06-26 16:53 ` [Suspend2][ 08/11] [Suspend2] Initialise and cleanup routines for suspend2 modules Nigel Cunningham
2006-06-26 16:53 ` [Suspend2][ 09/11] [Suspend2] Get next suspend2 module in the pipeline Nigel Cunningham
2006-06-26 16:53 ` [Suspend2][ 10/11] [Suspend2] Get and put references to Suspend2 modules Nigel Cunningham
2006-06-26 16:53 ` [Suspend2][ 11/11] [Suspend2] Header file for " Nigel Cunningham
2006-06-26 21:15 ` [Suspend2][ 00/11 Module support Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®