]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
Update bcachefs sources to 24bdb6fed91c bcachefs: bch2_btree_id_str()
authorKent Overstreet <kent.overstreet@linux.dev>
Fri, 20 Oct 2023 02:52:02 +0000 (22:52 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Fri, 20 Oct 2023 02:56:59 +0000 (22:56 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
34 files changed:
.bcachefs_revision
cmd_data.c
cmd_kill_btree_node.c
cmd_list_journal.c
include/linux/compiler.h
libbcachefs.c
libbcachefs/alloc_background.c
libbcachefs/backpointers.c
libbcachefs/bbpos.h
libbcachefs/bcachefs.h
libbcachefs/bkey_methods.c
libbcachefs/btree_cache.c
libbcachefs/btree_cache.h
libbcachefs/btree_gc.c
libbcachefs/btree_io.c
libbcachefs/btree_iter.c
libbcachefs/btree_key_cache.c
libbcachefs/btree_trans_commit.c
libbcachefs/debug.c
libbcachefs/fsck.c
libbcachefs/journal_io.c
libbcachefs/move.c
libbcachefs/opts.c
libbcachefs/opts.h
libbcachefs/recovery.c
libbcachefs/recovery_types.h
libbcachefs/snapshot.c
libbcachefs/snapshot.h
libbcachefs/subvolume.c
libbcachefs/sysfs.c
libbcachefs/trace.h
rust-src/bch_bindgen/build.rs
rust-src/bch_bindgen/src/lib.rs
tools-util.c

index 6f98bb843d8120802ddd579fa0efe74731a343cf..6344df96a654626cbd9066879c1acd9f2a5b0094 100644 (file)
@@ -1 +1 @@
-a180af9dd349d9819b13af43f877bea4f94c1c79
+24bdb6fed91c0ebbee0bc71ac622a8439be1696f
index 160eb918b8947a6e7d265860e26e7e55f91e17af..6d709883720d7a5dc137105d99cc234056e860a0 100644 (file)
@@ -103,7 +103,7 @@ int cmd_data_job(int argc, char *argv[])
                switch (opt) {
                case 'b':
                        op.start_btree = read_string_list_or_die(optarg,
-                                               bch2_btree_ids, "btree id");
+                                               __bch2_btree_ids, "btree id");
                        op.end_btree = op.start_btree;
                        break;
                case 's':
index 83389bc4df8974f38b63bc4b6de624547b6e5ea1..21b78f1cd5cd6c1d16ec4e000fb89a45aeff8798 100644 (file)
@@ -41,7 +41,7 @@ int cmd_kill_btree_node(int argc, char *argv[])
                switch (opt) {
                case 'b':
                        btree_id = read_string_list_or_die(optarg,
-                                               bch2_btree_ids, "btree id");
+                                               __bch2_btree_ids, "btree id");
                        break;
                case 'l':
                        if (kstrtouint(optarg, 10, &level) || level >= BTREE_MAX_DEPTH)
index 655bfe2e686e430416850c0d1fe9a54182371923..70f7e669207ef9d3f7600f75586e7fb983479089 100644 (file)
@@ -252,7 +252,7 @@ int cmd_list_journal(int argc, char *argv[])
                        darray_push(&transaction_filter, bbpos_parse(optarg));
                        break;
                case 'k':
-                       darray_push(&key_filter, read_string_list_or_die(optarg, bch2_btree_ids, "btree id"));
+                       darray_push(&key_filter, read_string_list_or_die(optarg, __bch2_btree_ids, "btree id"));
                        break;
                case 'v':
                        opt_set(opts, verbose, true);
index 61beee94871f065bef3157ab36bd668508a8c290..577869062fe27a5602047375c4e297aeb529c710 100644 (file)
 #define __same_type(a, b)      __builtin_types_compatible_p(typeof(a), typeof(b))
 #define fallthrough            __attribute__((__fallthrough__))
 #define __noreturn             __attribute__((__noreturn__))
+
+#ifndef __counted_by
 #define __counted_by(nr)
+#endif
 
 #define ___PASTE(a,b) a##b
 #define __PASTE(a,b) ___PASTE(a,b)
index 577ccac170a78c4a13fdcef7b07920af18c1dbf8..016ff882ddc0f21bfbbad05c7ea6b95712f32114 100644 (file)
@@ -509,7 +509,7 @@ int bchu_data(struct bchfs_handle fs, struct bch_ioctl_data cmd)
                case BCH_DATA_btree:
                case BCH_DATA_user:
                        printf(" %s:%llu:%llu",
-                              bch2_btree_ids[e.p.btree_id],
+                              bch2_btree_id_str(e.p.btree_id),
                               e.p.pos.inode,
                               e.p.pos.offset);
                }
index 2d516207e223f097d75c056288620297bfcbedb6..455ee0b47f314c0205b5eb2d988df5657d43a04b 100644 (file)
@@ -727,7 +727,7 @@ static int bch2_bucket_do_index(struct btree_trans *trans,
                        "incorrect key when %s %s:%llu:%llu:0 (got %s should be %s)\n"
                        "  for %s",
                        set ? "setting" : "clearing",
-                       bch2_btree_ids[btree],
+                       bch2_btree_id_str(btree),
                        iter.pos.inode,
                        iter.pos.offset,
                        bch2_bkey_types[old.k->type],
@@ -1245,7 +1245,7 @@ static noinline_for_stack int __bch2_check_discard_freespace_key(struct btree_tr
 
        if (fsck_err_on(!bch2_dev_bucket_exists(c, pos), c,
                        "entry in %s btree for nonexistant dev:bucket %llu:%llu",
-                       bch2_btree_ids[iter->btree_id], pos.inode, pos.offset))
+                       bch2_btree_id_str(iter->btree_id), pos.inode, pos.offset))
                goto delete;
 
        a = bch2_alloc_to_v4(alloc_k, &a_convert);
@@ -1255,7 +1255,7 @@ static noinline_for_stack int __bch2_check_discard_freespace_key(struct btree_tr
                         genbits != alloc_freespace_genbits(*a)), c,
                        "%s\n  incorrectly set at %s:%llu:%llu:0 (free %u, genbits %llu should be %llu)",
                        (bch2_bkey_val_to_text(&buf, c, alloc_k), buf.buf),
-                       bch2_btree_ids[iter->btree_id],
+                       bch2_btree_id_str(iter->btree_id),
                        iter->pos.inode,
                        iter->pos.offset,
                        a->data_type == state,
index cc856150a948ea7859feedcd0bb99493f328fd04..e74295c21a03e3d315e85b997844052200a25510 100644 (file)
@@ -55,7 +55,7 @@ int bch2_backpointer_invalid(const struct bch_fs *c, struct bkey_s_c k,
 void bch2_backpointer_to_text(struct printbuf *out, const struct bch_backpointer *bp)
 {
        prt_printf(out, "btree=%s l=%u offset=%llu:%u len=%u pos=",
-              bch2_btree_ids[bp->btree_id],
+              bch2_btree_id_str(bp->btree_id),
               bp->level,
               (u64) (bp->bucket_offset >> MAX_EXTENT_COMPRESS_RATIO_SHIFT),
               (u32) bp->bucket_offset & ~(~0U << MAX_EXTENT_COMPRESS_RATIO_SHIFT),
@@ -453,7 +453,7 @@ fsck_err:
        return ret;
 missing:
        prt_printf(&buf, "missing backpointer for btree=%s l=%u ",
-              bch2_btree_ids[bp.btree_id], bp.level);
+              bch2_btree_id_str(bp.btree_id), bp.level);
        bch2_bkey_val_to_text(&buf, c, orig_k);
        prt_printf(&buf, "\nbp pos ");
        bch2_bpos_to_text(&buf, bp_iter.pos);
index 1fbed1f8378d1aeeca4d781f9fa3c64583e2a833..0038bc28ba8c01b45b8962571ed37f107c1447b0 100644 (file)
@@ -3,6 +3,7 @@
 #define _BCACHEFS_BBPOS_H
 
 #include "bkey_methods.h"
+#include "btree_cache.h"
 
 struct bbpos {
        enum btree_id           btree;
@@ -40,7 +41,7 @@ static inline struct bbpos bbpos_successor(struct bbpos pos)
 
 static inline void bch2_bbpos_to_text(struct printbuf *out, struct bbpos pos)
 {
-       prt_str(out, bch2_btree_ids[pos.btree]);
+       prt_str(out, bch2_btree_id_str(pos.btree));
        prt_char(out, ':');
        bch2_bpos_to_text(out, pos.pos);
 }
index 53ffa88cae16cab4e883459dae1fb61424b3b7ec..9863571feebf38503f655218c855a06c1efb4a62 100644 (file)
@@ -578,7 +578,7 @@ enum {
        BCH_FS_INITIAL_GC_UNFIXED,      /* kill when we enumerate fsck errors */
        BCH_FS_NEED_ANOTHER_GC,
 
-       BCH_FS_HAVE_DELETED_SNAPSHOTS,
+       BCH_FS_NEED_DELETE_DEAD_SNAPSHOTS,
 
        /* errors: */
        BCH_FS_ERROR,
index d9fb1fc81f1e17fb45dedf76349177a0abc9f22a..d9711a27a71e1a39f6e56f4f46eab7d470973cb9 100644 (file)
@@ -3,6 +3,7 @@
 #include "bcachefs.h"
 #include "backpointers.h"
 #include "bkey_methods.h"
+#include "btree_cache.h"
 #include "btree_types.h"
 #include "alloc_background.h"
 #include "dirent.h"
@@ -164,7 +165,7 @@ int __bch2_bkey_invalid(struct bch_fs *c, struct bkey_s_c k,
        if (flags & BKEY_INVALID_COMMIT  &&
            !(bch2_key_types_allowed[type] & BIT_ULL(k.k->type))) {
                prt_printf(err, "invalid key type for btree %s (%s)",
-                          bch2_btree_ids[type], bch2_bkey_types[k.k->type]);
+                          bch2_btree_id_str(type), bch2_bkey_types[k.k->type]);
                return -BCH_ERR_invalid_bkey;
        }
 
index 7c6769cd17b33338a2ba03b416aa8c7950a0fe77..9a7d54a66047b6961054c091f696ca3e6c85dc60 100644 (file)
@@ -832,12 +832,12 @@ static noinline void btree_bad_header(struct bch_fs *c, struct btree *b)
               "btree node header doesn't match ptr\n"
               "btree %s level %u\n"
               "ptr: ",
-              bch2_btree_ids[b->c.btree_id], b->c.level);
+              bch2_btree_id_str(b->c.btree_id), b->c.level);
        bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(&b->key));
 
        prt_printf(&buf, "\nheader: btree %s level %llu\n"
               "min ",
-              bch2_btree_ids[BTREE_NODE_ID(b->data)],
+              bch2_btree_id_str(BTREE_NODE_ID(b->data)),
               BTREE_NODE_LEVEL(b->data));
        bch2_bpos_to_text(&buf, b->data->min_key);
 
@@ -1200,8 +1200,21 @@ wait_on_io:
        six_unlock_intent(&b->c.lock);
 }
 
-void bch2_btree_node_to_text(struct printbuf *out, struct bch_fs *c,
-                            const struct btree *b)
+const char *bch2_btree_id_str(enum btree_id btree)
+{
+       return btree < BTREE_ID_NR ? __bch2_btree_ids[btree] : "(unknown)";
+}
+
+void bch2_btree_pos_to_text(struct printbuf *out, struct bch_fs *c, const struct btree *b)
+{
+       prt_printf(out, "%s level %u/%u\n  ",
+              bch2_btree_id_str(b->c.btree_id),
+              b->c.level,
+              bch2_btree_id_root(c, b->c.btree_id)->level);
+       bch2_bkey_val_to_text(out, c, bkey_i_to_s_c(&b->key));
+}
+
+void bch2_btree_node_to_text(struct printbuf *out, struct bch_fs *c, const struct btree *b)
 {
        struct bset_stats stats;
 
index 00c9b92183e7969839d48240e3e4b05498a98ed7..bfe1d7482cbc8d5205ddb87edf801e251c6206a2 100644 (file)
@@ -123,8 +123,9 @@ static inline struct btree *btree_node_root(struct bch_fs *c, struct btree *b)
        return bch2_btree_id_root(c, b->c.btree_id)->b;
 }
 
-void bch2_btree_node_to_text(struct printbuf *, struct bch_fs *,
-                            const struct btree *);
+const char *bch2_btree_id_str(enum btree_id);
+void bch2_btree_pos_to_text(struct printbuf *, struct bch_fs *, const struct btree *);
+void bch2_btree_node_to_text(struct printbuf *, struct bch_fs *, const struct btree *);
 void bch2_btree_cache_to_text(struct printbuf *, const struct btree_cache *);
 
 #endif /* _BCACHEFS_BTREE_CACHE_H */
index 97fbd833115800e4ed8a8b1b0577fa1a6f359af0..fc5513a7719e516298c57d6f6b14cce178baf82e 100644 (file)
@@ -101,7 +101,7 @@ static int bch2_gc_check_topology(struct bch_fs *c,
                                  "btree node with incorrect min_key at btree %s level %u:\n"
                                  "  prev %s\n"
                                  "  cur %s",
-                                 bch2_btree_ids[b->c.btree_id], b->c.level,
+                                 bch2_btree_id_str(b->c.btree_id), b->c.level,
                                  buf1.buf, buf2.buf) &&
                            should_restart_for_topology_repair(c)) {
                                bch_info(c, "Halting mark and sweep to start topology repair pass");
@@ -129,7 +129,7 @@ static int bch2_gc_check_topology(struct bch_fs *c,
                          "btree node with incorrect max_key at btree %s level %u:\n"
                          "  %s\n"
                          "  expected %s",
-                         bch2_btree_ids[b->c.btree_id], b->c.level,
+                         bch2_btree_id_str(b->c.btree_id), b->c.level,
                          buf1.buf, buf2.buf) &&
                    should_restart_for_topology_repair(c)) {
                        bch_info(c, "Halting mark and sweep to start topology repair pass");
@@ -290,7 +290,7 @@ static int btree_repair_node_boundaries(struct bch_fs *c, struct btree *b,
                                "btree node overwritten by next node at btree %s level %u:\n"
                                "  node %s\n"
                                "  next %s",
-                               bch2_btree_ids[b->c.btree_id], b->c.level,
+                               bch2_btree_id_str(b->c.btree_id), b->c.level,
                                buf1.buf, buf2.buf)) {
                        ret = DROP_PREV_NODE;
                        goto out;
@@ -301,7 +301,7 @@ static int btree_repair_node_boundaries(struct bch_fs *c, struct btree *b,
                                "btree node with incorrect max_key at btree %s level %u:\n"
                                "  node %s\n"
                                "  next %s",
-                               bch2_btree_ids[b->c.btree_id], b->c.level,
+                               bch2_btree_id_str(b->c.btree_id), b->c.level,
                                buf1.buf, buf2.buf))
                        ret = set_node_max(c, prev,
                                           bpos_predecessor(cur->data->min_key));
