From: Jaegeuk Kim <jaegeuk@kernel.org>
To: Guowei Du <duguoweisz@gmail.com>
Cc: linux-kernel@vger.kernel.org, duguowei <duguowei@xiaomi.com>,
linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [f2fs-dev] [PATCH] f2fs: add some sysfs nodes for segment
Date: Mon, 11 Jul 2022 18:43:08 -0700 [thread overview]
Message-ID: <YszRrHHqLk4My3vO@google.com> (raw)
In-Reply-To: <20220706020615.29938-1-duguoweisz@gmail.com>
On 07/06, Guowei Du wrote:
> 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)));
> +}
Can we create a macro to do the above functions?
> +
> #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
next prev parent reply other threads:[~2022-07-12 1:43 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-06 2:06 [f2fs-dev] [PATCH] f2fs: add some sysfs nodes for segment Guowei Du
2022-07-12 1:43 ` Jaegeuk Kim [this message]
2022-07-12 12:51 ` Chao Yu
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=YszRrHHqLk4My3vO@google.com \
--to=jaegeuk@kernel.org \
--cc=duguowei@xiaomi.com \
--cc=duguoweisz@gmail.com \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).