Commit 0c1daee0 authored by Xiao Guangrong's avatar Xiao Guangrong Committed by Chris Mason

Btrfs: fix the race between remove dev and alloc chunk

On remove device path, it updates device->dev_alloc_list but does not hold
chunk lock
Signed-off-by: default avatarXiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent c9513edb
...@@ -1291,7 +1291,9 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path) ...@@ -1291,7 +1291,9 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
} }
if (device->writeable) { if (device->writeable) {
lock_chunks(root);
list_del_init(&device->dev_alloc_list); list_del_init(&device->dev_alloc_list);
unlock_chunks(root);
root->fs_info->fs_devices->rw_devices--; root->fs_info->fs_devices->rw_devices--;
} }
...@@ -1345,7 +1347,9 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path) ...@@ -1345,7 +1347,9 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
} }
fs_devices->seed = device->fs_devices->seed; fs_devices->seed = device->fs_devices->seed;
device->fs_devices->seed = NULL; device->fs_devices->seed = NULL;
lock_chunks(root);
__btrfs_close_devices(device->fs_devices); __btrfs_close_devices(device->fs_devices);
unlock_chunks(root);
free_fs_devices(device->fs_devices); free_fs_devices(device->fs_devices);
} }
...@@ -1377,8 +1381,10 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path) ...@@ -1377,8 +1381,10 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
return ret; return ret;
error_undo: error_undo:
if (device->writeable) { if (device->writeable) {
lock_chunks(root);
list_add(&device->dev_alloc_list, list_add(&device->dev_alloc_list,
&root->fs_info->fs_devices->alloc_list); &root->fs_info->fs_devices->alloc_list);
unlock_chunks(root);
root->fs_info->fs_devices->rw_devices++; root->fs_info->fs_devices->rw_devices++;
} }
goto error_brelse; goto error_brelse;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment