linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/13] Sysfs cleanups
@ 2019-08-02 13:40 David Sterba
  2019-08-02 13:40 ` [PATCH 01/13] btrfs: move sysfs declarations out of ctree.h David Sterba
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: David Sterba @ 2019-08-02 13:40 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

Handful of almost trivial changes that clean up the sysfs structures and
helpers so the sysfs-related api is used only inside sysfs.c and that
the API facing btrfs is minimized.

David Sterba (13):
  btrfs: move sysfs declarations out of ctree.h
  btrfs: move btrfs_add_raid_kobjects to sysfs.c
  btrfs: factor sysfs code out of link_block_group
  btrfs: sysfs: unexport btrfs_raid_ktype
  btrfs: factor out sysfs code for creating space infos
  btrfs: sysfs: unexport space_info_ktype
  btrfs: sysfs: replace direct access to feature set names with a helper
  btrfs: factor out sysfs code for sending device uevent
  btrfs: factor out sysfs code for deleting block group and space infos
  btrfs: factor out sysfs code for updating sprout fsid
  btrfs: cleanup kobject.h includes
  btrfs: sysfs: move helper macros to sysfs.c
  btrfs: sysfs: move type conversion helpers to sysfs.c

 fs/btrfs/ctree.h       |  15 ---
 fs/btrfs/extent-tree.c |  59 +----------
 fs/btrfs/ioctl.c       |   2 +-
 fs/btrfs/space-info.c  |  25 +----
 fs/btrfs/super.c       |   1 +
 fs/btrfs/sysfs.c       | 217 ++++++++++++++++++++++++++++++++++++++++-
 fs/btrfs/sysfs.h       |  80 +++------------
 fs/btrfs/volumes.c     |  25 +----
 8 files changed, 238 insertions(+), 186 deletions(-)

-- 
2.22.0


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

* [PATCH 01/13] btrfs: move sysfs declarations out of ctree.h
  2019-08-02 13:40 [PATCH 00/13] Sysfs cleanups David Sterba
@ 2019-08-02 13:40 ` David Sterba
  2019-08-02 13:40 ` [PATCH 02/13] btrfs: move btrfs_add_raid_kobjects to sysfs.c David Sterba
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: David Sterba @ 2019-08-02 13:40 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

As the header for sysfs code already exists, use it to clean up ctree.h.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/ctree.h | 13 -------------
 fs/btrfs/super.c |  1 +
 fs/btrfs/sysfs.h | 12 ++++++++++++
 3 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 1110bbd4bffb..894a249b2182 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -397,13 +397,6 @@ struct btrfs_dev_replace {
 	wait_queue_head_t replace_wait;
 };
 
-/* For raid type sysfs entries */
-struct raid_kobject {
-	u64 flags;
-	struct kobject kobj;
-	struct list_head list;
-};
-
 /*
  * free clusters are used to claim free space in relatively large chunks,
  * allowing us to do less seeky writes. They are used for all metadata
@@ -3265,12 +3258,6 @@ loff_t btrfs_remap_file_range(struct file *file_in, loff_t pos_in,
 int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
 			struct btrfs_root *root);
 
-/* sysfs.c */
-int __init btrfs_init_sysfs(void);
-void __cold btrfs_exit_sysfs(void);
-int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info);
-void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info);
-
 /* super.c */
 int btrfs_parse_options(struct btrfs_fs_info *info, char *options,
 			unsigned long new_flags);
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 10bc7e6cca75..69eaa198e51e 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -43,6 +43,7 @@
 #include "free-space-cache.h"
 #include "backref.h"
 #include "space-info.h"
+#include "sysfs.h"
 #include "tests/btrfs-tests.h"
 
 #include "qgroup.h"
diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h
index 40716b357c1d..f9fc7101e696 100644
--- a/fs/btrfs/sysfs.h
+++ b/fs/btrfs/sysfs.h
@@ -40,6 +40,13 @@ struct btrfs_feature_attr {
 	u64 feature_bit;
 };
 
+/* For raid type sysfs entries */
+struct raid_kobject {
+	u64 flags;
+	struct kobject kobj;
+	struct list_head list;
+};
+
 #define BTRFS_FEAT_ATTR(_name, _feature_set, _feature_prefix, _feature_bit)  \
 static struct btrfs_feature_attr btrfs_attr_features_##_name = {	     \
 	.kobj_attr = __INIT_KOBJ_ATTR(_name, S_IRUGO,			     \
@@ -91,4 +98,9 @@ void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs);
 void btrfs_sysfs_feature_update(struct btrfs_fs_info *fs_info,
 		u64 bit, enum btrfs_feature_set set);
 
+int __init btrfs_init_sysfs(void);
+void __cold btrfs_exit_sysfs(void);
+int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info);
+void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info);
+
 #endif
-- 
2.22.0


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

* [PATCH 02/13] btrfs: move btrfs_add_raid_kobjects to sysfs.c
  2019-08-02 13:40 [PATCH 00/13] Sysfs cleanups David Sterba
  2019-08-02 13:40 ` [PATCH 01/13] btrfs: move sysfs declarations out of ctree.h David Sterba
@ 2019-08-02 13:40 ` David Sterba
  2019-08-02 13:40 ` [PATCH 03/13] btrfs: factor sysfs code out of link_block_group David Sterba
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: David Sterba @ 2019-08-02 13:40 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

The function manipulates sysfs entries so this belongs to sysfs.c.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/ctree.h       |  1 -
 fs/btrfs/extent-tree.c | 27 ---------------------------
 fs/btrfs/sysfs.c       | 27 +++++++++++++++++++++++++++
 fs/btrfs/sysfs.h       |  1 +
 4 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 894a249b2182..a61bf19a7ef6 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -2700,7 +2700,6 @@ int btrfs_read_block_groups(struct btrfs_fs_info *info);
 int btrfs_make_block_group(struct btrfs_trans_handle *trans,
 			   u64 bytes_used, u64 type, u64 chunk_offset,
 			   u64 size);
-void btrfs_add_raid_kobjects(struct btrfs_fs_info *fs_info);
 struct btrfs_trans_handle *btrfs_start_trans_remove_block_group(
 				struct btrfs_fs_info *fs_info,
 				const u64 chunk_offset);
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 81f109357050..7f7a0530b0e2 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -7774,33 +7774,6 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info)
 	return 0;
 }
 
