linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: David Sterba <dsterba@suse.com>
Subject: [PATCH 09/13] btrfs: factor out sysfs code for deleting block group and space infos
Date: Fri,  2 Aug 2019 15:40:21 +0200	[thread overview]
Message-ID: <4e6e4f7834c7f877e278031010b357ffeed5ed82.1564752900.git.dsterba@suse.com> (raw)
In-Reply-To: <cover.1564752900.git.dsterba@suse.com>

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


  parent reply	other threads:[~2019-08-02 13:39 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` David Sterba [this message]
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

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=4e6e4f7834c7f877e278031010b357ffeed5ed82.1564752900.git.dsterba@suse.com \
    --to=dsterba@suse.com \
    --cc=linux-btrfs@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).