]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bcachefs: Plumb bch_validate_flags to sb_field_ops.validate()
authorKent Overstreet <kent.overstreet@linux.dev>
Wed, 8 May 2024 22:49:14 +0000 (18:49 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 9 May 2024 20:23:36 +0000 (16:23 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
13 files changed:
fs/bcachefs/checksum.c
fs/bcachefs/disk_groups.c
fs/bcachefs/journal_sb.c
fs/bcachefs/journal_seq_blacklist.c
fs/bcachefs/quota.c
fs/bcachefs/replicas.c
fs/bcachefs/sb-clean.c
fs/bcachefs/sb-counters.c
fs/bcachefs/sb-downgrade.c
fs/bcachefs/sb-errors.c
fs/bcachefs/sb-members.c
fs/bcachefs/super-io.c
fs/bcachefs/super-io.h

index 2b3677ae094251e1509546a97a7955ce567c6b26..85198f391e9c8fbb18e44cb53c1c36b5dbf60391 100644 (file)
@@ -469,9 +469,8 @@ int bch2_rechecksum_bio(struct bch_fs *c, struct bio *bio,
 
 /* BCH_SB_FIELD_crypt: */
 
-static int bch2_sb_crypt_validate(struct bch_sb *sb,
-                                 struct bch_sb_field *f,
-                                 struct printbuf *err)
+static int bch2_sb_crypt_validate(struct bch_sb *sb, struct bch_sb_field *f,
+                                 enum bch_validate_flags flags, struct printbuf *err)
 {
        struct bch_sb_field_crypt *crypt = field_to_type(f, crypt);
 
index 1cb563dfa01765e073b9bdd65f22141ff5f0ec4b..521a86df5e52aa185aee34d079803d77e1d13354 100644 (file)
@@ -18,9 +18,8 @@ static int group_cmp(const void *_l, const void *_r)
                strncmp(l->label, r->label, sizeof(l->label));
 }
 
-static int bch2_sb_disk_groups_validate(struct bch_sb *sb,
-                                       struct bch_sb_field *f,
-                                       struct printbuf *err)
+static int bch2_sb_disk_groups_validate(struct bch_sb *sb, struct bch_sb_field *f,
+                               enum bch_validate_flags flags, struct printbuf *err)
 {
        struct bch_sb_field_disk_groups *groups =
                field_to_type(f, disk_groups);
index ae4fb8c3a2bc26fe937c5bc88f8b5b78143e91b0..db80e506e3abee5f2776d02cfe2508b90693b8b5 100644 (file)
@@ -16,9 +16,8 @@ static int u64_cmp(const void *_l, const void *_r)
        return cmp_int(*l, *r);
 }
 
-static int bch2_sb_journal_validate(struct bch_sb *sb,
-                                   struct bch_sb_field *f,
-                                   struct printbuf *err)
+static int bch2_sb_journal_validate(struct bch_sb *sb, struct bch_sb_field *f,
+                               enum bch_validate_flags flags, struct printbuf *err)
 {
        struct bch_sb_field_journal *journal = field_to_type(f, journal);
        struct bch_member m = bch2_sb_member_get(sb, sb->dev_idx);
@@ -99,9 +98,8 @@ static int u64_range_cmp(const void *_l, const void *_r)
        return cmp_int(l->start, r->start);
 }
 
-static int bch2_sb_journal_v2_validate(struct bch_sb *sb,
-                                   struct bch_sb_field *f,
-                                   struct printbuf *err)
+static int bch2_sb_journal_v2_validate(struct bch_sb *sb, struct bch_sb_field *f,
+                               enum bch_validate_flags flags, struct printbuf *err)
 {
        struct bch_sb_field_journal_v2 *journal = field_to_type(f, journal_v2);
        struct bch_member m = bch2_sb_member_get(sb, sb->dev_idx);
index d8d40d46a27a2aa28eb3b0eb17c69830408e3354..ed484670961152b1ce83d11e1c235dd7e5d4dc26 100644 (file)
@@ -162,9 +162,8 @@ int bch2_blacklist_table_initialize(struct bch_fs *c)
        return 0;
 }
 
-static int bch2_sb_journal_seq_blacklist_validate(struct bch_sb *sb,
-                                                 struct bch_sb_field *f,
-                                                 struct printbuf *err)
+static int bch2_sb_journal_seq_blacklist_validate(struct bch_sb *sb, struct bch_sb_field *f,
+                               enum bch_validate_flags flags, struct printbuf *err)
 {
        struct bch_sb_field_journal_seq_blacklist *bl =
                field_to_type(f, journal_seq_blacklist);
index d86381e9ac8696aedc60d813a2f9d318a6feff1a..a0cca8b70e0ae173e8f10496c1d679028969743f 100644 (file)
@@ -20,7 +20,7 @@ static const char * const bch2_quota_counters[] = {
 };
 
 static int bch2_sb_quota_validate(struct bch_sb *sb, struct bch_sb_field *f,
-                                 struct printbuf *err)
+                                 enum bch_validate_flags flags, struct printbuf *err)
 {
        struct bch_sb_field_quota *q = field_to_type(f, quota);
 
@@ -60,8 +60,7 @@ const struct bch_sb_field_ops bch_sb_field_ops_quota = {
 };
 
 int bch2_quota_invalid(struct bch_fs *c, struct bkey_s_c k,
-                      enum bch_validate_flags flags,
-                      struct printbuf *err)
+                      enum bch_validate_flags flags, struct printbuf *err)
 {
        int ret = 0;
 
index f8ff7c8bb05ee5a17c99464b3021326e6c3b2ff7..bd1d5d085e23365b6bab993c558901fc178f4d7f 100644 (file)
@@ -860,7 +860,7 @@ static int bch2_cpu_replicas_validate(struct bch_replicas_cpu *cpu_r,
 }
 
 static int bch2_sb_replicas_validate(struct bch_sb *sb, struct bch_sb_field *f,
-                                    struct printbuf *err)
+                                    enum bch_validate_flags flags, struct printbuf *err)
 {
        struct bch_sb_field_replicas *sb_r = field_to_type(f, replicas);
        struct bch_replicas_cpu cpu_r;
@@ -899,7 +899,7 @@ const struct bch_sb_field_ops bch_sb_field_ops_replicas = {
 };
 
 static int bch2_sb_replicas_v0_validate(struct bch_sb *sb, struct bch_sb_field *f,
-                                       struct printbuf *err)
+                                       enum bch_validate_flags flags, struct printbuf *err)
 {
        struct bch_sb_field_replicas_v0 *sb_r = field_to_type(f, replicas_v0);
        struct bch_replicas_cpu cpu_r;
index e2beb2308c70c740409b756427a18a71426788be..47f10ab57f40c3773d329d9d3f407efe0b3467ca 100644 (file)
@@ -266,9 +266,8 @@ void bch2_journal_super_entries_add_common(struct bch_fs *c,
        }
 }
 
-static int bch2_sb_clean_validate(struct bch_sb *sb,
-                                 struct bch_sb_field *f,
-                                 struct printbuf *err)
+static int bch2_sb_clean_validate(struct bch_sb *sb, struct bch_sb_field *f,
+                                 enum bch_validate_flags flags, struct printbuf *err)
 {
        struct bch_sb_field_clean *clean = field_to_type(f, clean);
 
index 7282f78861926eea6a5a697a871fc500f1e78669..6992e7469112cf143b6a8fd5c7303e6f1d502235 100644 (file)
@@ -20,9 +20,8 @@ static size_t bch2_sb_counter_nr_entries(struct bch_sb_field_counters *ctrs)
        return (__le64 *) vstruct_end(&ctrs->field) - &ctrs->d[0];
 };
 
-static int bch2_sb_counters_validate(struct bch_sb *sb,
-                                    struct bch_sb_field *f,
-                                    struct printbuf *err)
+static int bch2_sb_counters_validate(struct bch_sb *sb, struct bch_sb_field *f,
+                               enum bch_validate_flags flags, struct printbuf *err)
 {
        return 0;
 };
index 90b06f8aa1df086c99005505a4075353d440c9e6..7d2abadbd6e3972c29f7baaedc59028dc20b0c04 100644 (file)
@@ -138,7 +138,7 @@ downgrade_entry_next_c(const struct bch_sb_field_downgrade_entry *e)
             _i = downgrade_entry_next_c(_i))
 
 static int bch2_sb_downgrade_validate(struct bch_sb *sb, struct bch_sb_field *f,
-                                     struct printbuf *err)
+                                     enum bch_validate_flags flags, struct printbuf *err)
 {
        struct bch_sb_field_downgrade *e = field_to_type(f, downgrade);
 
index 5f5bcae391fb9fcde0d306870adbb6779e06cda1..bda33e59e2264bc2225d223ce9edc68d48885643 100644 (file)
@@ -30,7 +30,7 @@ static inline unsigned bch2_sb_field_errors_u64s(unsigned nr)
 }
 
 static int bch2_sb_errors_validate(struct bch_sb *sb, struct bch_sb_field *f,
-                                  struct printbuf *err)
+                                  enum bch_validate_flags flags, struct printbuf *err)
 {
        struct bch_sb_field_errors *e = field_to_type(f, errors);
        unsigned i, nr = bch2_sb_field_errors_nr_entries(e);
index 8f197bb088a06cc30a785e3fe7805859fb44e57d..39196f2a41974f5ca39784cbfe52b64ce5bf1aab 100644 (file)
@@ -261,9 +261,8 @@ static void member_to_text(struct printbuf *out,
        printbuf_indent_sub(out, 2);
 }
 
-static int bch2_sb_members_v1_validate(struct bch_sb *sb,
-                                   struct bch_sb_field *f,
-                                   struct printbuf *err)
+static int bch2_sb_members_v1_validate(struct bch_sb *sb, struct bch_sb_field *f,
+                               enum bch_validate_flags flags, struct printbuf *err)
 {
        struct bch_sb_field_members_v1 *mi = field_to_type(f, members_v1);
        unsigned i;
@@ -311,9 +310,8 @@ static void bch2_sb_members_v2_to_text(struct printbuf *out, struct bch_sb *sb,
                member_to_text(out, members_v2_get(mi, i), gi, sb, i);
 }
 
-static int bch2_sb_members_v2_validate(struct bch_sb *sb,
-                                      struct bch_sb_field *f,
-                                      struct printbuf *err)
+static int bch2_sb_members_v2_validate(struct bch_sb *sb, struct bch_sb_field *f,
+                               enum bch_validate_flags flags, struct printbuf *err)
 {
        struct bch_sb_field_members_v2 *mi = field_to_type(f, members_v2);
        size_t mi_bytes = (void *) __bch2_members_v2_get_mut(mi, sb->nr_devices) -
index fb45749586811bec270d8d3ff04c768bf3e56ebd..f1bee6c5222d24b0dd32da210c7924b350c05d59 100644 (file)
@@ -76,7 +76,7 @@ const char * const bch2_sb_fields[] = {
 };
 
 static int bch2_sb_field_validate(struct bch_sb *, struct bch_sb_field *,
-                                 struct printbuf *);
+                                 enum bch_validate_flags, struct printbuf *);
 
 struct bch_sb_field *bch2_sb_field_get_id(struct bch_sb *sb,
                                      enum bch_sb_field_type type)
@@ -344,8 +344,8 @@ static int bch2_sb_compatible(struct bch_sb *sb, struct printbuf *out)
        return 0;
 }
 
-static int bch2_sb_validate(struct bch_sb_handle *disk_sb, struct printbuf *out,
-                           int rw)
+static int bch2_sb_validate(struct bch_sb_handle *disk_sb,
+                           enum bch_validate_flags flags, struct printbuf *out)
 {
        struct bch_sb *sb = disk_sb->sb;
        struct bch_sb_field_members_v1 *mi;
@@ -401,7 +401,7 @@ static int bch2_sb_validate(struct bch_sb_handle *disk_sb, struct printbuf *out,
                return -BCH_ERR_invalid_sb_time_precision;
        }
 
-       if (rw == READ) {
+       if (!flags) {
                /*
                 * Been seeing a bug where these are getting inexplicably
                 * zeroed, so we're now validating them, but we have to be
@@ -457,7 +457,7 @@ static int bch2_sb_validate(struct bch_sb_handle *disk_sb, struct printbuf *out,
                return -BCH_ERR_invalid_sb_members_missing;
        }
 
-       ret = bch2_sb_field_validate(sb, &mi->field, out);
+       ret = bch2_sb_field_validate(sb, &mi->field, flags, out);
        if (ret)
                return ret;
 
@@ -465,12 +465,12 @@ static int bch2_sb_validate(struct bch_sb_handle *disk_sb, struct printbuf *out,
                if (le32_to_cpu(f->type) == BCH_SB_FIELD_members_v1)
                        continue;
 
-               ret = bch2_sb_field_validate(sb, f, out);
+               ret = bch2_sb_field_validate(sb, f, flags, out);
                if (ret)
                        return ret;
        }
 
-       if (rw == WRITE &&
+       if ((flags & BCH_VALIDATE_write) &&
            bch2_sb_member_get(sb, sb->dev_idx).seq != sb->seq) {
                prt_printf(out, "Invalid superblock: member seq %llu != sb seq %llu",
                           le64_to_cpu(bch2_sb_member_get(sb, sb->dev_idx).seq),
@@ -819,7 +819,7 @@ got_super:
 
        sb->have_layout = true;
 
-       ret = bch2_sb_validate(sb, &err, READ);
+       ret = bch2_sb_validate(sb, 0, &err);
        if (ret) {
                bch2_print_opts(opts, KERN_ERR "bcachefs (%s): error validating superblock: %s\n",
                                path, err.buf);
@@ -975,7 +975,7 @@ int bch2_write_super(struct bch_fs *c)
        darray_for_each(online_devices, ca) {
                printbuf_reset(&err);
 
-               ret = bch2_sb_validate(&(*ca)->disk_sb, &err, WRITE);
+               ret = bch2_sb_validate(&(*ca)->disk_sb, BCH_VALIDATE_write, &err);
                if (ret) {
                        bch2_fs_inconsistent(c, "sb invalid before write: %s", err.buf);
                        goto out;
@@ -1161,7 +1161,7 @@ void bch2_sb_upgrade(struct bch_fs *c, unsigned new_version)
 }
 
 static int bch2_sb_ext_validate(struct bch_sb *sb, struct bch_sb_field *f,
-                               struct printbuf *err)
+                               enum bch_validate_flags flags, struct printbuf *err)
 {
        if (vstruct_bytes(f) < 88) {
                prt_printf(err, "field too small (%zu < %u)", vstruct_bytes(f), 88);
@@ -1219,14 +1219,14 @@ static const struct bch_sb_field_ops *bch2_sb_field_type_ops(unsigned type)
 }
 
 static int bch2_sb_field_validate(struct bch_sb *sb, struct bch_sb_field *f,
-                                 struct printbuf *err)
+                                 enum bch_validate_flags flags, struct printbuf *err)
 {
        unsigned type = le32_to_cpu(f->type);
        struct printbuf field_err = PRINTBUF;
        const struct bch_sb_field_ops *ops = bch2_sb_field_type_ops(type);
        int ret;
 
-       ret = ops->validate ? ops->validate(sb, f, &field_err) : 0;
+       ret = ops->validate ? ops->validate(sb, f, flags, &field_err) : 0;
        if (ret) {
                prt_printf(err, "Invalid superblock section %s: %s",
                           bch2_sb_fields[type], field_err.buf);
index 95e80e06316bf49873d64d4dc79cc766df0023a0..fadd364e2802a9e22d582e3004a88ac312f7da5d 100644 (file)
@@ -51,7 +51,8 @@ void bch2_sb_field_delete(struct bch_sb_handle *, enum bch_sb_field_type);
 extern const char * const bch2_sb_fields[];
 
 struct bch_sb_field_ops {
-       int     (*validate)(struct bch_sb *, struct bch_sb_field *, struct printbuf *);
+       int     (*validate)(struct bch_sb *, struct bch_sb_field *,
+                           enum bch_validate_flags, struct printbuf *);
        void    (*to_text)(struct printbuf *, struct bch_sb *, struct bch_sb_field *);
 };