@@ -313,7 +313,7 @@ static int btree_repair_node_boundaries(struct bch_fs *c, struct btree *b,
                                "btree node overwritten by prev node at btree %s level %u:\n"
                                "  prev %s\n"
                                "  node %s",
-                               bch2_btree_ids[b->c.btree_id], b->c.level,
+                               bch2_btree_id_str(b->c.btree_id), b->c.level,
                                buf1.buf, buf2.buf)) {
                        ret = DROP_THIS_NODE;
                        goto out;
@@ -323,7 +323,7 @@ static int btree_repair_node_boundaries(struct bch_fs *c, struct btree *b,
                                "btree node with incorrect min_key at btree %s level %u:\n"
                                "  prev %s\n"
                                "  node %s",
-                               bch2_btree_ids[b->c.btree_id], b->c.level,
+                               bch2_btree_id_str(b->c.btree_id), b->c.level,
                                buf1.buf, buf2.buf))
                        ret = set_node_min(c, cur, expected_start);
        }
@@ -347,7 +347,7 @@ static int btree_repair_node_end(struct bch_fs *c, struct btree *b,
                        "btree node with incorrect max_key at btree %s level %u:\n"
                        "  %s\n"
                        "  expected %s",
-                       bch2_btree_ids[b->c.btree_id], b->c.level,
+                       bch2_btree_id_str(b->c.btree_id), b->c.level,
                        buf1.buf, buf2.buf)) {
                ret = set_node_max(c, child, b->key.k.p);
                if (ret)
@@ -398,7 +398,7 @@ again:
                if (mustfix_fsck_err_on(ret == -EIO, c,
                                "Topology repair: unreadable btree node at btree %s level %u:\n"
                                "  %s",
-                               bch2_btree_ids[b->c.btree_id],
+                               bch2_btree_id_str(b->c.btree_id),
                                b->c.level - 1,
                                buf.buf)) {
                        bch2_btree_node_evict(trans, cur_k.k);
@@ -506,7 +506,7 @@ again:
        if (mustfix_fsck_err_on(!have_child, c,
                        "empty interior btree node at btree %s level %u\n"
                        "  %s",
-                       bch2_btree_ids[b->c.btree_id],
+                       bch2_btree_id_str(b->c.btree_id),
                        b->c.level, buf.buf))
                ret = DROP_THIS_NODE;
 err:
@@ -970,7 +970,7 @@ static int bch2_gc_btree_init_recurse(struct btree_trans *trans, struct btree *b
                                          FSCK_NO_RATELIMIT,
                                          "Unreadable btree node at btree %s level %u:\n"
                                          "  %s",
-                                         bch2_btree_ids[b->c.btree_id],
+                                         bch2_btree_id_str(b->c.btree_id),
                                          b->c.level - 1,
                                          (printbuf_reset(&buf),
                                           bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(cur.k)), buf.buf)) &&
index a869cf6ac7c6b94c84cba88bb0a3eeaac0d98d68..7bf3ee25bc32e878f81cbe8a656208787ffdd27b 100644 (file)
@@ -510,16 +510,6 @@ void bch2_btree_init_next(struct btree_trans *trans, struct btree *b)
                bch2_trans_node_reinit_iter(trans, b);
 }
 
