bcachefs: Switch data_update path to snapshot_id_list
authorKent Overstreet <kent.overstreet@gmail.com>
Thu, 14 Jul 2022 06:34:48 +0000 (02:34 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:35 +0000 (17:09 -0400)
snapshots_seen is becoming private to fsck, and snapshot_id_list is
actually what the data update path needs.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
fs/bcachefs/data_update.c
fs/bcachefs/subvolume.c
fs/bcachefs/subvolume.h

index f7bce89f84edc48b997ecbc4291d0e1c9d9870d8..6726bd6b9b07c51e861d5f5f124abc956b76d4a6 100644 (file)
@@ -22,13 +22,13 @@ static int insert_snapshot_whiteouts(struct btree_trans *trans,
        struct bch_fs *c = trans->c;
        struct btree_iter iter, update_iter;
        struct bkey_s_c k;
-       struct snapshots_seen s;
+       snapshot_id_list s;
        int ret;
 
        if (!btree_type_has_snapshots(id))
                return 0;
 
-       snapshots_seen_init(&s);
+       darray_init(&s);
 
        if (!bkey_cmp(old_pos, new_pos))
                return 0;
@@ -40,7 +40,6 @@ static int insert_snapshot_whiteouts(struct btree_trans *trans,
                             BTREE_ITER_NOT_EXTENTS|
                             BTREE_ITER_ALL_SNAPSHOTS);
        while (1) {
-next:
                k = bch2_btree_iter_prev(&iter);
                ret = bkey_err(k);
                if (ret)
@@ -51,11 +50,9 @@ next:
 
                if (bch2_snapshot_is_ancestor(c, k.k->p.snapshot, old_pos.snapshot)) {
                        struct bkey_i *update;
-                       u32 *i;
 
-                       darray_for_each(s.ids, i)
-                               if (bch2_snapshot_is_ancestor(c, k.k->p.snapshot, *i))
-                                       goto next;
+                       if (snapshot_list_has_ancestor(c, &s, k.k->p.snapshot))
+                               continue;
 
                        update = bch2_trans_kmalloc(trans, sizeof(struct bkey_i));
 
@@ -78,13 +75,13 @@ next:
                        if (ret)
                                break;
 
-                       ret = snapshots_seen_add(c, &s, k.k->p.snapshot);
+                       ret = snapshot_list_add(c, &s, k.k->p.snapshot);
                        if (ret)
                                break;
                }
        }
        bch2_trans_iter_exit(trans, &iter);
-       darray_exit(&s.ids);
+       darray_exit(&s);
 
        return ret;
 }
index 083eb432458367e28315282aca4585c20a3569d0..1865c5b3a2c5a5a3be73001f9b77603d9ab6be49 100644 (file)
@@ -565,13 +565,6 @@ err:
        return ret;
 }
 
-static int snapshot_id_add(snapshot_id_list *s, u32 id)
-{
-       BUG_ON(snapshot_list_has_id(s, id));
-
-       return darray_push(s, id);
-}
-
 static int bch2_snapshot_delete_keys_btree(struct btree_trans *trans,
                                           snapshot_id_list *deleted,
                                           enum btree_id btree_id)
@@ -617,7 +610,7 @@ static int bch2_snapshot_delete_keys_btree(struct btree_trans *trans,
                        if (ret)
                                break;
                } else {
-                       ret = snapshot_id_add(&equiv_seen, equiv);
+                       ret = snapshot_list_add(c, &equiv_seen, equiv);
                        if (ret)
                                break;
                }
@@ -693,7 +686,7 @@ static void bch2_delete_dead_snapshots_work(struct work_struct *work)
 
                snap = bkey_s_c_to_snapshot(k);
                if (BCH_SNAPSHOT_DELETED(snap.v)) {
-                       ret = snapshot_id_add(&deleted, k.k->p.offset);
+                       ret = snapshot_list_add(c, &deleted, k.k->p.offset);
                        if (ret)
                                break;
                }
@@ -921,7 +914,7 @@ int bch2_subvolume_wait_for_pagecache_and_delete_hook(struct btree_trans *trans,
 
        mutex_lock(&c->snapshots_unlinked_lock);
        if (!snapshot_list_has_id(&c->snapshots_unlinked, h->subvol))
-               ret = snapshot_id_add(&c->snapshots_unlinked, h->subvol);
+               ret = snapshot_list_add(c, &c->snapshots_unlinked, h->subvol);
        mutex_unlock(&c->snapshots_unlinked_lock);
 
        if (ret)
index b1739d29c7d40af0a6082e42c4c5e0ea1cb567fb..28dbd0968f3df540e3282cb9be2af2007bab3590 100644 (file)
@@ -93,6 +93,27 @@ static inline bool snapshot_list_has_id(snapshot_id_list *s, u32 id)
        return false;
 }
 
+static inline bool snapshot_list_has_ancestor(struct bch_fs *c, snapshot_id_list *s, u32 id)
+{
+       u32 *i;
+
+       darray_for_each(*s, i)
+               if (bch2_snapshot_is_ancestor(c, id, *i))
+                       return true;
+       return false;
+}
+
+static inline int snapshot_list_add(struct bch_fs *c, snapshot_id_list *s, u32 id)
+{
+       int ret;
+
+       BUG_ON(snapshot_list_has_id(s, id));
+       ret = darray_push(s, id);
+       if (ret)
+               bch_err(c, "error reallocating snapshot_id_list (size %zu)", s->size);
+       return ret;
+}
+
 int bch2_fs_snapshots_check(struct bch_fs *);
 void bch2_fs_snapshots_exit(struct bch_fs *);
 int bch2_fs_snapshots_start(struct bch_fs *);