All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nobuhiro Iwamatsu <nobuhiro.iwamatsu.kw@hitachi.com>
To: Anton Vorontsov <anton@enomsg.org>,
	Colin Cross <ccross@android.com>,
	Kees Cook <keescook@chromium.org>,
	Tony Luck <tony.luck@intel.com>
Cc: linux-kernel@vger.kernel.org,
	cti.systems-productivity-manager.ts@hitachi.com,
	Hiraku Toyooka <hiraku.toyooka.gu@hitachi.com>,
	Nobuhiro Iwamatsu <nobuhiro.iwamatsu.kw@hitachi.com>,
	Mark Salyzyn <salyzyn@android.com>,
	Seiji Aguchi <seiji.aguchi.tr@hitachi.com>
Subject: [PATCH v3 6/8] pstore: support multiple pmsg instances
Date: Tue, 18 Oct 2016 16:13:32 +0900	[thread overview]
Message-ID: <1476774814-6840-7-git-send-email-nobuhiro.iwamatsu.kw@hitachi.com> (raw)
In-Reply-To: <1476774814-6840-1-git-send-email-nobuhiro.iwamatsu.kw@hitachi.com>

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>

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

diff --git a/fs/pstore/pmsg.c b/fs/pstore/pmsg.c
index 78f6176..5da5cba 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 additional /dev/pmsg[ID] */
+	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/include/linux/pstore.h b/include/linux/pstore.h
index 92013cc..a606656 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.9.3

  parent reply	other threads:[~2016-10-18  7:15 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-18  7:13 [PATCH v3 0/8] pstore: ramoops: support multiple pmsg instances Nobuhiro Iwamatsu
2016-10-18  7:13 ` [PATCH v3 1/8] pstore: Replace four kzalloc() calls by kcalloc() in ramoops_init_przs() Nobuhiro Iwamatsu
2016-10-18  7:13 ` [PATCH v3 2/8] pstore: Change parameter of ramoops_free_przs() Nobuhiro Iwamatsu
2016-10-18  7:13 ` [PATCH v3 3/8] ramoops: Add __ramoops_init_prz() as generic function Nobuhiro Iwamatsu
2016-10-18  7:13 ` [PATCH v3 4/8] pstore: Rename 'przs' to 'dprzs' in struct ramoops_context Nobuhiro Iwamatsu
2016-10-18  7:13 ` [PATCH v3 5/8] ramoops: Rename ramoops_init_prz() to ramoops_init_dprzs() Nobuhiro Iwamatsu
2016-10-18  7:13 ` Nobuhiro Iwamatsu [this message]
2016-10-18  7:13 ` [PATCH v3 7/8] ramoops: support multiple pmsg instances Nobuhiro Iwamatsu
2016-10-18  7:13 ` [PATCH v3 8/8] selftests/pstore: add testcases for " Nobuhiro Iwamatsu
2016-11-11 22:24 ` [PATCH v3 0/8] pstore: ramoops: support " Kees Cook
2016-12-05  1:47   ` 岩松信洋 / IWAMATSU,NOBUHIRO
2016-12-27  0:48     ` 岩松信洋 / IWAMATSU,NOBUHIRO
2017-01-04  6:20       ` Kees Cook

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=1476774814-6840-7-git-send-email-nobuhiro.iwamatsu.kw@hitachi.com \
    --to=nobuhiro.iwamatsu.kw@hitachi.com \
    --cc=anton@enomsg.org \
    --cc=ccross@android.com \
    --cc=cti.systems-productivity-manager.ts@hitachi.com \
    --cc=hiraku.toyooka.gu@hitachi.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=salyzyn@android.com \
    --cc=seiji.aguchi.tr@hitachi.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.