-static void btree_pos_to_text(struct printbuf *out, struct bch_fs *c,
-                         struct btree *b)
-{
-       prt_printf(out, "%s level %u/%u\n  ",
-              bch2_btree_ids[b->c.btree_id],
-              b->c.level,
-              bch2_btree_id_root(c, b->c.btree_id)->level);
-       bch2_bkey_val_to_text(out, c, bkey_i_to_s_c(&b->key));
-}
-
 static void btree_err_msg(struct printbuf *out, struct bch_fs *c,
                          struct bch_dev *ca,
                          struct btree *b, struct bset *i,
@@ -532,7 +522,7 @@ static void btree_err_msg(struct printbuf *out, struct bch_fs *c,
        if (ca)
                prt_printf(out, "on %s ", ca->name);
        prt_printf(out, "at btree ");
-       btree_pos_to_text(out, c, b);
+       bch2_btree_pos_to_text(out, c, b);
 
        prt_printf(out, "\n  node offset %u", b->written);
        if (i)
@@ -1177,7 +1167,7 @@ static void btree_node_read_work(struct work_struct *work)
                }
 start:
                printbuf_reset(&buf);
-               btree_pos_to_text(&buf, c, b);
+               bch2_btree_pos_to_text(&buf, c, b);
                bch2_dev_io_err_on(bio->bi_status, ca, "btree read error %s for %s",
                                   bch2_blk_status_to_str(bio->bi_status), buf.buf);
                if (rb->have_ioref)
@@ -1213,7 +1203,7 @@ start:
                printbuf_reset(&buf);
                bch2_bpos_to_text(&buf, b->key.k.p);
                bch_info(c, "%s: rewriting btree node at btree=%s level=%u %s due to error",
-                        __func__, bch2_btree_ids[b->c.btree_id], b->c.level, buf.buf);
+                        __func__, bch2_btree_id_str(b->c.btree_id), b->c.level, buf.buf);
 
                bch2_btree_node_rewrite_async(c, b);
        }
