mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Irina Tirdea <irina.tirdea@intel.com>
To: Anton Vorontsov <cbouatmailru@gmail.com>,
	Colin Cross <ccross@android.com>,
	Kees Cook <keescook@chromium.org>,
	Tony Luck <tony.luck@intel.com>, Chris Ball <cjb@laptop.org>
Cc: linux-kernel@vger.kernel.org,
	Adrian Hunter <adrian.hunter@intel.com>,
	Octavian Purdila <octavian.purdila@intel.com>,
	Irina Tirdea <irina.tirdea@intel.com>
Subject: [PATCH 01/26] pstore: allow for big files
Date: Tue, 23 Oct 2012 16:47:59 +0300	[thread overview]
Message-ID: <1351000104-13015-2-git-send-email-irina.tirdea@intel.com> (raw)
In-Reply-To: <1351000104-13015-1-git-send-email-irina.tirdea@intel.com>

From: Adrian Hunter <adrian.hunter@intel.com>

pstore reads all files into memory at mount time. To allow for back ends
that will store arbitrarily large files, enhance pstore also to be able
to read from the back end as needed.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
---
 drivers/acpi/apei/erst.c |   16 +++++++++-------
 fs/pstore/inode.c        |   26 ++++++++++++++++++++------
 fs/pstore/internal.h     |    5 +++--
 fs/pstore/platform.c     |   11 +++++++----
 fs/pstore/ram.c          |   15 +++++++--------
 include/linux/pstore.h   |    7 +++++--
 6 files changed, 51 insertions(+), 29 deletions(-)

diff --git a/drivers/acpi/apei/erst.c b/drivers/acpi/apei/erst.c
index e4d9d24..f70ba37 100644
--- a/drivers/acpi/apei/erst.c
+++ b/drivers/acpi/apei/erst.c
@@ -931,9 +931,9 @@ static int erst_check_table(struct acpi_table_erst *erst_tab)
 
 static int erst_open_pstore(struct pstore_info *psi);
 static int erst_close_pstore(struct pstore_info *psi);
-static ssize_t erst_reader(u64 *id, enum pstore_type_id *type,
-			   struct timespec *time, char **buf,
-			   struct pstore_info *psi);
+static int erst_reader(u64 *id, enum pstore_type_id *type,
+		       struct timespec *time, char **buf, loff_t *size,
+		       struct pstore_info *psi);
 static int erst_writer(enum pstore_type_id type, enum kmsg_dump_reason reason,
 		       u64 *id, unsigned int part,
 		       size_t size, struct pstore_info *psi);
@@ -987,9 +987,9 @@ static int erst_close_pstore(struct pstore_info *psi)
 	return 0;
 }
 
