Lines Matching refs:pool

232 struct pool {  struct
290 static void metadata_operation_failed(struct pool *pool, const char *op, int r); argument
292 static enum pool_mode get_pool_mode(struct pool *pool) in get_pool_mode() argument
294 return pool->pf.mode; in get_pool_mode()
297 static void notify_of_pool_mode_change(struct pool *pool) in notify_of_pool_mode_change() argument
307 enum pool_mode mode = get_pool_mode(pool); in notify_of_pool_mode_change()
310 if (!pool->pf.error_if_no_space) in notify_of_pool_mode_change()
316 dm_table_event(pool->ti->table); in notify_of_pool_mode_change()
318 dm_device_name(pool->pool_md), in notify_of_pool_mode_change()
327 struct pool *pool; member
346 struct pool *pool; member
367 static bool block_size_is_power_of_two(struct pool *pool) in block_size_is_power_of_two() argument
369 return pool->sectors_per_block_shift >= 0; in block_size_is_power_of_two()
372 static sector_t block_to_sectors(struct pool *pool, dm_block_t b) in block_to_sectors() argument
374 return block_size_is_power_of_two(pool) ? in block_to_sectors()
375 (b << pool->sectors_per_block_shift) : in block_to_sectors()
376 (b * pool->sectors_per_block); in block_to_sectors()
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()
436 static void wake_worker(struct pool *pool) in wake_worker() argument
438 queue_work(pool->wq, &pool->worker); in wake_worker()
443 static int bio_detain(struct pool *pool, struct dm_cell_key *key, struct bio *bio, in bio_detain() argument
453 cell_prealloc = dm_bio_prison_alloc_cell(pool->prison, GFP_NOIO); in bio_detain()
455 r = dm_bio_detain(pool->prison, key, bio, cell_prealloc, cell_result); in bio_detain()
461 dm_bio_prison_free_cell(pool->prison, cell_prealloc); in bio_detain()
467 static void cell_release(struct pool *pool, in cell_release() argument
471 dm_cell_release(pool->prison, cell, bios); in cell_release()
472 dm_bio_prison_free_cell(pool->prison, cell); in cell_release()
475 static void cell_visit_release(struct pool *pool, in cell_visit_release() argument
480 dm_cell_visit_release(pool->prison, fn, context, cell); in cell_visit_release()
481 dm_bio_prison_free_cell(pool->prison, cell); in cell_visit_release()
484 static void cell_release_no_holder(struct pool *pool, in cell_release_no_holder() argument
488 dm_cell_release_no_holder(pool->prison, cell, bios); in cell_release_no_holder()
489 dm_bio_prison_free_cell(pool->prison, cell); in cell_release_no_holder()
492 static void cell_error_with_code(struct pool *pool, in cell_error_with_code() argument
495 dm_cell_error(pool->prison, cell, error_code); in cell_error_with_code()
496 dm_bio_prison_free_cell(pool->prison, cell); in cell_error_with_code()
499 static blk_status_t get_pool_io_error_code(struct pool *pool) in get_pool_io_error_code() argument
501 return pool->out_of_data_space ? BLK_STS_NOSPC : BLK_STS_IOERR; in get_pool_io_error_code()
504 static void cell_error(struct pool *pool, struct dm_bio_prison_cell *cell) in cell_error() argument
506 cell_error_with_code(pool, cell, get_pool_io_error_code(pool)); in cell_error()
509 static void cell_success(struct pool *pool, struct dm_bio_prison_cell *cell) in cell_success() argument
511 cell_error_with_code(pool, cell, 0); in cell_success()
514 static void cell_requeue(struct pool *pool, struct dm_bio_prison_cell *cell) in cell_requeue() argument
516 cell_error_with_code(pool, cell, BLK_STS_DM_REQUEUE); in cell_requeue()
540 static void __pool_table_insert(struct pool *pool) in __pool_table_insert() argument
543 list_add(&pool->list, &dm_thin_pool_table.pools); in __pool_table_insert()
546 static void __pool_table_remove(struct pool *pool) in __pool_table_remove() argument
549 list_del(&pool->list); in __pool_table_remove()
552 static struct pool *__pool_table_lookup(struct mapped_device *md) in __pool_table_lookup()
554 struct pool *pool = NULL, *tmp; in __pool_table_lookup() local
560 pool = tmp; in __pool_table_lookup()
565 return pool; in __pool_table_lookup()
568 static struct pool *__pool_table_lookup_metadata_dev(struct block_device *md_dev) in __pool_table_lookup_metadata_dev()
570 struct pool *pool = NULL, *tmp; in __pool_table_lookup_metadata_dev() local
576 pool = tmp; in __pool_table_lookup_metadata_dev()
581 return pool; in __pool_table_lookup_metadata_dev()
621 struct pool *pool = tc->pool; in requeue_deferred_cells() local
632 cell_requeue(pool, cell); in requeue_deferred_cells()
650 static void error_retry_list_with_code(struct pool *pool, blk_status_t error) in error_retry_list_with_code() argument
655 list_for_each_entry_rcu(tc, &pool->active_thins, list) in error_retry_list_with_code()
660 static void error_retry_list(struct pool *pool) in error_retry_list() argument
662 error_retry_list_with_code(pool, get_pool_io_error_code(pool)); in error_retry_list()
674 struct pool *pool = tc->pool; in get_bio_block() local
677 if (block_size_is_power_of_two(pool)) in get_bio_block()
678 block_nr >>= pool->sectors_per_block_shift; in get_bio_block()
680 (void) sector_div(block_nr, pool->sectors_per_block); in get_bio_block()
691 struct pool *pool = tc->pool; in get_bio_block_range() local
695 b += pool->sectors_per_block - 1ull; /* so we round up */ in get_bio_block_range()
697 if (block_size_is_power_of_two(pool)) { in get_bio_block_range()
698 b >>= pool->sectors_per_block_shift; in get_bio_block_range()
699 e >>= pool->sectors_per_block_shift; in get_bio_block_range()
701 (void) sector_div(b, pool->sectors_per_block); in get_bio_block_range()
702 (void) sector_div(e, pool->sectors_per_block); in get_bio_block_range()
716 struct pool *pool = tc->pool; in remap() local
720 if (block_size_is_power_of_two(pool)) { in remap()
722 (block << pool->sectors_per_block_shift) | in remap()
723 (bi_sector & (pool->sectors_per_block - 1)); in remap()
725 bio->bi_iter.bi_sector = (block * pool->sectors_per_block) + in remap()
726 sector_div(bi_sector, pool->sectors_per_block); in remap()
741 static void inc_all_io_entry(struct pool *pool, struct bio *bio) in inc_all_io_entry() argument
749 h->all_io_entry = dm_deferred_entry_inc(pool->all_io_ds); in inc_all_io_entry()
754 struct pool *pool = tc->pool; in issue() local
775 spin_lock_irq(&pool->lock); in issue()
776 bio_list_add(&pool->deferred_flush_bios, bio); in issue()
777 spin_unlock_irq(&pool->lock); in issue()
829 struct pool *pool = m->tc->pool; in __complete_mapping_preparation() local
832 list_add_tail(&m->list, &pool->prepared_mappings); in __complete_mapping_preparation()
833 wake_worker(pool); in __complete_mapping_preparation()
840 struct pool *pool = m->tc->pool; in complete_mapping_preparation() local
842 spin_lock_irqsave(&pool->lock, flags); in complete_mapping_preparation()
844 spin_unlock_irqrestore(&pool->lock, flags); in complete_mapping_preparation()
882 struct pool *pool = tc->pool; in cell_defer_no_holder() local
887 cell_release_no_holder(pool, cell, &bios); in cell_defer_no_holder()
893 wake_worker(pool); in cell_defer_no_holder()
915 inc_all_io_entry(info->tc->pool, bio); in __inc_remap_and_issue_cell()
943 cell_visit_release(tc->pool, __inc_remap_and_issue_cell, in inc_remap_and_issue_cell()
955 cell_error(m->tc->pool, m->cell); in process_prepared_mapping_fail()
957 mempool_free(m, &m->tc->pool->mapping_pool); in process_prepared_mapping_fail()
962 struct pool *pool = tc->pool; in complete_overwrite_bio() local
987 spin_lock_irq(&pool->lock); in complete_overwrite_bio()
988 bio_list_add(&pool->deferred_flush_completions, bio); in complete_overwrite_bio()
989 spin_unlock_irq(&pool->lock); in complete_overwrite_bio()
995 struct pool *pool = tc->pool; in process_prepared_mapping() local
1000 cell_error(pool, m->cell); in process_prepared_mapping()
1011 metadata_operation_failed(pool, "dm_thin_insert_block", r); in process_prepared_mapping()
1012 cell_error(pool, m->cell); in process_prepared_mapping()
1026 inc_all_io_entry(tc->pool, m->cell->holder); in process_prepared_mapping()
1033 mempool_free(m, &pool->mapping_pool); in process_prepared_mapping()
1044 mempool_free(m, &tc->pool->mapping_pool); in free_discard_mapping()
1066 metadata_operation_failed(tc->pool, "dm_thin_remove_range", r); in process_prepared_discard_no_passdown()
1072 mempool_free(m, &tc->pool->mapping_pool); in process_prepared_discard_no_passdown()
1087 struct pool *pool = tc->pool; in passdown_double_checking_shared_status() local
1095 r = dm_pool_block_is_shared(pool->pmd, b, &shared); in passdown_double_checking_shared_status()
1108 r = dm_pool_block_is_shared(pool->pmd, e, &shared); in passdown_double_checking_shared_status()
1129 struct pool *pool = m->tc->pool; in queue_passdown_pt2() local
1131 spin_lock_irqsave(&pool->lock, flags); in queue_passdown_pt2()
1132 list_add_tail(&m->list, &pool->prepared_discards_pt2); in queue_passdown_pt2()
1133 spin_unlock_irqrestore(&pool->lock, flags); in queue_passdown_pt2()
1134 wake_worker(pool); in queue_passdown_pt2()
1151 struct pool *pool = tc->pool; in process_prepared_discard_passdown_pt1() local
1162 metadata_operation_failed(pool, "dm_thin_remove_range", r); in process_prepared_discard_passdown_pt1()
1165 mempool_free(m, &pool->mapping_pool); in process_prepared_discard_passdown_pt1()
1173 r = dm_pool_inc_data_range(pool->pmd, m->data_block, data_end); in process_prepared_discard_passdown_pt1()
1175 metadata_operation_failed(pool, "dm_pool_inc_data_range", r); in process_prepared_discard_passdown_pt1()
1178 mempool_free(m, &pool->mapping_pool); in process_prepared_discard_passdown_pt1()
1200 struct pool *pool = tc->pool; in process_prepared_discard_passdown_pt2() local
1206 r = dm_pool_dec_data_range(pool->pmd, m->data_block, in process_prepared_discard_passdown_pt2()
1209 metadata_operation_failed(pool, "dm_pool_dec_data_range", r); in process_prepared_discard_passdown_pt2()
1215 mempool_free(m, &pool->mapping_pool); in process_prepared_discard_passdown_pt2()
1218 static void process_prepared(struct pool *pool, struct list_head *head, in process_prepared() argument
1225 spin_lock_irq(&pool->lock); in process_prepared()
1227 spin_unlock_irq(&pool->lock); in process_prepared()
1236 static int io_overlaps_block(struct pool *pool, struct bio *bio) in io_overlaps_block() argument
1239 (pool->sectors_per_block << SECTOR_SHIFT); in io_overlaps_block()
1242 static int io_overwrites_block(struct pool *pool, struct bio *bio) in io_overwrites_block() argument
1245 io_overlaps_block(pool, bio); in io_overwrites_block()
1255 static int ensure_next_mapping(struct pool *pool) in ensure_next_mapping() argument
1257 if (pool->next_mapping) in ensure_next_mapping()
1260 pool->next_mapping = mempool_alloc(&pool->mapping_pool, GFP_ATOMIC); in ensure_next_mapping()
1262 return pool->next_mapping ? 0 : -ENOMEM; in ensure_next_mapping()
1265 static struct dm_thin_new_mapping *get_next_mapping(struct pool *pool) in get_next_mapping() argument
1267 struct dm_thin_new_mapping *m = pool->next_mapping; in get_next_mapping()
1269 BUG_ON(!pool->next_mapping); in get_next_mapping()
1275 pool->next_mapping = NULL; in get_next_mapping()
1289 dm_kcopyd_zero(tc->pool->copier, 1, &to, 0, copy_complete, m); in ll_zero()
1296 struct pool *pool = tc->pool; in remap_and_issue_overwrite() local
1302 inc_all_io_entry(pool, bio); in remap_and_issue_overwrite()
1315 struct pool *pool = tc->pool; in schedule_copy() local
1316 struct dm_thin_new_mapping *m = get_next_mapping(pool); in schedule_copy()
1331 if (!dm_deferred_set_add_work(pool->shared_read_ds, &m->list)) in schedule_copy()
1340 if (io_overwrites_block(pool, bio)) in schedule_copy()
1346 from.sector = data_origin * pool->sectors_per_block; in schedule_copy()
1350 to.sector = data_dest * pool->sectors_per_block; in schedule_copy()
1353 dm_kcopyd_copy(pool->copier, &from, 1, &to, in schedule_copy()
1359 if (len < pool->sectors_per_block && pool->pf.zero_new_blocks) { in schedule_copy()
1362 data_dest * pool->sectors_per_block + len, in schedule_copy()
1363 (data_dest + 1) * pool->sectors_per_block); in schedule_copy()
1376 tc->pool->sectors_per_block); in schedule_internal_copy()
1383 struct pool *pool = tc->pool; in schedule_zero() local
1384 struct dm_thin_new_mapping *m = get_next_mapping(pool); in schedule_zero()
1398 if (pool->pf.zero_new_blocks) { in schedule_zero()
1399 if (io_overwrites_block(pool, bio)) in schedule_zero()
1402 ll_zero(tc, m, data_block * pool->sectors_per_block, in schedule_zero()
1403 (data_block + 1) * pool->sectors_per_block); in schedule_zero()
1413 struct pool *pool = tc->pool; in schedule_external_copy() local
1414 sector_t virt_block_begin = virt_block * pool->sectors_per_block; in schedule_external_copy()
1415 sector_t virt_block_end = (virt_block + 1) * pool->sectors_per_block; in schedule_external_copy()
1420 pool->sectors_per_block); in schedule_external_copy()
1431 static void set_pool_mode(struct pool *pool, enum pool_mode new_mode);
1433 static void requeue_bios(struct pool *pool);
1440 static bool is_read_only(struct pool *pool) in is_read_only() argument
1442 return is_read_only_pool_mode(get_pool_mode(pool)); in is_read_only()
1445 static void check_for_metadata_space(struct pool *pool) in check_for_metadata_space() argument
1451 r = dm_pool_get_free_metadata_block_count(pool->pmd, &nr_free); in check_for_metadata_space()
1457 if (ooms_reason && !is_read_only(pool)) { in check_for_metadata_space()
1459 set_pool_mode(pool, PM_OUT_OF_METADATA_SPACE); in check_for_metadata_space()
1463 static void check_for_data_space(struct pool *pool) in check_for_data_space() argument
1468 if (get_pool_mode(pool) != PM_OUT_OF_DATA_SPACE) in check_for_data_space()
1471 r = dm_pool_get_free_block_count(pool->pmd, &nr_free); in check_for_data_space()
1476 set_pool_mode(pool, PM_WRITE); in check_for_data_space()
1477 requeue_bios(pool); in check_for_data_space()
1485 static int commit(struct pool *pool) in commit() argument
1489 if (get_pool_mode(pool) >= PM_OUT_OF_METADATA_SPACE) in commit()
1492 r = dm_pool_commit_metadata(pool->pmd); in commit()
1494 metadata_operation_failed(pool, "dm_pool_commit_metadata", r); in commit()
1496 check_for_metadata_space(pool); in commit()
1497 check_for_data_space(pool); in commit()
1503 static void check_low_water_mark(struct pool *pool, dm_block_t free_blocks) in check_low_water_mark() argument
1505 if (free_blocks <= pool->low_water_blocks && !pool->low_water_triggered) { in check_low_water_mark()
1507 dm_device_name(pool->pool_md)); in check_low_water_mark()
1508 spin_lock_irq(&pool->lock); in check_low_water_mark()
1509 pool->low_water_triggered = true; in check_low_water_mark()
1510 spin_unlock_irq(&pool->lock); in check_low_water_mark()
1511 dm_table_event(pool->ti->table); in check_low_water_mark()
1519 struct pool *pool = tc->pool; in alloc_data_block() local
1521 if (WARN_ON(get_pool_mode(pool) != PM_WRITE)) in alloc_data_block()
1524 r = dm_pool_get_free_block_count(pool->pmd, &free_blocks); in alloc_data_block()
1526 metadata_operation_failed(pool, "dm_pool_get_free_block_count", r); in alloc_data_block()
1530 check_low_water_mark(pool, free_blocks); in alloc_data_block()
1537 r = commit(pool); in alloc_data_block()
1541 r = dm_pool_get_free_block_count(pool->pmd, &free_blocks); in alloc_data_block()
1543 metadata_operation_failed(pool, "dm_pool_get_free_block_count", r); in alloc_data_block()
1548 set_pool_mode(pool, PM_OUT_OF_DATA_SPACE); in alloc_data_block()
1553 r = dm_pool_alloc_data_block(pool->pmd, result); in alloc_data_block()
1556 set_pool_mode(pool, PM_OUT_OF_DATA_SPACE); in alloc_data_block()
1558 metadata_operation_failed(pool, "dm_pool_alloc_data_block", r); in alloc_data_block()
1562 r = dm_pool_get_free_metadata_block_count(pool->pmd, &free_blocks); in alloc_data_block()
1564 metadata_operation_failed(pool, "dm_pool_get_free_metadata_block_count", r); in alloc_data_block()
1570 r = commit(pool); in alloc_data_block()
1592 static blk_status_t should_error_unserviceable_bio(struct pool *pool) in should_error_unserviceable_bio() argument
1594 enum pool_mode m = get_pool_mode(pool); in should_error_unserviceable_bio()
1603 return pool->pf.error_if_no_space ? BLK_STS_NOSPC : 0; in should_error_unserviceable_bio()
1616 static void handle_unserviceable_bio(struct pool *pool, struct bio *bio) in handle_unserviceable_bio() argument
1618 blk_status_t error = should_error_unserviceable_bio(pool); in handle_unserviceable_bio()
1627 static void retry_bios_on_resume(struct pool *pool, struct dm_bio_prison_cell *cell) in retry_bios_on_resume() argument
1633 error = should_error_unserviceable_bio(pool); in retry_bios_on_resume()
1635 cell_error_with_code(pool, cell, error); in retry_bios_on_resume()
1640 cell_release(pool, cell, &bios); in retry_bios_on_resume()
1649 struct pool *pool = tc->pool; in process_discard_cell_no_passdown() local
1650 struct dm_thin_new_mapping *m = get_next_mapping(pool); in process_discard_cell_no_passdown()
1662 if (!dm_deferred_set_add_work(pool->all_io_ds, &m->list)) in process_discard_cell_no_passdown()
1663 pool->process_prepared_discard(m); in process_discard_cell_no_passdown()
1669 struct pool *pool = tc->pool; in break_up_discard_bio() local
1696 r = ensure_next_mapping(pool); in break_up_discard_bio()
1706 if (bio_detain(tc->pool, &data_key, NULL, &data_cell)) { in break_up_discard_bio()
1716 m = get_next_mapping(pool); in break_up_discard_bio()
1734 if (!dm_deferred_set_add_work(pool->all_io_ds, &m->list)) in break_up_discard_bio()
1735 pool->process_prepared_discard(m); in break_up_discard_bio()
1787 if (bio_detain(tc->pool, &virt_key, bio, &virt_cell)) { in process_discard_bio()
1798 tc->pool->process_discard_cell(tc, virt_cell); in process_discard_bio()
1808 struct pool *pool = tc->pool; in break_sharing() local
1818 retry_bios_on_resume(pool, cell); in break_sharing()
1824 cell_error(pool, cell); in break_sharing()
1842 h->shared_read_entry = dm_deferred_entry_inc(info->tc->pool->shared_read_ds); in __remap_and_issue_shared_cell()
1843 inc_all_io_entry(info->tc->pool, bio); in __remap_and_issue_shared_cell()
1860 cell_visit_release(tc->pool, __remap_and_issue_shared_cell, in remap_and_issue_shared_cell()
1876 struct pool *pool = tc->pool; in process_shared_bio() local
1884 if (bio_detain(pool, &key, bio, &data_cell)) { in process_shared_bio()
1895 h->shared_read_entry = dm_deferred_entry_inc(pool->shared_read_ds); in process_shared_bio()
1896 inc_all_io_entry(pool, bio); in process_shared_bio()
1909 struct pool *pool = tc->pool; in provision_block() local
1915 inc_all_io_entry(pool, bio); in provision_block()
1942 retry_bios_on_resume(pool, cell); in provision_block()
1948 cell_error(pool, cell); in provision_block()
1956 struct pool *pool = tc->pool; in process_cell() local
1962 cell_requeue(pool, cell); in process_cell()
1972 inc_all_io_entry(pool, bio); in process_cell()
1980 inc_all_io_entry(pool, bio); in process_cell()
2010 struct pool *pool = tc->pool; in process_bio() local
2020 if (bio_detain(pool, &key, bio, &cell)) in process_bio()
2038 handle_unserviceable_bio(tc->pool, bio); in __process_bio_read_only()
2042 inc_all_io_entry(tc->pool, bio); in __process_bio_read_only()
2053 handle_unserviceable_bio(tc->pool, bio); in __process_bio_read_only()
2058 inc_all_io_entry(tc->pool, bio); in __process_bio_read_only()
2099 cell_success(tc->pool, cell); in process_cell_success()
2104 cell_error(tc->pool, cell); in process_cell_fail()
2111 static int need_commit_due_to_time(struct pool *pool) in need_commit_due_to_time() argument
2113 return !time_in_range(jiffies, pool->last_commit_jiffies, in need_commit_due_to_time()
2114 pool->last_commit_jiffies + COMMIT_PERIOD); in need_commit_due_to_time()
2183 struct pool *pool = tc->pool; in process_thin_deferred_bios() local
2218 if (ensure_next_mapping(pool)) { in process_thin_deferred_bios()
2227 pool->process_discard(tc, bio); in process_thin_deferred_bios()
2229 pool->process_bio(tc, bio); in process_thin_deferred_bios()
2232 throttle_work_update(&pool->throttle); in process_thin_deferred_bios()
2233 dm_pool_issue_prefetches(pool->pmd); in process_thin_deferred_bios()
2257 static unsigned int sort_cells(struct pool *pool, struct list_head *cells) in sort_cells() argument
2266 pool->cell_sort_array[count++] = cell; in sort_cells()
2270 sort(pool->cell_sort_array, count, sizeof(cell), cmp_cells, NULL); in sort_cells()
2277 struct pool *pool = tc->pool; in process_thin_deferred_cells() local
2292 count = sort_cells(tc->pool, &cells); in process_thin_deferred_cells()
2295 cell = pool->cell_sort_array[i]; in process_thin_deferred_cells()
2303 if (ensure_next_mapping(pool)) { in process_thin_deferred_cells()
2305 list_add(&pool->cell_sort_array[j]->user_list, &cells); in process_thin_deferred_cells()
2314 pool->process_discard_cell(tc, cell); in process_thin_deferred_cells()
2316 pool->process_cell(tc, cell); in process_thin_deferred_cells()
2330 static struct thin_c *get_first_thin(struct pool *pool) in get_first_thin() argument
2335 if (!list_empty(&pool->active_thins)) { in get_first_thin()
2336 tc = list_entry_rcu(pool->active_thins.next, struct thin_c, list); in get_first_thin()
2344 static struct thin_c *get_next_thin(struct pool *pool, struct thin_c *tc) in get_next_thin() argument
2349 list_for_each_entry_continue_rcu(tc, &pool->active_thins, list) { in get_next_thin()
2361 static void process_deferred_bios(struct pool *pool) in process_deferred_bios() argument
2367 tc = get_first_thin(pool); in process_deferred_bios()
2371 tc = get_next_thin(pool, tc); in process_deferred_bios()
2381 spin_lock_irq(&pool->lock); in process_deferred_bios()
2382 bio_list_merge(&bios, &pool->deferred_flush_bios); in process_deferred_bios()
2383 bio_list_init(&pool->deferred_flush_bios); in process_deferred_bios()
2385 bio_list_merge(&bio_completions, &pool->deferred_flush_completions); in process_deferred_bios()
2386 bio_list_init(&pool->deferred_flush_completions); in process_deferred_bios()
2387 spin_unlock_irq(&pool->lock); in process_deferred_bios()
2390 !(dm_pool_changed_this_transaction(pool->pmd) && need_commit_due_to_time(pool))) in process_deferred_bios()
2393 if (commit(pool)) { in process_deferred_bios()
2400 pool->last_commit_jiffies = jiffies; in process_deferred_bios()
2419 struct pool *pool = container_of(ws, struct pool, worker); in do_worker() local
2421 throttle_work_start(&pool->throttle); in do_worker()
2422 dm_pool_issue_prefetches(pool->pmd); in do_worker()
2423 throttle_work_update(&pool->throttle); in do_worker()
2424 process_prepared(pool, &pool->prepared_mappings, &pool->process_prepared_mapping); in do_worker()
2425 throttle_work_update(&pool->throttle); in do_worker()
2426 process_prepared(pool, &pool->prepared_discards, &pool->process_prepared_discard); in do_worker()
2427 throttle_work_update(&pool->throttle); in do_worker()
2428 process_prepared(pool, &pool->prepared_discards_pt2, &pool->process_prepared_discard_pt2); in do_worker()
2429 throttle_work_update(&pool->throttle); in do_worker()
2430 process_deferred_bios(pool); in do_worker()
2431 throttle_work_complete(&pool->throttle); in do_worker()
2440 struct pool *pool = container_of(to_delayed_work(ws), struct pool, waker); in do_waker() local
2442 wake_worker(pool); in do_waker()
2443 queue_delayed_work(pool->wq, &pool->waker, COMMIT_PERIOD); in do_waker()
2453 struct pool *pool = container_of(to_delayed_work(ws), struct pool, in do_no_space_timeout() local
2456 if (get_pool_mode(pool) == PM_OUT_OF_DATA_SPACE && !pool->pf.error_if_no_space) { in do_no_space_timeout()
2457 pool->pf.error_if_no_space = true; in do_no_space_timeout()
2458 notify_of_pool_mode_change(pool); in do_no_space_timeout()
2459 error_retry_list_with_code(pool, BLK_STS_NOSPC); in do_no_space_timeout()
2480 static void pool_work_wait(struct pool_work *pw, struct pool *pool, in pool_work_wait() argument
2485 queue_work(pool->wq, &pw->worker); in pool_work_wait()
2523 pool_work_wait(&w.pw, tc->pool, fn); in noflush_work()
2528 static void set_discard_callbacks(struct pool *pool) in set_discard_callbacks() argument
2530 struct pool_c *pt = pool->ti->private; in set_discard_callbacks()
2533 pool->process_discard_cell = process_discard_cell_passdown; in set_discard_callbacks()
2534 pool->process_prepared_discard = process_prepared_discard_passdown_pt1; in set_discard_callbacks()
2535 pool->process_prepared_discard_pt2 = process_prepared_discard_passdown_pt2; in set_discard_callbacks()
2537 pool->process_discard_cell = process_discard_cell_no_passdown; in set_discard_callbacks()
2538 pool->process_prepared_discard = process_prepared_discard_no_passdown; in set_discard_callbacks()
2542 static void set_pool_mode(struct pool *pool, enum pool_mode new_mode) in set_pool_mode() argument
2544 struct pool_c *pt = pool->ti->private; in set_pool_mode()
2545 bool needs_check = dm_pool_metadata_needs_check(pool->pmd); in set_pool_mode()
2546 enum pool_mode old_mode = get_pool_mode(pool); in set_pool_mode()
2555 dm_device_name(pool->pool_md)); in set_pool_mode()
2571 dm_pool_metadata_read_only(pool->pmd); in set_pool_mode()
2572 pool->process_bio = process_bio_fail; in set_pool_mode()
2573 pool->process_discard = process_bio_fail; in set_pool_mode()
2574 pool->process_cell = process_cell_fail; in set_pool_mode()
2575 pool->process_discard_cell = process_cell_fail; in set_pool_mode()
2576 pool->process_prepared_mapping = process_prepared_mapping_fail; in set_pool_mode()
2577 pool->process_prepared_discard = process_prepared_discard_fail; in set_pool_mode()
2579 error_retry_list(pool); in set_pool_mode()
2584 dm_pool_metadata_read_only(pool->pmd); in set_pool_mode()
2585 pool->process_bio = process_bio_read_only; in set_pool_mode()
2586 pool->process_discard = process_bio_success; in set_pool_mode()
2587 pool->process_cell = process_cell_read_only; in set_pool_mode()
2588 pool->process_discard_cell = process_cell_success; in set_pool_mode()
2589 pool->process_prepared_mapping = process_prepared_mapping_fail; in set_pool_mode()
2590 pool->process_prepared_discard = process_prepared_discard_success; in set_pool_mode()
2592 error_retry_list(pool); in set_pool_mode()
2604 pool->out_of_data_space = true; in set_pool_mode()
2605 pool->process_bio = process_bio_read_only; in set_pool_mode()
2606 pool->process_discard = process_discard_bio; in set_pool_mode()
2607 pool->process_cell = process_cell_read_only; in set_pool_mode()
2608 pool->process_prepared_mapping = process_prepared_mapping; in set_pool_mode()
2609 set_discard_callbacks(pool); in set_pool_mode()
2611 if (!pool->pf.error_if_no_space && no_space_timeout) in set_pool_mode()
2612 queue_delayed_work(pool->wq, &pool->no_space_timeout, no_space_timeout); in set_pool_mode()
2617 cancel_delayed_work_sync(&pool->no_space_timeout); in set_pool_mode()
2618 pool->out_of_data_space = false; in set_pool_mode()
2619 pool->pf.error_if_no_space = pt->requested_pf.error_if_no_space; in set_pool_mode()
2620 dm_pool_metadata_read_write(pool->pmd); in set_pool_mode()
2621 pool->process_bio = process_bio; in set_pool_mode()
2622 pool->process_discard = process_discard_bio; in set_pool_mode()
2623 pool->process_cell = process_cell; in set_pool_mode()
2624 pool->process_prepared_mapping = process_prepared_mapping; in set_pool_mode()
2625 set_discard_callbacks(pool); in set_pool_mode()
2629 pool->pf.mode = new_mode; in set_pool_mode()
2637 notify_of_pool_mode_change(pool); in set_pool_mode()
2640 static void abort_transaction(struct pool *pool) in abort_transaction() argument
2642 const char *dev_name = dm_device_name(pool->pool_md); in abort_transaction()
2645 if (dm_pool_abort_metadata(pool->pmd)) { in abort_transaction()
2647 set_pool_mode(pool, PM_FAIL); in abort_transaction()
2650 if (dm_pool_metadata_set_needs_check(pool->pmd)) { in abort_transaction()
2652 set_pool_mode(pool, PM_FAIL); in abort_transaction()
2656 static void metadata_operation_failed(struct pool *pool, const char *op, int r) in metadata_operation_failed() argument
2659 dm_device_name(pool->pool_md), op, r); in metadata_operation_failed()
2661 abort_transaction(pool); in metadata_operation_failed()
2662 set_pool_mode(pool, PM_READ_ONLY); in metadata_operation_failed()
2676 struct pool *pool = tc->pool; in thin_defer_bio() local
2682 wake_worker(pool); in thin_defer_bio()
2687 struct pool *pool = tc->pool; in thin_defer_bio_with_throttle() local
2689 throttle_lock(&pool->throttle); in thin_defer_bio_with_throttle()
2691 throttle_unlock(&pool->throttle); in thin_defer_bio_with_throttle()
2696 struct pool *pool = tc->pool; in thin_defer_cell() local
2698 throttle_lock(&pool->throttle); in thin_defer_cell()
2702 throttle_unlock(&pool->throttle); in thin_defer_cell()
2704 wake_worker(pool); in thin_defer_cell()
2739 if (get_pool_mode(tc->pool) == PM_FAIL) { in thin_bio_map()
2754 if (bio_detain(tc->pool, &key, bio, &virt_cell)) in thin_bio_map()
2784 if (bio_detain(tc->pool, &key, bio, &data_cell)) { in thin_bio_map()
2789 inc_all_io_entry(tc->pool, bio); in thin_bio_map()
2813 static void requeue_bios(struct pool *pool) in requeue_bios() argument
2818 list_for_each_entry_rcu(tc, &pool->active_thins, list) { in requeue_bios()
2843 struct pool *pool = pt->pool; in disable_discard_passdown_if_not_supported() local
2854 else if (data_limits->max_discard_sectors < pool->sectors_per_block) in disable_discard_passdown_if_not_supported()
2863 static int bind_control_target(struct pool *pool, struct dm_target *ti) in bind_control_target() argument
2870 enum pool_mode old_mode = get_pool_mode(pool); in bind_control_target()
2880 pool->ti = ti; in bind_control_target()
2881 pool->pf = pt->adjusted_pf; in bind_control_target()
2882 pool->low_water_blocks = pt->low_water_blocks; in bind_control_target()
2884 set_pool_mode(pool, new_mode); in bind_control_target()
2889 static void unbind_control_target(struct pool *pool, struct dm_target *ti) in unbind_control_target() argument
2891 if (pool->ti == ti) in unbind_control_target()
2892 pool->ti = NULL; in unbind_control_target()
2910 static void __pool_destroy(struct pool *pool) in __pool_destroy() argument
2912 __pool_table_remove(pool); in __pool_destroy()
2914 vfree(pool->cell_sort_array); in __pool_destroy()
2915 if (dm_pool_metadata_close(pool->pmd) < 0) in __pool_destroy()
2918 dm_bio_prison_destroy(pool->prison); in __pool_destroy()
2919 dm_kcopyd_client_destroy(pool->copier); in __pool_destroy()
2921 cancel_delayed_work_sync(&pool->waker); in __pool_destroy()
2922 cancel_delayed_work_sync(&pool->no_space_timeout); in __pool_destroy()
2923 if (pool->wq) in __pool_destroy()
2924 destroy_workqueue(pool->wq); in __pool_destroy()
2926 if (pool->next_mapping) in __pool_destroy()
2927 mempool_free(pool->next_mapping, &pool->mapping_pool); in __pool_destroy()
2928 mempool_exit(&pool->mapping_pool); in __pool_destroy()
2929 dm_deferred_set_destroy(pool->shared_read_ds); in __pool_destroy()
2930 dm_deferred_set_destroy(pool->all_io_ds); in __pool_destroy()
2931 kfree(pool); in __pool_destroy()
2936 static struct pool *pool_create(struct mapped_device *pool_md, in pool_create()
2944 struct pool *pool; in pool_create() local
2954 pool = kzalloc(sizeof(*pool), GFP_KERNEL); in pool_create()
2955 if (!pool) { in pool_create()
2961 pool->pmd = pmd; in pool_create()
2962 pool->sectors_per_block = block_size; in pool_create()
2964 pool->sectors_per_block_shift = -1; in pool_create()
2966 pool->sectors_per_block_shift = __ffs(block_size); in pool_create()
2967 pool->low_water_blocks = 0; in pool_create()
2968 pool_features_init(&pool->pf); in pool_create()
2969 pool->prison = dm_bio_prison_create(); in pool_create()
2970 if (!pool->prison) { in pool_create()
2976 pool->copier = dm_kcopyd_client_create(&dm_kcopyd_throttle); in pool_create()
2977 if (IS_ERR(pool->copier)) { in pool_create()
2978 r = PTR_ERR(pool->copier); in pool_create()
2988 pool->wq = alloc_ordered_workqueue("dm-" DM_MSG_PREFIX, WQ_MEM_RECLAIM); in pool_create()
2989 if (!pool->wq) { in pool_create()
2995 throttle_init(&pool->throttle); in pool_create()
2996 INIT_WORK(&pool->worker, do_worker); in pool_create()
2997 INIT_DELAYED_WORK(&pool->waker, do_waker); in pool_create()
2998 INIT_DELAYED_WORK(&pool->no_space_timeout, do_no_space_timeout); in pool_create()
2999 spin_lock_init(&pool->lock); in pool_create()
3000 bio_list_init(&pool->deferred_flush_bios); in pool_create()
3001 bio_list_init(&pool->deferred_flush_completions); in pool_create()
3002 INIT_LIST_HEAD(&pool->prepared_mappings); in pool_create()
3003 INIT_LIST_HEAD(&pool->prepared_discards); in pool_create()
3004 INIT_LIST_HEAD(&pool->prepared_discards_pt2); in pool_create()
3005 INIT_LIST_HEAD(&pool->active_thins); in pool_create()
3006 pool->low_water_triggered = false; in pool_create()
3007 pool->suspended = true; in pool_create()
3008 pool->out_of_data_space = false; in pool_create()
3010 pool->shared_read_ds = dm_deferred_set_create(); in pool_create()
3011 if (!pool->shared_read_ds) { in pool_create()
3017 pool->all_io_ds = dm_deferred_set_create(); in pool_create()
3018 if (!pool->all_io_ds) { in pool_create()
3024 pool->next_mapping = NULL; in pool_create()
3025 r = mempool_init_slab_pool(&pool->mapping_pool, MAPPING_POOL_SIZE, in pool_create()
3033 pool->cell_sort_array = in pool_create()
3035 sizeof(*pool->cell_sort_array))); in pool_create()
3036 if (!pool->cell_sort_array) { in pool_create()
3042 pool->ref_count = 1; in pool_create()
3043 pool->last_commit_jiffies = jiffies; in pool_create()
3044 pool->pool_md = pool_md; in pool_create()
3045 pool->md_dev = metadata_dev; in pool_create()
3046 pool->data_dev = data_dev; in pool_create()
3047 __pool_table_insert(pool); in pool_create()
3049 return pool; in pool_create()
3052 mempool_exit(&pool->mapping_pool); in pool_create()
3054 dm_deferred_set_destroy(pool->all_io_ds); in pool_create()
3056 dm_deferred_set_destroy(pool->shared_read_ds); in pool_create()
3058 destroy_workqueue(pool->wq); in pool_create()
3060 dm_kcopyd_client_destroy(pool->copier); in pool_create()
3062 dm_bio_prison_destroy(pool->prison); in pool_create()
3064 kfree(pool); in pool_create()
3072 static void __pool_inc(struct pool *pool) in __pool_inc() argument
3075 pool->ref_count++; in __pool_inc()
3078 static void __pool_dec(struct pool *pool) in __pool_dec() argument
3081 BUG_ON(!pool->ref_count); in __pool_dec()
3082 if (!--pool->ref_count) in __pool_dec()
3083 __pool_destroy(pool); in __pool_dec()
3086 static struct pool *__pool_find(struct mapped_device *pool_md, in __pool_find()
3092 struct pool *pool = __pool_table_lookup_metadata_dev(metadata_dev); in __pool_find() local
3094 if (pool) { in __pool_find()
3095 if (pool->pool_md != pool_md) { in __pool_find()
3099 if (pool->data_dev != data_dev) { in __pool_find()
3103 __pool_inc(pool); in __pool_find()
3106 pool = __pool_table_lookup(pool_md); in __pool_find()
3107 if (pool) { in __pool_find()
3108 if (pool->md_dev != metadata_dev || pool->data_dev != data_dev) { in __pool_find()
3112 __pool_inc(pool); in __pool_find()
3115 pool = pool_create(pool_md, metadata_dev, data_dev, block_size, read_only, error); in __pool_find()
3120 return pool; in __pool_find()
3134 unbind_control_target(pt->pool, ti); in pool_dtr()
3135 __pool_dec(pt->pool); in pool_dtr()
3195 struct pool *pool = context; in metadata_low_callback() local
3198 dm_device_name(pool->pool_md)); in metadata_low_callback()
3200 dm_table_event(pool->ti->table); in metadata_low_callback()
3216 struct pool *pool = context; in metadata_pre_commit_callback() local
3218 return blkdev_issue_flush(pool->data_dev); in metadata_pre_commit_callback()
3289 struct pool *pool; in pool_ctr() local
3365 pool = __pool_find(dm_table_get_md(ti->table), metadata_dev->bdev, data_dev->bdev, in pool_ctr()
3367 if (IS_ERR(pool)) { in pool_ctr()
3368 r = PTR_ERR(pool); in pool_ctr()
3378 if (!pool_created && pf.discard_enabled != pool->pf.discard_enabled) { in pool_ctr()
3384 pt->pool = pool; in pool_ctr()
3410 r = dm_pool_register_metadata_threshold(pt->pool->pmd, in pool_ctr()
3413 pool); in pool_ctr()
3419 dm_pool_register_pre_commit_callback(pool->pmd, in pool_ctr()
3420 metadata_pre_commit_callback, pool); in pool_ctr()
3427 __pool_dec(pool); in pool_ctr()
3443 struct pool *pool = pt->pool; in pool_map() local
3448 spin_lock_irq(&pool->lock); in pool_map()
3450 spin_unlock_irq(&pool->lock); in pool_map()
3459 struct pool *pool = pt->pool; in maybe_resize_data_dev() local
3465 (void) sector_div(data_size, pool->sectors_per_block); in maybe_resize_data_dev()
3467 r = dm_pool_get_data_dev_size(pool->pmd, &sb_data_size); in maybe_resize_data_dev()
3470 dm_device_name(pool->pool_md)); in maybe_resize_data_dev()
3476 dm_device_name(pool->pool_md), in maybe_resize_data_dev()
3481 if (dm_pool_metadata_needs_check(pool->pmd)) { in maybe_resize_data_dev()
3483 dm_device_name(pool->pool_md)); in maybe_resize_data_dev()
3489 dm_device_name(pool->pool_md), in maybe_resize_data_dev()
3491 r = dm_pool_resize_data_dev(pool->pmd, data_size); in maybe_resize_data_dev()
3493 metadata_operation_failed(pool, "dm_pool_resize_data_dev", r); in maybe_resize_data_dev()
3507 struct pool *pool = pt->pool; in maybe_resize_metadata_dev() local
3512 metadata_dev_size = get_metadata_dev_size_in_blocks(pool->md_dev); in maybe_resize_metadata_dev()
3514 r = dm_pool_get_metadata_dev_size(pool->pmd, &sb_metadata_dev_size); in maybe_resize_metadata_dev()
3517 dm_device_name(pool->pool_md)); in maybe_resize_metadata_dev()
3523 dm_device_name(pool->pool_md), in maybe_resize_metadata_dev()
3528 if (dm_pool_metadata_needs_check(pool->pmd)) { in maybe_resize_metadata_dev()
3530 dm_device_name(pool->pool_md)); in maybe_resize_metadata_dev()
3534 warn_if_metadata_device_too_big(pool->md_dev); in maybe_resize_metadata_dev()
3536 dm_device_name(pool->pool_md), in maybe_resize_metadata_dev()
3539 if (get_pool_mode(pool) == PM_OUT_OF_METADATA_SPACE) in maybe_resize_metadata_dev()
3540 set_pool_mode(pool, PM_WRITE); in maybe_resize_metadata_dev()
3542 r = dm_pool_resize_metadata_dev(pool->pmd, metadata_dev_size); in maybe_resize_metadata_dev()
3544 metadata_operation_failed(pool, "dm_pool_resize_metadata_dev", r); in maybe_resize_metadata_dev()
3570 struct pool *pool = pt->pool; in pool_preresume() local
3575 r = bind_control_target(pool, ti); in pool_preresume()
3588 (void) commit(pool); in pool_preresume()
3595 if (r && get_pool_mode(pool) == PM_FAIL) in pool_preresume()
3601 static void pool_suspend_active_thins(struct pool *pool) in pool_suspend_active_thins() argument
3606 tc = get_first_thin(pool); in pool_suspend_active_thins()
3609 tc = get_next_thin(pool, tc); in pool_suspend_active_thins()
3613 static void pool_resume_active_thins(struct pool *pool) in pool_resume_active_thins() argument
3618 tc = get_first_thin(pool); in pool_resume_active_thins()
3621 tc = get_next_thin(pool, tc); in pool_resume_active_thins()
3628 struct pool *pool = pt->pool; in pool_resume() local
3634 requeue_bios(pool); in pool_resume()
3635 pool_resume_active_thins(pool); in pool_resume()
3637 spin_lock_irq(&pool->lock); in pool_resume()
3638 pool->low_water_triggered = false; in pool_resume()
3639 pool->suspended = false; in pool_resume()
3640 spin_unlock_irq(&pool->lock); in pool_resume()
3642 do_waker(&pool->waker.work); in pool_resume()
3648 struct pool *pool = pt->pool; in pool_presuspend() local
3650 spin_lock_irq(&pool->lock); in pool_presuspend()
3651 pool->suspended = true; in pool_presuspend()
3652 spin_unlock_irq(&pool->lock); in pool_presuspend()
3654 pool_suspend_active_thins(pool); in pool_presuspend()
3660 struct pool *pool = pt->pool; in pool_presuspend_undo() local
3662 pool_resume_active_thins(pool); in pool_presuspend_undo()
3664 spin_lock_irq(&pool->lock); in pool_presuspend_undo()
3665 pool->suspended = false; in pool_presuspend_undo()
3666 spin_unlock_irq(&pool->lock); in pool_presuspend_undo()
3672 struct pool *pool = pt->pool; in pool_postsuspend() local
3674 cancel_delayed_work_sync(&pool->waker); in pool_postsuspend()
3675 cancel_delayed_work_sync(&pool->no_space_timeout); in pool_postsuspend()
3676 flush_workqueue(pool->wq); in pool_postsuspend()
3677 (void) commit(pool); in pool_postsuspend()
3703 static int process_create_thin_mesg(unsigned int argc, char **argv, struct pool *pool) in process_create_thin_mesg() argument
3716 r = dm_pool_create_thin(pool->pmd, dev_id); in process_create_thin_mesg()
3726 static int process_create_snap_mesg(unsigned int argc, char **argv, struct pool *pool) in process_create_snap_mesg() argument
3744 r = dm_pool_create_snap(pool->pmd, dev_id, origin_dev_id); in process_create_snap_mesg()
3754 static int process_delete_mesg(unsigned int argc, char **argv, struct pool *pool) in process_delete_mesg() argument
3767 r = dm_pool_delete_thin_device(pool->pmd, dev_id); in process_delete_mesg()
3774 static int process_set_transaction_id_mesg(unsigned int argc, char **argv, struct pool *pool) in process_set_transaction_id_mesg() argument
3793 r = dm_pool_set_metadata_transaction_id(pool->pmd, old_id, new_id); in process_set_transaction_id_mesg()
3803 static int process_reserve_metadata_snap_mesg(unsigned int argc, char **argv, struct pool *pool) in process_reserve_metadata_snap_mesg() argument
3811 (void) commit(pool); in process_reserve_metadata_snap_mesg()
3813 r = dm_pool_reserve_metadata_snap(pool->pmd); in process_reserve_metadata_snap_mesg()
3820 static int process_release_metadata_snap_mesg(unsigned int argc, char **argv, struct pool *pool) in process_release_metadata_snap_mesg() argument
3828 r = dm_pool_release_metadata_snap(pool->pmd); in process_release_metadata_snap_mesg()
3849 struct pool *pool = pt->pool; in pool_message() local
3851 if (get_pool_mode(pool) >= PM_OUT_OF_METADATA_SPACE) { in pool_message()
3853 dm_device_name(pool->pool_md)); in pool_message()
3858 r = process_create_thin_mesg(argc, argv, pool); in pool_message()
3861 r = process_create_snap_mesg(argc, argv, pool); in pool_message()
3864 r = process_delete_mesg(argc, argv, pool); in pool_message()
3867 r = process_set_transaction_id_mesg(argc, argv, pool); in pool_message()
3870 r = process_reserve_metadata_snap_mesg(argc, argv, pool); in pool_message()
3873 r = process_release_metadata_snap_mesg(argc, argv, pool); in pool_message()
3879 (void) commit(pool); in pool_message()
3929 struct pool *pool = pt->pool; in pool_status() local
3933 if (get_pool_mode(pool) == PM_FAIL) { in pool_status()
3940 (void) commit(pool); in pool_status()
3942 r = dm_pool_get_metadata_transaction_id(pool->pmd, &transaction_id); in pool_status()
3945 dm_device_name(pool->pool_md), r); in pool_status()
3949 r = dm_pool_get_free_metadata_block_count(pool->pmd, &nr_free_blocks_metadata); in pool_status()
3952 dm_device_name(pool->pool_md), r); in pool_status()
3956 r = dm_pool_get_metadata_dev_size(pool->pmd, &nr_blocks_metadata); in pool_status()
3959 dm_device_name(pool->pool_md), r); in pool_status()
3963 r = dm_pool_get_free_block_count(pool->pmd, &nr_free_blocks_data); in pool_status()
3966 dm_device_name(pool->pool_md), r); in pool_status()
3970 r = dm_pool_get_data_dev_size(pool->pmd, &nr_blocks_data); in pool_status()
3973 dm_device_name(pool->pool_md), r); in pool_status()
3977 r = dm_pool_get_metadata_snap(pool->pmd, &held_root); in pool_status()
3980 dm_device_name(pool->pool_md), r); in pool_status()
3996 mode = get_pool_mode(pool); in pool_status()
4004 if (!pool->pf.discard_enabled) in pool_status()
4006 else if (pool->pf.discard_passdown) in pool_status()
4011 if (pool->pf.error_if_no_space) in pool_status()
4016 if (dm_pool_metadata_needs_check(pool->pmd)) in pool_status()
4029 (unsigned long)pool->sectors_per_block, in pool_status()
4055 struct pool *pool = pt->pool; in pool_io_hints() local
4067 if (limits->max_sectors < pool->sectors_per_block) { in pool_io_hints()
4068 while (!is_factor(pool->sectors_per_block, limits->max_sectors)) { in pool_io_hints()
4079 if (io_opt_sectors < pool->sectors_per_block || in pool_io_hints()
4080 !is_factor(io_opt_sectors, pool->sectors_per_block)) { in pool_io_hints()
4081 if (is_factor(pool->sectors_per_block, limits->max_sectors)) in pool_io_hints()
4084 limits->io_min = pool->sectors_per_block << SECTOR_SHIFT; in pool_io_hints()
4085 limits->io_opt = pool->sectors_per_block << SECTOR_SHIFT; in pool_io_hints()
4151 spin_lock_irq(&tc->pool->lock); in thin_dtr()
4153 spin_unlock_irq(&tc->pool->lock); in thin_dtr()
4161 __pool_dec(tc->pool); in thin_dtr()
4246 tc->pool = __pool_table_lookup(pool_md); in thin_ctr()
4247 if (!tc->pool) { in thin_ctr()
4252 __pool_inc(tc->pool); in thin_ctr()
4254 if (get_pool_mode(tc->pool) == PM_FAIL) { in thin_ctr()
4260 r = dm_pool_open_thin_device(tc->pool->pmd, tc->dev_id, &tc->td); in thin_ctr()
4266 r = dm_set_target_max_io_len(ti, tc->pool->sectors_per_block); in thin_ctr()
4277 if (tc->pool->pf.discard_enabled) { in thin_ctr()
4285 spin_lock_irq(&tc->pool->lock); in thin_ctr()
4286 if (tc->pool->suspended) { in thin_ctr()
4287 spin_unlock_irq(&tc->pool->lock); in thin_ctr()
4295 list_add_tail_rcu(&tc->list, &tc->pool->active_thins); in thin_ctr()
4296 spin_unlock_irq(&tc->pool->lock); in thin_ctr()
4312 __pool_dec(tc->pool); in thin_ctr()
4342 struct pool *pool = h->tc->pool; in thin_endio() local
4348 spin_lock_irqsave(&pool->lock, flags); in thin_endio()
4353 spin_unlock_irqrestore(&pool->lock, flags); in thin_endio()
4360 spin_lock_irqsave(&pool->lock, flags); in thin_endio()
4362 list_add_tail(&m->list, &pool->prepared_discards); in thin_endio()
4363 spin_unlock_irqrestore(&pool->lock, flags); in thin_endio()
4364 wake_worker(pool); in thin_endio()
4415 if (get_pool_mode(tc->pool) == PM_FAIL) { in thin_status()
4437 DMEMIT("%llu ", mapped * tc->pool->sectors_per_block); in thin_status()
4440 tc->pool->sectors_per_block) - 1); in thin_status()
4470 struct pool *pool = tc->pool; in thin_iterate_devices() local
4476 if (!pool->ti) in thin_iterate_devices()
4479 blocks = pool->ti->len; in thin_iterate_devices()
4480 (void) sector_div(blocks, pool->sectors_per_block); in thin_iterate_devices()
4482 return fn(ti, tc->pool_dev, 0, pool->sectors_per_block * blocks, data); in thin_iterate_devices()
4490 struct pool *pool = tc->pool; in thin_io_hints() local
4492 if (pool->pf.discard_enabled) { in thin_io_hints()
4493 limits->discard_granularity = pool->sectors_per_block << SECTOR_SHIFT; in thin_io_hints()
4494 limits->max_hw_discard_sectors = pool->sectors_per_block * BIO_PRISON_MAX_RANGE; in thin_io_hints()