bkey_methods.c (83f33d686553c5105ff36da4dd554c34125094e9) | bkey_methods.c (facafdcbc157686311dbe58649ef9d29fcf8e610) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2 3#include "bcachefs.h" 4#include "backpointers.h" 5#include "bkey_methods.h" 6#include "btree_types.h" 7#include "alloc_background.h" 8#include "dirent.h" --- 10 unchanged lines hidden (view full) --- 19const char * const bch2_bkey_types[] = { 20#define x(name, nr) #name, 21 BCH_BKEY_TYPES() 22#undef x 23 NULL 24}; 25 26static int deleted_key_invalid(const struct bch_fs *c, struct bkey_s_c k, | 1// SPDX-License-Identifier: GPL-2.0 2 3#include "bcachefs.h" 4#include "backpointers.h" 5#include "bkey_methods.h" 6#include "btree_types.h" 7#include "alloc_background.h" 8#include "dirent.h" --- 10 unchanged lines hidden (view full) --- 19const char * const bch2_bkey_types[] = { 20#define x(name, nr) #name, 21 BCH_BKEY_TYPES() 22#undef x 23 NULL 24}; 25 26static int deleted_key_invalid(const struct bch_fs *c, struct bkey_s_c k, |
27 int rw, struct printbuf *err) | 27 unsigned flags, struct printbuf *err) |
28{ 29 return 0; 30} 31 32#define bch2_bkey_ops_deleted ((struct bkey_ops) { \ 33 .key_invalid = deleted_key_invalid, \ 34}) 35 36#define bch2_bkey_ops_whiteout ((struct bkey_ops) { \ 37 .key_invalid = deleted_key_invalid, \ 38}) 39 40static int empty_val_key_invalid(const struct bch_fs *c, struct bkey_s_c k, | 28{ 29 return 0; 30} 31 32#define bch2_bkey_ops_deleted ((struct bkey_ops) { \ 33 .key_invalid = deleted_key_invalid, \ 34}) 35 36#define bch2_bkey_ops_whiteout ((struct bkey_ops) { \ 37 .key_invalid = deleted_key_invalid, \ 38}) 39 40static int empty_val_key_invalid(const struct bch_fs *c, struct bkey_s_c k, |
41 int rw, struct printbuf *err) | 41 unsigned flags, struct printbuf *err) |
42{ 43 if (bkey_val_bytes(k.k)) { 44 prt_printf(err, "incorrect value size (%zu != 0)", 45 bkey_val_bytes(k.k)); 46 return -BCH_ERR_invalid_bkey; 47 } 48 49 return 0; 50} 51 52#define bch2_bkey_ops_error ((struct bkey_ops) { \ 53 .key_invalid = empty_val_key_invalid, \ 54}) 55 56static int key_type_cookie_invalid(const struct bch_fs *c, struct bkey_s_c k, | 42{ 43 if (bkey_val_bytes(k.k)) { 44 prt_printf(err, "incorrect value size (%zu != 0)", 45 bkey_val_bytes(k.k)); 46 return -BCH_ERR_invalid_bkey; 47 } 48 49 return 0; 50} 51 52#define bch2_bkey_ops_error ((struct bkey_ops) { \ 53 .key_invalid = empty_val_key_invalid, \ 54}) 55 56static int key_type_cookie_invalid(const struct bch_fs *c, struct bkey_s_c k, |
57 int rw, struct printbuf *err) | 57 unsigned flags, struct printbuf *err) |
58{ 59 if (bkey_val_bytes(k.k) != sizeof(struct bch_cookie)) { 60 prt_printf(err, "incorrect value size (%zu != %zu)", 61 bkey_val_bytes(k.k), sizeof(struct bch_cookie)); 62 return -BCH_ERR_invalid_bkey; 63 } 64 65 return 0; 66} 67 68#define bch2_bkey_ops_cookie ((struct bkey_ops) { \ 69 .key_invalid = key_type_cookie_invalid, \ 70}) 71 72#define bch2_bkey_ops_hash_whiteout ((struct bkey_ops) {\ 73 .key_invalid = empty_val_key_invalid, \ 74}) 75 76static int key_type_inline_data_invalid(const struct bch_fs *c, struct bkey_s_c k, | 58{ 59 if (bkey_val_bytes(k.k) != sizeof(struct bch_cookie)) { 60 prt_printf(err, "incorrect value size (%zu != %zu)", 61 bkey_val_bytes(k.k), sizeof(struct bch_cookie)); 62 return -BCH_ERR_invalid_bkey; 63 } 64 65 return 0; 66} 67 68#define bch2_bkey_ops_cookie ((struct bkey_ops) { \ 69 .key_invalid = key_type_cookie_invalid, \ 70}) 71 72#define bch2_bkey_ops_hash_whiteout ((struct bkey_ops) {\ 73 .key_invalid = empty_val_key_invalid, \ 74}) 75 76static int key_type_inline_data_invalid(const struct bch_fs *c, struct bkey_s_c k, |
77 int rw, struct printbuf *err) | 77 unsigned flags, struct printbuf *err) |
78{ 79 return 0; 80} 81 82static void key_type_inline_data_to_text(struct printbuf *out, struct bch_fs *c, 83 struct bkey_s_c k) 84{ 85 struct bkey_s_c_inline_data d = bkey_s_c_to_inline_data(k); --- 4 unchanged lines hidden (view full) --- 90} 91 92#define bch2_bkey_ops_inline_data ((struct bkey_ops) { \ 93 .key_invalid = key_type_inline_data_invalid, \ 94 .val_to_text = key_type_inline_data_to_text, \ 95}) 96 97static int key_type_set_invalid(const struct bch_fs *c, struct bkey_s_c k, | 78{ 79 return 0; 80} 81 82static void key_type_inline_data_to_text(struct printbuf *out, struct bch_fs *c, 83 struct bkey_s_c k) 84{ 85 struct bkey_s_c_inline_data d = bkey_s_c_to_inline_data(k); --- 4 unchanged lines hidden (view full) --- 90} 91 92#define bch2_bkey_ops_inline_data ((struct bkey_ops) { \ 93 .key_invalid = key_type_inline_data_invalid, \ 94 .val_to_text = key_type_inline_data_to_text, \ 95}) 96 97static int key_type_set_invalid(const struct bch_fs *c, struct bkey_s_c k, |
98 int rw, struct printbuf *err) | 98 unsigned flags, struct printbuf *err) |
99{ 100 if (bkey_val_bytes(k.k)) { 101 prt_printf(err, "incorrect value size (%zu != %zu)", 102 bkey_val_bytes(k.k), sizeof(struct bch_cookie)); 103 return -BCH_ERR_invalid_bkey; 104 } 105 106 return 0; --- 12 unchanged lines hidden (view full) --- 119 120const struct bkey_ops bch2_bkey_ops[] = { 121#define x(name, nr) [KEY_TYPE_##name] = bch2_bkey_ops_##name, 122 BCH_BKEY_TYPES() 123#undef x 124}; 125 126int bch2_bkey_val_invalid(struct bch_fs *c, struct bkey_s_c k, | 99{ 100 if (bkey_val_bytes(k.k)) { 101 prt_printf(err, "incorrect value size (%zu != %zu)", 102 bkey_val_bytes(k.k), sizeof(struct bch_cookie)); 103 return -BCH_ERR_invalid_bkey; 104 } 105 106 return 0; --- 12 unchanged lines hidden (view full) --- 119 120const struct bkey_ops bch2_bkey_ops[] = { 121#define x(name, nr) [KEY_TYPE_##name] = bch2_bkey_ops_##name, 122 BCH_BKEY_TYPES() 123#undef x 124}; 125 126int bch2_bkey_val_invalid(struct bch_fs *c, struct bkey_s_c k, |
127 int rw, struct printbuf *err) | 127 unsigned flags, struct printbuf *err) |
128{ 129 if (k.k->type >= KEY_TYPE_MAX) { 130 prt_printf(err, "invalid type (%u >= %u)", k.k->type, KEY_TYPE_MAX); 131 return -BCH_ERR_invalid_bkey; 132 } 133 | 128{ 129 if (k.k->type >= KEY_TYPE_MAX) { 130 prt_printf(err, "invalid type (%u >= %u)", k.k->type, KEY_TYPE_MAX); 131 return -BCH_ERR_invalid_bkey; 132 } 133 |
134 return bch2_bkey_ops[k.k->type].key_invalid(c, k, rw, err); | 134 return bch2_bkey_ops[k.k->type].key_invalid(c, k, flags, err); |
135} 136 137static unsigned bch2_key_types_allowed[] = { 138 [BKEY_TYPE_extents] = 139 (1U << KEY_TYPE_deleted)| 140 (1U << KEY_TYPE_whiteout)| 141 (1U << KEY_TYPE_error)| 142 (1U << KEY_TYPE_cookie)| --- 59 unchanged lines hidden (view full) --- 202 [BKEY_TYPE_btree] = 203 (1U << KEY_TYPE_deleted)| 204 (1U << KEY_TYPE_btree_ptr)| 205 (1U << KEY_TYPE_btree_ptr_v2), 206}; 207 208int __bch2_bkey_invalid(struct bch_fs *c, struct bkey_s_c k, 209 enum btree_node_type type, | 135} 136 137static unsigned bch2_key_types_allowed[] = { 138 [BKEY_TYPE_extents] = 139 (1U << KEY_TYPE_deleted)| 140 (1U << KEY_TYPE_whiteout)| 141 (1U << KEY_TYPE_error)| 142 (1U << KEY_TYPE_cookie)| --- 59 unchanged lines hidden (view full) --- 202 [BKEY_TYPE_btree] = 203 (1U << KEY_TYPE_deleted)| 204 (1U << KEY_TYPE_btree_ptr)| 205 (1U << KEY_TYPE_btree_ptr_v2), 206}; 207 208int __bch2_bkey_invalid(struct bch_fs *c, struct bkey_s_c k, 209 enum btree_node_type type, |
210 int rw, struct printbuf *err) | 210 unsigned flags, struct printbuf *err) |
211{ 212 if (k.k->u64s < BKEY_U64s) { 213 prt_printf(err, "u64s too small (%u < %zu)", k.k->u64s, BKEY_U64s); 214 return -BCH_ERR_invalid_bkey; 215 } 216 217 if (!(bch2_key_types_allowed[type] & (1U << k.k->type))) { 218 prt_printf(err, "invalid key type for btree %s (%s)", --- 39 unchanged lines hidden (view full) --- 258 return -BCH_ERR_invalid_bkey; 259 } 260 261 return 0; 262} 263 264int bch2_bkey_invalid(struct bch_fs *c, struct bkey_s_c k, 265 enum btree_node_type type, | 211{ 212 if (k.k->u64s < BKEY_U64s) { 213 prt_printf(err, "u64s too small (%u < %zu)", k.k->u64s, BKEY_U64s); 214 return -BCH_ERR_invalid_bkey; 215 } 216 217 if (!(bch2_key_types_allowed[type] & (1U << k.k->type))) { 218 prt_printf(err, "invalid key type for btree %s (%s)", --- 39 unchanged lines hidden (view full) --- 258 return -BCH_ERR_invalid_bkey; 259 } 260 261 return 0; 262} 263 264int bch2_bkey_invalid(struct bch_fs *c, struct bkey_s_c k, 265 enum btree_node_type type, |
266 int rw, struct printbuf *err) | 266 unsigned flags, struct printbuf *err) |
267{ | 267{ |
268 return __bch2_bkey_invalid(c, k, type, rw, err) ?: 269 bch2_bkey_val_invalid(c, k, rw, err); | 268 return __bch2_bkey_invalid(c, k, type, flags, err) ?: 269 bch2_bkey_val_invalid(c, k, flags, err); |
270} 271 272int bch2_bkey_in_btree_node(struct btree *b, struct bkey_s_c k, 273 struct printbuf *err) 274{ 275 if (bpos_lt(k.k->p, b->data->min_key)) { 276 prt_printf(err, "key before start of btree node"); 277 return -BCH_ERR_invalid_bkey; --- 235 unchanged lines hidden --- | 270} 271 272int bch2_bkey_in_btree_node(struct btree *b, struct bkey_s_c k, 273 struct printbuf *err) 274{ 275 if (bpos_lt(k.k->p, b->data->min_key)) { 276 prt_printf(err, "key before start of btree node"); 277 return -BCH_ERR_invalid_bkey; --- 235 unchanged lines hidden --- |