]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/tests.c
Update bcachefs sources to 2115a2ffde bcachefs: Kill bch2_verify_bucket_evacuated()
[bcachefs-tools-debian] / libbcachefs / tests.c
index 56058a56f2a287f812f2b6cf748633f480dae403..d352821d5614005aee064052fe841a6c87a64189 100644 (file)
@@ -15,13 +15,14 @@ static void delete_test_keys(struct bch_fs *c)
        int ret;
 
        ret = bch2_btree_delete_range(c, BTREE_ID_extents,
-                                     SPOS(0, 0, U32_MAX), SPOS_MAX,
-                                     0,
-                                     NULL);
+                                     SPOS(0, 0, U32_MAX),
+                                     POS(0, U64_MAX),
+                                     0, NULL);
        BUG_ON(ret);
 
        ret = bch2_btree_delete_range(c, BTREE_ID_xattrs,
-                                     SPOS(0, 0, U32_MAX), SPOS_MAX,
+                                     SPOS(0, 0, U32_MAX),
+                                     POS(0, U64_MAX),
                                      0, NULL);
        BUG_ON(ret);
 }
@@ -46,7 +47,7 @@ static int test_delete(struct bch_fs *c, u64 nr)
                bch2_btree_iter_traverse(&iter) ?:
                bch2_trans_update(&trans, &iter, &k.k_i, 0));
        if (ret) {
-               bch_err(c, "update error in test_delete: %s", bch2_err_str(ret));
+               bch_err(c, "%s(): update error in: %s", __func__, bch2_err_str(ret));
                goto err;
        }
 
@@ -55,7 +56,7 @@ static int test_delete(struct bch_fs *c, u64 nr)
                bch2_btree_iter_traverse(&iter) ?:
                bch2_btree_delete_at(&trans, &iter, 0));
        if (ret) {
-               bch_err(c, "delete error (first) in test_delete: %s", bch2_err_str(ret));
+               bch_err(c, "%s(): delete error (first): %s", __func__, bch2_err_str(ret));
                goto err;
        }
 
@@ -64,7 +65,7 @@ static int test_delete(struct bch_fs *c, u64 nr)
                bch2_btree_iter_traverse(&iter) ?:
                bch2_btree_delete_at(&trans, &iter, 0));
        if (ret) {
-               bch_err(c, "delete error (second) in test_delete: %s", bch2_err_str(ret));
+               bch_err(c, "%s(): delete error (second): %s", __func__, bch2_err_str(ret));
                goto err;
        }
 err:
@@ -92,7 +93,7 @@ static int test_delete_written(struct bch_fs *c, u64 nr)
                bch2_btree_iter_traverse(&iter) ?:
                bch2_trans_update(&trans, &iter, &k.k_i, 0));
        if (ret) {
-               bch_err(c, "update error in test_delete_written: %s", bch2_err_str(ret));
+               bch_err(c, "%s(): update error: %s", __func__, bch2_err_str(ret));
                goto err;
        }
 
@@ -103,7 +104,7 @@ static int test_delete_written(struct bch_fs *c, u64 nr)
                bch2_btree_iter_traverse(&iter) ?:
                bch2_btree_delete_at(&trans, &iter, 0));
        if (ret) {
-               bch_err(c, "delete error in test_delete_written: %s", bch2_err_str(ret));
+               bch_err(c, "%s(): delete error: %s", __func__, bch2_err_str(ret));
                goto err;
        }
 err:
@@ -136,7 +137,7 @@ static int test_iterate(struct bch_fs *c, u64 nr)
                ret = bch2_btree_insert(c, BTREE_ID_xattrs, &k.k_i,
                                        NULL, NULL, 0);
                if (ret) {
-                       bch_err(c, "insert error in test_iterate: %s", bch2_err_str(ret));
+                       bch_err(c, "%s(): insert error: %s", __func__, bch2_err_str(ret));
                        goto err;
                }
        }
@@ -145,8 +146,9 @@ static int test_iterate(struct bch_fs *c, u64 nr)
 
        i = 0;
 