-/* link_block_group will queue up kobjects to add when we're reclaim-safe */
-void btrfs_add_raid_kobjects(struct btrfs_fs_info *fs_info)
-{
-	struct btrfs_space_info *space_info;
-	struct raid_kobject *rkobj;
-	LIST_HEAD(list);
-	int ret = 0;
-
-	spin_lock(&fs_info->pending_raid_kobjs_lock);
-	list_splice_init(&fs_info->pending_raid_kobjs, &list);
-	spin_unlock(&fs_info->pending_raid_kobjs_lock);
-
-	list_for_each_entry(rkobj, &list, list) {
-		space_info = btrfs_find_space_info(fs_info, rkobj->flags);
-
-		ret = kobject_add(&rkobj->kobj, &space_info->kobj,
-				"%s", btrfs_bg_type_to_raid_name(rkobj->flags));
-		if (ret) {
-			kobject_put(&rkobj->kobj);
-			break;
-		}
-	}
-	if (ret)
-		btrfs_warn(fs_info,
-			   "failed to add kobject for block cache, ignoring");
-}
-
 static void link_block_group(struct btrfs_block_group_cache *cache)
 {
 	struct btrfs_space_info *space_info = cache->space_info;
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 9539f8143b7a..a6894b6c2623 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -730,6 +730,33 @@ static void init_feature_attrs(void)
 	}
 }
 
+/* link_block_group will queue up kobjects to add when we're reclaim-safe */
+void btrfs_add_raid_kobjects(struct btrfs_fs_info *fs_info)
+{
+	struct btrfs_space_info *space_info;
+	struct raid_kobject *rkobj;
+	LIST_HEAD(list);
+	int ret = 0;
+
+	spin_lock(&fs_info->pending_raid_kobjs_lock);
+	list_splice_init(&fs_info->pending_raid_kobjs, &list);
+	spin_unlock(&fs_info->pending_raid_kobjs_lock);
+
+	list_for_each_entry(rkobj, &list, list) {
+		space_info = btrfs_find_space_info(fs_info, rkobj->flags);
+
+		ret = kobject_add(&rkobj->kobj, &space_info->kobj,
+				"%s", btrfs_bg_type_to_raid_name(rkobj->flags));
+		if (ret) {
+			kobject_put(&rkobj->kobj);
+			break;
+		}
+	}
+	if (ret)
+		btrfs_warn(fs_info,
+			   "failed to add kobject for block cache, ignoring");
+}
+
 /* when one_device is NULL, it removes all device links */
 
 int btrfs_sysfs_rm_device_link(struct btrfs_fs_devices *fs_devices,
diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h
index f9fc7101e696..25f028b65316 100644
--- a/fs/btrfs/sysfs.h
+++ b/fs/btrfs/sysfs.h
@@ -102,5 +102,6 @@ int __init btrfs_init_sysfs(void);
 void __cold btrfs_exit_sysfs(void);
 int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info);
 void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info);
+void btrfs_add_raid_kobjects(struct btrfs_fs_info *fs_info);
 
 #endif
-- 
2.22.0


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

* [PATCH 03/13] btrfs: factor sysfs code out of link_block_group
  2019-08-02 13:40 [PATCH 00/13] Sysfs cleanups David Sterba
  2019-08-02 13:40 ` [PATCH 01/13] btrfs: move sysfs declarations out of ctree.h David Sterba
  2019-08-02 13:40 ` [PATCH 02/13] btrfs: move btrfs_add_raid_kobjects to sysfs.c David Sterba
@ 2019-08-02 13:40 ` David Sterba
  2019-08-02 13:40 ` [PATCH 04/13] btrfs: sysfs: unexport btrfs_raid_ktype David Sterba
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: David Sterba @ 2019-08-02 13:40 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

The part of link_block_group that just creates the sysfs object is
independent and can be factored out to a helper.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/extent-tree.c | 18 ++----------------
 fs/btrfs/sysfs.c       | 27 +++++++++++++++++++++++++++
 fs/btrfs/sysfs.h       |  1 +
 3 files changed, 30 insertions(+), 16 deletions(-)

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 7f7a0530b0e2..8ac496fddc59 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -7777,7 +7777,6 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info)
 static void link_block_group(struct btrfs_block_group_cache *cache)
 {
 	struct btrfs_space_info *space_info = cache->space_info;
-	struct btrfs_fs_info *fs_info = cache->fs_info;
 	int index = btrfs_bg_flags_to_raid_index(cache->flags);
 	bool first = false;
 
@@ -7787,21 +7786,8 @@ static void link_block_group(struct btrfs_block_group_cache *cache)
 	list_add_tail(&cache->list, &space_info->block_groups[index]);
 	up_write(&space_info->groups_sem);
 
-	if (first) {
-		struct raid_kobject *rkobj = kzalloc(sizeof(*rkobj), GFP_NOFS);
-		if (!rkobj) {
-			btrfs_warn(cache->fs_info,
-				"couldn't alloc memory for raid level kobject");
-			return;
-		}
-		rkobj->flags = cache->flags;
-		kobject_init(&rkobj->kobj, &btrfs_raid_ktype);
-
-		spin_lock(&fs_info->pending_raid_kobjs_lock);
-		list_add_tail(&rkobj->list, &fs_info->pending_raid_kobjs);
-		spin_unlock(&fs_info->pending_raid_kobjs_lock);
-		space_info->block_group_kobjs[index] = &rkobj->kobj;
-	}
+	if (first)
+		btrfs_sysfs_add_block_group_type(cache);
 }
 
 static struct btrfs_block_group_cache *
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index a6894b6c2623..008d58f618cd 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -757,6 +757,33 @@ void btrfs_add_raid_kobjects(struct btrfs_fs_info *fs_info)
 			   "failed to add kobject for block cache, ignoring");
 }
 
