Skip to content

Commit 9566997

Browse files
Miao Xiemasoncl
authored andcommitted
Btrfs: don't consider the missing device when allocating new chunks
The original code allocated new chunks by the number of the writable devices and missing devices to make sure that any RAID levels on a degraded FS continue to be honored, but it introduced a problem that it stopped us to allocating new chunks, the steps to reproduce is following: # mkfs.btrfs -m raid1 -d raid1 -f <dev0> <dev1> # mkfs.btrfs -f <dev1> //Removing <dev1> from the original fs # mount -o degraded <dev0> <mnt> # dd if=/dev/null of=<mnt>/tmpfile bs=1M It is because we allocate new chunks only on the writable devices, if we take the number of missing devices into account, and want to allocate new chunks with higher RAID level, we will fail becaue we don't have enough writable device. Fix it by ignoring the number of missing devices when allocating new chunks. Signed-off-by: Miao Xie <[email protected]> Signed-off-by: Chris Mason <[email protected]>
1 parent 7df69d3 commit 9566997

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

fs/btrfs/extent-tree.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3586,13 +3586,7 @@ static u64 get_restripe_target(struct btrfs_fs_info *fs_info, u64 flags)
35863586
*/
35873587
static u64 btrfs_reduce_alloc_profile(struct btrfs_root *root, u64 flags)
35883588
{
3589-
/*
3590-
* we add in the count of missing devices because we want
3591-
* to make sure that any RAID levels on a degraded FS
3592-
* continue to be honored.
3593-
*/
3594-
u64 num_devices = root->fs_info->fs_devices->rw_devices +
3595-
root->fs_info->fs_devices->missing_devices;
3589+
u64 num_devices = root->fs_info->fs_devices->rw_devices;
35963590
u64 target;
35973591
u64 tmp;
35983592

@@ -8440,13 +8434,7 @@ static u64 update_block_group_flags(struct btrfs_root *root, u64 flags)
84408434
if (stripped)
84418435
return extended_to_chunk(stripped);
84428436

8443-
/*
8444-
* we add in the count of missing devices because we want
8445-
* to make sure that any RAID levels on a degraded FS
8446-
* continue to be honored.
8447-
*/
8448-
num_devices = root->fs_info->fs_devices->rw_devices +
8449-
root->fs_info->fs_devices->missing_devices;
8437+
num_devices = root->fs_info->fs_devices->rw_devices;
84508438

84518439
stripped = BTRFS_BLOCK_GROUP_RAID0 |
84528440
BTRFS_BLOCK_GROUP_RAID5 | BTRFS_BLOCK_GROUP_RAID6 |

0 commit comments

Comments
 (0)