@@ -1524,7 +1514,7 @@ void bch2_btree_node_read(struct bch_fs *c, struct btree *b,
                struct printbuf buf = PRINTBUF;
 
                prt_str(&buf, "btree node read error: no device to read from\n at ");
-               btree_pos_to_text(&buf, c, b);
+               bch2_btree_pos_to_text(&buf, c, b);
                bch_err(c, "%s", buf.buf);
 
                if (c->recovery_passes_explicit & BIT_ULL(BCH_RECOVERY_PASS_check_topology) &&
index 4cee5e6cd7f4aa5c7270d2f766ada56a6cef6ba3..eff7630a8e6ecf3184d1879804e5fd974c0f28f2 100644 (file)
@@ -362,7 +362,7 @@ void bch2_assert_pos_locked(struct btree_trans *trans, enum btree_id id,
        bch2_bpos_to_text(&buf, pos);
 
        panic("not locked: %s %s%s\n",
-             bch2_btree_ids[id], buf.buf,
+             bch2_btree_id_str(id), buf.buf,
              key_cache ? " cached" : "");
 }
 
@@ -1371,7 +1371,7 @@ void bch2_trans_updates_to_text(struct printbuf *buf, struct btree_trans *trans)
                struct bkey_s_c old = { &i->old_k, i->old_v };
 
                prt_printf(buf, "update: btree=%s cached=%u %pS",
-                      bch2_btree_ids[i->btree_id],
+                      bch2_btree_id_str(i->btree_id),
                       i->cached,
                       (void *) i->ip_allocated);
                prt_newline(buf);
@@ -1387,7 +1387,7 @@ void bch2_trans_updates_to_text(struct printbuf *buf, struct btree_trans *trans)
 
        trans_for_each_wb_update(trans, wb) {
                prt_printf(buf, "update: btree=%s wb=1 %pS",
-                      bch2_btree_ids[wb->btree],
+                      bch2_btree_id_str(wb->btree),
                       (void *) i->ip_allocated);
                prt_newline(buf);
 
@@ -1416,7 +1416,7 @@ void bch2_btree_path_to_text(struct printbuf *out, struct btree_path *path)
                   path->idx, path->ref, path->intent_ref,
                   path->preserve ? 'P' : ' ',
                   path->should_be_locked ? 'S' : ' ',
-                  bch2_btree_ids[path->btree_id],
+                  bch2_btree_id_str(path->btree_id),
                   path->level);
        bch2_bpos_to_text(out, path->pos);
 
@@ -3027,7 +3027,7 @@ leaked:
        trans_for_each_path(trans, path)
                if (path->ref)
                        printk(KERN_ERR "  btree %s %pS\n",
-                              bch2_btree_ids[path->btree_id],
+                              bch2_btree_id_str(path->btree_id),
                               (void *) path->ip_allocated);
        /* Be noisy about this: */
        bch2_fatal_error(c);
@@ -3102,7 +3102,7 @@ bch2_btree_bkey_cached_common_to_text(struct printbuf *out,
 
        prt_tab(out);
        prt_printf(out, "%px %c l=%u %s:", b, b->cached ? 'c' : 'b',
-                  b->level, bch2_btree_ids[b->btree_id]);
+                  b->level, bch2_btree_id_str(b->btree_id));
        bch2_bpos_to_text(out, btree_node_pos(b));
 
        prt_tab(out);
@@ -3132,7 +3132,7 @@ void bch2_btree_trans_to_text(struct printbuf *out, struct btree_trans *trans)
                       path->idx,
                       path->cached ? 'c' : 'b',
                       path->level,
-                      bch2_btree_ids[path->btree_id]);
+                      bch2_btree_id_str(path->btree_id));
                bch2_bpos_to_text(out, path->pos);
                prt_newline(out);
 
index 1407f69140c2060c4f85ccda0f4f59d18f5e2304..19f98c26cfaaac8a353440216e22ec746e4d2c18 100644 (file)
@@ -325,7 +325,7 @@ btree_key_cache_create(struct btree_trans *trans, struct btree_path *path)
                ck = bkey_cached_reuse(bc);
                if (unlikely(!ck)) {
                        bch_err(c, "error allocating memory for key cache item, btree %s",
-                               bch2_btree_ids[path->btree_id]);
+                               bch2_btree_id_str(path->btree_id));
                        return ERR_PTR(-BCH_ERR_ENOMEM_btree_key_cache_create);
                }
 
@@ -408,7 +408,7 @@ static int btree_key_cache_fill(struct btree_trans *trans,
                        new_k = kmalloc(new_u64s * sizeof(u64), GFP_KERNEL);
                        if (!new_k) {
                                bch_err(trans->c, "error allocating memory for key cache key, btree %s u64s %u",
-                                       bch2_btree_ids[ck->key.btree_id], new_u64s);
+                                       bch2_btree_id_str(ck->key.btree_id), new_u64s);
                                ret = -BCH_ERR_ENOMEM_btree_key_cache_fill;
                                goto err;
                        }
