aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/btrfs/scrub.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 2907a77fb1f6..6b3fd51d9a99 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -3483,6 +3483,7 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
3483 u64 length; 3483 u64 length;
3484 u64 chunk_offset; 3484 u64 chunk_offset;
3485 int ret = 0; 3485 int ret = 0;
3486 int ro_set;
3486 int slot; 3487 int slot;
3487 struct extent_buffer *l; 3488 struct extent_buffer *l;
3488 struct btrfs_key key; 3489 struct btrfs_key key;
@@ -3568,7 +3569,21 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
3568 scrub_pause_on(fs_info); 3569 scrub_pause_on(fs_info);
3569 ret = btrfs_inc_block_group_ro(root, cache); 3570 ret = btrfs_inc_block_group_ro(root, cache);
3570 scrub_pause_off(fs_info); 3571 scrub_pause_off(fs_info);
3571 if (ret) { 3572
3573 if (ret == 0) {
3574 ro_set = 1;
3575 } else if (ret == -ENOSPC) {
3576 /*
3577 * btrfs_inc_block_group_ro return -ENOSPC when it
3578 * failed in creating new chunk for metadata.
3579 * It is not a problem for scrub/replace, because
3580 * metadata are always cowed, and our scrub paused
3581 * commit_transactions.
3582 */
3583 ro_set = 0;
3584 } else {
3585 btrfs_warn(fs_info, "failed setting block group ro, ret=%d\n",
3586 ret);
3572 btrfs_put_block_group(cache); 3587 btrfs_put_block_group(cache);
3573 break; 3588 break;
3574 } 3589 }
@@ -3611,7 +3626,8 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
3611 3626
3612 scrub_pause_off(fs_info); 3627 scrub_pause_off(fs_info);
3613 3628
3614 btrfs_dec_block_group_ro(root, cache); 3629 if (ro_set)
3630 btrfs_dec_block_group_ro(root, cache);
3615 3631
3616 btrfs_put_block_group(cache); 3632 btrfs_put_block_group(cache);
3617 if (ret) 3633 if (ret)