Messages in this thread Patch in this message | | | From | Guowei Du <> | Subject | [PATCH] f2fs: add some sysfs nodes for segment | Date | Wed, 6 Jul 2022 10:06:15 +0800 |
| |
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
| |