linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Aruna Balakrishnaiah <aruna@linux.vnet.ibm.com>
To: linuxppc-dev@ozlabs.org, paulus@samba.org,
	linux-kernel@vger.kernel.org, benh@kernel.crashing.org
Cc: jkenisto@linux.vnet.ibm.com, tony.luck@intel.com,
	mahesh@linux.vnet.ibm.com, cbouatmailru@gmail.com,
	anton@samba.org, ccross@android.com, keescook@chromium.org
Subject: [PATCH 06/11] pstore: Provide decompression support to pstore
Date: Mon, 15 Jul 2013 22:26:06 +0530	[thread overview]
Message-ID: <20130715165606.1520.76699.stgit@aruna-ThinkPad-T420> (raw)
In-Reply-To: <20130715164844.1520.27771.stgit@aruna-ThinkPad-T420>

Based on the flag 'compressed' set or not, pstore will decompress the
data returning a plain text file. If decompression fails for a particular
record it will have the compressed data in the file which can be
decompressed with 'openssl' command line tool.

Signed-off-by: Aruna Balakrishnaiah <aruna@linux.vnet.ibm.com>
---
 arch/powerpc/platforms/pseries/nvram.c |   59 -------------------------
 fs/pstore/platform.c                   |   77 ++++++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+), 60 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/nvram.c b/arch/powerpc/platforms/pseries/nvram.c
index 1ddc266..78c6f45 100644
--- a/arch/powerpc/platforms/pseries/nvram.c
+++ b/arch/powerpc/platforms/pseries/nvram.c
@@ -539,65 +539,6 @@ static int zip_oops(size_t text_len)
 }
 
 #ifdef CONFIG_PSTORE
-/* Derived from logfs_uncompress */
-int nvram_decompress(void *in, void *out, size_t inlen, size_t outlen)
-{
-	int err, ret;
-
-	ret = -EIO;
-	err = zlib_inflateInit(&stream);
-	if (err != Z_OK)
-		goto error;
-
-	stream.next_in = in;
-	stream.avail_in = inlen;
-	stream.total_in = 0;
-	stream.next_out = out;
-	stream.avail_out = outlen;
-	stream.total_out = 0;
-
-	err = zlib_inflate(&stream, Z_FINISH);
-	if (err != Z_STREAM_END)
-		goto error;
-
-	err = zlib_inflateEnd(&stream);
-	if (err != Z_OK)
-		goto error;
-
-	ret = stream.total_out;
-error:
-	return ret;
-}
-
-static int unzip_oops(char *oops_buf, char *big_buf)
-{
-	struct oops_log_info *oops_hdr = (struct oops_log_info *)oops_buf;
-	u64 timestamp = oops_hdr->timestamp;
-	char *big_oops_data = NULL;
-	char *oops_data_buf = NULL;
-	size_t big_oops_data_sz;
-	int unzipped_len;
-
-	big_oops_data = big_buf + sizeof(struct oops_log_info);
-	big_oops_data_sz = big_oops_buf_sz - sizeof(struct oops_log_info);
-	oops_data_buf = oops_buf + sizeof(struct oops_log_info);
-
-	unzipped_len = nvram_decompress(oops_data_buf, big_oops_data,
-					oops_hdr->report_length,
-					big_oops_data_sz);
-
-	if (unzipped_len < 0) {
-		pr_err("nvram: decompression failed; returned %d\n",
-								unzipped_len);
-		return -1;
-	}
-	oops_hdr = (struct oops_log_info *)big_buf;
-	oops_hdr->version = OOPS_HDR_VERSION;
-	oops_hdr->report_length = (u16) unzipped_len;
-	oops_hdr->timestamp = timestamp;
-	return 0;
-}
-
 static int nvram_pstore_open(struct pstore_info *psi)
 {
 	/* Reset the iterator to start reading partitions again */
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index b1faf25..119db58 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -198,6 +198,59 @@ static char *allocate_buf_for_compression(unsigned long big_buf_sz)
 
 	return big_buf;
 }