index 04c1f4610972599686c18ada9591a1f83dbd1557..5fb0903e5bd27726280692720980883d3635eb92 100644 (file)
@@ -349,7 +349,7 @@ static int btree_key_can_insert_cached(struct btree_trans *trans, unsigned flags
        new_k           = krealloc(ck->k, new_u64s * sizeof(u64), GFP_NOFS);
        if (!new_k) {
                bch_err(c, "error allocating memory for key cache key, btree %s u64s %u",
-                       bch2_btree_ids[path->btree_id], new_u64s);
+                       bch2_btree_id_str(path->btree_id), new_u64s);
                return -BCH_ERR_ENOMEM_btree_key_cache_insert;
        }
 
index 75a3dc7cbd470da758750e612b187f16e34e8eb1..57c5128db173f4579168c71b8c67749b1d63004c 100644 (file)
@@ -517,7 +517,7 @@ static void bch2_cached_btree_node_to_text(struct printbuf *out, struct bch_fs *
 
        prt_printf(out, "%px btree=%s l=%u ",
               b,
-              bch2_btree_ids[b->c.btree_id],
+              bch2_btree_id_str(b->c.btree_id),
               b->c.level);
        prt_newline(out);
 
@@ -919,18 +919,18 @@ void bch2_fs_debug_init(struct bch_fs *c)
             bd < c->btree_debug + ARRAY_SIZE(c->btree_debug);
             bd++) {
                bd->id = bd - c->btree_debug;
-               debugfs_create_file(bch2_btree_ids[bd->id],
+               debugfs_create_file(bch2_btree_id_str(bd->id),
                                    0400, c->btree_debug_dir, bd,
                                    &btree_debug_ops);
 
                snprintf(name, sizeof(name), "%s-formats",
-                        bch2_btree_ids[bd->id]);
+                        bch2_btree_id_str(bd->id));
 
                debugfs_create_file(name, 0400, c->btree_debug_dir, bd,
                                    &btree_format_debug_ops);
 
                snprintf(name, sizeof(name), "%s-bfloat-failed",
-                        bch2_btree_ids[bd->id]);
+                        bch2_btree_id_str(bd->id));
 
                debugfs_create_file(name, 0400, c->btree_debug_dir, bd,
                                    &bfloat_failed_debug_ops);
index b8f9e7475dc5f744ba9545c3499b627f5f122df0..f26b824e70a84bedd1d16c45ea966b4f8589971c 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "bcachefs.h"
 #include "bkey_buf.h"
+#include "btree_cache.h"
 #include "btree_update.h"
 #include "buckets.h"
 #include "darray.h"
@@ -444,9 +445,10 @@ static int snapshots_seen_update(struct bch_fs *c, struct snapshots_seen *s,
                if (i->equiv == n.equiv) {
                        bch_err(c, "snapshot deletion did not finish:\n"
                                "  duplicate keys in btree %s at %llu:%llu snapshots %u, %u (equiv %u)\n",
-                               bch2_btree_ids[btree_id],
+                               bch2_btree_id_str(btree_id),
                                pos.inode, pos.offset,
                                i->id, n.id, n.equiv);
+                       set_bit(BCH_FS_NEED_DELETE_DEAD_SNAPSHOTS, &c->flags);
                        return bch2_run_explicit_recovery_pass(c, BCH_RECOVERY_PASS_delete_dead_snapshots);
                }
        }
@@ -808,7 +810,7 @@ out:
        return ret;
 bad_hash:
        if (fsck_err(c, "hash table key at wrong offset: btree %s inode %llu offset %llu, hashed to %llu\n%s",
-                    bch2_btree_ids[desc.btree_id], hash_k.k->p.inode, hash_k.k->p.offset, hash,
+                    bch2_btree_id_str(desc.btree_id), hash_k.k->p.inode, hash_k.k->p.offset, hash,
                     (printbuf_reset(&buf),
                      bch2_bkey_val_to_text(&buf, c, hash_k), buf.buf))) {
                ret = hash_redo_key(trans, desc, hash_info, k_iter, hash_k);
index 6a3d6a374e9cc4385547eaf8a32894cfda15b49e..b29ece313e443c681a7b0720caf5a7d4267c7d4a 100644 (file)
@@ -369,7 +369,7 @@ static void journal_entry_btree_keys_to_text(struct printbuf *out, struct bch_fs
                        prt_newline(out);
                        prt_printf(out, "%s: ", bch2_jset_entry_types[entry->type]);
                }
-               prt_printf(out, "btree=%s l=%u ", bch2_btree_ids[entry->btree_id], entry->level);
+               prt_printf(out, "btree=%s l=%u ", bch2_btree_id_str(entry->btree_id), entry->level);
                bch2_bkey_val_to_text(out, c, bkey_i_to_s_c(k));
                first = false;
        }
index 39a14e3216807d222fc11856fa285448f4a24ca3..82f60c7883ba6b08396e763c4eeaea0328d07b44 100644 (file)
@@ -1110,7 +1110,7 @@ static void bch2_moving_ctxt_to_text(struct printbuf *out, struct bch_fs *c, str
 
        prt_printf(out, " data type %s btree_id %s position: ",
                   bch2_data_types[stats->data_type],
-                  bch2_btree_ids[stats->btree_id]);
+                  bch2_btree_id_str(stats->btree_id));
        bch2_bpos_to_text(out, stats->pos);
        prt_newline(out);
        printbuf_indent_add(out, 2);
index 232f50c73a9452efa01cfa97436588bb42b1fc87..8294f56e45d5a503821e1bf1d15539f3bee8ae89 100644 (file)
@@ -42,9 +42,8 @@ const char * const bch2_sb_compat[] = {
        NULL
 };
 