+/*
+ * Create a sysfs entry for a given block group type at path
+ * /sys/fs/btrfs/UUID/allocation/data/TYPE
+ */
+void btrfs_sysfs_add_block_group_type(struct btrfs_block_group_cache *cache)
+{
+	struct btrfs_fs_info *fs_info = cache->fs_info;
+	struct btrfs_space_info *space_info = cache->space_info;
+	struct raid_kobject *rkobj;
+	const int index = btrfs_bg_flags_to_raid_index(cache->flags);
+
+	rkobj = kzalloc(sizeof(*rkobj), GFP_NOFS);
+	if (!rkobj) {
+		btrfs_warn(cache->fs_info,
+				"couldn't alloc memory for raid level kobject");
+		return;
+	}
+
+	rkobj->flags = cache->flags;
+	kobject_init(&rkobj->kobj, &btrfs_raid_ktype);
+
+	spin_lock(&fs_info->pending_raid_kobjs_lock);
+	list_add_tail(&rkobj->list, &fs_info->pending_raid_kobjs);
+	spin_unlock(&fs_info->pending_raid_kobjs_lock);
+	space_info->block_group_kobjs[index] = &rkobj->kobj;
+}
+
 /* when one_device is NULL, it removes all device links */
 
 int btrfs_sysfs_rm_device_link(struct btrfs_fs_devices *fs_devices,
diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h
index 25f028b65316..fa1b9bb5d320 100644
--- a/fs/btrfs/sysfs.h
+++ b/fs/btrfs/sysfs.h
@@ -103,5 +103,6 @@ void __cold btrfs_exit_sysfs(void);
 int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info);
 void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info);
 void btrfs_add_raid_kobjects(struct btrfs_fs_info *fs_info);
+void btrfs_sysfs_add_block_group_type(struct btrfs_block_group_cache *cache);
 
 #endif
-- 
2.22.0


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

* [PATCH 04/13] btrfs: sysfs: unexport btrfs_raid_ktype
  2019-08-02 13:40 [PATCH 00/13] Sysfs cleanups David Sterba
                   ` (2 preceding siblings ...)
  2019-08-02 13:40 ` [PATCH 03/13] btrfs: factor sysfs code out of link_block_group David Sterba
@ 2019-08-02 13:40 ` David Sterba
  2019-08-02 13:40 ` [PATCH 05/13] btrfs: factor out sysfs code for creating space infos David Sterba
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: David Sterba @ 2019-08-02 13:40 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

The last non-sysfs usage of btrfs_raid_ktype has been moved to a private
helper in previous patch so the variable can be made static.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/sysfs.c | 2 +-
 fs/btrfs/sysfs.h | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 008d58f618cd..25097d6cf2ca 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -316,7 +316,7 @@ static void release_raid_kobj(struct kobject *kobj)
 	kfree(to_raid_kobj(kobj));
 }
 
-struct kobj_type btrfs_raid_ktype = {
+static struct kobj_type btrfs_raid_ktype = {
 	.sysfs_ops = &kobj_sysfs_ops,
 	.release = release_raid_kobj,
 	.default_groups = raid_groups,
diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h
index fa1b9bb5d320..7f659ce7be84 100644
--- a/fs/btrfs/sysfs.h
+++ b/fs/btrfs/sysfs.h
@@ -86,7 +86,6 @@ attr_to_btrfs_feature_attr(struct attribute *attr)
 char *btrfs_printable_features(enum btrfs_feature_set set, u64 flags);
 extern const char * const btrfs_feature_set_names[FEAT_MAX];
 extern struct kobj_type space_info_ktype;
-extern struct kobj_type btrfs_raid_ktype;
 int btrfs_sysfs_add_device_link(struct btrfs_fs_devices *fs_devices,
 		struct btrfs_device *one_device);
 int btrfs_sysfs_rm_device_link(struct btrfs_fs_devices *fs_devices,
-- 
2.22.0


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

* [PATCH 05/13] btrfs: factor out sysfs code for creating space infos
  2019-08-02 13:40 [PATCH 00/13] Sysfs cleanups David Sterba
                   ` (3 preceding siblings ...)
  2019-08-02 13:40 ` [PATCH 04/13] btrfs: sysfs: unexport btrfs_raid_ktype David Sterba
@ 2019-08-02 13:40 ` David Sterba
  2019-08-02 13:40 ` [PATCH 06/13] btrfs: sysfs: unexport space_info_ktype David Sterba
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: David Sterba @ 2019-08-02 13:40 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

Move creation of data/metadata/system space info directories to sysfs.c.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/space-info.c | 25 ++-----------------------
 fs/btrfs/sysfs.c      | 37 +++++++++++++++++++++++++++++++++++++
 fs/btrfs/sysfs.h      |  2 ++
 3 files changed, 41 insertions(+), 23 deletions(-)

diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
index ab7b9ec4c240..061a216ff966 100644
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
@@ -33,23 +33,6 @@ void btrfs_clear_space_info_full(struct btrfs_fs_info *info)
 	rcu_read_unlock();
 }
 
-static const char *alloc_name(u64 flags)
-{
-	switch (flags) {
-	case BTRFS_BLOCK_GROUP_METADATA|BTRFS_BLOCK_GROUP_DATA:
-		return "mixed";
-	case BTRFS_BLOCK_GROUP_METADATA:
-		return "metadata";
-	case BTRFS_BLOCK_GROUP_DATA:
-		return "data";
-	case BTRFS_BLOCK_GROUP_SYSTEM:
-		return "system";
-	default:
-		WARN_ON(1);
-		return "invalid-combination";
-	};
-}
-
 static int create_space_info(struct btrfs_fs_info *info, u64 flags)
 {
 
@@ -79,13 +62,9 @@ static int create_space_info(struct btrfs_fs_info *info, u64 flags)
 	INIT_LIST_HEAD(&space_info->tickets);
 	INIT_LIST_HEAD(&space_info->priority_tickets);
 
-	ret = kobject_init_and_add(&space_info->kobj, &space_info_ktype,
-				    info->space_info_kobj, "%s",
-				    alloc_name(space_info->flags));
-	if (ret) {
-		kobject_put(&space_info->kobj);
+	ret = btrfs_sysfs_add_space_info_type(info, space_info);
+	if (ret)
 		return ret;
-	}
 
 	list_add_rcu(&space_info->list, &info->space_info);
 	if (flags & BTRFS_BLOCK_GROUP_DATA)
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 25097d6cf2ca..24aaac281580 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -784,6 +784,43 @@ void btrfs_sysfs_add_block_group_type(struct btrfs_block_group_cache *cache)
 	space_info->block_group_kobjs[index] = &rkobj->kobj;
 }
 
+static const char *alloc_name(u64 flags)
+{
+	switch (flags) {
+	case BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_DATA:
+		return "mixed";
+	case BTRFS_BLOCK_GROUP_METADATA:
+		return "metadata";
+	case BTRFS_BLOCK_GROUP_DATA:
+		return "data";
+	case BTRFS_BLOCK_GROUP_SYSTEM:
+		return "system";
+	default:
+		WARN_ON(1);
+		return "invalid-combination";
+	};
+}
+
+/*
+ * Create a sysfs entry for a space info type at path
+ * /sys/fs/btrfs/UUID/allocation/TYPE
+ */
+int btrfs_sysfs_add_space_info_type(struct btrfs_fs_info *fs_info,
+				    struct btrfs_space_info *space_info)
+{
+	int ret;
+
+	ret = kobject_init_and_add(&space_info->kobj, &space_info_ktype,
+				   fs_info->space_info_kobj, "%s",
+				   alloc_name(space_info->flags));
+	if (ret) {
+		kobject_put(&space_info->kobj);
+		return ret;
+	}
+
+	return 0;
+}
+
 /* when one_device is NULL, it removes all device links */
 
 int btrfs_sysfs_rm_device_link(struct btrfs_fs_devices *fs_devices,
diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h
index 7f659ce7be84..928c8ab37fd9 100644
--- a/fs/btrfs/sysfs.h
+++ b/fs/btrfs/sysfs.h
@@ -103,5 +103,7 @@ int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info);
 void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info);
 void btrfs_add_raid_kobjects(struct btrfs_fs_info *fs_info);
 void btrfs_sysfs_add_block_group_type(struct btrfs_block_group_cache *cache);
+int btrfs_sysfs_add_space_info_type(struct btrfs_fs_info *fs_info,
+				    struct btrfs_space_info *space_info);
 
 #endif
-- 
2.22.0


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

* [PATCH 06/13] btrfs: sysfs: unexport space_info_ktype
  2019-08-02 13:40 [PATCH 00/13] Sysfs cleanups David Sterba
                   ` (4 preceding siblings ...)
  2019-08-02 13:40 ` [PATCH 05/13] btrfs: factor out sysfs code for creating space infos David Sterba
@ 2019-08-02 13:40 ` David Sterba
  2019-08-02 13:40 ` [PATCH 07/13] btrfs: sysfs: replace direct access to feature set names with a helper David Sterba
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: David Sterba @ 2019-08-02 13:40 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

The last non-sysfs usage of space_info_ktype has been moved to a private
helper in previous patch so the variable can be made static.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/sysfs.c | 2 +-
 fs/btrfs/sysfs.h | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 24aaac281580..90822cdbf59e 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -375,7 +375,7 @@ static void space_info_release(struct kobject *kobj)
 	kfree(sinfo);
 }
 
