lkml.org 
[lkml]   [2017]   [Feb]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v5 3/5] pstore: support multiple pmsg instances
Date
From: Hiraku Toyooka <hiraku.toyooka.gu@hitachi.com>

This enables pmsg to deal with multiple instances. One possible
use is content priority control on limited persistent store space. By
using different buffers, we can prevent important messages from being
overwritten by less important messages.

When pstore backend module specifies the number of instances (num_pmsg)
in pstore_info, multiple /dev/pmsg[ID] appear. (ID is an integer
starting at 0. It corresponds to minor number of the each char device.)
Writes to each /dev/pmsg[ID] are isolated each other. After reboot, the
contents are available in /sys/fs/pstore/pmsg-[backend]-[ID].

Signed-off-by: Hiraku Toyooka <hiraku.toyooka.gu@hitachi.com>
Signed-off-by: Nobuhiro Iwamatsu <nobuhiro.iwamatsu.kw@hitachi.com>
Cc: Anton Vorontsov <anton@enomsg.org>
Cc: Colin Cross <ccross@android.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Mark Salyzyn <salyzyn@android.com>
Cc: Seiji Aguchi <seiji.aguchi.tr@hitachi.com>
Cc: Tony Luck <tony.luck@intel.com>

V5:
- Fix comment.
- Fix initialization of num_pmsg.

V4:
- Rebase.

V3:
- rebase.
- merged device_create().
---
fs/pstore/pmsg.c | 23 ++++++++++++++++-------
fs/pstore/ram.c | 2 ++
include/linux/pstore.h | 1 +
3 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/fs/pstore/pmsg.c b/fs/pstore/pmsg.c
index 78f6176c020f..699a24763adb 100644
--- a/fs/pstore/pmsg.c
+++ b/fs/pstore/pmsg.c
@@ -34,7 +34,8 @@ static ssize_t write_pmsg(struct file *file, const char __user *buf,
return -EFAULT;

mutex_lock(&pmsg_lock);
- ret = psinfo->write_buf_user(PSTORE_TYPE_PMSG, 0, &id, 0, buf, 0, count,
+ ret = psinfo->write_buf_user(PSTORE_TYPE_PMSG, 0, &id,
+ iminor(file->f_inode), buf, 0, count,
psinfo);
mutex_unlock(&pmsg_lock);
return ret ? ret : count;
@@ -61,7 +62,7 @@ static char *pmsg_devnode(struct device *dev, umode_t *mode)

void pstore_register_pmsg(void)
{
- struct device *pmsg_device;
+ int i;

pmsg_major = register_chrdev(0, PMSG_NAME, &pmsg_fops);
if (pmsg_major < 0) {
@@ -76,15 +77,23 @@ void pstore_register_pmsg(void)
}
pmsg_class->devnode = pmsg_devnode;

- pmsg_device = device_create(pmsg_class, NULL, MKDEV(pmsg_major, 0),
- NULL, "%s%d", PMSG_NAME, 0);
- if (IS_ERR(pmsg_device)) {
- pr_err("failed to create device\n");
- goto err_device;
+ /* allocate each pmsg device */
+ for (i = 0; i < psinfo->num_pmsg; i++) {
+ struct device *pmsg_device;
+
+ pmsg_device = device_create(pmsg_class, NULL,
+ MKDEV(pmsg_major, i), NULL, "%s%d",
+ PMSG_NAME, i);
+ if (IS_ERR(pmsg_device)) {
+ pr_err("failed to create device\n");
+ goto err_device;
+ }
}
return;

err_device:
+ for (i--; i >= 0; i--)
+ device_destroy(pmsg_class, MKDEV(pmsg_major, i));
class_destroy(pmsg_class);
err_class:
unregister_chrdev(pmsg_major, PMSG_NAME);
diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
index 48cfeef42cb6..c2825bb08b3d 100644
--- a/fs/pstore/ram.c
+++ b/fs/pstore/ram.c
@@ -816,6 +816,8 @@ static int ramoops_probe(struct platform_device *pdev)
err = -ENOMEM;
goto fail_clear;
}
+ /* In order to make sure to use one, set 1. */
+ cxt->pstore.num_pmsg = 1;
spin_lock_init(&cxt->pstore.buf_lock);

cxt->pstore.flags = PSTORE_FLAGS_DMESG;
diff --git a/include/linux/pstore.h b/include/linux/pstore.h
index 0da29cae009b..7a5db4833b8a 100644
--- a/include/linux/pstore.h
+++ b/include/linux/pstore.h
@@ -55,6 +55,7 @@ struct pstore_info {
size_t bufsize;
struct mutex read_mutex; /* serialize open/read/close */
int flags;
+ unsigned int num_pmsg;
int (*open)(struct pstore_info *psi);
int (*close)(struct pstore_info *psi);
ssize_t (*read)(u64 *id, enum pstore_type_id *type,
--
2.11.0
\
 
 \ /
  Last update: 2017-02-27 02:55    [W:0.054 / U:2.696 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site