-const char * const bch2_btree_ids[] = {
+const char * const __bch2_btree_ids[] = {
        BCH_BTREE_IDS()
-       "interior btree node",
        NULL
 };
 
index 55014336c5f7534d3deadf16fc77671108d25d7b..16dd0f0622bcbbbb72d3222810b603a12b3ce5ad 100644 (file)
@@ -16,7 +16,7 @@ extern const char * const bch2_fsck_fix_opts[];
 extern const char * const bch2_version_upgrade_opts[];
 extern const char * const bch2_sb_features[];
 extern const char * const bch2_sb_compat[];
-extern const char * const bch2_btree_ids[];
+extern const char * const __bch2_btree_ids[];
 extern const char * const bch2_csum_types[];
 extern const char * const bch2_csum_opts[];
 extern const char * const bch2_compression_types[];
index 4cd660650e5bda264283f10624b52a3f02910b37..55663253c9d3359615d4668173d09fea7bd182e7 100644 (file)
@@ -182,7 +182,7 @@ static int bch2_journal_replay(struct bch_fs *c)
                             bch2_journal_replay_key(trans, k));
                if (ret) {
                        bch_err(c, "journal replay: error while replaying key at btree %s level %u: %s",
-                               bch2_btree_ids[k->btree_id], k->level, bch2_err_str(ret));
+                               bch2_btree_id_str(k->btree_id), k->level, bch2_err_str(ret));
                        goto err;
                }
        }
@@ -367,7 +367,7 @@ static int read_btree_roots(struct bch_fs *c)
                        __fsck_err(c, btree_id_is_alloc(i)
                                   ? FSCK_CAN_IGNORE : 0,
                                   "invalid btree root %s",
-                                  bch2_btree_ids[i]);
+                                  bch2_btree_id_str(i));
                        if (i == BTREE_ID_alloc)
                                c->sb.compat &= ~(1ULL << BCH_COMPAT_alloc_info);
                }
@@ -376,7 +376,7 @@ static int read_btree_roots(struct bch_fs *c)
                if (ret) {
                        fsck_err(c,
                                 "error reading btree root %s",
-                                bch2_btree_ids[i]);
+                                bch2_btree_id_str(i));
                        if (btree_id_is_alloc(i))
                                c->sb.compat &= ~(1ULL << BCH_COMPAT_alloc_info);
                        ret = 0;
@@ -901,7 +901,7 @@ out:
        }
        kfree(clean);
 