-       ret = for_each_btree_key2(&trans, iter, BTREE_ID_xattrs,
-                                 SPOS(0, 0, U32_MAX), 0, k, ({
+       ret = for_each_btree_key2_upto(&trans, iter, BTREE_ID_xattrs,
+                                 SPOS(0, 0, U32_MAX), POS(0, U64_MAX),
+                                 0, k, ({
                BUG_ON(k.k->p.offset != i++);
                0;
        }));
@@ -202,7 +204,7 @@ static int test_iterate_extents(struct bch_fs *c, u64 nr)
                ret = bch2_btree_insert(c, BTREE_ID_extents, &k.k_i,
                                        NULL, NULL, 0);
                if (ret) {
-                       bch_err(c, "insert error in test_iterate_extents: %s", bch2_err_str(ret));
+                       bch_err(c, "%s(): insert error: %s", __func__, bch2_err_str(ret));
                        goto err;
                }
        }
@@ -211,8 +213,9 @@ static int test_iterate_extents(struct bch_fs *c, u64 nr)
 
        i = 0;
 
-       ret = for_each_btree_key2(&trans, iter, BTREE_ID_extents,
-                                 SPOS(0, 0, U32_MAX), 0, k, ({
+       ret = for_each_btree_key2_upto(&trans, iter, BTREE_ID_extents,
+                                 SPOS(0, 0, U32_MAX), POS(0, U64_MAX),
+                                 0, k, ({
                BUG_ON(bkey_start_offset(k.k) != i);
                i = k.k->p.offset;
                0;
@@ -269,7 +272,7 @@ static int test_iterate_slots(struct bch_fs *c, u64 nr)
                ret = bch2_btree_insert(c, BTREE_ID_xattrs, &k.k_i,
                                        NULL, NULL, 0);
                if (ret) {
-                       bch_err(c, "insert error in test_iterate_slots: %s", bch2_err_str(ret));
+                       bch_err(c, "%s(): insert error: %s", __func__, bch2_err_str(ret));
                        goto err;
                }
        }
@@ -278,8 +281,9 @@ static int test_iterate_slots(struct bch_fs *c, u64 nr)
 
        i = 0;
 
-       ret = for_each_btree_key2(&trans, iter, BTREE_ID_xattrs,
-                                 SPOS(0, 0, U32_MAX), 0, k, ({
+       ret = for_each_btree_key2_upto(&trans, iter, BTREE_ID_xattrs,
+                                 SPOS(0, 0, U32_MAX), POS(0, U64_MAX),
+                                 0, k, ({
                BUG_ON(k.k->p.offset != i);
                i += 2;
                0;
@@ -295,8 +299,8 @@ static int test_iterate_slots(struct bch_fs *c, u64 nr)
 
        i = 0;
 
-       ret = for_each_btree_key2(&trans, iter, BTREE_ID_xattrs,
-                                 SPOS(0, 0, U32_MAX),
+       ret = for_each_btree_key2_upto(&trans, iter, BTREE_ID_xattrs,
+                                 SPOS(0, 0, U32_MAX), POS(0, U64_MAX),
                                  BTREE_ITER_SLOTS, k, ({
                if (i >= nr * 2)
                        break;
@@ -342,7 +346,7 @@ static int test_iterate_slots_extents(struct bch_fs *c, u64 nr)
                ret = bch2_btree_insert(c, BTREE_ID_extents, &k.k_i,
                                        NULL, NULL, 0);
                if (ret) {
-                       bch_err(c, "insert error in test_iterate_slots_extents: %s", bch2_err_str(ret));
+                       bch_err(c, "%s(): insert error: %s", __func__, bch2_err_str(ret));
                        goto err;
                }
        }
@@ -351,8 +355,9 @@ static int test_iterate_slots_extents(struct bch_fs *c, u64 nr)
 
        i = 0;
 
-       ret = for_each_btree_key2(&trans, iter, BTREE_ID_extents,
-                                 SPOS(0, 0, U32_MAX), 0, k, ({
+       ret = for_each_btree_key2_upto(&trans, iter, BTREE_ID_extents,
+                                 SPOS(0, 0, U32_MAX), POS(0, U64_MAX),
+                                 0, k, ({
                BUG_ON(bkey_start_offset(k.k) != i + 8);
                BUG_ON(k.k->size != 8);
                i += 16;
@@ -369,8 +374,8 @@ static int test_iterate_slots_extents(struct bch_fs *c, u64 nr)
 
        i = 0;
 
-       ret = for_each_btree_key2(&trans, iter, BTREE_ID_extents,
-                                SPOS(0, 0, U32_MAX),
+       ret = for_each_btree_key2_upto(&trans, iter, BTREE_ID_extents,
+                                SPOS(0, 0, U32_MAX), POS(0, U64_MAX),
                                 BTREE_ITER_SLOTS, k, ({
                if (i == nr)
                        break;
@@ -405,10 +410,10 @@ static int test_peek_end(struct bch_fs *c, u64 nr)
        bch2_trans_iter_init(&trans, &iter, BTREE_ID_xattrs,
                             SPOS(0, 0, U32_MAX), 0);
 
-       lockrestart_do(&trans, bkey_err(k = bch2_btree_iter_peek(&iter)));
+       lockrestart_do(&trans, bkey_err(k = bch2_btree_iter_peek_upto(&iter, POS(0, U64_MAX))));
        BUG_ON(k.k);
 
-       lockrestart_do(&trans, bkey_err(k = bch2_btree_iter_peek(&iter)));
+       lockrestart_do(&trans, bkey_err(k = bch2_btree_iter_peek_upto(&iter, POS(0, U64_MAX))));
        BUG_ON(k.k);
 
        bch2_trans_iter_exit(&trans, &iter);
@@ -426,10 +431,10 @@ static int test_peek_end_extents(struct bch_fs *c, u64 nr)
        bch2_trans_iter_init(&trans, &iter, BTREE_ID_extents,
                             SPOS(0, 0, U32_MAX), 0);
 
-       lockrestart_do(&trans, bkey_err(k = bch2_btree_iter_peek(&iter)));
+       lockrestart_do(&trans, bkey_err(k = bch2_btree_iter_peek_upto(&iter, POS(0, U64_MAX))));
        BUG_ON(k.k);
 
-       lockrestart_do(&trans, bkey_err(k = bch2_btree_iter_peek(&iter)));
+       lockrestart_do(&trans, bkey_err(k = bch2_btree_iter_peek_upto(&iter, POS(0, U64_MAX))));
        BUG_ON(k.k);
 
        bch2_trans_iter_exit(&trans, &iter);
@@ -456,7 +461,7 @@ static int insert_test_extent(struct bch_fs *c,
        ret = bch2_btree_insert(c, BTREE_ID_extents, &k.k_i,
                                NULL, NULL, 0);
        if (ret)
-               bch_err(c, "insert error in insert_test_extent: %s", bch2_err_str(ret));
+               bch_err(c, "%s(): insert error: %s", __func__, bch2_err_str(ret));
        return ret;
 }
 
@@ -519,7 +524,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_iter_init(&trans, &iter, BTREE_ID_xattrs,
                             SPOS(0, 0, snapid_lo), 0);
-       lockrestart_do(&trans, bkey_err(k = bch2_btree_iter_peek(&iter)));
+       lockrestart_do(&trans, bkey_err(k = bch2_btree_iter_peek_upto(&iter, POS(0, U64_MAX))));
 
        BUG_ON(k.k->p.snapshot != U32_MAX);
 
@@ -555,7 +560,7 @@ static int test_snapshots(struct bch_fs *c, u64 nr)
 
        ret = test_snapshot_filter(c, snapids[0], snapids[1]);
        if (ret) {
-               bch_err(c, "err from test_snapshot_filter: %s", bch2_err_str(ret));
+               bch_err(c, "%s(): err from test_snapshot_filter: %s", __func__, bch2_err_str(ret));
                return ret;
        }
 
@@ -567,11 +572,8 @@ static int test_snapshots(struct bch_fs *c, u64 nr)
 static u64 test_rand(void)
 {
        u64 v;
-#if 0
-       v = prandom_u32();
-#else
-       prandom_bytes(&v, sizeof(v));
-#endif
+
+       get_random_bytes(&v, sizeof(v));
        return v;
 }
 
@@ -590,9 +592,9 @@ static int rand_insert(struct bch_fs *c, u64 nr)
                k.k.p.snapshot = U32_MAX;
 
                ret = commit_do(&trans, NULL, NULL, 0,
-                       __bch2_btree_insert(&trans, BTREE_ID_xattrs, &k.k_i));
+                       __bch2_btree_insert(&trans, BTREE_ID_xattrs, &k.k_i, 0));
                if (ret) {
-                       bch_err(c, "error in rand_insert: %s", bch2_err_str(ret));
+                       bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret));
                        break;
                }
        }
@@ -619,16 +621,16 @@ static int rand_insert_multi(struct bch_fs *c, u64 nr)
                }
 
                ret = commit_do(&trans, NULL, NULL, 0,
-                       __bch2_btree_insert(&trans, BTREE_ID_xattrs, &k[0].k_i) ?:
-                       __bch2_btree_insert(&trans, BTREE_ID_xattrs, &k[1].k_i) ?:
-                       __bch2_btree_insert(&trans, BTREE_ID_xattrs, &k[2].k_i) ?:
-                       __bch2_btree_insert(&trans, BTREE_ID_xattrs, &k[3].k_i) ?:
-                       __bch2_btree_insert(&trans, BTREE_ID_xattrs, &k[4].k_i) ?:
-                       __bch2_btree_insert(&trans, BTREE_ID_xattrs, &k[5].k_i) ?:
-                       __bch2_btree_insert(&trans, BTREE_ID_xattrs, &k[6].k_i) ?:
-                       __bch2_btree_insert(&trans, BTREE_ID_xattrs, &k[7].k_i));
+                       __bch2_btree_insert(&trans, BTREE_ID_xattrs, &k[0].k_i, 0) ?:
+                       __bch2_btree_insert(&trans, BTREE_ID_xattrs, &k[1].k_i, 0) ?:
+                       __bch2_btree_insert(&trans, BTREE_ID_xattrs, &k[2].k_i, 0) ?:
+                       __bch2_btree_insert(&trans, BTREE_ID_xattrs, &k[3].k_i, 0) ?:
+                       __bch2_btree_insert(&trans, BTREE_ID_xattrs, &k[4].k_i, 0) ?:
+                       __bch2_btree_insert(&trans, BTREE_ID_xattrs, &k[5].k_i, 0) ?:
+                       __bch2_btree_insert(&trans, BTREE_ID_xattrs, &k[6].k_i, 0) ?:
+                       __bch2_btree_insert(&trans, BTREE_ID_xattrs, &k[7].k_i, 0));
                if (ret) {
-                       bch_err(c, "error in rand_insert_multi: %s", bch2_err_str(ret));
+                       bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret));
                        break;
                }
        }
@@ -655,7 +657,7 @@ static int rand_lookup(struct bch_fs *c, u64 nr)
                lockrestart_do(&trans, bkey_err(k = bch2_btree_iter_peek(&iter)));
                ret = bkey_err(k);
                if (ret) {
-                       bch_err(c, "error in rand_lookup: %s", bch2_err_str(ret));
+                       bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret));
                        break;
                }
        }
@@ -675,10 +677,10 @@ static int rand_mixed_trans(struct btree_trans *trans,
 
        bch2_btree_iter_set_pos(iter, SPOS(0, pos, U32_MAX));
 
-       lockrestart_do(trans, bkey_err(k = bch2_btree_iter_peek(iter)));
+       k = bch2_btree_iter_peek(iter);
        ret = bkey_err(k);
        if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart))
-               bch_err(trans->c, "lookup error in rand_mixed: %s", bch2_err_str(ret));
+               bch_err(trans->c, "%s(): lookup error: %s", __func__, bch2_err_str(ret));
        if (ret)
                return ret;
 
@@ -708,7 +710,7 @@ static int rand_mixed(struct bch_fs *c, u64 nr)
                ret = commit_do(&trans, NULL, NULL, 0,
                        rand_mixed_trans(&trans, &iter, &cookie, i, rand));
                if (ret) {
-                       bch_err(c, "update error in rand_mixed: %s", bch2_err_str(ret));
+                       bch_err(c, "%s(): update error: %s", __func__, bch2_err_str(ret));
                        break;
                }
        }
@@ -754,7 +756,7 @@ static int rand_delete(struct bch_fs *c, u64 nr)
                ret = commit_do(&trans, NULL, NULL, 0,
                        __do_delete(&trans, pos));
                if (ret) {
-                       bch_err(c, "error in rand_delete: %s", bch2_err_str(ret));
+                       bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret));
                        break;
                }
        }
@@ -786,7 +788,7 @@ static int seq_insert(struct bch_fs *c, u64 nr)
                        bch2_trans_update(&trans, &iter, &insert.k_i, 0);
                }));
        if (ret)
-               bch_err(c, "error in %s(): %s", __func__, bch2_err_str(ret));
+               bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret));
 
        bch2_trans_exit(&trans);
        return ret;
@@ -801,11 +803,12 @@ static int seq_lookup(struct bch_fs *c, u64 nr)
 
        bch2_trans_init(&trans, c, 0, 0);
 
-       ret = for_each_btree_key2(&trans, iter, BTREE_ID_xattrs,
-                                 SPOS(0, 0, U32_MAX), 0, k,
+       ret = for_each_btree_key2_upto(&trans, iter, BTREE_ID_xattrs,
+                                 SPOS(0, 0, U32_MAX), POS(0, U64_MAX),
+                                 0, k,
                0);
        if (ret)
-               bch_err(c, "error in %s(): %s", __func__, bch2_err_str(ret));
+               bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret));
 
        bch2_trans_exit(&trans);
        return ret;
@@ -831,7 +834,7 @@ static int seq_overwrite(struct bch_fs *c, u64 nr)
                        bch2_trans_update(&trans, &iter, &u.k_i, 0);
                }));
        if (ret)
-               bch_err(c, "error in %s(): %s", __func__, bch2_err_str(ret));
+               bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret));
 
        bch2_trans_exit(&trans);
        return ret;
@@ -842,10 +845,11 @@ static int seq_delete(struct bch_fs *c, u64 nr)
        int ret;
 
        ret = bch2_btree_delete_range(c, BTREE_ID_xattrs,
-                                     SPOS(0, 0, U32_MAX), SPOS_MAX,
+                                     SPOS(0, 0, U32_MAX),
+                                     POS(0, U64_MAX),
                                      0, NULL);
        if (ret)
-               bch_err(c, "error in seq_delete: %s", bch2_err_str(ret));
+               bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret));
        return ret;
 }