Skip to content

Commit

Permalink
bcachefs: Log original key being moved in data updates
Browse files Browse the repository at this point in the history
There's something going on with the data move path; log the original key
being moved for debugging.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
  • Loading branch information
Kent Overstreet committed Mar 30, 2025
1 parent edaed8e commit 7fdc3fa
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
22 changes: 21 additions & 1 deletion fs/bcachefs/data_update.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@

#include <linux/ioprio.h>

static const char * const bch2_data_update_type_strs[] = {
#define x(t, n, ...) [n] = #t,
BCH_DATA_UPDATE_TYPES()
#undef x
NULL
};

static void bkey_put_dev_refs(struct bch_fs *c, struct bkey_s_c k)
{
struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
Expand Down Expand Up @@ -181,6 +188,7 @@ static int __bch2_data_update_index_update(struct btree_trans *trans,
container_of(op, struct data_update, op);
struct keylist *keys = &op->insert_keys;
struct bkey_buf _new, _insert;
struct printbuf journal_msg = PRINTBUF;
int ret = 0;

bch2_bkey_buf_init(&_new);
Expand Down Expand Up @@ -372,7 +380,12 @@ static int __bch2_data_update_index_update(struct btree_trans *trans,
printbuf_exit(&buf);
}

ret = bch2_insert_snapshot_whiteouts(trans, m->btree_id,
printbuf_reset(&journal_msg);
prt_str(&journal_msg, bch2_data_update_type_strs[m->type]);

ret = bch2_trans_log_msg(trans, &journal_msg) ?:
bch2_trans_log_bkey(trans, m->btree_id, 0, m->k.k) ?:
bch2_insert_snapshot_whiteouts(trans, m->btree_id,
k.k->p, bkey_start_pos(&insert->k)) ?:
bch2_insert_snapshot_whiteouts(trans, m->btree_id,
k.k->p, insert->k.p) ?:
Expand Down Expand Up @@ -417,6 +430,7 @@ static int __bch2_data_update_index_update(struct btree_trans *trans,
goto next;
}
out:
printbuf_exit(&journal_msg);
bch2_trans_iter_exit(trans, &iter);
bch2_bkey_buf_exit(&_insert, c);
bch2_bkey_buf_exit(&_new, c);
Expand Down Expand Up @@ -577,6 +591,9 @@ void bch2_data_update_opts_to_text(struct printbuf *out, struct bch_fs *c,

void bch2_data_update_to_text(struct printbuf *out, struct data_update *m)
{
prt_str(out, bch2_data_update_type_strs[m->type]);
prt_newline(out);

bch2_data_update_opts_to_text(out, m->op.c, &m->op.opts, &m->data_opts);
prt_newline(out);

Expand Down Expand Up @@ -738,6 +755,9 @@ int bch2_data_update_init(struct btree_trans *trans,

bch2_bkey_buf_init(&m->k);
bch2_bkey_buf_reassemble(&m->k, c, k);
m->type = data_opts.btree_insert_flags & BCH_WATERMARK_copygc
? BCH_DATA_UPDATE_copygc
: BCH_DATA_UPDATE_rebalance;
m->btree_id = btree_id;
m->data_opts = data_opts;
m->ctxt = ctxt;
Expand Down
12 changes: 12 additions & 0 deletions fs/bcachefs/data_update.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,19 @@ struct data_update_opts {
void bch2_data_update_opts_to_text(struct printbuf *, struct bch_fs *,
struct bch_io_opts *, struct data_update_opts *);

#define BCH_DATA_UPDATE_TYPES() \
x(copygc, 0) \
x(rebalance, 1) \
x(promote, 2)

enum bch_data_update_types {
#define x(n, id) BCH_DATA_UPDATE_##n = id,
BCH_DATA_UPDATE_TYPES()
#undef x
};

struct data_update {
enum bch_data_update_types type;
/* extent being updated: */
bool read_done;
enum btree_id btree_id;
Expand Down
1 change: 1 addition & 0 deletions fs/bcachefs/io_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ static struct bch_read_bio *__promote_alloc(struct btree_trans *trans,
&orig->opts,
update_opts,
btree_id, k);
op->write.type = BCH_DATA_UPDATE_promote;
/*
* possible errors: -BCH_ERR_nocow_lock_blocked,
* -BCH_ERR_ENOSPC_disk_reservation:
Expand Down

0 comments on commit 7fdc3fa

Please sign in to comment.