Skip to content

Commit

Permalink
Update bcachefs sources to 070f7d6a382a bcachefs: bch2_sb_nr_devices()
Browse files Browse the repository at this point in the history
Signed-off-by: Kent Overstreet <[email protected]>
  • Loading branch information
Kent Overstreet committed Aug 10, 2024
1 parent 495a54c commit 6687752
Show file tree
Hide file tree
Showing 16 changed files with 196 additions and 118 deletions.
2 changes: 1 addition & 1 deletion .bcachefs_revision
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dfc7b2c9433ed926cad881b8fbee55e36105989b
070f7d6a382a0d67628756727751c24f70eb48ea
10 changes: 4 additions & 6 deletions c_src/cmd_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,26 +70,24 @@ static void dump_one_device(struct bch_fs *c, struct bch_dev *ca, int fd,
/* Btree: */
for (i = 0; i < BTREE_ID_NR; i++) {
struct btree_trans *trans = bch2_trans_get(c);
struct btree_iter iter;
struct btree *b;

__for_each_btree_node(trans, iter, i, POS_MIN, 0, 1, 0, b, ret) {
ret = __for_each_btree_node(trans, iter, i, POS_MIN, 0, 1, 0, b, ({
struct btree_node_iter iter;
struct bkey u;
struct bkey_s_c k;

for_each_btree_node_key_unpack(b, k, &iter, &u)
dump_node(c, ca, k, &data);
}
0;
}));

if (ret)
die("error %s walking btree nodes", bch2_err_str(ret));

b = bch2_btree_id_root(c, i)->b;
struct btree *b = bch2_btree_id_root(c, i)->b;
if (!btree_node_fake(b))
dump_node(c, ca, bkey_i_to_s_c(&b->key), &data);

bch2_trans_iter_exit(trans, &iter);
bch2_trans_put(trans);
}

Expand Down
73 changes: 35 additions & 38 deletions c_src/cmd_kill_btree_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,56 +64,53 @@ int cmd_kill_btree_node(int argc, char *argv[])
if (IS_ERR(c))
die("error opening %s: %s", argv[0], bch2_err_str(PTR_ERR(c)));

struct btree_trans *trans = bch2_trans_get(c);
struct btree_iter iter;
struct btree *b;
int ret;
void *zeroes;

ret = posix_memalign(&zeroes, c->opts.block_size, c->opts.block_size);
if (ret)
die("error %s from posix_memalign", bch2_err_str(ret));

__for_each_btree_node(trans, iter, btree_id, POS_MIN, 0, level, 0, b, ret) {
if (b->c.level != level)
continue;

if (!node_index) {
struct printbuf buf = PRINTBUF;
bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(&b->key));
bch_info(c, "killing btree node %s", buf.buf);
printbuf_exit(&buf);

struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(bkey_i_to_s_c(&b->key));
bkey_for_each_ptr(ptrs, ptr) {
struct bch_dev *ca = bch2_dev_tryget(c, ptr->dev);
if (!ca)
continue;

ret = pwrite(ca->disk_sb.bdev->bd_fd, zeroes,
c->opts.block_size, ptr->offset << 9);
bch2_dev_put(ca);
if (ret != c->opts.block_size) {
bch_err(c, "pwrite error: expected %u got %i %s",
c->opts.block_size, ret, strerror(errno));
ret = EXIT_FAILURE;
goto done;
ret = bch2_trans_run(c,
__for_each_btree_node(trans, iter, btree_id, POS_MIN, 0, level, 0, b, ({
if (b->c.level != level)
continue;

int ret2 = 0;
if (!node_index) {
struct printbuf buf = PRINTBUF;
bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(&b->key));
bch_info(c, "killing btree node %s", buf.buf);
printbuf_exit(&buf);

ret2 = 1;

struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(bkey_i_to_s_c(&b->key));
bkey_for_each_ptr(ptrs, ptr) {
struct bch_dev *ca = bch2_dev_tryget(c, ptr->dev);
if (!ca)
continue;

int ret3 = pwrite(ca->disk_sb.bdev->bd_fd, zeroes,
c->opts.block_size, ptr->offset << 9);
bch2_dev_put(ca);
if (ret3 != c->opts.block_size) {
bch_err(c, "pwrite error: expected %u got %i %s",
c->opts.block_size, ret, strerror(errno));
ret2 = EXIT_FAILURE;
}
}
}
ret = 0;
goto done;
}

node_index--;
}
if (ret)
node_index--;
ret2;
})));
if (ret < 0)
bch_err(c, "error %i walking btree nodes", ret);
else
else if (!ret) {
bch_err(c, "node at specified index not found");
ret = EXIT_FAILURE;
done:
bch2_trans_iter_exit(trans, &iter);
bch2_trans_put(trans);
ret = EXIT_FAILURE;
}

bch2_fs_stop(c);
return ret;
Expand Down
2 changes: 1 addition & 1 deletion libbcachefs/alloc_foreground.c
Original file line number Diff line number Diff line change
Expand Up @@ -1737,7 +1737,7 @@ void bch2_dev_alloc_debug_to_text(struct printbuf *out, struct bch_dev *ca)
printbuf_tabstop_push(out, 16);
printbuf_tabstop_push(out, 16);

bch2_dev_usage_to_text(out, &stats);
bch2_dev_usage_to_text(out, ca, &stats);

prt_newline(out);

Expand Down
15 changes: 5 additions & 10 deletions libbcachefs/backpointers.c
Original file line number Diff line number Diff line change
Expand Up @@ -763,27 +763,22 @@ static int bch2_get_btree_in_memory_pos(struct btree_trans *trans,
btree < BTREE_ID_NR && !ret;
btree++) {
unsigned depth = (BIT_ULL(btree) & btree_leaf_mask) ? 0 : 1;
struct btree_iter iter;
struct btree *b;

if (!(BIT_ULL(btree) & btree_leaf_mask) &&
!(BIT_ULL(btree) & btree_interior_mask))
continue;

bch2_trans_begin(trans);

__for_each_btree_node(trans, iter, btree,
ret = __for_each_btree_node(trans, iter, btree,
btree == start.btree ? start.pos : POS_MIN,
0, depth, BTREE_ITER_prefetch, b, ret) {
0, depth, BTREE_ITER_prefetch, b, ({
mem_may_pin -= btree_buf_bytes(b);
if (mem_may_pin <= 0) {
c->btree_cache.pinned_nodes_end = *end =
BBPOS(btree, b->key.k.p);
bch2_trans_iter_exit(trans, &iter);
return 0;
break;
}
}
bch2_trans_iter_exit(trans, &iter);
0;
}));
}

return ret;
Expand Down
3 changes: 2 additions & 1 deletion libbcachefs/bcachefs_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,8 @@ struct bch_sb_field_ext {
x(btree_subvolume_children, BCH_VERSION(1, 6)) \
x(mi_btree_bitmap, BCH_VERSION(1, 7)) \
x(bucket_stripe_sectors, BCH_VERSION(1, 8)) \
x(disk_accounting_v2, BCH_VERSION(1, 9))
x(disk_accounting_v2, BCH_VERSION(1, 9)) \
x(disk_accounting_v3, BCH_VERSION(1, 10))

enum bcachefs_metadata_version {
bcachefs_metadata_version_min = 9,
Expand Down
1 change: 1 addition & 0 deletions libbcachefs/btree_iter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1913,6 +1913,7 @@ struct btree *bch2_btree_iter_peek_node(struct btree_iter *iter)
goto out;
}

/* Only kept for -tools */
struct btree *bch2_btree_iter_peek_node_and_restart(struct btree_iter *iter)
{
struct btree *b;
Expand Down
42 changes: 27 additions & 15 deletions libbcachefs/btree_iter.h
Original file line number Diff line number Diff line change
Expand Up @@ -618,23 +618,35 @@ void bch2_trans_srcu_unlock(struct btree_trans *);

u32 bch2_trans_begin(struct btree_trans *);

/*
* XXX
* this does not handle transaction restarts from bch2_btree_iter_next_node()
* correctly
*/
#define __for_each_btree_node(_trans, _iter, _btree_id, _start, \
_locks_want, _depth, _flags, _b, _ret) \
for (bch2_trans_node_iter_init((_trans), &(_iter), (_btree_id), \
_start, _locks_want, _depth, _flags); \
(_b) = bch2_btree_iter_peek_node_and_restart(&(_iter)), \
!((_ret) = PTR_ERR_OR_ZERO(_b)) && (_b); \
(_b) = bch2_btree_iter_next_node(&(_iter)))
#define __for_each_btree_node(_trans, _iter, _btree_id, _start, \
_locks_want, _depth, _flags, _b, _do) \
({ \
bch2_trans_begin((_trans)); \
\
struct btree_iter _iter; \
bch2_trans_node_iter_init((_trans), &_iter, (_btree_id), \
_start, _locks_want, _depth, _flags); \
int _ret3 = 0; \
do { \
_ret3 = lockrestart_do((_trans), ({ \
struct btree *_b = bch2_btree_iter_peek_node(&_iter); \
if (!_b) \
break; \
\
PTR_ERR_OR_ZERO(_b) ?: (_do); \
})) ?: \
lockrestart_do((_trans), \
PTR_ERR_OR_ZERO(bch2_btree_iter_next_node(&_iter))); \
} while (!_ret3); \
\
bch2_trans_iter_exit((_trans), &(_iter)); \
_ret3; \
})

#define for_each_btree_node(_trans, _iter, _btree_id, _start, \
_flags, _b, _ret) \
__for_each_btree_node(_trans, _iter, _btree_id, _start, \
0, 0, _flags, _b, _ret)
_flags, _b, _do) \
__for_each_btree_node(_trans, _iter, _btree_id, _start, \
0, 0, _flags, _b, _do)

