Commit 84ece59a authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Unit test updates

 - Convert to for_each_btree_key2(), for_each_btree_key_commit(),
   for_each_btree_key_reverse()
 - No more bare bch2_btree_iter_peek(); we're now fault-injection lock
   restarts, so we always need a lockrestart_do() or equivalent.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
parent 4f84b7e3
...@@ -145,20 +145,30 @@ static int test_iterate(struct bch_fs *c, u64 nr) ...@@ -145,20 +145,30 @@ static int test_iterate(struct bch_fs *c, u64 nr)
i = 0; i = 0;
for_each_btree_key(&trans, iter, BTREE_ID_xattrs, ret = for_each_btree_key2(&trans, iter, BTREE_ID_xattrs,
SPOS(0, 0, U32_MAX), 0, k, ret) { SPOS(0, 0, U32_MAX), 0, k, ({
if (k.k->p.inode)
break;
BUG_ON(k.k->p.offset != i++); BUG_ON(k.k->p.offset != i++);
0;
}));
if (ret) {
bch_err(c, "%s(): error iterating forwards: %s", __func__, bch2_err_str(ret));
goto err;
} }
BUG_ON(i != nr); BUG_ON(i != nr);
pr_info("iterating backwards"); pr_info("iterating backwards");
while (!IS_ERR_OR_NULL((k = bch2_btree_iter_prev(&iter)).k)) ret = for_each_btree_key_reverse(&trans, iter, BTREE_ID_xattrs,
BUG_ON(k.k->p.offset != --i); SPOS(0, U64_MAX, U32_MAX), 0, k,
({
BUG_ON(k.k->p.offset != --i);
0;
}));
if (ret) {
bch_err(c, "%s(): error iterating backwards: %s", __func__, bch2_err_str(ret));
goto err;
}
BUG_ON(i); BUG_ON(i);
err: err:
...@@ -201,19 +211,31 @@ static int test_iterate_extents(struct bch_fs *c, u64 nr) ...@@ -201,19 +211,31 @@ static int test_iterate_extents(struct bch_fs *c, u64 nr)
i = 0; i = 0;
for_each_btree_key(&trans, iter, BTREE_ID_extents, ret = for_each_btree_key2(&trans, iter, BTREE_ID_extents,
SPOS(0, 0, U32_MAX), 0, k, ret) { SPOS(0, 0, U32_MAX), 0, k, ({
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;
0;
}));
if (ret) {
bch_err(c, "%s(): error iterating forwards: %s", __func__, bch2_err_str(ret));
goto err;
} }
BUG_ON(i != nr); BUG_ON(i != nr);
pr_info("iterating backwards"); pr_info("iterating backwards");
while (!IS_ERR_OR_NULL((k = bch2_btree_iter_prev(&iter)).k)) { ret = for_each_btree_key_reverse(&trans, iter, BTREE_ID_extents,
BUG_ON(k.k->p.offset != i); SPOS(0, U64_MAX, U32_MAX), 0, k,
i = bkey_start_offset(k.k); ({
BUG_ON(k.k->p.offset != i);
i = bkey_start_offset(k.k);
0;
}));
if (ret) {
bch_err(c, "%s(): error iterating backwards: %s", __func__, bch2_err_str(ret));
goto err;
} }
BUG_ON(i); BUG_ON(i);
...@@ -256,15 +278,16 @@ static int test_iterate_slots(struct bch_fs *c, u64 nr) ...@@ -256,15 +278,16 @@ static int test_iterate_slots(struct bch_fs *c, u64 nr)
i = 0; i = 0;
for_each_btree_key(&trans, iter, BTREE_ID_xattrs, ret = for_each_btree_key2(&trans, iter, BTREE_ID_xattrs,
SPOS(0, 0, U32_MAX), 0, k, ret) { SPOS(0, 0, U32_MAX), 0, k, ({
if (k.k->p.inode)
break;
BUG_ON(k.k->p.offset != i); BUG_ON(k.k->p.offset != i);
i += 2; i += 2;
0;
}));
if (ret) {
bch_err(c, "%s(): error iterating forwards: %s", __func__, bch2_err_str(ret));
goto err;
} }
bch2_trans_iter_exit(&trans, &iter);
BUG_ON(i != nr * 2); BUG_ON(i != nr * 2);
...@@ -272,17 +295,23 @@ static int test_iterate_slots(struct bch_fs *c, u64 nr) ...@@ -272,17 +295,23 @@ static int test_iterate_slots(struct bch_fs *c, u64 nr)
i = 0; i = 0;
for_each_btree_key(&trans, iter, BTREE_ID_xattrs, ret = for_each_btree_key2(&trans, iter, BTREE_ID_xattrs,
SPOS(0, 0, U32_MAX), SPOS(0, 0, U32_MAX),
BTREE_ITER_SLOTS, k, ret) { BTREE_ITER_SLOTS, k, ({
if (i >= nr * 2)
break;
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));
i++; i++;
if (i == nr * 2) 0;
break; }));
if (ret < 0) {
bch_err(c, "%s(): error iterating forwards by slots: %s", __func__, bch2_err_str(ret));
goto err;
} }
bch2_trans_iter_exit(&trans, &iter); ret = 0;
err: err:
bch2_trans_exit(&trans); bch2_trans_exit(&trans);
return ret; return ret;
...@@ -322,13 +351,17 @@ static int test_iterate_slots_extents(struct bch_fs *c, u64 nr) ...@@ -322,13 +351,17 @@ 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, ret = for_each_btree_key2(&trans, iter, BTREE_ID_extents,
SPOS(0, 0, U32_MAX), 0, k, ret) { SPOS(0, 0, U32_MAX), 0, k, ({
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;
0;
}));
if (ret) {
bch_err(c, "%s(): error iterating forwards: %s", __func__, bch2_err_str(ret));
goto err;
} }
bch2_trans_iter_exit(&trans, &iter);
BUG_ON(i != nr); BUG_ON(i != nr);
...@@ -336,19 +369,23 @@ static int test_iterate_slots_extents(struct bch_fs *c, u64 nr) ...@@ -336,19 +369,23 @@ 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, ret = for_each_btree_key2(&trans, iter, BTREE_ID_extents,
SPOS(0, 0, U32_MAX), SPOS(0, 0, U32_MAX),
BTREE_ITER_SLOTS, k, ret) { BTREE_ITER_SLOTS, k, ({
if (i == nr)
break;
BUG_ON(bkey_deleted(k.k) != !(i % 16)); BUG_ON(bkey_deleted(k.k) != !(i % 16));
BUG_ON(bkey_start_offset(k.k) != i); BUG_ON(bkey_start_offset(k.k) != i);
BUG_ON(k.k->size != 8); BUG_ON(k.k->size != 8);
i = k.k->p.offset; i = k.k->p.offset;
0;
if (i == nr) }));
break; if (ret) {
bch_err(c, "%s(): error iterating forwards by slots: %s", __func__, bch2_err_str(ret));
goto err;
} }
bch2_trans_iter_exit(&trans, &iter); ret = 0;
err: err:
bch2_trans_exit(&trans); bch2_trans_exit(&trans);
return 0; return 0;
...@@ -368,10 +405,10 @@ static int test_peek_end(struct bch_fs *c, u64 nr) ...@@ -368,10 +405,10 @@ static int test_peek_end(struct bch_fs *c, u64 nr)
bch2_trans_iter_init(&trans, &iter, BTREE_ID_xattrs, bch2_trans_iter_init(&trans, &iter, BTREE_ID_xattrs,
SPOS(0, 0, U32_MAX), 0); SPOS(0, 0, U32_MAX), 0);
k = bch2_btree_iter_peek(&iter); lockrestart_do(&trans, bkey_err(k = bch2_btree_iter_peek(&iter)));
BUG_ON(k.k); BUG_ON(k.k);
k = bch2_btree_iter_peek(&iter); lockrestart_do(&trans, bkey_err(k = bch2_btree_iter_peek(&iter)));
BUG_ON(k.k); BUG_ON(k.k);
bch2_trans_iter_exit(&trans, &iter); bch2_trans_iter_exit(&trans, &iter);
...@@ -389,10 +426,10 @@ static int test_peek_end_extents(struct bch_fs *c, u64 nr) ...@@ -389,10 +426,10 @@ static int test_peek_end_extents(struct bch_fs *c, u64 nr)
bch2_trans_iter_init(&trans, &iter, BTREE_ID_extents, bch2_trans_iter_init(&trans, &iter, BTREE_ID_extents,
SPOS(0, 0, U32_MAX), 0); SPOS(0, 0, U32_MAX), 0);
k = bch2_btree_iter_peek(&iter); lockrestart_do(&trans, bkey_err(k = bch2_btree_iter_peek(&iter)));
BUG_ON(k.k); BUG_ON(k.k);
k = bch2_btree_iter_peek(&iter); lockrestart_do(&trans, bkey_err(k = bch2_btree_iter_peek(&iter)));
BUG_ON(k.k); BUG_ON(k.k);
bch2_trans_iter_exit(&trans, &iter); bch2_trans_iter_exit(&trans, &iter);
...@@ -482,7 +519,7 @@ static int test_snapshot_filter(struct bch_fs *c, u32 snapid_lo, u32 snapid_hi) ...@@ -482,7 +519,7 @@ static int test_snapshot_filter(struct bch_fs *c, u32 snapid_lo, u32 snapid_hi)
bch2_trans_init(&trans, c, 0, 0); bch2_trans_init(&trans, c, 0, 0);
bch2_trans_iter_init(&trans, &iter, BTREE_ID_xattrs, bch2_trans_iter_init(&trans, &iter, BTREE_ID_xattrs,
SPOS(0, 0, snapid_lo), 0); SPOS(0, 0, snapid_lo), 0);
k = bch2_btree_iter_peek(&iter); lockrestart_do(&trans, bkey_err(k = bch2_btree_iter_peek(&iter)));
BUG_ON(k.k->p.snapshot != U32_MAX); BUG_ON(k.k->p.snapshot != U32_MAX);
...@@ -615,7 +652,7 @@ static int rand_lookup(struct bch_fs *c, u64 nr) ...@@ -615,7 +652,7 @@ static int rand_lookup(struct bch_fs *c, u64 nr)
for (i = 0; i < nr; i++) { for (i = 0; i < nr; i++) {
bch2_btree_iter_set_pos(&iter, SPOS(0, test_rand(), U32_MAX)); bch2_btree_iter_set_pos(&iter, SPOS(0, test_rand(), U32_MAX));
k = bch2_btree_iter_peek(&iter); lockrestart_do(&trans, bkey_err(k = bch2_btree_iter_peek(&iter)));
ret = bkey_err(k); ret = bkey_err(k);
if (ret) { if (ret) {
bch_err(c, "error in rand_lookup: %s", bch2_err_str(ret)); bch_err(c, "error in rand_lookup: %s", bch2_err_str(ret));
...@@ -689,7 +726,7 @@ static int __do_delete(struct btree_trans *trans, struct bpos pos) ...@@ -689,7 +726,7 @@ static int __do_delete(struct btree_trans *trans, struct bpos pos)
bch2_trans_iter_init(trans, &iter, BTREE_ID_xattrs, pos, bch2_trans_iter_init(trans, &iter, BTREE_ID_xattrs, pos,
BTREE_ITER_INTENT); BTREE_ITER_INTENT);
k = bch2_btree_iter_peek(&iter); lockrestart_do(trans, bkey_err(k = bch2_btree_iter_peek(&iter)));
ret = bkey_err(k); ret = bkey_err(k);
if (ret) if (ret)
goto err; goto err;
...@@ -733,28 +770,23 @@ static int seq_insert(struct bch_fs *c, u64 nr) ...@@ -733,28 +770,23 @@ static int seq_insert(struct bch_fs *c, u64 nr)
struct bkey_s_c k; struct bkey_s_c k;
struct bkey_i_cookie insert; struct bkey_i_cookie insert;
int ret = 0; int ret = 0;
u64 i = 0;
bkey_cookie_init(&insert.k_i); bkey_cookie_init(&insert.k_i);
bch2_trans_init(&trans, c, 0, 0); bch2_trans_init(&trans, c, 0, 0);
for_each_btree_key(&trans, iter, BTREE_ID_xattrs, SPOS(0, 0, U32_MAX), ret = for_each_btree_key_commit(&trans, iter, BTREE_ID_xattrs,
BTREE_ITER_SLOTS|BTREE_ITER_INTENT, k, ret) { SPOS(0, 0, U32_MAX),
insert.k.p = iter.pos; BTREE_ITER_SLOTS|BTREE_ITER_INTENT, k,
NULL, NULL, 0,
ret = commit_do(&trans, NULL, NULL, 0, ({
bch2_btree_iter_traverse(&iter) ?: if (iter.pos.offset >= nr)
bch2_trans_update(&trans, &iter, &insert.k_i, 0)); break;
if (ret) { insert.k.p = iter.pos;
bch_err(c, "error in seq_insert: %s", bch2_err_str(ret)); bch2_trans_update(&trans, &iter, &insert.k_i, 0);
break; }));
} if (ret)
bch_err(c, "error in %s(): %s", __func__, bch2_err_str(ret));
if (++i == nr)
break;
}
bch2_trans_iter_exit(&trans, &iter);
bch2_trans_exit(&trans); bch2_trans_exit(&trans);
return ret; return ret;
...@@ -769,10 +801,11 @@ static int seq_lookup(struct bch_fs *c, u64 nr) ...@@ -769,10 +801,11 @@ 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, ret = for_each_btree_key2(&trans, iter, BTREE_ID_xattrs,
SPOS(0, 0, U32_MAX), 0, k, ret) SPOS(0, 0, U32_MAX), 0, k,
; 0);
bch2_trans_iter_exit(&trans, &iter); if (ret)
bch_err(c, "error in %s(): %s", __func__, bch2_err_str(ret));
bch2_trans_exit(&trans); bch2_trans_exit(&trans);
return ret; return ret;
...@@ -787,22 +820,18 @@ static int seq_overwrite(struct bch_fs *c, u64 nr) ...@@ -787,22 +820,18 @@ 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, ret = for_each_btree_key_commit(&trans, iter, BTREE_ID_xattrs,
SPOS(0, 0, U32_MAX), SPOS(0, 0, U32_MAX),
BTREE_ITER_INTENT, k, ret) { BTREE_ITER_INTENT, k,
struct bkey_i_cookie u; NULL, NULL, 0,
({
bkey_reassemble(&u.k_i, k); struct bkey_i_cookie u;
ret = commit_do(&trans, NULL, NULL, 0, bkey_reassemble(&u.k_i, k);
bch2_btree_iter_traverse(&iter) ?: bch2_trans_update(&trans, &iter, &u.k_i, 0);
bch2_trans_update(&trans, &iter, &u.k_i, 0)); }));
if (ret) { if (ret)
bch_err(c, "error in seq_overwrite: %s", bch2_err_str(ret)); bch_err(c, "error in %s(): %s", __func__, bch2_err_str(ret));
break;
}
}
bch2_trans_iter_exit(&trans, &iter);
bch2_trans_exit(&trans); bch2_trans_exit(&trans);
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