From: Nigel Cunningham <nigel@suspend2.net>
To: linux-kernel@vger.kernel.org
Subject: [Suspend2][ 05/13] [Suspend2] Compression write routines.
Date: Tue, 27 Jun 2006 14:37:34 +1000 [thread overview]
Message-ID: <20060627043732.14320.33665.stgit@nigel.suspend2.net> (raw)
In-Reply-To: <20060627043716.14320.30977.stgit@nigel.suspend2.net>
Add routines used in compressing pages and passing them to the next module.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/compression.c | 87 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 87 insertions(+), 0 deletions(-)
diff --git a/kernel/power/compression.c b/kernel/power/compression.c
index 44d46be..db3bca3 100644
--- a/kernel/power/compression.c
+++ b/kernel/power/compression.c
@@ -188,3 +188,90 @@ static int suspend_compress_rw_init(int
return 0;
}
+/*
+ * suspend_compress_write()
+ * @u8*: Output buffer to be written.
+ * @unsigned int: Length of buffer.
+ *
+ * Helper function for write_chunk. Write the compressed data.
+ * Return: Int. Result to be passed back to caller.
+ */
+static int suspend_compress_write (u8 *buffer, unsigned int len)
+{
+ int ret;
+
+ bytes_out += len;
+
+ while (len + bufofs > PAGE_SIZE) {
+ unsigned int chunk = PAGE_SIZE - bufofs;
+ memcpy (local_buffer + bufofs, buffer, chunk);
+ buffer += chunk;
+ len -= chunk;
+ bufofs = 0;
+ if ((ret = next_driver->write_chunk(virt_to_page(local_buffer))) < 0)
+ return ret;
+ }
+ memcpy (local_buffer + bufofs, buffer, len);
+ bufofs += len;
+ return 0;
+}
+
+/*
+ * suspend_compress_write_chunk()
+ *
+ * Compress a page of data, buffering output and passing on filled
+ * pages to the next module in the pipeline.
+ *
+ * Buffer_page: Pointer to a buffer of size PAGE_SIZE, containing
+ * data to be compressed.
+ *
+ * Returns: 0 on success. Otherwise the error is that returned by later
+ * modules, -ECHILD if we have a broken pipeline or -EIO if
+ * zlib errs.
+ */
+static int suspend_compress_write_chunk(struct page *buffer_page)
+{
+ int ret;
+ unsigned int len;
+ u16 len_written;
+ char *buffer_start;
+
+ if (!suspend_compressor_transform)
+ return next_driver->write_chunk(buffer_page);
+
+ buffer_start = kmap(buffer_page);
+
+ bytes_in += PAGE_SIZE;
+
+ len = PAGE_SIZE;
+
+ ret = crypto_comp_compress(suspend_compressor_transform,
+ buffer_start, PAGE_SIZE,
+ page_buffer, &len);
+
+ if (ret) {
+ printk("Compression failed.\n");
+ goto failure;
+ }
+
+ len_written = (u16) len;
+
+ if ((ret = suspend_compress_write((u8 *)&len_written, 2)) >= 0) {
+ if ((ret = suspend_compress_write((u8 *) &position, sizeof(position))))
+ return -EIO;
+ if (len < PAGE_SIZE) { /* some compression */
+ position += len;
+ ret = suspend_compress_write(page_buffer, len);
+ } else {
+ ret = suspend_compress_write(buffer_start, PAGE_SIZE);
+ position += PAGE_SIZE;
+ }
+ }
+ position += 2 + sizeof(int);
+
+
+failure:
+ kunmap(buffer_page);
+ return ret;
+}
+
--
Nigel Cunningham nigel at suspend2 dot net
next prev parent reply other threads:[~2006-06-27 5:14 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-06-27 4:37 [Suspend2][ 00/13] Compression support Nigel Cunningham
2006-06-27 4:37 ` [Suspend2][ 01/13] [Suspend2] Compression File Header Nigel Cunningham
2006-06-27 4:37 ` [Suspend2][ 02/13] [Suspend2] Allocate compression buffers Nigel Cunningham
2006-06-27 4:37 ` [Suspend2][ 03/13] [Suspend2] Compression cryptoapi initialisation and cleanup Nigel Cunningham
2006-06-27 4:37 ` [Suspend2][ 04/13] [Suspend2] Compression initialise & cleanup routines Nigel Cunningham
2006-06-27 4:37 ` Nigel Cunningham [this message]
2006-06-27 4:37 ` [Suspend2][ 06/13] [Suspend2] Compression read routines Nigel Cunningham
2006-06-27 4:37 ` [Suspend2][ 07/13] [Suspend2] Compression debug stats Nigel Cunningham
2006-06-27 4:37 ` [Suspend2][ 08/13] [Suspend2] Compression memory and storage usage routines Nigel Cunningham
2006-06-27 4:37 ` [Suspend2][ 09/13] [Suspend2] Serialisation of compressor configuration in image header Nigel Cunningham
2006-06-27 4:37 ` [Suspend2][ 10/13] [Suspend2] Get expected compression ratio Nigel Cunningham
2006-06-27 4:37 ` [Suspend2][ 11/13] [Suspend2] Compression proc entry data Nigel Cunningham
2006-06-27 4:37 ` [Suspend2][ 12/13] [Suspend2] Compression operations structure Nigel Cunningham
2006-06-27 4:38 ` [Suspend2][ 13/13] [Suspend2] Compression (un)load routines Nigel Cunningham
2006-06-27 13:59 ` [Suspend2][ 00/13] Compression support Pavel Machek
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=20060627043732.14320.33665.stgit@nigel.suspend2.net \
--to=nigel@suspend2.net \
--cc=linux-kernel@vger.kernel.org \
/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
Powered by JetHome