btt.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * Block Translation Table library
  3. * Copyright (c) 2014-2015, Intel Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. */
  14. #ifndef _LINUX_BTT_H
  15. #define _LINUX_BTT_H
  16. #include <linux/types.h>
  17. #define BTT_SIG_LEN 16
  18. #define BTT_SIG "BTT_ARENA_INFO\0"
  19. #define MAP_ENT_SIZE 4
  20. #define MAP_TRIM_SHIFT 31
  21. #define MAP_TRIM_MASK (1 << MAP_TRIM_SHIFT)
  22. #define MAP_ERR_SHIFT 30
  23. #define MAP_ERR_MASK (1 << MAP_ERR_SHIFT)
  24. #define MAP_LBA_MASK (~((1 << MAP_TRIM_SHIFT) | (1 << MAP_ERR_SHIFT)))
  25. #define MAP_ENT_NORMAL 0xC0000000
  26. #define LOG_ENT_SIZE sizeof(struct log_entry)
  27. #define ARENA_MIN_SIZE (1UL << 24) /* 16 MB */
  28. #define ARENA_MAX_SIZE (1ULL << 39) /* 512 GB */
  29. #define RTT_VALID (1UL << 31)
  30. #define RTT_INVALID 0
  31. #define BTT_PG_SIZE 4096
  32. #define BTT_DEFAULT_NFREE ND_MAX_LANES
  33. #define LOG_SEQ_INIT 1
  34. #define IB_FLAG_ERROR 0x00000001
  35. #define IB_FLAG_ERROR_MASK 0x00000001
  36. enum btt_init_state {
  37. INIT_UNCHECKED = 0,
  38. INIT_NOTFOUND,
  39. INIT_READY
  40. };
  41. struct log_entry {
  42. __le32 lba;
  43. __le32 old_map;
  44. __le32 new_map;
  45. __le32 seq;
  46. __le64 padding[2];
  47. };
  48. struct btt_sb {
  49. u8 signature[BTT_SIG_LEN];
  50. u8 uuid[16];
  51. u8 parent_uuid[16];
  52. __le32 flags;
  53. __le16 version_major;
  54. __le16 version_minor;
  55. __le32 external_lbasize;
  56. __le32 external_nlba;
  57. __le32 internal_lbasize;
  58. __le32 internal_nlba;
  59. __le32 nfree;
  60. __le32 infosize;
  61. __le64 nextoff;
  62. __le64 dataoff;
  63. __le64 mapoff;
  64. __le64 logoff;
  65. __le64 info2off;
  66. u8 padding[3968];
  67. __le64 checksum;
  68. };
  69. struct free_entry {
  70. u32 block;
  71. u8 sub;
  72. u8 seq;
  73. };
  74. struct aligned_lock {
  75. union {
  76. spinlock_t lock;
  77. u8 cacheline_padding[L1_CACHE_BYTES];
  78. };
  79. };
  80. /**
  81. * struct arena_info - handle for an arena
  82. * @size: Size in bytes this arena occupies on the raw device.
  83. * This includes arena metadata.
  84. * @external_lba_start: The first external LBA in this arena.
  85. * @internal_nlba: Number of internal blocks available in the arena
  86. * including nfree reserved blocks
  87. * @internal_lbasize: Internal and external lba sizes may be different as
  88. * we can round up 'odd' external lbasizes such as 520B
  89. * to be aligned.
  90. * @external_nlba: Number of blocks contributed by the arena to the number
  91. * reported to upper layers. (internal_nlba - nfree)
  92. * @external_lbasize: LBA size as exposed to upper layers.
  93. * @nfree: A reserve number of 'free' blocks that is used to
  94. * handle incoming writes.
  95. * @version_major: Metadata layout version major.
  96. * @version_minor: Metadata layout version minor.
  97. * @nextoff: Offset in bytes to the start of the next arena.
  98. * @infooff: Offset in bytes to the info block of this arena.
  99. * @dataoff: Offset in bytes to the data area of this arena.
  100. * @mapoff: Offset in bytes to the map area of this arena.
  101. * @logoff: Offset in bytes to the log area of this arena.
  102. * @info2off: Offset in bytes to the backup info block of this arena.
  103. * @freelist: Pointer to in-memory list of free blocks
  104. * @rtt: Pointer to in-memory "Read Tracking Table"
  105. * @map_locks: Spinlocks protecting concurrent map writes
  106. * @nd_btt: Pointer to parent nd_btt structure.
  107. * @list: List head for list of arenas
  108. * @debugfs_dir: Debugfs dentry
  109. * @flags: Arena flags - may signify error states.
  110. *
  111. * arena_info is a per-arena handle. Once an arena is narrowed down for an
  112. * IO, this struct is passed around for the duration of the IO.
  113. */
  114. struct arena_info {
  115. u64 size; /* Total bytes for this arena */
  116. u64 external_lba_start;
  117. u32 internal_nlba;
  118. u32 internal_lbasize;
  119. u32 external_nlba;
  120. u32 external_lbasize;
  121. u32 nfree;
  122. u16 version_major;
  123. u16 version_minor;
  124. /* Byte offsets to the different on-media structures */
  125. u64 nextoff;
  126. u64 infooff;
  127. u64 dataoff;
  128. u64 mapoff;
  129. u64 logoff;
  130. u64 info2off;
  131. /* Pointers to other in-memory structures for this arena */
  132. struct free_entry *freelist;
  133. u32 *rtt;
  134. struct aligned_lock *map_locks;
  135. struct nd_btt *nd_btt;
  136. struct list_head list;
  137. struct dentry *debugfs_dir;
  138. /* Arena flags */
  139. u32 flags;
  140. };
  141. /**
  142. * struct btt - handle for a BTT instance
  143. * @btt_disk: Pointer to the gendisk for BTT device
  144. * @btt_queue: Pointer to the request queue for the BTT device
  145. * @arena_list: Head of the list of arenas
  146. * @debugfs_dir: Debugfs dentry
  147. * @nd_btt: Parent nd_btt struct
  148. * @nlba: Number of logical blocks exposed to the upper layers
  149. * after removing the amount of space needed by metadata
  150. * @rawsize: Total size in bytes of the available backing device
  151. * @lbasize: LBA size as requested and presented to upper layers.
  152. * This is sector_size + size of any metadata.
  153. * @sector_size: The Linux sector size - 512 or 4096
  154. * @lanes: Per-lane spinlocks
  155. * @init_lock: Mutex used for the BTT initialization
  156. * @init_state: Flag describing the initialization state for the BTT
  157. * @num_arenas: Number of arenas in the BTT instance
  158. */
  159. struct btt {
  160. struct gendisk *btt_disk;
  161. struct request_queue *btt_queue;
  162. struct list_head arena_list;
  163. struct dentry *debugfs_dir;
  164. struct nd_btt *nd_btt;
  165. u64 nlba;
  166. unsigned long long rawsize;
  167. u32 lbasize;
  168. u32 sector_size;
  169. struct nd_region *nd_region;
  170. struct mutex init_lock;
  171. int init_state;
  172. int num_arenas;
  173. };
  174. bool nd_btt_arena_is_valid(struct nd_btt *nd_btt, struct btt_sb *super);
  175. #endif