Skip to content

Commit 2522dbe

Browse files
adam900710kdave
authored andcommitted
btrfs: scrub: remove the unnecessary path parameter for scrub_raid56_parity()
In function scrub_stripe() we allocated two btrfs_path's, one @path for extent tree search and another @ppath for full stripe extent tree search for RAID56. This is totally umncessary, as the @ppath usage is completely inside scrub_raid56_parity(), thus we can move the path allocation into scrub_raid56_parity() completely. Signed-off-by: Qu Wenruo <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent c122799 commit 2522dbe

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

fs/btrfs/scrub.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2885,7 +2885,6 @@ static void scrub_parity_put(struct scrub_parity *sparity)
28852885
static noinline_for_stack int scrub_raid56_parity(struct scrub_ctx *sctx,
28862886
struct map_lookup *map,
28872887
struct btrfs_device *sdev,
2888-
struct btrfs_path *path,
28892888
u64 logic_start,
28902889
u64 logic_end)
28912890
{
@@ -2894,6 +2893,7 @@ static noinline_for_stack int scrub_raid56_parity(struct scrub_ctx *sctx,
28942893
struct btrfs_root *csum_root;
28952894
struct btrfs_extent_item *extent;
28962895
struct btrfs_io_context *bioc = NULL;
2896+
struct btrfs_path *path;
28972897
u64 flags;
28982898
int ret;
28992899
int slot;
@@ -2912,6 +2912,16 @@ static noinline_for_stack int scrub_raid56_parity(struct scrub_ctx *sctx,
29122912
int extent_mirror_num;
29132913
int stop_loop = 0;
29142914

2915+
path = btrfs_alloc_path();
2916+
if (!path) {
2917+
spin_lock(&sctx->stat_lock);
2918+
sctx->stat.malloc_errors++;
2919+
spin_unlock(&sctx->stat_lock);
2920+
return -ENOMEM;
2921+
}
2922+
path->search_commit_root = 1;
2923+
path->skip_locking = 1;
2924+
29152925
ASSERT(map->stripe_len <= U32_MAX);
29162926
nsectors = map->stripe_len >> fs_info->sectorsize_bits;
29172927
bitmap_len = scrub_calc_parity_bitmap_len(nsectors);
@@ -2921,6 +2931,7 @@ static noinline_for_stack int scrub_raid56_parity(struct scrub_ctx *sctx,
29212931
spin_lock(&sctx->stat_lock);
29222932
sctx->stat.malloc_errors++;
29232933
spin_unlock(&sctx->stat_lock);
2934+
btrfs_free_path(path);
29242935
return -ENOMEM;
29252936
}
29262937

@@ -3110,7 +3121,7 @@ static noinline_for_stack int scrub_raid56_parity(struct scrub_ctx *sctx,
31103121
scrub_wr_submit(sctx);
31113122
mutex_unlock(&sctx->wr_lock);
31123123

3113-
btrfs_release_path(path);
3124+
btrfs_free_path(path);
31143125
return ret < 0 ? ret : 0;
31153126
}
31163127

@@ -3160,7 +3171,7 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
31603171
int num, u64 base, u64 length,
31613172
struct btrfs_block_group *cache)
31623173
{
3163-
struct btrfs_path *path, *ppath;
3174+
struct btrfs_path *path;
31643175
struct btrfs_fs_info *fs_info = sctx->fs_info;
31653176
struct btrfs_root *root;
31663177
struct btrfs_root *csum_root;
@@ -3222,12 +3233,6 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
32223233
if (!path)
32233234
return -ENOMEM;
32243235

3225-
ppath = btrfs_alloc_path();
3226-
if (!ppath) {
3227-
btrfs_free_path(path);
3228-
return -ENOMEM;
3229-
}
3230-
32313236
/*
32323237
* work on commit root. The related disk blocks are static as
32333238
* long as COW is applied. This means, it is save to rewrite
@@ -3236,8 +3241,6 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
32363241
path->search_commit_root = 1;
32373242
path->skip_locking = 1;
32383243

3239-
ppath->search_commit_root = 1;
3240-
ppath->skip_locking = 1;
32413244
/*
32423245
* trigger the readahead for extent tree csum tree and wait for
32433246
* completion. During readahead, the scrub is officially paused
@@ -3340,7 +3343,7 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
33403343
stripe_logical += base;
33413344
stripe_end = stripe_logical + increment;
33423345
ret = scrub_raid56_parity(sctx, map, scrub_dev,
3343-
ppath, stripe_logical,
3346+
stripe_logical,
33443347
stripe_end);
33453348
if (ret)
33463349
goto out;
@@ -3511,7 +3514,7 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
35113514
stripe_end = stripe_logical +
35123515
increment;
35133516
ret = scrub_raid56_parity(sctx,
3514-
map, scrub_dev, ppath,
3517+
map, scrub_dev,
35153518
stripe_logical,
35163519
stripe_end);
35173520
if (ret)
@@ -3558,7 +3561,6 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
35583561

35593562
blk_finish_plug(&plug);
35603563
btrfs_free_path(path);
3561-
btrfs_free_path(ppath);
35623564

35633565
if (sctx->is_dev_replace && ret >= 0) {
35643566
int ret2;

0 commit comments

Comments
 (0)