Lines Matching refs:pmd
230 struct dm_pool_metadata *pmd; member
413 static inline void pmd_write_lock_in_core(struct dm_pool_metadata *pmd) in pmd_write_lock_in_core() argument
414 __acquires(pmd->root_lock) in pmd_write_lock_in_core()
416 down_write(&pmd->root_lock); in pmd_write_lock_in_core()
419 static inline void pmd_write_lock(struct dm_pool_metadata *pmd) in pmd_write_lock() argument
421 pmd_write_lock_in_core(pmd); in pmd_write_lock()
422 if (unlikely(!pmd->in_service)) in pmd_write_lock()
423 pmd->in_service = true; in pmd_write_lock()
426 static inline void pmd_write_unlock(struct dm_pool_metadata *pmd) in pmd_write_unlock() argument
427 __releases(pmd->root_lock) in pmd_write_unlock()
429 up_write(&pmd->root_lock); in pmd_write_unlock()
434 static int superblock_lock_zero(struct dm_pool_metadata *pmd, in superblock_lock_zero() argument
437 return dm_bm_write_lock_zero(pmd->bm, THIN_SUPERBLOCK_LOCATION, in superblock_lock_zero()
441 static int superblock_lock(struct dm_pool_metadata *pmd, in superblock_lock() argument
444 return dm_bm_write_lock(pmd->bm, THIN_SUPERBLOCK_LOCATION, in superblock_lock()
477 static void __setup_btree_details(struct dm_pool_metadata *pmd) in __setup_btree_details() argument
479 pmd->info.tm = pmd->tm; in __setup_btree_details()
480 pmd->info.levels = 2; in __setup_btree_details()
481 pmd->info.value_type.context = pmd->data_sm; in __setup_btree_details()
482 pmd->info.value_type.size = sizeof(__le64); in __setup_btree_details()
483 pmd->info.value_type.inc = data_block_inc; in __setup_btree_details()
484 pmd->info.value_type.dec = data_block_dec; in __setup_btree_details()
485 pmd->info.value_type.equal = data_block_equal; in __setup_btree_details()
487 memcpy(&pmd->nb_info, &pmd->info, sizeof(pmd->nb_info)); in __setup_btree_details()
488 pmd->nb_info.tm = pmd->nb_tm; in __setup_btree_details()
490 pmd->tl_info.tm = pmd->tm; in __setup_btree_details()
491 pmd->tl_info.levels = 1; in __setup_btree_details()
492 pmd->tl_info.value_type.context = &pmd->bl_info; in __setup_btree_details()
493 pmd->tl_info.value_type.size = sizeof(__le64); in __setup_btree_details()
494 pmd->tl_info.value_type.inc = subtree_inc; in __setup_btree_details()
495 pmd->tl_info.value_type.dec = subtree_dec; in __setup_btree_details()
496 pmd->tl_info.value_type.equal = subtree_equal; in __setup_btree_details()
498 pmd->bl_info.tm = pmd->tm; in __setup_btree_details()
499 pmd->bl_info.levels = 1; in __setup_btree_details()
500 pmd->bl_info.value_type.context = pmd->data_sm; in __setup_btree_details()
501 pmd->bl_info.value_type.size = sizeof(__le64); in __setup_btree_details()
502 pmd->bl_info.value_type.inc = data_block_inc; in __setup_btree_details()
503 pmd->bl_info.value_type.dec = data_block_dec; in __setup_btree_details()
504 pmd->bl_info.value_type.equal = data_block_equal; in __setup_btree_details()
506 pmd->details_info.tm = pmd->tm; in __setup_btree_details()
507 pmd->details_info.levels = 1; in __setup_btree_details()
508 pmd->details_info.value_type.context = NULL; in __setup_btree_details()
509 pmd->details_info.value_type.size = sizeof(struct disk_device_details); in __setup_btree_details()
510 pmd->details_info.value_type.inc = NULL; in __setup_btree_details()
511 pmd->details_info.value_type.dec = NULL; in __setup_btree_details()
512 pmd->details_info.value_type.equal = NULL; in __setup_btree_details()
515 static int save_sm_roots(struct dm_pool_metadata *pmd) in save_sm_roots() argument
520 r = dm_sm_root_size(pmd->metadata_sm, &len); in save_sm_roots()
524 r = dm_sm_copy_root(pmd->metadata_sm, &pmd->metadata_space_map_root, len); in save_sm_roots()
528 r = dm_sm_root_size(pmd->data_sm, &len); in save_sm_roots()
532 return dm_sm_copy_root(pmd->data_sm, &pmd->data_space_map_root, len); in save_sm_roots()
535 static void copy_sm_roots(struct dm_pool_metadata *pmd, in copy_sm_roots() argument
539 &pmd->metadata_space_map_root, in copy_sm_roots()
540 sizeof(pmd->metadata_space_map_root)); in copy_sm_roots()
543 &pmd->data_space_map_root, in copy_sm_roots()
544 sizeof(pmd->data_space_map_root)); in copy_sm_roots()
547 static int __write_initial_superblock(struct dm_pool_metadata *pmd) in __write_initial_superblock() argument
552 sector_t bdev_size = bdev_nr_sectors(pmd->bdev); in __write_initial_superblock()
557 r = dm_sm_commit(pmd->data_sm); in __write_initial_superblock()
561 r = dm_tm_pre_commit(pmd->tm); in __write_initial_superblock()
565 r = save_sm_roots(pmd); in __write_initial_superblock()
569 r = superblock_lock_zero(pmd, &sblock); in __write_initial_superblock()
582 copy_sm_roots(pmd, disk_super); in __write_initial_superblock()
584 disk_super->data_mapping_root = cpu_to_le64(pmd->root); in __write_initial_superblock()
585 disk_super->device_details_root = cpu_to_le64(pmd->details_root); in __write_initial_superblock()
588 disk_super->data_block_size = cpu_to_le32(pmd->data_block_size); in __write_initial_superblock()
590 return dm_tm_commit(pmd->tm, sblock); in __write_initial_superblock()
593 static int __format_metadata(struct dm_pool_metadata *pmd) in __format_metadata() argument
597 r = dm_tm_create_with_sm(pmd->bm, THIN_SUPERBLOCK_LOCATION, in __format_metadata()
598 &pmd->tm, &pmd->metadata_sm); in __format_metadata()
604 pmd->data_sm = dm_sm_disk_create(pmd->tm, 0); in __format_metadata()
605 if (IS_ERR(pmd->data_sm)) { in __format_metadata()
607 r = PTR_ERR(pmd->data_sm); in __format_metadata()
611 pmd->nb_tm = dm_tm_create_non_blocking_clone(pmd->tm); in __format_metadata()
612 if (!pmd->nb_tm) { in __format_metadata()
618 __setup_btree_details(pmd); in __format_metadata()
620 r = dm_btree_empty(&pmd->info, &pmd->root); in __format_metadata()
624 r = dm_btree_empty(&pmd->details_info, &pmd->details_root); in __format_metadata()
630 r = __write_initial_superblock(pmd); in __format_metadata()
637 dm_tm_destroy(pmd->nb_tm); in __format_metadata()
639 dm_sm_destroy(pmd->data_sm); in __format_metadata()
641 dm_tm_destroy(pmd->tm); in __format_metadata()
642 dm_sm_destroy(pmd->metadata_sm); in __format_metadata()
648 struct dm_pool_metadata *pmd) in __check_incompat_features() argument
662 if (bdev_read_only(pmd->bdev)) in __check_incompat_features()
675 static int __open_metadata(struct dm_pool_metadata *pmd) in __open_metadata() argument
681 r = dm_bm_read_lock(pmd->bm, THIN_SUPERBLOCK_LOCATION, in __open_metadata()
691 if (le32_to_cpu(disk_super->data_block_size) != pmd->data_block_size) { in __open_metadata()
694 (unsigned long long)pmd->data_block_size); in __open_metadata()
699 r = __check_incompat_features(disk_super, pmd); in __open_metadata()
703 r = dm_tm_open_with_sm(pmd->bm, THIN_SUPERBLOCK_LOCATION, in __open_metadata()
706 &pmd->tm, &pmd->metadata_sm); in __open_metadata()
712 pmd->data_sm = dm_sm_disk_open(pmd->tm, disk_super->data_space_map_root, in __open_metadata()
714 if (IS_ERR(pmd->data_sm)) { in __open_metadata()
716 r = PTR_ERR(pmd->data_sm); in __open_metadata()
720 pmd->nb_tm = dm_tm_create_non_blocking_clone(pmd->tm); in __open_metadata()
721 if (!pmd->nb_tm) { in __open_metadata()
727 __setup_btree_details(pmd); in __open_metadata()
733 dm_sm_destroy(pmd->data_sm); in __open_metadata()
735 dm_tm_destroy(pmd->tm); in __open_metadata()
736 dm_sm_destroy(pmd->metadata_sm); in __open_metadata()
743 static int __open_or_format_metadata(struct dm_pool_metadata *pmd, bool format_device) in __open_or_format_metadata() argument
747 r = __superblock_all_zeroes(pmd->bm, &unformatted); in __open_or_format_metadata()
752 return format_device ? __format_metadata(pmd) : -EPERM; in __open_or_format_metadata()
754 return __open_metadata(pmd); in __open_or_format_metadata()
757 static int __create_persistent_data_objects(struct dm_pool_metadata *pmd, bool format_device) in __create_persistent_data_objects() argument
761 pmd->bm = dm_block_manager_create(pmd->bdev, THIN_METADATA_BLOCK_SIZE << SECTOR_SHIFT, in __create_persistent_data_objects()
763 if (IS_ERR(pmd->bm)) { in __create_persistent_data_objects()
765 r = PTR_ERR(pmd->bm); in __create_persistent_data_objects()
766 pmd->bm = NULL; in __create_persistent_data_objects()
770 r = __open_or_format_metadata(pmd, format_device); in __create_persistent_data_objects()
772 dm_block_manager_destroy(pmd->bm); in __create_persistent_data_objects()
773 pmd->bm = NULL; in __create_persistent_data_objects()
779 static void __destroy_persistent_data_objects(struct dm_pool_metadata *pmd) in __destroy_persistent_data_objects() argument
781 dm_sm_destroy(pmd->data_sm); in __destroy_persistent_data_objects()
782 dm_sm_destroy(pmd->metadata_sm); in __destroy_persistent_data_objects()
783 dm_tm_destroy(pmd->nb_tm); in __destroy_persistent_data_objects()
784 dm_tm_destroy(pmd->tm); in __destroy_persistent_data_objects()
785 dm_block_manager_destroy(pmd->bm); in __destroy_persistent_data_objects()
788 static int __begin_transaction(struct dm_pool_metadata *pmd) in __begin_transaction() argument
798 r = dm_bm_read_lock(pmd->bm, THIN_SUPERBLOCK_LOCATION, in __begin_transaction()
804 pmd->time = le32_to_cpu(disk_super->time); in __begin_transaction()
805 pmd->root = le64_to_cpu(disk_super->data_mapping_root); in __begin_transaction()
806 pmd->details_root = le64_to_cpu(disk_super->device_details_root); in __begin_transaction()
807 pmd->trans_id = le64_to_cpu(disk_super->trans_id); in __begin_transaction()
808 pmd->flags = le32_to_cpu(disk_super->flags); in __begin_transaction()
809 pmd->data_block_size = le32_to_cpu(disk_super->data_block_size); in __begin_transaction()
815 static int __write_changed_details(struct dm_pool_metadata *pmd) in __write_changed_details() argument
822 list_for_each_entry_safe(td, tmp, &pmd->thin_devices, list) { in __write_changed_details()
834 r = dm_btree_insert(&pmd->details_info, pmd->details_root, in __write_changed_details()
835 &key, &details, &pmd->details_root); in __write_changed_details()
850 static int __commit_transaction(struct dm_pool_metadata *pmd) in __commit_transaction() argument
860 BUG_ON(!rwsem_is_locked(&pmd->root_lock)); in __commit_transaction()
862 if (unlikely(!pmd->in_service)) in __commit_transaction()
865 if (pmd->pre_commit_fn) { in __commit_transaction()
866 r = pmd->pre_commit_fn(pmd->pre_commit_context); in __commit_transaction()
873 r = __write_changed_details(pmd); in __commit_transaction()
877 r = dm_sm_commit(pmd->data_sm); in __commit_transaction()
881 r = dm_tm_pre_commit(pmd->tm); in __commit_transaction()
885 r = save_sm_roots(pmd); in __commit_transaction()
889 r = superblock_lock(pmd, &sblock); in __commit_transaction()
894 disk_super->time = cpu_to_le32(pmd->time); in __commit_transaction()
895 disk_super->data_mapping_root = cpu_to_le64(pmd->root); in __commit_transaction()
896 disk_super->device_details_root = cpu_to_le64(pmd->details_root); in __commit_transaction()
897 disk_super->trans_id = cpu_to_le64(pmd->trans_id); in __commit_transaction()
898 disk_super->flags = cpu_to_le32(pmd->flags); in __commit_transaction()
900 copy_sm_roots(pmd, disk_super); in __commit_transaction()
902 return dm_tm_commit(pmd->tm, sblock); in __commit_transaction()
905 static void __set_metadata_reserve(struct dm_pool_metadata *pmd) in __set_metadata_reserve() argument
911 r = dm_sm_get_nr_blocks(pmd->metadata_sm, &total); in __set_metadata_reserve()
914 pmd->metadata_reserve = max_blocks; in __set_metadata_reserve()
916 pmd->metadata_reserve = min(max_blocks, div_u64(total, 10)); in __set_metadata_reserve()
924 struct dm_pool_metadata *pmd; in dm_pool_metadata_open() local
926 pmd = kmalloc(sizeof(*pmd), GFP_KERNEL); in dm_pool_metadata_open()
927 if (!pmd) { in dm_pool_metadata_open()
932 init_rwsem(&pmd->root_lock); in dm_pool_metadata_open()
933 pmd->time = 0; in dm_pool_metadata_open()
934 INIT_LIST_HEAD(&pmd->thin_devices); in dm_pool_metadata_open()
935 pmd->fail_io = false; in dm_pool_metadata_open()
936 pmd->in_service = false; in dm_pool_metadata_open()
937 pmd->bdev = bdev; in dm_pool_metadata_open()
938 pmd->data_block_size = data_block_size; in dm_pool_metadata_open()
939 pmd->pre_commit_fn = NULL; in dm_pool_metadata_open()
940 pmd->pre_commit_context = NULL; in dm_pool_metadata_open()
942 r = __create_persistent_data_objects(pmd, format_device); in dm_pool_metadata_open()
944 kfree(pmd); in dm_pool_metadata_open()
948 r = __begin_transaction(pmd); in dm_pool_metadata_open()
950 if (dm_pool_metadata_close(pmd) < 0) in dm_pool_metadata_open()
955 __set_metadata_reserve(pmd); in dm_pool_metadata_open()
957 return pmd; in dm_pool_metadata_open()
960 int dm_pool_metadata_close(struct dm_pool_metadata *pmd) in dm_pool_metadata_close() argument
966 down_read(&pmd->root_lock); in dm_pool_metadata_close()
967 list_for_each_entry_safe(td, tmp, &pmd->thin_devices, list) { in dm_pool_metadata_close()
975 up_read(&pmd->root_lock); in dm_pool_metadata_close()
983 pmd_write_lock_in_core(pmd); in dm_pool_metadata_close()
984 if (!pmd->fail_io && !dm_bm_is_read_only(pmd->bm)) { in dm_pool_metadata_close()
985 r = __commit_transaction(pmd); in dm_pool_metadata_close()
990 pmd_write_unlock(pmd); in dm_pool_metadata_close()
991 if (!pmd->fail_io) in dm_pool_metadata_close()
992 __destroy_persistent_data_objects(pmd); in dm_pool_metadata_close()
994 kfree(pmd); in dm_pool_metadata_close()
1003 static int __open_device(struct dm_pool_metadata *pmd, in __open_device() argument
1015 list_for_each_entry(td2, &pmd->thin_devices, list) in __open_device()
1031 r = dm_btree_lookup(&pmd->details_info, pmd->details_root, in __open_device()
1042 details_le.transaction_id = cpu_to_le64(pmd->trans_id); in __open_device()
1043 details_le.creation_time = cpu_to_le32(pmd->time); in __open_device()
1044 details_le.snapshotted_time = cpu_to_le32(pmd->time); in __open_device()
1051 (*td)->pmd = pmd; in __open_device()
1061 list_add(&(*td)->list, &pmd->thin_devices); in __open_device()
1071 static int __create_thin(struct dm_pool_metadata *pmd, in __create_thin() argument
1080 r = dm_btree_lookup(&pmd->details_info, pmd->details_root, in __create_thin()
1088 r = dm_btree_empty(&pmd->bl_info, &dev_root); in __create_thin()
1097 r = dm_btree_insert(&pmd->tl_info, pmd->root, &key, &value, &pmd->root); in __create_thin()
1099 dm_btree_del(&pmd->bl_info, dev_root); in __create_thin()
1103 r = __open_device(pmd, dev, 1, &td); in __create_thin()
1105 dm_btree_remove(&pmd->tl_info, pmd->root, &key, &pmd->root); in __create_thin()
1106 dm_btree_del(&pmd->bl_info, dev_root); in __create_thin()
1114 int dm_pool_create_thin(struct dm_pool_metadata *pmd, dm_thin_id dev) in dm_pool_create_thin() argument
1118 pmd_write_lock(pmd); in dm_pool_create_thin()
1119 if (!pmd->fail_io) in dm_pool_create_thin()
1120 r = __create_thin(pmd, dev); in dm_pool_create_thin()
1121 pmd_write_unlock(pmd); in dm_pool_create_thin()
1126 static int __set_snapshot_details(struct dm_pool_metadata *pmd, in __set_snapshot_details() argument
1133 r = __open_device(pmd, origin, 0, &td); in __set_snapshot_details()
1147 static int __create_snap(struct dm_pool_metadata *pmd, in __create_snap() argument
1157 r = dm_btree_lookup(&pmd->details_info, pmd->details_root, in __create_snap()
1163 r = dm_btree_lookup(&pmd->tl_info, pmd->root, &key, &value); in __create_snap()
1169 dm_tm_inc(pmd->tm, origin_root); in __create_snap()
1175 r = dm_btree_insert(&pmd->tl_info, pmd->root, &key, &value, &pmd->root); in __create_snap()
1177 dm_tm_dec(pmd->tm, origin_root); in __create_snap()
1181 pmd->time++; in __create_snap()
1183 r = __open_device(pmd, dev, 1, &td); in __create_snap()
1187 r = __set_snapshot_details(pmd, td, origin, pmd->time); in __create_snap()
1196 dm_btree_remove(&pmd->tl_info, pmd->root, &key, &pmd->root); in __create_snap()
1197 dm_btree_remove(&pmd->details_info, pmd->details_root, in __create_snap()
1198 &key, &pmd->details_root); in __create_snap()
1202 int dm_pool_create_snap(struct dm_pool_metadata *pmd, in dm_pool_create_snap() argument
1208 pmd_write_lock(pmd); in dm_pool_create_snap()
1209 if (!pmd->fail_io) in dm_pool_create_snap()
1210 r = __create_snap(pmd, dev, origin); in dm_pool_create_snap()
1211 pmd_write_unlock(pmd); in dm_pool_create_snap()
1216 static int __delete_device(struct dm_pool_metadata *pmd, dm_thin_id dev) in __delete_device() argument
1223 r = __open_device(pmd, dev, 0, &td); in __delete_device()
1234 r = dm_btree_remove(&pmd->details_info, pmd->details_root, in __delete_device()
1235 &key, &pmd->details_root); in __delete_device()
1239 r = dm_btree_remove(&pmd->tl_info, pmd->root, &key, &pmd->root); in __delete_device()
1246 int dm_pool_delete_thin_device(struct dm_pool_metadata *pmd, in dm_pool_delete_thin_device() argument
1251 pmd_write_lock(pmd); in dm_pool_delete_thin_device()
1252 if (!pmd->fail_io) in dm_pool_delete_thin_device()
1253 r = __delete_device(pmd, dev); in dm_pool_delete_thin_device()
1254 pmd_write_unlock(pmd); in dm_pool_delete_thin_device()
1259 int dm_pool_set_metadata_transaction_id(struct dm_pool_metadata *pmd, in dm_pool_set_metadata_transaction_id() argument
1265 pmd_write_lock(pmd); in dm_pool_set_metadata_transaction_id()
1267 if (pmd->fail_io) in dm_pool_set_metadata_transaction_id()
1270 if (pmd->trans_id != current_id) { in dm_pool_set_metadata_transaction_id()
1275 pmd->trans_id = new_id; in dm_pool_set_metadata_transaction_id()
1279 pmd_write_unlock(pmd); in dm_pool_set_metadata_transaction_id()
1284 int dm_pool_get_metadata_transaction_id(struct dm_pool_metadata *pmd, in dm_pool_get_metadata_transaction_id() argument
1289 down_read(&pmd->root_lock); in dm_pool_get_metadata_transaction_id()
1290 if (!pmd->fail_io) { in dm_pool_get_metadata_transaction_id()
1291 *result = pmd->trans_id; in dm_pool_get_metadata_transaction_id()
1294 up_read(&pmd->root_lock); in dm_pool_get_metadata_transaction_id()
1299 static int __reserve_metadata_snap(struct dm_pool_metadata *pmd) in __reserve_metadata_snap() argument
1310 r = __commit_transaction(pmd); in __reserve_metadata_snap()
1320 dm_sm_inc_block(pmd->metadata_sm, THIN_SUPERBLOCK_LOCATION); in __reserve_metadata_snap()
1321 r = dm_tm_shadow_block(pmd->tm, THIN_SUPERBLOCK_LOCATION, in __reserve_metadata_snap()
1334 dm_tm_dec(pmd->tm, held_root); in __reserve_metadata_snap()
1335 dm_tm_unlock(pmd->tm, copy); in __reserve_metadata_snap()
1350 dm_tm_inc(pmd->tm, le64_to_cpu(disk_super->data_mapping_root)); in __reserve_metadata_snap()
1351 dm_tm_inc(pmd->tm, le64_to_cpu(disk_super->device_details_root)); in __reserve_metadata_snap()
1352 dm_tm_unlock(pmd->tm, copy); in __reserve_metadata_snap()
1357 r = superblock_lock(pmd, &sblock); in __reserve_metadata_snap()
1359 dm_tm_dec(pmd->tm, held_root); in __reserve_metadata_snap()
1369 int dm_pool_reserve_metadata_snap(struct dm_pool_metadata *pmd) in dm_pool_reserve_metadata_snap() argument
1373 pmd_write_lock(pmd); in dm_pool_reserve_metadata_snap()
1374 if (!pmd->fail_io) in dm_pool_reserve_metadata_snap()
1375 r = __reserve_metadata_snap(pmd); in dm_pool_reserve_metadata_snap()
1376 pmd_write_unlock(pmd); in dm_pool_reserve_metadata_snap()
1381 static int __release_metadata_snap(struct dm_pool_metadata *pmd) in __release_metadata_snap() argument
1388 r = superblock_lock(pmd, &sblock); in __release_metadata_snap()
1403 r = dm_tm_read_lock(pmd->tm, held_root, &sb_validator, ©); in __release_metadata_snap()
1408 dm_btree_del(&pmd->info, le64_to_cpu(disk_super->data_mapping_root)); in __release_metadata_snap()
1409 dm_btree_del(&pmd->details_info, le64_to_cpu(disk_super->device_details_root)); in __release_metadata_snap()
1410 dm_sm_dec_block(pmd->metadata_sm, held_root); in __release_metadata_snap()
1412 dm_tm_unlock(pmd->tm, copy); in __release_metadata_snap()
1417 int dm_pool_release_metadata_snap(struct dm_pool_metadata *pmd) in dm_pool_release_metadata_snap() argument
1421 pmd_write_lock(pmd); in dm_pool_release_metadata_snap()
1422 if (!pmd->fail_io) in dm_pool_release_metadata_snap()
1423 r = __release_metadata_snap(pmd); in dm_pool_release_metadata_snap()
1424 pmd_write_unlock(pmd); in dm_pool_release_metadata_snap()
1429 static int __get_metadata_snap(struct dm_pool_metadata *pmd, in __get_metadata_snap() argument
1436 r = dm_bm_read_lock(pmd->bm, THIN_SUPERBLOCK_LOCATION, in __get_metadata_snap()
1449 int dm_pool_get_metadata_snap(struct dm_pool_metadata *pmd, in dm_pool_get_metadata_snap() argument
1454 down_read(&pmd->root_lock); in dm_pool_get_metadata_snap()
1455 if (!pmd->fail_io) in dm_pool_get_metadata_snap()
1456 r = __get_metadata_snap(pmd, result); in dm_pool_get_metadata_snap()
1457 up_read(&pmd->root_lock); in dm_pool_get_metadata_snap()
1462 int dm_pool_open_thin_device(struct dm_pool_metadata *pmd, dm_thin_id dev, in dm_pool_open_thin_device() argument
1467 pmd_write_lock_in_core(pmd); in dm_pool_open_thin_device()
1468 if (!pmd->fail_io) in dm_pool_open_thin_device()
1469 r = __open_device(pmd, dev, 0, td); in dm_pool_open_thin_device()
1470 pmd_write_unlock(pmd); in dm_pool_open_thin_device()
1477 pmd_write_lock_in_core(td->pmd); in dm_pool_close_thin_device()
1479 pmd_write_unlock(td->pmd); in dm_pool_close_thin_device()
1518 struct dm_pool_metadata *pmd = td->pmd; in __find_block() local
1523 info = &pmd->info; in __find_block()
1525 info = &pmd->nb_info; in __find_block()
1527 r = dm_btree_lookup(info, pmd->root, keys, &value); in __find_block()
1538 struct dm_pool_metadata *pmd = td->pmd; in dm_thin_find_block() local
1540 down_read(&pmd->root_lock); in dm_thin_find_block()
1541 if (pmd->fail_io) { in dm_thin_find_block()
1542 up_read(&pmd->root_lock); in dm_thin_find_block()
1548 up_read(&pmd->root_lock); in dm_thin_find_block()
1558 struct dm_pool_metadata *pmd = td->pmd; in __find_next_mapped_block() local
1561 r = dm_btree_lookup_next(&pmd->info, pmd->root, keys, vblock, &value); in __find_next_mapped_block()
1620 struct dm_pool_metadata *pmd = td->pmd; in dm_thin_find_mapped_range() local
1622 down_read(&pmd->root_lock); in dm_thin_find_mapped_range()
1623 if (!pmd->fail_io) { in dm_thin_find_mapped_range()
1627 up_read(&pmd->root_lock); in dm_thin_find_mapped_range()
1637 struct dm_pool_metadata *pmd = td->pmd; in __insert() local
1640 value = cpu_to_le64(pack_block_time(data_block, pmd->time)); in __insert()
1643 r = dm_btree_insert_notify(&pmd->info, pmd->root, keys, &value, in __insert()
1644 &pmd->root, &inserted); in __insert()
1660 pmd_write_lock(td->pmd); in dm_thin_insert_block()
1661 if (!td->pmd->fail_io) in dm_thin_insert_block()
1663 pmd_write_unlock(td->pmd); in dm_thin_insert_block()
1671 struct dm_pool_metadata *pmd = td->pmd; in __remove() local
1674 r = dm_btree_remove(&pmd->info, pmd->root, keys, &pmd->root); in __remove()
1688 struct dm_pool_metadata *pmd = td->pmd; in __remove_range() local
1696 r = dm_btree_lookup(&pmd->tl_info, pmd->root, keys, &value); in __remove_range()
1705 dm_tm_inc(pmd->tm, mapping_root); in __remove_range()
1706 r = dm_btree_remove(&pmd->tl_info, pmd->root, keys, &pmd->root); in __remove_range()
1715 r = dm_btree_lookup_next(&pmd->bl_info, mapping_root, &begin, &begin, &value); in __remove_range()
1725 r = dm_btree_remove_leaves(&pmd->bl_info, mapping_root, &begin, end, &mapping_root, &count); in __remove_range()
1740 return dm_btree_insert(&pmd->tl_info, pmd->root, keys, &value, &pmd->root); in __remove_range()
1747 pmd_write_lock(td->pmd); in dm_thin_remove_block()
1748 if (!td->pmd->fail_io) in dm_thin_remove_block()
1750 pmd_write_unlock(td->pmd); in dm_thin_remove_block()
1760 pmd_write_lock(td->pmd); in dm_thin_remove_range()
1761 if (!td->pmd->fail_io) in dm_thin_remove_range()
1763 pmd_write_unlock(td->pmd); in dm_thin_remove_range()
1768 int dm_pool_block_is_shared(struct dm_pool_metadata *pmd, dm_block_t b, bool *result) in dm_pool_block_is_shared() argument
1773 down_read(&pmd->root_lock); in dm_pool_block_is_shared()
1774 r = dm_sm_get_count(pmd->data_sm, b, &ref_count); in dm_pool_block_is_shared()
1777 up_read(&pmd->root_lock); in dm_pool_block_is_shared()
1782 int dm_pool_inc_data_range(struct dm_pool_metadata *pmd, dm_block_t b, dm_block_t e) in dm_pool_inc_data_range() argument
1786 pmd_write_lock(pmd); in dm_pool_inc_data_range()
1787 r = dm_sm_inc_blocks(pmd->data_sm, b, e); in dm_pool_inc_data_range()
1788 pmd_write_unlock(pmd); in dm_pool_inc_data_range()
1793 int dm_pool_dec_data_range(struct dm_pool_metadata *pmd, dm_block_t b, dm_block_t e) in dm_pool_dec_data_range() argument
1797 pmd_write_lock(pmd); in dm_pool_dec_data_range()
1798 r = dm_sm_dec_blocks(pmd->data_sm, b, e); in dm_pool_dec_data_range()
1799 pmd_write_unlock(pmd); in dm_pool_dec_data_range()
1808 down_read(&td->pmd->root_lock); in dm_thin_changed_this_transaction()
1810 up_read(&td->pmd->root_lock); in dm_thin_changed_this_transaction()
1815 bool dm_pool_changed_this_transaction(struct dm_pool_metadata *pmd) in dm_pool_changed_this_transaction() argument
1820 down_read(&pmd->root_lock); in dm_pool_changed_this_transaction()
1821 list_for_each_entry_safe(td, tmp, &pmd->thin_devices, list) { in dm_pool_changed_this_transaction()
1827 up_read(&pmd->root_lock); in dm_pool_changed_this_transaction()
1836 down_read(&td->pmd->root_lock); in dm_thin_aborted_changes()
1838 up_read(&td->pmd->root_lock); in dm_thin_aborted_changes()
1843 int dm_pool_alloc_data_block(struct dm_pool_metadata *pmd, dm_block_t *result) in dm_pool_alloc_data_block() argument
1847 pmd_write_lock(pmd); in dm_pool_alloc_data_block()
1848 if (!pmd->fail_io) in dm_pool_alloc_data_block()
1849 r = dm_sm_new_block(pmd->data_sm, result); in dm_pool_alloc_data_block()
1850 pmd_write_unlock(pmd); in dm_pool_alloc_data_block()
1855 int dm_pool_commit_metadata(struct dm_pool_metadata *pmd) in dm_pool_commit_metadata() argument
1863 pmd_write_lock_in_core(pmd); in dm_pool_commit_metadata()
1864 if (pmd->fail_io) in dm_pool_commit_metadata()
1867 r = __commit_transaction(pmd); in dm_pool_commit_metadata()
1874 r = __begin_transaction(pmd); in dm_pool_commit_metadata()
1876 pmd_write_unlock(pmd); in dm_pool_commit_metadata()
1880 static void __set_abort_with_changes_flags(struct dm_pool_metadata *pmd) in __set_abort_with_changes_flags() argument
1884 list_for_each_entry(td, &pmd->thin_devices, list) in __set_abort_with_changes_flags()
1888 int dm_pool_abort_metadata(struct dm_pool_metadata *pmd) in dm_pool_abort_metadata() argument
1892 pmd_write_lock(pmd); in dm_pool_abort_metadata()
1893 if (pmd->fail_io) in dm_pool_abort_metadata()
1896 __set_abort_with_changes_flags(pmd); in dm_pool_abort_metadata()
1897 __destroy_persistent_data_objects(pmd); in dm_pool_abort_metadata()
1898 r = __create_persistent_data_objects(pmd, false); in dm_pool_abort_metadata()
1900 pmd->fail_io = true; in dm_pool_abort_metadata()
1903 pmd_write_unlock(pmd); in dm_pool_abort_metadata()
1908 int dm_pool_get_free_block_count(struct dm_pool_metadata *pmd, dm_block_t *result) in dm_pool_get_free_block_count() argument
1912 down_read(&pmd->root_lock); in dm_pool_get_free_block_count()
1913 if (!pmd->fail_io) in dm_pool_get_free_block_count()
1914 r = dm_sm_get_nr_free(pmd->data_sm, result); in dm_pool_get_free_block_count()
1915 up_read(&pmd->root_lock); in dm_pool_get_free_block_count()
1920 int dm_pool_get_free_metadata_block_count(struct dm_pool_metadata *pmd, in dm_pool_get_free_metadata_block_count() argument
1925 down_read(&pmd->root_lock); in dm_pool_get_free_metadata_block_count()
1926 if (!pmd->fail_io) in dm_pool_get_free_metadata_block_count()
1927 r = dm_sm_get_nr_free(pmd->metadata_sm, result); in dm_pool_get_free_metadata_block_count()
1930 if (*result < pmd->metadata_reserve) in dm_pool_get_free_metadata_block_count()
1933 *result -= pmd->metadata_reserve; in dm_pool_get_free_metadata_block_count()
1935 up_read(&pmd->root_lock); in dm_pool_get_free_metadata_block_count()
1940 int dm_pool_get_metadata_dev_size(struct dm_pool_metadata *pmd, in dm_pool_get_metadata_dev_size() argument
1945 down_read(&pmd->root_lock); in dm_pool_get_metadata_dev_size()
1946 if (!pmd->fail_io) in dm_pool_get_metadata_dev_size()
1947 r = dm_sm_get_nr_blocks(pmd->metadata_sm, result); in dm_pool_get_metadata_dev_size()
1948 up_read(&pmd->root_lock); in dm_pool_get_metadata_dev_size()
1953 int dm_pool_get_data_dev_size(struct dm_pool_metadata *pmd, dm_block_t *result) in dm_pool_get_data_dev_size() argument
1957 down_read(&pmd->root_lock); in dm_pool_get_data_dev_size()
1958 if (!pmd->fail_io) in dm_pool_get_data_dev_size()
1959 r = dm_sm_get_nr_blocks(pmd->data_sm, result); in dm_pool_get_data_dev_size()
1960 up_read(&pmd->root_lock); in dm_pool_get_data_dev_size()
1968 struct dm_pool_metadata *pmd = td->pmd; in dm_thin_get_mapped_count() local
1970 down_read(&pmd->root_lock); in dm_thin_get_mapped_count()
1971 if (!pmd->fail_io) { in dm_thin_get_mapped_count()
1975 up_read(&pmd->root_lock); in dm_thin_get_mapped_count()
1985 struct dm_pool_metadata *pmd = td->pmd; in __highest_block() local
1987 r = dm_btree_lookup(&pmd->tl_info, pmd->root, &td->id, &value_le); in __highest_block()
1993 return dm_btree_find_highest_key(&pmd->bl_info, thin_root, result); in __highest_block()
2000 struct dm_pool_metadata *pmd = td->pmd; in dm_thin_get_highest_mapped_block() local
2002 down_read(&pmd->root_lock); in dm_thin_get_highest_mapped_block()
2003 if (!pmd->fail_io) in dm_thin_get_highest_mapped_block()
2005 up_read(&pmd->root_lock); in dm_thin_get_highest_mapped_block()
2030 int dm_pool_resize_data_dev(struct dm_pool_metadata *pmd, dm_block_t new_count) in dm_pool_resize_data_dev() argument
2034 pmd_write_lock(pmd); in dm_pool_resize_data_dev()
2035 if (!pmd->fail_io) in dm_pool_resize_data_dev()
2036 r = __resize_space_map(pmd->data_sm, new_count); in dm_pool_resize_data_dev()
2037 pmd_write_unlock(pmd); in dm_pool_resize_data_dev()
2042 int dm_pool_resize_metadata_dev(struct dm_pool_metadata *pmd, dm_block_t new_count) in dm_pool_resize_metadata_dev() argument
2046 pmd_write_lock(pmd); in dm_pool_resize_metadata_dev()
2047 if (!pmd->fail_io) { in dm_pool_resize_metadata_dev()
2048 r = __resize_space_map(pmd->metadata_sm, new_count); in dm_pool_resize_metadata_dev()
2050 __set_metadata_reserve(pmd); in dm_pool_resize_metadata_dev()
2052 pmd_write_unlock(pmd); in dm_pool_resize_metadata_dev()
2057 void dm_pool_metadata_read_only(struct dm_pool_metadata *pmd) in dm_pool_metadata_read_only() argument
2059 pmd_write_lock_in_core(pmd); in dm_pool_metadata_read_only()
2060 dm_bm_set_read_only(pmd->bm); in dm_pool_metadata_read_only()
2061 pmd_write_unlock(pmd); in dm_pool_metadata_read_only()
2064 void dm_pool_metadata_read_write(struct dm_pool_metadata *pmd) in dm_pool_metadata_read_write() argument
2066 pmd_write_lock_in_core(pmd); in dm_pool_metadata_read_write()
2067 dm_bm_set_read_write(pmd->bm); in dm_pool_metadata_read_write()
2068 pmd_write_unlock(pmd); in dm_pool_metadata_read_write()
2071 int dm_pool_register_metadata_threshold(struct dm_pool_metadata *pmd, in dm_pool_register_metadata_threshold() argument
2078 pmd_write_lock_in_core(pmd); in dm_pool_register_metadata_threshold()
2079 r = dm_sm_register_threshold_callback(pmd->metadata_sm, threshold, fn, context); in dm_pool_register_metadata_threshold()
2080 pmd_write_unlock(pmd); in dm_pool_register_metadata_threshold()
2085 void dm_pool_register_pre_commit_callback(struct dm_pool_metadata *pmd, in dm_pool_register_pre_commit_callback() argument
2089 pmd_write_lock_in_core(pmd); in dm_pool_register_pre_commit_callback()
2090 pmd->pre_commit_fn = fn; in dm_pool_register_pre_commit_callback()
2091 pmd->pre_commit_context = context; in dm_pool_register_pre_commit_callback()
2092 pmd_write_unlock(pmd); in dm_pool_register_pre_commit_callback()
2095 int dm_pool_metadata_set_needs_check(struct dm_pool_metadata *pmd) in dm_pool_metadata_set_needs_check() argument
2101 pmd_write_lock(pmd); in dm_pool_metadata_set_needs_check()
2102 if (pmd->fail_io) in dm_pool_metadata_set_needs_check()
2105 pmd->flags |= THIN_METADATA_NEEDS_CHECK_FLAG; in dm_pool_metadata_set_needs_check()
2107 r = superblock_lock(pmd, &sblock); in dm_pool_metadata_set_needs_check()
2114 disk_super->flags = cpu_to_le32(pmd->flags); in dm_pool_metadata_set_needs_check()
2118 pmd_write_unlock(pmd); in dm_pool_metadata_set_needs_check()
2122 bool dm_pool_metadata_needs_check(struct dm_pool_metadata *pmd) in dm_pool_metadata_needs_check() argument
2126 down_read(&pmd->root_lock); in dm_pool_metadata_needs_check()
2127 needs_check = pmd->flags & THIN_METADATA_NEEDS_CHECK_FLAG; in dm_pool_metadata_needs_check()
2128 up_read(&pmd->root_lock); in dm_pool_metadata_needs_check()
2133 void dm_pool_issue_prefetches(struct dm_pool_metadata *pmd) in dm_pool_issue_prefetches() argument
2135 down_read(&pmd->root_lock); in dm_pool_issue_prefetches()
2136 if (!pmd->fail_io) in dm_pool_issue_prefetches()
2137 dm_tm_issue_prefetches(pmd->tm); in dm_pool_issue_prefetches()
2138 up_read(&pmd->root_lock); in dm_pool_issue_prefetches()