All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] f2fs: add some sysfs nodes for segment
@ 2022-07-06  2:06 ` Guowei Du
  0 siblings, 0 replies; 6+ messages in thread
From: Guowei Du @ 2022-07-06  2:06 UTC (permalink / raw)
  To: jaegeuk, chao; +Cc: linux-f2fs-devel, linux-kernel, duguowei

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


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

* [f2fs-dev] [PATCH] f2fs: add some sysfs nodes for segment
@ 2022-07-06  2:06 ` Guowei Du
  0 siblings, 0 replies; 6+ 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] 6+ messages in thread

* Re: [PATCH] f2fs: add some sysfs nodes for segment
  2022-07-06  2:06 ` [f2fs-dev] " Guowei Du
@ 2022-07-12  1:43   ` Jaegeuk Kim
  -1 siblings, 0 replies; 6+ messages in thread
From: Jaegeuk Kim @ 2022-07-12  1:43 UTC (permalink / raw)
  To: Guowei Du; +Cc: chao, linux-f2fs-devel, linux-kernel, duguowei

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

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

* Re: [f2fs-dev] [PATCH] f2fs: add some sysfs nodes for segment
@ 2022-07-12  1:43   ` Jaegeuk Kim
  0 siblings, 0 replies; 6+ messages in thread
From: Jaegeuk Kim @ 2022-07-12  1:43 UTC (permalink / raw)
  To: Guowei Du; +Cc: linux-kernel, duguowei, linux-f2fs-devel

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

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

* Re: [PATCH] f2fs: add some sysfs nodes for segment
  2022-07-12  1:43   ` [f2fs-dev] " Jaegeuk Kim
@ 2022-07-12 12:51     ` Chao Yu
  -1 siblings, 0 replies; 6+ messages in thread
From: Chao Yu @ 2022-07-12 12:51 UTC (permalink / raw)
  To: Jaegeuk Kim, Guowei Du; +Cc: linux-f2fs-devel, linux-kernel, duguowei

On 2022/7/12 9:43, Jaegeuk Kim wrote:
> 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.

If this is used for debug, how about checking /sys/kernel/debug/f2fs/status?

Thanks,

>>
>> 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

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

* Re: [f2fs-dev] [PATCH] f2fs: add some sysfs nodes for segment
@ 2022-07-12 12:51     ` Chao Yu
  0 siblings, 0 replies; 6+ messages in thread
From: Chao Yu @ 2022-07-12 12:51 UTC (permalink / raw)
  To: Jaegeuk Kim, Guowei Du; +Cc: linux-kernel, duguowei, linux-f2fs-devel

On 2022/7/12 9:43, Jaegeuk Kim wrote:
> 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.

If this is used for debug, how about checking /sys/kernel/debug/f2fs/status?

Thanks,

>>
>> 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

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

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

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.