-static ssize_t erst_reader(u64 *id, enum pstore_type_id *type,
-			   struct timespec *time, char **buf,
-			   struct pstore_info *psi)
+static int erst_reader(u64 *id, enum pstore_type_id *type,
+		       struct timespec *time, char **buf, loff_t *size,
+		       struct pstore_info *psi)
 {
 	int rc;
 	ssize_t len = 0;
@@ -1051,7 +1051,9 @@ skip:
 
 out:
 	kfree(rcd);
-	return (rc < 0) ? rc : (len - sizeof(*rcd));
+	if (!rc)
+		*size = len - sizeof(*rcd);
+	return rc;
 }
 
 static int erst_writer(enum pstore_type_id type, enum kmsg_dump_reason reason,
diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c
index 4ab572e..ff0970f 100644
--- a/fs/pstore/inode.c
+++ b/fs/pstore/inode.c
@@ -49,7 +49,8 @@ struct pstore_private {
 	struct pstore_info *psi;
 	enum pstore_type_id type;
 	u64	id;
-	ssize_t	size;
+	loff_t	size;
+	bool	big;
 	char	data[];
 };
 
@@ -65,12 +66,13 @@ static void *pstore_ftrace_seq_start(struct seq_file *s, loff_t *pos)
 {
 	struct pstore_private *ps = s->private;
 	struct pstore_ftrace_seq_data *data;
+	loff_t size = ps->size;
 
 	data = kzalloc(sizeof(*data), GFP_KERNEL);
 	if (!data)
 		return NULL;
 
-	data->off = ps->size % REC_SIZE;
+	data->off = do_div(size,  REC_SIZE);
 	data->off += *pos * REC_SIZE;
 	if (data->off + REC_SIZE > ps->size) {
 		kfree(data);
@@ -127,6 +129,12 @@ static ssize_t pstore_file_read(struct file *file, char __user *userbuf,
 
 	if (ps->type == PSTORE_TYPE_FTRACE)
 		return seq_read(file, userbuf, count, ppos);
+	if (ps->big) {
+		if (ps->psi->file_read)
+			return ps->psi->file_read(ps->id, ps->type, userbuf,
+						count, ppos, ps->psi);
+		return -EFBIG;
+	}
 	return simple_read_from_buffer(userbuf, count, ppos, ps->data, ps->size);
 }
 
@@ -271,8 +279,8 @@ int pstore_is_mounted(void)
  * Set the mtime & ctime to the date that this record was originally stored.
  */
 int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id,
-		  char *data, size_t size, struct timespec time,
-		  struct pstore_info *psi)
+		  char *data, loff_t size, struct timespec time,
+		  struct pstore_info *psi, bool big)
 {
 	struct dentry		*root = pstore_sb->s_root;
 	struct dentry		*dentry;
@@ -281,6 +289,7 @@ int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id,
 	char			name[PSTORE_NAMELEN];
 	struct pstore_private	*private, *pos;
 	unsigned long		flags;
+	size_t			inline_size;
 
 	spin_lock_irqsave(&allpstore_lock, flags);
 	list_for_each_entry(pos, &allpstore, list) {
@@ -301,12 +310,17 @@ int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id,
 		goto fail;
 	inode->i_mode = S_IFREG | 0444;
 	inode->i_fop = &pstore_file_operations;
-	private = kmalloc(sizeof *private + size, GFP_KERNEL);
+	if (big)
+		inline_size = 0;
+	else
+		inline_size = size;
+	private = kmalloc(sizeof(*private) + inline_size, GFP_KERNEL);
 	if (!private)
 		goto fail_alloc;
 	private->type = type;
 	private->id = id;
 	private->psi = psi;
+	private->big = big;
 
 	switch (type) {
 	case PSTORE_TYPE_DMESG:
@@ -336,7 +350,7 @@ int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id,
 	if (IS_ERR(dentry))
 		goto fail_lockedalloc;
 
-	memcpy(private->data, data, size);
+	memcpy(private->data, data, inline_size);
 	inode->i_size = private->size = size;
 
 	inode->i_private = private;
diff --git a/fs/pstore/internal.h b/fs/pstore/internal.h
index 4847f58..f840159 100644
--- a/fs/pstore/internal.h
+++ b/fs/pstore/internal.h
@@ -50,8 +50,9 @@ extern struct pstore_info *psinfo;
 extern void	pstore_set_kmsg_bytes(int);
 extern void	pstore_get_records(int);
 extern int	pstore_mkfile(enum pstore_type_id, char *psname, u64 id,
-			      char *data, size_t size,
-			      struct timespec time, struct pstore_info *psi);
+			      char *data, loff_t size,
+			      struct timespec time, struct pstore_info *psi,
+			      bool big);
 extern int	pstore_is_mounted(void);
 
 #endif
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index a40da07..108bd69 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -264,7 +264,7 @@ void pstore_get_records(int quiet)
 {
 	struct pstore_info *psi = psinfo;
 	char			*buf = NULL;
-	ssize_t			size;
+	loff_t			size;
 	u64			id;
 	enum pstore_type_id	type;
 	struct timespec		time;
@@ -277,9 +277,12 @@ void pstore_get_records(int quiet)
 	if (psi->open && psi->open(psi))
 		goto out;
 
-	while ((size = psi->read(&id, &type, &time, &buf, psi)) > 0) {
-		rc = pstore_mkfile(type, psi->name, id, buf, (size_t)size,
-				  time, psi);
+	while (1) {
+		rc = psi->read(&id, &type, &time, &buf, &size, psi);
+		if (rc && rc != -EFBIG)
+			break;
+		rc = pstore_mkfile(type, psi->name, id, buf, size,
+				  time, psi, rc == -EFBIG);
 		kfree(buf);
 		buf = NULL;
 		if (rc && (rc != -EEXIST || !quiet))
diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
index 1a4f6da..dd47a87 100644
--- a/fs/pstore/ram.c
+++ b/fs/pstore/ram.c
@@ -131,12 +131,11 @@ ramoops_get_next_prz(struct persistent_ram_zone *przs[], uint *c, uint max,
 	return prz;
 }
 
-static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type,
+static int ramoops_pstore_read(u64 *id, enum pstore_type_id *type,
 				   struct timespec *time,
-				   char **buf,
+				   char **buf, loff_t *size,
 				   struct pstore_info *psi)
 {
-	ssize_t size;
 	struct ramoops_context *cxt = psi->data;
 	struct persistent_ram_zone *prz;
 
@@ -150,19 +149,19 @@ static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type,
 		prz = ramoops_get_next_prz(&cxt->fprz, &cxt->ftrace_read_cnt,
 					   1, id, type, PSTORE_TYPE_FTRACE, 0);
 	if (!prz)
-		return 0;
+		return -EINVAL;
 
 	/* TODO(kees): Bogus time for the moment. */
 	time->tv_sec = 0;
 	time->tv_nsec = 0;
 
-	size = persistent_ram_old_size(prz);
-	*buf = kmalloc(size, GFP_KERNEL);
+	*size = persistent_ram_old_size(prz);
+	*buf = kmalloc(*size, GFP_KERNEL);
 	if (*buf == NULL)
 		return -ENOMEM;
-	memcpy(*buf, persistent_ram_old(prz), size);
+	memcpy(*buf, persistent_ram_old(prz), *size);
 
-	return size;
+	return 0;
 }
 
 static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz)
diff --git a/include/linux/pstore.h b/include/linux/pstore.h
index ee3034a..3a293ff 100644
--- a/include/linux/pstore.h
+++ b/include/linux/pstore.h
@@ -49,8 +49,11 @@ struct pstore_info {
 	struct mutex	read_mutex;	/* serialize open/read/close */
 	int		(*open)(struct pstore_info *psi);
 	int		(*close)(struct pstore_info *psi);
-	ssize_t		(*read)(u64 *id, enum pstore_type_id *type,
-			struct timespec *time, char **buf,
+	int		(*read)(u64 *id, enum pstore_type_id *type,
+			struct timespec *time, char **buf, loff_t *size,
+			struct pstore_info *psi);
+	ssize_t		(*file_read)(u64 id, enum pstore_type_id type,
+			char __user *userbuf, size_t count, loff_t *ppos,
 			struct pstore_info *psi);
 	int		(*write)(enum pstore_type_id type,
 			enum kmsg_dump_reason reason, u64 *id,
-- 
1.7.9.5


  reply	other threads:[~2012-10-23 13:42 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-23 13:47 [PATCH 00/26] pstore, mmc: add mmc as backend for pstore Irina Tirdea
2012-10-23 13:47 ` Irina Tirdea [this message]
2012-10-23 16:48   ` [PATCH 01/26] pstore: allow for big files Kees Cook
2012-10-25  8:54     ` Tatulea, Dragos
2012-10-23 13:48 ` [PATCH 02/26] pstore: add flags Irina Tirdea
2012-10-23 16:54   ` Kees Cook
2012-10-23 16:57     ` Luck, Tony
2012-10-25 11:25       ` Tatulea, Dragos
2012-10-23 13:48 ` [PATCH 03/26] pstore: add flush Irina Tirdea
2012-10-23 16:50   ` Kees Cook
2012-10-23 13:48 ` [PATCH 04/26] blkoops: add a block device oops / panic logger Irina Tirdea
2012-10-23 13:48 ` [PATCH 05/26] block: add panic write Irina Tirdea
2012-10-23 13:48 ` [PATCH 06/26] mmc: block: add panic write support Irina Tirdea
2012-10-23 13:48 ` [PATCH 07/26] mmc: panic write: bypass host claiming Irina Tirdea
2012-10-23 13:48 ` [PATCH 08/26] mmc: panic write: bypass request completion Irina Tirdea
2012-10-23 13:48 ` [PATCH 09/26] mmc: panic write: suppress host not claimed warnings Irina Tirdea
2012-10-23 13:48 ` [PATCH 10/26] mmc: panic write: do not msleep Irina Tirdea
2012-10-23 13:48 ` [PATCH 11/26] mmc: panic write: bypass clock gating Irina Tirdea
2012-10-23 13:48 ` [PATCH 12/26] mmc: panic write: bypass regulators Irina Tirdea
2012-10-23 13:48 ` [PATCH 13/26] mmc: panic write: trap non panic tasks Irina Tirdea
2012-10-23 13:48 ` [PATCH 14/26] mmc: panic write: bypass bus ref locking Irina Tirdea
2012-10-23 13:48 ` [PATCH 15/26] mmc: sdhci: panic write: bypass spin lock Irina Tirdea
2012-10-23 13:48 ` [PATCH 16/26] mmc: sdhci: panic write: no sleeping Irina Tirdea
2012-10-23 13:48 ` [PATCH 17/26] mmc: sdhci: panic write: call tasklets inline Irina Tirdea
2012-10-23 13:48 ` [PATCH 18/26] mmc: sdhci: panic write: no timeout timer Irina Tirdea
2012-10-23 13:48 ` [PATCH 19/26] mmc: sdhci: panic write: no runtime pm Irina Tirdea
2012-10-23 13:48 ` [PATCH 20/26] mmc: sdhci: panic write: no tuning Irina Tirdea
2012-10-23 13:48 ` [PATCH 21/26] mmc: sdhci: panic write: poll interrupts Irina Tirdea
2012-10-23 13:48 ` [PATCH 22/26] mmc: sdhci: panic write: no dma mapping Irina Tirdea
2012-10-23 13:48 ` [PATCH 23/26] mmc: sdhci: panic write: resume suspended host Irina Tirdea
2012-10-23 13:48 ` [PATCH 24/26] mmc: sdhci: panic write: abort request in progress Irina Tirdea
2012-10-23 13:48 ` [PATCH 25/26] mmc: sdhci: panic write: trap nonpanic tasks Irina Tirdea
2012-10-23 13:48 ` [PATCH 26/26] mmc: sdhci-pci: add panic write support Irina Tirdea
2012-10-29 20:28 ` [PATCH 00/26] pstore, mmc: add mmc as backend for pstore Kirill A. Shutemov
2012-10-29 20:50   ` Chris Ball

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=1351000104-13015-2-git-send-email-irina.tirdea@intel.com \
    --to=irina.tirdea@intel.com \
    --cc=adrian.hunter@intel.com \
    --cc=cbouatmailru@gmail.com \
    --cc=ccross@android.com \
    --cc=cjb@laptop.org \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=octavian.purdila@intel.com \
    --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

all inboxes | Powered by JetHome®