-       if (!ret && test_bit(BCH_FS_HAVE_DELETED_SNAPSHOTS, &c->flags)) {
+       if (!ret && test_bit(BCH_FS_NEED_DELETE_DEAD_SNAPSHOTS, &c->flags)) {
                bch2_fs_read_write_early(c);
                bch2_delete_dead_snapshots_async(c);
        }
index fbfa9d831d6f2382647c77dbcd0c6c15e82976f7..4c1cea2a601d2f2ae0d2c9e8746a6ed763ce52e5 100644 (file)
@@ -27,7 +27,7 @@
        x(check_snapshot_trees,         PASS_FSCK)                                              \
        x(check_snapshots,              PASS_FSCK)                                              \
        x(check_subvols,                PASS_FSCK)                                              \
-       x(delete_dead_snapshots,        PASS_FSCK|PASS_UNCLEAN)                                 \
+       x(delete_dead_snapshots,        PASS_FSCK)                                              \
        x(fs_upgrade_for_subvolumes,    0)                                                      \
        x(resume_logged_ops,            PASS_ALWAYS)                                            \
        x(check_inodes,                 PASS_FSCK)                                              \
index 4982468bfe1182910fa6a03e3b691bf7ce8be758..315e88cc3867f5bbbf13b9017f9eab8fa3234515 100644 (file)
@@ -325,8 +325,9 @@ int bch2_mark_snapshot(struct btree_trans *trans,
                __set_is_ancestor_bitmap(c, id);
 
                if (BCH_SNAPSHOT_DELETED(s.v)) {
-                       set_bit(BCH_FS_HAVE_DELETED_SNAPSHOTS, &c->flags);
-                       c->recovery_passes_explicit |= BIT_ULL(BCH_RECOVERY_PASS_delete_dead_snapshots);
+                       set_bit(BCH_FS_NEED_DELETE_DEAD_SNAPSHOTS, &c->flags);
+                       if (c->curr_recovery_pass > BCH_RECOVERY_PASS_delete_dead_snapshots)
+                               bch2_delete_dead_snapshots_async(c);
                }
        } else {
                memset(t, 0, sizeof(*t));
@@ -1251,13 +1252,7 @@ static int move_key_to_correct_snapshot(struct btree_trans *trans,
        return 0;
 }
 
-/*
- * For a given snapshot, if it doesn't have a subvolume that points to it, and
- * it doesn't have child snapshot nodes - it's now redundant and we can mark it
- * as deleted.
- */
-static int bch2_delete_redundant_snapshot(struct btree_trans *trans, struct btree_iter *iter,
-                                         struct bkey_s_c k)
+static int bch2_snapshot_needs_delete(struct btree_trans *trans, struct bkey_s_c k)
 {
        struct bkey_s_c_snapshot snap;
        u32 children[2];
@@ -1278,10 +1273,21 @@ static int bch2_delete_redundant_snapshot(struct btree_trans *trans, struct btre
                bch2_snapshot_live(trans, children[1]);
        if (ret < 0)
                return ret;
+       return !ret;
+}
 
-       if (!ret)
-               return bch2_snapshot_node_set_deleted(trans, k.k->p.offset);
-       return 0;
+/*
+ * For a given snapshot, if it doesn't have a subvolume that points to it, and
+ * it doesn't have child snapshot nodes - it's now redundant and we can mark it
+ * as deleted.
+ */
+static int bch2_delete_redundant_snapshot(struct btree_trans *trans, struct bkey_s_c k)
+{
+       int ret = bch2_snapshot_needs_delete(trans, k);
+
+       return ret <= 0
+               ? ret
+               : bch2_snapshot_node_set_deleted(trans, k.k->p.offset);
 }
 
 static inline u32 bch2_snapshot_nth_parent_skip(struct bch_fs *c, u32 id, u32 n,
@@ -1369,6 +1375,9 @@ int bch2_delete_dead_snapshots(struct bch_fs *c)
        u32 *i, id;
        int ret = 0;
 
+       if (!test_and_clear_bit(BCH_FS_NEED_DELETE_DEAD_SNAPSHOTS, &c->flags))
+               return 0;
+
        if (!test_bit(BCH_FS_STARTED, &c->flags)) {
                ret = bch2_fs_read_write_early(c);
                if (ret) {
@@ -1386,7 +1395,7 @@ int bch2_delete_dead_snapshots(struct bch_fs *c)
        ret = for_each_btree_key_commit(trans, iter, BTREE_ID_snapshots,
                        POS_MIN, 0, k,
                        NULL, NULL, 0,
-               bch2_delete_redundant_snapshot(trans, &iter, k));
+               bch2_delete_redundant_snapshot(trans, k));
        if (ret) {
                bch_err_msg(c, ret, "deleting redundant snapshots");
                goto err;
@@ -1447,6 +1456,7 @@ int bch2_delete_dead_snapshots(struct bch_fs *c)
                }
        }
 
+       bch2_trans_unlock(trans);
        down_write(&c->snapshot_create_lock);
 
        for_each_btree_key(trans, iter, BTREE_ID_snapshots,
@@ -1491,8 +1501,6 @@ int bch2_delete_dead_snapshots(struct bch_fs *c)
                        goto err_create_lock;
                }
        }
-
-       clear_bit(BCH_FS_HAVE_DELETED_SNAPSHOTS, &c->flags);
 err_create_lock:
        up_write(&c->snapshot_create_lock);
 err:
@@ -1508,8 +1516,7 @@ void bch2_delete_dead_snapshots_work(struct work_struct *work)
 {
        struct bch_fs *c = container_of(work, struct bch_fs, snapshot_delete_work);
 
-       if (test_bit(BCH_FS_HAVE_DELETED_SNAPSHOTS, &c->flags))
-               bch2_delete_dead_snapshots(c);
+       bch2_delete_dead_snapshots(c);
        bch2_write_ref_put(c, BCH_WRITE_REF_delete_dead_snapshots);
 }
 
@@ -1520,20 +1527,6 @@ void bch2_delete_dead_snapshots_async(struct bch_fs *c)
                bch2_write_ref_put(c, BCH_WRITE_REF_delete_dead_snapshots);
 }
 
-int bch2_delete_dead_snapshots_hook(struct btree_trans *trans,
-                                   struct btree_trans_commit_hook *h)
-{
-       struct bch_fs *c = trans->c;
-
-       set_bit(BCH_FS_HAVE_DELETED_SNAPSHOTS, &c->flags);
-
-       if (c->curr_recovery_pass <= BCH_RECOVERY_PASS_delete_dead_snapshots)
-               return 0;
-
-       bch2_delete_dead_snapshots_async(c);
-       return 0;
-}
-
 int __bch2_key_has_snapshot_overwrites(struct btree_trans *trans,
                                       enum btree_id id,
                                       struct bpos pos)
@@ -1664,6 +1657,26 @@ again:
        return ret ?: trans_was_restarted(trans, restart_count);
 }
 
+static int bch2_check_snapshot_needs_deletion(struct btree_trans *trans, struct bkey_s_c k)
+{
+       struct bch_fs *c = trans->c;
+       struct bkey_s_c_snapshot snap;
+       int ret = 0;
+
+       if (k.k->type != KEY_TYPE_snapshot)
+               return 0;
+
+       snap = bkey_s_c_to_snapshot(k);
+       if (BCH_SNAPSHOT_DELETED(snap.v) ||
+           bch2_snapshot_equiv(c, k.k->p.offset) != k.k->p.offset ||
+           (ret = bch2_snapshot_needs_delete(trans, k)) > 0) {
+               set_bit(BCH_FS_NEED_DELETE_DEAD_SNAPSHOTS, &c->flags);
+               return 0;
+       }
+
+       return ret;
+}
+
 int bch2_snapshots_read(struct bch_fs *c)
 {
        struct btree_iter iter;
@@ -1674,7 +1687,8 @@ int bch2_snapshots_read(struct bch_fs *c)
                for_each_btree_key2(trans, iter, BTREE_ID_snapshots,
                           POS_MIN, 0, k,
                        bch2_mark_snapshot(trans, BTREE_ID_snapshots, 0, bkey_s_c_null, k, 0) ?:
-                       bch2_snapshot_set_equiv(trans, k)) ?:
+                       bch2_snapshot_set_equiv(trans, k) ?:
+                       bch2_check_snapshot_needs_deletion(trans, k)) ?:
                for_each_btree_key2(trans, iter, BTREE_ID_snapshots,
                           POS_MIN, 0, k,
                           (set_is_ancestor_bitmap(c, k.k->p.offset), 0)));
index de215d9d1252549db99d7d8c6cea352f90264382..01f006cac83105bbb2b15e0c550296bbe56f62fc 100644 (file)
@@ -244,8 +244,6 @@ int bch2_check_snapshot_trees(struct bch_fs *);
 int bch2_check_snapshots(struct bch_fs *);
 
 int bch2_snapshot_node_set_deleted(struct btree_trans *, u32);
-int bch2_delete_dead_snapshots_hook(struct btree_trans *,
-                                   struct btree_trans_commit_hook *);
 void bch2_delete_dead_snapshots_work(struct work_struct *);
 
 int __bch2_key_has_snapshot_overwrites(struct btree_trans *, enum btree_id, struct bpos);
index caf2dd7dafff65e636b32d8893ead65bfa6dd150..73ba22c219a1c97f600a7ec0756fccf3463d85cd 100644 (file)
@@ -230,7 +230,6 @@ static int __bch2_subvolume_delete(struct btree_trans *trans, u32 subvolid)
 {
        struct btree_iter iter;
        struct bkey_s_c_subvolume subvol;
-       struct btree_trans_commit_hook *h;
        u32 snapid;
        int ret = 0;
 
@@ -246,22 +245,8 @@ static int __bch2_subvolume_delete(struct btree_trans *trans, u32 subvolid)
 
        snapid = le32_to_cpu(subvol.v->snapshot);
 
-       ret = bch2_btree_delete_at(trans, &iter, 0);
-       if (ret)
-               goto err;
-
-       ret = bch2_snapshot_node_set_deleted(trans, snapid);
-       if (ret)
-               goto err;
-
-       h = bch2_trans_kmalloc(trans, sizeof(*h));
-       ret = PTR_ERR_OR_ZERO(h);
-       if (ret)
-               goto err;
-
-       h->fn = bch2_delete_dead_snapshots_hook;
-       bch2_trans_commit_hook(trans, h);
-err:
+       ret =   bch2_btree_delete_at(trans, &iter, 0) ?:
+               bch2_snapshot_node_set_deleted(trans, snapid);
        bch2_trans_iter_exit(trans, &iter);
        return ret;
 }
