All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: Rename __btrfs_alloc_chunk to btrfs_alloc_chunk
@ 2020-03-02 10:29 Nikolay Borisov
  2020-03-02 19:47 ` David Sterba
  0 siblings, 1 reply; 2+ messages in thread
From: Nikolay Borisov @ 2020-03-02 10:29 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Nikolay Borisov

Having btrfs_alloc_chunk doesn't bring any value since it
encapsulates a lockdep assert and a call to find_next_chunk. Simply
rename the internal __btrfs_alloc_chunk function to the public one
and remove it's 2nd parameter as all callers always pass the return
value of find_next_chunk. Finally, migrate the call to
lockdep_assert_held so as to not lose the check.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 fs/btrfs/volumes.c | 38 +++++++++++++-------------------------
 1 file changed, 13 insertions(+), 25 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 37e79de3256f..267847c72c22 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -5113,8 +5113,7 @@ static int create_chunk(struct btrfs_trans_handle *trans,
 	return ret;
 }
 
-static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
-			       u64 start, u64 type)
+int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, u64 type)
 {
 	struct btrfs_fs_info *info = trans->fs_info;
 	struct btrfs_fs_devices *fs_devices = info->fs_devices;
@@ -5122,6 +5121,8 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
 	struct alloc_chunk_ctl ctl;
 	int ret;
 
+	lockdep_assert_held(&info->chunk_mutex);
+
 	if (!alloc_profile_is_valid(type, 0)) {
 		ASSERT(0);
 		return -EINVAL;
@@ -5139,7 +5140,7 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
 		return -EINVAL;
 	}
 
-	ctl.start = start;
+	ctl.start = find_next_chunk(info);
 	ctl.type = type;
 	init_alloc_chunk_ctl(fs_devices, &ctl);
 
@@ -5163,6 +5164,13 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
 	return ret;
 }
 
+/*
+ * Chunk allocation falls into two parts. The first part does work
+ * that makes the new allocated chunk usable, but does not do any operation
+ * that modifies the chunk tree. The second part does the work that
+ * requires modifying the chunk tree. This division is important for the
+ * bootstrap process of adding storage to a seed btrfs.
+ */
 int btrfs_finish_chunk_alloc(struct btrfs_trans_handle *trans,
 			     u64 chunk_offset, u64 chunk_size)
 {
@@ -5261,39 +5269,19 @@ int btrfs_finish_chunk_alloc(struct btrfs_trans_handle *trans,
 	return ret;
 }
 
-/*
- * Chunk allocation falls into two parts. The first part does work
- * that makes the new allocated chunk usable, but does not do any operation
- * that modifies the chunk tree. The second part does the work that
- * requires modifying the chunk tree. This division is important for the
- * bootstrap process of adding storage to a seed btrfs.
- */
-int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, u64 type)
-{
-	u64 chunk_offset;
-
-	lockdep_assert_held(&trans->fs_info->chunk_mutex);
-	chunk_offset = find_next_chunk(trans->fs_info);
-	return __btrfs_alloc_chunk(trans, chunk_offset, type);
-}
-
 static noinline int init_first_rw_device(struct btrfs_trans_handle *trans)
 {
 	struct btrfs_fs_info *fs_info = trans->fs_info;
-	u64 chunk_offset;
-	u64 sys_chunk_offset;
 	u64 alloc_profile;
 	int ret;
 
-	chunk_offset = find_next_chunk(fs_info);
 	alloc_profile = btrfs_metadata_alloc_profile(fs_info);
-	ret = __btrfs_alloc_chunk(trans, chunk_offset, alloc_profile);
+	ret = btrfs_alloc_chunk(trans, alloc_profile);
 	if (ret)
 		return ret;
 
-	sys_chunk_offset = find_next_chunk(fs_info);
 	alloc_profile = btrfs_system_alloc_profile(fs_info);
-	ret = __btrfs_alloc_chunk(trans, sys_chunk_offset, alloc_profile);
+	ret = btrfs_alloc_chunk(trans, alloc_profile);
 	return ret;
 }
 
-- 
2.17.1


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

* Re: [PATCH] btrfs: Rename __btrfs_alloc_chunk to btrfs_alloc_chunk
  2020-03-02 10:29 [PATCH] btrfs: Rename __btrfs_alloc_chunk to btrfs_alloc_chunk Nikolay Borisov
@ 2020-03-02 19:47 ` David Sterba
  0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2020-03-02 19:47 UTC (permalink / raw)
  To: Nikolay Borisov; +Cc: linux-btrfs

On Mon, Mar 02, 2020 at 12:29:25PM +0200, Nikolay Borisov wrote:
> Having btrfs_alloc_chunk doesn't bring any value since it
> encapsulates a lockdep assert and a call to find_next_chunk. Simply
> rename the internal __btrfs_alloc_chunk function to the public one
> and remove it's 2nd parameter as all callers always pass the return
> value of find_next_chunk. Finally, migrate the call to
> lockdep_assert_held so as to not lose the check.
> 
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>

Added to misc-next, thanks.

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

end of thread, other threads:[~2020-03-02 19:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-02 10:29 [PATCH] btrfs: Rename __btrfs_alloc_chunk to btrfs_alloc_chunk Nikolay Borisov
2020-03-02 19:47 ` David Sterba

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.