bcachefs: bkey_ops.min_val_size
authorKent Overstreet <kent.overstreet@linux.dev>
Sat, 29 Apr 2023 17:24:18 +0000 (13:24 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:10:00 +0000 (17:10 -0400)
This adds a new field to bkey_ops for the minimum size of the value,
which standardizes that check and also enforces the new rule (previously
done somewhat ad-hoc) that we can extend value types by adding new
fields on to the end.

To make that work we do _not_ initialize min_val_size with sizeof,
instead we initialize it to the size of the first version of those
values.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
23 files changed:
fs/bcachefs/alloc_background.h
fs/bcachefs/backpointers.c
fs/bcachefs/backpointers.h
fs/bcachefs/bkey_methods.c
fs/bcachefs/bkey_methods.h
fs/bcachefs/dirent.c
fs/bcachefs/dirent.h
fs/bcachefs/ec.c
fs/bcachefs/ec.h
fs/bcachefs/extents.c
fs/bcachefs/extents.h
fs/bcachefs/inode.c
fs/bcachefs/inode.h
fs/bcachefs/lru.c
fs/bcachefs/lru.h
fs/bcachefs/quota.c
fs/bcachefs/quota.h
fs/bcachefs/reflink.c
fs/bcachefs/reflink.h
fs/bcachefs/subvolume.c
fs/bcachefs/subvolume.h
fs/bcachefs/xattr.c
fs/bcachefs/xattr.h

index 324798396fc6b667f608e035a78033e2c035f456..94b3c057cd62539fce10598c673bbc45ebbfe54f 100644 (file)
@@ -159,6 +159,7 @@ void bch2_alloc_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
        .val_to_text    = bch2_alloc_to_text,           \
        .trans_trigger  = bch2_trans_mark_alloc,        \
        .atomic_trigger = bch2_mark_alloc,              \
+       .min_val_size   = 8,                            \
 })
 
 #define bch2_bkey_ops_alloc_v2 ((struct bkey_ops) {    \
@@ -166,6 +167,7 @@ void bch2_alloc_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
        .val_to_text    = bch2_alloc_to_text,           \
        .trans_trigger  = bch2_trans_mark_alloc,        \
        .atomic_trigger = bch2_mark_alloc,              \
+       .min_val_size   = 8,                            \
 })
 
 #define bch2_bkey_ops_alloc_v3 ((struct bkey_ops) {    \
@@ -173,6 +175,7 @@ void bch2_alloc_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
        .val_to_text    = bch2_alloc_to_text,           \
        .trans_trigger  = bch2_trans_mark_alloc,        \
        .atomic_trigger = bch2_mark_alloc,              \
+       .min_val_size   = 16,                           \
 })
 
 #define bch2_bkey_ops_alloc_v4 ((struct bkey_ops) {    \
@@ -181,6 +184,7 @@ void bch2_alloc_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
        .swab           = bch2_alloc_v4_swab,           \
        .trans_trigger  = bch2_trans_mark_alloc,        \
        .atomic_trigger = bch2_mark_alloc,              \
+       .min_val_size   = 48,                           \
 })
 
 int bch2_bucket_gens_invalid(const struct bch_fs *, struct bkey_s_c, unsigned, struct printbuf *);
index a3a1ed6e596819bbdb530ee70d14a8a2e781fc74..e8666c3ed465e27228c86c57c686aacfedf8dc93 100644 (file)
@@ -43,11 +43,6 @@ int bch2_backpointer_invalid(const struct bch_fs *c, struct bkey_s_c k,
        struct bkey_s_c_backpointer bp = bkey_s_c_to_backpointer(k);
        struct bpos bucket = bp_pos_to_bucket(c, bp.k->p);
 
-       if (bkey_val_bytes(bp.k) < sizeof(*bp.v)) {
-               prt_str(err, "incorrect value size");
-               return -BCH_ERR_invalid_bkey;
-       }
-
        if (!bpos_eq(bp.k->p, bucket_pos_to_bp(c, bucket, bp.v->bucket_offset))) {
                prt_str(err, "backpointer at wrong pos");
                return -BCH_ERR_invalid_bkey;
index 9c03709ade50420ee7e694ca8b04ed90871599c7..3994bc83d69df31e90df8fd7c48677e217be42d7 100644 (file)
@@ -17,6 +17,7 @@ void bch2_backpointer_swab(struct bkey_s);
        .key_invalid    = bch2_backpointer_invalid,     \
        .val_to_text    = bch2_backpointer_k_to_text,   \
        .swab           = bch2_backpointer_swab,        \
+       .min_val_size   = 32,                           \
 })
 
 #define MAX_EXTENT_COMPRESS_RATIO_SHIFT                10
