]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
Btrfs: do not add extra mirror when dev_replace target dev is not available
authorLiu Bo <bo.li.liu@oracle.com>
Tue, 14 Mar 2017 20:33:59 +0000 (13:33 -0700)
committerDavid Sterba <dsterba@suse.com>
Tue, 18 Apr 2017 12:07:25 +0000 (14:07 +0200)
With this, we can avoid allocating memory for dev replace copies if the
target dev is not available.

Reviewed-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/volumes.c

index f27f9cebce240fb91ae9be2897658c6fc6d53a25..8cc40268c50c8be51cd7b744b2019588f88184c0 100644 (file)
@@ -5157,7 +5157,8 @@ int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len)
        free_extent_map(em);
 
        btrfs_dev_replace_lock(&fs_info->dev_replace, 0);
-       if (btrfs_dev_replace_is_ongoing(&fs_info->dev_replace))
+       if (btrfs_dev_replace_is_ongoing(&fs_info->dev_replace) &&
+           fs_info->dev_replace.tgtdev)
                ret++;
        btrfs_dev_replace_unlock(&fs_info->dev_replace, 0);
 
@@ -5845,7 +5846,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
        }
 
        num_alloc_stripes = num_stripes;
-       if (dev_replace_is_ongoing) {
+       if (dev_replace_is_ongoing && dev_replace->tgtdev != NULL) {
                if (op == BTRFS_MAP_WRITE)
                        num_alloc_stripes <<= 1;
                if (op == BTRFS_MAP_GET_READ_MIRRORS)
@@ -5858,7 +5859,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
                ret = -ENOMEM;
                goto out;
        }
-       if (dev_replace_is_ongoing)
+       if (dev_replace_is_ongoing && dev_replace->tgtdev != NULL)
                bbio->tgtdev_map = (int *)(bbio->stripes + num_alloc_stripes);
 
        /* build raid_map */