alloc_background.c (83f33d686553c5105ff36da4dd554c34125094e9) | alloc_background.c (facafdcbc157686311dbe58649ef9d29fcf8e610) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2#include "bcachefs.h" 3#include "alloc_background.h" 4#include "alloc_foreground.h" 5#include "backpointers.h" 6#include "btree_cache.h" 7#include "btree_io.h" 8#include "btree_key_cache.h" --- 208 unchanged lines hidden (view full) --- 217 for (i = 0; i < ARRAY_SIZE(BCH_ALLOC_V1_FIELD_BYTES); i++) 218 if (a->fields & (1 << i)) 219 bytes += BCH_ALLOC_V1_FIELD_BYTES[i]; 220 221 return DIV_ROUND_UP(bytes, sizeof(u64)); 222} 223 224int bch2_alloc_v1_invalid(const struct bch_fs *c, struct bkey_s_c k, | 1// SPDX-License-Identifier: GPL-2.0 2#include "bcachefs.h" 3#include "alloc_background.h" 4#include "alloc_foreground.h" 5#include "backpointers.h" 6#include "btree_cache.h" 7#include "btree_io.h" 8#include "btree_key_cache.h" --- 208 unchanged lines hidden (view full) --- 217 for (i = 0; i < ARRAY_SIZE(BCH_ALLOC_V1_FIELD_BYTES); i++) 218 if (a->fields & (1 << i)) 219 bytes += BCH_ALLOC_V1_FIELD_BYTES[i]; 220 221 return DIV_ROUND_UP(bytes, sizeof(u64)); 222} 223 224int bch2_alloc_v1_invalid(const struct bch_fs *c, struct bkey_s_c k, |
225 int rw, struct printbuf *err) | 225 unsigned flags, struct printbuf *err) |
226{ 227 struct bkey_s_c_alloc a = bkey_s_c_to_alloc(k); 228 229 /* allow for unknown fields */ 230 if (bkey_val_u64s(a.k) < bch_alloc_v1_val_u64s(a.v)) { 231 prt_printf(err, "incorrect value size (%zu < %u)", 232 bkey_val_u64s(a.k), bch_alloc_v1_val_u64s(a.v)); 233 return -BCH_ERR_invalid_bkey; 234 } 235 236 return 0; 237} 238 239int bch2_alloc_v2_invalid(const struct bch_fs *c, struct bkey_s_c k, | 226{ 227 struct bkey_s_c_alloc a = bkey_s_c_to_alloc(k); 228 229 /* allow for unknown fields */ 230 if (bkey_val_u64s(a.k) < bch_alloc_v1_val_u64s(a.v)) { 231 prt_printf(err, "incorrect value size (%zu < %u)", 232 bkey_val_u64s(a.k), bch_alloc_v1_val_u64s(a.v)); 233 return -BCH_ERR_invalid_bkey; 234 } 235 236 return 0; 237} 238 239int bch2_alloc_v2_invalid(const struct bch_fs *c, struct bkey_s_c k, |
240 int rw, struct printbuf *err) | 240 unsigned flags, struct printbuf *err) |
241{ 242 struct bkey_alloc_unpacked u; 243 244 if (bch2_alloc_unpack_v2(&u, k)) { 245 prt_printf(err, "unpack error"); 246 return -BCH_ERR_invalid_bkey; 247 } 248 249 return 0; 250} 251 252int bch2_alloc_v3_invalid(const struct bch_fs *c, struct bkey_s_c k, | 241{ 242 struct bkey_alloc_unpacked u; 243 244 if (bch2_alloc_unpack_v2(&u, k)) { 245 prt_printf(err, "unpack error"); 246 return -BCH_ERR_invalid_bkey; 247 } 248 249 return 0; 250} 251 252int bch2_alloc_v3_invalid(const struct bch_fs *c, struct bkey_s_c k, |
253 int rw, struct printbuf *err) | 253 unsigned flags, struct printbuf *err) |
254{ 255 struct bkey_alloc_unpacked u; 256 257 if (bch2_alloc_unpack_v3(&u, k)) { 258 prt_printf(err, "unpack error"); 259 return -BCH_ERR_invalid_bkey; 260 } 261 262 return 0; 263} 264 265int bch2_alloc_v4_invalid(const struct bch_fs *c, struct bkey_s_c k, | 254{ 255 struct bkey_alloc_unpacked u; 256 257 if (bch2_alloc_unpack_v3(&u, k)) { 258 prt_printf(err, "unpack error"); 259 return -BCH_ERR_invalid_bkey; 260 } 261 262 return 0; 263} 264 265int bch2_alloc_v4_invalid(const struct bch_fs *c, struct bkey_s_c k, |
266 int rw, struct printbuf *err) | 266 unsigned flags, struct printbuf *err) |
267{ 268 struct bkey_s_c_alloc_v4 a = bkey_s_c_to_alloc_v4(k); | 267{ 268 struct bkey_s_c_alloc_v4 a = bkey_s_c_to_alloc_v4(k); |
269 int rw = flags & WRITE; |
|
269 270 if (alloc_v4_u64s(a.v) != bkey_val_u64s(k.k)) { 271 prt_printf(err, "bad val size (%lu != %u)", 272 bkey_val_u64s(k.k), alloc_v4_u64s(a.v)); 273 return -BCH_ERR_invalid_bkey; 274 } 275 276 if (!BCH_ALLOC_V4_BACKPOINTERS_START(a.v) && --- 338 unchanged lines hidden (view full) --- 615static unsigned alloc_gen(struct bkey_s_c k, unsigned offset) 616{ 617 return k.k->type == KEY_TYPE_bucket_gens 618 ? bkey_s_c_to_bucket_gens(k).v->gens[offset] 619 : 0; 620} 621 622int bch2_bucket_gens_invalid(const struct bch_fs *c, struct bkey_s_c k, | 270 271 if (alloc_v4_u64s(a.v) != bkey_val_u64s(k.k)) { 272 prt_printf(err, "bad val size (%lu != %u)", 273 bkey_val_u64s(k.k), alloc_v4_u64s(a.v)); 274 return -BCH_ERR_invalid_bkey; 275 } 276 277 if (!BCH_ALLOC_V4_BACKPOINTERS_START(a.v) && --- 338 unchanged lines hidden (view full) --- 616static unsigned alloc_gen(struct bkey_s_c k, unsigned offset) 617{ 618 return k.k->type == KEY_TYPE_bucket_gens 619 ? bkey_s_c_to_bucket_gens(k).v->gens[offset] 620 : 0; 621} 622 623int bch2_bucket_gens_invalid(const struct bch_fs *c, struct bkey_s_c k, |
623 int rw, struct printbuf *err) | 624 unsigned flags, struct printbuf *err) |
624{ 625 if (bkey_val_bytes(k.k) != sizeof(struct bch_bucket_gens)) { 626 prt_printf(err, "bad val size (%lu != %zu)", 627 bkey_val_bytes(k.k), sizeof(struct bch_bucket_gens)); 628 return -BCH_ERR_invalid_bkey; 629 } 630 631 return 0; --- 1562 unchanged lines hidden --- | 625{ 626 if (bkey_val_bytes(k.k) != sizeof(struct bch_bucket_gens)) { 627 prt_printf(err, "bad val size (%lu != %zu)", 628 bkey_val_bytes(k.k), sizeof(struct bch_bucket_gens)); 629 return -BCH_ERR_invalid_bkey; 630 } 631 632 return 0; --- 1562 unchanged lines hidden --- |