[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220401071909.505086-2-yuyufen@huawei.com>
Date: Fri, 1 Apr 2022 15:19:05 +0800
From: Yufen Yu <yuyufen@...wei.com>
To: <jaegeuk@...nel.org>, <chao@...nel.org>
CC: <linux-kernel@...r.kernel.org>,
<linux-f2fs-devel@...ts.sourceforge.net>, <yuyufen@...wei.com>
Subject: [PATCH 1/5] f2fs: extract f2fs root debugfs to init_f2fs_fs
Then, we don't need to depend on CONFIG_F2FS_STAT_FS to create
f2fs root debugfs directory /sys/kernel/debug/f2fs.
This patch is prepared for following f2fs fault injection,
which will create sub directory 'fault_inject' into f2fs root debugfs.
Signed-off-by: Yufen Yu <yuyufen@...wei.com>
---
fs/f2fs/debug.c | 19 ++-----------------
fs/f2fs/f2fs.h | 4 ++--
fs/f2fs/super.c | 22 ++++++++++++++++++++--
3 files changed, 24 insertions(+), 21 deletions(-)
diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c
index fcdf253cd211..15b3567cd208 100644
--- a/fs/f2fs/debug.c
+++ b/fs/f2fs/debug.c
@@ -22,9 +22,6 @@
static LIST_HEAD(f2fs_stat_list);
static DEFINE_RAW_SPINLOCK(f2fs_stat_lock);
-#ifdef CONFIG_DEBUG_FS
-static struct dentry *f2fs_debugfs_root;
-#endif
/*
* This function calculates BDF of every segments
@@ -648,18 +645,6 @@ void f2fs_destroy_stats(struct f2fs_sb_info *sbi)
void __init f2fs_create_root_stats(void)
{
-#ifdef CONFIG_DEBUG_FS
- f2fs_debugfs_root = debugfs_create_dir("f2fs", NULL);
-
- debugfs_create_file("status", 0444, f2fs_debugfs_root, NULL,
- &stat_fops);
-#endif
-}
-
-void f2fs_destroy_root_stats(void)
-{
-#ifdef CONFIG_DEBUG_FS
- debugfs_remove_recursive(f2fs_debugfs_root);
- f2fs_debugfs_root = NULL;
-#endif
+ if (f2fs_debugfs_root)
+ debugfs_create_file("status", 0444, f2fs_debugfs_root, NULL, &stat_fops);
}
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index cd1e65bcf0b0..be3014029a4e 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -62,6 +62,8 @@ enum {
FAULT_MAX,
};
+extern struct dentry *f2fs_debugfs_root;
+
#ifdef CONFIG_F2FS_FAULT_INJECTION
#define F2FS_ALL_FAULT_TYPE ((1 << FAULT_MAX) - 1)
@@ -3994,7 +3996,6 @@ static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi)
int f2fs_build_stats(struct f2fs_sb_info *sbi);
void f2fs_destroy_stats(struct f2fs_sb_info *sbi);
void __init f2fs_create_root_stats(void);
-void f2fs_destroy_root_stats(void);
void f2fs_update_sit_info(struct f2fs_sb_info *sbi);
#else
#define stat_inc_cp_count(si) do { } while (0)
@@ -4035,7 +4036,6 @@ void f2fs_update_sit_info(struct f2fs_sb_info *sbi);
static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; }
static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { }
static inline void __init f2fs_create_root_stats(void) { }
-static inline void f2fs_destroy_root_stats(void) { }
static inline void f2fs_update_sit_info(struct f2fs_sb_info *sbi) {}
#endif
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index ea939db18f88..04e41360303c 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -27,6 +27,7 @@
#include <linux/part_stat.h>
#include <linux/zstd.h>
#include <linux/lz4.h>
+#include <linux/debugfs.h>
#include "f2fs.h"
#include "node.h"
@@ -39,6 +40,7 @@
#include <trace/events/f2fs.h>
static struct kmem_cache *f2fs_inode_cachep;
+struct dentry *f2fs_debugfs_root;
#ifdef CONFIG_F2FS_FAULT_INJECTION
@@ -4575,6 +4577,21 @@ static void destroy_inodecache(void)
kmem_cache_destroy(f2fs_inode_cachep);
}
+static void f2fs_create_debugfs(void)
+{
+#ifdef CONFIG_DEBUG_FS
+ f2fs_debugfs_root = debugfs_create_dir("f2fs", NULL);
+#endif
+}
+
+static void f2fs_destroy_debugfs(void)
+{
+#ifdef CONFIG_DEBUG_FS
+ debugfs_remove_recursive(f2fs_debugfs_root);
+ f2fs_debugfs_root = NULL;
+#endif
+}
+
static int __init init_f2fs_fs(void)
{
int err;
@@ -4615,6 +4632,7 @@ static int __init init_f2fs_fs(void)
err = register_filesystem(&f2fs_fs_type);
if (err)
goto free_shrinker;
+ f2fs_create_debugfs();
f2fs_create_root_stats();
err = f2fs_init_post_read_processing();
if (err)
@@ -4651,7 +4669,7 @@ static int __init init_f2fs_fs(void)
free_post_read:
f2fs_destroy_post_read_processing();
free_root_stats:
- f2fs_destroy_root_stats();
+ f2fs_destroy_debugfs();
unregister_filesystem(&f2fs_fs_type);
free_shrinker:
unregister_shrinker(&f2fs_shrinker_info);
@@ -4684,7 +4702,7 @@ static void __exit exit_f2fs_fs(void)
f2fs_destroy_bio_entry_cache();
f2fs_destroy_iostat_processing();
f2fs_destroy_post_read_processing();
- f2fs_destroy_root_stats();
+ f2fs_destroy_debugfs();
unregister_filesystem(&f2fs_fs_type);
unregister_shrinker(&f2fs_shrinker_info);
f2fs_exit_sysfs();
--
2.31.1
Powered by blists - more mailing lists