Skip to content

Commit 9978059

Browse files
Goldwyn Rodrigueskdave
authored andcommitted
btrfs: Evaluate io_tree in find_lock_delalloc_range()
Simplification. No point passing the tree variable when it can be evaluated from inode. The tests now use the io_tree from btrfs_inode as opposed to creating one. Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 67f9c22 commit 9978059

3 files changed

Lines changed: 19 additions & 19 deletions

File tree

‎fs/btrfs/extent_io.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,10 +1780,10 @@ static noinline int lock_delalloc_pages(struct inode *inode,
17801780
*/
17811781
EXPORT_FOR_TESTS
17821782
noinline_for_stack bool find_lock_delalloc_range(struct inode *inode,
1783-
struct extent_io_tree *tree,
17841783
struct page *locked_page, u64 *start,
17851784
u64 *end)
17861785
{
1786+
struct extent_io_tree *tree = &BTRFS_I(inode)->io_tree;
17871787
u64 max_bytes = BTRFS_MAX_EXTENT_SIZE;
17881788
u64 delalloc_start;
17891789
u64 delalloc_end;
@@ -3330,7 +3330,6 @@ static noinline_for_stack int writepage_delalloc(struct inode *inode,
33303330
struct page *page, struct writeback_control *wbc,
33313331
u64 delalloc_start, unsigned long *nr_written)
33323332
{
3333-
struct extent_io_tree *tree = &BTRFS_I(inode)->io_tree;
33343333
u64 page_end = delalloc_start + PAGE_SIZE - 1;
33353334
bool found;
33363335
u64 delalloc_to_write = 0;
@@ -3340,8 +3339,7 @@ static noinline_for_stack int writepage_delalloc(struct inode *inode,
33403339

33413340

33423341
while (delalloc_end < page_end) {
3343-
found = find_lock_delalloc_range(inode, tree,
3344-
page,
3342+
found = find_lock_delalloc_range(inode, page,
33453343
&delalloc_start,
33463344
&delalloc_end);
33473345
if (!found) {

‎fs/btrfs/extent_io.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ int free_io_failure(struct extent_io_tree *failure_tree,
549549
struct extent_io_tree *io_tree,
550550
struct io_failure_record *rec);
551551
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
552-
bool find_lock_delalloc_range(struct inode *inode, struct extent_io_tree *tree,
552+
bool find_lock_delalloc_range(struct inode *inode,
553553
struct page *locked_page, u64 *start,
554554
u64 *end);
555555
#endif

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "btrfs-tests.h"
1111
#include "../ctree.h"
1212
#include "../extent_io.h"
13+
#include "../btrfs_inode.h"
1314

1415
#define PROCESS_UNLOCK (1 << 0)
1516
#define PROCESS_RELEASE (1 << 1)
@@ -58,7 +59,7 @@ static noinline int process_page_range(struct inode *inode, u64 start, u64 end,
5859
static int test_find_delalloc(u32 sectorsize)
5960
{
6061
struct inode *inode;
61-
struct extent_io_tree tmp;
62+
struct extent_io_tree *tmp;
6263
struct page *page;
6364
struct page *locked_page = NULL;
6465
unsigned long index = 0;
@@ -76,12 +77,13 @@ static int test_find_delalloc(u32 sectorsize)
7677
test_std_err(TEST_ALLOC_INODE);
7778
return -ENOMEM;
7879
}
80+
tmp = &BTRFS_I(inode)->io_tree;
7981

8082
/*
8183
* Passing NULL as we don't have fs_info but tracepoints are not used
8284
* at this point
8385
*/
84-
extent_io_tree_init(NULL, &tmp, IO_TREE_SELFTEST, NULL);
86+
extent_io_tree_init(NULL, tmp, IO_TREE_SELFTEST, NULL);
8587

8688
/*
8789
* First go through and create and mark all of our pages dirty, we pin
@@ -108,10 +110,10 @@ static int test_find_delalloc(u32 sectorsize)
108110
* |--- delalloc ---|
109111
* |--- search ---|
110112
*/
111-
set_extent_delalloc(&tmp, 0, sectorsize - 1, 0, NULL);
113+
set_extent_delalloc(tmp, 0, sectorsize - 1, 0, NULL);
112114
start = 0;
113115
end = 0;
114-
found = find_lock_delalloc_range(inode, &tmp, locked_page, &start,
116+
found = find_lock_delalloc_range(inode, locked_page, &start,
115117
&end);
116118
if (!found) {
117119
test_err("should have found at least one delalloc");
@@ -122,7 +124,7 @@ static int test_find_delalloc(u32 sectorsize)
122124
sectorsize - 1, start, end);
123125
goto out_bits;
124126
}
125-
unlock_extent(&tmp, start, end);
127+
unlock_extent(tmp, start, end);
126128
unlock_page(locked_page);
127129
put_page(locked_page);
128130

@@ -139,10 +141,10 @@ static int test_find_delalloc(u32 sectorsize)
139141
test_err("couldn't find the locked page");
140142
goto out_bits;
141143
}
142-
set_extent_delalloc(&tmp, sectorsize, max_bytes - 1, 0, NULL);
144+
set_extent_delalloc(tmp, sectorsize, max_bytes - 1, 0, NULL);
143145
start = test_start;
144146
end = 0;
145-
found = find_lock_delalloc_range(inode, &tmp, locked_page, &start,
147+
found = find_lock_delalloc_range(inode, locked_page, &start,
146148
&end);
147149
if (!found) {
148150
test_err("couldn't find delalloc in our range");
@@ -158,7 +160,7 @@ static int test_find_delalloc(u32 sectorsize)
158160
test_err("there were unlocked pages in the range");
159161
goto out_bits;
160162
}
161-
unlock_extent(&tmp, start, end);
163+
unlock_extent(tmp, start, end);
162164
/* locked_page was unlocked above */
163165
put_page(locked_page);
164166

@@ -176,7 +178,7 @@ static int test_find_delalloc(u32 sectorsize)
176178
}
177179
start = test_start;
178180
end = 0;
179-
found = find_lock_delalloc_range(inode, &tmp, locked_page, &start,
181+
found = find_lock_delalloc_range(inode, locked_page, &start,
180182
&end);
181183
if (found) {
182184
test_err("found range when we shouldn't have");
@@ -194,10 +196,10 @@ static int test_find_delalloc(u32 sectorsize)
194196
*
195197
* We are re-using our test_start from above since it works out well.
196198
*/
197-
set_extent_delalloc(&tmp, max_bytes, total_dirty - 1, 0, NULL);
199+
set_extent_delalloc(tmp, max_bytes, total_dirty - 1, 0, NULL);
198200
start = test_start;
199201
end = 0;
200-
found = find_lock_delalloc_range(inode, &tmp, locked_page, &start,
202+
found = find_lock_delalloc_range(inode, locked_page, &start,
201203
&end);
202204
if (!found) {
203205
test_err("didn't find our range");
@@ -213,7 +215,7 @@ static int test_find_delalloc(u32 sectorsize)
213215
test_err("pages in range were not all locked");
214216
goto out_bits;
215217
}
216-
unlock_extent(&tmp, start, end);
218+
unlock_extent(tmp, start, end);
217219

218220
/*
219221
* Now to test where we run into a page that is no longer dirty in the
@@ -238,7 +240,7 @@ static int test_find_delalloc(u32 sectorsize)
238240
* this changes at any point in the future we will need to fix this
239241
* tests expected behavior.
240242
*/
241-
found = find_lock_delalloc_range(inode, &tmp, locked_page, &start,
243+
found = find_lock_delalloc_range(inode, locked_page, &start,
242244
&end);
243245
if (!found) {
244246
test_err("didn't find our range");
@@ -256,7 +258,7 @@ static int test_find_delalloc(u32 sectorsize)
256258
}
257259
ret = 0;
258260
out_bits:
259-
clear_extent_bits(&tmp, 0, total_dirty - 1, (unsigned)-1);
261+
clear_extent_bits(tmp, 0, total_dirty - 1, (unsigned)-1);
260262
out:
261263
if (locked_page)
262264
put_page(locked_page);

0 commit comments

Comments
 (0)