]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/bkey_methods.h
Update bcachefs sources to f70a3402188e bcachefs: Fix ca->oldest_gen allocation
[bcachefs-tools-debian] / libbcachefs / bkey_methods.h
index 4739b3c32cff6df783dfcf16e6d219d310f08f28..668f595e2fcfeadf29547bd33d46448bad6dc7e3 100644 (file)
@@ -11,6 +11,7 @@ struct bkey;
 enum btree_node_type;
 
 extern const char * const bch2_bkey_types[];
+extern const struct bkey_ops bch2_bkey_null_ops;
 
 /*
  * key_invalid: checks validity of @k, returns 0 if good or -EINVAL if bad. If
@@ -21,7 +22,7 @@ extern const char * const bch2_bkey_types[];
  */
 struct bkey_ops {
        int             (*key_invalid)(const struct bch_fs *c, struct bkey_s_c k,
-                                      int rw, struct printbuf *err);
+                                      enum bkey_invalid_flags flags, struct printbuf *err);
        void            (*val_to_text)(struct printbuf *, struct bch_fs *,
                                       struct bkey_s_c);
        void            (*swab)(struct bkey_s);
@@ -29,20 +30,31 @@ struct bkey_ops {
        bool            (*key_merge)(struct bch_fs *, struct bkey_s, struct bkey_s_c);
        int             (*trans_trigger)(struct btree_trans *, enum btree_id, unsigned,
                                         struct bkey_s_c, struct bkey_i *, unsigned);
-       int             (*atomic_trigger)(struct btree_trans *, struct bkey_s_c,
-                                         struct bkey_s_c, unsigned);
+       int             (*atomic_trigger)(struct btree_trans *, enum btree_id, unsigned,
+                                         struct bkey_s_c, struct bkey_s_c, unsigned);
        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[];
 
-int bch2_bkey_val_invalid(struct bch_fs *, struct bkey_s_c, int, struct printbuf *);
-int __bch2_bkey_invalid(struct bch_fs *, struct bkey_s_c,
-                       enum btree_node_type, int, struct printbuf *);
-int bch2_bkey_invalid(struct bch_fs *, struct bkey_s_c,
-                     enum btree_node_type, int, struct printbuf *);
+static inline const struct bkey_ops *bch2_bkey_type_ops(enum bch_bkey_type type)
+{
+       return likely(type < KEY_TYPE_MAX)
+               ? &bch2_bkey_ops[type]
+               : &bch2_bkey_null_ops;
+}
+
+int bch2_bkey_val_invalid(struct bch_fs *, struct bkey_s_c,
+                         enum bkey_invalid_flags, struct printbuf *);
+int __bch2_bkey_invalid(struct bch_fs *, struct bkey_s_c, enum btree_node_type,
+                       enum bkey_invalid_flags, struct printbuf *);
+int bch2_bkey_invalid(struct bch_fs *, struct bkey_s_c, enum btree_node_type,
+                     enum bkey_invalid_flags, struct printbuf *);
 int bch2_bkey_in_btree_node(struct btree *, struct bkey_s_c, struct printbuf *);
 
 void bch2_bpos_to_text(struct printbuf *, struct bpos);
@@ -60,28 +72,27 @@ static inline bool bch2_bkey_maybe_mergable(const struct bkey *l, const struct b
 {
        return l->type == r->type &&
                !bversion_cmp(l->version, r->version) &&
-               !bpos_cmp(l->p, bkey_start_pos(r)) &&
-               (u64) l->size + r->size <= KEY_SIZE_MAX &&
-               bch2_bkey_ops[l->type].key_merge &&
-               !bch2_key_merging_disabled;
+               bpos_eq(l->p, bkey_start_pos(r));
 }
 
 bool bch2_bkey_merge(struct bch_fs *, struct bkey_s, struct bkey_s_c);
 
 static inline int bch2_mark_key(struct btree_trans *trans,
-                 struct bkey_s_c old,
-                 struct bkey_s_c new,
-                 unsigned flags)
+               enum btree_id btree, unsigned level,
+               struct bkey_s_c old, struct bkey_s_c new,
+               unsigned flags)
 {
-       const struct bkey_ops *ops = &bch2_bkey_ops[old.k->type ?: new.k->type];
+       const struct bkey_ops *ops = bch2_bkey_type_ops(old.k->type ?: new.k->type);
 
        return ops->atomic_trigger
-               ? ops->atomic_trigger(trans, old, new, flags)
+               ? ops->atomic_trigger(trans, btree, level, old, new, flags)
                : 0;
 }
 
 enum btree_update_flags {
-       __BTREE_UPDATE_INTERNAL_SNAPSHOT_NODE,
+       __BTREE_UPDATE_INTERNAL_SNAPSHOT_NODE = __BTREE_ITER_FLAGS_END,
+       __BTREE_UPDATE_NOJOURNAL,
+       __BTREE_UPDATE_PREJOURNAL,
        __BTREE_UPDATE_KEY_CACHE_RECLAIM,
 
        __BTREE_TRIGGER_NORUN,          /* Don't run triggers at all */
@@ -95,6 +106,8 @@ enum btree_update_flags {
 };
 
 #define BTREE_UPDATE_INTERNAL_SNAPSHOT_NODE (1U << __BTREE_UPDATE_INTERNAL_SNAPSHOT_NODE)
+#define BTREE_UPDATE_NOJOURNAL         (1U << __BTREE_UPDATE_NOJOURNAL)
+#define BTREE_UPDATE_PREJOURNAL                (1U << __BTREE_UPDATE_PREJOURNAL)
 #define BTREE_UPDATE_KEY_CACHE_RECLAIM (1U << __BTREE_UPDATE_KEY_CACHE_RECLAIM)
 
 #define BTREE_TRIGGER_NORUN            (1U << __BTREE_TRIGGER_NORUN)
@@ -121,7 +134,7 @@ static inline int bch2_trans_mark_key(struct btree_trans *trans,
                                      struct bkey_s_c old, struct bkey_i *new,
                                      unsigned flags)
 {
-       const struct bkey_ops *ops = &bch2_bkey_ops[old.k->type ?: new->k.type];
+       const struct bkey_ops *ops = bch2_bkey_type_ops(old.k->type ?: new->k.type);
 
        return ops->trans_trigger
                ? ops->trans_trigger(trans, btree_id, level, old, new, flags)