Lines Matching refs:t

59 static inline sector_t *get_node(struct dm_table *t,  in get_node()  argument
62 return t->index[l] + (n * KEYS_PER_NODE); in get_node()
69 static sector_t high(struct dm_table *t, unsigned int l, unsigned int n) in high() argument
71 for (; l < t->depth - 1; l++) in high()
74 if (n >= t->counts[l]) in high()
77 return get_node(t, l, n)[KEYS_PER_NODE - 1]; in high()
84 static int setup_btree_index(unsigned int l, struct dm_table *t) in setup_btree_index() argument
89 for (n = 0U; n < t->counts[l]; n++) { in setup_btree_index()
90 node = get_node(t, l, n); in setup_btree_index()
93 node[k] = high(t, l + 1, get_child(n, k)); in setup_btree_index()
103 static int alloc_targets(struct dm_table *t, unsigned int num) in alloc_targets() argument
119 kvfree(t->highs); in alloc_targets()
121 t->num_allocated = num; in alloc_targets()
122 t->highs = n_highs; in alloc_targets()
123 t->targets = n_targets; in alloc_targets()
131 struct dm_table *t = kzalloc(sizeof(*t), GFP_KERNEL); in dm_table_create() local
133 if (!t) in dm_table_create()
136 INIT_LIST_HEAD(&t->devices); in dm_table_create()
144 kfree(t); in dm_table_create()
148 if (alloc_targets(t, num_targets)) { in dm_table_create()
149 kfree(t); in dm_table_create()
153 t->type = DM_TYPE_NONE; in dm_table_create()
154 t->mode = mode; in dm_table_create()
155 t->md = md; in dm_table_create()
156 *result = t; in dm_table_create()
174 static void dm_table_destroy_crypto_profile(struct dm_table *t);
176 void dm_table_destroy(struct dm_table *t) in dm_table_destroy() argument
178 if (!t) in dm_table_destroy()
182 if (t->depth >= 2) in dm_table_destroy()
183 kvfree(t->index[t->depth - 2]); in dm_table_destroy()
186 for (unsigned int i = 0; i < t->num_targets; i++) { in dm_table_destroy()
187 struct dm_target *ti = dm_table_get_target(t, i); in dm_table_destroy()
195 kvfree(t->highs); in dm_table_destroy()
198 free_devices(&t->devices, t->md); in dm_table_destroy()
200 dm_free_md_mempools(t->mempools); in dm_table_destroy()
202 dm_table_destroy_crypto_profile(t); in dm_table_destroy()
204 kfree(t); in dm_table_destroy()
353 struct dm_table *t = ti->table; in dm_get_device() local
355 BUG_ON(!t); in dm_get_device()
368 dd = find_device(&t->devices, dev); in dm_get_device()
374 if ((r = dm_get_table_device(t->md, dev, mode, &dd->dm_dev))) { in dm_get_device()
380 list_add(&dd->list, &t->devices); in dm_get_device()
384 r = upgrade_mode(dd, mode, t->md); in dm_get_device()
452 static int adjoin(struct dm_table *t, struct dm_target *ti) in adjoin() argument
456 if (!t->num_targets) in adjoin()
459 prev = &t->targets[t->num_targets - 1]; in adjoin()
566 static int validate_hardware_logical_block_alignment(struct dm_table *t, in validate_hardware_logical_block_alignment() argument
594 for (i = 0; i < t->num_targets; i++) { in validate_hardware_logical_block_alignment()
595 ti = dm_table_get_target(t, i); in validate_hardware_logical_block_alignment()
623 dm_device_name(t->md), i, in validate_hardware_logical_block_alignment()
633 int dm_table_add_target(struct dm_table *t, const char *type, in dm_table_add_target() argument
640 if (t->singleton) { in dm_table_add_target()
642 dm_device_name(t->md), t->targets->type->name); in dm_table_add_target()
646 BUG_ON(t->num_targets >= t->num_allocated); in dm_table_add_target()
648 ti = t->targets + t->num_targets; in dm_table_add_target()
652 DMERR("%s: zero-length target", dm_device_name(t->md)); in dm_table_add_target()
658 DMERR("%s: %s: unknown target type", dm_device_name(t->md), type); in dm_table_add_target()
663 if (t->num_targets) { in dm_table_add_target()
667 t->singleton = true; in dm_table_add_target()
670 if (dm_target_always_writeable(ti->type) && !(t->mode & FMODE_WRITE)) { in dm_table_add_target()
675 if (t->immutable_target_type) { in dm_table_add_target()
676 if (t->immutable_target_type != ti->type) { in dm_table_add_target()
681 if (t->num_targets) { in dm_table_add_target()
685 t->immutable_target_type = ti->type; in dm_table_add_target()
689 t->integrity_added = 1; in dm_table_add_target()
691 ti->table = t; in dm_table_add_target()
699 if (!adjoin(t, ti)) { in dm_table_add_target()
715 t->highs[t->num_targets++] = ti->begin + ti->len - 1; in dm_table_add_target()
719 dm_device_name(t->md), type); in dm_table_add_target()
727 DMERR("%s: %s: %s (%pe)", dm_device_name(t->md), type, ti->error, ERR_PTR(r)); in dm_table_add_target()
802 void dm_table_set_type(struct dm_table *t, enum dm_queue_mode type) in dm_table_set_type() argument
804 t->type = type; in dm_table_set_type()
826 static bool dm_table_supports_dax(struct dm_table *t, in dm_table_supports_dax() argument
830 for (unsigned int i = 0; i < t->num_targets; i++) { in dm_table_supports_dax()
831 struct dm_target *ti = dm_table_get_target(t, i); in dm_table_supports_dax()
857 static int dm_table_determine_type(struct dm_table *t) in dm_table_determine_type() argument
861 struct list_head *devices = dm_table_get_devices(t); in dm_table_determine_type()
862 enum dm_queue_mode live_md_type = dm_get_md_type(t->md); in dm_table_determine_type()
864 if (t->type != DM_TYPE_NONE) { in dm_table_determine_type()
866 if (t->type == DM_TYPE_BIO_BASED) { in dm_table_determine_type()
870 BUG_ON(t->type == DM_TYPE_DAX_BIO_BASED); in dm_table_determine_type()
874 for (unsigned int i = 0; i < t->num_targets; i++) { in dm_table_determine_type()
875 ti = dm_table_get_target(t, i); in dm_table_determine_type()
905 t->type = DM_TYPE_BIO_BASED; in dm_table_determine_type()
906 if (dm_table_supports_dax(t, device_not_dax_capable) || in dm_table_determine_type()
908 t->type = DM_TYPE_DAX_BIO_BASED; in dm_table_determine_type()
915 t->type = DM_TYPE_REQUEST_BASED; in dm_table_determine_type()
924 if (t->num_targets > 1) { in dm_table_determine_type()
931 struct dm_table *live_table = dm_get_live_table(t->md, &srcu_idx); in dm_table_determine_type()
935 t->type = live_table->type; in dm_table_determine_type()
936 dm_put_live_table(t->md, srcu_idx); in dm_table_determine_type()
940 ti = dm_table_get_immutable_target(t); in dm_table_determine_type()
959 enum dm_queue_mode dm_table_get_type(struct dm_table *t) in dm_table_get_type() argument
961 return t->type; in dm_table_get_type()
964 struct target_type *dm_table_get_immutable_target_type(struct dm_table *t) in dm_table_get_immutable_target_type() argument
966 return t->immutable_target_type; in dm_table_get_immutable_target_type()
969 struct dm_target *dm_table_get_immutable_target(struct dm_table *t) in dm_table_get_immutable_target() argument
972 if (t->num_targets > 1 || in dm_table_get_immutable_target()
973 !dm_target_is_immutable(t->targets[0].type)) in dm_table_get_immutable_target()
976 return t->targets; in dm_table_get_immutable_target()
979 struct dm_target *dm_table_get_wildcard_target(struct dm_table *t) in dm_table_get_wildcard_target() argument
981 for (unsigned int i = 0; i < t->num_targets; i++) { in dm_table_get_wildcard_target()
982 struct dm_target *ti = dm_table_get_target(t, i); in dm_table_get_wildcard_target()
991 bool dm_table_bio_based(struct dm_table *t) in dm_table_bio_based() argument
993 return __table_type_bio_based(dm_table_get_type(t)); in dm_table_bio_based()
996 bool dm_table_request_based(struct dm_table *t) in dm_table_request_based() argument
998 return __table_type_request_based(dm_table_get_type(t)); in dm_table_request_based()
1001 static bool dm_table_supports_poll(struct dm_table *t);
1003 static int dm_table_alloc_md_mempools(struct dm_table *t, struct mapped_device *md) in dm_table_alloc_md_mempools() argument
1005 enum dm_queue_mode type = dm_table_get_type(t); in dm_table_alloc_md_mempools()
1025 for (unsigned int i = 0; i < t->num_targets; i++) { in dm_table_alloc_md_mempools()
1026 struct dm_target *ti = dm_table_get_target(t, i); in dm_table_alloc_md_mempools()
1038 dm_table_supports_poll(t) ? BIOSET_PERCPU_CACHE : 0)) in dm_table_alloc_md_mempools()
1040 if (t->integrity_supported && in dm_table_alloc_md_mempools()
1046 if (t->integrity_supported && in dm_table_alloc_md_mempools()
1050 t->mempools = pools; in dm_table_alloc_md_mempools()
1058 static int setup_indexes(struct dm_table *t) in setup_indexes() argument
1065 for (i = t->depth - 2; i >= 0; i--) { in setup_indexes()
1066 t->counts[i] = dm_div_up(t->counts[i + 1], CHILDREN_PER_NODE); in setup_indexes()
1067 total += t->counts[i]; in setup_indexes()
1075 for (i = t->depth - 2; i >= 0; i--) { in setup_indexes()
1076 t->index[i] = indexes; in setup_indexes()
1077 indexes += (KEYS_PER_NODE * t->counts[i]); in setup_indexes()
1078 setup_btree_index(i, t); in setup_indexes()
1087 static int dm_table_build_index(struct dm_table *t) in dm_table_build_index() argument
1093 leaf_nodes = dm_div_up(t->num_targets, KEYS_PER_NODE); in dm_table_build_index()
1094 t->depth = 1 + int_log(leaf_nodes, CHILDREN_PER_NODE); in dm_table_build_index()
1097 t->counts[t->depth - 1] = leaf_nodes; in dm_table_build_index()
1098 t->index[t->depth - 1] = t->highs; in dm_table_build_index()
1100 if (t->depth >= 2) in dm_table_build_index()
1101 r = setup_indexes(t); in dm_table_build_index()
1115 static struct gendisk *dm_table_get_integrity_disk(struct dm_table *t) in dm_table_get_integrity_disk() argument
1117 struct list_head *devices = dm_table_get_devices(t); in dm_table_get_integrity_disk()
1121 for (unsigned int i = 0; i < t->num_targets; i++) { in dm_table_get_integrity_disk()
1122 struct dm_target *ti = dm_table_get_target(t, i); in dm_table_get_integrity_disk()
1143 dm_device_name(t->md), in dm_table_get_integrity_disk()
1159 static int dm_table_register_integrity(struct dm_table *t) in dm_table_register_integrity() argument
1161 struct mapped_device *md = t->md; in dm_table_register_integrity()
1165 if (t->integrity_added) in dm_table_register_integrity()
1168 template_disk = dm_table_get_integrity_disk(t); in dm_table_register_integrity()
1173 t->integrity_supported = true; in dm_table_register_integrity()
1190 dm_device_name(t->md), in dm_table_register_integrity()
1196 t->integrity_supported = true; in dm_table_register_integrity()
1235 struct dm_table *t; in dm_keyslot_evict() local
1238 t = dm_get_live_table(md, &srcu_idx); in dm_keyslot_evict()
1239 if (!t) in dm_keyslot_evict()
1242 for (unsigned int i = 0; i < t->num_targets; i++) { in dm_keyslot_evict()
1243 struct dm_target *ti = dm_table_get_target(t, i); in dm_keyslot_evict()
1279 static void dm_table_destroy_crypto_profile(struct dm_table *t) in dm_table_destroy_crypto_profile() argument
1281 dm_destroy_crypto_profile(t->crypto_profile); in dm_table_destroy_crypto_profile()
1282 t->crypto_profile = NULL; in dm_table_destroy_crypto_profile()
1294 static int dm_table_construct_crypto_profile(struct dm_table *t) in dm_table_construct_crypto_profile() argument
1304 dmcp->md = t->md; in dm_table_construct_crypto_profile()
1313 for (i = 0; i < t->num_targets; i++) { in dm_table_construct_crypto_profile()
1314 struct dm_target *ti = dm_table_get_target(t, i); in dm_table_construct_crypto_profile()
1327 if (t->md->queue && in dm_table_construct_crypto_profile()
1329 t->md->queue->crypto_profile)) { in dm_table_construct_crypto_profile()
1356 t->crypto_profile = profile; in dm_table_construct_crypto_profile()
1362 struct dm_table *t) in dm_update_crypto_profile() argument
1364 if (!t->crypto_profile) in dm_update_crypto_profile()
1369 blk_crypto_register(t->crypto_profile, q); in dm_update_crypto_profile()
1372 t->crypto_profile); in dm_update_crypto_profile()
1373 dm_destroy_crypto_profile(t->crypto_profile); in dm_update_crypto_profile()
1375 t->crypto_profile = NULL; in dm_update_crypto_profile()
1380 static int dm_table_construct_crypto_profile(struct dm_table *t) in dm_table_construct_crypto_profile() argument
1389 static void dm_table_destroy_crypto_profile(struct dm_table *t) in dm_table_destroy_crypto_profile() argument
1394 struct dm_table *t) in dm_update_crypto_profile() argument
1404 int dm_table_complete(struct dm_table *t) in dm_table_complete() argument
1408 r = dm_table_determine_type(t); in dm_table_complete()
1414 r = dm_table_build_index(t); in dm_table_complete()
1420 r = dm_table_register_integrity(t); in dm_table_complete()
1426 r = dm_table_construct_crypto_profile(t); in dm_table_complete()
1432 r = dm_table_alloc_md_mempools(t, t->md); in dm_table_complete()
1440 void dm_table_event_callback(struct dm_table *t, in dm_table_event_callback() argument
1444 t->event_fn = fn; in dm_table_event_callback()
1445 t->event_context = context; in dm_table_event_callback()
1449 void dm_table_event(struct dm_table *t) in dm_table_event() argument
1452 if (t->event_fn) in dm_table_event()
1453 t->event_fn(t->event_context); in dm_table_event()
1458 inline sector_t dm_table_get_size(struct dm_table *t) in dm_table_get_size() argument
1460 return t->num_targets ? (t->highs[t->num_targets - 1] + 1) : 0; in dm_table_get_size()
1470 struct dm_target *dm_table_find_target(struct dm_table *t, sector_t sector) in dm_table_find_target() argument
1475 if (unlikely(sector >= dm_table_get_size(t))) in dm_table_find_target()
1478 for (l = 0; l < t->depth; l++) { in dm_table_find_target()
1480 node = get_node(t, l, n); in dm_table_find_target()
1487 return &t->targets[(KEYS_PER_NODE * n) + k]; in dm_table_find_target()
1521 static bool dm_table_any_dev_attr(struct dm_table *t, in dm_table_any_dev_attr() argument
1524 for (unsigned int i = 0; i < t->num_targets; i++) { in dm_table_any_dev_attr()
1525 struct dm_target *ti = dm_table_get_target(t, i); in dm_table_any_dev_attr()
1545 static bool dm_table_supports_poll(struct dm_table *t) in dm_table_supports_poll() argument
1547 for (unsigned int i = 0; i < t->num_targets; i++) { in dm_table_supports_poll()
1548 struct dm_target *ti = dm_table_get_target(t, i); in dm_table_supports_poll()
1564 bool dm_table_has_no_data_devices(struct dm_table *t) in dm_table_has_no_data_devices() argument
1566 for (unsigned int i = 0; i < t->num_targets; i++) { in dm_table_has_no_data_devices()
1567 struct dm_target *ti = dm_table_get_target(t, i); in dm_table_has_no_data_devices()
1597 static bool dm_table_supports_zoned_model(struct dm_table *t, in dm_table_supports_zoned_model() argument
1600 for (unsigned int i = 0; i < t->num_targets; i++) { in dm_table_supports_zoned_model()
1601 struct dm_target *ti = dm_table_get_target(t, i); in dm_table_supports_zoned_model()
1632 static int validate_hardware_zoned_model(struct dm_table *t, in validate_hardware_zoned_model() argument
1639 if (!dm_table_supports_zoned_model(t, zoned_model)) { in validate_hardware_zoned_model()
1641 dm_device_name(t->md)); in validate_hardware_zoned_model()
1649 if (dm_table_any_dev_attr(t, device_not_matches_zone_sectors, &zone_sectors)) { in validate_hardware_zoned_model()
1651 dm_device_name(t->md)); in validate_hardware_zoned_model()
1661 int dm_calculate_queue_limits(struct dm_table *t, in dm_calculate_queue_limits() argument
1670 for (unsigned int i = 0; i < t->num_targets; i++) { in dm_calculate_queue_limits()
1671 struct dm_target *ti = dm_table_get_target(t, i); in dm_calculate_queue_limits()
1714 dm_device_name(t->md), in dm_calculate_queue_limits()
1734 if (validate_hardware_zoned_model(t, zoned_model, zone_sectors)) in dm_calculate_queue_limits()
1737 return validate_hardware_logical_block_alignment(t, limits); in dm_calculate_queue_limits()
1745 static void dm_table_verify_integrity(struct dm_table *t) in dm_table_verify_integrity() argument
1749 if (t->integrity_added) in dm_table_verify_integrity()
1752 if (t->integrity_supported) { in dm_table_verify_integrity()
1757 template_disk = dm_table_get_integrity_disk(t); in dm_table_verify_integrity()
1759 blk_integrity_compare(dm_disk(t->md), template_disk) >= 0) in dm_table_verify_integrity()
1763 if (integrity_profile_exists(dm_disk(t->md))) { in dm_table_verify_integrity()
1765 dm_device_name(t->md)); in dm_table_verify_integrity()
1766 blk_integrity_unregister(dm_disk(t->md)); in dm_table_verify_integrity()
1779 static bool dm_table_supports_flush(struct dm_table *t, unsigned long flush) in dm_table_supports_flush() argument
1787 for (unsigned int i = 0; i < t->num_targets; i++) { in dm_table_supports_flush()
1788 struct dm_target *ti = dm_table_get_target(t, i); in dm_table_supports_flush()
1840 static bool dm_table_supports_write_zeroes(struct dm_table *t) in dm_table_supports_write_zeroes() argument
1842 for (unsigned int i = 0; i < t->num_targets; i++) { in dm_table_supports_write_zeroes()
1843 struct dm_target *ti = dm_table_get_target(t, i); in dm_table_supports_write_zeroes()
1862 static bool dm_table_supports_nowait(struct dm_table *t) in dm_table_supports_nowait() argument
1864 for (unsigned int i = 0; i < t->num_targets; i++) { in dm_table_supports_nowait()
1865 struct dm_target *ti = dm_table_get_target(t, i); in dm_table_supports_nowait()
1884 static bool dm_table_supports_discards(struct dm_table *t) in dm_table_supports_discards() argument
1886 for (unsigned int i = 0; i < t->num_targets; i++) { in dm_table_supports_discards()
1887 struct dm_target *ti = dm_table_get_target(t, i); in dm_table_supports_discards()
1913 static bool dm_table_supports_secure_erase(struct dm_table *t) in dm_table_supports_secure_erase() argument
1915 for (unsigned int i = 0; i < t->num_targets; i++) { in dm_table_supports_secure_erase()
1916 struct dm_target *ti = dm_table_get_target(t, i); in dm_table_supports_secure_erase()
1936 int dm_table_set_restrictions(struct dm_table *t, struct request_queue *q, in dm_table_set_restrictions() argument
1947 if (dm_table_supports_nowait(t)) in dm_table_set_restrictions()
1952 if (!dm_table_supports_discards(t)) { in dm_table_set_restrictions()
1960 if (!dm_table_supports_secure_erase(t)) in dm_table_set_restrictions()
1963 if (dm_table_supports_flush(t, (1UL << QUEUE_FLAG_WC))) { in dm_table_set_restrictions()
1965 if (dm_table_supports_flush(t, (1UL << QUEUE_FLAG_FUA))) in dm_table_set_restrictions()
1970 if (dm_table_supports_dax(t, device_not_dax_capable)) { in dm_table_set_restrictions()
1972 if (dm_table_supports_dax(t, device_not_dax_synchronous_capable)) in dm_table_set_restrictions()
1973 set_dax_synchronous(t->md->dax_dev); in dm_table_set_restrictions()
1978 if (dm_table_any_dev_attr(t, device_dax_write_cache_enabled, NULL)) in dm_table_set_restrictions()
1979 dax_write_cache(t->md->dax_dev, true); in dm_table_set_restrictions()
1982 if (dm_table_any_dev_attr(t, device_is_rotational, NULL)) in dm_table_set_restrictions()
1987 if (!dm_table_supports_write_zeroes(t)) in dm_table_set_restrictions()
1990 dm_table_verify_integrity(t); in dm_table_set_restrictions()
1999 if (dm_table_any_dev_attr(t, device_requires_stable_pages, NULL)) in dm_table_set_restrictions()
2011 dm_table_any_dev_attr(t, device_is_not_random, NULL)) in dm_table_set_restrictions()
2019 r = dm_set_zones_restrictions(t, q); in dm_table_set_restrictions()
2026 dm_update_crypto_profile(q, t); in dm_table_set_restrictions()
2027 disk_update_readahead(t->md->disk); in dm_table_set_restrictions()
2036 if (__table_type_bio_based(t->type)) { in dm_table_set_restrictions()
2037 if (dm_table_supports_poll(t)) in dm_table_set_restrictions()
2046 struct list_head *dm_table_get_devices(struct dm_table *t) in dm_table_get_devices() argument
2048 return &t->devices; in dm_table_get_devices()
2051 fmode_t dm_table_get_mode(struct dm_table *t) in dm_table_get_mode() argument
2053 return t->mode; in dm_table_get_mode()
2063 static void suspend_targets(struct dm_table *t, enum suspend_mode mode) in suspend_targets() argument
2065 lockdep_assert_held(&t->md->suspend_lock); in suspend_targets()
2067 for (unsigned int i = 0; i < t->num_targets; i++) { in suspend_targets()
2068 struct dm_target *ti = dm_table_get_target(t, i); in suspend_targets()
2087 void dm_table_presuspend_targets(struct dm_table *t) in dm_table_presuspend_targets() argument
2089 if (!t) in dm_table_presuspend_targets()
2092 suspend_targets(t, PRESUSPEND); in dm_table_presuspend_targets()
2095 void dm_table_presuspend_undo_targets(struct dm_table *t) in dm_table_presuspend_undo_targets() argument
2097 if (!t) in dm_table_presuspend_undo_targets()
2100 suspend_targets(t, PRESUSPEND_UNDO); in dm_table_presuspend_undo_targets()
2103 void dm_table_postsuspend_targets(struct dm_table *t) in dm_table_postsuspend_targets() argument
2105 if (!t) in dm_table_postsuspend_targets()
2108 suspend_targets(t, POSTSUSPEND); in dm_table_postsuspend_targets()
2111 int dm_table_resume_targets(struct dm_table *t) in dm_table_resume_targets() argument
2116 lockdep_assert_held(&t->md->suspend_lock); in dm_table_resume_targets()
2118 for (i = 0; i < t->num_targets; i++) { in dm_table_resume_targets()
2119 struct dm_target *ti = dm_table_get_target(t, i); in dm_table_resume_targets()
2127 dm_device_name(t->md), ti->type->name, r); in dm_table_resume_targets()
2132 for (i = 0; i < t->num_targets; i++) { in dm_table_resume_targets()
2133 struct dm_target *ti = dm_table_get_target(t, i); in dm_table_resume_targets()
2142 struct mapped_device *dm_table_get_md(struct dm_table *t) in dm_table_get_md() argument
2144 return t->md; in dm_table_get_md()
2148 const char *dm_table_device_name(struct dm_table *t) in dm_table_device_name() argument
2150 return dm_device_name(t->md); in dm_table_device_name()
2154 void dm_table_run_md_queue_async(struct dm_table *t) in dm_table_run_md_queue_async() argument
2156 if (!dm_table_request_based(t)) in dm_table_run_md_queue_async()
2159 if (t->md->queue) in dm_table_run_md_queue_async()
2160 blk_mq_run_hw_queues(t->md->queue, true); in dm_table_run_md_queue_async()