/* SPDX-License-Identifier: GPL-2.0-only */ /* * Block Translation Table library * Copyright (c) 2014-2015, Intel Corporation. */ #ifndef _LINUX_BTT_H #define _LINUX_BTT_H #include <linux/types.h> #define BTT_SIG_LEN … #define BTT_SIG … #define MAP_ENT_SIZE … #define MAP_TRIM_SHIFT … #define MAP_TRIM_MASK … #define MAP_ERR_SHIFT … #define MAP_ERR_MASK … #define MAP_LBA_MASK … #define MAP_ENT_NORMAL … #define LOG_GRP_SIZE … #define LOG_ENT_SIZE … #define ARENA_MIN_SIZE … #define ARENA_MAX_SIZE … #define RTT_VALID … #define RTT_INVALID … #define BTT_PG_SIZE … #define BTT_DEFAULT_NFREE … #define LOG_SEQ_INIT … #define IB_FLAG_ERROR … #define IB_FLAG_ERROR_MASK … #define ent_lba(ent) … #define ent_e_flag(ent) … #define ent_z_flag(ent) … #define set_e_flag(ent) … /* 'normal' is both e and z flags set */ #define ent_normal(ent) … enum btt_init_state { … }; /* * A log group represents one log 'lane', and consists of four log entries. * Two of the four entries are valid entries, and the remaining two are * padding. Due to an old bug in the padding location, we need to perform a * test to determine the padding scheme being used, and use that scheme * thereafter. * * In kernels prior to 4.15, 'log group' would have actual log entries at * indices (0, 2) and padding at indices (1, 3), where as the correct/updated * format has log entries at indices (0, 1) and padding at indices (2, 3). * * Old (pre 4.15) format: * +-----------------+-----------------+ * | ent[0] | ent[1] | * | 16B | 16B | * | lba/old/new/seq | pad | * +-----------------------------------+ * | ent[2] | ent[3] | * | 16B | 16B | * | lba/old/new/seq | pad | * +-----------------+-----------------+ * * New format: * +-----------------+-----------------+ * | ent[0] | ent[1] | * | 16B | 16B | * | lba/old/new/seq | lba/old/new/seq | * +-----------------------------------+ * | ent[2] | ent[3] | * | 16B | 16B | * | pad | pad | * +-----------------+-----------------+ * * We detect during start-up which format is in use, and set * arena->log_index[(0, 1)] with the detected format. */ struct log_entry { … }; struct log_group { … }; struct btt_sb { … }; struct free_entry { … }; struct aligned_lock { … }; /** * struct arena_info - handle for an arena * @size: Size in bytes this arena occupies on the raw device. * This includes arena metadata. * @external_lba_start: The first external LBA in this arena. * @internal_nlba: Number of internal blocks available in the arena * including nfree reserved blocks * @internal_lbasize: Internal and external lba sizes may be different as * we can round up 'odd' external lbasizes such as 520B * to be aligned. * @external_nlba: Number of blocks contributed by the arena to the number * reported to upper layers. (internal_nlba - nfree) * @external_lbasize: LBA size as exposed to upper layers. * @nfree: A reserve number of 'free' blocks that is used to * handle incoming writes. * @version_major: Metadata layout version major. * @version_minor: Metadata layout version minor. * @sector_size: The Linux sector size - 512 or 4096 * @nextoff: Offset in bytes to the start of the next arena. * @infooff: Offset in bytes to the info block of this arena. * @dataoff: Offset in bytes to the data area of this arena. * @mapoff: Offset in bytes to the map area of this arena. * @logoff: Offset in bytes to the log area of this arena. * @info2off: Offset in bytes to the backup info block of this arena. * @freelist: Pointer to in-memory list of free blocks * @rtt: Pointer to in-memory "Read Tracking Table" * @map_locks: Spinlocks protecting concurrent map writes * @nd_btt: Pointer to parent nd_btt structure. * @list: List head for list of arenas * @debugfs_dir: Debugfs dentry * @flags: Arena flags - may signify error states. * @err_lock: Mutex for synchronizing error clearing. * @log_index: Indices of the valid log entries in a log_group * * arena_info is a per-arena handle. Once an arena is narrowed down for an * IO, this struct is passed around for the duration of the IO. */ struct arena_info { … }; struct badblocks; /** * struct btt - handle for a BTT instance * @btt_disk: Pointer to the gendisk for BTT device * @arena_list: Head of the list of arenas * @debugfs_dir: Debugfs dentry * @nd_btt: Parent nd_btt struct * @nlba: Number of logical blocks exposed to the upper layers * after removing the amount of space needed by metadata * @rawsize: Total size in bytes of the available backing device * @lbasize: LBA size as requested and presented to upper layers. * This is sector_size + size of any metadata. * @sector_size: The Linux sector size - 512 or 4096 * @lanes: Per-lane spinlocks * @init_lock: Mutex used for the BTT initialization * @init_state: Flag describing the initialization state for the BTT * @num_arenas: Number of arenas in the BTT instance * @phys_bb: Pointer to the namespace's badblocks structure */ struct btt { … }; bool nd_btt_arena_is_valid(struct nd_btt *nd_btt, struct btt_sb *super); int nd_btt_version(struct nd_btt *nd_btt, struct nd_namespace_common *ndns, struct btt_sb *btt_sb); #endif