Lines Matching refs:tc
217 typedef void (*process_bio_fn)(struct thin_c *tc, struct bio *bio);
218 typedef void (*process_cell_fn)(struct thin_c *tc, struct dm_bio_prison_cell *cell);
386 static int issue_discard(struct thin_c *tc, dm_block_t data_b, dm_block_t data_e, in issue_discard() argument
389 sector_t s = block_to_sectors(tc->pool, data_b); in issue_discard()
390 sector_t len = block_to_sectors(tc->pool, data_e - data_b); in issue_discard()
392 return __blkdev_issue_discard_async(tc->pool_dev->bdev, s, len, in issue_discard()
542 struct thin_c *tc; member
566 static void error_thin_bio_list(struct thin_c *tc, struct bio_list *master, int error) in error_thin_bio_list() argument
573 spin_lock_irqsave(&tc->lock, flags); in error_thin_bio_list()
575 spin_unlock_irqrestore(&tc->lock, flags); in error_thin_bio_list()
580 static void requeue_deferred_cells(struct thin_c *tc) in requeue_deferred_cells() argument
582 struct pool *pool = tc->pool; in requeue_deferred_cells()
589 spin_lock_irqsave(&tc->lock, flags); in requeue_deferred_cells()
590 list_splice_init(&tc->deferred_cells, &cells); in requeue_deferred_cells()
591 spin_unlock_irqrestore(&tc->lock, flags); in requeue_deferred_cells()
597 static void requeue_io(struct thin_c *tc) in requeue_io() argument
604 spin_lock_irqsave(&tc->lock, flags); in requeue_io()
605 __merge_bio_list(&bios, &tc->deferred_bio_list); in requeue_io()
606 __merge_bio_list(&bios, &tc->retry_on_resume_list); in requeue_io()
607 spin_unlock_irqrestore(&tc->lock, flags); in requeue_io()
610 requeue_deferred_cells(tc); in requeue_io()
615 struct thin_c *tc; in error_retry_list_with_code() local
618 list_for_each_entry_rcu(tc, &pool->active_thins, list) in error_retry_list_with_code()
619 error_thin_bio_list(tc, &tc->retry_on_resume_list, error); in error_retry_list_with_code()
635 static dm_block_t get_bio_block(struct thin_c *tc, struct bio *bio) in get_bio_block() argument
637 struct pool *pool = tc->pool; in get_bio_block()
651 static void get_bio_block_range(struct thin_c *tc, struct bio *bio, in get_bio_block_range() argument
654 struct pool *pool = tc->pool; in get_bio_block_range()
676 static void remap(struct thin_c *tc, struct bio *bio, dm_block_t block) in remap() argument
678 struct pool *pool = tc->pool; in remap()
681 bio->bi_bdev = tc->pool_dev->bdev; in remap()
691 static void remap_to_origin(struct thin_c *tc, struct bio *bio) in remap_to_origin() argument
693 bio->bi_bdev = tc->origin_dev->bdev; in remap_to_origin()
696 static int bio_triggers_commit(struct thin_c *tc, struct bio *bio) in bio_triggers_commit() argument
699 dm_thin_changed_this_transaction(tc->td); in bio_triggers_commit()
713 static void issue(struct thin_c *tc, struct bio *bio) in issue() argument
715 struct pool *pool = tc->pool; in issue()
718 if (!bio_triggers_commit(tc, bio)) { in issue()
728 if (dm_thin_aborted_changes(tc->td)) { in issue()
742 static void remap_to_origin_and_issue(struct thin_c *tc, struct bio *bio) in remap_to_origin_and_issue() argument
744 remap_to_origin(tc, bio); in remap_to_origin_and_issue()
745 issue(tc, bio); in remap_to_origin_and_issue()
748 static void remap_and_issue(struct thin_c *tc, struct bio *bio, in remap_and_issue() argument
751 remap(tc, bio, block); in remap_and_issue()
752 issue(tc, bio); in remap_and_issue()
774 struct thin_c *tc; member
791 struct pool *pool = m->tc->pool; in __complete_mapping_preparation()
802 struct pool *pool = m->tc->pool; in complete_mapping_preparation()
842 static void cell_defer_no_holder(struct thin_c *tc, struct dm_bio_prison_cell *cell) in cell_defer_no_holder() argument
844 struct pool *pool = tc->pool; in cell_defer_no_holder()
847 spin_lock_irqsave(&tc->lock, flags); in cell_defer_no_holder()
848 cell_release_no_holder(pool, cell, &tc->deferred_bio_list); in cell_defer_no_holder()
849 spin_unlock_irqrestore(&tc->lock, flags); in cell_defer_no_holder()
854 static void thin_defer_bio(struct thin_c *tc, struct bio *bio);
857 struct thin_c *tc; member
872 inc_all_io_entry(info->tc->pool, bio); in __inc_remap_and_issue_cell()
884 static void inc_remap_and_issue_cell(struct thin_c *tc, in inc_remap_and_issue_cell() argument
891 info.tc = tc; in inc_remap_and_issue_cell()
900 cell_visit_release(tc->pool, __inc_remap_and_issue_cell, in inc_remap_and_issue_cell()
904 thin_defer_bio(tc, bio); in inc_remap_and_issue_cell()
907 remap_and_issue(info.tc, bio, block); in inc_remap_and_issue_cell()
912 cell_error(m->tc->pool, m->cell); in process_prepared_mapping_fail()
914 mempool_free(m, m->tc->pool->mapping_pool); in process_prepared_mapping_fail()
919 struct thin_c *tc = m->tc; in process_prepared_mapping() local
920 struct pool *pool = tc->pool; in process_prepared_mapping()
934 r = dm_thin_insert_block(tc->td, m->virt_begin, m->data_block); in process_prepared_mapping()
948 inc_remap_and_issue_cell(tc, m->cell, m->data_block); in process_prepared_mapping()
951 inc_all_io_entry(tc->pool, m->cell->holder); in process_prepared_mapping()
952 remap_and_issue(tc, m->cell->holder, m->data_block); in process_prepared_mapping()
953 inc_remap_and_issue_cell(tc, m->cell, m->data_block); in process_prepared_mapping()
965 struct thin_c *tc = m->tc; in free_discard_mapping() local
967 cell_defer_no_holder(tc, m->cell); in free_discard_mapping()
968 mempool_free(m, tc->pool->mapping_pool); in free_discard_mapping()
986 struct thin_c *tc = m->tc; in process_prepared_discard_no_passdown() local
988 r = dm_thin_remove_range(tc->td, m->cell->key.block_begin, m->cell->key.block_end); in process_prepared_discard_no_passdown()
990 metadata_operation_failed(tc->pool, "dm_thin_remove_range", r); in process_prepared_discard_no_passdown()
995 cell_defer_no_holder(tc, m->cell); in process_prepared_discard_no_passdown()
996 mempool_free(m, tc->pool->mapping_pool); in process_prepared_discard_no_passdown()
1007 struct thin_c *tc = m->tc; in passdown_double_checking_shared_status() local
1008 struct pool *pool = tc->pool; in passdown_double_checking_shared_status()
1035 r = issue_discard(tc, b, e, m->bio); in passdown_double_checking_shared_status()
1048 struct thin_c *tc = m->tc; in process_prepared_discard_passdown() local
1049 struct pool *pool = tc->pool; in process_prepared_discard_passdown()
1051 r = dm_thin_remove_range(tc->td, m->virt_begin, m->virt_end); in process_prepared_discard_passdown()
1058 r = issue_discard(tc, m->data_block, m->data_block + (m->virt_end - m->virt_begin), m->bio); in process_prepared_discard_passdown()
1066 cell_defer_no_holder(tc, m->cell); in process_prepared_discard_passdown()
1133 static void ll_zero(struct thin_c *tc, struct dm_thin_new_mapping *m, in ll_zero() argument
1139 to.bdev = tc->pool_dev->bdev; in ll_zero()
1143 r = dm_kcopyd_zero(tc->pool->copier, 1, &to, 0, copy_complete, m); in ll_zero()
1150 static void remap_and_issue_overwrite(struct thin_c *tc, struct bio *bio, in remap_and_issue_overwrite() argument
1154 struct pool *pool = tc->pool; in remap_and_issue_overwrite()
1161 remap_and_issue(tc, bio, data_begin); in remap_and_issue_overwrite()
1167 static void schedule_copy(struct thin_c *tc, dm_block_t virt_block, in schedule_copy() argument
1174 struct pool *pool = tc->pool; in schedule_copy()
1177 m->tc = tc; in schedule_copy()
1200 remap_and_issue_overwrite(tc, bio, data_dest, m); in schedule_copy()
1208 to.bdev = tc->pool_dev->bdev; in schedule_copy()
1231 ll_zero(tc, m, in schedule_copy()
1240 static void schedule_internal_copy(struct thin_c *tc, dm_block_t virt_block, in schedule_internal_copy() argument
1244 schedule_copy(tc, virt_block, tc->pool_dev, in schedule_internal_copy()
1246 tc->pool->sectors_per_block); in schedule_internal_copy()
1249 static void schedule_zero(struct thin_c *tc, dm_block_t virt_block, in schedule_zero() argument
1253 struct pool *pool = tc->pool; in schedule_zero()
1257 m->tc = tc; in schedule_zero()
1270 remap_and_issue_overwrite(tc, bio, data_block, m); in schedule_zero()
1272 ll_zero(tc, m, data_block * pool->sectors_per_block, in schedule_zero()
1278 static void schedule_external_copy(struct thin_c *tc, dm_block_t virt_block, in schedule_external_copy() argument
1282 struct pool *pool = tc->pool; in schedule_external_copy()
1286 if (virt_block_end <= tc->origin_size) in schedule_external_copy()
1287 schedule_copy(tc, virt_block, tc->origin_dev, in schedule_external_copy()
1291 else if (virt_block_begin < tc->origin_size) in schedule_external_copy()
1292 schedule_copy(tc, virt_block, tc->origin_dev, in schedule_external_copy()
1294 tc->origin_size - virt_block_begin); in schedule_external_copy()
1297 schedule_zero(tc, virt_block, data_dest, cell, bio); in schedule_external_copy()
1352 static int alloc_data_block(struct thin_c *tc, dm_block_t *result) in alloc_data_block() argument
1356 struct pool *pool = tc->pool; in alloc_data_block()
1406 struct thin_c *tc = h->tc; in retry_on_resume() local
1409 spin_lock_irqsave(&tc->lock, flags); in retry_on_resume()
1410 bio_list_add(&tc->retry_on_resume_list, bio); in retry_on_resume()
1411 spin_unlock_irqrestore(&tc->lock, flags); in retry_on_resume()
1467 static void process_discard_cell_no_passdown(struct thin_c *tc, in process_discard_cell_no_passdown() argument
1470 struct pool *pool = tc->pool; in process_discard_cell_no_passdown()
1477 m->tc = tc; in process_discard_cell_no_passdown()
1498 static void break_up_discard_bio(struct thin_c *tc, dm_block_t begin, dm_block_t end, in break_up_discard_bio() argument
1501 struct pool *pool = tc->pool; in break_up_discard_bio()
1516 r = dm_thin_find_mapped_range(tc->td, begin, end, &virt_begin, &virt_end, in break_up_discard_bio()
1525 build_key(tc->td, PHYSICAL, data_begin, data_begin + (virt_end - virt_begin), &data_key); in break_up_discard_bio()
1526 if (bio_detain(tc->pool, &data_key, NULL, &data_cell)) { in break_up_discard_bio()
1537 m->tc = tc; in break_up_discard_bio()
1561 static void process_discard_cell_passdown(struct thin_c *tc, struct dm_bio_prison_cell *virt_cell) in process_discard_cell_passdown() argument
1572 break_up_discard_bio(tc, virt_cell->key.block_begin, virt_cell->key.block_end, bio); in process_discard_cell_passdown()
1582 static void process_discard_bio(struct thin_c *tc, struct bio *bio) in process_discard_bio() argument
1588 get_bio_block_range(tc, bio, &begin, &end); in process_discard_bio()
1597 build_key(tc->td, VIRTUAL, begin, end, &virt_key); in process_discard_bio()
1598 if (bio_detain(tc->pool, &virt_key, bio, &virt_cell)) in process_discard_bio()
1608 tc->pool->process_discard_cell(tc, virt_cell); in process_discard_bio()
1611 static void break_sharing(struct thin_c *tc, struct bio *bio, dm_block_t block, in break_sharing() argument
1618 struct pool *pool = tc->pool; in break_sharing()
1620 r = alloc_data_block(tc, &data_block); in break_sharing()
1623 schedule_internal_copy(tc, block, lookup_result->block, in break_sharing()
1652 h->shared_read_entry = dm_deferred_entry_inc(info->tc->pool->shared_read_ds); in __remap_and_issue_shared_cell()
1653 inc_all_io_entry(info->tc->pool, bio); in __remap_and_issue_shared_cell()
1659 static void remap_and_issue_shared_cell(struct thin_c *tc, in remap_and_issue_shared_cell() argument
1666 info.tc = tc; in remap_and_issue_shared_cell()
1670 cell_visit_release(tc->pool, __remap_and_issue_shared_cell, in remap_and_issue_shared_cell()
1674 thin_defer_bio(tc, bio); in remap_and_issue_shared_cell()
1677 remap_and_issue(tc, bio, block); in remap_and_issue_shared_cell()
1680 static void process_shared_bio(struct thin_c *tc, struct bio *bio, in process_shared_bio() argument
1686 struct pool *pool = tc->pool; in process_shared_bio()
1693 build_data_key(tc->td, lookup_result->block, &key); in process_shared_bio()
1695 cell_defer_no_holder(tc, virt_cell); in process_shared_bio()
1700 break_sharing(tc, bio, block, &key, lookup_result, data_cell); in process_shared_bio()
1701 cell_defer_no_holder(tc, virt_cell); in process_shared_bio()
1707 remap_and_issue(tc, bio, lookup_result->block); in process_shared_bio()
1709 remap_and_issue_shared_cell(tc, data_cell, lookup_result->block); in process_shared_bio()
1710 remap_and_issue_shared_cell(tc, virt_cell, lookup_result->block); in process_shared_bio()
1714 static void provision_block(struct thin_c *tc, struct bio *bio, dm_block_t block, in provision_block() argument
1719 struct pool *pool = tc->pool; in provision_block()
1726 cell_defer_no_holder(tc, cell); in provision_block()
1728 remap_and_issue(tc, bio, 0); in provision_block()
1737 cell_defer_no_holder(tc, cell); in provision_block()
1742 r = alloc_data_block(tc, &data_block); in provision_block()
1745 if (tc->origin_dev) in provision_block()
1746 schedule_external_copy(tc, block, data_block, cell, bio); in provision_block()
1748 schedule_zero(tc, block, data_block, cell, bio); in provision_block()
1763 static void process_cell(struct thin_c *tc, struct dm_bio_prison_cell *cell) in process_cell() argument
1766 struct pool *pool = tc->pool; in process_cell()
1768 dm_block_t block = get_bio_block(tc, bio); in process_cell()
1771 if (tc->requeue_mode) { in process_cell()
1776 r = dm_thin_find_block(tc->td, block, 1, &lookup_result); in process_cell()
1780 process_shared_bio(tc, bio, block, &lookup_result, cell); in process_cell()
1783 remap_and_issue(tc, bio, lookup_result.block); in process_cell()
1784 inc_remap_and_issue_cell(tc, cell, lookup_result.block); in process_cell()
1789 if (bio_data_dir(bio) == READ && tc->origin_dev) { in process_cell()
1791 cell_defer_no_holder(tc, cell); in process_cell()
1793 if (bio_end_sector(bio) <= tc->origin_size) in process_cell()
1794 remap_to_origin_and_issue(tc, bio); in process_cell()
1796 else if (bio->bi_iter.bi_sector < tc->origin_size) { in process_cell()
1798 bio->bi_iter.bi_size = (tc->origin_size - bio->bi_iter.bi_sector) << SECTOR_SHIFT; in process_cell()
1799 remap_to_origin_and_issue(tc, bio); in process_cell()
1806 provision_block(tc, bio, block, cell); in process_cell()
1812 cell_defer_no_holder(tc, cell); in process_cell()
1818 static void process_bio(struct thin_c *tc, struct bio *bio) in process_bio() argument
1820 struct pool *pool = tc->pool; in process_bio()
1821 dm_block_t block = get_bio_block(tc, bio); in process_bio()
1829 build_virtual_key(tc->td, block, &key); in process_bio()
1833 process_cell(tc, cell); in process_bio()
1836 static void __process_bio_read_only(struct thin_c *tc, struct bio *bio, in __process_bio_read_only() argument
1841 dm_block_t block = get_bio_block(tc, bio); in __process_bio_read_only()
1844 r = dm_thin_find_block(tc->td, block, 1, &lookup_result); in __process_bio_read_only()
1848 handle_unserviceable_bio(tc->pool, bio); in __process_bio_read_only()
1850 cell_defer_no_holder(tc, cell); in __process_bio_read_only()
1852 inc_all_io_entry(tc->pool, bio); in __process_bio_read_only()
1853 remap_and_issue(tc, bio, lookup_result.block); in __process_bio_read_only()
1855 inc_remap_and_issue_cell(tc, cell, lookup_result.block); in __process_bio_read_only()
1861 cell_defer_no_holder(tc, cell); in __process_bio_read_only()
1863 handle_unserviceable_bio(tc->pool, bio); in __process_bio_read_only()
1867 if (tc->origin_dev) { in __process_bio_read_only()
1868 inc_all_io_entry(tc->pool, bio); in __process_bio_read_only()
1869 remap_to_origin_and_issue(tc, bio); in __process_bio_read_only()
1881 cell_defer_no_holder(tc, cell); in __process_bio_read_only()
1887 static void process_bio_read_only(struct thin_c *tc, struct bio *bio) in process_bio_read_only() argument
1889 __process_bio_read_only(tc, bio, NULL); in process_bio_read_only()
1892 static void process_cell_read_only(struct thin_c *tc, struct dm_bio_prison_cell *cell) in process_cell_read_only() argument
1894 __process_bio_read_only(tc, cell->holder, cell); in process_cell_read_only()
1897 static void process_bio_success(struct thin_c *tc, struct bio *bio) in process_bio_success() argument
1902 static void process_bio_fail(struct thin_c *tc, struct bio *bio) in process_bio_fail() argument
1907 static void process_cell_success(struct thin_c *tc, struct dm_bio_prison_cell *cell) in process_cell_success() argument
1909 cell_success(tc->pool, cell); in process_cell_success()
1912 static void process_cell_fail(struct thin_c *tc, struct dm_bio_prison_cell *cell) in process_cell_fail() argument
1914 cell_error(tc->pool, cell); in process_cell_fail()
1930 static void __thin_bio_rb_add(struct thin_c *tc, struct bio *bio) in __thin_bio_rb_add() argument
1936 rbp = &tc->sort_bio_list.rb_node; in __thin_bio_rb_add()
1950 rb_insert_color(&pbd->rb_node, &tc->sort_bio_list); in __thin_bio_rb_add()
1953 static void __extract_sorted_bios(struct thin_c *tc) in __extract_sorted_bios() argument
1959 for (node = rb_first(&tc->sort_bio_list); node; node = rb_next(node)) { in __extract_sorted_bios()
1963 bio_list_add(&tc->deferred_bio_list, bio); in __extract_sorted_bios()
1964 rb_erase(&pbd->rb_node, &tc->sort_bio_list); in __extract_sorted_bios()
1967 WARN_ON(!RB_EMPTY_ROOT(&tc->sort_bio_list)); in __extract_sorted_bios()
1970 static void __sort_thin_deferred_bios(struct thin_c *tc) in __sort_thin_deferred_bios() argument
1976 bio_list_merge(&bios, &tc->deferred_bio_list); in __sort_thin_deferred_bios()
1977 bio_list_init(&tc->deferred_bio_list); in __sort_thin_deferred_bios()
1981 __thin_bio_rb_add(tc, bio); in __sort_thin_deferred_bios()
1988 __extract_sorted_bios(tc); in __sort_thin_deferred_bios()
1991 static void process_thin_deferred_bios(struct thin_c *tc) in process_thin_deferred_bios() argument
1993 struct pool *pool = tc->pool; in process_thin_deferred_bios()
2000 if (tc->requeue_mode) { in process_thin_deferred_bios()
2001 error_thin_bio_list(tc, &tc->deferred_bio_list, DM_ENDIO_REQUEUE); in process_thin_deferred_bios()
2007 spin_lock_irqsave(&tc->lock, flags); in process_thin_deferred_bios()
2009 if (bio_list_empty(&tc->deferred_bio_list)) { in process_thin_deferred_bios()
2010 spin_unlock_irqrestore(&tc->lock, flags); in process_thin_deferred_bios()
2014 __sort_thin_deferred_bios(tc); in process_thin_deferred_bios()
2016 bio_list_merge(&bios, &tc->deferred_bio_list); in process_thin_deferred_bios()
2017 bio_list_init(&tc->deferred_bio_list); in process_thin_deferred_bios()
2019 spin_unlock_irqrestore(&tc->lock, flags); in process_thin_deferred_bios()
2029 spin_lock_irqsave(&tc->lock, flags); in process_thin_deferred_bios()
2030 bio_list_add(&tc->deferred_bio_list, bio); in process_thin_deferred_bios()
2031 bio_list_merge(&tc->deferred_bio_list, &bios); in process_thin_deferred_bios()
2032 spin_unlock_irqrestore(&tc->lock, flags); in process_thin_deferred_bios()
2037 pool->process_discard(tc, bio); in process_thin_deferred_bios()
2039 pool->process_bio(tc, bio); in process_thin_deferred_bios()
2084 static void process_thin_deferred_cells(struct thin_c *tc) in process_thin_deferred_cells() argument
2086 struct pool *pool = tc->pool; in process_thin_deferred_cells()
2094 spin_lock_irqsave(&tc->lock, flags); in process_thin_deferred_cells()
2095 list_splice_init(&tc->deferred_cells, &cells); in process_thin_deferred_cells()
2096 spin_unlock_irqrestore(&tc->lock, flags); in process_thin_deferred_cells()
2102 count = sort_cells(tc->pool, &cells); in process_thin_deferred_cells()
2117 spin_lock_irqsave(&tc->lock, flags); in process_thin_deferred_cells()
2118 list_splice(&cells, &tc->deferred_cells); in process_thin_deferred_cells()
2119 spin_unlock_irqrestore(&tc->lock, flags); in process_thin_deferred_cells()
2124 pool->process_discard_cell(tc, cell); in process_thin_deferred_cells()
2126 pool->process_cell(tc, cell); in process_thin_deferred_cells()
2131 static void thin_get(struct thin_c *tc);
2132 static void thin_put(struct thin_c *tc);
2141 struct thin_c *tc = NULL; in get_first_thin() local
2145 tc = list_entry_rcu(pool->active_thins.next, struct thin_c, list); in get_first_thin()
2146 thin_get(tc); in get_first_thin()
2150 return tc; in get_first_thin()
2153 static struct thin_c *get_next_thin(struct pool *pool, struct thin_c *tc) in get_next_thin() argument
2155 struct thin_c *old_tc = tc; in get_next_thin()
2158 list_for_each_entry_continue_rcu(tc, &pool->active_thins, list) { in get_next_thin()
2159 thin_get(tc); in get_next_thin()
2162 return tc; in get_next_thin()
2175 struct thin_c *tc; in process_deferred_bios() local
2177 tc = get_first_thin(pool); in process_deferred_bios()
2178 while (tc) { in process_deferred_bios()
2179 process_thin_deferred_cells(tc); in process_deferred_bios()
2180 process_thin_deferred_bios(tc); in process_deferred_bios()
2181 tc = get_next_thin(pool, tc); in process_deferred_bios()
2284 struct thin_c *tc; member
2295 w->tc->requeue_mode = true; in do_noflush_start()
2296 requeue_io(w->tc); in do_noflush_start()
2303 w->tc->requeue_mode = false; in do_noflush_stop()
2307 static void noflush_work(struct thin_c *tc, void (*fn)(struct work_struct *)) in noflush_work() argument
2311 w.tc = tc; in noflush_work()
2312 pool_work_wait(&w.pw, tc->pool, fn); in noflush_work()
2487 static void thin_defer_bio(struct thin_c *tc, struct bio *bio) in thin_defer_bio() argument
2490 struct pool *pool = tc->pool; in thin_defer_bio()
2492 spin_lock_irqsave(&tc->lock, flags); in thin_defer_bio()
2493 bio_list_add(&tc->deferred_bio_list, bio); in thin_defer_bio()
2494 spin_unlock_irqrestore(&tc->lock, flags); in thin_defer_bio()
2499 static void thin_defer_bio_with_throttle(struct thin_c *tc, struct bio *bio) in thin_defer_bio_with_throttle() argument
2501 struct pool *pool = tc->pool; in thin_defer_bio_with_throttle()
2504 thin_defer_bio(tc, bio); in thin_defer_bio_with_throttle()
2508 static void thin_defer_cell(struct thin_c *tc, struct dm_bio_prison_cell *cell) in thin_defer_cell() argument
2511 struct pool *pool = tc->pool; in thin_defer_cell()
2514 spin_lock_irqsave(&tc->lock, flags); in thin_defer_cell()
2515 list_add_tail(&cell->user_list, &tc->deferred_cells); in thin_defer_cell()
2516 spin_unlock_irqrestore(&tc->lock, flags); in thin_defer_cell()
2522 static void thin_hook_bio(struct thin_c *tc, struct bio *bio) in thin_hook_bio() argument
2526 h->tc = tc; in thin_hook_bio()
2539 struct thin_c *tc = ti->private; in thin_bio_map() local
2540 dm_block_t block = get_bio_block(tc, bio); in thin_bio_map()
2541 struct dm_thin_device *td = tc->td; in thin_bio_map()
2546 thin_hook_bio(tc, bio); in thin_bio_map()
2548 if (tc->requeue_mode) { in thin_bio_map()
2554 if (get_pool_mode(tc->pool) == PM_FAIL) { in thin_bio_map()
2560 thin_defer_bio_with_throttle(tc, bio); in thin_bio_map()
2568 build_virtual_key(tc->td, block, &key); in thin_bio_map()
2569 if (bio_detain(tc->pool, &key, bio, &virt_cell)) in thin_bio_map()
2594 thin_defer_cell(tc, virt_cell); in thin_bio_map()
2598 build_data_key(tc->td, result.block, &key); in thin_bio_map()
2599 if (bio_detain(tc->pool, &key, bio, &data_cell)) { in thin_bio_map()
2600 cell_defer_no_holder(tc, virt_cell); in thin_bio_map()
2604 inc_all_io_entry(tc->pool, bio); in thin_bio_map()
2605 cell_defer_no_holder(tc, data_cell); in thin_bio_map()
2606 cell_defer_no_holder(tc, virt_cell); in thin_bio_map()
2608 remap(tc, bio, result.block); in thin_bio_map()
2613 thin_defer_cell(tc, virt_cell); in thin_bio_map()
2623 cell_defer_no_holder(tc, virt_cell); in thin_bio_map()
2643 struct thin_c *tc; in requeue_bios() local
2646 list_for_each_entry_rcu(tc, &pool->active_thins, list) { in requeue_bios()
2647 spin_lock_irqsave(&tc->lock, flags); in requeue_bios()
2648 bio_list_merge(&tc->deferred_bio_list, &tc->retry_on_resume_list); in requeue_bios()
2649 bio_list_init(&tc->retry_on_resume_list); in requeue_bios()
2650 spin_unlock_irqrestore(&tc->lock, flags); in requeue_bios()
3382 struct thin_c *tc; in pool_suspend_active_thins() local
3385 tc = get_first_thin(pool); in pool_suspend_active_thins()
3386 while (tc) { in pool_suspend_active_thins()
3387 dm_internal_suspend_noflush(tc->thin_md); in pool_suspend_active_thins()
3388 tc = get_next_thin(pool, tc); in pool_suspend_active_thins()
3394 struct thin_c *tc; in pool_resume_active_thins() local
3397 tc = get_first_thin(pool); in pool_resume_active_thins()
3398 while (tc) { in pool_resume_active_thins()
3399 dm_internal_resume(tc->thin_md); in pool_resume_active_thins()
3400 tc = get_next_thin(pool, tc); in pool_resume_active_thins()
3908 static void thin_get(struct thin_c *tc) in thin_get() argument
3910 atomic_inc(&tc->refcount); in thin_get()
3913 static void thin_put(struct thin_c *tc) in thin_put() argument
3915 if (atomic_dec_and_test(&tc->refcount)) in thin_put()
3916 complete(&tc->can_destroy); in thin_put()
3921 struct thin_c *tc = ti->private; in thin_dtr() local
3924 spin_lock_irqsave(&tc->pool->lock, flags); in thin_dtr()
3925 list_del_rcu(&tc->list); in thin_dtr()
3926 spin_unlock_irqrestore(&tc->pool->lock, flags); in thin_dtr()
3929 thin_put(tc); in thin_dtr()
3930 wait_for_completion(&tc->can_destroy); in thin_dtr()
3934 __pool_dec(tc->pool); in thin_dtr()
3935 dm_pool_close_thin_device(tc->td); in thin_dtr()
3936 dm_put_device(ti, tc->pool_dev); in thin_dtr()
3937 if (tc->origin_dev) in thin_dtr()
3938 dm_put_device(ti, tc->origin_dev); in thin_dtr()
3939 kfree(tc); in thin_dtr()
3959 struct thin_c *tc; in thin_ctr() local
3972 tc = ti->private = kzalloc(sizeof(*tc), GFP_KERNEL); in thin_ctr()
3973 if (!tc) { in thin_ctr()
3978 tc->thin_md = dm_table_get_md(ti->table); in thin_ctr()
3979 spin_lock_init(&tc->lock); in thin_ctr()
3980 INIT_LIST_HEAD(&tc->deferred_cells); in thin_ctr()
3981 bio_list_init(&tc->deferred_bio_list); in thin_ctr()
3982 bio_list_init(&tc->retry_on_resume_list); in thin_ctr()
3983 tc->sort_bio_list = RB_ROOT; in thin_ctr()
3991 tc->origin_dev = origin_dev; in thin_ctr()
3999 tc->pool_dev = pool_dev; in thin_ctr()
4001 if (read_dev_id(argv[1], (unsigned long long *)&tc->dev_id, 0)) { in thin_ctr()
4007 pool_md = dm_get_md(tc->pool_dev->bdev->bd_dev); in thin_ctr()
4014 tc->pool = __pool_table_lookup(pool_md); in thin_ctr()
4015 if (!tc->pool) { in thin_ctr()
4020 __pool_inc(tc->pool); in thin_ctr()
4022 if (get_pool_mode(tc->pool) == PM_FAIL) { in thin_ctr()
4028 r = dm_pool_open_thin_device(tc->pool->pmd, tc->dev_id, &tc->td); in thin_ctr()
4034 r = dm_set_target_max_io_len(ti, tc->pool->sectors_per_block); in thin_ctr()
4044 if (tc->pool->pf.discard_enabled) { in thin_ctr()
4052 spin_lock_irqsave(&tc->pool->lock, flags); in thin_ctr()
4053 if (tc->pool->suspended) { in thin_ctr()
4054 spin_unlock_irqrestore(&tc->pool->lock, flags); in thin_ctr()
4060 atomic_set(&tc->refcount, 1); in thin_ctr()
4061 init_completion(&tc->can_destroy); in thin_ctr()
4062 list_add_tail_rcu(&tc->list, &tc->pool->active_thins); in thin_ctr()
4063 spin_unlock_irqrestore(&tc->pool->lock, flags); in thin_ctr()
4077 dm_pool_close_thin_device(tc->td); in thin_ctr()
4079 __pool_dec(tc->pool); in thin_ctr()
4083 dm_put_device(ti, tc->pool_dev); in thin_ctr()
4085 if (tc->origin_dev) in thin_ctr()
4086 dm_put_device(ti, tc->origin_dev); in thin_ctr()
4088 kfree(tc); in thin_ctr()
4108 struct pool *pool = h->tc->pool; in thin_endio()
4135 cell_defer_no_holder(h->tc, h->cell); in thin_endio()
4142 struct thin_c *tc = ti->private; in thin_presuspend() local
4145 noflush_work(tc, do_noflush_start); in thin_presuspend()
4150 struct thin_c *tc = ti->private; in thin_postsuspend() local
4156 noflush_work(tc, do_noflush_stop); in thin_postsuspend()
4161 struct thin_c *tc = ti->private; in thin_preresume() local
4163 if (tc->origin_dev) in thin_preresume()
4164 tc->origin_size = get_dev_size(tc->origin_dev->bdev); in thin_preresume()
4179 struct thin_c *tc = ti->private; in thin_status() local
4181 if (get_pool_mode(tc->pool) == PM_FAIL) { in thin_status()
4186 if (!tc->td) in thin_status()
4191 r = dm_thin_get_mapped_count(tc->td, &mapped); in thin_status()
4197 r = dm_thin_get_highest_mapped_block(tc->td, &highest); in thin_status()
4203 DMEMIT("%llu ", mapped * tc->pool->sectors_per_block); in thin_status()
4206 tc->pool->sectors_per_block) - 1); in thin_status()
4213 format_dev_t(buf, tc->pool_dev->bdev->bd_dev), in thin_status()
4214 (unsigned long) tc->dev_id); in thin_status()
4215 if (tc->origin_dev) in thin_status()
4216 DMEMIT(" %s", format_dev_t(buf, tc->origin_dev->bdev->bd_dev)); in thin_status()
4231 struct thin_c *tc = ti->private; in thin_iterate_devices() local
4232 struct pool *pool = tc->pool; in thin_iterate_devices()
4244 return fn(ti, tc->pool_dev, 0, pool->sectors_per_block * blocks, data); in thin_iterate_devices()
4251 struct thin_c *tc = ti->private; in thin_io_hints() local
4252 struct pool *pool = tc->pool; in thin_io_hints()