bcachefs: mark now takes bkey_s
authorKent Overstreet <kent.overstreet@linux.dev>
Thu, 28 Dec 2023 04:19:09 +0000 (23:19 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 6 Jan 2024 04:24:19 +0000 (23:24 -0500)
Prep work for disk space accounting rewrite: we're going to want to use
a single callback for both of our current triggers, so we need to change
them to have the same type signature first.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/bkey_methods.h
fs/bcachefs/btree_gc.c
fs/bcachefs/btree_trans_commit.c
fs/bcachefs/buckets.c
fs/bcachefs/buckets.h
fs/bcachefs/inode.c
fs/bcachefs/inode.h
fs/bcachefs/reflink.c
fs/bcachefs/reflink.h
fs/bcachefs/snapshot.c
fs/bcachefs/snapshot.h

index fa68e28c4f8215776d6c5d9143cb5e996de17784..da934d8f75fedc17336afacc245b428818a38576 100644 (file)
@@ -31,7 +31,7 @@ struct bkey_ops {
        int             (*trans_trigger)(struct btree_trans *, enum btree_id, unsigned,
                                         struct bkey_s_c, struct bkey_s, unsigned);
        int             (*atomic_trigger)(struct btree_trans *, enum btree_id, unsigned,
-                                         struct bkey_s_c, struct bkey_s_c, unsigned);
+                                         struct bkey_s_c, struct bkey_s, unsigned);
        void            (*compat)(enum btree_id id, unsigned version,
                                  unsigned big_endian, int write,
                                  struct bkey_s);
@@ -80,7 +80,7 @@ bool bch2_bkey_merge(struct bch_fs *, struct bkey_s, struct bkey_s_c);
 
 static inline int bch2_mark_key(struct btree_trans *trans,
                enum btree_id btree, unsigned level,
-               struct bkey_s_c old, struct bkey_s_c new,
+               struct bkey_s_c old, struct bkey_s new,
                unsigned flags)
 {
        const struct bkey_ops *ops = bch2_bkey_type_ops(old.k->type ?: new.k->type);
index 3143544ca24c00451de6782b42243df3596925da..88e069d7a7bb6a7eafc652774173604725360879 100644 (file)
 #define DROP_THIS_NODE         10
 #define DROP_PREV_NODE         11
 
+static struct bkey_s unsafe_bkey_s_c_to_s(struct bkey_s_c k)
+{
+       return (struct bkey_s) {{{
+               (struct bkey *) k.k,
+               (struct bch_val *) k.v
+       }}};
+}
+
 static bool should_restart_for_topology_repair(struct bch_fs *c)
 {
        return c->opts.fix_errors != FSCK_FIX_no &&
@@ -829,7 +837,7 @@ static int bch2_gc_mark_key(struct btree_trans *trans, enum btree_id btree_id,
        }
 
        ret = commit_do(trans, NULL, NULL, 0,
-                       bch2_mark_key(trans, btree_id, level, old, *k, flags));
+                       bch2_mark_key(trans, btree_id, level, old, unsafe_bkey_s_c_to_s(*k), flags));
 fsck_err:
 err:
        bch_err_fn(c, ret);
index b62eba04e0be2def32da7f9db4865cacef3a6faa..5b5cc3f44a8213eb0495b6c40ff6c4d6e68544f6 100644 (file)
@@ -453,14 +453,14 @@ static int run_one_mem_trigger(struct btree_trans *trans,
 
        if (old_ops->atomic_trigger == new_ops->atomic_trigger) {
                ret   = bch2_mark_key(trans, i->btree_id, i->level,
-                               old, bkey_i_to_s_c(new),
+                               old, bkey_i_to_s(new),
                                BTREE_TRIGGER_INSERT|BTREE_TRIGGER_OVERWRITE|flags);
        } else {
                struct bkey             _deleted = POS_KEY((trans->paths + i->path)->pos);
-               struct bkey_s_c         deleted = (struct bkey_s_c) { &_deleted, NULL };
+               struct bkey_s           deleted = (struct bkey_s) { { { &_deleted, NULL } } };
 
                ret   = bch2_mark_key(trans, i->btree_id, i->level,
-                               deleted, bkey_i_to_s_c(new),
+                               deleted.s_c, bkey_i_to_s(new),
                                BTREE_TRIGGER_INSERT|flags) ?:
                        bch2_mark_key(trans, i->btree_id, i->level,
                                old, deleted,
index e96e418918780a67baf372b93fb1a2cc77c3003a..7099a7db58a806a88c13e14bb17493410f16c060 100644 (file)
@@ -498,7 +498,7 @@ int bch2_update_cached_sectors_list(struct btree_trans *trans, unsigned dev, s64
 
 int bch2_mark_alloc(struct btree_trans *trans,
                    enum btree_id btree, unsigned level,
-                   struct bkey_s_c old, struct bkey_s_c new,
+                   struct bkey_s_c old, struct bkey_s new,
                    unsigned flags)
 {
        bool gc = flags & BTREE_TRIGGER_GC;
@@ -524,7 +524,7 @@ int bch2_mark_alloc(struct btree_trans *trans,
        ca = bch_dev_bkey_exists(c, new.k->p.inode);
 
        old_a = bch2_alloc_to_v4(old, &old_a_convert);
-       new_a = bch2_alloc_to_v4(new, &new_a_convert);
+       new_a = bch2_alloc_to_v4(new.s_c, &new_a_convert);
 
        bucket_journal_seq = new_a->journal_seq;
 
@@ -1008,7 +1008,7 @@ static int __mark_extent(struct btree_trans *trans,
 
 int bch2_mark_extent(struct btree_trans *trans,
                     enum btree_id btree_id, unsigned level,
-                    struct bkey_s_c old, struct bkey_s_c new,
+                    struct bkey_s_c old, struct bkey_s new,
                     unsigned flags)
 {
        return mem_trigger_run_overwrite_then_insert(__mark_extent, trans, btree_id, level, old, new, flags);
@@ -1016,9 +1016,10 @@ int bch2_mark_extent(struct btree_trans *trans,
 
 int bch2_mark_stripe(struct btree_trans *trans,
                     enum btree_id btree_id, unsigned level,
-                    struct bkey_s_c old, struct bkey_s_c new,
+                    struct bkey_s_c old, struct bkey_s _new,
                     unsigned flags)
 {
+       struct bkey_s_c new = _new.s_c;
        bool gc = flags & BTREE_TRIGGER_GC;
        u64 journal_seq = trans->journal_res.seq;
        struct bch_fs *c = trans->c;
@@ -1153,7 +1154,7 @@ static int __mark_reservation(struct btree_trans *trans,
 
 int bch2_mark_reservation(struct btree_trans *trans,
                          enum btree_id btree_id, unsigned level,
-                         struct bkey_s_c old, struct bkey_s_c new,
+                         struct bkey_s_c old, struct bkey_s new,
                          unsigned flags)
 {
        return mem_trigger_run_overwrite_then_insert(__mark_reservation, trans, btree_id, level, old, new, flags);
index c7168b86bb2e497060c05a2823d85ae37c9ec07f..de1a28dd0e077c32f5c97e587e6e0b8a60b46bbe 100644 (file)
@@ -328,13 +328,13 @@ int bch2_mark_metadata_bucket(struct bch_fs *, struct bch_dev *,
                              struct gc_pos, unsigned);
 
 int bch2_mark_alloc(struct btree_trans *, enum btree_id, unsigned,
-                   struct bkey_s_c, struct bkey_s_c, unsigned);
+                   struct bkey_s_c, struct bkey_s, unsigned);
 int bch2_mark_extent(struct btree_trans *, enum btree_id, unsigned,
-                    struct bkey_s_c, struct bkey_s_c, unsigned);
+                    struct bkey_s_c, struct bkey_s, unsigned);
 int bch2_mark_stripe(struct btree_trans *, enum btree_id, unsigned,
-                    struct bkey_s_c, struct bkey_s_c, unsigned);
+                    struct bkey_s_c, struct bkey_s, unsigned);
 int bch2_mark_reservation(struct btree_trans *, enum btree_id, unsigned,
-                         struct bkey_s_c, struct bkey_s_c, unsigned);
+                         struct bkey_s_c, struct bkey_s, unsigned);
 
 int bch2_trans_mark_extent(struct btree_trans *, enum btree_id, unsigned, struct bkey_s_c, struct bkey_s, unsigned);
 int bch2_trans_mark_stripe(struct btree_trans *, enum btree_id, unsigned, struct bkey_s_c, struct bkey_s, unsigned);
@@ -346,12 +346,12 @@ int bch2_trans_mark_reservation(struct btree_trans *, enum btree_id, unsigned, s
        if (_old.k->type)                                                                       \
                ret = _fn(_trans, _btree_id, _level, _old, _flags & ~BTREE_TRIGGER_INSERT);     \
        if (!ret && _new.k->type)                                                               \
-               ret = _fn(_trans, _btree_id, _level, _new, _flags & ~BTREE_TRIGGER_OVERWRITE);  \
+               ret = _fn(_trans, _btree_id, _level, _new.s_c, _flags & ~BTREE_TRIGGER_OVERWRITE);\
        ret;                                                                                    \
 })
 
 #define trigger_run_overwrite_then_insert(_fn, _trans, _btree_id, _level, _old, _new, _flags)  \
-       mem_trigger_run_overwrite_then_insert(_fn, _trans, _btree_id, _level, _old, _new.s_c, _flags)
+       mem_trigger_run_overwrite_then_insert(_fn, _trans, _btree_id, _level, _old, _new, _flags)
 
 void bch2_trans_fs_usage_revert(struct btree_trans *, struct replicas_delta_list *);
 int bch2_trans_fs_usage_apply(struct btree_trans *, struct replicas_delta_list *);
index 32e0736ba71869d8d82d34e8079c913356e9997e..e6978005bafd29029017ef048a4cc24aa8a0f2fb 100644 (file)
@@ -592,7 +592,7 @@ int bch2_trans_mark_inode(struct btree_trans *trans,
 
 int bch2_mark_inode(struct btree_trans *trans,
                    enum btree_id btree_id, unsigned level,
-                   struct bkey_s_c old, struct bkey_s_c new,
+                   struct bkey_s_c old, struct bkey_s new,
                    unsigned flags)
 {
        struct bch_fs *c = trans->c;
@@ -600,12 +600,9 @@ int bch2_mark_inode(struct btree_trans *trans,
        u64 journal_seq = trans->journal_res.seq;
 
        if (flags & BTREE_TRIGGER_INSERT) {
-               struct bch_inode_v3 *v = (struct bch_inode_v3 *) new.v;
-
                BUG_ON(!journal_seq);
-               BUG_ON(new.k->type != KEY_TYPE_inode_v3);
 
-               v->bi_journal_seq = cpu_to_le64(journal_seq);
+               bkey_s_to_inode_v3(new).v->bi_journal_seq = cpu_to_le64(journal_seq);
        }
 
        if (flags & BTREE_TRIGGER_GC) {
index 7533a16a78cb3cf1663da29381b3f71387286625..f1838dccfb3c0dd3a3d90bb2142b5985a3680b90 100644 (file)
@@ -20,7 +20,7 @@ void bch2_inode_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
 int bch2_trans_mark_inode(struct btree_trans *, enum btree_id, unsigned,
                          struct bkey_s_c, struct bkey_s, unsigned);
 int bch2_mark_inode(struct btree_trans *, enum btree_id, unsigned,
-                   struct bkey_s_c, struct bkey_s_c, unsigned);
+                   struct bkey_s_c, struct bkey_s, unsigned);
 
 #define bch2_bkey_ops_inode ((struct bkey_ops) {       \
        .key_invalid    = bch2_inode_invalid,           \
index aa2ff7ee801ffd4e721343be8964d34cfe7aaa43..5c1ae3be8e486c1e264cc5173d06f4c0900897d8 100644 (file)
@@ -268,7 +268,7 @@ static int __mark_reflink_p(struct btree_trans *trans,
 
 int bch2_mark_reflink_p(struct btree_trans *trans,
                        enum btree_id btree_id, unsigned level,
-                       struct bkey_s_c old, struct bkey_s_c new,
+                       struct bkey_s_c old, struct bkey_s new,
                        unsigned flags)
 {
        return mem_trigger_run_overwrite_then_insert(__mark_reflink_p, trans, btree_id, level, old, new, flags);
index fa2ec7f8314ae8043daa4641c55aea214b29a841..130b44625c85f7c355bf0167b52c2870a364a855 100644 (file)
@@ -12,7 +12,7 @@ bool bch2_reflink_p_merge(struct bch_fs *, struct bkey_s, struct bkey_s_c);
 int bch2_trans_mark_reflink_p(struct btree_trans *, enum btree_id, unsigned,
                              struct bkey_s_c, struct bkey_s, unsigned);
 int bch2_mark_reflink_p(struct btree_trans *, enum btree_id, unsigned,
-                       struct bkey_s_c, struct bkey_s_c, unsigned);
+                       struct bkey_s_c, struct bkey_s, unsigned);
 
 #define bch2_bkey_ops_reflink_p ((struct bkey_ops) {           \
        .key_invalid    = bch2_reflink_p_invalid,               \
index 96df4052ff7b93b8927daf7f8429b86fcf15a428..b2306fabd1c9492acaa83e811a465adf8caf979c 100644 (file)
@@ -276,7 +276,7 @@ static void set_is_ancestor_bitmap(struct bch_fs *c, u32 id)
        mutex_unlock(&c->snapshot_table_lock);
 }
 
-int bch2_mark_snapshot(struct btree_trans *trans,
+static int __bch2_mark_snapshot(struct btree_trans *trans,
                       enum btree_id btree, unsigned level,
                       struct bkey_s_c old, struct bkey_s_c new,
                       unsigned flags)
@@ -330,6 +330,14 @@ err:
        return ret;
 }
 
+int bch2_mark_snapshot(struct btree_trans *trans,
+                      enum btree_id btree, unsigned level,
+                      struct bkey_s_c old, struct bkey_s new,
+                      unsigned flags)
+{
+       return __bch2_mark_snapshot(trans, btree, level, old, new.s_c, flags);
+}
+
 int bch2_snapshot_lookup(struct btree_trans *trans, u32 id,
                         struct bch_snapshot *s)
 {
@@ -1055,7 +1063,7 @@ static int create_snapids(struct btree_trans *trans, u32 parent, u32 tree,
                bubble_sort(n->v.skip, ARRAY_SIZE(n->v.skip), cmp_le32);
                SET_BCH_SNAPSHOT_SUBVOL(&n->v, true);
 
-               ret = bch2_mark_snapshot(trans, BTREE_ID_snapshots, 0,
+               ret = __bch2_mark_snapshot(trans, BTREE_ID_snapshots, 0,
                                         bkey_s_c_null, bkey_i_to_s_c(&n->k_i), 0);
                if (ret)
                        goto err;
@@ -1664,7 +1672,7 @@ int bch2_snapshots_read(struct bch_fs *c)
        int ret = bch2_trans_run(c,
                for_each_btree_key(trans, iter, BTREE_ID_snapshots,
                                   POS_MIN, 0, k,
-                       bch2_mark_snapshot(trans, BTREE_ID_snapshots, 0, bkey_s_c_null, k, 0) ?:
+                       __bch2_mark_snapshot(trans, BTREE_ID_snapshots, 0, bkey_s_c_null, k, 0) ?:
                        bch2_snapshot_set_equiv(trans, k) ?:
                        bch2_check_snapshot_needs_deletion(trans, k)) ?:
                for_each_btree_key(trans, iter, BTREE_ID_snapshots,
index 94f35b2cfbb3427ca83ab6d5b423ab9b640bed99..bf5b200d189b082c8fe44a666be0777cff3e636b 100644 (file)
@@ -22,7 +22,7 @@ void bch2_snapshot_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
 int bch2_snapshot_invalid(struct bch_fs *, struct bkey_s_c,
                          enum bkey_invalid_flags, struct printbuf *);
 int bch2_mark_snapshot(struct btree_trans *, enum btree_id, unsigned,
-                      struct bkey_s_c, struct bkey_s_c, unsigned);
+                      struct bkey_s_c, struct bkey_s, unsigned);
 
 #define bch2_bkey_ops_snapshot ((struct bkey_ops) {            \
        .key_invalid    = bch2_snapshot_invalid,                \