index 72d95831d65df7a752dfc5a2ca0e084c9d2d141b..47f0ab023d641c1ee6d711b75a8fd3d81ba1dd19 100644 (file)
@@ -56,17 +56,12 @@ static int empty_val_key_invalid(const struct bch_fs *c, struct bkey_s_c k,
 static int key_type_cookie_invalid(const struct bch_fs *c, struct bkey_s_c k,
                                   unsigned flags, struct printbuf *err)
 {
-       if (bkey_val_bytes(k.k) != sizeof(struct bch_cookie)) {
-               prt_printf(err, "incorrect value size (%zu != %zu)",
-                      bkey_val_bytes(k.k), sizeof(struct bch_cookie));
-               return -BCH_ERR_invalid_bkey;
-       }
-
        return 0;
 }
 
 #define bch2_bkey_ops_cookie ((struct bkey_ops) {      \
-       .key_invalid = key_type_cookie_invalid,         \
+       .key_invalid    = key_type_cookie_invalid,      \
+       .min_val_size   = 8,                            \
 })
 
 #define bch2_bkey_ops_hash_whiteout ((struct bkey_ops) {\
@@ -126,12 +121,22 @@ const struct bkey_ops bch2_bkey_ops[] = {
 int bch2_bkey_val_invalid(struct bch_fs *c, struct bkey_s_c k,
                          unsigned flags, struct printbuf *err)
 {
+       const struct bkey_ops *ops;
+
        if (k.k->type >= KEY_TYPE_MAX) {
                prt_printf(err, "invalid type (%u >= %u)", k.k->type, KEY_TYPE_MAX);
                return -BCH_ERR_invalid_bkey;
        }
 
-       return bch2_bkey_ops[k.k->type].key_invalid(c, k, flags, err);
+       ops = &bch2_bkey_ops[k.k->type];
+
+       if (bkey_val_bytes(k.k) < ops->min_val_size) {
+               prt_printf(err, "bad val size (%zu < %u)",
+                          bkey_val_bytes(k.k), ops->min_val_size);
+               return -BCH_ERR_invalid_bkey;
+       }
+
+       return ops->key_invalid(c, k, flags, err);
 }
 
 static unsigned bch2_key_types_allowed[] = {
index ec4638150eae94e4d90b3875e29d90256aa349f7..a65756e306b05eb16569896e3b4bc9b54f0696c8 100644 (file)
@@ -34,6 +34,9 @@ struct bkey_ops {
        void            (*compat)(enum btree_id id, unsigned version,
                                  unsigned big_endian, int write,
                                  struct bkey_s);
+
+       /* Size of value type when first created: */
+       unsigned        min_val_size;
 };
 
 extern const struct bkey_ops bch2_bkey_ops[];
index 4c85d3399fb4cf4b93f5467ec50c8d409c05b25d..1544fc56974f213d51c978756033482bd205c512 100644 (file)
@@ -89,12 +89,6 @@ int bch2_dirent_invalid(const struct bch_fs *c, struct bkey_s_c k,
        struct bkey_s_c_dirent d = bkey_s_c_to_dirent(k);
        unsigned len;
 
-       if (bkey_val_bytes(k.k) < sizeof(struct bch_dirent)) {
-               prt_printf(err, "incorrect value size (%zu < %zu)",
-                      bkey_val_bytes(k.k), sizeof(*d.v));
-               return -BCH_ERR_invalid_bkey;
-       }
-
        len = bch2_dirent_name_bytes(d);
        if (!len) {
                prt_printf(err, "empty name");
index ad131e8edc29649da8a544f71d95740a13bfa480..bf9ea2e35faeb9a87c42be340e1d17e4fbb6e136 100644 (file)
@@ -12,6 +12,7 @@ void bch2_dirent_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
 #define bch2_bkey_ops_dirent ((struct bkey_ops) {      \
        .key_invalid    = bch2_dirent_invalid,          \
        .val_to_text    = bch2_dirent_to_text,          \
+       .min_val_size   = 16,                           \
 })
 
 struct qstr;
index 1855d08efd4be2b190398a57250b091ec3afa8a5..cf9f8c0260344991e422ce829a5c69feefb6ac8c 100644 (file)
@@ -119,12 +119,6 @@ int bch2_stripe_invalid(const struct bch_fs *c, struct bkey_s_c k,
                return -BCH_ERR_invalid_bkey;
        }
 
-       if (bkey_val_bytes(k.k) < sizeof(*s)) {
-               prt_printf(err, "incorrect value size (%zu < %zu)",
-                      bkey_val_bytes(k.k), sizeof(*s));
-               return -BCH_ERR_invalid_bkey;
-       }
-
        if (bkey_val_u64s(k.k) < stripe_val_u64s(s)) {
                prt_printf(err, "incorrect value size (%zu < %u)",
                       bkey_val_u64s(k.k), stripe_val_u64s(s));
index 7c08a49d741956534a229e92e2d787ceacb3b407..3995b707642702f782732480858c7c941ea56d00 100644 (file)
@@ -17,6 +17,7 @@ void bch2_stripe_to_text(struct printbuf *, struct bch_fs *,
        .swab           = bch2_ptr_swab,                \
        .trans_trigger  = bch2_trans_mark_stripe,       \
        .atomic_trigger = bch2_mark_stripe,             \
+       .min_val_size   = 8,                            \
 })
 
 static inline unsigned stripe_csums_per_device(const struct bch_stripe *s)
index ccefacd0bda7df2daf1ac0f726327ea2310f1f1b..e2b126ad2babdf5a3b8fdb8730cffd6453e12d25 100644 (file)
@@ -183,14 +183,6 @@ void bch2_btree_ptr_to_text(struct printbuf *out, struct bch_fs *c,
 int bch2_btree_ptr_v2_invalid(const struct bch_fs *c, struct bkey_s_c k,
                              unsigned flags, struct printbuf *err)
 {
-       struct bkey_s_c_btree_ptr_v2 bp = bkey_s_c_to_btree_ptr_v2(k);
-
-       if (bkey_val_bytes(k.k) <= sizeof(*bp.v)) {
-               prt_printf(err, "value too small (%zu <= %zu)",
-                      bkey_val_bytes(k.k), sizeof(*bp.v));
-               return -BCH_ERR_invalid_bkey;
-       }
-
        if (bkey_val_u64s(k.k) > BKEY_BTREE_PTR_VAL_U64s_MAX) {
                prt_printf(err, "value too big (%zu > %zu)",
                       bkey_val_u64s(k.k), BKEY_BTREE_PTR_VAL_U64s_MAX);
@@ -383,12 +375,6 @@ int bch2_reservation_invalid(const struct bch_fs *c, struct bkey_s_c k,
 {
        struct bkey_s_c_reservation r = bkey_s_c_to_reservation(k);
 
-       if (bkey_val_bytes(k.k) != sizeof(struct bch_reservation)) {
-               prt_printf(err, "incorrect value size (%zu != %zu)",
-                      bkey_val_bytes(k.k), sizeof(*r.v));
-               return -BCH_ERR_invalid_bkey;
-       }
-
        if (!r.v->nr_replicas || r.v->nr_replicas > BCH_REPLICAS_MAX) {
                prt_printf(err, "invalid nr_replicas (%u)",
                       r.v->nr_replicas);
index 9b026ae95932f382d5b6c7aacd34b38d628c059f..31c8140950e0073d615c52bb39a4146e7815c2e4 100644 (file)
@@ -407,6 +407,7 @@ void bch2_btree_ptr_v2_compat(enum btree_id, unsigned, unsigned,
        .compat         = bch2_btree_ptr_v2_compat,             \
        .trans_trigger  = bch2_trans_mark_extent,               \
        .atomic_trigger = bch2_mark_extent,                     \
+       .min_val_size   = 40,                                   \
 })
 
 /* KEY_TYPE_extent: */
@@ -436,6 +437,7 @@ bool bch2_reservation_merge(struct bch_fs *, struct bkey_s, struct bkey_s_c);
        .key_merge      = bch2_reservation_merge,               \
        .trans_trigger  = bch2_trans_mark_reservation,          \
        .atomic_trigger = bch2_mark_reservation,                \
+       .min_val_size   = 8,                                    \
 })
 
 /* Extent checksum entries: */
index 7ccbc00b7156ed9f7ad9e2f16326555b475a5760..107210dd9c9a657f625adb138dd99ce8211859b0 100644 (file)
@@ -437,12 +437,6 @@ int bch2_inode_invalid(const struct bch_fs *c, struct bkey_s_c k,
 {
        struct bkey_s_c_inode inode = bkey_s_c_to_inode(k);
 
-       if (bkey_val_bytes(k.k) < sizeof(*inode.v)) {
-               prt_printf(err, "incorrect value size (%zu < %zu)",
-                      bkey_val_bytes(k.k), sizeof(*inode.v));
-               return -BCH_ERR_invalid_bkey;
-       }
-
        if (INODE_STR_HASH(inode.v) >= BCH_STR_HASH_NR) {
                prt_printf(err, "invalid str hash type (%llu >= %u)",
                       INODE_STR_HASH(inode.v), BCH_STR_HASH_NR);
@@ -457,12 +451,6 @@ int bch2_inode_v2_invalid(const struct bch_fs *c, struct bkey_s_c k,
 {
        struct bkey_s_c_inode_v2 inode = bkey_s_c_to_inode_v2(k);
 
-       if (bkey_val_bytes(k.k) < sizeof(*inode.v)) {
-               prt_printf(err, "incorrect value size (%zu < %zu)",
-                      bkey_val_bytes(k.k), sizeof(*inode.v));
-               return -BCH_ERR_invalid_bkey;
-       }
-
        if (INODEv2_STR_HASH(inode.v) >= BCH_STR_HASH_NR) {
                prt_printf(err, "invalid str hash type (%llu >= %u)",
                       INODEv2_STR_HASH(inode.v), BCH_STR_HASH_NR);
@@ -477,12 +465,6 @@ int bch2_inode_v3_invalid(const struct bch_fs *c, struct bkey_s_c k,
 {
        struct bkey_s_c_inode_v3 inode = bkey_s_c_to_inode_v3(k);
 
-       if (bkey_val_bytes(k.k) < sizeof(*inode.v)) {
-               prt_printf(err, "incorrect value size (%zu < %zu)",
-                      bkey_val_bytes(k.k), sizeof(*inode.v));
-               return -BCH_ERR_invalid_bkey;
-       }
-
        if (INODEv3_FIELDS_START(inode.v) < INODEv3_FIELDS_START_INITIAL ||
            INODEv3_FIELDS_START(inode.v) > bkey_val_u64s(inode.k)) {
                prt_printf(err, "invalid fields_start (got %llu, min %u max %zu)",
@@ -543,12 +525,6 @@ int bch2_inode_generation_invalid(const struct bch_fs *c, struct bkey_s_c k,
                return -BCH_ERR_invalid_bkey;
        }
 
-       if (bkey_val_bytes(k.k) != sizeof(struct bch_inode_generation)) {
-               prt_printf(err, "incorrect value size (%zu != %zu)",
-                      bkey_val_bytes(k.k), sizeof(struct bch_inode_generation));
-               return -BCH_ERR_invalid_bkey;
-       }
-
        return 0;
 }
 
index f5066afb4886c5e67a3fd426020f74596e3b257f..0c3022d3f995f00ef0bfe99de85a6f50877e9032 100644 (file)
@@ -17,6 +17,7 @@ void bch2_inode_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
        .val_to_text    = bch2_inode_to_text,           \
        .trans_trigger  = bch2_trans_mark_inode,        \
        .atomic_trigger = bch2_mark_inode,              \
+       .min_val_size   = 16,                           \
 })
 
 #define bch2_bkey_ops_inode_v2 ((struct bkey_ops) {    \
@@ -24,6 +25,7 @@ void bch2_inode_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
        .val_to_text    = bch2_inode_to_text,           \
        .trans_trigger  = bch2_trans_mark_inode,        \
        .atomic_trigger = bch2_mark_inode,              \
+       .min_val_size   = 32,                           \
 })
 
 #define bch2_bkey_ops_inode_v3 ((struct bkey_ops) {    \
@@ -31,6 +33,7 @@ void bch2_inode_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
        .val_to_text    = bch2_inode_to_text,           \
        .trans_trigger  = bch2_trans_mark_inode,        \
        .atomic_trigger = bch2_mark_inode,              \
+       .min_val_size   = 48,                           \
 })
 
 static inline bool bkey_is_inode(const struct bkey *k)
@@ -47,6 +50,7 @@ void bch2_inode_generation_to_text(struct printbuf *, struct bch_fs *, struct bk
 #define bch2_bkey_ops_inode_generation ((struct bkey_ops) {    \
        .key_invalid    = bch2_inode_generation_invalid,        \
        .val_to_text    = bch2_inode_generation_to_text,        \
+       .min_val_size   = 8,                                    \
 })
 
 #if 0
index c2dece27da2d3c856a46af66ae3c0579584d0011..0e6193d6b5f8a6887826a8ba5521ab62b8f39484 100644 (file)
 int bch2_lru_invalid(const struct bch_fs *c, struct bkey_s_c k,
                     unsigned flags, struct printbuf *err)
 {
-       const struct bch_lru *lru = bkey_s_c_to_lru(k).v;
-
-       if (bkey_val_bytes(k.k) < sizeof(*lru)) {
-               prt_printf(err, "incorrect value size (%zu < %zu)",
-                      bkey_val_bytes(k.k), sizeof(*lru));
-               return -BCH_ERR_invalid_bkey;
-       }
-
        if (!lru_pos_time(k.k->p)) {
                prt_printf(err, "lru entry at time=0");
                return -BCH_ERR_invalid_bkey;
index 78a6076999ed11383a029e007440c7c61d0f22b5..adb98429248ef3ceee4b34f34d05417fbe3a1ce8 100644 (file)
@@ -51,6 +51,7 @@ void bch2_lru_pos_to_text(struct printbuf *, struct bpos);
 #define bch2_bkey_ops_lru ((struct bkey_ops) { \
        .key_invalid    = bch2_lru_invalid,     \
        .val_to_text    = bch2_lru_to_text,     \
+       .min_val_size   = 8,                    \
 })
 
 int bch2_lru_del(struct btree_trans *, u16, u64, u64);
index 331f22835d1859574cd073784242d557e130d7cd..22cd662429d3735cec4c2fad3f71ef8258cf8cf7 100644 (file)
@@ -67,12 +67,6 @@ int bch2_quota_invalid(const struct bch_fs *c, struct bkey_s_c k,
                return -BCH_ERR_invalid_bkey;
        }
 
-       if (bkey_val_bytes(k.k) != sizeof(struct bch_quota)) {
-               prt_printf(err, "incorrect value size (%zu != %zu)",
-                      bkey_val_bytes(k.k), sizeof(struct bch_quota));
-               return -BCH_ERR_invalid_bkey;
-       }
-
        return 0;
 }
 
index 146264fd16ce0bf24a5dafe285b4921b0355d79f..b0f7d4ee775e17ae15e0177652c49d8006086558 100644 (file)
@@ -13,6 +13,7 @@ void bch2_quota_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
 #define bch2_bkey_ops_quota ((struct bkey_ops) {       \
        .key_invalid    = bch2_quota_invalid,           \
        .val_to_text    = bch2_quota_to_text,           \
+       .min_val_size   = 32,                           \
 })
 
 static inline struct bch_qid bch_qid(struct bch_inode_unpacked *u)
index d8426e754cdf0cd9cef8ed9c71a26c367294987b..9430899a5a31633ddb56cb2fde5dae3f4869b29a 100644 (file)
@@ -30,12 +30,6 @@ int bch2_reflink_p_invalid(const struct bch_fs *c, struct bkey_s_c k,
 {
        struct bkey_s_c_reflink_p p = bkey_s_c_to_reflink_p(k);
 
-       if (bkey_val_bytes(p.k) != sizeof(*p.v)) {
-               prt_printf(err, "incorrect value size (%zu != %zu)",
-                      bkey_val_bytes(p.k), sizeof(*p.v));
-               return -EINVAL;
-       }
-
        if (c->sb.version >= bcachefs_metadata_version_reflink_p_fix &&
            le64_to_cpu(p.v->idx) < le32_to_cpu(p.v->front_pad)) {
                prt_printf(err, "idx < front_pad (%llu < %u)",
@@ -80,14 +74,6 @@ bool bch2_reflink_p_merge(struct bch_fs *c, struct bkey_s _l, struct bkey_s_c _r
 int bch2_reflink_v_invalid(const struct bch_fs *c, struct bkey_s_c k,
                           unsigned flags, struct printbuf *err)
 {
-       struct bkey_s_c_reflink_v r = bkey_s_c_to_reflink_v(k);
-
-       if (bkey_val_bytes(r.k) < sizeof(*r.v)) {
-               prt_printf(err, "incorrect value size (%zu < %zu)",
-                      bkey_val_bytes(r.k), sizeof(*r.v));
-               return -BCH_ERR_invalid_bkey;
-       }
-
        return bch2_bkey_ptrs_invalid(c, k, flags, err);
 }
 
@@ -133,12 +119,6 @@ int bch2_trans_mark_reflink_v(struct btree_trans *trans,
 int bch2_indirect_inline_data_invalid(const struct bch_fs *c, struct bkey_s_c k,
                                      unsigned flags, struct printbuf *err)
 {
-       if (bkey_val_bytes(k.k) < sizeof(struct bch_indirect_inline_data)) {
-               prt_printf(err, "incorrect value size (%zu < %zu)",
-                      bkey_val_bytes(k.k), sizeof(struct bch_indirect_inline_data));
-               return -BCH_ERR_invalid_bkey;
-       }
-
        return 0;
 }
 
index 2391037c2ece6ca5ad2ec1ac4c3f69bf7f352037..ba400188f5befeea949f69a95cefc5c876309e44 100644 (file)
@@ -14,6 +14,7 @@ bool bch2_reflink_p_merge(struct bch_fs *, struct bkey_s, struct bkey_s_c);
        .key_merge      = bch2_reflink_p_merge,                 \
        .trans_trigger  = bch2_trans_mark_reflink_p,            \
        .atomic_trigger = bch2_mark_reflink_p,                  \
+       .min_val_size   = 16,                                   \
 })
 
 int bch2_reflink_v_invalid(const struct bch_fs *, struct bkey_s_c,
@@ -29,6 +30,7 @@ int bch2_trans_mark_reflink_v(struct btree_trans *, enum btree_id, unsigned,
        .swab           = bch2_ptr_swab,                        \
        .trans_trigger  = bch2_trans_mark_reflink_v,            \
        .atomic_trigger = bch2_mark_extent,                     \
+       .min_val_size   = 8,                                    \
 })
 
 int bch2_indirect_inline_data_invalid(const struct bch_fs *, struct bkey_s_c,
@@ -44,6 +46,7 @@ int bch2_trans_mark_indirect_inline_data(struct btree_trans *,
        .key_invalid    = bch2_indirect_inline_data_invalid,    \
        .val_to_text    = bch2_indirect_inline_data_to_text,    \
        .trans_trigger  = bch2_trans_mark_indirect_inline_data, \
+       .min_val_size   = 8,                                    \
 })
 
 static inline const __le64 *bkey_refcount_c(struct bkey_s_c k)
index 6407d19edc0e5cc87be979376a906858d0137ae3..31af41df09e351ed152f568308154d520cd5c14b 100644 (file)
@@ -36,12 +36,6 @@ int bch2_snapshot_invalid(const struct bch_fs *c, struct bkey_s_c k,
                return -BCH_ERR_invalid_bkey;
        }
 
-       if (bkey_val_bytes(k.k) != sizeof(struct bch_snapshot)) {
-               prt_printf(err, "bad val size (%zu != %zu)",
-                      bkey_val_bytes(k.k), sizeof(struct bch_snapshot));
-               return -BCH_ERR_invalid_bkey;
-       }
-
        s = bkey_s_c_to_snapshot(k);
 
        id = le32_to_cpu(s.v->parent);
@@ -743,12 +737,6 @@ int bch2_subvolume_invalid(const struct bch_fs *c, struct bkey_s_c k,
                return -BCH_ERR_invalid_bkey;
        }
 
-       if (bkey_val_bytes(k.k) != sizeof(struct bch_subvolume)) {
-               prt_printf(err, "incorrect value size (%zu != %zu)",
-                      bkey_val_bytes(k.k), sizeof(struct bch_subvolume));
-               return -BCH_ERR_invalid_bkey;
-       }
-
        return 0;
 }
 
index df6657952e2f66922577319b1d0a80f64a9d7e61..1f6f7862e48f73fa654f12ba70b2796d609e8e6e 100644 (file)
@@ -15,6 +15,7 @@ int bch2_mark_snapshot(struct btree_trans *, enum btree_id, unsigned,
        .key_invalid    = bch2_snapshot_invalid,                \
        .val_to_text    = bch2_snapshot_to_text,                \
        .atomic_trigger = bch2_mark_snapshot,                   \
+       .min_val_size   = 24,                                   \
 })
 
 static inline struct snapshot_t *snapshot_t(struct bch_fs *c, u32 id)
@@ -119,6 +120,7 @@ void bch2_subvolume_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c)
 #define bch2_bkey_ops_subvolume ((struct bkey_ops) {           \
        .key_invalid    = bch2_subvolume_invalid,               \
        .val_to_text    = bch2_subvolume_to_text,               \
+       .min_val_size   = 16,                                   \
 })
 
 int bch2_subvolume_get(struct btree_trans *, unsigned,
index 4c86878b3df26f653d12a31baf07c4453b22c34a..448eb446946b11c8bd715f2158c73ac082bd0965 100644 (file)
@@ -75,12 +75,6 @@ int bch2_xattr_invalid(const struct bch_fs *c, struct bkey_s_c k,
        const struct xattr_handler *handler;
        struct bkey_s_c_xattr xattr = bkey_s_c_to_xattr(k);
 
-       if (bkey_val_bytes(k.k) < sizeof(struct bch_xattr)) {
-               prt_printf(err, "incorrect value size (%zu < %zu)",
-                      bkey_val_bytes(k.k), sizeof(*xattr.v));
-               return -BCH_ERR_invalid_bkey;
-       }
-
        if (bkey_val_u64s(k.k) <
            xattr_val_u64s(xattr.v->x_name_len,
                           le16_to_cpu(xattr.v->x_val_len))) {
index 1a4cff3a9d962aaa994a0ce554a3c2fdb4e4fab0..b3e16729bcbba472f15302a3c3bb0b560330c8ce 100644 (file)
@@ -12,6 +12,7 @@ void bch2_xattr_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
 #define bch2_bkey_ops_xattr ((struct bkey_ops) {       \
        .key_invalid    = bch2_xattr_invalid,           \
        .val_to_text    = bch2_xattr_to_text,           \
+       .min_val_size   = 8,                            \
 })
 
 static inline unsigned xattr_val_u64s(unsigned name_len, unsigned val_len)