0001
0002
0003
0004
0005
0006
0007 #ifndef DM_BTREE_INTERNAL_H
0008 #define DM_BTREE_INTERNAL_H
0009
0010 #include "dm-btree.h"
0011
0012
0013
0014
0015
0016
0017
0018
0019 enum node_flags {
0020 INTERNAL_NODE = 1,
0021 LEAF_NODE = 1 << 1
0022 };
0023
0024
0025
0026
0027
0028 struct node_header {
0029 __le32 csum;
0030 __le32 flags;
0031 __le64 blocknr;
0032
0033 __le32 nr_entries;
0034 __le32 max_entries;
0035 __le32 value_size;
0036 __le32 padding;
0037 } __attribute__((packed, aligned(8)));
0038
0039 struct btree_node {
0040 struct node_header header;
0041 __le64 keys[];
0042 } __attribute__((packed, aligned(8)));
0043
0044
0045
0046
0047
0048 int bn_read_lock(struct dm_btree_info *info, dm_block_t b,
0049 struct dm_block **result);
0050
0051 void inc_children(struct dm_transaction_manager *tm, struct btree_node *n,
0052 struct dm_btree_value_type *vt);
0053
0054 int new_block(struct dm_btree_info *info, struct dm_block **result);
0055 void unlock_block(struct dm_btree_info *info, struct dm_block *b);
0056
0057
0058
0059
0060
0061
0062
0063 struct ro_spine {
0064 struct dm_btree_info *info;
0065
0066 int count;
0067 struct dm_block *nodes[2];
0068 };
0069
0070 void init_ro_spine(struct ro_spine *s, struct dm_btree_info *info);
0071 void exit_ro_spine(struct ro_spine *s);
0072 int ro_step(struct ro_spine *s, dm_block_t new_child);
0073 void ro_pop(struct ro_spine *s);
0074 struct btree_node *ro_node(struct ro_spine *s);
0075
0076 struct shadow_spine {
0077 struct dm_btree_info *info;
0078
0079 int count;
0080 struct dm_block *nodes[2];
0081
0082 dm_block_t root;
0083 };
0084
0085 void init_shadow_spine(struct shadow_spine *s, struct dm_btree_info *info);
0086 void exit_shadow_spine(struct shadow_spine *s);
0087
0088 int shadow_step(struct shadow_spine *s, dm_block_t b,
0089 struct dm_btree_value_type *vt);
0090
0091
0092
0093
0094 struct dm_block *shadow_current(struct shadow_spine *s);
0095
0096
0097
0098
0099 struct dm_block *shadow_parent(struct shadow_spine *s);
0100
0101 int shadow_has_parent(struct shadow_spine *s);
0102
0103 dm_block_t shadow_root(struct shadow_spine *s);
0104
0105
0106
0107
0108 static inline __le64 *key_ptr(struct btree_node *n, uint32_t index)
0109 {
0110 return n->keys + index;
0111 }
0112
0113 static inline void *value_base(struct btree_node *n)
0114 {
0115 return &n->keys[le32_to_cpu(n->header.max_entries)];
0116 }
0117
0118 static inline void *value_ptr(struct btree_node *n, uint32_t index)
0119 {
0120 uint32_t value_size = le32_to_cpu(n->header.value_size);
0121 return value_base(n) + (value_size * index);
0122 }
0123
0124
0125
0126
0127 static inline uint64_t value64(struct btree_node *n, uint32_t index)
0128 {
0129 __le64 *values_le = value_base(n);
0130
0131 return le64_to_cpu(values_le[index]);
0132 }
0133
0134
0135
0136
0137 int lower_bound(struct btree_node *n, uint64_t key);
0138
0139 extern struct dm_block_validator btree_node_validator;
0140
0141
0142
0143
0144 extern void init_le64_type(struct dm_transaction_manager *tm,
0145 struct dm_btree_value_type *vt);
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156 int btree_get_overwrite_leaf(struct dm_btree_info *info, dm_block_t root,
0157 uint64_t key, int *index,
0158 dm_block_t *new_root, struct dm_block **leaf);
0159
0160 #endif