static inline struct bkey_s_c bch2_btree_iter_peek_prev_type(struct btree_iter *iter,
unsigned flags)
Expand Down
12 changes: 8 additions & 4 deletions libbcachefs/buckets.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,21 @@ bch2_fs_usage_read_short(struct bch_fs *c)
return ret;
}

void bch2_dev_usage_to_text(struct printbuf *out, struct bch_dev_usage *usage)
void bch2_dev_usage_to_text(struct printbuf *out,
struct bch_dev *ca,
struct bch_dev_usage *usage)
{
prt_printf(out, "\tbuckets\rsectors\rfragmented\r\n");

for (unsigned i = 0; i < BCH_DATA_NR; i++) {
bch2_prt_data_type(out, i);
prt_printf(out, "\t%llu\r%llu\r%llu\r\n",
usage->d[i].buckets,
usage->d[i].sectors,
usage->d[i].fragmented);
usage->d[i].buckets,
usage->d[i].sectors,
usage->d[i].fragmented);
}

prt_printf(out, "capacity\t%llu\r\n", ca->mi.nbuckets);
}

static int bch2_check_fix_ptr(struct btree_trans *trans,
Expand Down
2 changes: 1 addition & 1 deletion libbcachefs/buckets.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ static inline struct bch_dev_usage bch2_dev_usage_read(struct bch_dev *ca)
return ret;
}

