]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/snapshot.c
Disable pristine-tar option in gbp.conf, since there is no pristine-tar branch.
[bcachefs-tools-debian] / libbcachefs / snapshot.c
index 96df4052ff7b93b8927daf7f8429b86fcf15a428..45f67e8b29eb67f188e5cfb32aa39e0b1ad1d625 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)
 {
@@ -806,11 +814,10 @@ static int check_snapshot(struct btree_trans *trans,
 
        real_depth = bch2_snapshot_depth(c, parent_id);
 
-       if (le32_to_cpu(s.depth) != real_depth &&
-           (c->sb.version_upgrade_complete < bcachefs_metadata_version_snapshot_skiplists ||
-            fsck_err(c, snapshot_bad_depth,
-                     "snapshot with incorrect depth field, should be %u:\n  %s",
-                     real_depth, (bch2_bkey_val_to_text(&buf, c, k), buf.buf)))) {
+       if (fsck_err_on(le32_to_cpu(s.depth) != real_depth,
+                       c, snapshot_bad_depth,
+                       "snapshot with incorrect depth field, should be %u:\n  %s",
+                       real_depth, (bch2_bkey_val_to_text(&buf, c, k), buf.buf))) {
                u = bch2_bkey_make_mut_typed(trans, iter, &k, 0, snapshot);
                ret = PTR_ERR_OR_ZERO(u);
                if (ret)
@@ -824,11 +831,9 @@ static int check_snapshot(struct btree_trans *trans,
        if (ret < 0)
                goto err;
 
-       if (!ret &&
-           (c->sb.version_upgrade_complete < bcachefs_metadata_version_snapshot_skiplists ||
-            fsck_err(c, snapshot_bad_skiplist,
-                     "snapshot with bad skiplist field:\n  %s",
-                     (bch2_bkey_val_to_text(&buf, c, k), buf.buf)))) {
+       if (fsck_err_on(!ret, c, snapshot_bad_skiplist,
+                       "snapshot with bad skiplist field:\n  %s",
+                       (bch2_bkey_val_to_text(&buf, c, k), buf.buf))) {
                u = bch2_bkey_make_mut_typed(trans, iter, &k, 0, snapshot);
                ret = PTR_ERR_OR_ZERO(u);
                if (ret)
@@ -1048,6 +1053,8 @@ static int create_snapids(struct btree_trans *trans, u32 parent, u32 tree,
                n->v.subvol     = cpu_to_le32(snapshot_subvols[i]);
                n->v.tree       = cpu_to_le32(tree);
                n->v.depth      = cpu_to_le32(depth);
+               n->v.btime.lo   = cpu_to_le64(bch2_current_time(c));
+               n->v.btime.hi   = 0;
 
                for (j = 0; j < ARRAY_SIZE(n->v.skip); j++)
                        n->v.skip[j] = cpu_to_le32(bch2_snapshot_skiplist_get(c, parent));
@@ -1055,7 +1062,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 +1671,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,
@@ -1676,5 +1683,5 @@ int bch2_snapshots_read(struct bch_fs *c)
 
 void bch2_fs_snapshots_exit(struct bch_fs *c)
 {
-       kfree(rcu_dereference_protected(c->snapshots, true));
+       kvfree(rcu_dereference_protected(c->snapshots, true));
 }