linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
* [f2fs-dev] [PATCH] f2fs: add some sysfs nodes for segment
@ 2022-07-06  2:06 Guowei Du
  2022-07-12  1:43 ` Jaegeuk Kim
  0 siblings, 1 reply; 3+ messages in thread
From: Guowei Du @ 2022-07-06  2:06 UTC (permalink / raw)
  To: jaegeuk, chao; +Cc: linux-kernel, duguowei, linux-f2fs-devel

From: duguowei <duguowei@xiaomi.com>

There are two ways to show meta segment information,
one is by dump.f2fs, another is by sysfs node. But,
sometimes dump needs root privilege,So adding a
few sysfs nodes.

The generic permission of node is 0444(S_IRUGO).

$ cd /sys/fs/f2fs/DEVICE/...
$ ls -l
...
-r--r--r-- 1 root root 4096 7月   5 23:21 reserved_segments
-r--r--r-- 1 root root 4096 7月   5 23:21 segment_count
-r--r--r-- 1 root root 4096 7月   5 23:21 segment_count_ckpt
-r--r--r-- 1 root root 4096 7月   5 23:21 segment_count_main
-r--r--r-- 1 root root 4096 7月   5 23:21 segment_count_nat
-r--r--r-- 1 root root 4096 7月   5 23:21 segment_count_sit
-r--r--r-- 1 root root 4096 7月   5 23:21 segment_count_ssa
...

$ sudo dump.f2fs -d 1 DEVICE
...
Super block
segment_count                           [0x      26 : 38]
segment_count_ckpt                      [0x       2 : 2]
segment_count_sit                       [0x       2 : 2]
segment_count_nat                       [0x       2 : 2]
segment_count_ssa                       [0x       1 : 1]
segment_count_main                      [0x      1f : 31]
...
Checkpoint
rsvd_segment_count                      [0x       e : 14]
...

Signed-off-by: duguowei <duguowei@xiaomi.com>
---
 fs/f2fs/sysfs.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
index 4c50aedd5144..05350bba2c83 100644
--- a/fs/f2fs/sysfs.c
+++ b/fs/f2fs/sysfs.c
@@ -697,6 +697,55 @@ static ssize_t f2fs_sb_feature_show(struct f2fs_attr *a,
 	return sprintf(buf, "unsupported\n");
 }
 
+static ssize_t segment_count_show(struct f2fs_attr *a,
+		struct f2fs_sb_info *sbi, char *buf)
+{
+	return sprintf(buf, "%llu\n",
+			(unsigned long long)(F2FS_RAW_SUPER(sbi)->segment_count));
+}
+
+static ssize_t segment_count_ckpt_show(struct f2fs_attr *a,
+		struct f2fs_sb_info *sbi, char *buf)
+{
+	return sprintf(buf, "%llu\n",
+			(unsigned long long)(F2FS_RAW_SUPER(sbi)->segment_count_ckpt));
+}
+
+static ssize_t segment_count_sit_show(struct f2fs_attr *a,
+		struct f2fs_sb_info *sbi, char *buf)
+{
+	return sprintf(buf, "%llu\n",
+			(unsigned long long)(F2FS_RAW_SUPER(sbi)->segment_count_sit));
+}
+
+static ssize_t segment_count_nat_show(struct f2fs_attr *a,
+		struct f2fs_sb_info *sbi, char *buf)
+{
+	return sprintf(buf, "%llu\n",
+			(unsigned long long)(F2FS_RAW_SUPER(sbi)->segment_count_nat));
+}
+
+static ssize_t segment_count_ssa_show(struct f2fs_attr *a,
+		struct f2fs_sb_info *sbi, char *buf)
+{
+	return sprintf(buf, "%llu\n",
+			(unsigned long long)(F2FS_RAW_SUPER(sbi)->segment_count_ssa));
+}
+
+static ssize_t segment_count_main_show(struct f2fs_attr *a,
+		struct f2fs_sb_info *sbi, char *buf)
+{
+	return sprintf(buf, "%llu\n",
+			(unsigned long long)(F2FS_RAW_SUPER(sbi)->segment_count_main));
+}
+
+static ssize_t reserved_segments_show(struct f2fs_attr *a,
+		struct f2fs_sb_info *sbi, char *buf)
+{
+	return sprintf(buf, "%llu\n",
+			(unsigned long long)(reserved_segments(sbi)));
+}
+
 #define F2FS_SB_FEATURE_RO_ATTR(_name, _feat)			\
 static struct f2fs_attr f2fs_attr_sb_##_name = {		\
 	.attr = {.name = __stringify(_name), .mode = 0444 },	\
@@ -801,6 +850,13 @@ F2FS_GENERAL_RO_ATTR(moved_blocks_background);
 F2FS_GENERAL_RO_ATTR(moved_blocks_foreground);
 F2FS_GENERAL_RO_ATTR(avg_vblocks);
 #endif
+F2FS_GENERAL_RO_ATTR(segment_count);
+F2FS_GENERAL_RO_ATTR(segment_count_ckpt);
+F2FS_GENERAL_RO_ATTR(segment_count_sit);
+F2FS_GENERAL_RO_ATTR(segment_count_nat);
+F2FS_GENERAL_RO_ATTR(segment_count_ssa);
+F2FS_GENERAL_RO_ATTR(segment_count_main);
+F2FS_GENERAL_RO_ATTR(reserved_segments);
 
 #ifdef CONFIG_FS_ENCRYPTION
 F2FS_FEATURE_RO_ATTR(encryption);
@@ -934,6 +990,13 @@ static struct attribute *f2fs_attrs[] = {
 	ATTR_LIST(gc_reclaimed_segments),
 	ATTR_LIST(max_fragment_chunk),
 	ATTR_LIST(max_fragment_hole),
+	ATTR_LIST(segment_count),
+	ATTR_LIST(segment_count_ckpt),
+	ATTR_LIST(segment_count_sit),
+	ATTR_LIST(segment_count_nat),
+	ATTR_LIST(segment_count_ssa),
+	ATTR_LIST(segment_count_main),
+	ATTR_LIST(reserved_segments),
 	NULL,
 };
 ATTRIBUTE_GROUPS(f2fs);
-- 
2.36.1



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-07-12 12:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-06  2:06 [f2fs-dev] [PATCH] f2fs: add some sysfs nodes for segment Guowei Du
2022-07-12  1:43 ` Jaegeuk Kim
2022-07-12 12:51   ` Chao Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).