Commit 6f83cb84 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Fix unit & perf tests for snapshots

This finishes updating the unit & perf tests for snapshots - btrees that
use snapshots now always require the snapshot field of the start
position to be a valid snapshot ID.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
parent 18443cb9
...@@ -14,12 +14,14 @@ static void delete_test_keys(struct bch_fs *c) ...@@ -14,12 +14,14 @@ static void delete_test_keys(struct bch_fs *c)
int ret; int ret;
ret = bch2_btree_delete_range(c, BTREE_ID_extents, ret = bch2_btree_delete_range(c, BTREE_ID_extents,
POS(0, 0), POS(0, U64_MAX), SPOS(0, 0, U32_MAX),
SPOS(0, U64_MAX, U32_MAX),
NULL); NULL);
BUG_ON(ret); BUG_ON(ret);
ret = bch2_btree_delete_range(c, BTREE_ID_xattrs, ret = bch2_btree_delete_range(c, BTREE_ID_xattrs,
POS(0, 0), POS(0, U64_MAX), SPOS(0, 0, U32_MAX),
SPOS(0, U64_MAX, U32_MAX),
NULL); NULL);
BUG_ON(ret); BUG_ON(ret);
} }
...@@ -144,7 +146,7 @@ static int test_iterate(struct bch_fs *c, u64 nr) ...@@ -144,7 +146,7 @@ static int test_iterate(struct bch_fs *c, u64 nr)
i = 0; i = 0;
for_each_btree_key(&trans, iter, BTREE_ID_xattrs, for_each_btree_key(&trans, iter, BTREE_ID_xattrs,
POS_MIN, 0, k, ret) { SPOS(0, 0, U32_MAX), 0, k, ret) {
if (k.k->p.inode) if (k.k->p.inode)
break; break;
...@@ -200,7 +202,7 @@ static int test_iterate_extents(struct bch_fs *c, u64 nr) ...@@ -200,7 +202,7 @@ static int test_iterate_extents(struct bch_fs *c, u64 nr)
i = 0; i = 0;
for_each_btree_key(&trans, iter, BTREE_ID_extents, for_each_btree_key(&trans, iter, BTREE_ID_extents,
POS_MIN, 0, k, ret) { SPOS(0, 0, U32_MAX), 0, k, ret) {
BUG_ON(bkey_start_offset(k.k) != i); BUG_ON(bkey_start_offset(k.k) != i);
i = k.k->p.offset; i = k.k->p.offset;
} }
...@@ -254,8 +256,8 @@ static int test_iterate_slots(struct bch_fs *c, u64 nr) ...@@ -254,8 +256,8 @@ static int test_iterate_slots(struct bch_fs *c, u64 nr)
i = 0; i = 0;
for_each_btree_key(&trans, iter, BTREE_ID_xattrs, POS_MIN, for_each_btree_key(&trans, iter, BTREE_ID_xattrs,
0, k, ret) { SPOS(0, 0, U32_MAX), 0, k, ret) {
if (k.k->p.inode) if (k.k->p.inode)
break; break;
...@@ -270,7 +272,8 @@ static int test_iterate_slots(struct bch_fs *c, u64 nr) ...@@ -270,7 +272,8 @@ static int test_iterate_slots(struct bch_fs *c, u64 nr)
i = 0; i = 0;
for_each_btree_key(&trans, iter, BTREE_ID_xattrs, POS_MIN, for_each_btree_key(&trans, iter, BTREE_ID_xattrs,
SPOS(0, 0, U32_MAX),
BTREE_ITER_SLOTS, k, ret) { BTREE_ITER_SLOTS, k, ret) {
BUG_ON(k.k->p.offset != i); BUG_ON(k.k->p.offset != i);
BUG_ON(bkey_deleted(k.k) != (i & 1)); BUG_ON(bkey_deleted(k.k) != (i & 1));
...@@ -319,8 +322,8 @@ static int test_iterate_slots_extents(struct bch_fs *c, u64 nr) ...@@ -319,8 +322,8 @@ static int test_iterate_slots_extents(struct bch_fs *c, u64 nr)
i = 0; i = 0;
for_each_btree_key(&trans, iter, BTREE_ID_extents, POS_MIN, for_each_btree_key(&trans, iter, BTREE_ID_extents,
0, k, ret) { SPOS(0, 0, U32_MAX), 0, k, ret) {
BUG_ON(bkey_start_offset(k.k) != i + 8); BUG_ON(bkey_start_offset(k.k) != i + 8);
BUG_ON(k.k->size != 8); BUG_ON(k.k->size != 8);
i += 16; i += 16;
...@@ -333,7 +336,8 @@ static int test_iterate_slots_extents(struct bch_fs *c, u64 nr) ...@@ -333,7 +336,8 @@ static int test_iterate_slots_extents(struct bch_fs *c, u64 nr)
i = 0; i = 0;
for_each_btree_key(&trans, iter, BTREE_ID_extents, POS_MIN, for_each_btree_key(&trans, iter, BTREE_ID_extents,
SPOS(0, 0, U32_MAX),
BTREE_ITER_SLOTS, k, ret) { BTREE_ITER_SLOTS, k, ret) {
BUG_ON(bkey_deleted(k.k) != !(i % 16)); BUG_ON(bkey_deleted(k.k) != !(i % 16));
...@@ -361,7 +365,8 @@ static int test_peek_end(struct bch_fs *c, u64 nr) ...@@ -361,7 +365,8 @@ static int test_peek_end(struct bch_fs *c, u64 nr)
struct bkey_s_c k; struct bkey_s_c k;
bch2_trans_init(&trans, c, 0, 0); bch2_trans_init(&trans, c, 0, 0);
bch2_trans_iter_init(&trans, &iter, BTREE_ID_xattrs, POS_MIN, 0); bch2_trans_iter_init(&trans, &iter, BTREE_ID_xattrs,
SPOS(0, 0, U32_MAX), 0);
k = bch2_btree_iter_peek(&iter); k = bch2_btree_iter_peek(&iter);
BUG_ON(k.k); BUG_ON(k.k);
...@@ -381,7 +386,8 @@ static int test_peek_end_extents(struct bch_fs *c, u64 nr) ...@@ -381,7 +386,8 @@ static int test_peek_end_extents(struct bch_fs *c, u64 nr)
struct bkey_s_c k; struct bkey_s_c k;
bch2_trans_init(&trans, c, 0, 0); bch2_trans_init(&trans, c, 0, 0);
bch2_trans_iter_init(&trans, &iter, BTREE_ID_extents, POS_MIN, 0); bch2_trans_iter_init(&trans, &iter, BTREE_ID_extents,
SPOS(0, 0, U32_MAX), 0);
k = bch2_btree_iter_peek(&iter); k = bch2_btree_iter_peek(&iter);
BUG_ON(k.k); BUG_ON(k.k);
...@@ -404,8 +410,6 @@ static int insert_test_extent(struct bch_fs *c, ...@@ -404,8 +410,6 @@ static int insert_test_extent(struct bch_fs *c,
struct bkey_i_cookie k; struct bkey_i_cookie k;
int ret; int ret;
//pr_info("inserting %llu-%llu v %llu", start, end, test_version);
bkey_cookie_init(&k.k_i); bkey_cookie_init(&k.k_i);
k.k_i.k.p.offset = end; k.k_i.k.p.offset = end;
k.k_i.k.p.snapshot = U32_MAX; k.k_i.k.p.snapshot = U32_MAX;
...@@ -541,10 +545,11 @@ static int rand_lookup(struct bch_fs *c, u64 nr) ...@@ -541,10 +545,11 @@ static int rand_lookup(struct bch_fs *c, u64 nr)
u64 i; u64 i;
bch2_trans_init(&trans, c, 0, 0); bch2_trans_init(&trans, c, 0, 0);
bch2_trans_iter_init(&trans, &iter, BTREE_ID_xattrs, POS_MIN, 0); bch2_trans_iter_init(&trans, &iter, BTREE_ID_xattrs,
SPOS(0, 0, U32_MAX), 0);
for (i = 0; i < nr; i++) { for (i = 0; i < nr; i++) {
bch2_btree_iter_set_pos(&iter, POS(0, test_rand())); bch2_btree_iter_set_pos(&iter, SPOS(0, test_rand(), U32_MAX));
k = bch2_btree_iter_peek(&iter); k = bch2_btree_iter_peek(&iter);
ret = bkey_err(k); ret = bkey_err(k);
...@@ -567,7 +572,7 @@ static int rand_mixed_trans(struct btree_trans *trans, ...@@ -567,7 +572,7 @@ static int rand_mixed_trans(struct btree_trans *trans,
struct bkey_s_c k; struct bkey_s_c k;
int ret; int ret;
bch2_btree_iter_set_pos(iter, POS(0, pos)); bch2_btree_iter_set_pos(iter, SPOS(0, pos, U32_MAX));
k = bch2_btree_iter_peek(iter); k = bch2_btree_iter_peek(iter);
ret = bkey_err(k); ret = bkey_err(k);
...@@ -594,7 +599,8 @@ static int rand_mixed(struct bch_fs *c, u64 nr) ...@@ -594,7 +599,8 @@ static int rand_mixed(struct bch_fs *c, u64 nr)
u64 i, rand; u64 i, rand;
bch2_trans_init(&trans, c, 0, 0); bch2_trans_init(&trans, c, 0, 0);
bch2_trans_iter_init(&trans, &iter, BTREE_ID_xattrs, POS_MIN, 0); bch2_trans_iter_init(&trans, &iter, BTREE_ID_xattrs,
SPOS(0, 0, U32_MAX), 0);
for (i = 0; i < nr; i++) { for (i = 0; i < nr; i++) {
rand = test_rand(); rand = test_rand();
...@@ -614,7 +620,6 @@ static int rand_mixed(struct bch_fs *c, u64 nr) ...@@ -614,7 +620,6 @@ static int rand_mixed(struct bch_fs *c, u64 nr)
static int __do_delete(struct btree_trans *trans, struct bpos pos) static int __do_delete(struct btree_trans *trans, struct bpos pos)
{ {
struct btree_iter iter; struct btree_iter iter;
struct bkey_i delete;
struct bkey_s_c k; struct bkey_s_c k;
int ret = 0; int ret = 0;
...@@ -628,10 +633,7 @@ static int __do_delete(struct btree_trans *trans, struct bpos pos) ...@@ -628,10 +633,7 @@ static int __do_delete(struct btree_trans *trans, struct bpos pos)
if (!k.k) if (!k.k)
goto err; goto err;
bkey_init(&delete.k); ret = bch2_btree_delete_at(trans, &iter, 0);
delete.k.p = k.k->p;
ret = bch2_trans_update(trans, &iter, &delete, 0);
err: err:
bch2_trans_iter_exit(trans, &iter); bch2_trans_iter_exit(trans, &iter);
return ret; return ret;
...@@ -646,7 +648,7 @@ static int rand_delete(struct bch_fs *c, u64 nr) ...@@ -646,7 +648,7 @@ static int rand_delete(struct bch_fs *c, u64 nr)
bch2_trans_init(&trans, c, 0, 0); bch2_trans_init(&trans, c, 0, 0);
for (i = 0; i < nr; i++) { for (i = 0; i < nr; i++) {
struct bpos pos = POS(0, test_rand()); struct bpos pos = SPOS(0, test_rand(), U32_MAX);
ret = __bch2_trans_do(&trans, NULL, NULL, 0, ret = __bch2_trans_do(&trans, NULL, NULL, 0,
__do_delete(&trans, pos)); __do_delete(&trans, pos));
...@@ -673,7 +675,7 @@ static int seq_insert(struct bch_fs *c, u64 nr) ...@@ -673,7 +675,7 @@ static int seq_insert(struct bch_fs *c, u64 nr)
bch2_trans_init(&trans, c, 0, 0); bch2_trans_init(&trans, c, 0, 0);
for_each_btree_key(&trans, iter, BTREE_ID_xattrs, POS_MIN, for_each_btree_key(&trans, iter, BTREE_ID_xattrs, SPOS(0, 0, U32_MAX),
BTREE_ITER_SLOTS|BTREE_ITER_INTENT, k, ret) { BTREE_ITER_SLOTS|BTREE_ITER_INTENT, k, ret) {
insert.k.p = iter.pos; insert.k.p = iter.pos;
...@@ -703,7 +705,8 @@ static int seq_lookup(struct bch_fs *c, u64 nr) ...@@ -703,7 +705,8 @@ static int seq_lookup(struct bch_fs *c, u64 nr)
bch2_trans_init(&trans, c, 0, 0); bch2_trans_init(&trans, c, 0, 0);
for_each_btree_key(&trans, iter, BTREE_ID_xattrs, POS_MIN, 0, k, ret) for_each_btree_key(&trans, iter, BTREE_ID_xattrs,
SPOS(0, 0, U32_MAX), 0, k, ret)
; ;
bch2_trans_iter_exit(&trans, &iter); bch2_trans_iter_exit(&trans, &iter);
...@@ -720,7 +723,8 @@ static int seq_overwrite(struct bch_fs *c, u64 nr) ...@@ -720,7 +723,8 @@ static int seq_overwrite(struct bch_fs *c, u64 nr)
bch2_trans_init(&trans, c, 0, 0); bch2_trans_init(&trans, c, 0, 0);
for_each_btree_key(&trans, iter, BTREE_ID_xattrs, POS_MIN, for_each_btree_key(&trans, iter, BTREE_ID_xattrs,
SPOS(0, 0, U32_MAX),
BTREE_ITER_INTENT, k, ret) { BTREE_ITER_INTENT, k, ret) {
struct bkey_i_cookie u; struct bkey_i_cookie u;
...@@ -745,8 +749,7 @@ static int seq_delete(struct bch_fs *c, u64 nr) ...@@ -745,8 +749,7 @@ static int seq_delete(struct bch_fs *c, u64 nr)
int ret; int ret;
ret = bch2_btree_delete_range(c, BTREE_ID_xattrs, ret = bch2_btree_delete_range(c, BTREE_ID_xattrs,
POS(0, 0), POS(0, U64_MAX), SPOS(0, 0, U32_MAX), POS_MAX, NULL);
NULL);
if (ret) if (ret)
bch_err(c, "error in seq_delete: %i", ret); bch_err(c, "error in seq_delete: %i", ret);
return ret; return ret;
......
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