Commit b2d1d56b authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: Fixes for building in userspace

 - 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: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent a7ecd30c
...@@ -226,6 +226,10 @@ do { \ ...@@ -226,6 +226,10 @@ do { \
dynamic_fault("bcachefs:meta:write:" name) dynamic_fault("bcachefs:meta:write:" name)
#ifdef __KERNEL__ #ifdef __KERNEL__
#define BCACHEFS_LOG_PREFIX
#endif
#ifdef BCACHEFS_LOG_PREFIX
#define bch2_log_msg(_c, fmt) "bcachefs (%s): " fmt, ((_c)->name) #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(_c, fmt) bch2_log_msg(_c, fmt "\n")
#define bch2_fmt_inum(_c, _inum, fmt) "bcachefs (%s inum %llu): " fmt "\n", ((_c)->name), (_inum) #define bch2_fmt_inum(_c, _inum, fmt) "bcachefs (%s inum %llu): " fmt "\n", ((_c)->name), (_inum)
......
...@@ -636,9 +636,9 @@ static inline void __btree_path_level_init(struct btree_path *path, ...@@ -636,9 +636,9 @@ static inline void __btree_path_level_init(struct btree_path *path,
bch2_btree_node_iter_peek(&l->iter, l->b); bch2_btree_node_iter_peek(&l->iter, l->b);
} }
inline void bch2_btree_path_level_init(struct btree_trans *trans, void bch2_btree_path_level_init(struct btree_trans *trans,
struct btree_path *path, struct btree_path *path,
struct btree *b) struct btree *b)
{ {
BUG_ON(path->cached); BUG_ON(path->cached);
...@@ -1554,7 +1554,7 @@ struct btree_path *bch2_path_get(struct btree_trans *trans, ...@@ -1554,7 +1554,7 @@ struct btree_path *bch2_path_get(struct btree_trans *trans,
return path; 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); struct btree_path_level *l = path_l(path);
......
...@@ -177,13 +177,12 @@ int __must_check bch2_btree_path_traverse(struct btree_trans *, ...@@ -177,13 +177,12 @@ int __must_check bch2_btree_path_traverse(struct btree_trans *,
struct btree_path *, unsigned); struct btree_path *, unsigned);
struct btree_path *bch2_path_get(struct btree_trans *, enum btree_id, struct bpos, struct btree_path *bch2_path_get(struct btree_trans *, enum btree_id, struct bpos,
unsigned, unsigned, unsigned); 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 bkey_i *bch2_btree_journal_peek_slot(struct btree_trans *,
struct btree_iter *, struct bpos); struct btree_iter *, struct bpos);
inline void bch2_btree_path_level_init(struct btree_trans *, void bch2_btree_path_level_init(struct btree_trans *, struct btree_path *, struct btree *);
struct btree_path *, struct btree *);
#ifdef CONFIG_BCACHEFS_DEBUG #ifdef CONFIG_BCACHEFS_DEBUG
void bch2_trans_verify_paths(struct btree_trans *); void bch2_trans_verify_paths(struct btree_trans *);
......
...@@ -179,10 +179,9 @@ static noinline int break_cycle(struct lock_graph *g, struct printbuf *cycle) ...@@ -179,10 +179,9 @@ static noinline int break_cycle(struct lock_graph *g, struct printbuf *cycle)
} }
if (unlikely(!best)) { if (unlikely(!best)) {
struct bch_fs *c = g->g->trans->c;
struct printbuf buf = PRINTBUF; 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++) { for (i = g->g; i < g->g + g->nr; i++) {
struct btree_trans *trans = i->trans; struct btree_trans *trans = i->trans;
......
...@@ -255,6 +255,7 @@ int __bch2_disk_reservation_add(struct bch_fs *, ...@@ -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, static inline int bch2_disk_reservation_add(struct bch_fs *c, struct disk_reservation *res,
u64 sectors, int flags) u64 sectors, int flags)
{ {
#ifdef __KERNEL__
u64 old, new; u64 old, new;
do { do {
...@@ -268,6 +269,9 @@ static inline int bch2_disk_reservation_add(struct bch_fs *c, struct disk_reserv ...@@ -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); this_cpu_add(*c->online_reserved, sectors);
res->sectors += sectors; res->sectors += sectors;
return 0; return 0;
#else
return __bch2_disk_reservation_add(c, res, sectors, flags);
#endif
} }
static inline struct disk_reservation static inline struct disk_reservation
......
...@@ -125,8 +125,10 @@ int bch2_fsck_err(struct bch_fs *c, unsigned flags, const char *fmt, ...) ...@@ -125,8 +125,10 @@ int bch2_fsck_err(struct bch_fs *c, unsigned flags, const char *fmt, ...)
s->nr++; s->nr++;
} }
#ifdef BCACHEFS_LOG_PREFIX
if (!strncmp(fmt, "bcachefs:", 9)) if (!strncmp(fmt, "bcachefs:", 9))
prt_printf(out, bch2_log_msg(c, "")); prt_printf(out, bch2_log_msg(c, ""));
#endif
va_start(args, fmt); va_start(args, fmt);
prt_vprintf(out, fmt, args); prt_vprintf(out, fmt, args);
......
...@@ -177,7 +177,7 @@ void bch2_moving_ctxt_init(struct moving_context *ctxt, ...@@ -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)); memset(stats, 0, sizeof(*stats));
scnprintf(stats->name, sizeof(stats->name), "%s", name); scnprintf(stats->name, sizeof(stats->name), "%s", name);
...@@ -755,7 +755,7 @@ int bch2_data_job(struct bch_fs *c, ...@@ -755,7 +755,7 @@ int bch2_data_job(struct bch_fs *c,
switch (op.op) { switch (op.op) {
case BCH_DATA_OP_REREPLICATE: case BCH_DATA_OP_REREPLICATE:
bch_move_stats_init(stats, "rereplicate"); bch2_move_stats_init(stats, "rereplicate");
stats->data_type = BCH_DATA_journal; stats->data_type = BCH_DATA_journal;
ret = bch2_journal_flush_device_pins(&c->journal, -1); ret = bch2_journal_flush_device_pins(&c->journal, -1);
...@@ -779,7 +779,7 @@ int bch2_data_job(struct bch_fs *c, ...@@ -779,7 +779,7 @@ int bch2_data_job(struct bch_fs *c,
if (op.migrate.dev >= c->sb.nr_devices) if (op.migrate.dev >= c->sb.nr_devices)
return -EINVAL; return -EINVAL;
bch_move_stats_init(stats, "migrate"); bch2_move_stats_init(stats, "migrate");
stats->data_type = BCH_DATA_journal; stats->data_type = BCH_DATA_journal;
ret = bch2_journal_flush_device_pins(&c->journal, op.migrate.dev); ret = bch2_journal_flush_device_pins(&c->journal, op.migrate.dev);
...@@ -800,7 +800,7 @@ int bch2_data_job(struct bch_fs *c, ...@@ -800,7 +800,7 @@ int bch2_data_job(struct bch_fs *c,
ret = bch2_replicas_gc2(c) ?: ret; ret = bch2_replicas_gc2(c) ?: ret;
break; break;
case BCH_DATA_OP_REWRITE_OLD_NODES: 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); ret = bch2_scan_old_btree_nodes(c, stats);
break; break;
default: default:
......
...@@ -50,8 +50,7 @@ int bch2_data_job(struct bch_fs *, ...@@ -50,8 +50,7 @@ int bch2_data_job(struct bch_fs *,
struct bch_move_stats *, struct bch_move_stats *,
struct bch_ioctl_data); struct bch_ioctl_data);
inline void bch_move_stats_init(struct bch_move_stats *stats, void bch2_move_stats_init(struct bch_move_stats *stats, char *name);
char *name);
#endif /* _BCACHEFS_MOVE_H */ #endif /* _BCACHEFS_MOVE_H */
...@@ -213,7 +213,7 @@ static int bch2_copygc(struct bch_fs *c) ...@@ -213,7 +213,7 @@ static int bch2_copygc(struct bch_fs *c)
size_t heap_size = 0; size_t heap_size = 0;
int ret; int ret;
bch_move_stats_init(&move_stats, "copygc"); bch2_move_stats_init(&move_stats, "copygc");
/* /*
* Find buckets with lowest sector counts, skipping completely * Find buckets with lowest sector counts, skipping completely
......
...@@ -189,7 +189,7 @@ static int bch2_rebalance_thread(void *arg) ...@@ -189,7 +189,7 @@ static int bch2_rebalance_thread(void *arg)
prev_start = jiffies; prev_start = jiffies;
prev_cputime = curr_cputime(); prev_cputime = curr_cputime();
bch_move_stats_init(&move_stats, "rebalance"); bch2_move_stats_init(&move_stats, "rebalance");
while (!kthread_wait_freezable(r->enabled)) { while (!kthread_wait_freezable(r->enabled)) {
cond_resched(); cond_resched();
......
...@@ -1376,7 +1376,7 @@ int bch2_fs_recovery(struct bch_fs *c) ...@@ -1376,7 +1376,7 @@ int bch2_fs_recovery(struct bch_fs *c)
le16_to_cpu(c->sb.version_min) < bcachefs_metadata_version_btree_ptr_sectors_written) { le16_to_cpu(c->sb.version_min) < bcachefs_metadata_version_btree_ptr_sectors_written) {
struct bch_move_stats stats; 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"); bch_info(c, "scanning for old btree nodes");
ret = bch2_fs_read_write(c); ret = bch2_fs_read_write(c);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment