Update bcachefs sources to 01d7ad6d95 bcachefs: snapshot_to_text() includes snapshot tree

This commit is contained in:
Kent Overstreet 2023-06-13 15:06:46 -04:00
parent 17d1c4f4fe
commit ba88873432
8 changed files with 69 additions and 127 deletions

View File

@ -1 +1 @@
ed6b7f81a7b51ac05d02635907f92aff4a3f8445
01d7ad6d95c85cf5434a891e6dd7971797e0e1fa

View File

@ -35,6 +35,15 @@
#include <linux/rculist.h>
#include <linux/rcupdate.h>
static void bch2_trans_mutex_lock_norelock(struct btree_trans *trans,
struct mutex *lock)
{
if (!mutex_trylock(lock)) {
bch2_trans_unlock(trans);
mutex_lock(lock);
}
}
const char * const bch2_alloc_reserves[] = {
#define x(t) #t,
BCH_ALLOC_RESERVES()
@ -150,9 +159,7 @@ static struct open_bucket *bch2_open_bucket_alloc(struct bch_fs *c)
return ob;
}
static void open_bucket_free_unused(struct bch_fs *c,
struct write_point *wp,
struct open_bucket *ob)
static void open_bucket_free_unused(struct bch_fs *c, struct open_bucket *ob)
{
BUG_ON(c->open_buckets_partial_nr >=
ARRAY_SIZE(c->open_buckets_partial));
@ -1158,9 +1165,12 @@ static bool try_increase_writepoints(struct bch_fs *c)
return true;
}
static bool try_decrease_writepoints(struct bch_fs *c, unsigned old_nr)
static bool try_decrease_writepoints(struct btree_trans *trans, unsigned old_nr)
{
struct bch_fs *c = trans->c;
struct write_point *wp;
struct open_bucket *ob;
unsigned i;
mutex_lock(&c->write_points_hash_lock);
if (c->write_points_nr < old_nr) {
@ -1179,19 +1189,13 @@ static bool try_decrease_writepoints(struct bch_fs *c, unsigned old_nr)
hlist_del_rcu(&wp->node);
mutex_unlock(&c->write_points_hash_lock);
bch2_writepoint_stop(c, NULL, false, wp);
bch2_trans_mutex_lock_norelock(trans, &wp->lock);
open_bucket_for_each(c, &wp->ptrs, ob, i)
open_bucket_free_unused(c, ob);
mutex_unlock(&wp->lock);
return true;
}
static void bch2_trans_mutex_lock_norelock(struct btree_trans *trans,
struct mutex *lock)
{
if (!mutex_trylock(lock)) {
bch2_trans_unlock(trans);
mutex_lock(lock);
}
}
static struct write_point *writepoint_find(struct btree_trans *trans,
unsigned long write_point)
{
@ -1336,7 +1340,7 @@ alloc_done:
/* Free buckets we didn't use: */
open_bucket_for_each(c, &wp->ptrs, ob, i)
open_bucket_free_unused(c, wp, ob);
open_bucket_free_unused(c, ob);
wp->ptrs = ptrs;
@ -1353,13 +1357,13 @@ err:
if (ptrs.nr < ARRAY_SIZE(ptrs.v))
ob_push(c, &ptrs, ob);
else
open_bucket_free_unused(c, wp, ob);
open_bucket_free_unused(c, ob);
wp->ptrs = ptrs;
mutex_unlock(&wp->lock);
if (bch2_err_matches(ret, BCH_ERR_freelist_empty) &&
try_decrease_writepoints(c, write_points_nr))
try_decrease_writepoints(trans, write_points_nr))
goto retry;
if (bch2_err_matches(ret, BCH_ERR_open_buckets_empty) ||

View File

@ -1674,9 +1674,6 @@ static int bch2_btree_insert_node(struct btree_update *as, struct btree_trans *t
BUG_ON(!as || as->b);
bch2_verify_keylist_sorted(keys);
if ((local_clock() & 63) == 63)
return btree_trans_restart(trans, BCH_ERR_transaction_restart_split_race);
ret = bch2_btree_node_lock_write(trans, path, &b->c);
if (ret)
return ret;

View File

@ -1311,130 +1311,64 @@ static int need_whiteout_for_snapshot(struct btree_trans *trans,
return ret;
}
static int get_snapshot_overwrites(struct btree_trans *trans,
enum btree_id btree,
struct bpos pos,
snapshot_id_list *overwrites)
{
struct bch_fs *c = trans->c;
struct btree_iter iter;
struct bkey_s_c k;
snapshot_id_list overwrites2;
u32 *i;
int ret = 0;
darray_init(overwrites);
darray_init(&overwrites2);
for_each_btree_key_norestart(trans, iter, btree,
SPOS(pos.inode, pos.offset, 0),
BTREE_ITER_ALL_SNAPSHOTS, k, ret) {
if (bpos_ge(k.k->p, pos))
break;
if (bch2_snapshot_is_ancestor(c, k.k->p.snapshot, pos.snapshot)) {
ret = snapshot_list_add(c, &overwrites2, k.k->p.snapshot);
if (ret)
break;
}
}
bch2_trans_iter_exit(trans, &iter);
if (ret)
goto err;
darray_for_each(overwrites2, i)
if (!snapshot_list_has_ancestor(c, &overwrites2, *i)) {
ret = snapshot_list_add(c, overwrites, *i);
if (ret)
goto err;
}
*overwrites = overwrites2;
out:
darray_exit(&overwrites2);
return ret;
err:
darray_exit(overwrites);
goto out;
}
int __bch2_insert_snapshot_whiteouts(struct btree_trans *trans,
enum btree_id btree,
enum btree_id id,
struct bpos old_pos,
struct bpos new_pos)
{
struct bch_fs *c = trans->c;
snapshot_id_list old_overwrites, new_overwrites, updates;
bool began_transaction = false;
u32 *i;
struct btree_iter old_iter, new_iter;
struct bkey_s_c old_k, new_k;
snapshot_id_list s;
struct bkey_i *update;
int ret;
if (!bch2_snapshot_has_children(c, old_pos.snapshot))
return 0;
darray_init(&old_overwrites);
darray_init(&new_overwrites);
darray_init(&updates);
darray_init(&s);
ret = get_snapshot_overwrites(trans, btree, old_pos, &old_overwrites) ?:
get_snapshot_overwrites(trans, btree, new_pos, &new_overwrites);
if (ret)
goto err;
bch2_trans_iter_init(trans, &old_iter, id, old_pos,
BTREE_ITER_NOT_EXTENTS|
BTREE_ITER_ALL_SNAPSHOTS);
while ((old_k = bch2_btree_iter_prev(&old_iter)).k &&
!(ret = bkey_err(old_k)) &&
bkey_eq(old_pos, old_k.k->p)) {
struct bpos whiteout_pos =
SPOS(new_pos.inode, new_pos.offset, old_k.k->p.snapshot);;
darray_for_each(old_overwrites, i)
if (!snapshot_list_has_ancestor(c, &new_overwrites, *i)) {
ret = darray_push(&updates, *i);
if (ret)
goto err;
}
if (!bch2_snapshot_is_ancestor(c, old_k.k->p.snapshot, old_pos.snapshot) ||
snapshot_list_has_ancestor(c, &s, old_k.k->p.snapshot))
continue;
if (updates.nr > 4) {
bch2_trans_begin(trans);
began_transaction = true;
}
darray_for_each(updates, i) {
struct btree_iter iter;
struct bkey_i *update;
bch2_trans_iter_init(trans, &iter, btree,
SPOS(new_pos.inode, new_pos.offset, *i),
BTREE_ITER_NOT_EXTENTS|
BTREE_ITER_INTENT);
update = bch2_trans_kmalloc(trans, sizeof(struct bkey_i));
ret = PTR_ERR_OR_ZERO(update);
new_k = bch2_bkey_get_iter(trans, &new_iter, id, whiteout_pos,
BTREE_ITER_NOT_EXTENTS|
BTREE_ITER_INTENT);
ret = bkey_err(new_k);
if (ret)
break;
bkey_init(&update->k);
update->k.p = iter.pos;
update->k.type = KEY_TYPE_whiteout;
if (new_k.k->type == KEY_TYPE_deleted) {
update = bch2_trans_kmalloc(trans, sizeof(struct bkey_i));
ret = PTR_ERR_OR_ZERO(update);
if (ret)
break;
ret = bch2_btree_iter_traverse(&iter) ?:
bch2_trans_update(trans, &iter, update,
BTREE_UPDATE_INTERNAL_SNAPSHOT_NODE) ?:
(began_transaction && trans->nr_updates > 4
? bch2_trans_commit(trans, NULL, NULL, BTREE_INSERT_NOFAIL) : 0);
bkey_init(&update->k);
update->k.p = whiteout_pos;
update->k.type = KEY_TYPE_whiteout;
bch2_trans_iter_exit(trans, &iter);
ret = bch2_trans_update(trans, &new_iter, update,
BTREE_UPDATE_INTERNAL_SNAPSHOT_NODE);
}
bch2_trans_iter_exit(trans, &new_iter);
ret = snapshot_list_add(c, &s, old_k.k->p.snapshot);
if (ret)
goto err;
break;
}
if (began_transaction && trans->nr_updates) {
ret = bch2_trans_commit(trans, NULL, NULL, BTREE_INSERT_NOFAIL);
if (ret)
goto err;
}
if (began_transaction)
ret = -BCH_ERR_transaction_restart_nested;
err:
darray_exit(&updates);
darray_exit(&new_overwrites);
darray_exit(&old_overwrites);
bch2_trans_iter_exit(trans, &old_iter);
darray_exit(&s);
return ret;
}

View File

@ -78,6 +78,7 @@ trans_commit:
return bch2_trans_update(trans, iter, &wb->k, 0) ?:
bch2_trans_commit(trans, NULL, NULL,
commit_flags|
BTREE_INSERT_NOCHECK_RW|
BTREE_INSERT_NOFAIL|
BTREE_INSERT_JOURNAL_RECLAIM);
}

View File

@ -86,13 +86,14 @@ void bch2_snapshot_to_text(struct printbuf *out, struct bch_fs *c,
{
struct bkey_s_c_snapshot s = bkey_s_c_to_snapshot(k);
prt_printf(out, "is_subvol %llu deleted %llu parent %10u children %10u %10u subvol %u",
prt_printf(out, "is_subvol %llu deleted %llu parent %10u children %10u %10u subvol %u tree %u",
BCH_SNAPSHOT_SUBVOL(s.v),
BCH_SNAPSHOT_DELETED(s.v),
le32_to_cpu(s.v->parent),
le32_to_cpu(s.v->children[0]),
le32_to_cpu(s.v->children[1]),
le32_to_cpu(s.v->subvol));
le32_to_cpu(s.v->subvol),
le32_to_cpu(s.v->tree));
}
int bch2_snapshot_invalid(const struct bch_fs *c, struct bkey_s_c k,

View File

@ -121,7 +121,7 @@ static inline int snapshot_list_add(struct bch_fs *c, snapshot_id_list *s, u32 i
{
int ret;
EBUG_ON(snapshot_list_has_id(s, id));
BUG_ON(snapshot_list_has_id(s, id));
ret = darray_push(s, id);
if (ret)
bch_err(c, "error reallocating snapshot_id_list (size %zu)", s->size);

View File

@ -302,6 +302,11 @@ void bch2_fs_read_only(struct bch_fs *c)
test_bit(BCH_FS_STARTED, &c->flags) &&
test_bit(BCH_FS_CLEAN_SHUTDOWN, &c->flags) &&
!c->opts.norecovery) {
BUG_ON(c->journal.last_empty_seq != journal_cur_seq(&c->journal));
BUG_ON(atomic_read(&c->btree_cache.dirty));
BUG_ON(atomic_long_read(&c->btree_key_cache.nr_dirty));
BUG_ON(c->btree_write_buffer.state.nr);
bch_verbose(c, "marking filesystem clean");
bch2_fs_mark_clean(c);
}