diff options
Diffstat (limited to 'drivers/md/dm-thin-metadata.c')
-rw-r--r-- | drivers/md/dm-thin-metadata.c | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c index 59c4f0446ff..237571af77f 100644 --- a/drivers/md/dm-thin-metadata.c +++ b/drivers/md/dm-thin-metadata.c | |||
@@ -385,6 +385,7 @@ static int init_pmd(struct dm_pool_metadata *pmd, | |||
385 | data_sm = dm_sm_disk_create(tm, nr_blocks); | 385 | data_sm = dm_sm_disk_create(tm, nr_blocks); |
386 | if (IS_ERR(data_sm)) { | 386 | if (IS_ERR(data_sm)) { |
387 | DMERR("sm_disk_create failed"); | 387 | DMERR("sm_disk_create failed"); |
388 | dm_tm_unlock(tm, sblock); | ||
388 | r = PTR_ERR(data_sm); | 389 | r = PTR_ERR(data_sm); |
389 | goto bad; | 390 | goto bad; |
390 | } | 391 | } |
@@ -789,6 +790,11 @@ int dm_pool_metadata_close(struct dm_pool_metadata *pmd) | |||
789 | return 0; | 790 | return 0; |
790 | } | 791 | } |
791 | 792 | ||
793 | /* | ||
794 | * __open_device: Returns @td corresponding to device with id @dev, | ||
795 | * creating it if @create is set and incrementing @td->open_count. | ||
796 | * On failure, @td is undefined. | ||
797 | */ | ||
792 | static int __open_device(struct dm_pool_metadata *pmd, | 798 | static int __open_device(struct dm_pool_metadata *pmd, |
793 | dm_thin_id dev, int create, | 799 | dm_thin_id dev, int create, |
794 | struct dm_thin_device **td) | 800 | struct dm_thin_device **td) |
@@ -799,10 +805,16 @@ static int __open_device(struct dm_pool_metadata *pmd, | |||
799 | struct disk_device_details details_le; | 805 | struct disk_device_details details_le; |
800 | 806 | ||
801 | /* | 807 | /* |
802 | * Check the device isn't already open. | 808 | * If the device is already open, return it. |
803 | */ | 809 | */ |
804 | list_for_each_entry(td2, &pmd->thin_devices, list) | 810 | list_for_each_entry(td2, &pmd->thin_devices, list) |
805 | if (td2->id == dev) { | 811 | if (td2->id == dev) { |
812 | /* | ||
813 | * May not create an already-open device. | ||
814 | */ | ||
815 | if (create) | ||
816 | return -EEXIST; | ||
817 | |||
806 | td2->open_count++; | 818 | td2->open_count++; |
807 | *td = td2; | 819 | *td = td2; |
808 | return 0; | 820 | return 0; |
@@ -817,6 +829,9 @@ static int __open_device(struct dm_pool_metadata *pmd, | |||
817 | if (r != -ENODATA || !create) | 829 | if (r != -ENODATA || !create) |
818 | return r; | 830 | return r; |
819 | 831 | ||
832 | /* | ||
833 | * Create new device. | ||
834 | */ | ||
820 | changed = 1; | 835 | changed = 1; |
821 | details_le.mapped_blocks = 0; | 836 | details_le.mapped_blocks = 0; |
822 | details_le.transaction_id = cpu_to_le64(pmd->trans_id); | 837 | details_le.transaction_id = cpu_to_le64(pmd->trans_id); |
@@ -882,12 +897,10 @@ static int __create_thin(struct dm_pool_metadata *pmd, | |||
882 | 897 | ||
883 | r = __open_device(pmd, dev, 1, &td); | 898 | r = __open_device(pmd, dev, 1, &td); |
884 | if (r) { | 899 | if (r) { |
885 | __close_device(td); | ||
886 | dm_btree_remove(&pmd->tl_info, pmd->root, &key, &pmd->root); | 900 | dm_btree_remove(&pmd->tl_info, pmd->root, &key, &pmd->root); |
887 | dm_btree_del(&pmd->bl_info, dev_root); | 901 | dm_btree_del(&pmd->bl_info, dev_root); |
888 | return r; | 902 | return r; |
889 | } | 903 | } |
890 | td->changed = 1; | ||
891 | __close_device(td); | 904 | __close_device(td); |
892 | 905 | ||
893 | return r; | 906 | return r; |
@@ -967,14 +980,14 @@ static int __create_snap(struct dm_pool_metadata *pmd, | |||
967 | goto bad; | 980 | goto bad; |
968 | 981 | ||
969 | r = __set_snapshot_details(pmd, td, origin, pmd->time); | 982 | r = __set_snapshot_details(pmd, td, origin, pmd->time); |
983 | __close_device(td); | ||
984 | |||
970 | if (r) | 985 | if (r) |
971 | goto bad; | 986 | goto bad; |
972 | 987 | ||
973 | __close_device(td); | ||
974 | return 0; | 988 | return 0; |
975 | 989 | ||
976 | bad: | 990 | bad: |
977 | __close_device(td); | ||
978 | dm_btree_remove(&pmd->tl_info, pmd->root, &key, &pmd->root); | 991 | dm_btree_remove(&pmd->tl_info, pmd->root, &key, &pmd->root); |
979 | dm_btree_remove(&pmd->details_info, pmd->details_root, | 992 | dm_btree_remove(&pmd->details_info, pmd->details_root, |
980 | &key, &pmd->details_root); | 993 | &key, &pmd->details_root); |
@@ -1211,6 +1224,8 @@ static int __remove(struct dm_thin_device *td, dm_block_t block) | |||
1211 | if (r) | 1224 | if (r) |
1212 | return r; | 1225 | return r; |
1213 | 1226 | ||
1227 | td->mapped_blocks--; | ||
1228 | td->changed = 1; | ||
1214 | pmd->need_commit = 1; | 1229 | pmd->need_commit = 1; |
1215 | 1230 | ||
1216 | return 0; | 1231 | return 0; |