From a9bc0a5173bb9c30d0073ccf39b10e26d2f96ecf Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Tue, 18 Feb 2020 20:02:41 -0500 Subject: [PATCH] bcachefs: Check for bad key version number Signed-off-by: Kent Overstreet Signed-off-by: Kent Overstreet --- fs/bcachefs/btree_gc.c | 6 +++++- fs/bcachefs/io.c | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/bcachefs/btree_gc.c b/fs/bcachefs/btree_gc.c index a0b65267cf76..a5fe3b316e06 100644 --- a/fs/bcachefs/btree_gc.c +++ b/fs/bcachefs/btree_gc.c @@ -126,7 +126,11 @@ static int bch2_gc_mark_key(struct bch_fs *c, struct bkey_s_c k, BUG_ON(journal_seq_verify(c) && k.k->version.lo > journal_cur_seq(&c->journal)); - if (k.k->version.lo > atomic64_read(&c->key_version)) + /* XXX change to fsck check */ + if (fsck_err_on(k.k->version.lo > atomic64_read(&c->key_version), c, + "key version number higher than recorded: %llu > %llu", + k.k->version.lo, + atomic64_read(&c->key_version))) atomic64_set(&c->key_version, k.k->version.lo); if (test_bit(BCH_FS_REBUILD_REPLICAS, &c->flags) || diff --git a/fs/bcachefs/io.c b/fs/bcachefs/io.c index 679ad54d4c4e..33603624b42a 100644 --- a/fs/bcachefs/io.c +++ b/fs/bcachefs/io.c @@ -943,7 +943,7 @@ static int bch2_write_extent(struct bch_write_op *op, struct write_point *wp, if (bch2_csum_type_is_encryption(op->csum_type)) { if (bversion_zero(version)) { - version.lo = atomic64_inc_return(&c->key_version) + 1; + version.lo = atomic64_inc_return(&c->key_version); } else { crc.nonce = op->nonce; op->nonce += src_len >> 9;