-struct kobj_type space_info_ktype = {
+static struct kobj_type space_info_ktype = {
 	.sysfs_ops = &kobj_sysfs_ops,
 	.release = space_info_release,
 	.default_groups = space_info_groups,
diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h
index 928c8ab37fd9..0550358eb24e 100644
--- a/fs/btrfs/sysfs.h
+++ b/fs/btrfs/sysfs.h
@@ -85,7 +85,6 @@ attr_to_btrfs_feature_attr(struct attribute *attr)
 
 char *btrfs_printable_features(enum btrfs_feature_set set, u64 flags);
 extern const char * const btrfs_feature_set_names[FEAT_MAX];
-extern struct kobj_type space_info_ktype;
 int btrfs_sysfs_add_device_link(struct btrfs_fs_devices *fs_devices,
 		struct btrfs_device *one_device);
 int btrfs_sysfs_rm_device_link(struct btrfs_fs_devices *fs_devices,
-- 
2.22.0


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

* [PATCH 07/13] btrfs: sysfs: replace direct access to feature set names with a helper
  2019-08-02 13:40 [PATCH 00/13] Sysfs cleanups David Sterba
                   ` (5 preceding siblings ...)
  2019-08-02 13:40 ` [PATCH 06/13] btrfs: sysfs: unexport space_info_ktype David Sterba
@ 2019-08-02 13:40 ` David Sterba
  2019-08-02 13:40 ` [PATCH 08/13] btrfs: factor out sysfs code for sending device uevent David Sterba
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: David Sterba @ 2019-08-02 13:40 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

In order to unexport the feature type array, add a helper for the
enum-to-string conversion.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/ioctl.c | 2 +-
 fs/btrfs/sysfs.c | 7 ++++++-
 fs/btrfs/sysfs.h | 2 +-
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index ccac62d40dd2..fa091b6cc0ba 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -5258,7 +5258,7 @@ static int check_feature_bits(struct btrfs_fs_info *fs_info,
 			      u64 change_mask, u64 flags, u64 supported_flags,
 			      u64 safe_set, u64 safe_clear)
 {
-	const char *type = btrfs_feature_set_names[set];
+	const char *type = btrfs_feature_set_name(set);
 	char *names;
 	u64 disallowed, unsupported;
 	u64 set_mask = flags & change_mask;
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 90822cdbf59e..0d37403a4733 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -655,12 +655,17 @@ void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info)
 	btrfs_sysfs_rm_device_link(fs_info->fs_devices, NULL);
 }
 
-const char * const btrfs_feature_set_names[FEAT_MAX] = {
+static const char * const btrfs_feature_set_names[FEAT_MAX] = {
 	[FEAT_COMPAT]	 = "compat",
 	[FEAT_COMPAT_RO] = "compat_ro",
 	[FEAT_INCOMPAT]	 = "incompat",
 };
 
+const char * const btrfs_feature_set_name(enum btrfs_feature_set set)
+{
+	return btrfs_feature_set_names[set];
+}
+
 char *btrfs_printable_features(enum btrfs_feature_set set, u64 flags)
 {
 	size_t bufsize = 4096; /* safe max, 64 names * 64 bytes */
diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h
index 0550358eb24e..f17faa5d5264 100644
--- a/fs/btrfs/sysfs.h
+++ b/fs/btrfs/sysfs.h
@@ -84,7 +84,7 @@ attr_to_btrfs_feature_attr(struct attribute *attr)
 }
 
 char *btrfs_printable_features(enum btrfs_feature_set set, u64 flags);
-extern const char * const btrfs_feature_set_names[FEAT_MAX];
+const char * const btrfs_feature_set_name(enum btrfs_feature_set set);
 int btrfs_sysfs_add_device_link(struct btrfs_fs_devices *fs_devices,
 		struct btrfs_device *one_device);
 int btrfs_sysfs_rm_device_link(struct btrfs_fs_devices *fs_devices,
-- 
2.22.0


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

* [PATCH 08/13] btrfs: factor out sysfs code for sending device uevent
  2019-08-02 13:40 [PATCH 00/13] Sysfs cleanups David Sterba
                   ` (6 preceding siblings ...)
  2019-08-02 13:40 ` [PATCH 07/13] btrfs: sysfs: replace direct access to feature set names with a helper David Sterba
@ 2019-08-02 13:40 ` David Sterba
  2019-08-02 13:40 ` [PATCH 09/13] btrfs: factor out sysfs code for deleting block group and space infos David Sterba
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: David Sterba @ 2019-08-02 13:40 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

The device uevent belongs to the sysfs API.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/sysfs.c   | 11 +++++++++++
 fs/btrfs/sysfs.h   |  1 +
 fs/btrfs/volumes.c | 13 -------------
 3 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 0d37403a4733..0f7e97ceec4e 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -902,6 +902,17 @@ int btrfs_sysfs_add_device_link(struct btrfs_fs_devices *fs_devices,
 	return error;
 }
 
+void btrfs_kobject_uevent(struct block_device *bdev, enum kobject_action action)
+{
+	int ret;
+
+	ret = kobject_uevent(&disk_to_dev(bdev->bd_disk)->kobj, action);
+	if (ret)
+		pr_warn("BTRFS: Sending event '%d' to kobject: '%s' (%p): failed\n",
+			action, kobject_name(&disk_to_dev(bdev->bd_disk)->kobj),
+			&disk_to_dev(bdev->bd_disk)->kobj);
+}
+
 /* /sys/fs/btrfs/ entry */
 static struct kset *btrfs_kset;
 
diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h
index f17faa5d5264..371fa9db5bbd 100644
--- a/fs/btrfs/sysfs.h
+++ b/fs/btrfs/sysfs.h
@@ -95,6 +95,7 @@ int btrfs_sysfs_add_device(struct btrfs_fs_devices *fs_devs);
 void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs);
 void btrfs_sysfs_feature_update(struct btrfs_fs_info *fs_info,
 		u64 bit, enum btrfs_feature_set set);
+void btrfs_kobject_uevent(struct block_device *bdev, enum kobject_action action);
 
 int __init btrfs_init_sysfs(void);
 void __cold btrfs_exit_sysfs(void);
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index f85bbc819ab6..bc20e01f2f93 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -358,19 +358,6 @@ static void free_fs_devices(struct btrfs_fs_devices *fs_devices)
 	kfree(fs_devices);
 }
 
-static void btrfs_kobject_uevent(struct block_device *bdev,
-				 enum kobject_action action)
-{
-	int ret;
-
-	ret = kobject_uevent(&disk_to_dev(bdev->bd_disk)->kobj, action);
-	if (ret)
-		pr_warn("BTRFS: Sending event '%d' to kobject: '%s' (%p): failed\n",
-			action,
-			kobject_name(&disk_to_dev(bdev->bd_disk)->kobj),
-			&disk_to_dev(bdev->bd_disk)->kobj);
-}
-
 void __exit btrfs_cleanup_fs_uuids(void)
 {
 	struct btrfs_fs_devices *fs_devices;
-- 
2.22.0


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

* [PATCH 09/13] btrfs: factor out sysfs code for deleting block group and space infos
  2019-08-02 13:40 [PATCH 00/13] Sysfs cleanups David Sterba
                   ` (7 preceding siblings ...)
  2019-08-02 13:40 ` [PATCH 08/13] btrfs: factor out sysfs code for sending device uevent David Sterba
@ 2019-08-02 13:40 ` David Sterba
  2019-08-02 13:40 ` [PATCH 10/13] btrfs: factor out sysfs code for updating sprout fsid David Sterba
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: David Sterba @ 2019-08-02 13:40 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

The helpers to create block group and space info directories already
live in sysfs.c, move the deletion part there too.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/extent-tree.c | 14 +-------------
 fs/btrfs/sysfs.c       | 22 ++++++++++++++++++++++
 fs/btrfs/sysfs.h       |  1 +
 3 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 8ac496fddc59..3a711f5e7919 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -7744,8 +7744,6 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info)
 	btrfs_release_global_block_rsv(info);
 
 	while (!list_empty(&info->space_info)) {
-		int i;
-
 		space_info = list_entry(info->space_info.next,
 					struct btrfs_space_info,
 					list);
@@ -7759,17 +7757,7 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info)
 			    space_info->bytes_may_use > 0))
 			btrfs_dump_space_info(info, space_info, 0, 0);
 		list_del(&space_info->list);