void bch2_dev_usage_to_text(struct printbuf *, struct bch_dev_usage *);
void bch2_dev_usage_to_text(struct printbuf *, struct bch_dev *, struct bch_dev_usage *);

static inline u64 bch2_dev_buckets_reserved(struct bch_dev *ca, enum bch_watermark watermark)
{
Expand Down
38 changes: 9 additions & 29 deletions libbcachefs/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,47 +397,27 @@ static ssize_t bch2_read_btree_formats(struct file *file, char __user *buf,
size_t size, loff_t *ppos)
{
struct dump_iter *i = file->private_data;
struct btree_trans *trans;
struct btree_iter iter;
struct btree *b;
ssize_t ret;

i->ubuf = buf;
i->size = size;
i->ret = 0;

ret = flush_buf(i);
ssize_t ret = flush_buf(i);
if (ret)
return ret;

if (bpos_eq(SPOS_MAX, i->from))
return i->ret;

trans = bch2_trans_get(i->c);
retry:
bch2_trans_begin(trans);

for_each_btree_node(trans, iter, i->id, i->from, 0, b, ret) {
bch2_btree_node_to_text(&i->buf, i->c, b);
i->from = !bpos_eq(SPOS_MAX, b->key.k.p)
? bpos_successor(b->key.k.p)
: b->key.k.p;

ret = drop_locks_do(trans, flush_buf(i));
if (ret)
break;
}
bch2_trans_iter_exit(trans, &iter);

if (bch2_err_matches(ret, BCH_ERR_transaction_restart))
goto retry;

bch2_trans_put(trans);

if (!ret)
ret = flush_buf(i);
return bch2_trans_run(i->c,
for_each_btree_node(trans, iter, i->id, i->from, 0, b, ({
bch2_btree_node_to_text(&i->buf, i->c, b);
i->from = !bpos_eq(SPOS_MAX, b->key.k.p)
? bpos_successor(b->key.k.p)
: b->key.k.p;

return ret ?: i->ret;
drop_locks_do(trans, flush_buf(i));
}))) ?: i->ret;
}

static const struct file_operations btree_format_debug_ops = {
Expand Down
Loading

0 comments on commit 6687752

Please sign in to comment.