+
+static char *allocate_buf_for_decompression(unsigned long size)
+{
+	char *big_buf;
+
+	big_buf = kmalloc(size, GFP_KERNEL);
+	if (big_buf) {
+		stream.workspace = kmalloc(zlib_inflate_workspacesize(),
+								GFP_KERNEL);
+		if (!stream.workspace) {
+			pr_err("pstore: No memory for decompression workspace; "
+				"skipping decompression\n");
+			kfree(big_buf);
+			big_buf = NULL;
+		}
+	} else {
+		pr_err("No memory for decompressed data; "
+			"skipping decompression\n");
+		stream.workspace = NULL;
+	}
+
+	return big_buf;
+}
+
+/* Derived from logfs_uncompress */
+int pstore_decompress(void *in, void *out, size_t inlen, size_t outlen)
+{
+	int err, ret;
+
+	ret = -EIO;
+	err = zlib_inflateInit(&stream);
+	if (err != Z_OK)
+		goto error;
+
+	stream.next_in = in;
+	stream.avail_in = inlen;
+	stream.total_in = 0;
+	stream.next_out = out;
+	stream.avail_out = outlen;
+	stream.total_out = 0;
+
+	err = zlib_inflate(&stream, Z_FINISH);
+	if (err != Z_STREAM_END)
+		goto error;
+
+	err = zlib_inflateEnd(&stream);
+	if (err != Z_OK)
+		goto error;
+
+	ret = stream.total_out;
+error:
+	return ret;
+}
 /*
  * callback from kmsg_dump. (s2,l2) has the most recently
  * written bytes, older bytes are in (s1,l1). Save as much
@@ -398,12 +451,14 @@ void pstore_get_records(int quiet)
 {
 	struct pstore_info *psi = psinfo;
 	char			*buf = NULL;
-	ssize_t			size;
+	char			*big_buf = NULL;
+	ssize_t			size, big_buf_sz;
 	u64			id;
 	int			count;
 	enum pstore_type_id	type;
 	struct timespec		time;
 	int			failed = 0, rc;
+	int			unzipped_len = -1;
 	bool			compressed;
 
 	if (!psi)
@@ -415,10 +470,30 @@ void pstore_get_records(int quiet)
 
 	while ((size = psi->read(&id, &type, &count, &time, &buf, &compressed,
 				psi)) > 0) {
+		if (compressed && (type == PSTORE_TYPE_DMESG)) {
+			big_buf_sz = (psinfo->bufsize * 100) / 45;
+			big_buf = allocate_buf_for_decompression(big_buf_sz);
+
+			if (big_buf || stream.workspace)
+				unzipped_len = pstore_decompress(buf, big_buf,
+							size, big_buf_sz);
+
+			if (unzipped_len > 0) {
+				buf = big_buf;
+				size = unzipped_len;
+			} else {
+				pr_err("pstore: decompression failed;"
+					"returned %d\n", unzipped_len);
+			}
+		}
 		rc = pstore_mkfile(type, psi->name, id, count, buf,
 				  (size_t)size, time, psi);
 		kfree(buf);
+		kfree(stream.workspace);
+		kfree(big_buf);
 		buf = NULL;
+		stream.workspace = NULL;
+		big_buf = NULL;
 		if (rc && (rc != -EEXIST || !quiet))
 			failed++;
 	}

  parent reply	other threads:[~2013-07-15 16:56 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-15 16:55 [PATCH 00/11] Add compression support to pstore Aruna Balakrishnaiah
2013-07-15 16:55 ` [PATCH 01/11] powerpc/pseries: Remove (de)compression in nvram with pstore enabled Aruna Balakrishnaiah
2013-07-15 16:55 ` [PATCH 02/11] pstore: Add new argument 'compressed' in pstore write callback Aruna Balakrishnaiah
2013-07-15 16:55 ` [PATCH 03/11] pstore/Kconfig: Select ZLIB_DEFLATE and ZLIB_INFLATE when PSTORE is selected Aruna Balakrishnaiah
2013-07-15 16:55 ` [PATCH 04/11] pstore: Add compression support to pstore Aruna Balakrishnaiah
2013-07-15 16:55 ` [PATCH 05/11] pstore: Introduce new argument 'compressed' in the read callback Aruna Balakrishnaiah
2013-07-15 16:56 ` Aruna Balakrishnaiah [this message]
2013-07-15 16:56 ` [PATCH 07/11] pstore: Add file extension to pstore file if compressed Aruna Balakrishnaiah
2013-07-15 16:56 ` [PATCH 08/11] powerpc/pseries: Read and write to the 'compressed' flag of pstore Aruna Balakrishnaiah
2013-07-15 16:56 ` [PATCH 09/11] erst: " Aruna Balakrishnaiah
2013-07-15 16:56 ` [PATCH 10/11] efi-pstore: " Aruna Balakrishnaiah
2013-07-15 16:57 ` [PATCH 11/11] pstore/ram: " Aruna Balakrishnaiah
2013-08-01 10:40 ` [PATCH 00/11] Add compression support to pstore Aruna Balakrishnaiah
2013-08-01 23:42   ` Luck, Tony
2013-08-02 21:39     ` Tony Luck
2013-08-02 22:12       ` Tony Luck
2013-08-05 16:41         ` Tony Luck
2013-08-05 17:10         ` Aruna Balakrishnaiah
2013-08-05 18:22           ` Tony Luck
2013-08-05 19:41             ` Aruna Balakrishnaiah
2013-08-05 21:20               ` Tony Luck
2013-08-06 23:36                 ` Tony Luck
2013-08-07  1:58                   ` Aruna Balakrishnaiah
2013-08-07  3:25                     ` Tony Luck
2013-08-07  5:13                       ` Aruna Balakrishnaiah
2013-08-07  5:35                         ` Tony Luck
2013-08-07 17:30                           ` Tony Luck
2013-08-08  4:29                             ` Aruna Balakrishnaiah
2013-08-08  5:05                               ` Tony Luck
2013-08-07 22:22                           ` Tony Luck
2013-08-08  4:08                             ` Aruna Balakrishnaiah
2013-08-09 10:13                               ` Aruna Balakrishnaiah

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=20130715165606.1520.76699.stgit@aruna-ThinkPad-T420 \
    --to=aruna@linux.vnet.ibm.com \
    --cc=anton@samba.org \
    --cc=benh@kernel.crashing.org \
    --cc=cbouatmailru@gmail.com \
    --cc=ccross@android.com \
    --cc=jkenisto@linux.vnet.ibm.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=mahesh@linux.vnet.ibm.com \
    --cc=paulus@samba.org \
    --cc=tony.luck@intel.com \
    /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;
as well as URLs for NNTP newsgroup(s).