-		for (i = 0; i < BTRFS_NR_RAID_TYPES; i++) {
-			struct kobject *kobj;
-			kobj = space_info->block_group_kobjs[i];
-			space_info->block_group_kobjs[i] = NULL;
-			if (kobj) {
-				kobject_del(kobj);
-				kobject_put(kobj);
-			}
-		}
-		kobject_del(&space_info->kobj);
-		kobject_put(&space_info->kobj);
+		btrfs_sysfs_remove_space_info(space_info);
 	}
 	return 0;
 }
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 0f7e97ceec4e..2490144863ae 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -789,6 +789,28 @@ void btrfs_sysfs_add_block_group_type(struct btrfs_block_group_cache *cache)
 	space_info->block_group_kobjs[index] = &rkobj->kobj;
 }
 
+/*
+ * Remove sysfs directories for all block group types of a given space info and
+ * the space info as well
+ */
+void btrfs_sysfs_remove_space_info(struct btrfs_space_info *space_info)
+{
+	int i;
+
+	for (i = 0; i < BTRFS_NR_RAID_TYPES; i++) {
+		struct kobject *kobj;
+
+		kobj = space_info->block_group_kobjs[i];
+		space_info->block_group_kobjs[i] = NULL;
+		if (kobj) {
+			kobject_del(kobj);
+			kobject_put(kobj);
+		}
+	}
+	kobject_del(&space_info->kobj);
+	kobject_put(&space_info->kobj);
+}
+
 static const char *alloc_name(u64 flags)
 {
 	switch (flags) {
diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h
index 371fa9db5bbd..857710e77775 100644
--- a/fs/btrfs/sysfs.h
+++ b/fs/btrfs/sysfs.h
@@ -105,5 +105,6 @@ void btrfs_add_raid_kobjects(struct btrfs_fs_info *fs_info);
 void btrfs_sysfs_add_block_group_type(struct btrfs_block_group_cache *cache);
 int btrfs_sysfs_add_space_info_type(struct btrfs_fs_info *fs_info,
 				    struct btrfs_space_info *space_info);
+void btrfs_sysfs_remove_space_info(struct btrfs_space_info *space_info);
 
 #endif
-- 
2.22.0


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

* [PATCH 10/13] btrfs: factor out sysfs code for updating sprout fsid
  2019-08-02 13:40 [PATCH 00/13] Sysfs cleanups David Sterba
                   ` (8 preceding siblings ...)
  2019-08-02 13:40 ` [PATCH 09/13] btrfs: factor out sysfs code for deleting block group and space infos David Sterba
@ 2019-08-02 13:40 ` David Sterba
  2019-08-02 13:40 ` [PATCH 11/13] btrfs: cleanup kobject.h includes David Sterba
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: David Sterba @ 2019-08-02 13:40 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

Wrap the fsid renaming code and move it to sysfs.c.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/sysfs.c   | 15 +++++++++++++++
 fs/btrfs/sysfs.h   |  2 ++
 fs/btrfs/volumes.c | 12 ++----------
 3 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 2490144863ae..b7eb921e3fd3 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -935,6 +935,21 @@ void btrfs_kobject_uevent(struct block_device *bdev, enum kobject_action action)
 			&disk_to_dev(bdev->bd_disk)->kobj);
 }
 
