* [PATCH 00/27] Struct btrfs_path auto cleaning conversions
@ 2025-02-26 9:50 David Sterba
2025-02-26 9:50 ` [PATCH 01/27] btrfs: use BTRFS_PATH_AUTO_FREE in sample_block_group_extent_item() David Sterba
` (28 more replies)
0 siblings, 29 replies; 34+ messages in thread
From: David Sterba @ 2025-02-26 9:50 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
We have the scoped freeing for struct btrfs_path but it's not used as
much as it could. This patchset converts the easy cases and it's also a
preview if we really want to do that. It makes understanding the exit
paths a bit less obvious, but so far I think it's manageable.
The path is used in many functions and following a few simple patterns,
with the macro BTRFS_PATH_AUTO_FREE quite visible among the
declarations, so it's nothing hard to be aware of that when reading the
code.
The conversion has been done on half of the files, so if somebody wants
to continue, feel free. I've skipped functions with more complicated
branching where the auto freeing would make it worse.
David Sterba (27):
btrfs: use BTRFS_PATH_AUTO_FREE in sample_block_group_extent_item()
btrfs: use BTRFS_PATH_AUTO_FREE in insert_dev_extent()
btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_setup_space_cache()
btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_start_dirty_block_groups()
btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_write_dirty_block_groups()
btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_insert_item()
btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_commit_inode_delayed_items()
btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_init_dev_replace()
btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_run_dev_replace()
btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_check_dir_item_collision()
btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_read_tree_root()
btrfs: use BTRFS_PATH_AUTO_FREE in load_global_roots()
btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_init_root_free_objectid()
btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_get_name()
btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_lookup_data_extent()
btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_lookup_extent_info()
btrfs: use BTRFS_PATH_AUTO_FREE in __btrfs_inc_extent_ref()
btrfs: use BTRFS_PATH_AUTO_FREE in run_delayed_extent_op()
btrfs: use BTRFS_PATH_AUTO_FREE in check_ref_exists()
btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_drop_subtree()
btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_insert_hole_extent()
btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_lookup_bio_sums()
btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_del_csums()
btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_remove_free_space_inode()
btrfs: use BTRFS_PATH_AUTO_FREE in populate_free_space_tree()
btrfs: use BTRFS_PATH_AUTO_FREE in clear_free_space_tree()
btrfs: use BTRFS_PATH_AUTO_FREE in load_free_space_tree()
fs/btrfs/block-group.c | 20 ++++++----------
fs/btrfs/ctree.c | 3 +--
fs/btrfs/delayed-inode.c | 3 +--
fs/btrfs/dev-replace.c | 32 ++++++++++---------------
fs/btrfs/dir-item.c | 24 +++++++------------
fs/btrfs/disk-io.c | 29 ++++++++++-------------
fs/btrfs/export.c | 10 +++-----
fs/btrfs/extent-tree.c | 47 ++++++++++++++-----------------------
fs/btrfs/file-item.c | 17 +++++---------
fs/btrfs/free-space-cache.c | 13 ++++------
fs/btrfs/free-space-tree.c | 45 ++++++++++++++---------------------
11 files changed, 91 insertions(+), 152 deletions(-)
--
2.47.1
^ permalink raw reply [flat|nested] 34+ messages in thread
* [PATCH 01/27] btrfs: use BTRFS_PATH_AUTO_FREE in sample_block_group_extent_item()
2025-02-26 9:50 [PATCH 00/27] Struct btrfs_path auto cleaning conversions David Sterba
@ 2025-02-26 9:50 ` David Sterba
2025-02-26 9:50 ` [PATCH 02/27] btrfs: use BTRFS_PATH_AUTO_FREE in insert_dev_extent() David Sterba
` (27 subsequent siblings)
28 siblings, 0 replies; 34+ messages in thread
From: David Sterba @ 2025-02-26 9:50 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
This is the trivial pattern for path auto free, initialize at the
beginning and free at the end.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/block-group.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
index 18f58674a16c..cd20bf9289bd 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -584,7 +584,7 @@ static int sample_block_group_extent_item(struct btrfs_caching_control *caching_
struct btrfs_root *extent_root;
u64 search_offset;
u64 search_end = block_group->start + block_group->length;
- struct btrfs_path *path;
+ BTRFS_PATH_AUTO_FREE(path);
struct btrfs_key search_key;
int ret = 0;
@@ -626,7 +626,6 @@ static int sample_block_group_extent_item(struct btrfs_caching_control *caching_
lockdep_assert_held(&caching_ctl->mutex);
lockdep_assert_held_read(&fs_info->commit_root_sem);
- btrfs_free_path(path);
return ret;
}
--
2.47.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 02/27] btrfs: use BTRFS_PATH_AUTO_FREE in insert_dev_extent()
2025-02-26 9:50 [PATCH 00/27] Struct btrfs_path auto cleaning conversions David Sterba
2025-02-26 9:50 ` [PATCH 01/27] btrfs: use BTRFS_PATH_AUTO_FREE in sample_block_group_extent_item() David Sterba
@ 2025-02-26 9:50 ` David Sterba
2025-02-26 9:50 ` [PATCH 03/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_setup_space_cache() David Sterba
` (26 subsequent siblings)
28 siblings, 0 replies; 34+ messages in thread
From: David Sterba @ 2025-02-26 9:50 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
This is the trivial pattern for path auto free, initialize at the
beginning and free at the end with simple goto -> return conversions.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/block-group.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
index cd20bf9289bd..9c689e7982c2 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -2640,7 +2640,7 @@ static int insert_dev_extent(struct btrfs_trans_handle *trans,
{
struct btrfs_fs_info *fs_info = device->fs_info;
struct btrfs_root *root = fs_info->dev_root;
- struct btrfs_path *path;
+ BTRFS_PATH_AUTO_FREE(path);
struct btrfs_dev_extent *extent;
struct extent_buffer *leaf;
struct btrfs_key key;
@@ -2657,7 +2657,7 @@ static int insert_dev_extent(struct btrfs_trans_handle *trans,
key.offset = start;
ret = btrfs_insert_empty_item(trans, root, path, &key, sizeof(*extent));
if (ret)
- goto out;
+ return ret;
leaf = path->nodes[0];
extent = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_dev_extent);
@@ -2665,10 +2665,8 @@ static int insert_dev_extent(struct btrfs_trans_handle *trans,
btrfs_set_dev_extent_chunk_objectid(leaf, extent,
BTRFS_FIRST_CHUNK_TREE_OBJECTID);
btrfs_set_dev_extent_chunk_offset(leaf, extent, chunk_offset);
-
btrfs_set_dev_extent_length(leaf, extent, num_bytes);
-out:
- btrfs_free_path(path);
+
return ret;
}
--
2.47.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 03/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_setup_space_cache()
2025-02-26 9:50 [PATCH 00/27] Struct btrfs_path auto cleaning conversions David Sterba
2025-02-26 9:50 ` [PATCH 01/27] btrfs: use BTRFS_PATH_AUTO_FREE in sample_block_group_extent_item() David Sterba
2025-02-26 9:50 ` [PATCH 02/27] btrfs: use BTRFS_PATH_AUTO_FREE in insert_dev_extent() David Sterba
@ 2025-02-26 9:50 ` David Sterba
2025-02-26 9:50 ` [PATCH 04/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_start_dirty_block_groups() David Sterba
` (25 subsequent siblings)
28 siblings, 0 replies; 34+ messages in thread
From: David Sterba @ 2025-02-26 9:50 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
This is the trivial pattern for path auto free, initialize at the
beginning and free at the end.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/block-group.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
index 9c689e7982c2..d99e5ed307d5 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -3303,7 +3303,7 @@ int btrfs_setup_space_cache(struct btrfs_trans_handle *trans)
struct btrfs_fs_info *fs_info = trans->fs_info;
struct btrfs_block_group *cache, *tmp;
struct btrfs_transaction *cur_trans = trans->transaction;
- struct btrfs_path *path;
+ BTRFS_PATH_AUTO_FREE(path);
if (list_empty(&cur_trans->dirty_bgs) ||
!btrfs_test_opt(fs_info, SPACE_CACHE))
@@ -3320,7 +3320,6 @@ int btrfs_setup_space_cache(struct btrfs_trans_handle *trans)
cache_save_setup(cache, trans, path);
}
- btrfs_free_path(path);
return 0;
}
--
2.47.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 04/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_start_dirty_block_groups()
2025-02-26 9:50 [PATCH 00/27] Struct btrfs_path auto cleaning conversions David Sterba
` (2 preceding siblings ...)
2025-02-26 9:50 ` [PATCH 03/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_setup_space_cache() David Sterba
@ 2025-02-26 9:50 ` David Sterba
2025-02-26 9:50 ` [PATCH 05/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_write_dirty_block_groups() David Sterba
` (24 subsequent siblings)
28 siblings, 0 replies; 34+ messages in thread
From: David Sterba @ 2025-02-26 9:50 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
This is the trivial pattern for path auto free, initialize at the
beginning and free at the end.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/block-group.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
index d99e5ed307d5..95b14e3351b5 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -3342,7 +3342,7 @@ int btrfs_start_dirty_block_groups(struct btrfs_trans_handle *trans)
struct btrfs_transaction *cur_trans = trans->transaction;
int ret = 0;
int should_put;
- struct btrfs_path *path = NULL;
+ BTRFS_PATH_AUTO_FREE(path);
LIST_HEAD(dirty);
struct list_head *io = &cur_trans->io_bgs;
int loops = 0;
@@ -3497,7 +3497,6 @@ int btrfs_start_dirty_block_groups(struct btrfs_trans_handle *trans)
btrfs_cleanup_dirty_bgs(cur_trans, fs_info);
}
- btrfs_free_path(path);
return ret;
}
--
2.47.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 05/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_write_dirty_block_groups()
2025-02-26 9:50 [PATCH 00/27] Struct btrfs_path auto cleaning conversions David Sterba
` (3 preceding siblings ...)
2025-02-26 9:50 ` [PATCH 04/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_start_dirty_block_groups() David Sterba
@ 2025-02-26 9:50 ` David Sterba
2025-02-26 9:50 ` [PATCH 06/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_insert_item() David Sterba
` (23 subsequent siblings)
28 siblings, 0 replies; 34+ messages in thread
From: David Sterba @ 2025-02-26 9:50 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
This is the trivial pattern for path auto free, initialize at the
beginning and free at the end.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/block-group.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
index 95b14e3351b5..50398aa2fb89 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -3507,7 +3507,7 @@ int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans)
struct btrfs_transaction *cur_trans = trans->transaction;
int ret = 0;
int should_put;
- struct btrfs_path *path;
+ BTRFS_PATH_AUTO_FREE(path);
struct list_head *io = &cur_trans->io_bgs;
path = btrfs_alloc_path();
@@ -3619,7 +3619,6 @@ int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans)
btrfs_put_block_group(cache);
}
- btrfs_free_path(path);
return ret;
}
--
2.47.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 06/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_insert_item()
2025-02-26 9:50 [PATCH 00/27] Struct btrfs_path auto cleaning conversions David Sterba
` (4 preceding siblings ...)
2025-02-26 9:50 ` [PATCH 05/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_write_dirty_block_groups() David Sterba
@ 2025-02-26 9:50 ` David Sterba
2025-02-26 9:51 ` [PATCH 07/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_commit_inode_delayed_items() David Sterba
` (22 subsequent siblings)
28 siblings, 0 replies; 34+ messages in thread
From: David Sterba @ 2025-02-26 9:50 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
This is the trivial pattern for path auto free, initialize at the
beginning and free at the end.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/ctree.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 3dc5a35dd19b..4d02227e9498 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -4306,7 +4306,7 @@ int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
u32 data_size)
{
int ret = 0;
- struct btrfs_path *path;
+ BTRFS_PATH_AUTO_FREE(path);
struct extent_buffer *leaf;
unsigned long ptr;
@@ -4320,7 +4320,6 @@ int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
write_extent_buffer(leaf, data, ptr, data_size);
btrfs_mark_buffer_dirty(trans, leaf);
}
- btrfs_free_path(path);
return ret;
}
--
2.47.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 07/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_commit_inode_delayed_items()
2025-02-26 9:50 [PATCH 00/27] Struct btrfs_path auto cleaning conversions David Sterba
` (5 preceding siblings ...)
2025-02-26 9:50 ` [PATCH 06/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_insert_item() David Sterba
@ 2025-02-26 9:51 ` David Sterba
2025-02-26 9:51 ` [PATCH 08/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_init_dev_replace() David Sterba
` (21 subsequent siblings)
28 siblings, 0 replies; 34+ messages in thread
From: David Sterba @ 2025-02-26 9:51 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
This is the trivial pattern for path auto free, initialize at the
beginning and free at the end.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/delayed-inode.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
index 1a65f209339b..3f1551d8a5c6 100644
--- a/fs/btrfs/delayed-inode.c
+++ b/fs/btrfs/delayed-inode.c
@@ -1211,7 +1211,7 @@ int btrfs_commit_inode_delayed_items(struct btrfs_trans_handle *trans,
struct btrfs_inode *inode)
{
struct btrfs_delayed_node *delayed_node = btrfs_get_delayed_node(inode);
- struct btrfs_path *path;
+ BTRFS_PATH_AUTO_FREE(path);
struct btrfs_block_rsv *block_rsv;
int ret;
@@ -1238,7 +1238,6 @@ int btrfs_commit_inode_delayed_items(struct btrfs_trans_handle *trans,
ret = __btrfs_commit_inode_delayed_items(trans, path, delayed_node);
btrfs_release_delayed_node(delayed_node);
- btrfs_free_path(path);
trans->block_rsv = block_rsv;
return ret;
--
2.47.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 08/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_init_dev_replace()
2025-02-26 9:50 [PATCH 00/27] Struct btrfs_path auto cleaning conversions David Sterba
` (6 preceding siblings ...)
2025-02-26 9:51 ` [PATCH 07/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_commit_inode_delayed_items() David Sterba
@ 2025-02-26 9:51 ` David Sterba
2025-02-26 9:51 ` [PATCH 09/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_run_dev_replace() David Sterba
` (20 subsequent siblings)
28 siblings, 0 replies; 34+ messages in thread
From: David Sterba @ 2025-02-26 9:51 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
This is the trivial pattern for path auto free, initialize at the
beginning and free at the end with simple goto -> return conversions.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/dev-replace.c | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index f86fbea0b3de..147c5494adf9 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -76,7 +76,7 @@ int btrfs_init_dev_replace(struct btrfs_fs_info *fs_info)
struct extent_buffer *eb;
int slot;
int ret = 0;
- struct btrfs_path *path = NULL;
+ BTRFS_PATH_AUTO_FREE(path);
int item_size;
struct btrfs_dev_replace_item *ptr;
u64 src_devid;
@@ -85,10 +85,8 @@ int btrfs_init_dev_replace(struct btrfs_fs_info *fs_info)
return 0;
path = btrfs_alloc_path();
- if (!path) {
- ret = -ENOMEM;
- goto out;
- }
+ if (!path)
+ return -ENOMEM;
key.objectid = 0;
key.type = BTRFS_DEV_REPLACE_KEY;
@@ -103,8 +101,7 @@ int btrfs_init_dev_replace(struct btrfs_fs_info *fs_info)
if (btrfs_find_device(fs_info->fs_devices, &args)) {
btrfs_err(fs_info,
"found replace target device without a valid replace item");
- ret = -EUCLEAN;
- goto out;
+ return -EUCLEAN;
}
ret = 0;
dev_replace->replace_state =
@@ -123,7 +120,7 @@ int btrfs_init_dev_replace(struct btrfs_fs_info *fs_info)
dev_replace->tgtdev = NULL;
dev_replace->is_valid = 0;
dev_replace->item_needs_writeback = 0;
- goto out;
+ return ret;
}
slot = path->slots[0];
eb = path->nodes[0];
@@ -226,8 +223,6 @@ int btrfs_init_dev_replace(struct btrfs_fs_info *fs_info)
break;
}
-out:
- btrfs_free_path(path);
return ret;
}
--
2.47.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 09/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_run_dev_replace()
2025-02-26 9:50 [PATCH 00/27] Struct btrfs_path auto cleaning conversions David Sterba
` (7 preceding siblings ...)
2025-02-26 9:51 ` [PATCH 08/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_init_dev_replace() David Sterba
@ 2025-02-26 9:51 ` David Sterba
2025-02-26 9:51 ` [PATCH 10/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_check_dir_item_collision() David Sterba
` (19 subsequent siblings)
28 siblings, 0 replies; 34+ messages in thread
From: David Sterba @ 2025-02-26 9:51 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
This is the trivial pattern for path auto free, initialize at the
beginning and free at the end with simple goto -> return conversions.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/dev-replace.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index 147c5494adf9..1a82e88ec5c1 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -341,7 +341,7 @@ int btrfs_run_dev_replace(struct btrfs_trans_handle *trans)
struct btrfs_fs_info *fs_info = trans->fs_info;
int ret;
struct btrfs_root *dev_root = fs_info->dev_root;
- struct btrfs_path *path;
+ BTRFS_PATH_AUTO_FREE(path);
struct btrfs_key key;
struct extent_buffer *eb;
struct btrfs_dev_replace_item *ptr;
@@ -360,16 +360,15 @@ int btrfs_run_dev_replace(struct btrfs_trans_handle *trans)
key.offset = 0;
path = btrfs_alloc_path();
- if (!path) {
- ret = -ENOMEM;
- goto out;
- }
+ if (!path)
+ return -ENOMEM;
+
ret = btrfs_search_slot(trans, dev_root, &key, path, -1, 1);
if (ret < 0) {
btrfs_warn(fs_info,
"error %d while searching for dev_replace item!",
ret);
- goto out;
+ return ret;
}
if (ret == 0 &&
@@ -390,7 +389,7 @@ int btrfs_run_dev_replace(struct btrfs_trans_handle *trans)
btrfs_warn(fs_info,
"delete too small dev_replace item failed %d!",
ret);
- goto out;
+ return ret;
}
ret = 1;
}
@@ -403,7 +402,7 @@ int btrfs_run_dev_replace(struct btrfs_trans_handle *trans)
if (ret < 0) {
btrfs_warn(fs_info,
"insert dev_replace item failed %d!", ret);
- goto out;
+ return ret;
}
}
@@ -435,8 +434,6 @@ int btrfs_run_dev_replace(struct btrfs_trans_handle *trans)
dev_replace->cursor_right);
dev_replace->item_needs_writeback = 0;
up_write(&dev_replace->rwsem);
-out:
- btrfs_free_path(path);
return ret;
}
--
2.47.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 10/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_check_dir_item_collision()
2025-02-26 9:50 [PATCH 00/27] Struct btrfs_path auto cleaning conversions David Sterba
` (8 preceding siblings ...)
2025-02-26 9:51 ` [PATCH 09/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_run_dev_replace() David Sterba
@ 2025-02-26 9:51 ` David Sterba
2025-02-26 9:51 ` [PATCH 11/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_read_tree_root() David Sterba
` (18 subsequent siblings)
28 siblings, 0 replies; 34+ messages in thread
From: David Sterba @ 2025-02-26 9:51 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
This is the trivial pattern for path auto free, initialize at the
beginning and free at the end with simple goto -> return conversions.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/dir-item.c | 24 +++++++++---------------
1 file changed, 9 insertions(+), 15 deletions(-)
diff --git a/fs/btrfs/dir-item.c b/fs/btrfs/dir-item.c
index ccf91de29f80..b29cc31a7c4a 100644
--- a/fs/btrfs/dir-item.c
+++ b/fs/btrfs/dir-item.c
@@ -236,7 +236,7 @@ int btrfs_check_dir_item_collision(struct btrfs_root *root, u64 dir,
int data_size;
struct extent_buffer *leaf;
int slot;
- struct btrfs_path *path;
+ BTRFS_PATH_AUTO_FREE(path);
path = btrfs_alloc_path();
if (!path)
@@ -251,20 +251,17 @@ int btrfs_check_dir_item_collision(struct btrfs_root *root, u64 dir,
if (IS_ERR(di)) {
ret = PTR_ERR(di);
/* Nothing found, we're safe */
- if (ret == -ENOENT) {
- ret = 0;
- goto out;
- }
+ if (ret == -ENOENT)
+ return 0;
if (ret < 0)
- goto out;
+ return ret;
}
/* we found an item, look for our name in the item */
if (di) {
/* our exact name was found */
- ret = -EEXIST;
- goto out;
+ return -EEXIST;
}
/* See if there is room in the item to insert this name. */
@@ -273,14 +270,11 @@ int btrfs_check_dir_item_collision(struct btrfs_root *root, u64 dir,
slot = path->slots[0];
if (data_size + btrfs_item_size(leaf, slot) +
sizeof(struct btrfs_item) > BTRFS_LEAF_DATA_SIZE(root->fs_info)) {
- ret = -EOVERFLOW;
- } else {
- /* plenty of insertion room */
- ret = 0;
+ return -EOVERFLOW;
}
-out:
- btrfs_free_path(path);
- return ret;
+
+ /* Plenty of insertion room. */
+ return 0;
}
/*
--
2.47.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 11/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_read_tree_root()
2025-02-26 9:50 [PATCH 00/27] Struct btrfs_path auto cleaning conversions David Sterba
` (9 preceding siblings ...)
2025-02-26 9:51 ` [PATCH 10/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_check_dir_item_collision() David Sterba
@ 2025-02-26 9:51 ` David Sterba
2025-02-26 9:51 ` [PATCH 12/27] btrfs: use BTRFS_PATH_AUTO_FREE in load_global_roots() David Sterba
` (17 subsequent siblings)
28 siblings, 0 replies; 34+ messages in thread
From: David Sterba @ 2025-02-26 9:51 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
This is the trivial pattern for path auto free, initialize at the
beginning and free at the end.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/disk-io.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index a799216aa264..ab7cbbf90af3 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1089,13 +1089,12 @@ struct btrfs_root *btrfs_read_tree_root(struct btrfs_root *tree_root,
const struct btrfs_key *key)
{
struct btrfs_root *root;
- struct btrfs_path *path;
+ BTRFS_PATH_AUTO_FREE(path);
path = btrfs_alloc_path();
if (!path)
return ERR_PTR(-ENOMEM);
root = read_tree_root_path(tree_root, path, key);
- btrfs_free_path(path);
return root;
}
--
2.47.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 12/27] btrfs: use BTRFS_PATH_AUTO_FREE in load_global_roots()
2025-02-26 9:50 [PATCH 00/27] Struct btrfs_path auto cleaning conversions David Sterba
` (10 preceding siblings ...)
2025-02-26 9:51 ` [PATCH 11/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_read_tree_root() David Sterba
@ 2025-02-26 9:51 ` David Sterba
2025-02-26 9:51 ` [PATCH 13/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_init_root_free_objectid() David Sterba
` (16 subsequent siblings)
28 siblings, 0 replies; 34+ messages in thread
From: David Sterba @ 2025-02-26 9:51 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
This is the trivial pattern for path auto free, initialize at the
beginning and free at the end with simple goto -> return conversions.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/disk-io.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index ab7cbbf90af3..f0e4dd0245df 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2198,8 +2198,8 @@ static int load_global_roots_objectid(struct btrfs_root *tree_root,
static int load_global_roots(struct btrfs_root *tree_root)
{
- struct btrfs_path *path;
- int ret = 0;
+ BTRFS_PATH_AUTO_FREE(path);
+ int ret;
path = btrfs_alloc_path();
if (!path)
@@ -2208,18 +2208,17 @@ static int load_global_roots(struct btrfs_root *tree_root)
ret = load_global_roots_objectid(tree_root, path,
BTRFS_EXTENT_TREE_OBJECTID, "extent");
if (ret)
- goto out;
+ return ret;
ret = load_global_roots_objectid(tree_root, path,
BTRFS_CSUM_TREE_OBJECTID, "csum");
if (ret)
- goto out;
+ return ret;
if (!btrfs_fs_compat_ro(tree_root->fs_info, FREE_SPACE_TREE))
- goto out;
+ return ret;
ret = load_global_roots_objectid(tree_root, path,
BTRFS_FREE_SPACE_TREE_OBJECTID,
"free space");
-out:
- btrfs_free_path(path);
+
return ret;
}
--
2.47.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 13/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_init_root_free_objectid()
2025-02-26 9:50 [PATCH 00/27] Struct btrfs_path auto cleaning conversions David Sterba
` (11 preceding siblings ...)
2025-02-26 9:51 ` [PATCH 12/27] btrfs: use BTRFS_PATH_AUTO_FREE in load_global_roots() David Sterba
@ 2025-02-26 9:51 ` David Sterba
2025-02-26 9:51 ` [PATCH 14/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_get_name() David Sterba
` (15 subsequent siblings)
28 siblings, 0 replies; 34+ messages in thread
From: David Sterba @ 2025-02-26 9:51 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
This is the trivial pattern for path auto free, initialize at the
beginning and free at the end with simple goto -> return conversions.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/disk-io.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index f0e4dd0245df..7ae9d020f12a 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -4898,7 +4898,7 @@ static int btrfs_cleanup_transaction(struct btrfs_fs_info *fs_info)
int btrfs_init_root_free_objectid(struct btrfs_root *root)
{
- struct btrfs_path *path;
+ BTRFS_PATH_AUTO_FREE(path);
int ret;
struct extent_buffer *l;
struct btrfs_key search_key;
@@ -4914,14 +4914,13 @@ int btrfs_init_root_free_objectid(struct btrfs_root *root)
search_key.offset = (u64)-1;
ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0);
if (ret < 0)
- goto error;
+ return ret;
if (ret == 0) {
/*
* Key with offset -1 found, there would have to exist a root
* with such id, but this is out of valid range.
*/
- ret = -EUCLEAN;
- goto error;
+ return -EUCLEAN;
}
if (path->slots[0] > 0) {
slot = path->slots[0] - 1;
@@ -4932,10 +4931,8 @@ int btrfs_init_root_free_objectid(struct btrfs_root *root)
} else {
root->free_objectid = BTRFS_FIRST_FREE_OBJECTID;
}
- ret = 0;
-error:
- btrfs_free_path(path);
- return ret;
+
+ return 0;
}
int btrfs_get_free_objectid(struct btrfs_root *root, u64 *objectid)
--
2.47.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 14/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_get_name()
2025-02-26 9:50 [PATCH 00/27] Struct btrfs_path auto cleaning conversions David Sterba
` (12 preceding siblings ...)
2025-02-26 9:51 ` [PATCH 13/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_init_root_free_objectid() David Sterba
@ 2025-02-26 9:51 ` David Sterba
2025-02-27 7:01 ` Johannes Thumshirn
2025-02-26 9:51 ` [PATCH 15/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_lookup_data_extent() David Sterba
` (14 subsequent siblings)
28 siblings, 1 reply; 34+ messages in thread
From: David Sterba @ 2025-02-26 9:51 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
s is the trivial pattern for path auto free, initialize at the beginning
and free at the end with some return simplifications.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/export.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/fs/btrfs/export.c b/fs/btrfs/export.c
index 0c0b8db82df6..a91eaf0ca34e 100644
--- a/fs/btrfs/export.c
+++ b/fs/btrfs/export.c
@@ -223,7 +223,7 @@ static int btrfs_get_name(struct dentry *parent, char *name,
struct btrfs_inode *dir = BTRFS_I(d_inode(parent));
struct btrfs_root *root = dir->root;
struct btrfs_fs_info *fs_info = root->fs_info;
- struct btrfs_path *path;
+ BTRFS_PATH_AUTO_FREE(path);
struct btrfs_inode_ref *iref;
struct btrfs_root_ref *rref;
struct extent_buffer *leaf;
@@ -255,15 +255,12 @@ static int btrfs_get_name(struct dentry *parent, char *name,
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
if (ret < 0) {
- btrfs_free_path(path);
return ret;
} else if (ret > 0) {
- if (ino == BTRFS_FIRST_FREE_OBJECTID) {
+ if (ino == BTRFS_FIRST_FREE_OBJECTID)
path->slots[0]--;
- } else {
- btrfs_free_path(path);
+ else
return -ENOENT;
- }
}
leaf = path->nodes[0];
@@ -280,7 +277,6 @@ static int btrfs_get_name(struct dentry *parent, char *name,
}
read_extent_buffer(leaf, name, name_ptr, name_len);
- btrfs_free_path(path);
/*
* have to add the null termination to make sure that reconnect_path
--
2.47.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 15/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_lookup_data_extent()
2025-02-26 9:50 [PATCH 00/27] Struct btrfs_path auto cleaning conversions David Sterba
` (13 preceding siblings ...)
2025-02-26 9:51 ` [PATCH 14/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_get_name() David Sterba
@ 2025-02-26 9:51 ` David Sterba
2025-02-26 9:51 ` [PATCH 16/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_lookup_extent_info() David Sterba
` (13 subsequent siblings)
28 siblings, 0 replies; 34+ messages in thread
From: David Sterba @ 2025-02-26 9:51 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
This is the trivial pattern for path auto free, initialize at the
beginning and free at the end.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/extent-tree.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 4a6036e7fa83..e62ab4eaa6ff 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -70,9 +70,8 @@ static int block_group_bits(struct btrfs_block_group *cache, u64 bits)
int btrfs_lookup_data_extent(struct btrfs_fs_info *fs_info, u64 start, u64 len)
{
struct btrfs_root *root = btrfs_extent_root(fs_info, start);
- int ret;
struct btrfs_key key;
- struct btrfs_path *path;
+ BTRFS_PATH_AUTO_FREE(path);
path = btrfs_alloc_path();
if (!path)
@@ -81,9 +80,7 @@ int btrfs_lookup_data_extent(struct btrfs_fs_info *fs_info, u64 start, u64 len)
key.objectid = start;
key.type = BTRFS_EXTENT_ITEM_KEY;
key.offset = len;
- ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
- btrfs_free_path(path);
- return ret;
+ return btrfs_search_slot(NULL, root, &key, path, 0, 0);
}
/*
--
2.47.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 16/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_lookup_extent_info()
2025-02-26 9:50 [PATCH 00/27] Struct btrfs_path auto cleaning conversions David Sterba
` (14 preceding siblings ...)
2025-02-26 9:51 ` [PATCH 15/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_lookup_data_extent() David Sterba
@ 2025-02-26 9:51 ` David Sterba
2025-02-26 9:51 ` [PATCH 17/27] btrfs: use BTRFS_PATH_AUTO_FREE in __btrfs_inc_extent_ref() David Sterba
` (12 subsequent siblings)
28 siblings, 0 replies; 34+ messages in thread
From: David Sterba @ 2025-02-26 9:51 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
This is the trivial pattern for path auto free, initialize at the
beginning and free at the end with simple goto -> return conversions.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/extent-tree.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index e62ab4eaa6ff..f0dbb96651d6 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -100,7 +100,7 @@ int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans,
struct btrfs_root *extent_root;
struct btrfs_delayed_ref_head *head;
struct btrfs_delayed_ref_root *delayed_refs;
- struct btrfs_path *path;
+ BTRFS_PATH_AUTO_FREE(path);
struct btrfs_key key;
u64 num_refs;
u64 extent_flags;
@@ -131,7 +131,7 @@ int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans,
extent_root = btrfs_extent_root(fs_info, bytenr);
ret = btrfs_search_slot(NULL, extent_root, &key, path, 0, 0);
if (ret < 0)
- goto out_free;
+ return ret;
if (ret > 0 && key.type == BTRFS_METADATA_ITEM_KEY) {
if (path->slots[0]) {
@@ -156,7 +156,7 @@ int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans,
"unexpected extent item size, has %u expect >= %zu",
item_size, sizeof(*ei));
btrfs_abort_transaction(trans, ret);
- goto out_free;
+ return ret;
}
ei = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_extent_item);
@@ -167,7 +167,7 @@ int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans,
"unexpected zero reference count for extent item (%llu %u %llu)",
key.objectid, key.type, key.offset);
btrfs_abort_transaction(trans, ret);
- goto out_free;
+ return ret;
}
extent_flags = btrfs_extent_flags(leaf, ei);
owner = btrfs_get_extent_owner_root(fs_info, leaf, path->slots[0]);
@@ -213,8 +213,7 @@ int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans,
*flags = extent_flags;
if (owning_root)
*owning_root = owner;
-out_free:
- btrfs_free_path(path);
+
return ret;
}
--
2.47.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 17/27] btrfs: use BTRFS_PATH_AUTO_FREE in __btrfs_inc_extent_ref()
2025-02-26 9:50 [PATCH 00/27] Struct btrfs_path auto cleaning conversions David Sterba
` (15 preceding siblings ...)
2025-02-26 9:51 ` [PATCH 16/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_lookup_extent_info() David Sterba
@ 2025-02-26 9:51 ` David Sterba
2025-02-26 9:51 ` [PATCH 18/27] btrfs: use BTRFS_PATH_AUTO_FREE in run_delayed_extent_op() David Sterba
` (11 subsequent siblings)
28 siblings, 0 replies; 34+ messages in thread
From: David Sterba @ 2025-02-26 9:51 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
This is the trivial pattern for path auto free, initialize at the
beginning and free at the end with simple goto -> return conversions.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/extent-tree.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index f0dbb96651d6..9c1bd8831e83 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -1483,7 +1483,7 @@ static int __btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
struct btrfs_delayed_ref_node *node,
struct btrfs_delayed_extent_op *extent_op)
{
- struct btrfs_path *path;
+ BTRFS_PATH_AUTO_FREE(path);
struct extent_buffer *leaf;
struct btrfs_extent_item *item;
struct btrfs_key key;
@@ -1504,7 +1504,7 @@ static int __btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
node->parent, node->ref_root, owner,
offset, refs_to_add, extent_op);
if ((ret < 0 && ret != -EAGAIN) || !ret)
- goto out;
+ return ret;
/*
* Ok we had -EAGAIN which means we didn't have space to insert and
@@ -1529,8 +1529,7 @@ static int __btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
if (ret)
btrfs_abort_transaction(trans, ret);
-out:
- btrfs_free_path(path);
+
return ret;
}
--
2.47.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 18/27] btrfs: use BTRFS_PATH_AUTO_FREE in run_delayed_extent_op()
2025-02-26 9:50 [PATCH 00/27] Struct btrfs_path auto cleaning conversions David Sterba
` (16 preceding siblings ...)
2025-02-26 9:51 ` [PATCH 17/27] btrfs: use BTRFS_PATH_AUTO_FREE in __btrfs_inc_extent_ref() David Sterba
@ 2025-02-26 9:51 ` David Sterba
2025-02-26 9:51 ` [PATCH 19/27] btrfs: use BTRFS_PATH_AUTO_FREE in check_ref_exists() David Sterba
` (10 subsequent siblings)
28 siblings, 0 replies; 34+ messages in thread
From: David Sterba @ 2025-02-26 9:51 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
This is the trivial pattern for path auto free, initialize at the
beginning and free at the end with simple goto -> return conversions.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/extent-tree.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 9c1bd8831e83..f4ddef135851 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -1626,7 +1626,7 @@ static int run_delayed_extent_op(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info = trans->fs_info;
struct btrfs_root *root;
struct btrfs_key key;
- struct btrfs_path *path;
+ BTRFS_PATH_AUTO_FREE(path);
struct btrfs_extent_item *ei;
struct extent_buffer *leaf;
u32 item_size;
@@ -1657,7 +1657,7 @@ static int run_delayed_extent_op(struct btrfs_trans_handle *trans,
again:
ret = btrfs_search_slot(trans, root, &key, path, 0, 1);
if (ret < 0) {
- goto out;
+ return ret;
} else if (ret > 0) {
if (metadata) {
if (path->slots[0] > 0) {
@@ -1683,7 +1683,7 @@ static int run_delayed_extent_op(struct btrfs_trans_handle *trans,
btrfs_err(fs_info,
"missing extent item for extent %llu num_bytes %llu level %d",
head->bytenr, head->num_bytes, head->level);
- goto out;
+ return ret;
}
}
@@ -1696,13 +1696,12 @@ static int run_delayed_extent_op(struct btrfs_trans_handle *trans,
"unexpected extent item size, has %u expect >= %zu",
item_size, sizeof(*ei));
btrfs_abort_transaction(trans, ret);
- goto out;
+ return ret;
}
ei = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_extent_item);
__run_delayed_extent_op(extent_op, leaf, ei);
-out:
- btrfs_free_path(path);
+
return ret;
}
--
2.47.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 19/27] btrfs: use BTRFS_PATH_AUTO_FREE in check_ref_exists()
2025-02-26 9:50 [PATCH 00/27] Struct btrfs_path auto cleaning conversions David Sterba
` (17 preceding siblings ...)
2025-02-26 9:51 ` [PATCH 18/27] btrfs: use BTRFS_PATH_AUTO_FREE in run_delayed_extent_op() David Sterba
@ 2025-02-26 9:51 ` David Sterba
2025-02-26 9:51 ` [PATCH 20/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_drop_subtree() David Sterba
` (9 subsequent siblings)
28 siblings, 0 replies; 34+ messages in thread
From: David Sterba @ 2025-02-26 9:51 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
This is the trivial pattern for path auto free, initialize at the
beginning and free at the end.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/extent-tree.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index f4ddef135851..122d575c016b 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -5459,7 +5459,7 @@ static int check_ref_exists(struct btrfs_trans_handle *trans,
{
struct btrfs_delayed_ref_root *delayed_refs;
struct btrfs_delayed_ref_head *head;
- struct btrfs_path *path;
+ BTRFS_PATH_AUTO_FREE(path);
struct btrfs_extent_inline_ref *iref;
int ret;
bool exists = false;
@@ -5476,7 +5476,6 @@ static int check_ref_exists(struct btrfs_trans_handle *trans,
* If we get 0 then we found our reference, return 1, else
* return the error if it's not -ENOENT;
*/
- btrfs_free_path(path);
return (ret < 0 ) ? ret : 1;
}
@@ -5511,7 +5510,6 @@ static int check_ref_exists(struct btrfs_trans_handle *trans,
mutex_unlock(&head->mutex);
out:
spin_unlock(&delayed_refs->lock);
- btrfs_free_path(path);
return exists ? 1 : 0;
}
--
2.47.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 20/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_drop_subtree()
2025-02-26 9:50 [PATCH 00/27] Struct btrfs_path auto cleaning conversions David Sterba
` (18 preceding siblings ...)
2025-02-26 9:51 ` [PATCH 19/27] btrfs: use BTRFS_PATH_AUTO_FREE in check_ref_exists() David Sterba
@ 2025-02-26 9:51 ` David Sterba
2025-02-26 9:51 ` [PATCH 21/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_insert_hole_extent() David Sterba
` (8 subsequent siblings)
28 siblings, 0 replies; 34+ messages in thread
From: David Sterba @ 2025-02-26 9:51 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
This is the trivial pattern for path auto free, initialize at the
beginning and free at the end with simple goto -> return conversions.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/extent-tree.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 122d575c016b..5de1a1293c93 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -6277,7 +6277,7 @@ int btrfs_drop_subtree(struct btrfs_trans_handle *trans,
struct extent_buffer *parent)
{
struct btrfs_fs_info *fs_info = root->fs_info;
- struct btrfs_path *path;
+ BTRFS_PATH_AUTO_FREE(path);
struct walk_control *wc;
int level;
int parent_level;
@@ -6290,10 +6290,8 @@ int btrfs_drop_subtree(struct btrfs_trans_handle *trans,
return -ENOMEM;
wc = kzalloc(sizeof(*wc), GFP_NOFS);
- if (!wc) {
- btrfs_free_path(path);
+ if (!wc)
return -ENOMEM;
- }
btrfs_assert_tree_write_locked(parent);
parent_level = btrfs_header_level(parent);
@@ -6330,7 +6328,6 @@ int btrfs_drop_subtree(struct btrfs_trans_handle *trans,
}
kfree(wc);
- btrfs_free_path(path);
return ret;
}
--
2.47.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 21/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_insert_hole_extent()
2025-02-26 9:50 [PATCH 00/27] Struct btrfs_path auto cleaning conversions David Sterba
` (19 preceding siblings ...)
2025-02-26 9:51 ` [PATCH 20/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_drop_subtree() David Sterba
@ 2025-02-26 9:51 ` David Sterba
2025-02-26 9:51 ` [PATCH 22/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_lookup_bio_sums() David Sterba
` (7 subsequent siblings)
28 siblings, 0 replies; 34+ messages in thread
From: David Sterba @ 2025-02-26 9:51 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
This is the trivial pattern for path auto free, initialize at the
beginning and free at the end with simple goto -> return conversions.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/file-item.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
index 5083025d28b2..2f5e6cad8f55 100644
--- a/fs/btrfs/file-item.c
+++ b/fs/btrfs/file-item.c
@@ -163,7 +163,7 @@ int btrfs_insert_hole_extent(struct btrfs_trans_handle *trans,
int ret = 0;
struct btrfs_file_extent_item *item;
struct btrfs_key file_key;
- struct btrfs_path *path;
+ BTRFS_PATH_AUTO_FREE(path);
struct extent_buffer *leaf;
path = btrfs_alloc_path();
@@ -177,7 +177,7 @@ int btrfs_insert_hole_extent(struct btrfs_trans_handle *trans,
ret = btrfs_insert_empty_item(trans, root, path, &file_key,
sizeof(*item));
if (ret < 0)
- goto out;
+ return ret;
leaf = path->nodes[0];
item = btrfs_item_ptr(leaf, path->slots[0],
struct btrfs_file_extent_item);
@@ -191,8 +191,7 @@ int btrfs_insert_hole_extent(struct btrfs_trans_handle *trans,
btrfs_set_file_extent_compression(leaf, item, 0);
btrfs_set_file_extent_encryption(leaf, item, 0);
btrfs_set_file_extent_other_encoding(leaf, item, 0);
-out:
- btrfs_free_path(path);
+
return ret;
}
--
2.47.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 22/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_lookup_bio_sums()
2025-02-26 9:50 [PATCH 00/27] Struct btrfs_path auto cleaning conversions David Sterba
` (20 preceding siblings ...)
2025-02-26 9:51 ` [PATCH 21/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_insert_hole_extent() David Sterba
@ 2025-02-26 9:51 ` David Sterba
2025-02-26 9:51 ` [PATCH 23/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_del_csums() David Sterba
` (6 subsequent siblings)
28 siblings, 0 replies; 34+ messages in thread
From: David Sterba @ 2025-02-26 9:51 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
This is the trivial pattern for path auto free, initialize at the
beginning and free at the end.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/file-item.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
index 2f5e6cad8f55..e0475465ba51 100644
--- a/fs/btrfs/file-item.c
+++ b/fs/btrfs/file-item.c
@@ -341,7 +341,7 @@ blk_status_t btrfs_lookup_bio_sums(struct btrfs_bio *bbio)
struct btrfs_inode *inode = bbio->inode;
struct btrfs_fs_info *fs_info = inode->root->fs_info;
struct bio *bio = &bbio->bio;
- struct btrfs_path *path;
+ BTRFS_PATH_AUTO_FREE(path);
const u32 sectorsize = fs_info->sectorsize;
const u32 csum_size = fs_info->csum_size;
u32 orig_len = bio->bi_iter.bi_size;
@@ -373,10 +373,8 @@ blk_status_t btrfs_lookup_bio_sums(struct btrfs_bio *bbio)
if (nblocks * csum_size > BTRFS_BIO_INLINE_CSUM_SIZE) {
bbio->csum = kmalloc_array(nblocks, csum_size, GFP_NOFS);
- if (!bbio->csum) {
- btrfs_free_path(path);
+ if (!bbio->csum)
return BLK_STS_RESOURCE;
- }
} else {
bbio->csum = bbio->csum_inline;
}
@@ -444,7 +442,6 @@ blk_status_t btrfs_lookup_bio_sums(struct btrfs_bio *bbio)
bio_offset += count * sectorsize;
}
- btrfs_free_path(path);
return ret;
}
--
2.47.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 23/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_del_csums()
2025-02-26 9:50 [PATCH 00/27] Struct btrfs_path auto cleaning conversions David Sterba
` (21 preceding siblings ...)
2025-02-26 9:51 ` [PATCH 22/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_lookup_bio_sums() David Sterba
@ 2025-02-26 9:51 ` David Sterba
2025-02-26 9:51 ` [PATCH 24/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_remove_free_space_inode() David Sterba
` (5 subsequent siblings)
28 siblings, 0 replies; 34+ messages in thread
From: David Sterba @ 2025-02-26 9:51 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
This is the trivial pattern for path auto free, initialize at the
beginning and free at the end.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/file-item.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
index e0475465ba51..344b4db487a0 100644
--- a/fs/btrfs/file-item.c
+++ b/fs/btrfs/file-item.c
@@ -871,7 +871,7 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans,
struct btrfs_root *root, u64 bytenr, u64 len)
{
struct btrfs_fs_info *fs_info = trans->fs_info;
- struct btrfs_path *path;
+ BTRFS_PATH_AUTO_FREE(path);
struct btrfs_key key;
u64 end_byte = bytenr + len;
u64 csum_end;
@@ -1007,7 +1007,6 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans,
}
btrfs_release_path(path);
}
- btrfs_free_path(path);
return ret;
}
--
2.47.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 24/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_remove_free_space_inode()
2025-02-26 9:50 [PATCH 00/27] Struct btrfs_path auto cleaning conversions David Sterba
` (22 preceding siblings ...)
2025-02-26 9:51 ` [PATCH 23/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_del_csums() David Sterba
@ 2025-02-26 9:51 ` David Sterba
2025-02-26 9:51 ` [PATCH 25/27] btrfs: use BTRFS_PATH_AUTO_FREE in populate_free_space_tree() David Sterba
` (4 subsequent siblings)
28 siblings, 0 replies; 34+ messages in thread
From: David Sterba @ 2025-02-26 9:51 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
This is the trivial pattern for path auto free, initialize at the
beginning and free at the end with simple goto -> return conversions.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/free-space-cache.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index 056546bf9abd..3095cce904b5 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -244,7 +244,7 @@ int btrfs_remove_free_space_inode(struct btrfs_trans_handle *trans,
struct inode *inode,
struct btrfs_block_group *block_group)
{
- struct btrfs_path *path;
+ BTRFS_PATH_AUTO_FREE(path);
struct btrfs_key key;
int ret = 0;
@@ -257,12 +257,12 @@ int btrfs_remove_free_space_inode(struct btrfs_trans_handle *trans,
if (IS_ERR(inode)) {
if (PTR_ERR(inode) != -ENOENT)
ret = PTR_ERR(inode);
- goto out;
+ return ret;
}
ret = btrfs_orphan_add(trans, BTRFS_I(inode));
if (ret) {
btrfs_add_delayed_iput(BTRFS_I(inode));
- goto out;
+ return ret;
}
clear_nlink(inode);
/* One for the block groups ref */
@@ -285,12 +285,9 @@ int btrfs_remove_free_space_inode(struct btrfs_trans_handle *trans,
if (ret) {
if (ret > 0)
ret = 0;
- goto out;
+ return ret;
}
- ret = btrfs_del_item(trans, trans->fs_info->tree_root, path);
-out:
- btrfs_free_path(path);
- return ret;
+ return btrfs_del_item(trans, trans->fs_info->tree_root, path);
}
int btrfs_truncate_free_space_cache(struct btrfs_trans_handle *trans,
--
2.47.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 25/27] btrfs: use BTRFS_PATH_AUTO_FREE in populate_free_space_tree()
2025-02-26 9:50 [PATCH 00/27] Struct btrfs_path auto cleaning conversions David Sterba
` (23 preceding siblings ...)
2025-02-26 9:51 ` [PATCH 24/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_remove_free_space_inode() David Sterba
@ 2025-02-26 9:51 ` David Sterba
2025-02-26 9:51 ` [PATCH 26/27] btrfs: use BTRFS_PATH_AUTO_FREE in clear_free_space_tree() David Sterba
` (3 subsequent siblings)
28 siblings, 0 replies; 34+ messages in thread
From: David Sterba @ 2025-02-26 9:51 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
This is the trivial pattern for path auto free, initialize at the
beginning and free at the end with simple goto -> return conversions.
This applies to both path and path2.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/free-space-tree.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/fs/btrfs/free-space-tree.c b/fs/btrfs/free-space-tree.c
index cae540ec15ed..d1ec02d5e1f6 100644
--- a/fs/btrfs/free-space-tree.c
+++ b/fs/btrfs/free-space-tree.c
@@ -1062,7 +1062,8 @@ static int populate_free_space_tree(struct btrfs_trans_handle *trans,
struct btrfs_block_group *block_group)
{
struct btrfs_root *extent_root;
- struct btrfs_path *path, *path2;
+ BTRFS_PATH_AUTO_FREE(path);
+ BTRFS_PATH_AUTO_FREE(path2);
struct btrfs_key key;
u64 start, end;
int ret;
@@ -1070,17 +1071,16 @@ static int populate_free_space_tree(struct btrfs_trans_handle *trans,
path = btrfs_alloc_path();
if (!path)
return -ENOMEM;
- path->reada = READA_FORWARD;
path2 = btrfs_alloc_path();
- if (!path2) {
- btrfs_free_path(path);
+ if (!path2)
return -ENOMEM;
- }
+
+ path->reada = READA_FORWARD;
ret = add_new_free_space_info(trans, block_group, path2);
if (ret)
- goto out;
+ return ret;
mutex_lock(&block_group->free_space_lock);
@@ -1146,9 +1146,7 @@ static int populate_free_space_tree(struct btrfs_trans_handle *trans,
ret = 0;
out_locked:
mutex_unlock(&block_group->free_space_lock);
-out:
- btrfs_free_path(path2);
- btrfs_free_path(path);
+
return ret;
}
--
2.47.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 26/27] btrfs: use BTRFS_PATH_AUTO_FREE in clear_free_space_tree()
2025-02-26 9:50 [PATCH 00/27] Struct btrfs_path auto cleaning conversions David Sterba
` (24 preceding siblings ...)
2025-02-26 9:51 ` [PATCH 25/27] btrfs: use BTRFS_PATH_AUTO_FREE in populate_free_space_tree() David Sterba
@ 2025-02-26 9:51 ` David Sterba
2025-02-26 9:51 ` [PATCH 27/27] btrfs: use BTRFS_PATH_AUTO_FREE in load_free_space_tree() David Sterba
` (2 subsequent siblings)
28 siblings, 0 replies; 34+ messages in thread
From: David Sterba @ 2025-02-26 9:51 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
This is the trivial pattern for path auto free, initialize at the
beginning and free at the end with simple goto -> return conversions.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/free-space-tree.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/fs/btrfs/free-space-tree.c b/fs/btrfs/free-space-tree.c
index d1ec02d5e1f6..589ff73ed13a 100644
--- a/fs/btrfs/free-space-tree.c
+++ b/fs/btrfs/free-space-tree.c
@@ -1215,7 +1215,7 @@ int btrfs_create_free_space_tree(struct btrfs_fs_info *fs_info)
static int clear_free_space_tree(struct btrfs_trans_handle *trans,
struct btrfs_root *root)
{
- struct btrfs_path *path;
+ BTRFS_PATH_AUTO_FREE(path);
struct btrfs_key key;
int nr;
int ret;
@@ -1231,7 +1231,7 @@ static int clear_free_space_tree(struct btrfs_trans_handle *trans,
while (1) {
ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
if (ret < 0)
- goto out;
+ return ret;
nr = btrfs_header_nritems(path->nodes[0]);
if (!nr)
@@ -1240,15 +1240,12 @@ static int clear_free_space_tree(struct btrfs_trans_handle *trans,
path->slots[0] = 0;
ret = btrfs_del_items(trans, root, path, 0, nr);
if (ret)
- goto out;
+ return ret;
btrfs_release_path(path);
}
- ret = 0;
-out:
- btrfs_free_path(path);
- return ret;
+ return 0;
}
int btrfs_delete_free_space_tree(struct btrfs_fs_info *fs_info)
--
2.47.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 27/27] btrfs: use BTRFS_PATH_AUTO_FREE in load_free_space_tree()
2025-02-26 9:50 [PATCH 00/27] Struct btrfs_path auto cleaning conversions David Sterba
` (25 preceding siblings ...)
2025-02-26 9:51 ` [PATCH 26/27] btrfs: use BTRFS_PATH_AUTO_FREE in clear_free_space_tree() David Sterba
@ 2025-02-26 9:51 ` David Sterba
2025-02-27 7:06 ` Johannes Thumshirn
2025-02-27 7:09 ` [PATCH 00/27] Struct btrfs_path auto cleaning conversions Johannes Thumshirn
2025-02-27 9:55 ` David Sterba
28 siblings, 1 reply; 34+ messages in thread
From: David Sterba @ 2025-02-26 9:51 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
This is the trivial pattern for path auto free, initialize at the
beginning and free at the end with simple goto -> return conversions.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/free-space-tree.c | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/fs/btrfs/free-space-tree.c b/fs/btrfs/free-space-tree.c
index 589ff73ed13a..39c6b96a4c25 100644
--- a/fs/btrfs/free-space-tree.c
+++ b/fs/btrfs/free-space-tree.c
@@ -1633,9 +1633,8 @@ int load_free_space_tree(struct btrfs_caching_control *caching_ctl)
{
struct btrfs_block_group *block_group;
struct btrfs_free_space_info *info;
- struct btrfs_path *path;
+ BTRFS_PATH_AUTO_FREE(path);
u32 extent_count, flags;
- int ret;
block_group = caching_ctl->block_group;
@@ -1652,10 +1651,9 @@ int load_free_space_tree(struct btrfs_caching_control *caching_ctl)
path->reada = READA_FORWARD;
info = search_free_space_info(NULL, block_group, path, 0);
- if (IS_ERR(info)) {
- ret = PTR_ERR(info);
- goto out;
- }
+ if (IS_ERR(info))
+ return PTR_ERR(info);
+
extent_count = btrfs_free_space_extent_count(path->nodes[0], info);
flags = btrfs_free_space_flags(path->nodes[0], info);
@@ -1665,11 +1663,7 @@ int load_free_space_tree(struct btrfs_caching_control *caching_ctl)
* there.
*/
if (flags & BTRFS_FREE_SPACE_USING_BITMAPS)
- ret = load_free_space_bitmaps(caching_ctl, path, extent_count);
+ return load_free_space_bitmaps(caching_ctl, path, extent_count);
else
- ret = load_free_space_extents(caching_ctl, path, extent_count);
-
-out:
- btrfs_free_path(path);
- return ret;
+ return load_free_space_extents(caching_ctl, path, extent_count);
}
--
2.47.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* Re: [PATCH 14/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_get_name()
2025-02-26 9:51 ` [PATCH 14/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_get_name() David Sterba
@ 2025-02-27 7:01 ` Johannes Thumshirn
0 siblings, 0 replies; 34+ messages in thread
From: Johannes Thumshirn @ 2025-02-27 7:01 UTC (permalink / raw)
To: David Sterba, linux-btrfs@vger.kernel.org
On 26.02.25 10:52, David Sterba wrote:
> s is the trivial pattern for path auto free, initialize at the beginning
^~ This
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [PATCH 27/27] btrfs: use BTRFS_PATH_AUTO_FREE in load_free_space_tree()
2025-02-26 9:51 ` [PATCH 27/27] btrfs: use BTRFS_PATH_AUTO_FREE in load_free_space_tree() David Sterba
@ 2025-02-27 7:06 ` Johannes Thumshirn
0 siblings, 0 replies; 34+ messages in thread
From: Johannes Thumshirn @ 2025-02-27 7:06 UTC (permalink / raw)
To: David Sterba, linux-btrfs@vger.kernel.org
On 26.02.25 10:54, David Sterba wrote:
> @@ -1665,11 +1663,7 @@ int load_free_space_tree(struct btrfs_caching_control *caching_ctl)
> * there.
> */
> if (flags & BTRFS_FREE_SPACE_USING_BITMAPS)
> - ret = load_free_space_bitmaps(caching_ctl, path, extent_count);
> + return load_free_space_bitmaps(caching_ctl, path, extent_count);
> else
> - ret = load_free_space_extents(caching_ctl, path, extent_count);
> -
> -out:
> - btrfs_free_path(path);
> - return ret;
> + return load_free_space_extents(caching_ctl, path, extent_count);
> }
No need for the else here, i.e.:
if (flags & BTRFS_FREE_SPACE_USING_BITMAPS)
return load_free_space_bitmaps(caching_ctl, path, extent_count);
return load_free_space_extents(caching_ctl, path, extent_count);
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [PATCH 00/27] Struct btrfs_path auto cleaning conversions
2025-02-26 9:50 [PATCH 00/27] Struct btrfs_path auto cleaning conversions David Sterba
` (26 preceding siblings ...)
2025-02-26 9:51 ` [PATCH 27/27] btrfs: use BTRFS_PATH_AUTO_FREE in load_free_space_tree() David Sterba
@ 2025-02-27 7:09 ` Johannes Thumshirn
2025-02-27 9:55 ` David Sterba
28 siblings, 0 replies; 34+ messages in thread
From: Johannes Thumshirn @ 2025-02-27 7:09 UTC (permalink / raw)
To: David Sterba, linux-btrfs@vger.kernel.org
On 26.02.25 10:51, David Sterba wrote:
> We have the scoped freeing for struct btrfs_path but it's not used as
> much as it could. This patchset converts the easy cases and it's also a
> preview if we really want to do that. It makes understanding the exit
> paths a bit less obvious, but so far I think it's manageable.
>
> The path is used in many functions and following a few simple patterns,
> with the macro BTRFS_PATH_AUTO_FREE quite visible among the
> declarations, so it's nothing hard to be aware of that when reading the
> code.
>
> The conversion has been done on half of the files, so if somebody wants
> to continue, feel free. I've skipped functions with more complicated
> branching where the auto freeing would make it worse.
Let's see where this will lead us to.
Anyways, apart from the 2 small nits,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [PATCH 00/27] Struct btrfs_path auto cleaning conversions
2025-02-26 9:50 [PATCH 00/27] Struct btrfs_path auto cleaning conversions David Sterba
` (27 preceding siblings ...)
2025-02-27 7:09 ` [PATCH 00/27] Struct btrfs_path auto cleaning conversions Johannes Thumshirn
@ 2025-02-27 9:55 ` David Sterba
2025-02-27 10:56 ` Johannes Thumshirn
28 siblings, 1 reply; 34+ messages in thread
From: David Sterba @ 2025-02-27 9:55 UTC (permalink / raw)
To: David Sterba; +Cc: linux-btrfs
On Wed, Feb 26, 2025 at 10:50:40AM +0100, David Sterba wrote:
> We have the scoped freeing for struct btrfs_path but it's not used as
> much as it could. This patchset converts the easy cases and it's also a
> preview if we really want to do that. It makes understanding the exit
> paths a bit less obvious, but so far I think it's manageable.
>
> The path is used in many functions and following a few simple patterns,
> with the macro BTRFS_PATH_AUTO_FREE quite visible among the
> declarations, so it's nothing hard to be aware of that when reading the
> code.
>
> The conversion has been done on half of the files, so if somebody wants
> to continue, feel free. I've skipped functions with more complicated
> branching where the auto freeing would make it worse.
>
> David Sterba (27):
> btrfs: use BTRFS_PATH_AUTO_FREE in sample_block_group_extent_item()
> btrfs: use BTRFS_PATH_AUTO_FREE in insert_dev_extent()
> btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_setup_space_cache()
> btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_start_dirty_block_groups()
> btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_write_dirty_block_groups()
> btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_insert_item()
> btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_commit_inode_delayed_items()
> btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_init_dev_replace()
> btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_run_dev_replace()
> btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_check_dir_item_collision()
> btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_read_tree_root()
> btrfs: use BTRFS_PATH_AUTO_FREE in load_global_roots()
> btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_init_root_free_objectid()
> btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_get_name()
> btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_lookup_data_extent()
> btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_lookup_extent_info()
> btrfs: use BTRFS_PATH_AUTO_FREE in __btrfs_inc_extent_ref()
> btrfs: use BTRFS_PATH_AUTO_FREE in run_delayed_extent_op()
> btrfs: use BTRFS_PATH_AUTO_FREE in check_ref_exists()
> btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_drop_subtree()
> btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_insert_hole_extent()
> btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_lookup_bio_sums()
> btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_del_csums()
> btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_remove_free_space_inode()
> btrfs: use BTRFS_PATH_AUTO_FREE in populate_free_space_tree()
> btrfs: use BTRFS_PATH_AUTO_FREE in clear_free_space_tree()
> btrfs: use BTRFS_PATH_AUTO_FREE in load_free_space_tree()
Daniel noted that the trivial patches are maybe too trivial and should
be grouped into fewer patches. I agree after looking at the series now,
so I'll rework it
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [PATCH 00/27] Struct btrfs_path auto cleaning conversions
2025-02-27 9:55 ` David Sterba
@ 2025-02-27 10:56 ` Johannes Thumshirn
2025-02-27 13:53 ` David Sterba
0 siblings, 1 reply; 34+ messages in thread
From: Johannes Thumshirn @ 2025-02-27 10:56 UTC (permalink / raw)
To: dsterba@suse.cz, David Sterba; +Cc: linux-btrfs@vger.kernel.org
On 27.02.25 10:55, David Sterba wrote:
> Daniel noted that the trivial patches are maybe too trivial and should
> be grouped into fewer patches. I agree after looking at the series now,
> so I'll rework it
Agreed, though I must say it was super nice for reviewing them, one tiny
little change at a time.
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [PATCH 00/27] Struct btrfs_path auto cleaning conversions
2025-02-27 10:56 ` Johannes Thumshirn
@ 2025-02-27 13:53 ` David Sterba
0 siblings, 0 replies; 34+ messages in thread
From: David Sterba @ 2025-02-27 13:53 UTC (permalink / raw)
To: Johannes Thumshirn
Cc: dsterba@suse.cz, David Sterba, linux-btrfs@vger.kernel.org
On Thu, Feb 27, 2025 at 10:56:57AM +0000, Johannes Thumshirn wrote:
> On 27.02.25 10:55, David Sterba wrote:
> > Daniel noted that the trivial patches are maybe too trivial and should
> > be grouped into fewer patches. I agree after looking at the series now,
> > so I'll rework it
>
> Agreed, though I must say it was super nice for reviewing them, one tiny
> little change at a time.
Yeah, I think grouping the simple declaration/free removal patches to
one would still be easy to review as the scope is always just one
function and nothing is needed to be kept in memory. Which roughly cuts
the size of the patchset to half.
^ permalink raw reply [flat|nested] 34+ messages in thread
end of thread, other threads:[~2025-02-27 13:54 UTC | newest]
Thread overview: 34+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-26 9:50 [PATCH 00/27] Struct btrfs_path auto cleaning conversions David Sterba
2025-02-26 9:50 ` [PATCH 01/27] btrfs: use BTRFS_PATH_AUTO_FREE in sample_block_group_extent_item() David Sterba
2025-02-26 9:50 ` [PATCH 02/27] btrfs: use BTRFS_PATH_AUTO_FREE in insert_dev_extent() David Sterba
2025-02-26 9:50 ` [PATCH 03/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_setup_space_cache() David Sterba
2025-02-26 9:50 ` [PATCH 04/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_start_dirty_block_groups() David Sterba
2025-02-26 9:50 ` [PATCH 05/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_write_dirty_block_groups() David Sterba
2025-02-26 9:50 ` [PATCH 06/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_insert_item() David Sterba
2025-02-26 9:51 ` [PATCH 07/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_commit_inode_delayed_items() David Sterba
2025-02-26 9:51 ` [PATCH 08/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_init_dev_replace() David Sterba
2025-02-26 9:51 ` [PATCH 09/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_run_dev_replace() David Sterba
2025-02-26 9:51 ` [PATCH 10/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_check_dir_item_collision() David Sterba
2025-02-26 9:51 ` [PATCH 11/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_read_tree_root() David Sterba
2025-02-26 9:51 ` [PATCH 12/27] btrfs: use BTRFS_PATH_AUTO_FREE in load_global_roots() David Sterba
2025-02-26 9:51 ` [PATCH 13/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_init_root_free_objectid() David Sterba
2025-02-26 9:51 ` [PATCH 14/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_get_name() David Sterba
2025-02-27 7:01 ` Johannes Thumshirn
2025-02-26 9:51 ` [PATCH 15/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_lookup_data_extent() David Sterba
2025-02-26 9:51 ` [PATCH 16/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_lookup_extent_info() David Sterba
2025-02-26 9:51 ` [PATCH 17/27] btrfs: use BTRFS_PATH_AUTO_FREE in __btrfs_inc_extent_ref() David Sterba
2025-02-26 9:51 ` [PATCH 18/27] btrfs: use BTRFS_PATH_AUTO_FREE in run_delayed_extent_op() David Sterba
2025-02-26 9:51 ` [PATCH 19/27] btrfs: use BTRFS_PATH_AUTO_FREE in check_ref_exists() David Sterba
2025-02-26 9:51 ` [PATCH 20/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_drop_subtree() David Sterba
2025-02-26 9:51 ` [PATCH 21/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_insert_hole_extent() David Sterba
2025-02-26 9:51 ` [PATCH 22/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_lookup_bio_sums() David Sterba
2025-02-26 9:51 ` [PATCH 23/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_del_csums() David Sterba
2025-02-26 9:51 ` [PATCH 24/27] btrfs: use BTRFS_PATH_AUTO_FREE in btrfs_remove_free_space_inode() David Sterba
2025-02-26 9:51 ` [PATCH 25/27] btrfs: use BTRFS_PATH_AUTO_FREE in populate_free_space_tree() David Sterba
2025-02-26 9:51 ` [PATCH 26/27] btrfs: use BTRFS_PATH_AUTO_FREE in clear_free_space_tree() David Sterba
2025-02-26 9:51 ` [PATCH 27/27] btrfs: use BTRFS_PATH_AUTO_FREE in load_free_space_tree() David Sterba
2025-02-27 7:06 ` Johannes Thumshirn
2025-02-27 7:09 ` [PATCH 00/27] Struct btrfs_path auto cleaning conversions Johannes Thumshirn
2025-02-27 9:55 ` David Sterba
2025-02-27 10:56 ` Johannes Thumshirn
2025-02-27 13:53 ` David Sterba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox