bcachefs: Fixes for building in userspace
authorKent Overstreet <kent.overstreet@linux.dev>
Mon, 14 Nov 2022 01:01:42 +0000 (20:01 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:46 +0000 (17:09 -0400)
 - Marking a non-static function as inline doesn't actually work and is
   now causing problems - drop that

 - Introduce BCACHEFS_LOG_PREFIX for when we want to prefix log messages
   with bcachefs (filesystem name)

 - Userspace doesn't have real percpu variables (maybe we can get this
   fixed someday), put an #ifdef around bch2_disk_reservation_add()
   fastpath

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/bcachefs.h
fs/bcachefs/btree_iter.c
fs/bcachefs/btree_iter.h
fs/bcachefs/btree_locking.c
fs/bcachefs/buckets.h
fs/bcachefs/error.c
fs/bcachefs/move.c
fs/bcachefs/move.h
fs/bcachefs/movinggc.c
fs/bcachefs/rebalance.c
fs/bcachefs/recovery.c

index c0416258985bfdf0ca0c61d08d6780c9c3bd5767..90a1bd1f9d63c91edd34bcc70e5457975db2c36a 100644 (file)
@@ -226,6 +226,10 @@ do {                                                                       \
         dynamic_fault("bcachefs:meta:write:" name)
 
 #ifdef __KERNEL__
+#define BCACHEFS_LOG_PREFIX
+#endif
+
+#ifdef BCACHEFS_LOG_PREFIX
 #define bch2_log_msg(_c, fmt)          "bcachefs (%s): " fmt, ((_c)->name)
 #define bch2_fmt(_c, fmt)              bch2_log_msg(_c, fmt "\n")
 #define bch2_fmt_inum(_c, _inum, fmt)  "bcachefs (%s inum %llu): " fmt "\n", ((_c)->name), (_inum)
index d30fb32bb68392022049ea47eeeee95a0a0f006f..fc057ba11190503a349948ab1708b80414726962 100644 (file)
@@ -636,9 +636,9 @@ static inline void __btree_path_level_init(struct btree_path *path,
                bch2_btree_node_iter_peek(&l->iter, l->b);
 }
 
-inline void bch2_btree_path_level_init(struct btree_trans *trans,
-                                      struct btree_path *path,
-                                      struct btree *b)
+void bch2_btree_path_level_init(struct btree_trans *trans,
+                               struct btree_path *path,
+                               struct btree *b)
 {
        BUG_ON(path->cached);
 
@@ -1554,7 +1554,7 @@ struct btree_path *bch2_path_get(struct btree_trans *trans,
        return path;
 }
 
-inline struct bkey_s_c bch2_btree_path_peek_slot(struct btree_path *path, struct bkey *u)
+struct bkey_s_c bch2_btree_path_peek_slot(struct btree_path *path, struct bkey *u)
 {
 
        struct btree_path_level *l = path_l(path);
index cfbd07bc93668c1c40324c0c91075c490affd3b2..38bea61ed7f844c648bea50564efc1b465aabef1 100644 (file)
@@ -177,13 +177,12 @@ int __must_check bch2_btree_path_traverse(struct btree_trans *,
                                          struct btree_path *, unsigned);
 struct btree_path *bch2_path_get(struct btree_trans *, enum btree_id, struct bpos,
                                 unsigned, unsigned, unsigned);
-inline struct bkey_s_c bch2_btree_path_peek_slot(struct btree_path *, struct bkey *);
+struct bkey_s_c bch2_btree_path_peek_slot(struct btree_path *, struct bkey *);
 
 struct bkey_i *bch2_btree_journal_peek_slot(struct btree_trans *,
                                        struct btree_iter *, struct bpos);
 
-inline void bch2_btree_path_level_init(struct btree_trans *,
-                                      struct btree_path *, struct btree *);
+void bch2_btree_path_level_init(struct btree_trans *, struct btree_path *, struct btree *);
 
 #ifdef CONFIG_BCACHEFS_DEBUG
 void bch2_trans_verify_paths(struct btree_trans *);
index 1530457f0e6984a634e096efa8d4ab57efcfd7ad..9d4be3c9cfd7ab76da7971eed8df04d65ed373bc 100644 (file)
@@ -179,10 +179,9 @@ static noinline int break_cycle(struct lock_graph *g, struct printbuf *cycle)
        }
 
        if (unlikely(!best)) {
-               struct bch_fs *c = g->g->trans->c;
                struct printbuf buf = PRINTBUF;
 
-               bch_err(c, "cycle of nofail locks");
+               prt_printf(&buf, bch2_fmt(g->g->trans->c, "cycle of nofail locks"));
 
                for (i = g->g; i < g->g + g->nr; i++) {
                        struct btree_trans *trans = i->trans;
index ff61a0054eaa6e342c363f2d9b79fefc6fa07d58..0fc101b9aaf1f096008db147358573d8e82734c1 100644 (file)
@@ -255,6 +255,7 @@ int __bch2_disk_reservation_add(struct bch_fs *,
 static inline int bch2_disk_reservation_add(struct bch_fs *c, struct disk_reservation *res,
                                            u64 sectors, int flags)
 {
+#ifdef __KERNEL__
        u64 old, new;
 
        do {
@@ -268,6 +269,9 @@ static inline int bch2_disk_reservation_add(struct bch_fs *c, struct disk_reserv
        this_cpu_add(*c->online_reserved, sectors);
        res->sectors                    += sectors;
        return 0;
+#else
+       return __bch2_disk_reservation_add(c, res, sectors, flags);
+#endif
 }
 
 static inline struct disk_reservation
index 2fb5102ee31d16da84e83a37b32a0a0872254284..3e49d72d65b5e8db791cfa6254529e9217fce4e6 100644 (file)
@@ -125,8 +125,10 @@ int bch2_fsck_err(struct bch_fs *c, unsigned flags, const char *fmt, ...)
                s->nr++;
        }
 
+#ifdef BCACHEFS_LOG_PREFIX
        if (!strncmp(fmt, "bcachefs:", 9))
                prt_printf(out, bch2_log_msg(c, ""));
+#endif
 
        va_start(args, fmt);
        prt_vprintf(out, fmt, args);
index 7a9d1e4466c5def59c643331ade5315e5657996a..a66fbc1faa7b869fa71df127665d3bbae5b8ca11 100644 (file)
@@ -177,7 +177,7 @@ void bch2_moving_ctxt_init(struct moving_context *ctxt,
        }
 }
 
-void bch_move_stats_init(struct bch_move_stats *stats, char *name)
+void bch2_move_stats_init(struct bch_move_stats *stats, char *name)
 {
        memset(stats, 0, sizeof(*stats));
        scnprintf(stats->name, sizeof(stats->name), "%s", name);
@@ -755,7 +755,7 @@ int bch2_data_job(struct bch_fs *c,
 
        switch (op.op) {
        case BCH_DATA_OP_REREPLICATE:
-               bch_move_stats_init(stats, "rereplicate");
+               bch2_move_stats_init(stats, "rereplicate");
                stats->data_type = BCH_DATA_journal;
                ret = bch2_journal_flush_device_pins(&c->journal, -1);
 
@@ -779,7 +779,7 @@ int bch2_data_job(struct bch_fs *c,
                if (op.migrate.dev >= c->sb.nr_devices)
                        return -EINVAL;
 
-               bch_move_stats_init(stats, "migrate");
+               bch2_move_stats_init(stats, "migrate");
                stats->data_type = BCH_DATA_journal;
                ret = bch2_journal_flush_device_pins(&c->journal, op.migrate.dev);
 
@@ -800,7 +800,7 @@ int bch2_data_job(struct bch_fs *c,
                ret = bch2_replicas_gc2(c) ?: ret;
                break;
        case BCH_DATA_OP_REWRITE_OLD_NODES:
-               bch_move_stats_init(stats, "rewrite_old_nodes");
+               bch2_move_stats_init(stats, "rewrite_old_nodes");
                ret = bch2_scan_old_btree_nodes(c, stats);
                break;
        default:
index 6250c75618c4ead1208f7c1b91cc40149a64e76d..2eb6a15542e0e99dc0c19df19d2db944c0d181e9 100644 (file)
@@ -50,8 +50,7 @@ int bch2_data_job(struct bch_fs *,
                  struct bch_move_stats *,
                  struct bch_ioctl_data);
 
-inline void bch_move_stats_init(struct bch_move_stats *stats,
-                               char *name);
+void bch2_move_stats_init(struct bch_move_stats *stats, char *name);
 
 
 #endif /* _BCACHEFS_MOVE_H */
index dca8d4a3a89c2dcc601c995c5c35a7d01842bd6f..09f4303de1f62a82bb8ebd4baaca7e36c804aca1 100644 (file)
@@ -213,7 +213,7 @@ static int bch2_copygc(struct bch_fs *c)
        size_t heap_size = 0;
        int ret;
 
-       bch_move_stats_init(&move_stats, "copygc");
+       bch2_move_stats_init(&move_stats, "copygc");
 
        /*
         * Find buckets with lowest sector counts, skipping completely
index 6b9ccc1b3fe3943be17c949593bd7d316ab2a65c..66c40999163d64bcc6fdf8491398da02cac1ab0e 100644 (file)
@@ -189,7 +189,7 @@ static int bch2_rebalance_thread(void *arg)
        prev_start      = jiffies;
        prev_cputime    = curr_cputime();
 
-       bch_move_stats_init(&move_stats, "rebalance");
+       bch2_move_stats_init(&move_stats, "rebalance");
        while (!kthread_wait_freezable(r->enabled)) {
                cond_resched();
 
index 7eaced534a5b7221f1184c2cd9593b6f3cb2f292..8d767e787d6bf2e9b1ded703c93cae050d1eff85 100644 (file)
@@ -1376,7 +1376,7 @@ use_clean:
            le16_to_cpu(c->sb.version_min) < bcachefs_metadata_version_btree_ptr_sectors_written) {
                struct bch_move_stats stats;
 
-               bch_move_stats_init(&stats, "recovery");
+               bch2_move_stats_init(&stats, "recovery");
 
                bch_info(c, "scanning for old btree nodes");
                ret = bch2_fs_read_write(c);