+void btrfs_sysfs_update_sprout_fsid(struct btrfs_fs_devices *fs_devices,
+				    const u8 *fsid)
+{
+	char fsid_buf[BTRFS_UUID_UNPARSED_SIZE];
+
+	/*
+	 * Sprouting changes fsid of the mounted filesystem, rename the fsid
+	 * directory
+	 */
+	snprintf(fsid_buf, BTRFS_UUID_UNPARSED_SIZE, "%pU", fsid);
+	if (kobject_rename(&fs_devices->fsid_kobj, fsid_buf))
+		btrfs_warn(fs_devices->fs_info,
+				"sysfs: failed to create fsid for sprout");
+}
+
 /* /sys/fs/btrfs/ entry */
 static struct kset *btrfs_kset;
 
diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h
index 857710e77775..aabc67a20ce5 100644
--- a/fs/btrfs/sysfs.h
+++ b/fs/btrfs/sysfs.h
@@ -93,6 +93,8 @@ int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs,
 				struct kobject *parent);
 int btrfs_sysfs_add_device(struct btrfs_fs_devices *fs_devs);
 void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs);
+void btrfs_sysfs_update_sprout_fsid(struct btrfs_fs_devices *fs_devices,
+				    const u8 *fsid);
 void btrfs_sysfs_feature_update(struct btrfs_fs_info *fs_info,
 		u64 bit, enum btrfs_feature_set set);
 void btrfs_kobject_uevent(struct block_device *bdev, enum kobject_action action);
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index bc20e01f2f93..d32eaffbbcef 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2680,22 +2680,14 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
 	}
 
 	if (seeding_dev) {
-		char fsid_buf[BTRFS_UUID_UNPARSED_SIZE];
-
 		ret = btrfs_finish_sprout(trans);
 		if (ret) {
 			btrfs_abort_transaction(trans, ret);
 			goto error_sysfs;
 		}
 
-		/* Sprouting would change fsid of the mounted root,
-		 * so rename the fsid on the sysfs
-		 */
-		snprintf(fsid_buf, BTRFS_UUID_UNPARSED_SIZE, "%pU",
-						fs_info->fs_devices->fsid);
-		if (kobject_rename(&fs_devices->fsid_kobj, fsid_buf))
-			btrfs_warn(fs_info,
-				   "sysfs: failed to create fsid for sprout");
+		btrfs_sysfs_update_sprout_fsid(fs_devices,
+				fs_info->fs_devices->fsid);
 	}
 
 	ret = btrfs_commit_transaction(trans);
-- 
2.22.0


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

* [PATCH 11/13] btrfs: cleanup kobject.h includes
  2019-08-02 13:40 [PATCH 00/13] Sysfs cleanups David Sterba
                   ` (9 preceding siblings ...)
  2019-08-02 13:40 ` [PATCH 10/13] btrfs: factor out sysfs code for updating sprout fsid David Sterba
