Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Yuanhe Shu <xiangzao@linux.alibaba.com>
To: keescook@chromium.org, tony.luck@intel.com, gpiccoli@igalia.com,
	shuah@kernel.org, corbet@lwn.net
Cc: xlpang@linux.alibaba.com, linux-kernel@vger.kernel.org,
	xiangzao@linux.alibaba.com, yixingrui@linux.alibaba.com,
	linux-doc@vger.kernel.org, linux-hardening@vger.kernel.org,
	linux-kselftest@vger.kernel.org
Subject: [PATCH v4 2/4] pstore: add a /sys/module entry for loaded backends
Date: Fri,  8 Mar 2024 11:16:54 +0800	[thread overview]
Message-ID: <20240308031656.9672-3-xiangzao@linux.alibaba.com> (raw)
In-Reply-To: <20240308031656.9672-1-xiangzao@linux.alibaba.com>

Introduce a /sys/module entry for loaded pstore backends which
provide users and testcases with a standarized interface to retrieve
information on which pstore backends are currently registered.

Signed-off-by: Yuanhe Shu <xiangzao@linux.alibaba.com>
---
 fs/pstore/inode.c    | 38 ++++++++++++++++++++++++++++++++++++++
 fs/pstore/internal.h |  1 +
 fs/pstore/platform.c |  9 ++++++++-
 3 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c
index bee71c7da995..5800fa4abfce 100644
--- a/fs/pstore/inode.c
+++ b/fs/pstore/inode.c
@@ -6,6 +6,7 @@
  */
 
 #include <linux/module.h>
+#include <linux/kobject.h>
 #include <linux/fs.h>
 #include <linux/fsnotify.h>
 #include <linux/pagemap.h>
@@ -491,6 +492,43 @@ int __init pstore_init_fs(void)
 	return err;
 }
 
+static ssize_t loaded_backend_show(struct kobject *k,
+				   struct kobj_attribute *attr, char *buf)
+{
+	struct pstore_info_list *entry;
+	char *old, *loaded_backend = NULL;
+
+	mutex_lock(&psback_lock);
+	list_for_each_entry(entry, &psback->list_entry, list)
+		if (!loaded_backend)
+			loaded_backend = kstrdup(entry->psi->name, GFP_KERNEL);
+		else {
+			old = loaded_backend;
+			loaded_backend = kasprintf(GFP_KERNEL, "%s,%s",
+						   old, entry->psi->name);
+			kfree(old);
+		}
+	mutex_unlock(&psback_lock);
+
+	return sprintf(buf, "%s\n", loaded_backend);
+}
+
+static struct kobj_attribute backend_attribute =
+	__ATTR(loaded_backend, 0444, loaded_backend_show, NULL);
+
+int __init pstore_init_entry(void)
+{
+	int err = 0;
+	struct kobject *pstore_kobj;
+
+	pstore_kobj = kset_find_obj(module_kset, "pstore");
+	if (pstore_kobj) {
+		err = sysfs_create_file(pstore_kobj, &backend_attribute.attr);
+		kobject_put(pstore_kobj);
+	}
+	return err;
+}
+
 void __exit pstore_exit_fs(void)
 {
 	unregister_filesystem(&pstore_fs_type);
diff --git a/fs/pstore/internal.h b/fs/pstore/internal.h
index 4b1c7ba27052..ffc86b04c5cc 100644
--- a/fs/pstore/internal.h
+++ b/fs/pstore/internal.h
@@ -47,6 +47,7 @@ extern void	pstore_record_init(struct pstore_record *record,
 
 /* Called during pstore init/exit. */
 int __init	pstore_init_fs(void);
+int __init	pstore_init_entry(void);
 void __exit	pstore_exit_fs(void);
 
 #endif
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index a1742b39fb88..5c10a546cdf0 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -841,7 +841,14 @@ static void pstore_timefunc(struct timer_list *unused)
 
 static int __init pstore_init(void)
 {
-	return pstore_init_fs();
+	int ret;
+
+	ret = pstore_init_fs();
+	if (ret)
+		return ret;
+
+	ret = pstore_init_entry();
+	return ret;
 }
 late_initcall(pstore_init);
 
-- 
2.39.3


  parent reply	other threads:[~2024-03-08  3:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-08  3:16 [PATCH v4 0/4] pstore: add multi-backend suuport Yuanhe Shu
2024-03-08  3:16 ` [PATCH v4 1/4] pstore: add multi-backend support Yuanhe Shu
2024-03-08  3:16 ` Yuanhe Shu [this message]
2024-03-08  3:16 ` [PATCH v4 3/4] Documentation: adjust pstore backend related document Yuanhe Shu
2024-03-08  3:16 ` [PATCH v4 4/4] tools/testing: adjust pstore backend related selftest Yuanhe Shu

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=20240308031656.9672-3-xiangzao@linux.alibaba.com \
    --to=xiangzao@linux.alibaba.com \
    --cc=corbet@lwn.net \
    --cc=gpiccoli@igalia.com \
    --cc=keescook@chromium.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=tony.luck@intel.com \
    --cc=xlpang@linux.alibaba.com \
    --cc=yixingrui@linux.alibaba.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