From patchwork Thu Sep 28 02:42:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuanhe Shu X-Patchwork-Id: 728518 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A4A9EED611 for ; Thu, 28 Sep 2023 02:43:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230064AbjI1Cnz (ORCPT ); Wed, 27 Sep 2023 22:43:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229987AbjI1Cnx (ORCPT ); Wed, 27 Sep 2023 22:43:53 -0400 Received: from out30-112.freemail.mail.aliyun.com (out30-112.freemail.mail.aliyun.com [115.124.30.112]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF40D114; Wed, 27 Sep 2023 19:43:50 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R201e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=ay29a033018046051; MF=xiangzao@linux.alibaba.com; NM=1; PH=DS; RN=12; SR=0; TI=SMTPD_---0Vt.rlII_1695869027; Received: from localhost.localdomain(mailfrom:xiangzao@linux.alibaba.com fp:SMTPD_---0Vt.rlII_1695869027) by smtp.aliyun-inc.com; Thu, 28 Sep 2023 10:43:48 +0800 From: Yuanhe Shu To: gregkh@linuxfoundation.org, jirislaby@kernel.org, keescook@chromium.org, tony.luck@intel.com, gpiccoli@igalia.com, shuah@kernel.org Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, linux-hardening@vger.kernel.org, linux-kselftest@vger.kernel.org, Yuanhe Shu , Xingrui Yi Subject: [PATCH 3/5] pstore: add subdirs for multi-backends Date: Thu, 28 Sep 2023 10:42:42 +0800 Message-Id: <20230928024244.257687-4-xiangzao@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230928024244.257687-1-xiangzao@linux.alibaba.com> References: <20230928024244.257687-1-xiangzao@linux.alibaba.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org With pstore supporting multiple backends, since different backends may enable different kinds of frontends, records in the file system are very confusing. By simply modifying the file system, subdirs are added for each backend, each dir has the same name as the corresponding backend. Signed-off-by: Xingrui Yi Signed-off-by: Yuanhe Shu --- fs/pstore/inode.c | 80 ++++++++++++++++++++++++++++++++++++------ fs/pstore/internal.h | 1 + fs/pstore/platform.c | 5 ++- include/linux/pstore.h | 2 ++ 4 files changed, 77 insertions(+), 11 deletions(-) diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c index 312e7d55b95f..0f6d888a3b06 100644 --- a/fs/pstore/inode.c +++ b/fs/pstore/inode.c @@ -288,9 +288,14 @@ static const struct super_operations pstore_ops = { .show_options = pstore_show_options, }; -static struct dentry *psinfo_lock_root(struct pstore_info *psinfo) +static struct dentry *psinfo_lock(struct pstore_info *psinfo) { - struct dentry *root; + struct dentry *dentry; + struct qstr qname; + + qname.name = psinfo->name; + qname.len = strlen(psinfo->name); + qname.hash = full_name_hash(pstore_sb->s_root, qname.name, qname.len); mutex_lock(&pstore_sb_lock); /* @@ -302,11 +307,16 @@ static struct dentry *psinfo_lock_root(struct pstore_info *psinfo) return NULL; } - root = pstore_sb->s_root; - inode_lock(d_inode(root)); + dentry = d_lookup(pstore_sb->s_root, &qname); + if (!dentry) { + mutex_unlock(&pstore_sb_lock); + return NULL; + } + + inode_lock(d_inode(dentry)); mutex_unlock(&pstore_sb_lock); - return root; + return dentry; } int pstore_put_backend_records(struct pstore_info *psi) @@ -315,7 +325,7 @@ int pstore_put_backend_records(struct pstore_info *psi) struct dentry *root; int rc = 0; - root = psinfo_lock_root(psi); + root = psinfo_lock(psi); if (!root) return 0; @@ -416,14 +426,60 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record) */ void pstore_get_records(struct pstore_info *psi, int pos, int quiet) { + struct dentry *dentry; + + dentry = psinfo_lock(psi); + if (!dentry) + return; + + pstore_get_backend_records(psi, dentry, quiet, pos); + inode_unlock(d_inode(dentry)); +} + +void pstore_mksubdir(struct pstore_info *psi) +{ + struct dentry *dentry; + struct inode *inode; struct dentry *root; + struct qstr qname; - root = psinfo_lock_root(psi); - if (!root) + if (!psi || !pstore_sb) + return; + + root = pstore_sb->s_root; + qname.name = psi->name; + qname.len = strlen(psi->name); + qname.hash = full_name_hash(root, qname.name, qname.len); + dentry = d_lookup(root, &qname); + + /* Skip if subdir is already present in the filesystem. */ + if (dentry) return; - pstore_get_backend_records(psi, root, quiet, pos); + inode_lock(d_inode(root)); + + dentry = d_alloc_name(root, psi->name); + if (!dentry) + goto fail; + + inode = pstore_get_inode(pstore_sb); + if (!inode) { + dput(dentry); + dentry = ERR_PTR(-ENOMEM); + goto fail; + } + inode->i_mode = S_IFDIR | 0750; + inode->i_op = &pstore_dir_inode_operations; + inode->i_fop = &simple_dir_operations; + + inc_nlink(inode); + inc_nlink(d_inode(root)); + + d_add(dentry, inode); + +fail: inode_unlock(d_inode(root)); + return; } static int pstore_fill_super(struct super_block *sb, void *data, int silent) @@ -456,10 +512,14 @@ static int pstore_fill_super(struct super_block *sb, void *data, int silent) mutex_unlock(&pstore_sb_lock); rcu_read_lock(); - list_for_each_entry_rcu(entry, &psback->list_entry, list) + list_for_each_entry_rcu(entry, &psback->list_entry, list) { + pstore_mksubdir(entry->psi); pstore_get_records(entry->psi, entry->index, 0); + } rcu_read_unlock(); + psback->fs_ready = true; + return 0; } diff --git a/fs/pstore/internal.h b/fs/pstore/internal.h index 7465b5baf002..20449ca940bb 100644 --- a/fs/pstore/internal.h +++ b/fs/pstore/internal.h @@ -44,6 +44,7 @@ static inline void pstore_unregister_tty(void) {} extern struct pstore_backends *psback; extern void pstore_set_kmsg_bytes(int); +extern void pstore_mksubdir(struct pstore_info *psi); extern void pstore_get_records(struct pstore_info *psi, int pos, int quiet); extern void pstore_get_backend_records(struct pstore_info *psi, diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index 34fb21e6ff4f..d576ee48527c 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c @@ -652,7 +652,10 @@ int pstore_register(struct pstore_info *psi) if (psi->flags & PSTORE_FLAGS_DMESG && !psback->front_cnt[PSTORE_TYPE_DMESG]) allocate_buf_for_compression(psi, newpsi->index); - pstore_get_records(psi, newpsi->index, 0); + if (psback->fs_ready) { + pstore_mksubdir(psi); + pstore_get_records(psi, newpsi->index, 0); + } list_add_rcu(&newpsi->list, &psback->list_entry); diff --git a/include/linux/pstore.h b/include/linux/pstore.h index ede60617d778..306597545f2d 100644 --- a/include/linux/pstore.h +++ b/include/linux/pstore.h @@ -220,6 +220,7 @@ struct pstore_info_list { * @list_entry: entry of pstore backend driver information list * @front_cnt: count of each enabled frontend * @flag: bitmap of enabled pstore backend + * @fs_ready: whether the pstore filesystem is ready * */ @@ -227,6 +228,7 @@ struct pstore_backends { struct list_head list_entry; int front_cnt[PSTORE_TYPE_MAX]; u16 flag; + bool fs_ready; }; /* Supported frontends */ From patchwork Thu Sep 28 02:42:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuanhe Shu X-Patchwork-Id: 728517 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0EFB4CE7AE4 for ; Thu, 28 Sep 2023 02:44:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230089AbjI1Cn5 (ORCPT ); Wed, 27 Sep 2023 22:43:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230047AbjI1Cny (ORCPT ); Wed, 27 Sep 2023 22:43:54 -0400 Received: from out30-101.freemail.mail.aliyun.com (out30-101.freemail.mail.aliyun.com [115.124.30.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5FD294; Wed, 27 Sep 2023 19:43:51 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R741e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=ay29a033018045168; MF=xiangzao@linux.alibaba.com; NM=1; PH=DS; RN=12; SR=0; TI=SMTPD_---0Vt.rlIY_1695869028; Received: from localhost.localdomain(mailfrom:xiangzao@linux.alibaba.com fp:SMTPD_---0Vt.rlIY_1695869028) by smtp.aliyun-inc.com; Thu, 28 Sep 2023 10:43:49 +0800 From: Yuanhe Shu To: gregkh@linuxfoundation.org, jirislaby@kernel.org, keescook@chromium.org, tony.luck@intel.com, gpiccoli@igalia.com, shuah@kernel.org Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, linux-hardening@vger.kernel.org, linux-kselftest@vger.kernel.org, Yuanhe Shu , Xingrui Yi Subject: [PATCH 4/5] pstore: remove the module parameter "backend" Date: Thu, 28 Sep 2023 10:42:43 +0800 Message-Id: <20230928024244.257687-5-xiangzao@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230928024244.257687-1-xiangzao@linux.alibaba.com> References: <20230928024244.257687-1-xiangzao@linux.alibaba.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org Since all enabled backends have corresponding subdir in /sys/fs/pstore, and the logic of finding unexpected is changed by using psinfo_list rather than parameter backend, it is not necessary to retain the parameter backend. Remove the unnecessary module parameter "backend". Signed-off-by: Xingrui Yi Signed-off-by: Yuanhe Shu --- fs/pstore/platform.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index d576ee48527c..90c33c1ca39f 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c @@ -77,10 +77,6 @@ static DECLARE_WORK(pstore_work, pstore_dowork); DEFINE_MUTEX(psback_lock); struct pstore_backends *psback; -static char *backend; -module_param(backend, charp, 0444); -MODULE_PARM_DESC(backend, "specific backend to use"); - static char *compress = #ifdef CONFIG_PSTORE_COMPRESS_DEFAULT CONFIG_PSTORE_COMPRESS_DEFAULT; @@ -675,12 +671,6 @@ int pstore_register(struct pstore_info *psi) /* Start watching for new records, if desired. */ pstore_timer_kick(); - /* - * Update the module parameter backend, so it is visible - * through /sys/module/pstore/parameters/backend - */ - backend = kstrdup(psi->name, GFP_KERNEL); - pr_info("Registered %s as persistent store backend\n", psi->name); mutex_unlock(&psback_lock);