]> git.baikalelectronics.ru Git - kernel.git/commitdiff
btrfs: zoned: relocate block group to repair IO failure in zoned filesystems
authorNaohiro Aota <naohiro.aota@wdc.com>
Thu, 4 Feb 2021 10:22:16 +0000 (19:22 +0900)
committerDavid Sterba <dsterba@suse.com>
Tue, 9 Feb 2021 01:46:07 +0000 (02:46 +0100)
When a bad checksum is found and if the filesystem has a mirror of the
damaged data, we read the correct data from the mirror and writes it to
damaged blocks. This however, violates the sequential write constraints
of a zoned block device.

We can consider three methods to repair an IO failure in zoned filesystems:

(1) Reset and rewrite the damaged zone
(2) Allocate new device extent and replace the damaged device extent to
    the new extent
(3) Relocate the corresponding block group

Method (1) is most similar to a behavior done with regular devices.
However, it also wipes non-damaged data in the same device extent, and
so it unnecessary degrades non-damaged data.

Method (2) is much like device replacing but done in the same device. It
is safe because it keeps the device extent until the replacing finish.
However, extending device replacing is non-trivial. It assumes
"src_dev->physical == dst_dev->physical". Also, the extent mapping
replacing function should be extended to support replacing device extent
position in one device.

Method (3) invokes relocation of the damaged block group and is
straightforward to implement. It relocates all the mirrored device
extents, so it potentially is a more costly operation than method (1) or
(2). But it relocates only used extents which reduce the total IO size.

Let's apply method (3) for now. In the future, we can extend device-replace
and apply method (2).

For protecting a block group gets relocated multiple time with multiple
IO errors, this commit introduces "relocating_repair" bit to show it's
now relocating to repair IO failures. Also it uses a new kthread
"btrfs-relocating-repair", not to block IO path with relocating process.

This commit also supports repairing in the scrub process.

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/block-group.h
fs/btrfs/extent_io.c
fs/btrfs/scrub.c
fs/btrfs/volumes.c
fs/btrfs/volumes.h

index d37ee576ac6ec81ee27e965596e467d2e5d28822..29678426247deb52a687232f93e574c8aaaee9b5 100644 (file)
@@ -96,6 +96,7 @@ struct btrfs_block_group {
        unsigned int has_caching_ctl:1;
        unsigned int removed:1;
        unsigned int to_copy:1;
+       unsigned int relocating_repair:1;
 
        int disk_cache_state;
 
index dfa6c6106b945715fac9b83e1886cc34835856b1..4dfb3ead117572d883bbe5e6ea724b94385539b6 100644 (file)
@@ -2260,6 +2260,9 @@ int repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start,
        ASSERT(!(fs_info->sb->s_flags & SB_RDONLY));
        BUG_ON(!mirror_num);
 
+       if (btrfs_is_zoned(fs_info))
+               return btrfs_repair_one_zone(fs_info, logical);
+
        bio = btrfs_io_bio_alloc(1);
        bio->bi_iter.bi_size = 0;
        map_length = length;
index e0c3ec01e3244a225f187f0d1fd9adfa871a8c1e..310fce00fcda94347edfd56b2a38f4c065dd6a96 100644 (file)
@@ -857,6 +857,9 @@ static int scrub_handle_errored_block(struct scrub_block *sblock_to_check)
        have_csum = sblock_to_check->pagev[0]->have_csum;
        dev = sblock_to_check->pagev[0]->dev;
 
+       if (btrfs_is_zoned(fs_info) && !sctx->is_dev_replace)
+               return btrfs_repair_one_zone(fs_info, logical);
+
        /*
         * We must use GFP_NOFS because the scrub task might be waiting for a
         * worker task executing this function and in turn a transaction commit
index 1312b17a6b492a590147f58f01ec588103195131..b8fab44394f5a5a4666a769a60de3d8cdc3c3516 100644 (file)
@@ -7980,3 +7980,75 @@ bool btrfs_pinned_by_swapfile(struct btrfs_fs_info *fs_info, void *ptr)
        spin_unlock(&fs_info->swapfile_pins_lock);
        return node != NULL;
 }
+
+static int relocating_repair_kthread(void *data)
+{
+       struct btrfs_block_group *cache = (struct btrfs_block_group *)data;
+       struct btrfs_fs_info *fs_info = cache->fs_info;
+       u64 target;
+       int ret = 0;
+
+       target = cache->start;
+       btrfs_put_block_group(cache);
+
+       if (!btrfs_exclop_start(fs_info, BTRFS_EXCLOP_BALANCE)) {
+               btrfs_info(fs_info,
+                          "zoned: skip relocating block group %llu to repair: EBUSY",
+                          target);
+               return -EBUSY;
+       }
+
+       mutex_lock(&fs_info->delete_unused_bgs_mutex);
+
+       /* Ensure block group still exists */
+       cache = btrfs_lookup_block_group(fs_info, target);
+       if (!cache)
+               goto out;
+
+       if (!cache->relocating_repair)
+               goto out;
+
+       ret = btrfs_may_alloc_data_chunk(fs_info, target);
+       if (ret < 0)
+               goto out;
+
+       btrfs_info(fs_info,
+                  "zoned: relocating block group %llu to repair IO failure",
+                  target);
+       ret = btrfs_relocate_chunk(fs_info, target);
+
+out:
+       if (cache)
+               btrfs_put_block_group(cache);
+       mutex_unlock(&fs_info->delete_unused_bgs_mutex);
+       btrfs_exclop_finish(fs_info);
+
+       return ret;
+}
+
+int btrfs_repair_one_zone(struct btrfs_fs_info *fs_info, u64 logical)
+{
+       struct btrfs_block_group *cache;
+
+       /* Do not attempt to repair in degraded state */
+       if (btrfs_test_opt(fs_info, DEGRADED))
+               return 0;
+
+       cache = btrfs_lookup_block_group(fs_info, logical);
+       if (!cache)
+               return 0;
+
+       spin_lock(&cache->lock);
+       if (cache->relocating_repair) {
+               spin_unlock(&cache->lock);
+               btrfs_put_block_group(cache);
+               return 0;
+       }
+       cache->relocating_repair = 1;
+       spin_unlock(&cache->lock);
+
+       kthread_run(relocating_repair_kthread, cache,
+                   "btrfs-relocating-repair");
+
+       return 0;
+}
index d3bbdb4175df82fc8a065a51b75144248e357c6e..d4c3e0dd32b87e31992c9baf775d13dbcf93d39e 100644 (file)
@@ -599,5 +599,6 @@ void btrfs_scratch_superblocks(struct btrfs_fs_info *fs_info,
 int btrfs_bg_type_to_factor(u64 flags);
 const char *btrfs_bg_type_to_raid_name(u64 flags);
 int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info);
+int btrfs_repair_one_zone(struct btrfs_fs_info *fs_info, u64 logical);
 
 #endif