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 <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Qu Wenruo 2021-12-15 14:59:41 +08:00 committed by David Sterba
parent f26c923860
commit d04fbe19ae

View File

@ -3541,10 +3541,10 @@ out:
} }
static noinline_for_stack int scrub_chunk(struct scrub_ctx *sctx, static noinline_for_stack int scrub_chunk(struct scrub_ctx *sctx,
struct btrfs_block_group *bg,
struct btrfs_device *scrub_dev, struct btrfs_device *scrub_dev,
u64 chunk_offset, u64 length,
u64 dev_offset, u64 dev_offset,
struct btrfs_block_group *cache) u64 dev_extent_len)
{ {
struct btrfs_fs_info *fs_info = sctx->fs_info; struct btrfs_fs_info *fs_info = sctx->fs_info;
struct extent_map_tree *map_tree = &fs_info->mapping_tree; struct extent_map_tree *map_tree = &fs_info->mapping_tree;
@ -3554,7 +3554,7 @@ static noinline_for_stack int scrub_chunk(struct scrub_ctx *sctx,
int ret = 0; int ret = 0;
read_lock(&map_tree->lock); read_lock(&map_tree->lock);
em = lookup_extent_mapping(map_tree, chunk_offset, 1); em = lookup_extent_mapping(map_tree, bg->start, bg->length);
read_unlock(&map_tree->lock); read_unlock(&map_tree->lock);
if (!em) { if (!em) {
@ -3562,26 +3562,24 @@ static noinline_for_stack int scrub_chunk(struct scrub_ctx *sctx,
* Might have been an unused block group deleted by the cleaner * Might have been an unused block group deleted by the cleaner
* kthread or relocation. * kthread or relocation.
*/ */
spin_lock(&cache->lock); spin_lock(&bg->lock);
if (!cache->removed) if (!bg->removed)
ret = -EINVAL; ret = -EINVAL;
spin_unlock(&cache->lock); spin_unlock(&bg->lock);
return ret; return ret;
} }
if (em->start != bg->start)
goto out;
if (em->len < dev_extent_len)
goto out;
map = em->map_lookup; map = em->map_lookup;
if (em->start != chunk_offset)
goto out;
if (em->len < length)
goto out;
for (i = 0; i < map->num_stripes; ++i) { for (i = 0; i < map->num_stripes; ++i) {
if (map->stripes[i].dev->bdev == scrub_dev->bdev && if (map->stripes[i].dev->bdev == scrub_dev->bdev &&
map->stripes[i].physical == dev_offset) { map->stripes[i].physical == dev_offset) {
ret = scrub_stripe(sctx, map, scrub_dev, i, ret = scrub_stripe(sctx, map, scrub_dev, i,
chunk_offset, length, cache); bg->start, dev_extent_len, bg);
if (ret) if (ret)
goto out; goto out;
} }
@ -3619,7 +3617,6 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
struct btrfs_path *path; struct btrfs_path *path;
struct btrfs_fs_info *fs_info = sctx->fs_info; struct btrfs_fs_info *fs_info = sctx->fs_info;
struct btrfs_root *root = fs_info->dev_root; struct btrfs_root *root = fs_info->dev_root;
u64 length;
u64 chunk_offset; u64 chunk_offset;
int ret = 0; int ret = 0;
int ro_set; int ro_set;
@ -3643,6 +3640,8 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
key.type = BTRFS_DEV_EXTENT_KEY; key.type = BTRFS_DEV_EXTENT_KEY;
while (1) { while (1) {
u64 dev_extent_len;
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
if (ret < 0) if (ret < 0)
break; break;
@ -3679,9 +3678,9 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
break; break;
dev_extent = btrfs_item_ptr(l, slot, struct btrfs_dev_extent); dev_extent = btrfs_item_ptr(l, slot, struct btrfs_dev_extent);
length = btrfs_dev_extent_length(l, dev_extent); dev_extent_len = btrfs_dev_extent_length(l, dev_extent);
if (found_key.offset + length <= start) if (found_key.offset + dev_extent_len <= start)
goto skip; goto skip;
chunk_offset = btrfs_dev_extent_chunk_offset(l, dev_extent); chunk_offset = btrfs_dev_extent_chunk_offset(l, dev_extent);
@ -3815,13 +3814,14 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
scrub_pause_off(fs_info); scrub_pause_off(fs_info);
down_write(&dev_replace->rwsem); down_write(&dev_replace->rwsem);
dev_replace->cursor_right = found_key.offset + length; dev_replace->cursor_right = found_key.offset + dev_extent_len;
dev_replace->cursor_left = found_key.offset; dev_replace->cursor_left = found_key.offset;
dev_replace->item_needs_writeback = 1; dev_replace->item_needs_writeback = 1;
up_write(&dev_replace->rwsem); up_write(&dev_replace->rwsem);
ret = scrub_chunk(sctx, scrub_dev, chunk_offset, length, ASSERT(cache->start == chunk_offset);
found_key.offset, cache); ret = scrub_chunk(sctx, cache, scrub_dev, found_key.offset,
dev_extent_len);
/* /*
* flush, submit all pending read and write bios, afterwards * flush, submit all pending read and write bios, afterwards
@ -3902,7 +3902,7 @@ skip_unfreeze:
break; break;
} }
skip: skip:
key.offset = found_key.offset + length; key.offset = found_key.offset + dev_extent_len;
btrfs_release_path(path); btrfs_release_path(path);
} }