Lines Matching refs:tc

226 typedef void (*process_bio_fn)(struct thin_c *tc, struct bio *bio);
227 typedef void (*process_cell_fn)(struct thin_c *tc, struct dm_bio_prison_cell *cell);
382 struct thin_c *tc; member
388 static void begin_discard(struct discard_op *op, struct thin_c *tc, struct bio *parent) in begin_discard() argument
392 op->tc = tc; in begin_discard()
400 struct thin_c *tc = op->tc; in issue_discard() local
401 sector_t s = block_to_sectors(tc->pool, data_b); in issue_discard()
402 sector_t len = block_to_sectors(tc->pool, data_e - data_b); in issue_discard()
404 return __blkdev_issue_discard(tc->pool_dev->bdev, s, len, GFP_NOIO, &op->bio); in issue_discard()
586 struct thin_c *tc; member
610 static void error_thin_bio_list(struct thin_c *tc, struct bio_list *master, in error_thin_bio_list() argument
617 spin_lock_irq(&tc->lock); in error_thin_bio_list()
619 spin_unlock_irq(&tc->lock); in error_thin_bio_list()
624 static void requeue_deferred_cells(struct thin_c *tc) in requeue_deferred_cells() argument
626 struct pool *pool = tc->pool; in requeue_deferred_cells()
632 spin_lock_irq(&tc->lock); in requeue_deferred_cells()
633 list_splice_init(&tc->deferred_cells, &cells); in requeue_deferred_cells()
634 spin_unlock_irq(&tc->lock); in requeue_deferred_cells()
640 static void requeue_io(struct thin_c *tc) in requeue_io() argument
646 spin_lock_irq(&tc->lock); in requeue_io()
647 __merge_bio_list(&bios, &tc->deferred_bio_list); in requeue_io()
648 __merge_bio_list(&bios, &tc->retry_on_resume_list); in requeue_io()
649 spin_unlock_irq(&tc->lock); in requeue_io()
652 requeue_deferred_cells(tc); in requeue_io()
657 struct thin_c *tc; in error_retry_list_with_code() local
660 list_for_each_entry_rcu(tc, &pool->active_thins, list) in error_retry_list_with_code()
661 error_thin_bio_list(tc, &tc->retry_on_resume_list, error); in error_retry_list_with_code()
677 static dm_block_t get_bio_block(struct thin_c *tc, struct bio *bio) in get_bio_block() argument
679 struct pool *pool = tc->pool; in get_bio_block()
693 static void get_bio_block_range(struct thin_c *tc, struct bio *bio, in get_bio_block_range() argument
696 struct pool *pool = tc->pool; in get_bio_block_range()
718 static void remap(struct thin_c *tc, struct bio *bio, dm_block_t block) in remap() argument
720 struct pool *pool = tc->pool; in remap()
723 bio_set_dev(bio, tc->pool_dev->bdev); in remap()
733 static void remap_to_origin(struct thin_c *tc, struct bio *bio) in remap_to_origin() argument
735 bio_set_dev(bio, tc->origin_dev->bdev); in remap_to_origin()
738 static int bio_triggers_commit(struct thin_c *tc, struct bio *bio) in bio_triggers_commit() argument
741 dm_thin_changed_this_transaction(tc->td); in bio_triggers_commit()
755 static void issue(struct thin_c *tc, struct bio *bio) in issue() argument
757 struct pool *pool = tc->pool; in issue()
759 if (!bio_triggers_commit(tc, bio)) { in issue()
769 if (dm_thin_aborted_changes(tc->td)) { in issue()
783 static void remap_to_origin_and_issue(struct thin_c *tc, struct bio *bio) in remap_to_origin_and_issue() argument
785 remap_to_origin(tc, bio); in remap_to_origin_and_issue()
786 issue(tc, bio); in remap_to_origin_and_issue()
789 static void remap_and_issue(struct thin_c *tc, struct bio *bio, in remap_and_issue() argument
792 remap(tc, bio, block); in remap_and_issue()
793 issue(tc, bio); in remap_and_issue()
815 struct thin_c *tc; member
832 struct pool *pool = m->tc->pool; in __complete_mapping_preparation()
843 struct pool *pool = m->tc->pool; in complete_mapping_preparation()
883 static void cell_defer_no_holder(struct thin_c *tc, struct dm_bio_prison_cell *cell) in cell_defer_no_holder() argument
885 struct pool *pool = tc->pool; in cell_defer_no_holder()
893 spin_lock_irqsave(&tc->lock, flags); in cell_defer_no_holder()
894 bio_list_merge(&tc->deferred_bio_list, &bios); in cell_defer_no_holder()
895 spin_unlock_irqrestore(&tc->lock, flags); in cell_defer_no_holder()
900 static void thin_defer_bio(struct thin_c *tc, struct bio *bio);
903 struct thin_c *tc; member
918 inc_all_io_entry(info->tc->pool, bio); in __inc_remap_and_issue_cell()
930 static void inc_remap_and_issue_cell(struct thin_c *tc, in inc_remap_and_issue_cell() argument
937 info.tc = tc; in inc_remap_and_issue_cell()
946 cell_visit_release(tc->pool, __inc_remap_and_issue_cell, in inc_remap_and_issue_cell()
950 thin_defer_bio(tc, bio); in inc_remap_and_issue_cell()
953 remap_and_issue(info.tc, bio, block); in inc_remap_and_issue_cell()
958 cell_error(m->tc->pool, m->cell); in process_prepared_mapping_fail()
960 mempool_free(m, &m->tc->pool->mapping_pool); in process_prepared_mapping_fail()
963 static void complete_overwrite_bio(struct thin_c *tc, struct bio *bio) in complete_overwrite_bio() argument
965 struct pool *pool = tc->pool; in complete_overwrite_bio()
971 if (!bio_triggers_commit(tc, bio)) { in complete_overwrite_bio()
981 if (dm_thin_aborted_changes(tc->td)) { in complete_overwrite_bio()
997 struct thin_c *tc = m->tc; in process_prepared_mapping() local
998 struct pool *pool = tc->pool; in process_prepared_mapping()
1012 r = dm_thin_insert_block(tc->td, m->virt_begin, m->data_block); in process_prepared_mapping()
1026 inc_remap_and_issue_cell(tc, m->cell, m->data_block); in process_prepared_mapping()
1027 complete_overwrite_bio(tc, bio); in process_prepared_mapping()
1029 inc_all_io_entry(tc->pool, m->cell->holder); in process_prepared_mapping()
1030 remap_and_issue(tc, m->cell->holder, m->data_block); in process_prepared_mapping()
1031 inc_remap_and_issue_cell(tc, m->cell, m->data_block); in process_prepared_mapping()
1043 struct thin_c *tc = m->tc; in free_discard_mapping() local
1046 cell_defer_no_holder(tc, m->cell); in free_discard_mapping()
1047 mempool_free(m, &tc->pool->mapping_pool); in free_discard_mapping()
1065 struct thin_c *tc = m->tc; in process_prepared_discard_no_passdown() local
1067 r = dm_thin_remove_range(tc->td, m->cell->key.block_begin, m->cell->key.block_end); in process_prepared_discard_no_passdown()
1069 metadata_operation_failed(tc->pool, "dm_thin_remove_range", r); in process_prepared_discard_no_passdown()
1074 cell_defer_no_holder(tc, m->cell); in process_prepared_discard_no_passdown()
1075 mempool_free(m, &tc->pool->mapping_pool); in process_prepared_discard_no_passdown()
1089 struct thin_c *tc = m->tc; in passdown_double_checking_shared_status() local
1090 struct pool *pool = tc->pool; in passdown_double_checking_shared_status()
1094 begin_discard(&op, tc, discard_parent); in passdown_double_checking_shared_status()
1132 struct pool *pool = m->tc->pool; in queue_passdown_pt2()
1153 struct thin_c *tc = m->tc; in process_prepared_discard_passdown_pt1() local
1154 struct pool *pool = tc->pool; in process_prepared_discard_passdown_pt1()
1163 r = dm_thin_remove_range(tc->td, m->virt_begin, m->virt_end); in process_prepared_discard_passdown_pt1()
1167 cell_defer_no_holder(tc, m->cell); in process_prepared_discard_passdown_pt1()
1180 cell_defer_no_holder(tc, m->cell); in process_prepared_discard_passdown_pt1()
1193 begin_discard(&op, tc, discard_parent); in process_prepared_discard_passdown_pt1()
1202 struct thin_c *tc = m->tc; in process_prepared_discard_passdown_pt2() local
1203 struct pool *pool = tc->pool; in process_prepared_discard_passdown_pt2()
1217 cell_defer_no_holder(tc, m->cell); in process_prepared_discard_passdown_pt2()
1283 static void ll_zero(struct thin_c *tc, struct dm_thin_new_mapping *m, in ll_zero() argument
1288 to.bdev = tc->pool_dev->bdev; in ll_zero()
1292 dm_kcopyd_zero(tc->pool->copier, 1, &to, 0, copy_complete, m); in ll_zero()
1295 static void remap_and_issue_overwrite(struct thin_c *tc, struct bio *bio, in remap_and_issue_overwrite() argument
1299 struct pool *pool = tc->pool; in remap_and_issue_overwrite()
1306 remap_and_issue(tc, bio, data_begin); in remap_and_issue_overwrite()
1312 static void schedule_copy(struct thin_c *tc, dm_block_t virt_block, in schedule_copy() argument
1318 struct pool *pool = tc->pool; in schedule_copy()
1321 m->tc = tc; in schedule_copy()
1344 remap_and_issue_overwrite(tc, bio, data_dest, m); in schedule_copy()
1352 to.bdev = tc->pool_dev->bdev; in schedule_copy()
1364 ll_zero(tc, m, in schedule_copy()
1373 static void schedule_internal_copy(struct thin_c *tc, dm_block_t virt_block, in schedule_internal_copy() argument
1377 schedule_copy(tc, virt_block, tc->pool_dev, in schedule_internal_copy()
1379 tc->pool->sectors_per_block); in schedule_internal_copy()
1382 static void schedule_zero(struct thin_c *tc, dm_block_t virt_block, in schedule_zero() argument
1386 struct pool *pool = tc->pool; in schedule_zero()
1390 m->tc = tc; in schedule_zero()
1403 remap_and_issue_overwrite(tc, bio, data_block, m); in schedule_zero()
1405 ll_zero(tc, m, data_block * pool->sectors_per_block, in schedule_zero()
1411 static void schedule_external_copy(struct thin_c *tc, dm_block_t virt_block, in schedule_external_copy() argument
1415 struct pool *pool = tc->pool; in schedule_external_copy()
1419 if (virt_block_end <= tc->origin_size) in schedule_external_copy()
1420 schedule_copy(tc, virt_block, tc->origin_dev, in schedule_external_copy()
1424 else if (virt_block_begin < tc->origin_size) in schedule_external_copy()
1425 schedule_copy(tc, virt_block, tc->origin_dev, in schedule_external_copy()
1427 tc->origin_size - virt_block_begin); in schedule_external_copy()
1430 schedule_zero(tc, virt_block, data_dest, cell, bio); in schedule_external_copy()
1517 static int alloc_data_block(struct thin_c *tc, dm_block_t *result) in alloc_data_block() argument
1521 struct pool *pool = tc->pool; in alloc_data_block()
1587 struct thin_c *tc = h->tc; in retry_on_resume() local
1589 spin_lock_irq(&tc->lock); in retry_on_resume()
1590 bio_list_add(&tc->retry_on_resume_list, bio); in retry_on_resume()
1591 spin_unlock_irq(&tc->lock); in retry_on_resume()
1648 static void process_discard_cell_no_passdown(struct thin_c *tc, in process_discard_cell_no_passdown() argument
1651 struct pool *pool = tc->pool; in process_discard_cell_no_passdown()
1658 m->tc = tc; in process_discard_cell_no_passdown()
1668 static void break_up_discard_bio(struct thin_c *tc, dm_block_t begin, dm_block_t end, in break_up_discard_bio() argument
1671 struct pool *pool = tc->pool; in break_up_discard_bio()
1682 r = dm_thin_find_mapped_range(tc->td, begin, end, &virt_begin, &virt_end, in break_up_discard_bio()
1707 (void) build_key(tc->td, PHYSICAL, data_begin, data_begin + len, &data_key); in break_up_discard_bio()
1708 if (bio_detain(tc->pool, &data_key, NULL, &data_cell)) { in break_up_discard_bio()
1719 m->tc = tc; in break_up_discard_bio()
1747 static void process_discard_cell_passdown(struct thin_c *tc, struct dm_bio_prison_cell *virt_cell) in process_discard_cell_passdown() argument
1758 break_up_discard_bio(tc, virt_cell->key.block_begin, virt_cell->key.block_end, bio); in process_discard_cell_passdown()
1768 static void process_discard_bio(struct thin_c *tc, struct bio *bio) in process_discard_bio() argument
1774 get_bio_block_range(tc, bio, &begin, &end); in process_discard_bio()
1783 if (unlikely(!build_key(tc->td, VIRTUAL, begin, end, &virt_key))) { in process_discard_bio()
1789 if (bio_detain(tc->pool, &virt_key, bio, &virt_cell)) { in process_discard_bio()
1800 tc->pool->process_discard_cell(tc, virt_cell); in process_discard_bio()
1803 static void break_sharing(struct thin_c *tc, struct bio *bio, dm_block_t block, in break_sharing() argument
1810 struct pool *pool = tc->pool; in break_sharing()
1812 r = alloc_data_block(tc, &data_block); in break_sharing()
1815 schedule_internal_copy(tc, block, lookup_result->block, in break_sharing()
1844 h->shared_read_entry = dm_deferred_entry_inc(info->tc->pool->shared_read_ds); in __remap_and_issue_shared_cell()
1845 inc_all_io_entry(info->tc->pool, bio); in __remap_and_issue_shared_cell()
1851 static void remap_and_issue_shared_cell(struct thin_c *tc, in remap_and_issue_shared_cell() argument
1858 info.tc = tc; in remap_and_issue_shared_cell()
1862 cell_visit_release(tc->pool, __remap_and_issue_shared_cell, in remap_and_issue_shared_cell()
1866 thin_defer_bio(tc, bio); in remap_and_issue_shared_cell()
1869 remap_and_issue(tc, bio, block); in remap_and_issue_shared_cell()
1872 static void process_shared_bio(struct thin_c *tc, struct bio *bio, in process_shared_bio() argument
1878 struct pool *pool = tc->pool; in process_shared_bio()
1885 build_data_key(tc->td, lookup_result->block, &key); in process_shared_bio()
1887 cell_defer_no_holder(tc, virt_cell); in process_shared_bio()
1892 break_sharing(tc, bio, block, &key, lookup_result, data_cell); in process_shared_bio()
1893 cell_defer_no_holder(tc, virt_cell); in process_shared_bio()
1899 remap_and_issue(tc, bio, lookup_result->block); in process_shared_bio()
1901 remap_and_issue_shared_cell(tc, data_cell, lookup_result->block); in process_shared_bio()
1902 remap_and_issue_shared_cell(tc, virt_cell, lookup_result->block); in process_shared_bio()
1906 static void provision_block(struct thin_c *tc, struct bio *bio, dm_block_t block, in provision_block() argument
1911 struct pool *pool = tc->pool; in provision_block()
1918 cell_defer_no_holder(tc, cell); in provision_block()
1920 remap_and_issue(tc, bio, 0); in provision_block()
1929 cell_defer_no_holder(tc, cell); in provision_block()
1934 r = alloc_data_block(tc, &data_block); in provision_block()
1937 if (tc->origin_dev) in provision_block()
1938 schedule_external_copy(tc, block, data_block, cell, bio); in provision_block()
1940 schedule_zero(tc, block, data_block, cell, bio); in provision_block()
1955 static void process_cell(struct thin_c *tc, struct dm_bio_prison_cell *cell) in process_cell() argument
1958 struct pool *pool = tc->pool; in process_cell()
1960 dm_block_t block = get_bio_block(tc, bio); in process_cell()
1963 if (tc->requeue_mode) { in process_cell()
1968 r = dm_thin_find_block(tc->td, block, 1, &lookup_result); in process_cell()
1972 process_shared_bio(tc, bio, block, &lookup_result, cell); in process_cell()
1975 remap_and_issue(tc, bio, lookup_result.block); in process_cell()
1976 inc_remap_and_issue_cell(tc, cell, lookup_result.block); in process_cell()
1981 if (bio_data_dir(bio) == READ && tc->origin_dev) { in process_cell()
1983 cell_defer_no_holder(tc, cell); in process_cell()
1985 if (bio_end_sector(bio) <= tc->origin_size) in process_cell()
1986 remap_to_origin_and_issue(tc, bio); in process_cell()
1988 else if (bio->bi_iter.bi_sector < tc->origin_size) { in process_cell()
1990 bio->bi_iter.bi_size = (tc->origin_size - bio->bi_iter.bi_sector) << SECTOR_SHIFT; in process_cell()
1991 remap_to_origin_and_issue(tc, bio); in process_cell()
1998 provision_block(tc, bio, block, cell); in process_cell()
2004 cell_defer_no_holder(tc, cell); in process_cell()
2010 static void process_bio(struct thin_c *tc, struct bio *bio) in process_bio() argument
2012 struct pool *pool = tc->pool; in process_bio()
2013 dm_block_t block = get_bio_block(tc, bio); in process_bio()
2021 build_virtual_key(tc->td, block, &key); in process_bio()
2025 process_cell(tc, cell); in process_bio()
2028 static void __process_bio_read_only(struct thin_c *tc, struct bio *bio, in __process_bio_read_only() argument
2033 dm_block_t block = get_bio_block(tc, bio); in __process_bio_read_only()
2036 r = dm_thin_find_block(tc->td, block, 1, &lookup_result); in __process_bio_read_only()
2040 handle_unserviceable_bio(tc->pool, bio); in __process_bio_read_only()
2042 cell_defer_no_holder(tc, cell); in __process_bio_read_only()
2044 inc_all_io_entry(tc->pool, bio); in __process_bio_read_only()
2045 remap_and_issue(tc, bio, lookup_result.block); in __process_bio_read_only()
2047 inc_remap_and_issue_cell(tc, cell, lookup_result.block); in __process_bio_read_only()
2053 cell_defer_no_holder(tc, cell); in __process_bio_read_only()
2055 handle_unserviceable_bio(tc->pool, bio); in __process_bio_read_only()
2059 if (tc->origin_dev) { in __process_bio_read_only()
2060 inc_all_io_entry(tc->pool, bio); in __process_bio_read_only()
2061 remap_to_origin_and_issue(tc, bio); in __process_bio_read_only()
2073 cell_defer_no_holder(tc, cell); in __process_bio_read_only()
2079 static void process_bio_read_only(struct thin_c *tc, struct bio *bio) in process_bio_read_only() argument
2081 __process_bio_read_only(tc, bio, NULL); in process_bio_read_only()
2084 static void process_cell_read_only(struct thin_c *tc, struct dm_bio_prison_cell *cell) in process_cell_read_only() argument
2086 __process_bio_read_only(tc, cell->holder, cell); in process_cell_read_only()
2089 static void process_bio_success(struct thin_c *tc, struct bio *bio) in process_bio_success() argument
2094 static void process_bio_fail(struct thin_c *tc, struct bio *bio) in process_bio_fail() argument
2099 static void process_cell_success(struct thin_c *tc, struct dm_bio_prison_cell *cell) in process_cell_success() argument
2101 cell_success(tc->pool, cell); in process_cell_success()
2104 static void process_cell_fail(struct thin_c *tc, struct dm_bio_prison_cell *cell) in process_cell_fail() argument
2106 cell_error(tc->pool, cell); in process_cell_fail()
2122 static void __thin_bio_rb_add(struct thin_c *tc, struct bio *bio) in __thin_bio_rb_add() argument
2128 rbp = &tc->sort_bio_list.rb_node; in __thin_bio_rb_add()
2142 rb_insert_color(&pbd->rb_node, &tc->sort_bio_list); in __thin_bio_rb_add()
2145 static void __extract_sorted_bios(struct thin_c *tc) in __extract_sorted_bios() argument
2151 for (node = rb_first(&tc->sort_bio_list); node; node = rb_next(node)) { in __extract_sorted_bios()
2155 bio_list_add(&tc->deferred_bio_list, bio); in __extract_sorted_bios()
2156 rb_erase(&pbd->rb_node, &tc->sort_bio_list); in __extract_sorted_bios()
2159 WARN_ON(!RB_EMPTY_ROOT(&tc->sort_bio_list)); in __extract_sorted_bios()
2162 static void __sort_thin_deferred_bios(struct thin_c *tc) in __sort_thin_deferred_bios() argument
2168 bio_list_merge(&bios, &tc->deferred_bio_list); in __sort_thin_deferred_bios()
2169 bio_list_init(&tc->deferred_bio_list); in __sort_thin_deferred_bios()
2173 __thin_bio_rb_add(tc, bio); in __sort_thin_deferred_bios()
2180 __extract_sorted_bios(tc); in __sort_thin_deferred_bios()
2183 static void process_thin_deferred_bios(struct thin_c *tc) in process_thin_deferred_bios() argument
2185 struct pool *pool = tc->pool; in process_thin_deferred_bios()
2191 if (tc->requeue_mode) { in process_thin_deferred_bios()
2192 error_thin_bio_list(tc, &tc->deferred_bio_list, in process_thin_deferred_bios()
2199 spin_lock_irq(&tc->lock); in process_thin_deferred_bios()
2201 if (bio_list_empty(&tc->deferred_bio_list)) { in process_thin_deferred_bios()
2202 spin_unlock_irq(&tc->lock); in process_thin_deferred_bios()
2206 __sort_thin_deferred_bios(tc); in process_thin_deferred_bios()
2208 bio_list_merge(&bios, &tc->deferred_bio_list); in process_thin_deferred_bios()
2209 bio_list_init(&tc->deferred_bio_list); in process_thin_deferred_bios()
2211 spin_unlock_irq(&tc->lock); in process_thin_deferred_bios()
2221 spin_lock_irq(&tc->lock); in process_thin_deferred_bios()
2222 bio_list_add(&tc->deferred_bio_list, bio); in process_thin_deferred_bios()
2223 bio_list_merge(&tc->deferred_bio_list, &bios); in process_thin_deferred_bios()
2224 spin_unlock_irq(&tc->lock); in process_thin_deferred_bios()
2229 pool->process_discard(tc, bio); in process_thin_deferred_bios()
2231 pool->process_bio(tc, bio); in process_thin_deferred_bios()
2277 static void process_thin_deferred_cells(struct thin_c *tc) in process_thin_deferred_cells() argument
2279 struct pool *pool = tc->pool; in process_thin_deferred_cells()
2286 spin_lock_irq(&tc->lock); in process_thin_deferred_cells()
2287 list_splice_init(&tc->deferred_cells, &cells); in process_thin_deferred_cells()
2288 spin_unlock_irq(&tc->lock); in process_thin_deferred_cells()
2294 count = sort_cells(tc->pool, &cells); in process_thin_deferred_cells()
2309 spin_lock_irq(&tc->lock); in process_thin_deferred_cells()
2310 list_splice(&cells, &tc->deferred_cells); in process_thin_deferred_cells()
2311 spin_unlock_irq(&tc->lock); in process_thin_deferred_cells()
2316 pool->process_discard_cell(tc, cell); in process_thin_deferred_cells()
2318 pool->process_cell(tc, cell); in process_thin_deferred_cells()
2324 static void thin_get(struct thin_c *tc);
2325 static void thin_put(struct thin_c *tc);
2334 struct thin_c *tc = NULL; in get_first_thin() local
2338 tc = list_entry_rcu(pool->active_thins.next, struct thin_c, list); in get_first_thin()
2339 thin_get(tc); in get_first_thin()
2343 return tc; in get_first_thin()
2346 static struct thin_c *get_next_thin(struct pool *pool, struct thin_c *tc) in get_next_thin() argument
2348 struct thin_c *old_tc = tc; in get_next_thin()
2351 list_for_each_entry_continue_rcu(tc, &pool->active_thins, list) { in get_next_thin()
2352 thin_get(tc); in get_next_thin()
2355 return tc; in get_next_thin()
2367 struct thin_c *tc; in process_deferred_bios() local
2369 tc = get_first_thin(pool); in process_deferred_bios()
2370 while (tc) { in process_deferred_bios()
2371 process_thin_deferred_cells(tc); in process_deferred_bios()
2372 process_thin_deferred_bios(tc); in process_deferred_bios()
2373 tc = get_next_thin(pool, tc); in process_deferred_bios()
2495 struct thin_c *tc; member
2507 w->tc->requeue_mode = true; in do_noflush_start()
2508 requeue_io(w->tc); in do_noflush_start()
2516 w->tc->requeue_mode = false; in do_noflush_stop()
2520 static void noflush_work(struct thin_c *tc, void (*fn)(struct work_struct *)) in noflush_work() argument
2524 w.tc = tc; in noflush_work()
2525 pool_work_wait(&w.pw, tc->pool, fn); in noflush_work()
2676 static void thin_defer_bio(struct thin_c *tc, struct bio *bio) in thin_defer_bio() argument
2678 struct pool *pool = tc->pool; in thin_defer_bio()
2680 spin_lock_irq(&tc->lock); in thin_defer_bio()
2681 bio_list_add(&tc->deferred_bio_list, bio); in thin_defer_bio()
2682 spin_unlock_irq(&tc->lock); in thin_defer_bio()
2687 static void thin_defer_bio_with_throttle(struct thin_c *tc, struct bio *bio) in thin_defer_bio_with_throttle() argument
2689 struct pool *pool = tc->pool; in thin_defer_bio_with_throttle()
2692 thin_defer_bio(tc, bio); in thin_defer_bio_with_throttle()
2696 static void thin_defer_cell(struct thin_c *tc, struct dm_bio_prison_cell *cell) in thin_defer_cell() argument
2698 struct pool *pool = tc->pool; in thin_defer_cell()
2701 spin_lock_irq(&tc->lock); in thin_defer_cell()
2702 list_add_tail(&cell->user_list, &tc->deferred_cells); in thin_defer_cell()
2703 spin_unlock_irq(&tc->lock); in thin_defer_cell()
2709 static void thin_hook_bio(struct thin_c *tc, struct bio *bio) in thin_hook_bio() argument
2713 h->tc = tc; in thin_hook_bio()
2726 struct thin_c *tc = ti->private; in thin_bio_map() local
2727 dm_block_t block = get_bio_block(tc, bio); in thin_bio_map()
2728 struct dm_thin_device *td = tc->td; in thin_bio_map()
2733 thin_hook_bio(tc, bio); in thin_bio_map()
2735 if (tc->requeue_mode) { in thin_bio_map()
2741 if (get_pool_mode(tc->pool) == PM_FAIL) { in thin_bio_map()
2747 thin_defer_bio_with_throttle(tc, bio); in thin_bio_map()
2755 build_virtual_key(tc->td, block, &key); in thin_bio_map()
2756 if (bio_detain(tc->pool, &key, bio, &virt_cell)) in thin_bio_map()
2781 thin_defer_cell(tc, virt_cell); in thin_bio_map()
2785 build_data_key(tc->td, result.block, &key); in thin_bio_map()
2786 if (bio_detain(tc->pool, &key, bio, &data_cell)) { in thin_bio_map()
2787 cell_defer_no_holder(tc, virt_cell); in thin_bio_map()
2791 inc_all_io_entry(tc->pool, bio); in thin_bio_map()
2792 cell_defer_no_holder(tc, data_cell); in thin_bio_map()
2793 cell_defer_no_holder(tc, virt_cell); in thin_bio_map()
2795 remap(tc, bio, result.block); in thin_bio_map()
2800 thin_defer_cell(tc, virt_cell); in thin_bio_map()
2810 cell_defer_no_holder(tc, virt_cell); in thin_bio_map()
2817 struct thin_c *tc; in requeue_bios() local
2820 list_for_each_entry_rcu(tc, &pool->active_thins, list) { in requeue_bios()
2821 spin_lock_irq(&tc->lock); in requeue_bios()
2822 bio_list_merge(&tc->deferred_bio_list, &tc->retry_on_resume_list); in requeue_bios()
2823 bio_list_init(&tc->retry_on_resume_list); in requeue_bios()
2824 spin_unlock_irq(&tc->lock); in requeue_bios()
3605 struct thin_c *tc; in pool_suspend_active_thins() local
3608 tc = get_first_thin(pool); in pool_suspend_active_thins()
3609 while (tc) { in pool_suspend_active_thins()
3610 dm_internal_suspend_noflush(tc->thin_md); in pool_suspend_active_thins()
3611 tc = get_next_thin(pool, tc); in pool_suspend_active_thins()
3617 struct thin_c *tc; in pool_resume_active_thins() local
3620 tc = get_first_thin(pool); in pool_resume_active_thins()
3621 while (tc) { in pool_resume_active_thins()
3622 dm_internal_resume(tc->thin_md); in pool_resume_active_thins()
3623 tc = get_next_thin(pool, tc); in pool_resume_active_thins()
4138 static void thin_get(struct thin_c *tc) in thin_get() argument
4140 refcount_inc(&tc->refcount); in thin_get()
4143 static void thin_put(struct thin_c *tc) in thin_put() argument
4145 if (refcount_dec_and_test(&tc->refcount)) in thin_put()
4146 complete(&tc->can_destroy); in thin_put()
4151 struct thin_c *tc = ti->private; in thin_dtr() local
4153 spin_lock_irq(&tc->pool->lock); in thin_dtr()
4154 list_del_rcu(&tc->list); in thin_dtr()
4155 spin_unlock_irq(&tc->pool->lock); in thin_dtr()
4158 thin_put(tc); in thin_dtr()
4159 wait_for_completion(&tc->can_destroy); in thin_dtr()
4163 __pool_dec(tc->pool); in thin_dtr()
4164 dm_pool_close_thin_device(tc->td); in thin_dtr()
4165 dm_put_device(ti, tc->pool_dev); in thin_dtr()
4166 if (tc->origin_dev) in thin_dtr()
4167 dm_put_device(ti, tc->origin_dev); in thin_dtr()
4168 kfree(tc); in thin_dtr()
4188 struct thin_c *tc; in thin_ctr() local
4200 tc = ti->private = kzalloc(sizeof(*tc), GFP_KERNEL); in thin_ctr()
4201 if (!tc) { in thin_ctr()
4206 tc->thin_md = dm_table_get_md(ti->table); in thin_ctr()
4207 spin_lock_init(&tc->lock); in thin_ctr()
4208 INIT_LIST_HEAD(&tc->deferred_cells); in thin_ctr()
4209 bio_list_init(&tc->deferred_bio_list); in thin_ctr()
4210 bio_list_init(&tc->retry_on_resume_list); in thin_ctr()
4211 tc->sort_bio_list = RB_ROOT; in thin_ctr()
4225 tc->origin_dev = origin_dev; in thin_ctr()
4233 tc->pool_dev = pool_dev; in thin_ctr()
4235 if (read_dev_id(argv[1], (unsigned long long *)&tc->dev_id, 0)) { in thin_ctr()
4241 pool_md = dm_get_md(tc->pool_dev->bdev->bd_dev); in thin_ctr()
4248 tc->pool = __pool_table_lookup(pool_md); in thin_ctr()
4249 if (!tc->pool) { in thin_ctr()
4254 __pool_inc(tc->pool); in thin_ctr()
4256 if (get_pool_mode(tc->pool) == PM_FAIL) { in thin_ctr()
4262 r = dm_pool_open_thin_device(tc->pool->pmd, tc->dev_id, &tc->td); in thin_ctr()
4268 r = dm_set_target_max_io_len(ti, tc->pool->sectors_per_block); in thin_ctr()
4279 if (tc->pool->pf.discard_enabled) { in thin_ctr()
4287 spin_lock_irq(&tc->pool->lock); in thin_ctr()
4288 if (tc->pool->suspended) { in thin_ctr()
4289 spin_unlock_irq(&tc->pool->lock); in thin_ctr()
4295 refcount_set(&tc->refcount, 1); in thin_ctr()
4296 init_completion(&tc->can_destroy); in thin_ctr()
4297 list_add_tail_rcu(&tc->list, &tc->pool->active_thins); in thin_ctr()
4298 spin_unlock_irq(&tc->pool->lock); in thin_ctr()
4312 dm_pool_close_thin_device(tc->td); in thin_ctr()
4314 __pool_dec(tc->pool); in thin_ctr()
4318 dm_put_device(ti, tc->pool_dev); in thin_ctr()
4320 if (tc->origin_dev) in thin_ctr()
4321 dm_put_device(ti, tc->origin_dev); in thin_ctr()
4323 kfree(tc); in thin_ctr()
4344 struct pool *pool = h->tc->pool; in thin_endio()
4371 cell_defer_no_holder(h->tc, h->cell); in thin_endio()
4378 struct thin_c *tc = ti->private; in thin_presuspend() local
4381 noflush_work(tc, do_noflush_start); in thin_presuspend()
4386 struct thin_c *tc = ti->private; in thin_postsuspend() local
4392 noflush_work(tc, do_noflush_stop); in thin_postsuspend()
4397 struct thin_c *tc = ti->private; in thin_preresume() local
4399 if (tc->origin_dev) in thin_preresume()
4400 tc->origin_size = get_dev_size(tc->origin_dev->bdev); in thin_preresume()
4415 struct thin_c *tc = ti->private; in thin_status() local
4417 if (get_pool_mode(tc->pool) == PM_FAIL) { in thin_status()
4422 if (!tc->td) in thin_status()
4427 r = dm_thin_get_mapped_count(tc->td, &mapped); in thin_status()
4433 r = dm_thin_get_highest_mapped_block(tc->td, &highest); in thin_status()
4439 DMEMIT("%llu ", mapped * tc->pool->sectors_per_block); in thin_status()
4442 tc->pool->sectors_per_block) - 1); in thin_status()
4449 format_dev_t(buf, tc->pool_dev->bdev->bd_dev), in thin_status()
4450 (unsigned long) tc->dev_id); in thin_status()
4451 if (tc->origin_dev) in thin_status()
4452 DMEMIT(" %s", format_dev_t(buf, tc->origin_dev->bdev->bd_dev)); in thin_status()
4471 struct thin_c *tc = ti->private; in thin_iterate_devices() local
4472 struct pool *pool = tc->pool; in thin_iterate_devices()
4484 return fn(ti, tc->pool_dev, 0, pool->sectors_per_block * blocks, data); in thin_iterate_devices()
4491 struct thin_c *tc = ti->private; in thin_io_hints() local
4492 struct pool *pool = tc->pool; in thin_io_hints()