0001
0002
0003
0004
0005
0006 #ifndef _LINUX_DM_BTREE_H
0007 #define _LINUX_DM_BTREE_H
0008
0009 #include "dm-block-manager.h"
0010
0011 struct dm_transaction_manager;
0012
0013
0014
0015
0016
0017
0018 #ifdef __CHECKER__
0019 # define __dm_written_to_disk(x) __releases(x)
0020 # define __dm_reads_from_disk(x) __acquires(x)
0021 # define __dm_bless_for_disk(x) __acquire(x)
0022 # define __dm_unbless_for_disk(x) __release(x)
0023 #else
0024 # define __dm_written_to_disk(x)
0025 # define __dm_reads_from_disk(x)
0026 # define __dm_bless_for_disk(x)
0027 # define __dm_unbless_for_disk(x)
0028 #endif
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040 struct dm_btree_value_type {
0041 void *context;
0042
0043
0044
0045
0046 uint32_t size;
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061 void (*inc)(void *context, const void *value, unsigned count);
0062
0063
0064
0065
0066
0067
0068 void (*dec)(void *context, const void *value, unsigned count);
0069
0070
0071
0072
0073
0074
0075 int (*equal)(void *context, const void *value1, const void *value2);
0076 };
0077
0078
0079
0080
0081 struct dm_btree_info {
0082 struct dm_transaction_manager *tm;
0083
0084
0085
0086
0087 unsigned levels;
0088 struct dm_btree_value_type value_type;
0089 };
0090
0091
0092
0093
0094 int dm_btree_empty(struct dm_btree_info *info, dm_block_t *root);
0095
0096
0097
0098
0099
0100 int dm_btree_del(struct dm_btree_info *info, dm_block_t root);
0101
0102
0103
0104
0105
0106
0107
0108
0109 int dm_btree_lookup(struct dm_btree_info *info, dm_block_t root,
0110 uint64_t *keys, void *value_le);
0111
0112
0113
0114
0115
0116 int dm_btree_lookup_next(struct dm_btree_info *info, dm_block_t root,
0117 uint64_t *keys, uint64_t *rkey, void *value_le);
0118
0119
0120
0121
0122 int dm_btree_insert(struct dm_btree_info *info, dm_block_t root,
0123 uint64_t *keys, void *value, dm_block_t *new_root)
0124 __dm_written_to_disk(value);
0125
0126
0127
0128
0129
0130
0131 int dm_btree_insert_notify(struct dm_btree_info *info, dm_block_t root,
0132 uint64_t *keys, void *value, dm_block_t *new_root,
0133 int *inserted)
0134 __dm_written_to_disk(value);
0135
0136
0137
0138
0139
0140
0141 int dm_btree_remove(struct dm_btree_info *info, dm_block_t root,
0142 uint64_t *keys, dm_block_t *new_root);
0143
0144
0145
0146
0147
0148
0149
0150 int dm_btree_remove_leaves(struct dm_btree_info *info, dm_block_t root,
0151 uint64_t *keys, uint64_t end_key,
0152 dm_block_t *new_root, unsigned *nr_removed);
0153
0154
0155
0156
0157
0158
0159 int dm_btree_find_lowest_key(struct dm_btree_info *info, dm_block_t root,
0160 uint64_t *result_keys);
0161
0162
0163
0164
0165
0166
0167 int dm_btree_find_highest_key(struct dm_btree_info *info, dm_block_t root,
0168 uint64_t *result_keys);
0169
0170
0171
0172
0173
0174
0175 int dm_btree_walk(struct dm_btree_info *info, dm_block_t root,
0176 int (*fn)(void *context, uint64_t *keys, void *leaf),
0177 void *context);
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187 #define DM_BTREE_CURSOR_MAX_DEPTH 16
0188
0189 struct cursor_node {
0190 struct dm_block *b;
0191 unsigned index;
0192 };
0193
0194 struct dm_btree_cursor {
0195 struct dm_btree_info *info;
0196 dm_block_t root;
0197
0198 bool prefetch_leaves;
0199 unsigned depth;
0200 struct cursor_node nodes[DM_BTREE_CURSOR_MAX_DEPTH];
0201 };
0202
0203
0204
0205
0206
0207
0208 int dm_btree_cursor_begin(struct dm_btree_info *info, dm_block_t root,
0209 bool prefetch_leaves, struct dm_btree_cursor *c);
0210 void dm_btree_cursor_end(struct dm_btree_cursor *c);
0211 int dm_btree_cursor_next(struct dm_btree_cursor *c);
0212 int dm_btree_cursor_skip(struct dm_btree_cursor *c, uint32_t count);
0213 int dm_btree_cursor_get_value(struct dm_btree_cursor *c, uint64_t *key, void *value_le);
0214
0215 #endif