Lines Matching +full:super +full:- +full:set

1 // SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (c) 2014-2015, Intel Corporation.
9 #include <linux/blk-integrity.h>
19 #include <linux/backing-dev.h>
31 return &arena->nd_btt->dev; in to_dev()
36 return offset + nd_btt->initial_offset; in adjust_initial_offset()
42 struct nd_btt *nd_btt = arena->nd_btt; in arena_read_bytes()
43 struct nd_namespace_common *ndns = nd_btt->ndns; in arena_read_bytes()
53 struct nd_btt *nd_btt = arena->nd_btt; in arena_write_bytes()
54 struct nd_namespace_common *ndns = nd_btt->ndns; in arena_write_bytes()
61 static int btt_info_write(struct arena_info *arena, struct btt_sb *super) in btt_info_write() argument
70 dev_WARN_ONCE(to_dev(arena), !IS_ALIGNED(arena->infooff, 512), in btt_info_write()
71 "arena->infooff: %#llx is unaligned\n", arena->infooff); in btt_info_write()
72 dev_WARN_ONCE(to_dev(arena), !IS_ALIGNED(arena->info2off, 512), in btt_info_write()
73 "arena->info2off: %#llx is unaligned\n", arena->info2off); in btt_info_write()
75 ret = arena_write_bytes(arena, arena->info2off, super, in btt_info_write()
80 return arena_write_bytes(arena, arena->infooff, super, in btt_info_write()
84 static int btt_info_read(struct arena_info *arena, struct btt_sb *super) in btt_info_read() argument
86 return arena_read_bytes(arena, arena->infooff, super, in btt_info_read()
93 * mapping is in little-endian
99 u64 ns_off = arena->mapoff + (lba * MAP_ENT_SIZE); in __btt_map_write()
101 if (unlikely(lba >= arena->external_nlba)) in __btt_map_write()
104 __func__, lba, arena->external_nlba); in __btt_map_write()
116 * any flags set, so strip the flag bits. in btt_map_write()
124 * We want to set neither of the Z or E flags, and in btt_map_write()
145 return -EIO; in btt_map_write()
158 u64 ns_off = arena->mapoff + (lba * MAP_ENT_SIZE); in btt_map_read()
160 if (unlikely(lba >= arena->external_nlba)) in btt_map_read()
163 __func__, lba, arena->external_nlba); in btt_map_read()
197 return -EIO; in btt_map_read()
212 arena->logoff + (lane * LOG_GRP_SIZE), log, in btt_log_group_read()
232 a->debugfs_dir = d; in arena_debugfs_init()
234 debugfs_create_x64("size", S_IRUGO, d, &a->size); in arena_debugfs_init()
236 &a->external_lba_start); in arena_debugfs_init()
237 debugfs_create_x32("internal_nlba", S_IRUGO, d, &a->internal_nlba); in arena_debugfs_init()
239 &a->internal_lbasize); in arena_debugfs_init()
240 debugfs_create_x32("external_nlba", S_IRUGO, d, &a->external_nlba); in arena_debugfs_init()
242 &a->external_lbasize); in arena_debugfs_init()
243 debugfs_create_u32("nfree", S_IRUGO, d, &a->nfree); in arena_debugfs_init()
244 debugfs_create_u16("version_major", S_IRUGO, d, &a->version_major); in arena_debugfs_init()
245 debugfs_create_u16("version_minor", S_IRUGO, d, &a->version_minor); in arena_debugfs_init()
246 debugfs_create_x64("nextoff", S_IRUGO, d, &a->nextoff); in arena_debugfs_init()
247 debugfs_create_x64("infooff", S_IRUGO, d, &a->infooff); in arena_debugfs_init()
248 debugfs_create_x64("dataoff", S_IRUGO, d, &a->dataoff); in arena_debugfs_init()
249 debugfs_create_x64("mapoff", S_IRUGO, d, &a->mapoff); in arena_debugfs_init()
250 debugfs_create_x64("logoff", S_IRUGO, d, &a->logoff); in arena_debugfs_init()
251 debugfs_create_x64("info2off", S_IRUGO, d, &a->info2off); in arena_debugfs_init()
252 debugfs_create_x32("flags", S_IRUGO, d, &a->flags); in arena_debugfs_init()
253 debugfs_create_u32("log_index_0", S_IRUGO, d, &a->log_index[0]); in arena_debugfs_init()
254 debugfs_create_u32("log_index_1", S_IRUGO, d, &a->log_index[1]); in arena_debugfs_init()
262 btt->debugfs_dir = debugfs_create_dir(dev_name(&btt->nd_btt->dev), in btt_debugfs_init()
264 if (IS_ERR_OR_NULL(btt->debugfs_dir)) in btt_debugfs_init()
267 list_for_each_entry(arena, &btt->arena_list, list) { in btt_debugfs_init()
268 arena_debugfs_init(arena, btt->debugfs_dir, i); in btt_debugfs_init()
275 return le32_to_cpu(log->ent[log_idx].seq); in log_seq()
282 * make it the 'new' one if the mark_flag is set.
285 * TODO The logic feels a bit kludge-y. make it better..
289 int idx0 = a->log_index[0]; in btt_log_get_old()
290 int idx1 = a->log_index[1]; in btt_log_get_old()
299 log->ent[idx0].seq = cpu_to_le32(1); in btt_log_get_old()
304 return -EINVAL; in btt_log_get_old()
306 return -EINVAL; in btt_log_get_old()
309 if ((log_seq(log, idx1) - log_seq(log, idx0)) == 1) in btt_log_get_old()
314 if ((log_seq(log, idx0) - log_seq(log, idx1)) == 1) in btt_log_get_old()
325 * it is not NULL. It returns the sub-slot number (0 or 1)
338 return -EIO; in btt_log_read()
344 old_ent, lane, log.ent[arena->log_index[0]].seq, in btt_log_read()
345 log.ent[arena->log_index[1]].seq); in btt_log_read()
346 /* TODO set error state? */ in btt_log_read()
347 return -EIO; in btt_log_read()
350 ret_ent = (old_flag ? old_ent : (1 - old_ent)); in btt_log_read()
353 memcpy(ent, &log.ent[arena->log_index[ret_ent]], LOG_ENT_SIZE); in btt_log_read()
367 u32 group_slot = arena->log_index[sub]; in __btt_log_write()
372 ns_off = arena->logoff + (lane * LOG_GRP_SIZE) + in __btt_log_write()
394 arena->freelist[lane].sub = 1 - arena->freelist[lane].sub; in btt_flog_write()
395 if (++(arena->freelist[lane].seq) == 4) in btt_flog_write()
396 arena->freelist[lane].seq = 1; in btt_flog_write()
397 if (ent_e_flag(le32_to_cpu(ent->old_map))) in btt_flog_write()
398 arena->freelist[lane].has_err = 1; in btt_flog_write()
399 arena->freelist[lane].block = ent_lba(le32_to_cpu(ent->old_map)); in btt_flog_write()
406 * all-zeroes, and indicates an identity mapping
410 int ret = -EINVAL; in btt_map_init()
414 size_t mapsize = arena->logoff - arena->mapoff; in btt_map_init()
418 return -ENOMEM; in btt_map_init()
425 dev_WARN_ONCE(to_dev(arena), !IS_ALIGNED(arena->mapoff, 512), in btt_map_init()
426 "arena->mapoff: %#llx is unaligned\n", arena->mapoff); in btt_map_init()
433 ret = arena_write_bytes(arena, arena->mapoff + offset, zerobuf, in btt_map_init()
439 mapsize -= size; in btt_map_init()
450 * to the initial reserved set of blocks as being free
454 size_t logsize = arena->info2off - arena->logoff; in btt_log_init()
463 return -ENOMEM; in btt_log_init()
469 dev_WARN_ONCE(to_dev(arena), !IS_ALIGNED(arena->logoff, 512), in btt_log_init()
470 "arena->logoff: %#llx is unaligned\n", arena->logoff); in btt_log_init()
477 ret = arena_write_bytes(arena, arena->logoff + offset, zerobuf, in btt_log_init()
483 logsize -= size; in btt_log_init()
487 for (i = 0; i < arena->nfree; i++) { in btt_log_init()
489 ent.old_map = cpu_to_le32(arena->external_nlba + i); in btt_log_init()
490 ent.new_map = cpu_to_le32(arena->external_nlba + i); in btt_log_init()
504 return arena->dataoff + ((u64)lba * arena->internal_lbasize); in to_namespace_offset()
511 if (arena->freelist[lane].has_err) { in arena_clear_freelist_error()
513 u32 lba = arena->freelist[lane].block; in arena_clear_freelist_error()
515 unsigned long len = arena->sector_size; in arena_clear_freelist_error()
517 mutex_lock(&arena->err_lock); in arena_clear_freelist_error()
526 len -= chunk; in arena_clear_freelist_error()
529 arena->freelist[lane].has_err = 0; in arena_clear_freelist_error()
531 mutex_unlock(&arena->err_lock); in arena_clear_freelist_error()
542 arena->freelist = kcalloc(arena->nfree, sizeof(struct free_entry), in btt_freelist_init()
544 if (!arena->freelist) in btt_freelist_init()
545 return -ENOMEM; in btt_freelist_init()
547 for (i = 0; i < arena->nfree; i++) { in btt_freelist_init()
557 arena->freelist[i].sub = 1 - new; in btt_freelist_init()
558 arena->freelist[i].seq = nd_inc_seq(le32_to_cpu(log_new.seq)); in btt_freelist_init()
559 arena->freelist[i].block = log_oldmap; in btt_freelist_init()
563 * the BTT read-only in btt_freelist_init()
567 arena->freelist[i].has_err = 1; in btt_freelist_init()
608 return (ent->lba == 0) && (ent->old_map == 0) && (ent->new_map == 0) in ent_is_padding()
609 && (ent->seq == 0); in ent_is_padding()
615 * four slots. We expect that a padding slot will be all-zeroes, and use this
628 int ret, log_index[2] = {-1, -1}; in log_set_indices()
633 for (i = 0; i < arena->nfree; i++) { in log_set_indices()
657 return -ENXIO; in log_set_indices()
661 * once the indices have been set, just verify in log_set_indices()
669 return -ENXIO; in log_set_indices()
681 return -ENXIO; in log_set_indices()
687 * non-padding entry, then the we are no longer in the in log_set_indices()
696 return -ENXIO; in log_set_indices()
713 return -ENXIO; in log_set_indices()
716 arena->log_index[0] = log_index[0]; in log_set_indices()
717 arena->log_index[1] = log_index[1]; in log_set_indices()
725 arena->rtt = kcalloc(arena->nfree, sizeof(u32), GFP_KERNEL); in btt_rtt_init()
726 if (arena->rtt == NULL) in btt_rtt_init()
727 return -ENOMEM; in btt_rtt_init()
736 arena->map_locks = kcalloc(arena->nfree, sizeof(struct aligned_lock), in btt_maplocks_init()
738 if (!arena->map_locks) in btt_maplocks_init()
739 return -ENOMEM; in btt_maplocks_init()
741 for (i = 0; i < arena->nfree; i++) in btt_maplocks_init()
742 spin_lock_init(&arena->map_locks[i].lock); in btt_maplocks_init()
757 arena->nd_btt = btt->nd_btt; in alloc_arena()
758 arena->sector_size = btt->sector_size; in alloc_arena()
759 mutex_init(&arena->err_lock); in alloc_arena()
764 arena->size = size; in alloc_arena()
765 arena->external_lba_start = start; in alloc_arena()
766 arena->external_lbasize = btt->lbasize; in alloc_arena()
767 arena->internal_lbasize = roundup(arena->external_lbasize, in alloc_arena()
769 arena->nfree = BTT_DEFAULT_NFREE; in alloc_arena()
770 arena->version_major = btt->nd_btt->version_major; in alloc_arena()
771 arena->version_minor = btt->nd_btt->version_minor; in alloc_arena()
774 available -= (available % BTT_PG_SIZE); in alloc_arena()
776 /* Two pages are reserved for the super block and its copy */ in alloc_arena()
777 available -= 2 * BTT_PG_SIZE; in alloc_arena()
780 logsize = roundup(arena->nfree * LOG_GRP_SIZE, BTT_PG_SIZE); in alloc_arena()
781 available -= logsize; in alloc_arena()
784 arena->internal_nlba = div_u64(available - BTT_PG_SIZE, in alloc_arena()
785 arena->internal_lbasize + MAP_ENT_SIZE); in alloc_arena()
786 arena->external_nlba = arena->internal_nlba - arena->nfree; in alloc_arena()
788 mapsize = roundup((arena->external_nlba * MAP_ENT_SIZE), BTT_PG_SIZE); in alloc_arena()
789 datasize = available - mapsize; in alloc_arena()
792 arena->infooff = arena_off; in alloc_arena()
793 arena->dataoff = arena->infooff + BTT_PG_SIZE; in alloc_arena()
794 arena->mapoff = arena->dataoff + datasize; in alloc_arena()
795 arena->logoff = arena->mapoff + mapsize; in alloc_arena()
796 arena->info2off = arena->logoff + logsize; in alloc_arena()
799 arena->log_index[0] = 0; in alloc_arena()
800 arena->log_index[1] = 1; in alloc_arena()
808 list_for_each_entry_safe(arena, next, &btt->arena_list, list) { in free_arenas()
809 list_del(&arena->list); in free_arenas()
810 kfree(arena->rtt); in free_arenas()
811 kfree(arena->map_locks); in free_arenas()
812 kfree(arena->freelist); in free_arenas()
813 debugfs_remove_recursive(arena->debugfs_dir); in free_arenas()
822 static void parse_arena_meta(struct arena_info *arena, struct btt_sb *super, in parse_arena_meta() argument
825 arena->internal_nlba = le32_to_cpu(super->internal_nlba); in parse_arena_meta()
826 arena->internal_lbasize = le32_to_cpu(super->internal_lbasize); in parse_arena_meta()
827 arena->external_nlba = le32_to_cpu(super->external_nlba); in parse_arena_meta()
828 arena->external_lbasize = le32_to_cpu(super->external_lbasize); in parse_arena_meta()
829 arena->nfree = le32_to_cpu(super->nfree); in parse_arena_meta()
830 arena->version_major = le16_to_cpu(super->version_major); in parse_arena_meta()
831 arena->version_minor = le16_to_cpu(super->version_minor); in parse_arena_meta()
833 arena->nextoff = (super->nextoff == 0) ? 0 : (arena_off + in parse_arena_meta()
834 le64_to_cpu(super->nextoff)); in parse_arena_meta()
835 arena->infooff = arena_off; in parse_arena_meta()
836 arena->dataoff = arena_off + le64_to_cpu(super->dataoff); in parse_arena_meta()
837 arena->mapoff = arena_off + le64_to_cpu(super->mapoff); in parse_arena_meta()
838 arena->logoff = arena_off + le64_to_cpu(super->logoff); in parse_arena_meta()
839 arena->info2off = arena_off + le64_to_cpu(super->info2off); in parse_arena_meta()
841 arena->size = (le64_to_cpu(super->nextoff) > 0) in parse_arena_meta()
842 ? (le64_to_cpu(super->nextoff)) in parse_arena_meta()
843 : (arena->info2off - arena->infooff + BTT_PG_SIZE); in parse_arena_meta()
845 arena->flags = le32_to_cpu(super->flags); in parse_arena_meta()
852 size_t remaining = btt->rawsize; in discover_arenas()
857 struct btt_sb *super __free(kfree) = kzalloc(sizeof(*super), GFP_KERNEL); in discover_arenas()
858 if (!super) in discover_arenas()
859 return -ENOMEM; in discover_arenas()
865 return -ENOMEM; in discover_arenas()
867 arena->infooff = cur_off; in discover_arenas()
868 ret = btt_info_read(arena, super); in discover_arenas()
872 if (!nd_btt_arena_is_valid(btt->nd_btt, super)) { in discover_arenas()
873 if (remaining == btt->rawsize) { in discover_arenas()
874 btt->init_state = INIT_NOTFOUND; in discover_arenas()
880 ret = -ENODEV; in discover_arenas()
885 arena->external_lba_start = cur_nlba; in discover_arenas()
886 parse_arena_meta(arena, super, cur_off); in discover_arenas()
907 list_add_tail(&arena->list, &btt->arena_list); in discover_arenas()
909 remaining -= arena->size; in discover_arenas()
910 cur_off += arena->size; in discover_arenas()
911 cur_nlba += arena->external_nlba; in discover_arenas()
914 if (arena->nextoff == 0) in discover_arenas()
917 btt->num_arenas = num_arenas; in discover_arenas()
918 btt->nlba = cur_nlba; in discover_arenas()
919 btt->init_state = INIT_READY; in discover_arenas()
931 size_t remaining = btt->rawsize; in create_arenas()
938 remaining -= arena_size; in create_arenas()
942 arena = alloc_arena(btt, arena_size, btt->nlba, cur_off); in create_arenas()
945 return -ENOMEM; in create_arenas()
947 btt->nlba += arena->external_nlba; in create_arenas()
949 arena->nextoff = arena->size; in create_arenas()
951 arena->nextoff = 0; in create_arenas()
953 list_add_tail(&arena->list, &btt->arena_list); in create_arenas()
969 struct btt_sb *super; in btt_arena_write_layout() local
970 struct nd_btt *nd_btt = arena->nd_btt; in btt_arena_write_layout()
971 const uuid_t *parent_uuid = nd_dev_to_uuid(&nd_btt->ndns->dev); in btt_arena_write_layout()
981 super = kzalloc(sizeof(*super), GFP_NOIO); in btt_arena_write_layout()
982 if (!super) in btt_arena_write_layout()
983 return -ENOMEM; in btt_arena_write_layout()
985 strscpy(super->signature, BTT_SIG, sizeof(super->signature)); in btt_arena_write_layout()
986 export_uuid(super->uuid, nd_btt->uuid); in btt_arena_write_layout()
987 export_uuid(super->parent_uuid, parent_uuid); in btt_arena_write_layout()
988 super->flags = cpu_to_le32(arena->flags); in btt_arena_write_layout()
989 super->version_major = cpu_to_le16(arena->version_major); in btt_arena_write_layout()
990 super->version_minor = cpu_to_le16(arena->version_minor); in btt_arena_write_layout()
991 super->external_lbasize = cpu_to_le32(arena->external_lbasize); in btt_arena_write_layout()
992 super->external_nlba = cpu_to_le32(arena->external_nlba); in btt_arena_write_layout()
993 super->internal_lbasize = cpu_to_le32(arena->internal_lbasize); in btt_arena_write_layout()
994 super->internal_nlba = cpu_to_le32(arena->internal_nlba); in btt_arena_write_layout()
995 super->nfree = cpu_to_le32(arena->nfree); in btt_arena_write_layout()
996 super->infosize = cpu_to_le32(sizeof(struct btt_sb)); in btt_arena_write_layout()
997 super->nextoff = cpu_to_le64(arena->nextoff); in btt_arena_write_layout()
999 * Subtract arena->infooff (arena start) so numbers are relative in btt_arena_write_layout()
1002 super->dataoff = cpu_to_le64(arena->dataoff - arena->infooff); in btt_arena_write_layout()
1003 super->mapoff = cpu_to_le64(arena->mapoff - arena->infooff); in btt_arena_write_layout()
1004 super->logoff = cpu_to_le64(arena->logoff - arena->infooff); in btt_arena_write_layout()
1005 super->info2off = cpu_to_le64(arena->info2off - arena->infooff); in btt_arena_write_layout()
1007 super->flags = 0; in btt_arena_write_layout()
1008 sum = nd_sb_checksum((struct nd_gen_sb *) super); in btt_arena_write_layout()
1009 super->checksum = cpu_to_le64(sum); in btt_arena_write_layout()
1011 ret = btt_info_write(arena, super); in btt_arena_write_layout()
1013 kfree(super); in btt_arena_write_layout()
1026 mutex_lock(&btt->init_lock); in btt_meta_init()
1027 list_for_each_entry(arena, &btt->arena_list, list) { in btt_meta_init()
1045 btt->init_state = INIT_READY; in btt_meta_init()
1048 mutex_unlock(&btt->init_lock); in btt_meta_init()
1054 return btt->lbasize - btt->sector_size; in btt_meta_size()
1068 __u64 lba = div_u64(sector << SECTOR_SHIFT, btt->sector_size); in lba_to_arena()
1070 list_for_each_entry(arena_list, &btt->arena_list, list) { in lba_to_arena()
1071 if (lba < arena_list->external_nlba) { in lba_to_arena()
1076 lba -= arena_list->external_nlba; in lba_to_arena()
1079 return -EIO; in lba_to_arena()
1087 __acquires(&arena->map_locks[idx].lock) in lock_map()
1089 u32 idx = (premap * MAP_ENT_SIZE / L1_CACHE_BYTES) % arena->nfree; in lock_map()
1091 spin_lock(&arena->map_locks[idx].lock); in lock_map()
1095 __releases(&arena->map_locks[idx].lock) in unlock_map()
1097 u32 idx = (premap * MAP_ENT_SIZE / L1_CACHE_BYTES) % arena->nfree; in unlock_map()
1099 spin_unlock(&arena->map_locks[idx].lock); in unlock_map()
1147 meta_nsoff = to_namespace_offset(arena, postmap) + btt->sector_size; in btt_rw_integrity()
1154 bv = bvec_iter_bvec(bip->bip_vec, bip->bip_iter); in btt_rw_integrity()
1157 * .bv_offset already adjusted for iter->bi_bvec_done, and we in btt_rw_integrity()
1174 len -= cur_len; in btt_rw_integrity()
1176 if (!bvec_iter_advance(bip->bip_vec, &bip->bip_iter, cur_len)) in btt_rw_integrity()
1177 return -EIO; in btt_rw_integrity()
1203 lane = nd_region_acquire_lane(btt->nd_region); in btt_read_pg()
1209 cur_len = min(btt->sector_size, len); in btt_read_pg()
1231 ret = -EIO; in btt_read_pg()
1235 arena->rtt[lane] = RTT_VALID | postmap; in btt_read_pg()
1258 /* Media error - set the e_flag */ in btt_read_pg()
1272 arena->rtt[lane] = RTT_INVALID; in btt_read_pg()
1273 nd_region_release_lane(btt->nd_region, lane); in btt_read_pg()
1275 len -= cur_len; in btt_read_pg()
1277 sector += btt->sector_size >> SECTOR_SHIFT; in btt_read_pg()
1283 arena->rtt[lane] = RTT_INVALID; in btt_read_pg()
1285 nd_region_release_lane(btt->nd_region, lane); in btt_read_pg()
1297 u64 nsoff = adjust_initial_offset(arena->nd_btt, in btt_is_badblock()
1301 return is_bad_pmem(btt->phys_bb, phys_sector, arena->internal_lbasize); in btt_is_badblock()
1319 lane = nd_region_acquire_lane(btt->nd_region); in btt_write_pg()
1324 cur_len = min(btt->sector_size, len); in btt_write_pg()
1326 if ((arena->flags & IB_FLAG_ERROR_MASK) != 0) { in btt_write_pg()
1327 ret = -EIO; in btt_write_pg()
1331 if (btt_is_badblock(btt, arena, arena->freelist[lane].block)) in btt_write_pg()
1332 arena->freelist[lane].has_err = 1; in btt_write_pg()
1334 if (mutex_is_locked(&arena->err_lock) in btt_write_pg()
1335 || arena->freelist[lane].has_err) { in btt_write_pg()
1336 nd_region_release_lane(btt->nd_region, lane); in btt_write_pg()
1346 new_postmap = arena->freelist[lane].block; in btt_write_pg()
1349 for (i = 0; i < arena->nfree; i++) in btt_write_pg()
1350 while (arena->rtt[i] == (RTT_VALID | new_postmap)) in btt_write_pg()
1354 if (new_postmap >= arena->internal_nlba) { in btt_write_pg()
1355 ret = -EIO; in btt_write_pg()
1375 if (old_postmap >= arena->internal_nlba) { in btt_write_pg()
1376 ret = -EIO; in btt_write_pg()
1385 log.seq = cpu_to_le32(arena->freelist[lane].seq); in btt_write_pg()
1386 sub = arena->freelist[lane].sub; in btt_write_pg()
1397 nd_region_release_lane(btt->nd_region, lane); in btt_write_pg()
1405 len -= cur_len; in btt_write_pg()
1407 sector += btt->sector_size >> SECTOR_SHIFT; in btt_write_pg()
1415 nd_region_release_lane(btt->nd_region, lane); in btt_write_pg()
1439 struct btt *btt = bio->bi_bdev->bd_disk->private_data; in btt_submit_bio()
1449 do_acct = blk_queue_io_stat(bio->bi_bdev->bd_disk->queue); in btt_submit_bio()
1455 if (len > PAGE_SIZE || len < btt->sector_size || in btt_submit_bio()
1456 len % btt->sector_size) { in btt_submit_bio()
1457 dev_err_ratelimited(&btt->nd_btt->dev, in btt_submit_bio()
1459 bio->bi_status = BLK_STS_IOERR; in btt_submit_bio()
1466 dev_err(&btt->nd_btt->dev, in btt_submit_bio()
1471 bio->bi_status = errno_to_blk_status(err); in btt_submit_bio()
1484 geo->heads = 1 << 6; in btt_getgeo()
1485 geo->sectors = 1 << 5; in btt_getgeo()
1486 geo->cylinders = get_capacity(bd->bd_disk) >> 11; in btt_getgeo()
1498 struct nd_btt *nd_btt = btt->nd_btt; in btt_blk_init()
1499 struct nd_namespace_common *ndns = nd_btt->ndns; in btt_blk_init()
1501 .logical_block_size = btt->sector_size, in btt_blk_init()
1513 btt->btt_disk = blk_alloc_disk(&lim, NUMA_NO_NODE); in btt_blk_init()
1514 if (IS_ERR(btt->btt_disk)) in btt_blk_init()
1515 return PTR_ERR(btt->btt_disk); in btt_blk_init()
1517 nvdimm_namespace_disk_name(ndns, btt->btt_disk->disk_name); in btt_blk_init()
1518 btt->btt_disk->first_minor = 0; in btt_blk_init()
1519 btt->btt_disk->fops = &btt_fops; in btt_blk_init()
1520 btt->btt_disk->private_data = btt; in btt_blk_init()
1522 set_capacity(btt->btt_disk, btt->nlba * btt->sector_size >> 9); in btt_blk_init()
1523 rc = device_add_disk(&btt->nd_btt->dev, btt->btt_disk, NULL); in btt_blk_init()
1527 btt->nd_btt->size = btt->nlba * (u64)btt->sector_size; in btt_blk_init()
1528 nvdimm_check_and_set_ro(btt->btt_disk); in btt_blk_init()
1533 put_disk(btt->btt_disk); in btt_blk_init()
1539 del_gendisk(btt->btt_disk); in btt_blk_cleanup()
1540 put_disk(btt->btt_disk); in btt_blk_cleanup()
1544 * btt_init - initialize a block translation table for the given device
1548 * @uuid: A uuid for the backing device - this is stored on media
1567 struct device *dev = &nd_btt->dev; in btt_init()
1573 btt->nd_btt = nd_btt; in btt_init()
1574 btt->rawsize = rawsize; in btt_init()
1575 btt->lbasize = lbasize; in btt_init()
1576 btt->sector_size = ((lbasize >= 4096) ? 4096 : 512); in btt_init()
1577 INIT_LIST_HEAD(&btt->arena_list); in btt_init()
1578 mutex_init(&btt->init_lock); in btt_init()
1579 btt->nd_region = nd_region; in btt_init()
1580 nsio = to_nd_namespace_io(&nd_btt->ndns->dev); in btt_init()
1581 btt->phys_bb = &nsio->bb; in btt_init()
1589 if (btt->init_state != INIT_READY && nd_region->ro) { in btt_init()
1590 dev_warn(dev, "%s is read-only, unable to init btt metadata\n", in btt_init()
1591 dev_name(&nd_region->dev)); in btt_init()
1593 } else if (btt->init_state != INIT_READY) { in btt_init()
1594 btt->num_arenas = (rawsize / ARENA_MAX_SIZE) + in btt_init()
1597 btt->num_arenas, rawsize); in btt_init()
1624 * btt_fini - de-initialize a BTT
1627 * De-initialize a Block Translation Table on device removal
1637 debugfs_remove_recursive(btt->debugfs_dir); in btt_fini()
1643 struct nd_btt *nd_btt = to_nd_btt(ndns->claim); in nvdimm_namespace_attach_btt()
1650 if (!nd_btt->uuid || !nd_btt->ndns || !nd_btt->lbasize) { in nvdimm_namespace_attach_btt()
1651 dev_dbg(&nd_btt->dev, "incomplete btt configuration\n"); in nvdimm_namespace_attach_btt()
1652 return -ENODEV; in nvdimm_namespace_attach_btt()
1655 btt_sb = devm_kzalloc(&nd_btt->dev, sizeof(*btt_sb), GFP_KERNEL); in nvdimm_namespace_attach_btt()
1657 return -ENOMEM; in nvdimm_namespace_attach_btt()
1660 rc = devm_namespace_enable(&nd_btt->dev, ndns, size); in nvdimm_namespace_attach_btt()
1668 * set correctly based on the holder class in nvdimm_namespace_attach_btt()
1672 rawsize = size - nd_btt->initial_offset; in nvdimm_namespace_attach_btt()
1674 dev_dbg(&nd_btt->dev, "%s must be at least %ld bytes\n", in nvdimm_namespace_attach_btt()
1675 dev_name(&ndns->dev), in nvdimm_namespace_attach_btt()
1676 ARENA_MIN_SIZE + nd_btt->initial_offset); in nvdimm_namespace_attach_btt()
1677 return -ENXIO; in nvdimm_namespace_attach_btt()
1679 nd_region = to_nd_region(nd_btt->dev.parent); in nvdimm_namespace_attach_btt()
1680 btt = btt_init(nd_btt, rawsize, nd_btt->lbasize, nd_btt->uuid, in nvdimm_namespace_attach_btt()
1683 return -ENOMEM; in nvdimm_namespace_attach_btt()
1684 nd_btt->btt = btt; in nvdimm_namespace_attach_btt()
1692 struct btt *btt = nd_btt->btt; in nvdimm_namespace_detach_btt()
1695 nd_btt->btt = NULL; in nvdimm_namespace_detach_btt()
1707 rc = -ENXIO; in nd_btt_init()