Skip to content

Commit d04fbe1

Browse files
adam900710kdave
authored andcommitted
btrfs: scrub: cleanup the argument list of scrub_chunk()
The argument list of scrub_chunk() has the following problems: - Duplicated @chunk_offset It is the same as btrfs_block_group::start. - Confusing @Length The most instinctive guess is chunk length, and one may want to delete it, but the truth is, it's the device extent length. Fix this by: - Remove @chunk_offset Use btrfs_block_group::start instead. - Rename @Length to @dev_extent_len Also rename the caller to remove the ambiguous naming. - Rename @cache to @bg The "_cache" suffix for btrfs_block_group has been removed for a while. Signed-off-by: Qu Wenruo <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent f26c923 commit d04fbe1

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

fs/btrfs/scrub.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3541,10 +3541,10 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
35413541
}
35423542

35433543
static noinline_for_stack int scrub_chunk(struct scrub_ctx *sctx,
3544+
struct btrfs_block_group *bg,
35443545
struct btrfs_device *scrub_dev,
3545-
u64 chunk_offset, u64 length,
35463546
u64 dev_offset,
3547-
struct btrfs_block_group *cache)
3547+
u64 dev_extent_len)
35483548
{
35493549
struct btrfs_fs_info *fs_info = sctx->fs_info;
35503550
struct extent_map_tree *map_tree = &fs_info->mapping_tree;
@@ -3554,34 +3554,32 @@ static noinline_for_stack int scrub_chunk(struct scrub_ctx *sctx,
35543554
int ret = 0;
35553555

35563556
read_lock(&map_tree->lock);
3557-
em = lookup_extent_mapping(map_tree, chunk_offset, 1);
3557+
em = lookup_extent_mapping(map_tree, bg->start, bg->length);
35583558
read_unlock(&map_tree->lock);
35593559

35603560
if (!em) {
35613561
/*
35623562
* Might have been an unused block group deleted by the cleaner
35633563
* kthread or relocation.
35643564
*/
3565-
spin_lock(&cache->lock);
3566-
if (!cache->removed)
3565+
spin_lock(&bg->lock);
3566+
if (!bg->removed)
35673567
ret = -EINVAL;
3568-
spin_unlock(&cache->lock);
3568+
spin_unlock(&bg->lock);
35693569

35703570
return ret;
35713571
}
3572-
3573-
map = em->map_lookup;
3574-
if (em->start != chunk_offset)
3572+
if (em->start != bg->start)
35753573
goto out;
3576-
3577-
if (em->len < length)
3574+
if (em->len < dev_extent_len)
35783575
goto out;
35793576

3577+
map = em->map_lookup;
35803578
for (i = 0; i < map->num_stripes; ++i) {
35813579
if (map->stripes[i].dev->bdev == scrub_dev->bdev &&
35823580
map->stripes[i].physical == dev_offset) {
35833581
ret = scrub_stripe(sctx, map, scrub_dev, i,
3584-
chunk_offset, length, cache);
3582+
bg->start, dev_extent_len, bg);
35853583
if (ret)
35863584
goto out;
35873585
}
@@ -3619,7 +3617,6 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
36193617
struct btrfs_path *path;
36203618
struct btrfs_fs_info *fs_info = sctx->fs_info;
36213619
struct btrfs_root *root = fs_info->dev_root;
3622-
u64 length;
36233620
u64 chunk_offset;
36243621
int ret = 0;
36253622
int ro_set;
@@ -3643,6 +3640,8 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
36433640
key.type = BTRFS_DEV_EXTENT_KEY;
36443641

36453642
while (1) {
3643+
u64 dev_extent_len;
3644+
36463645
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
36473646
if (ret < 0)
36483647
break;
@@ -3679,9 +3678,9 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
36793678
break;
36803679

36813680
dev_extent = btrfs_item_ptr(l, slot, struct btrfs_dev_extent);
3682-
length = btrfs_dev_extent_length(l, dev_extent);
3681+
dev_extent_len = btrfs_dev_extent_length(l, dev_extent);
36833682

3684-
if (found_key.offset + length <= start)
3683+
if (found_key.offset + dev_extent_len <= start)
36853684
goto skip;
36863685

36873686
chunk_offset = btrfs_dev_extent_chunk_offset(l, dev_extent);
@@ -3815,13 +3814,14 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
38153814

38163815
scrub_pause_off(fs_info);
38173816
down_write(&dev_replace->rwsem);
3818-
dev_replace->cursor_right = found_key.offset + length;
3817+
dev_replace->cursor_right = found_key.offset + dev_extent_len;
38193818
dev_replace->cursor_left = found_key.offset;
38203819
dev_replace->item_needs_writeback = 1;
38213820
up_write(&dev_replace->rwsem);
38223821

3823-
ret = scrub_chunk(sctx, scrub_dev, chunk_offset, length,
3824-
found_key.offset, cache);
3822+
ASSERT(cache->start == chunk_offset);
3823+
ret = scrub_chunk(sctx, cache, scrub_dev, found_key.offset,
3824+
dev_extent_len);
38253825

38263826
/*
38273827
* flush, submit all pending read and write bios, afterwards
@@ -3902,7 +3902,7 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
39023902
break;
39033903
}
39043904
skip:
3905-
key.offset = found_key.offset + length;
3905+
key.offset = found_key.offset + dev_extent_len;
39063906
btrfs_release_path(path);
39073907
}
39083908

0 commit comments

Comments
 (0)