@ 2019-08-02 13:40 ` David Sterba
  2019-08-02 13:40 ` [PATCH 12/13] btrfs: sysfs: move helper macros to sysfs.c David Sterba
  2019-08-02 13:40 ` [PATCH 13/13] btrfs: sysfs: move type conversion helpers " David Sterba
  12 siblings, 0 replies; 14+ messages in thread
From: David Sterba @ 2019-08-02 13:40 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

The kobject should be pulled in via sysfs.h and that needs to include it
because it needs various definitions like kobj_attribute or kobject.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/ctree.h | 1 -
 fs/btrfs/sysfs.c | 1 -
 fs/btrfs/sysfs.h | 2 ++
 3 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index a61bf19a7ef6..e32d992a3597 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -16,7 +16,6 @@
 #include <linux/backing-dev.h>
 #include <linux/wait.h>
 #include <linux/slab.h>
-#include <linux/kobject.h>
 #include <trace/events/btrfs.h>
 #include <asm/kmap_types.h>
 #include <asm/unaligned.h>
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index b7eb921e3fd3..624ab9e29e21 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -7,7 +7,6 @@
 #include <linux/slab.h>
 #include <linux/spinlock.h>
 #include <linux/completion.h>
-#include <linux/kobject.h>
 #include <linux/bug.h>
 #include <linux/debugfs.h>
 
diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h
index aabc67a20ce5..ab5e39b5496a 100644
--- a/fs/btrfs/sysfs.h
+++ b/fs/btrfs/sysfs.h
@@ -3,6 +3,8 @@
 #ifndef BTRFS_SYSFS_H
 #define BTRFS_SYSFS_H
 
+#include <linux/kobject.h>
+
 /*
  * Data exported through sysfs
  */
-- 
2.22.0


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

* [PATCH 12/13] btrfs: sysfs: move helper macros to sysfs.c
  2019-08-02 13:40 [PATCH 00/13] Sysfs cleanups David Sterba
                   ` (10 preceding siblings ...)
  2019-08-02 13:40 ` [PATCH 11/13] btrfs: cleanup kobject.h includes David Sterba
@ 2019-08-02 13:40 ` David Sterba
  2019-08-02 13:40 ` [PATCH 13/13] btrfs: sysfs: move type conversion helpers " David Sterba
  12 siblings, 0 replies; 14+ messages in thread
From: David Sterba @ 2019-08-02 13:40 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

None of the macros is used outside of sysfs.c.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/sysfs.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++
 fs/btrfs/sysfs.h | 50 ------------------------------------------------
 2 files changed, 49 insertions(+), 50 deletions(-)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 624ab9e29e21..e306e6e173cf 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -17,6 +17,55 @@
 #include "volumes.h"
 #include "space-info.h"
 
+struct btrfs_feature_attr {
+	struct kobj_attribute kobj_attr;
+	enum btrfs_feature_set feature_set;
+	u64 feature_bit;
+};
+
+/* For raid type sysfs entries */
+struct raid_kobject {
+	u64 flags;
+	struct kobject kobj;
+	struct list_head list;
+};
+
+#define __INIT_KOBJ_ATTR(_name, _mode, _show, _store)			\
+{									\
+	.attr	= { .name = __stringify(_name), .mode = _mode },	\
+	.show	= _show,						\
+	.store	= _store,						\
+}
+
+#define BTRFS_ATTR_RW(_prefix, _name, _show, _store)			\
+	static struct kobj_attribute btrfs_attr_##_prefix##_##_name =	\
+			__INIT_KOBJ_ATTR(_name, 0644, _show, _store)
+
+#define BTRFS_ATTR(_prefix, _name, _show)				\
+	static struct kobj_attribute btrfs_attr_##_prefix##_##_name =	\
+			__INIT_KOBJ_ATTR(_name, 0444, _show, NULL)
+
+#define BTRFS_ATTR_PTR(_prefix, _name)					\
+	(&btrfs_attr_##_prefix##_##_name.attr)
+
+#define BTRFS_FEAT_ATTR(_name, _feature_set, _feature_prefix, _feature_bit)  \
+static struct btrfs_feature_attr btrfs_attr_features_##_name = {	     \
+	.kobj_attr = __INIT_KOBJ_ATTR(_name, S_IRUGO,			     \
+				      btrfs_feature_attr_show,		     \
+				      btrfs_feature_attr_store),	     \
+	.feature_set	= _feature_set,					     \
+	.feature_bit	= _feature_prefix ##_## _feature_bit,		     \
+}
+#define BTRFS_FEAT_ATTR_PTR(_name)					     \
+	(&btrfs_attr_features_##_name.kobj_attr.attr)
+
+#define BTRFS_FEAT_ATTR_COMPAT(name, feature) \
+	BTRFS_FEAT_ATTR(name, FEAT_COMPAT, BTRFS_FEATURE_COMPAT, feature)
+#define BTRFS_FEAT_ATTR_COMPAT_RO(name, feature) \
+	BTRFS_FEAT_ATTR(name, FEAT_COMPAT_RO, BTRFS_FEATURE_COMPAT_RO, feature)
+#define BTRFS_FEAT_ATTR_INCOMPAT(name, feature) \
+	BTRFS_FEAT_ATTR(name, FEAT_INCOMPAT, BTRFS_FEATURE_INCOMPAT, feature)
+
 static inline struct btrfs_fs_info *to_fs_info(struct kobject *kobj);
 static inline struct btrfs_fs_devices *to_fs_devs(struct kobject *kobj);
 
diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h
index ab5e39b5496a..ab0ea53b7d4b 100644
--- a/fs/btrfs/sysfs.h
+++ b/fs/btrfs/sysfs.h
@@ -17,56 +17,6 @@ enum btrfs_feature_set {
 	FEAT_MAX
 };
 
-#define __INIT_KOBJ_ATTR(_name, _mode, _show, _store)			\
-{									\
-	.attr	= { .name = __stringify(_name), .mode = _mode },	\
-	.show	= _show,						\
-	.store	= _store,						\
-}
-
-#define BTRFS_ATTR_RW(_prefix, _name, _show, _store)			\
-	static struct kobj_attribute btrfs_attr_##_prefix##_##_name =	\
-			__INIT_KOBJ_ATTR(_name, 0644, _show, _store)
-
-#define BTRFS_ATTR(_prefix, _name, _show)				\
-	static struct kobj_attribute btrfs_attr_##_prefix##_##_name =	\
-			__INIT_KOBJ_ATTR(_name, 0444, _show, NULL)
-
-#define BTRFS_ATTR_PTR(_prefix, _name)					\
-	(&btrfs_attr_##_prefix##_##_name.attr)
-
-
-struct btrfs_feature_attr {
-	struct kobj_attribute kobj_attr;
-	enum btrfs_feature_set feature_set;
-	u64 feature_bit;
-};
-
-/* For raid type sysfs entries */
-struct raid_kobject {
-	u64 flags;
-	struct kobject kobj;
-	struct list_head list;
-};
-
-#define BTRFS_FEAT_ATTR(_name, _feature_set, _feature_prefix, _feature_bit)  \
-static struct btrfs_feature_attr btrfs_attr_features_##_name = {	     \
-	.kobj_attr = __INIT_KOBJ_ATTR(_name, S_IRUGO,			     \
-				      btrfs_feature_attr_show,		     \
-				      btrfs_feature_attr_store),	     \
-	.feature_set	= _feature_set,					     \
-	.feature_bit	= _feature_prefix ##_## _feature_bit,		     \
-}
-#define BTRFS_FEAT_ATTR_PTR(_name)					     \
-	(&btrfs_attr_features_##_name.kobj_attr.attr)
-
-#define BTRFS_FEAT_ATTR_COMPAT(name, feature) \
-	BTRFS_FEAT_ATTR(name, FEAT_COMPAT, BTRFS_FEATURE_COMPAT, feature)
-#define BTRFS_FEAT_ATTR_COMPAT_RO(name, feature) \
-	BTRFS_FEAT_ATTR(name, FEAT_COMPAT_RO, BTRFS_FEATURE_COMPAT_RO, feature)
-#define BTRFS_FEAT_ATTR_INCOMPAT(name, feature) \
-	BTRFS_FEAT_ATTR(name, FEAT_INCOMPAT, BTRFS_FEATURE_INCOMPAT, feature)
-
 /* convert from attribute */
 static inline struct btrfs_feature_attr *
 to_btrfs_feature_attr(struct kobj_attribute *a)
-- 
2.22.0


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

* [PATCH 13/13] btrfs: sysfs: move type conversion helpers to sysfs.c
  2019-08-02 13:40 [PATCH 00/13] Sysfs cleanups David Sterba
                   ` (11 preceding siblings ...)
  2019-08-02 13:40 ` [PATCH 12/13] btrfs: sysfs: move helper macros to sysfs.c David Sterba
@ 2019-08-02 13:40 ` David Sterba
  12 siblings, 0 replies; 14+ messages in thread