index 9a858105d3f72b83f7c778fc478e5588d6be474a..89544dadcfd0c6c8e55a3bf65f1996627d3ce1a1 100644 (file)
@@ -341,7 +341,7 @@ static int bch2_compression_stats_to_text(struct printbuf *out, struct bch_fs *c
 
 static void bch2_gc_gens_pos_to_text(struct printbuf *out, struct bch_fs *c)
 {
-       prt_printf(out, "%s: ", bch2_btree_ids[c->gc_gens_btree]);
+       prt_printf(out, "%s: ", bch2_btree_id_str(c->gc_gens_btree));
        bch2_bpos_to_text(out, c->gc_gens_pos);
        prt_printf(out, "\n");
 }
index 19264492151b3a2a97edcceb57c66f2d6b31d68d..2308f49f3b2e2316cbe027c5a79812f92dfcc328 100644 (file)
@@ -68,7 +68,7 @@ DECLARE_EVENT_CLASS(btree_node,
        TP_printk("%d,%d %u %s %llu:%llu:%u",
                  MAJOR(__entry->dev), MINOR(__entry->dev),
                  __entry->level,
-                 bch2_btree_ids[__entry->btree_id],
+                 bch2_btree_id_str(__entry->btree_id),
                  __entry->pos_inode, __entry->pos_offset, __entry->pos_snapshot)
 );
 
@@ -461,7 +461,7 @@ TRACE_EVENT(btree_path_relock_fail,
        TP_printk("%s %pS btree %s pos %llu:%llu:%u level %u node %s held %u:%u lock count %u:%u iter seq %u lock seq %u",
                  __entry->trans_fn,
                  (void *) __entry->caller_ip,
-                 bch2_btree_ids[__entry->btree_id],
+                 bch2_btree_id_str(__entry->btree_id),
                  __entry->pos_inode,
                  __entry->pos_offset,
                  __entry->pos_snapshot,
@@ -522,7 +522,7 @@ TRACE_EVENT(btree_path_upgrade_fail,
        TP_printk("%s %pS btree %s pos %llu:%llu:%u level %u locked %u held %u:%u lock count %u:%u iter seq %u lock seq %u",
                  __entry->trans_fn,
                  (void *) __entry->caller_ip,
-                 bch2_btree_ids[__entry->btree_id],
+                 bch2_btree_id_str(__entry->btree_id),
                  __entry->pos_inode,
                  __entry->pos_offset,
                  __entry->pos_snapshot,
@@ -1012,7 +1012,7 @@ DECLARE_EVENT_CLASS(transaction_restart_iter,
        TP_printk("%s %pS btree %s pos %llu:%llu:%u",
                  __entry->trans_fn,
                  (void *) __entry->caller_ip,
-                 bch2_btree_ids[__entry->btree_id],
+                 bch2_btree_id_str(__entry->btree_id),
                  __entry->pos_inode,
                  __entry->pos_offset,
                  __entry->pos_snapshot)
@@ -1061,7 +1061,7 @@ TRACE_EVENT(trans_restart_upgrade,
        TP_printk("%s %pS btree %s pos %llu:%llu:%u locks_want %u -> %u",
                  __entry->trans_fn,
                  (void *) __entry->caller_ip,
-                 bch2_btree_ids[__entry->btree_id],
+                 bch2_btree_id_str(__entry->btree_id),
                  __entry->pos_inode,
                  __entry->pos_offset,
                  __entry->pos_snapshot,
@@ -1219,7 +1219,7 @@ TRACE_EVENT(trans_restart_key_cache_key_realloced,
        TP_printk("%s %pS btree %s pos %llu:%llu:%u old_u64s %u new_u64s %u",
                  __entry->trans_fn,
                  (void *) __entry->caller_ip,
-                 bch2_btree_ids[__entry->btree_id],
+                 bch2_btree_id_str(__entry->btree_id),
                  __entry->pos_inode,
                  __entry->pos_offset,
                  __entry->pos_snapshot,
index 92ec3cefc38a030647dd619add8a65d00a5848ab..819b337ec5e8ddf4c0b5afed76e3f61d46dea3fd 100644 (file)
@@ -60,6 +60,7 @@ fn main() {
         .allowlist_var("KEY_SPEC_.*")
         .allowlist_var("Fix753_FMODE_.*")
         .allowlist_var("bch.*")
+        .allowlist_var("__bch2.*")
         .allowlist_var("__BTREE_ITER.*")
         .allowlist_var("BTREE_ITER.*")
         .blocklist_item("bch2_bkey_ops")
index 73aeef64541f777f04304776fca307e9ba90f307..4c549442ad1a6c8953a69912d581645e11f55087 100644 (file)
@@ -62,7 +62,7 @@ use std::fmt;
 
 impl fmt::Display for c::btree_id {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        let s = unsafe { CStr::from_ptr(*c::bch2_btree_ids.get_unchecked(*self as usize)) };
+        let s = unsafe { CStr::from_ptr(c::bch2_btree_id_str(*self)) };
         let s = s.to_str().unwrap();
         write!(f, "{}", s)
     }
@@ -92,7 +92,7 @@ impl FromStr for c::btree_id {
         let s = CString::new(s).unwrap();
         let p = s.as_ptr();
 
-        let v = unsafe {c::match_string(c::bch2_btree_ids[..].as_ptr(), (-(1 as isize)) as usize, p)};
+        let v = unsafe {c::match_string(c::__bch2_btree_ids[..].as_ptr(), (-(1 as isize)) as usize, p)};
         if v >= 0 {
             Ok(unsafe { std::mem::transmute(v) })
         } else {
index f6e9a4789b3bc143fdb101339a8982a4417bc23a..923a6666c72422e5c5e6a4014235c1dddbdd38a9 100644 (file)
@@ -673,7 +673,7 @@ struct bbpos bbpos_parse(char *buf)
        if (!(field = strsep(&s, ":")))
                die("invalid bbpos %s", buf);
 
-       ret.btree = read_string_list_or_die(field, bch2_btree_ids, "btree id");
+       ret.btree = read_string_list_or_die(field, __bch2_btree_ids, "btree id");
 
        if (!s)
                die("invalid bbpos %s", buf);