diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2019-09-20 21:28:35 +0300 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-23 00:08:27 +0300 |
commit | eab32c8e4e8a3addcea0884acdb5bbe4cdb66c5a (patch) | |
tree | f9a04b86db7c4101a69c65468a20d1c2d1332b6e /fs | |
parent | 5f786787adf57c7597925a9df9897238cb3bc60e (diff) | |
download | linux-eab32c8e4e8a3addcea0884acdb5bbe4cdb66c5a.tar.xz |
bcachefs: Fix validation of replicas entries
When an extent is erasure coded, we need to record a replicas entry to
indicate that data is present on the devices that extent has pointers to
- but nr_required should be 0, because it's erasure coded.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/bcachefs/replicas.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/fs/bcachefs/replicas.c b/fs/bcachefs/replicas.c index 64024ce01665..afd226f3c8e7 100644 --- a/fs/bcachefs/replicas.c +++ b/fs/bcachefs/replicas.c @@ -16,11 +16,16 @@ static inline int u8_cmp(u8 l, u8 r) return cmp_int(l, r); } -static void verify_replicas_entry_sorted(struct bch_replicas_entry *e) +static void verify_replicas_entry(struct bch_replicas_entry *e) { -#ifdef CONFIG_BCACHES_DEBUG +#ifdef CONFIG_BCACHEFS_DEBUG unsigned i; + BUG_ON(e->data_type >= BCH_DATA_NR); + BUG_ON(!e->nr_devs); + BUG_ON(e->nr_required > 1 && + e->nr_required >= e->nr_devs); + for (i = 0; i + 1 < e->nr_devs; i++) BUG_ON(e->devs[i] >= e->devs[i + 1]); #endif @@ -158,7 +163,7 @@ cpu_replicas_add_entry(struct bch_replicas_cpu *old, }; BUG_ON(!new_entry->data_type); - verify_replicas_entry_sorted(new_entry); + verify_replicas_entry(new_entry); new.entries = kcalloc(new.nr, new.entry_size, GFP_NOIO); if (!new.entries) @@ -185,7 +190,7 @@ static inline int __replicas_entry_idx(struct bch_replicas_cpu *r, if (unlikely(entry_size > r->entry_size)) return -1; - verify_replicas_entry_sorted(search); + verify_replicas_entry(search); #define entry_cmp(_l, _r, size) memcmp(_l, _r, entry_size) idx = eytzinger0_find(r->entries, r->nr, r->entry_size, @@ -216,7 +221,7 @@ static bool bch2_replicas_marked_locked(struct bch_fs *c, if (!search->nr_devs) return true; - verify_replicas_entry_sorted(search); + verify_replicas_entry(search); return __replicas_has_entry(&c->replicas, search) && (!check_gc_replicas || @@ -363,6 +368,8 @@ static int bch2_mark_replicas_slowpath(struct bch_fs *c, struct bch_replicas_cpu new_r, new_gc; int ret = -ENOMEM; + verify_replicas_entry(new_entry); + memset(&new_r, 0, sizeof(new_r)); memset(&new_gc, 0, sizeof(new_gc)); @@ -878,9 +885,8 @@ static const char *bch2_sb_validate_replicas(struct bch_sb *sb, struct bch_sb_fi goto err; err = "invalid replicas entry: bad nr_required"; - if (!e->nr_required || - (e->nr_required > 1 && - e->nr_required >= e->nr_devs)) + if (e->nr_required > 1 && + e->nr_required >= e->nr_devs) goto err; err = "invalid replicas entry: invalid device"; |