Skip to content

Commit ced96ed

Browse files
Qu WenruoChris Mason
authored andcommitted
btrfs: Skip scrubbing removed chunks to avoid -ENOENT.
When run scrub with balance, sometimes -ENOENT will be returned, since in scrub_enumerate_chunks() will search dev_extent in *COMMIT_ROOT*, but btrfs_lookup_block_group() will search block group in *MEMORY*, so if a chunk is removed but not committed, -ENOENT will be returned. However, there is no need to stop scrubbing since other chunks may be scrubbed without problem. So this patch changes the behavior to skip removed chunks and continue to scrub the rest. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: Miao Xie <miaox@cn.fujitsu.com> Signed-off-by: Chris Mason <clm@fb.com>
1 parent e570fd2 commit ced96ed

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

‎fs/btrfs/scrub.c‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2725,11 +2725,8 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
27252725
dev_extent = btrfs_item_ptr(l, slot, struct btrfs_dev_extent);
27262726
length = btrfs_dev_extent_length(l, dev_extent);
27272727

2728-
if (found_key.offset + length <= start) {
2729-
key.offset = found_key.offset + length;
2730-
btrfs_release_path(path);
2731-
continue;
2732-
}
2728+
if (found_key.offset + length <= start)
2729+
goto skip;
27332730

27342731
chunk_tree = btrfs_dev_extent_chunk_tree(l, dev_extent);
27352732
chunk_objectid = btrfs_dev_extent_chunk_objectid(l, dev_extent);
@@ -2740,10 +2737,12 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
27402737
* the chunk from going away while we scrub it
27412738
*/
27422739
cache = btrfs_lookup_block_group(fs_info, chunk_offset);
2743-
if (!cache) {
2744-
ret = -ENOENT;
2745-
break;
2746-
}
2740+
2741+
/* some chunks are removed but not committed to disk yet,
2742+
* continue scrubbing */
2743+
if (!cache)
2744+
goto skip;
2745+
27472746
dev_replace->cursor_right = found_key.offset + length;
27482747
dev_replace->cursor_left = found_key.offset;
27492748
dev_replace->item_needs_writeback = 1;
@@ -2802,7 +2801,7 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
28022801

28032802
dev_replace->cursor_left = dev_replace->cursor_right;
28042803
dev_replace->item_needs_writeback = 1;
2805-
2804+
skip:
28062805
key.offset = found_key.offset + length;
28072806
btrfs_release_path(path);
28082807
}

0 commit comments

Comments
 (0)