From: David Sterba @ 2019-08-02 13:40 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/sysfs.c | 17 +++++++++++++++++
 fs/btrfs/sysfs.h | 18 ------------------
 2 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index e306e6e173cf..335450ad9d2d 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -69,6 +69,23 @@ static struct btrfs_feature_attr btrfs_attr_features_##_name = {	     \
 static inline struct btrfs_fs_info *to_fs_info(struct kobject *kobj);
 static inline struct btrfs_fs_devices *to_fs_devs(struct kobject *kobj);
 
+/* convert from attribute */
+static struct btrfs_feature_attr *to_btrfs_feature_attr(struct kobj_attribute *a)
+{
+	return container_of(a, struct btrfs_feature_attr, kobj_attr);
+}
+
+static struct kobj_attribute *attr_to_btrfs_attr(struct attribute *attr)
+{
+	return container_of(attr, struct kobj_attribute, attr);
+}
+
+static struct btrfs_feature_attr *attr_to_btrfs_feature_attr(
+		struct attribute *attr)
+{
+	return to_btrfs_feature_attr(attr_to_btrfs_attr(attr));
+}
+
 static u64 get_features(struct btrfs_fs_info *fs_info,
 			enum btrfs_feature_set set)
 {
diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h
index ab0ea53b7d4b..b8513c5fb2b0 100644
--- a/fs/btrfs/sysfs.h
+++ b/fs/btrfs/sysfs.h
@@ -17,24 +17,6 @@ enum btrfs_feature_set {
 	FEAT_MAX
 };
 
-/* convert from attribute */
-static inline struct btrfs_feature_attr *
-to_btrfs_feature_attr(struct kobj_attribute *a)
-{
-	return container_of(a, struct btrfs_feature_attr, kobj_attr);
-}
-
-static inline struct kobj_attribute *attr_to_btrfs_attr(struct attribute *attr)
-{
-	return container_of(attr, struct kobj_attribute, attr);
-}
-
-static inline struct btrfs_feature_attr *
-attr_to_btrfs_feature_attr(struct attribute *attr)
-{
-	return to_btrfs_feature_attr(attr_to_btrfs_attr(attr));
-}
-
 char *btrfs_printable_features(enum btrfs_feature_set set, u64 flags);
 const char * const btrfs_feature_set_name(enum btrfs_feature_set set);
 int btrfs_sysfs_add_device_link(struct btrfs_fs_devices *fs_devices,
-- 
2.22.0


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

end of thread, other threads:[~2019-08-02 13:40 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-02 13:40 [PATCH 00/13] Sysfs cleanups David Sterba
2019-08-02 13:40 ` [PATCH 01/13] btrfs: move sysfs declarations out of ctree.h David Sterba
2019-08-02 13:40 ` [PATCH 02/13] btrfs: move btrfs_add_raid_kobjects to sysfs.c David Sterba
2019-08-02 13:40 ` [PATCH 03/13] btrfs: factor sysfs code out of link_block_group David Sterba
2019-08-02 13:40 ` [PATCH 04/13] btrfs: sysfs: unexport btrfs_raid_ktype David Sterba
2019-08-02 13:40 ` [PATCH 05/13] btrfs: factor out sysfs code for creating space infos David Sterba
2019-08-02 13:40 ` [PATCH 06/13] btrfs: sysfs: unexport space_info_ktype David Sterba
2019-08-02 13:40 ` [PATCH 07/13] btrfs: sysfs: replace direct access to feature set names with a helper David Sterba
2019-08-02 13:40 ` [PATCH 08/13] btrfs: factor out sysfs code for sending device uevent David Sterba
2019-08-02 13:40 ` [PATCH 09/13] btrfs: factor out sysfs code for deleting block group and space infos David Sterba
2019-08-02 13:40 ` [PATCH 10/13] btrfs: factor out sysfs code for updating sprout fsid David Sterba
2019-08-02 13:40 ` [PATCH 11/13] btrfs: cleanup kobject.h includes David Sterba
2019-08-02 13:40 ` [PATCH 12/13] btrfs: sysfs: move helper macros to sysfs.c David Sterba
2019-08-02 13:40 ` [PATCH 13/13] btrfs: sysfs: move type conversion helpers " David Sterba

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