Skip to content

Commit f8911ad

Browse files
author
Kent Overstreet
committed
bcachefs: Check for accounting keys with bversion=0
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent cf49f8a commit f8911ad

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

fs/bcachefs/bkey.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,9 @@ static __always_inline int bversion_cmp(struct bversion l, struct bversion r)
214214
#define ZERO_VERSION ((struct bversion) { .hi = 0, .lo = 0 })
215215
#define MAX_VERSION ((struct bversion) { .hi = ~0, .lo = ~0ULL })
216216

217-
static __always_inline int bversion_zero(struct bversion v)
217+
static __always_inline bool bversion_zero(struct bversion v)
218218
{
219-
return !bversion_cmp(v, ZERO_VERSION);
219+
return bversion_cmp(v, ZERO_VERSION) == 0;
220220
}
221221

222222
#ifdef CONFIG_BCACHEFS_DEBUG

fs/bcachefs/disk_accounting.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ int bch2_accounting_validate(struct bch_fs *c, struct bkey_s_c k,
134134
void *end = &acc_k + 1;
135135
int ret = 0;
136136

137+
bkey_fsck_err_on(bversion_zero(k.k->bversion),
138+
c, accounting_key_version_0,
139+
"accounting key with version=0");
140+
137141
switch (acc_k.type) {
138142
case BCH_DISK_ACCOUNTING_nr_inodes:
139143
end = field_end(acc_k, nr_inodes);

fs/bcachefs/sb-errors_format.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@ enum bch_fsck_flags {
293293
x(accounting_key_replicas_nr_devs_0, 278, FSCK_AUTOFIX) \
294294
x(accounting_key_replicas_nr_required_bad, 279, FSCK_AUTOFIX) \
295295
x(accounting_key_replicas_devs_unsorted, 280, FSCK_AUTOFIX) \
296-
x(MAX, 282, 0)
296+
x(accounting_key_version_0, 282, FSCK_AUTOFIX) \
297+
x(MAX, 283, 0)
297298

298299
enum bch_sb_error_id {
299300
#define x(t, n, ...) BCH_FSCK_ERR_##t = n,

0 commit comments

Comments
 (0)