]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
bcachefs: bch2_snapshot_exists()
authorKent Overstreet <kent.overstreet@linux.dev>
Mon, 9 Dec 2024 06:31:43 +0000 (01:31 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 21 Dec 2024 06:36:23 +0000 (01:36 -0500)
bch2_snapshot_equiv() is going away; convert users that just wanted to
know if the snapshot exists to something better

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/data_update.c
fs/bcachefs/snapshot.c
fs/bcachefs/snapshot.h
fs/bcachefs/subvolume_types.h

index 31b2aeb0c6e6108e333907646284cec605d7c93c..585214931e056489a3fca2eaf8354c223b8b0027 100644 (file)
@@ -620,7 +620,7 @@ int bch2_data_update_init(struct btree_trans *trans,
         * and we have to check for this because we go rw before repairing the
         * snapshots table - just skip it, we can move it later.
         */
-       if (unlikely(k.k->p.snapshot && !bch2_snapshot_equiv(c, k.k->p.snapshot)))
+       if (unlikely(k.k->p.snapshot && !bch2_snapshot_exists(c, k.k->p.snapshot)))
                return -BCH_ERR_data_update_done;
 
        if (!bkey_get_dev_refs(c, k))
index f65f7b191d31d359b298dc3493e48924c397f8d5..ac664888847f81494ab58ff3f1cafa104645f988 100644 (file)
@@ -318,6 +318,7 @@ static int __bch2_mark_snapshot(struct btree_trans *trans,
        if (new.k->type == KEY_TYPE_snapshot) {
                struct bkey_s_c_snapshot s = bkey_s_c_to_snapshot(new);
 
+               t->live         = true;
                t->parent       = le32_to_cpu(s.v->parent);
                t->children[0]  = le32_to_cpu(s.v->children[0]);
                t->children[1]  = le32_to_cpu(s.v->children[1]);
@@ -914,7 +915,7 @@ static int check_snapshot_exists(struct btree_trans *trans, u32 id)
 {
        struct bch_fs *c = trans->c;
 
-       if (bch2_snapshot_equiv(c, id))
+       if (bch2_snapshot_exists(c, id))
                return 0;
 
        /* Do we need to reconstruct the snapshot_tree entry as well? */
@@ -1062,7 +1063,7 @@ int bch2_reconstruct_snapshots(struct bch_fs *c)
                snapshot_id_list_to_text(&buf, t);
 
                darray_for_each(*t, id) {
-                       if (fsck_err_on(!bch2_snapshot_equiv(c, *id),
+                       if (fsck_err_on(!bch2_snapshot_exists(c, *id),
                                        trans, snapshot_node_missing,
                                        "snapshot node %u from tree %s missing, recreate?", *id, buf.buf)) {
                                if (t->nr > 1) {
@@ -1095,7 +1096,7 @@ int bch2_check_key_has_snapshot(struct btree_trans *trans,
        struct printbuf buf = PRINTBUF;
        int ret = 0;
 
-       if (fsck_err_on(!bch2_snapshot_equiv(c, k.k->p.snapshot),
+       if (fsck_err_on(!bch2_snapshot_exists(c, k.k->p.snapshot),
                        trans, bkey_in_missing_snapshot,
                        "key in missing snapshot %s, delete?",
                        (bch2_btree_id_to_text(&buf, iter->btree_id),
index ae23d45fad6669cb10d88d368761c0174947ab0f..3ff0ffa774f593303bdbedca63392f8d9df268be 100644 (file)
@@ -119,6 +119,21 @@ static inline u32 bch2_snapshot_root(struct bch_fs *c, u32 id)
        return id;
 }
 
+static inline bool __bch2_snapshot_exists(struct bch_fs *c, u32 id)
+{
+       const struct snapshot_t *s = snapshot_t(c, id);
+       return s ? s->live : 0;
+}
+
+static inline bool bch2_snapshot_exists(struct bch_fs *c, u32 id)
+{
+       rcu_read_lock();
+       bool ret = __bch2_snapshot_exists(c, id);
+       rcu_read_unlock();
+
+       return ret;
+}
+
 static inline u32 __bch2_snapshot_equiv(struct bch_fs *c, u32 id)
 {
        const struct snapshot_t *s = snapshot_t(c, id);
index f2ec4277c2a5088cd770a9527f9ccc247bc3064d..8a7f7e87c381de71257fc7e9de776b30c20ea37f 100644 (file)
@@ -9,6 +9,7 @@ typedef DARRAY(u32) snapshot_id_list;
 #define IS_ANCESTOR_BITMAP     128
 
 struct snapshot_t {
+       bool                    live;
        u32                     parent;
        u32                     skip[3];
        u32                     depth;