Skip to content

Commit ce9f967

Browse files
Johannes Thumshirnkdave
authored andcommitted
btrfs: use EXPORT_FOR_TESTS for conditionally exported functions
Several functions in BTRFS are only used inside the source file they are declared if CONFIG_BTRFS_FS_RUN_SANITY_TESTS is not defined. However if CONFIG_BTRFS_FS_RUN_SANITY_TESTS is defined these functions are shared with the unit tests code. Before the introduction of the EXPORT_FOR_TESTS macro, these functions could not be declared as static and the compiler had a harder task when optimizing and inlining them. As we have EXPORT_FOR_TESTS now, use it where appropriate to support the compiler. Reviewed-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent f8f591d commit ce9f967

4 files changed

Lines changed: 20 additions & 25 deletions

File tree

‎fs/btrfs/extent_io.c‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,7 +1556,8 @@ static noinline int lock_delalloc_pages(struct inode *inode,
15561556
*
15571557
* 1 is returned if we find something, 0 if nothing was in the tree
15581558
*/
1559-
static noinline_for_stack u64 find_lock_delalloc_range(struct inode *inode,
1559+
EXPORT_FOR_TESTS
1560+
noinline_for_stack u64 find_lock_delalloc_range(struct inode *inode,
15601561
struct extent_io_tree *tree,
15611562
struct page *locked_page, u64 *start,
15621563
u64 *end)
@@ -1637,16 +1638,6 @@ static noinline_for_stack u64 find_lock_delalloc_range(struct inode *inode,
16371638
return found;
16381639
}
16391640

1640-
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
1641-
u64 btrfs_find_lock_delalloc_range(struct inode *inode,
1642-
struct extent_io_tree *tree,
1643-
struct page *locked_page, u64 *start,
1644-
u64 *end)
1645-
{
1646-
return find_lock_delalloc_range(inode, tree, locked_page, start, end);
1647-
}
1648-
#endif
1649-
16501641
static int __process_pages_contig(struct address_space *mapping,
16511642
struct page *locked_page,
16521643
pgoff_t start_index, pgoff_t end_index,

‎fs/btrfs/extent_io.h‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -522,10 +522,9 @@ int free_io_failure(struct extent_io_tree *failure_tree,
522522
struct extent_io_tree *io_tree,
523523
struct io_failure_record *rec);
524524
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
525-
u64 btrfs_find_lock_delalloc_range(struct inode *inode,
526-
struct extent_io_tree *tree,
527-
struct page *locked_page, u64 *start,
528-
u64 *end);
525+
u64 find_lock_delalloc_range(struct inode *inode, struct extent_io_tree *tree,
526+
struct page *locked_page, u64 *start,
527+
u64 *end);
529528
#endif
530529
struct extent_buffer *alloc_test_extent_buffer(struct btrfs_fs_info *fs_info,
531530
u64 start);

‎fs/btrfs/free-space-tree.c‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ static int add_new_free_space_info(struct btrfs_trans_handle *trans,
7474
return ret;
7575
}
7676

77-
struct btrfs_free_space_info *
78-
search_free_space_info(struct btrfs_trans_handle *trans,
79-
struct btrfs_fs_info *fs_info,
80-
struct btrfs_block_group_cache *block_group,
81-
struct btrfs_path *path, int cow)
77+
EXPORT_FOR_TESTS
78+
struct btrfs_free_space_info *search_free_space_info(
79+
struct btrfs_trans_handle *trans, struct btrfs_fs_info *fs_info,
80+
struct btrfs_block_group_cache *block_group,
81+
struct btrfs_path *path, int cow)
8282
{
8383
struct btrfs_root *root = fs_info->free_space_root;
8484
struct btrfs_key key;
@@ -176,6 +176,7 @@ static void le_bitmap_set(unsigned long *map, unsigned int start, int len)
176176
}
177177
}
178178

179+
EXPORT_FOR_TESTS
179180
int convert_free_space_to_bitmaps(struct btrfs_trans_handle *trans,
180181
struct btrfs_block_group_cache *block_group,
181182
struct btrfs_path *path)
@@ -315,6 +316,7 @@ int convert_free_space_to_bitmaps(struct btrfs_trans_handle *trans,
315316
return ret;
316317
}
317318

319+
EXPORT_FOR_TESTS
318320
int convert_free_space_to_extents(struct btrfs_trans_handle *trans,
319321
struct btrfs_block_group_cache *block_group,
320322
struct btrfs_path *path)
@@ -487,6 +489,7 @@ static int update_free_space_extent_count(struct btrfs_trans_handle *trans,
487489
return ret;
488490
}
489491

492+
EXPORT_FOR_TESTS
490493
int free_space_test_bit(struct btrfs_block_group_cache *block_group,
491494
struct btrfs_path *path, u64 offset)
492495
{
@@ -775,6 +778,7 @@ static int remove_free_space_extent(struct btrfs_trans_handle *trans,
775778
return ret;
776779
}
777780

781+
EXPORT_FOR_TESTS
778782
int __remove_from_free_space_tree(struct btrfs_trans_handle *trans,
779783
struct btrfs_block_group_cache *block_group,
780784
struct btrfs_path *path, u64 start, u64 size)
@@ -968,6 +972,7 @@ static int add_free_space_extent(struct btrfs_trans_handle *trans,
968972
return ret;
969973
}
970974

975+
EXPORT_FOR_TESTS
971976
int __add_to_free_space_tree(struct btrfs_trans_handle *trans,
972977
struct btrfs_block_group_cache *block_group,
973978
struct btrfs_path *path, u64 start, u64 size)

‎fs/btrfs/tests/extent-io-tests.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ static int test_find_delalloc(u32 sectorsize)
107107
set_extent_delalloc(&tmp, 0, sectorsize - 1, 0, NULL);
108108
start = 0;
109109
end = 0;
110-
found = btrfs_find_lock_delalloc_range(inode, &tmp, locked_page, &start,
110+
found = find_lock_delalloc_range(inode, &tmp, locked_page, &start,
111111
&end);
112112
if (!found) {
113113
test_err("should have found at least one delalloc");
@@ -138,7 +138,7 @@ static int test_find_delalloc(u32 sectorsize)
138138
set_extent_delalloc(&tmp, sectorsize, max_bytes - 1, 0, NULL);
139139
start = test_start;
140140
end = 0;
141-
found = btrfs_find_lock_delalloc_range(inode, &tmp, locked_page, &start,
141+
found = find_lock_delalloc_range(inode, &tmp, locked_page, &start,
142142
&end);
143143
if (!found) {
144144
test_err("couldn't find delalloc in our range");
@@ -172,7 +172,7 @@ static int test_find_delalloc(u32 sectorsize)
172172
}
173173
start = test_start;
174174
end = 0;
175-
found = btrfs_find_lock_delalloc_range(inode, &tmp, locked_page, &start,
175+
found = find_lock_delalloc_range(inode, &tmp, locked_page, &start,
176176
&end);
177177
if (found) {
178178
test_err("found range when we shouldn't have");
@@ -193,7 +193,7 @@ static int test_find_delalloc(u32 sectorsize)
193193
set_extent_delalloc(&tmp, max_bytes, total_dirty - 1, 0, NULL);
194194
start = test_start;
195195
end = 0;
196-
found = btrfs_find_lock_delalloc_range(inode, &tmp, locked_page, &start,
196+
found = find_lock_delalloc_range(inode, &tmp, locked_page, &start,
197197
&end);
198198
if (!found) {
199199
test_err("didn't find our range");
@@ -234,7 +234,7 @@ static int test_find_delalloc(u32 sectorsize)
234234
* this changes at any point in the future we will need to fix this
235235
* tests expected behavior.
236236
*/
237-
found = btrfs_find_lock_delalloc_range(inode, &tmp, locked_page, &start,
237+
found = find_lock_delalloc_range(inode, &tmp, locked_page, &start,
238238
&end);
239239
if (!found) {
240240
test_err("didn't find our range");

0 commit comments

Comments
 (0)