diff mbox series

[v2] btrfs: sysfs: map sysfs files to their path

Message ID 437f0a236348a3376ac2baeab564460491c7fa12.1628603355.git.anand.jain@oracle.com (mailing list archive)
State New, archived
Headers show
Series [v2] btrfs: sysfs: map sysfs files to their path | expand

Commit Message

Anand Jain Aug. 10, 2021, 1:55 p.m. UTC
Sysfs file has grown big. It takes some time to locate the correct
struct attribute to add new files. Create a table and map the
struct attribute to its sysfs path.

Also, fix the comment about the debug sysfs path.
And add the comments to the attributes instead of attribute group,
where sysfs file names are defined.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v2: Add sysfs path in the attribute definitions.

 fs/btrfs/sysfs.c | 87 +++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 72 insertions(+), 15 deletions(-)

Comments

David Sterba Aug. 10, 2021, 2:45 p.m. UTC | #1
On Tue, Aug 10, 2021 at 09:55:59PM +0800, Anand Jain wrote:
> Sysfs file has grown big. It takes some time to locate the correct
> struct attribute to add new files. Create a table and map the
> struct attribute to its sysfs path.
> 
> Also, fix the comment about the debug sysfs path.
> And add the comments to the attributes instead of attribute group,
> where sysfs file names are defined.
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
> v2: Add sysfs path in the attribute definitions.

Thanks, I've reworded and reformatted some of the comments. Added to
misc-next.

> + * qgroup_attrs				/sys/fs/btrfs/<uuid>/qgroups/<subvol-id>

This is not subvolid but the "level_qgroupid" formatted qgroup id.
Anand Jain Aug. 10, 2021, 3 p.m. UTC | #2
On 10/08/2021 22:45, David Sterba wrote:
> On Tue, Aug 10, 2021 at 09:55:59PM +0800, Anand Jain wrote:
>> Sysfs file has grown big. It takes some time to locate the correct
>> struct attribute to add new files. Create a table and map the
>> struct attribute to its sysfs path.
>>
>> Also, fix the comment about the debug sysfs path.
>> And add the comments to the attributes instead of attribute group,
>> where sysfs file names are defined.
>>
>> Signed-off-by: Anand Jain <anand.jain@oracle.com>
>> ---
>> v2: Add sysfs path in the attribute definitions.
> 
> Thanks, I've reworded and reformatted some of the comments. Added to
> misc-next.
> 
>> + * qgroup_attrs				/sys/fs/btrfs/<uuid>/qgroups/<subvol-id>
> 
> This is not subvolid but the "level_qgroupid" formatted qgroup id.
> 

Got it. Thanks.
diff mbox series

Patch

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index bfe5e27617b0..1ac97250d586 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -22,6 +22,26 @@ 
 #include "block-group.h"
 #include "qgroup.h"
 
+
+/*
+ * struct attributes (sysfs files)	sysfs path
+ * --------------------------------------------------------------------------
+ * btrfs_supported_static_feature_attrs /sys/fs/btrfs/features
+ * btrfs_supported_feature_attrs        /sys/fs/btrfs/features and
+ *					/sys/fs/btrfs/uuid/features (if visible)
+ * btrfs_debug_feature_attrs		/sys/fs/btrfs/debug
+ * btrfs_debug_mount_attrs		/sys/fs/btrfs/<uuid>/debug
+ * discard_debug_attrs			/sys/fs/btrfs/<uuid>/debug/discard
+ * btrfs_attrs				/sys/fs/btrfs/<uuid>
+ * devid_attrs				/sys/fs/btrfs/<uuid>/devinfo/<devid>
+ * allocation_attrs			/sys/fs/btrfs/<uuid>/allocation
+ * qgroup_attrs				/sys/fs/btrfs/<uuid>/qgroups/<subvol-id>
+ * space_info_attrs		/sys/fs/btrfs/<uuid>/allocation/<bg-type>
+ * raid_attrs		/sys/fs/btrfs/<uuid>/allocation/<bg-type>/<bg-profile>
+ */
+
+
+
 struct btrfs_feature_attr {
 	struct kobj_attribute kobj_attr;
 	enum btrfs_feature_set feature_set;
@@ -271,6 +291,13 @@  BTRFS_FEAT_ATTR_INCOMPAT(zoned, ZONED);
 BTRFS_FEAT_ATTR_COMPAT_RO(verity, VERITY);
 #endif
 
+/*
+ * Features which depend on feature bits and may differ between each fs.
+ *
+ * /sys/fs/btrfs/features lists all available features of this kernel while
+ * /sys/fs/btrfs/UUID/features shows features of the fs which are enabled or
+ * can be changed online.
+ */
 static struct attribute *btrfs_supported_feature_attrs[] = {
 	BTRFS_FEAT_ATTR_PTR(mixed_backref),
 	BTRFS_FEAT_ATTR_PTR(default_subvol),
@@ -294,13 +321,6 @@  static struct attribute *btrfs_supported_feature_attrs[] = {
 	NULL
 };
 
-/*
- * Features which depend on feature bits and may differ between each fs.
- *
- * /sys/fs/btrfs/features lists all available features of this kernel while
- * /sys/fs/btrfs/UUID/features shows features of the fs which are enabled or
- * can be changed online.
- */
 static const struct attribute_group btrfs_feature_attr_group = {
 	.name = "features",
 	.is_visible = btrfs_feature_visible,
@@ -384,6 +404,12 @@  static ssize_t supported_sectorsizes_show(struct kobject *kobj,
 BTRFS_ATTR(static_feature, supported_sectorsizes,
 	   supported_sectorsizes_show);
 
+/*
+ * Features which only depend on kernel version.
+ *
+ * These are listed in /sys/fs/btrfs/features along with
+ * btrfs_supported_feature_attrs.
+ */
 static struct attribute *btrfs_supported_static_feature_attrs[] = {
 	BTRFS_ATTR_PTR(static_feature, rmdir_subvol),
 	BTRFS_ATTR_PTR(static_feature, supported_checksums),
@@ -393,12 +419,6 @@  static struct attribute *btrfs_supported_static_feature_attrs[] = {
 	NULL
 };
 
-/*
- * Features which only depend on kernel version.
- *
- * These are listed in /sys/fs/btrfs/features along with
- * btrfs_feature_attr_group
- */
 static const struct attribute_group btrfs_static_feature_attr_group = {
 	.name = "features",
 	.attrs = btrfs_supported_static_feature_attrs,
@@ -557,6 +577,12 @@  static ssize_t btrfs_discard_max_discard_size_store(struct kobject *kobj,
 BTRFS_ATTR_RW(discard, max_discard_size, btrfs_discard_max_discard_size_show,
 	      btrfs_discard_max_discard_size_store);
 
+/*
+ * Runtime debugging exported via sysfs
+ *
+ * sysfs path:
+ *	/sys/fs/btrfs/<uuid>/debug/discard
+ */
 static const struct attribute *discard_debug_attrs[] = {
 	BTRFS_ATTR_PTR(discard, discardable_bytes),
 	BTRFS_ATTR_PTR(discard, discardable_extents),
@@ -572,13 +598,20 @@  static const struct attribute *discard_debug_attrs[] = {
 /*
  * Runtime debugging exported via sysfs
  *
- * /sys/fs/btrfs/debug - applies to module or all filesystems
- * /sys/fs/btrfs/UUID  - applies only to the given filesystem
+ * sysfs path:
+ *	/sys/fs/btrfs/UUID/debug
  */
 static const struct attribute *btrfs_debug_mount_attrs[] = {
 	NULL,
 };
 
+/*
+ * Runtime debugging exported via sysfs
+ *
+ * sysfs path:
+ *	/sys/fs/btrfs/debug
+ * Applies to all btrfs filesystem in the system
+ */
 static struct attribute *btrfs_debug_feature_attrs[] = {
 	NULL
 };
@@ -647,6 +680,10 @@  static ssize_t raid_bytes_show(struct kobject *kobj,
 	return scnprintf(buf, PAGE_SIZE, "%llu\n", val);
 }
 
+/*
+ * sysfs path
+ *	/sys/fs/btrfs/<uuid>/allocation/<bg-type>/<bg-profile>
+ */
 static struct attribute *raid_attrs[] = {
 	BTRFS_ATTR_PTR(raid, total_bytes),
 	BTRFS_ATTR_PTR(raid, used_bytes),
@@ -686,6 +723,10 @@  SPACE_INFO_ATTR(bytes_zone_unusable);
 SPACE_INFO_ATTR(disk_used);
 SPACE_INFO_ATTR(disk_total);
 
+/*
+ * sysfs path
+ *	/sys/fs/btrfs/<uuid>/allocation/<bg-type>
+ */
 static struct attribute *space_info_attrs[] = {
 	BTRFS_ATTR_PTR(space_info, flags),
 	BTRFS_ATTR_PTR(space_info, total_bytes),
@@ -713,6 +754,10 @@  static struct kobj_type space_info_ktype = {
 	.default_groups = space_info_groups,
 };
 
+/*
+ * sysfs path
+ *	sys/fs/btrfs/<uuid>/allocation
+ */
 static const struct attribute *allocation_attrs[] = {
 	BTRFS_ATTR_PTR(allocation, global_rsv_reserved),
 	BTRFS_ATTR_PTR(allocation, global_rsv_size),
@@ -1011,6 +1056,10 @@  static ssize_t btrfs_bg_reclaim_threshold_store(struct kobject *kobj,
 BTRFS_ATTR_RW(, bg_reclaim_threshold, btrfs_bg_reclaim_threshold_show,
 	      btrfs_bg_reclaim_threshold_store);
 
+/*
+ * sysfs path
+ *	/sys/fs/btrfs/<uuid>
+ */
 static const struct attribute *btrfs_attrs[] = {
 	BTRFS_ATTR_PTR(, label),
 	BTRFS_ATTR_PTR(, nodesize),
@@ -1520,6 +1569,10 @@  static ssize_t btrfs_devinfo_error_stats_show(struct kobject *kobj,
 }
 BTRFS_ATTR(devid, error_stats, btrfs_devinfo_error_stats_show);
 
+/*
+ * sysfs path
+ *	/sys/fs/btrfs/<uuid>/devinfo/<devid>
+ */
 static struct attribute *devid_attrs[] = {
 	BTRFS_ATTR_PTR(devid, error_stats),
 	BTRFS_ATTR_PTR(devid, in_fs_metadata),
@@ -1809,6 +1862,10 @@  QGROUP_RSV_ATTR(data, BTRFS_QGROUP_RSV_DATA);
 QGROUP_RSV_ATTR(meta_pertrans, BTRFS_QGROUP_RSV_META_PERTRANS);
 QGROUP_RSV_ATTR(meta_prealloc, BTRFS_QGROUP_RSV_META_PREALLOC);
 
+/*
+ * sysfs path
+ *	/sys/fs/btrfs/<uuid>/qgroups/<subvol-id>
+ */
 static struct attribute *qgroup_attrs[] = {
 	BTRFS_ATTR_PTR(qgroup, referenced),
 	BTRFS_ATTR_PTR(qgroup, exclusive),