diff options
author | Xiao Guangrong <xiaoguangrong@cn.fujitsu.com> | 2011-04-20 06:08:47 -0400 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2011-05-23 13:24:43 -0400 |
commit | 46224705656633466ca7dc71d81b3c0abc76cae4 (patch) | |
tree | 2cdc8c8cc82c2262edb8d89a27e5539359e61c40 /fs/btrfs | |
parent | 0c1daee085cff1395d1eba4ad6faff7810a594d8 (diff) |
Btrfs: drop unnecessary device lock
Drop device_list_mutex for the reader side on clone_fs_devices and
btrfs_rm_device pathes since the fs_info->volume_mutex can ensure the device
list is not updated
btrfs_close_extra_devices is the initialized path, we can not add or remove
device at this time, so we can simply drop the mutex safely, like other
initialized function does(add_missing_dev, __find_device, __btrfs_open_devices
...).
Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r-- | fs/btrfs/volumes.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index ee197ec28547..0b5ca2737268 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c | |||
@@ -406,7 +406,7 @@ static struct btrfs_fs_devices *clone_fs_devices(struct btrfs_fs_devices *orig) | |||
406 | fs_devices->latest_trans = orig->latest_trans; | 406 | fs_devices->latest_trans = orig->latest_trans; |
407 | memcpy(fs_devices->fsid, orig->fsid, sizeof(fs_devices->fsid)); | 407 | memcpy(fs_devices->fsid, orig->fsid, sizeof(fs_devices->fsid)); |
408 | 408 | ||
409 | mutex_lock(&orig->device_list_mutex); | 409 | /* We have held the volume lock, it is safe to get the devices. */ |
410 | list_for_each_entry(orig_dev, &orig->devices, dev_list) { | 410 | list_for_each_entry(orig_dev, &orig->devices, dev_list) { |
411 | device = kzalloc(sizeof(*device), GFP_NOFS); | 411 | device = kzalloc(sizeof(*device), GFP_NOFS); |
412 | if (!device) | 412 | if (!device) |
@@ -429,10 +429,8 @@ static struct btrfs_fs_devices *clone_fs_devices(struct btrfs_fs_devices *orig) | |||
429 | device->fs_devices = fs_devices; | 429 | device->fs_devices = fs_devices; |
430 | fs_devices->num_devices++; | 430 | fs_devices->num_devices++; |
431 | } | 431 | } |
432 | mutex_unlock(&orig->device_list_mutex); | ||
433 | return fs_devices; | 432 | return fs_devices; |
434 | error: | 433 | error: |
435 | mutex_unlock(&orig->device_list_mutex); | ||
436 | free_fs_devices(fs_devices); | 434 | free_fs_devices(fs_devices); |
437 | return ERR_PTR(-ENOMEM); | 435 | return ERR_PTR(-ENOMEM); |
438 | } | 436 | } |
@@ -443,7 +441,7 @@ int btrfs_close_extra_devices(struct btrfs_fs_devices *fs_devices) | |||
443 | 441 | ||
444 | mutex_lock(&uuid_mutex); | 442 | mutex_lock(&uuid_mutex); |
445 | again: | 443 | again: |
446 | mutex_lock(&fs_devices->device_list_mutex); | 444 | /* This is the initialized path, it is safe to release the devices. */ |
447 | list_for_each_entry_safe(device, next, &fs_devices->devices, dev_list) { | 445 | list_for_each_entry_safe(device, next, &fs_devices->devices, dev_list) { |
448 | if (device->in_fs_metadata) | 446 | if (device->in_fs_metadata) |
449 | continue; | 447 | continue; |
@@ -463,7 +461,6 @@ again: | |||
463 | kfree(device->name); | 461 | kfree(device->name); |
464 | kfree(device); | 462 | kfree(device); |
465 | } | 463 | } |
466 | mutex_unlock(&fs_devices->device_list_mutex); | ||
467 | 464 | ||
468 | if (fs_devices->seed) { | 465 | if (fs_devices->seed) { |
469 | fs_devices = fs_devices->seed; | 466 | fs_devices = fs_devices->seed; |
@@ -1242,14 +1239,16 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path) | |||
1242 | 1239 | ||
1243 | device = NULL; | 1240 | device = NULL; |
1244 | devices = &root->fs_info->fs_devices->devices; | 1241 | devices = &root->fs_info->fs_devices->devices; |
1245 | mutex_lock(&root->fs_info->fs_devices->device_list_mutex); | 1242 | /* |
1243 | * It is safe to read the devices since the volume_mutex | ||
1244 | * is held. | ||
1245 | */ | ||
1246 | list_for_each_entry(tmp, devices, dev_list) { | 1246 | list_for_each_entry(tmp, devices, dev_list) { |
1247 | if (tmp->in_fs_metadata && !tmp->bdev) { | 1247 | if (tmp->in_fs_metadata && !tmp->bdev) { |
1248 | device = tmp; | 1248 | device = tmp; |
1249 | break; | 1249 | break; |
1250 | } | 1250 | } |
1251 | } | 1251 | } |
1252 | mutex_unlock(&root->fs_info->fs_devices->device_list_mutex); | ||
1253 | bdev = NULL; | 1252 | bdev = NULL; |
1254 | bh = NULL; | 1253 | bh = NULL; |
1255 | disk_super = NULL; | 1254 | disk_super = NULL; |