diff options
Diffstat (limited to 'fs/btrfs/dev-replace.c')
-rw-r--r-- | fs/btrfs/dev-replace.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c index 264105a26e7e..c7f2d6b91a6f 100644 --- a/fs/btrfs/dev-replace.c +++ b/fs/btrfs/dev-replace.c | |||
@@ -400,6 +400,7 @@ int btrfs_dev_replace_start(struct btrfs_fs_info *fs_info, | |||
400 | int ret; | 400 | int ret; |
401 | struct btrfs_device *tgt_device = NULL; | 401 | struct btrfs_device *tgt_device = NULL; |
402 | struct btrfs_device *src_device = NULL; | 402 | struct btrfs_device *src_device = NULL; |
403 | bool need_unlock; | ||
403 | 404 | ||
404 | src_device = btrfs_find_device_by_devspec(fs_info, srcdevid, | 405 | src_device = btrfs_find_device_by_devspec(fs_info, srcdevid, |
405 | srcdev_name); | 406 | srcdev_name); |
@@ -424,6 +425,7 @@ int btrfs_dev_replace_start(struct btrfs_fs_info *fs_info, | |||
424 | return PTR_ERR(trans); | 425 | return PTR_ERR(trans); |
425 | } | 426 | } |
426 | 427 | ||
428 | need_unlock = true; | ||
427 | btrfs_dev_replace_write_lock(dev_replace); | 429 | btrfs_dev_replace_write_lock(dev_replace); |
428 | switch (dev_replace->replace_state) { | 430 | switch (dev_replace->replace_state) { |
429 | case BTRFS_IOCTL_DEV_REPLACE_STATE_NEVER_STARTED: | 431 | case BTRFS_IOCTL_DEV_REPLACE_STATE_NEVER_STARTED: |
@@ -463,6 +465,7 @@ int btrfs_dev_replace_start(struct btrfs_fs_info *fs_info, | |||
463 | atomic64_set(&dev_replace->num_write_errors, 0); | 465 | atomic64_set(&dev_replace->num_write_errors, 0); |
464 | atomic64_set(&dev_replace->num_uncorrectable_read_errors, 0); | 466 | atomic64_set(&dev_replace->num_uncorrectable_read_errors, 0); |
465 | btrfs_dev_replace_write_unlock(dev_replace); | 467 | btrfs_dev_replace_write_unlock(dev_replace); |
468 | need_unlock = false; | ||
466 | 469 | ||
467 | ret = btrfs_sysfs_add_device_link(tgt_device->fs_devices, tgt_device); | 470 | ret = btrfs_sysfs_add_device_link(tgt_device->fs_devices, tgt_device); |
468 | if (ret) | 471 | if (ret) |
@@ -474,6 +477,7 @@ int btrfs_dev_replace_start(struct btrfs_fs_info *fs_info, | |||
474 | trans = btrfs_start_transaction(root, 0); | 477 | trans = btrfs_start_transaction(root, 0); |
475 | if (IS_ERR(trans)) { | 478 | if (IS_ERR(trans)) { |
476 | ret = PTR_ERR(trans); | 479 | ret = PTR_ERR(trans); |
480 | need_unlock = true; | ||
477 | btrfs_dev_replace_write_lock(dev_replace); | 481 | btrfs_dev_replace_write_lock(dev_replace); |
478 | dev_replace->replace_state = | 482 | dev_replace->replace_state = |
479 | BTRFS_IOCTL_DEV_REPLACE_STATE_NEVER_STARTED; | 483 | BTRFS_IOCTL_DEV_REPLACE_STATE_NEVER_STARTED; |
@@ -500,7 +504,8 @@ int btrfs_dev_replace_start(struct btrfs_fs_info *fs_info, | |||
500 | return ret; | 504 | return ret; |
501 | 505 | ||
502 | leave: | 506 | leave: |
503 | btrfs_dev_replace_write_unlock(dev_replace); | 507 | if (need_unlock) |
508 | btrfs_dev_replace_write_unlock(dev_replace); | ||
504 | btrfs_destroy_dev_replace_tgtdev(tgt_device); | 509 | btrfs_destroy_dev_replace_tgtdev(tgt_device); |
505 | return ret; | 510 | return ret; |
506 | } | 511 | } |