diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2020-12-16 22:18:33 +0300 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-23 00:08:50 +0300 |
commit | ded54580bdf18ba3a2b38e7910c54b1c53f007c6 (patch) | |
tree | 32ccba1206735a8aa61d558f7e62fbe779033d29 | |
parent | 1d8305c11a289a13591d4c51726803cd37d8f646 (diff) | |
download | linux-ded54580bdf18ba3a2b38e7910c54b1c53f007c6.tar.xz |
bcachefs: Check for duplicate device ptrs in bch2_bkey_ptrs_invalid()
This is something we clearly should be checking for, but weren't -
oops.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r-- | fs/bcachefs/extents.c | 8 | ||||
-rw-r--r-- | fs/bcachefs/replicas.c | 5 | ||||
-rw-r--r-- | fs/bcachefs/util.h | 5 |
3 files changed, 13 insertions, 5 deletions
diff --git a/fs/bcachefs/extents.c b/fs/bcachefs/extents.c index f9838c1f36db..7cdfd09d797e 100644 --- a/fs/bcachefs/extents.c +++ b/fs/bcachefs/extents.c @@ -1045,11 +1045,13 @@ static const char *extent_ptr_invalid(const struct bch_fs *c, const char *bch2_bkey_ptrs_invalid(const struct bch_fs *c, struct bkey_s_c k) { struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); + struct bch_devs_list devs; const union bch_extent_entry *entry; struct bch_extent_crc_unpacked crc; unsigned size_ondisk = k.k->size; const char *reason; unsigned nonce = UINT_MAX; + unsigned i; if (k.k->type == KEY_TYPE_btree_ptr) size_ondisk = c->opts.btree_node_size; @@ -1100,6 +1102,12 @@ const char *bch2_bkey_ptrs_invalid(const struct bch_fs *c, struct bkey_s_c k) } } + devs = bch2_bkey_devs(k); + bubble_sort(devs.devs, devs.nr, u8_cmp); + for (i = 0; i + 1 < devs.nr; i++) + if (devs.devs[i] == devs.devs[i + 1]) + return "multiple ptrs to same device"; + return NULL; } diff --git a/fs/bcachefs/replicas.c b/fs/bcachefs/replicas.c index 85c97f67936a..57c2e66edad1 100644 --- a/fs/bcachefs/replicas.c +++ b/fs/bcachefs/replicas.c @@ -11,11 +11,6 @@ static int bch2_cpu_replicas_to_sb_replicas(struct bch_fs *, /* Replicas tracking - in memory: */ -static inline int u8_cmp(u8 l, u8 r) -{ - return cmp_int(l, r); -} - static void verify_replicas_entry(struct bch_replicas_entry *e) { #ifdef CONFIG_BCACHEFS_DEBUG diff --git a/fs/bcachefs/util.h b/fs/bcachefs/util.h index 7b7c638d8904..91aa8c0a0e09 100644 --- a/fs/bcachefs/util.h +++ b/fs/bcachefs/util.h @@ -750,4 +750,9 @@ u64 *bch2_acc_percpu_u64s(u64 __percpu *, unsigned); #define cmp_int(l, r) ((l > r) - (l < r)) +static inline int u8_cmp(u8 l, u8 r) +{ + return cmp_int(l, r); +} + #endif /* _BCACHEFS_UTIL_H */ |