]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
bcachefs: Check for accounting keys with bversion=0
authorKent Overstreet <kent.overstreet@linux.dev>
Thu, 26 Sep 2024 19:58:02 +0000 (15:58 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 28 Sep 2024 01:46:35 +0000 (21:46 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/bkey.h
fs/bcachefs/disk_accounting.c
fs/bcachefs/sb-errors_format.h

index 6e5092d4c62eb4e171cb3bf6cae3c5db31b18c68..41df24a53d971e6fc67db0378a2d1320b25e993b 100644 (file)
@@ -214,9 +214,9 @@ static __always_inline int bversion_cmp(struct bversion l, struct bversion r)
 #define ZERO_VERSION   ((struct bversion) { .hi = 0, .lo = 0 })
 #define MAX_VERSION    ((struct bversion) { .hi = ~0, .lo = ~0ULL })
 
-static __always_inline int bversion_zero(struct bversion v)
+static __always_inline bool bversion_zero(struct bversion v)
 {
-       return !bversion_cmp(v, ZERO_VERSION);
+       return bversion_cmp(v, ZERO_VERSION) == 0;
 }
 
 #ifdef CONFIG_BCACHEFS_DEBUG
index 9ac45a607b9318a8b11cb0b19cb331ffce1bfc18..59897b347c62ac3e528d34d7f9efec96b7b29f02 100644 (file)
@@ -134,6 +134,10 @@ int bch2_accounting_validate(struct bch_fs *c, struct bkey_s_c k,
        void *end = &acc_k + 1;
        int ret = 0;
 
+       bkey_fsck_err_on(bversion_zero(k.k->bversion),
+                        c, accounting_key_version_0,
+                        "accounting key with version=0");
+
        switch (acc_k.type) {
        case BCH_DISK_ACCOUNTING_nr_inodes:
                end = field_end(acc_k, nr_inodes);
index 3fca1d836318a246ca033c1893f13f97f7bccca3..6955bb4ea4c523d56d9ed3501f6231f3350c26bb 100644 (file)
@@ -293,7 +293,8 @@ enum bch_fsck_flags {
        x(accounting_key_replicas_nr_devs_0,                    278,    FSCK_AUTOFIX)   \
        x(accounting_key_replicas_nr_required_bad,              279,    FSCK_AUTOFIX)   \
        x(accounting_key_replicas_devs_unsorted,                280,    FSCK_AUTOFIX)   \
-       x(MAX,                                                  282,    0)
+       x(accounting_key_version_0,                             282,    FSCK_AUTOFIX)   \
+       x(MAX,                                                  283,    0)
 
 enum bch_sb_error_id {
 #define x(t, n, ...) BCH_FSCK_ERR_##t = n,