* Commit callback test. */
| 5503 | * Commit callback test. |
| 5504 | */ |
| 5505 | void |
| 5506 | ztest_dmu_commit_callbacks(ztest_ds_t *zd, uint64_t id) |
| 5507 | { |
| 5508 | objset_t *os = zd->zd_os; |
| 5509 | ztest_od_t *od; |
| 5510 | dmu_tx_t *tx; |
| 5511 | ztest_cb_data_t *cb_data[3], *tmp_cb; |
| 5512 | uint64_t old_txg, txg; |
| 5513 | int i, error = 0; |
| 5514 | |
| 5515 | od = umem_alloc(sizeof (ztest_od_t), UMEM_NOFAIL); |
| 5516 | ztest_od_init(od, id, FTAG, 0, DMU_OT_UINT64_OTHER, 0, 0, 0); |
| 5517 | |
| 5518 | if (ztest_object_init(zd, od, sizeof (ztest_od_t), B_FALSE) != 0) { |
| 5519 | umem_free(od, sizeof (ztest_od_t)); |
| 5520 | return; |
| 5521 | } |
| 5522 | |
| 5523 | tx = dmu_tx_create(os); |
| 5524 | |
| 5525 | cb_data[0] = ztest_create_cb_data(os, 0); |
| 5526 | dmu_tx_callback_register(tx, ztest_commit_callback, cb_data[0]); |
| 5527 | |
| 5528 | dmu_tx_hold_write(tx, od->od_object, 0, sizeof (uint64_t)); |
| 5529 | |
| 5530 | /* Every once in a while, abort the transaction on purpose */ |
| 5531 | if (ztest_random(100) == 0) |
| 5532 | error = -1; |
| 5533 | |
| 5534 | if (!error) |
| 5535 | error = dmu_tx_assign(tx, TXG_NOWAIT); |
| 5536 | |
| 5537 | txg = error ? 0 : dmu_tx_get_txg(tx); |
| 5538 | |
| 5539 | cb_data[0]->zcd_txg = txg; |
| 5540 | cb_data[1] = ztest_create_cb_data(os, txg); |
| 5541 | dmu_tx_callback_register(tx, ztest_commit_callback, cb_data[1]); |
| 5542 | |
| 5543 | if (error) { |
| 5544 | /* |
| 5545 | * It's not a strict requirement to call the registered |
| 5546 | * callbacks from inside dmu_tx_abort(), but that's what |
| 5547 | * it's supposed to happen in the current implementation |
| 5548 | * so we will check for that. |
| 5549 | */ |
| 5550 | for (i = 0; i < 2; i++) { |
| 5551 | cb_data[i]->zcd_expected_err = ECANCELED; |
| 5552 | VERIFY(!cb_data[i]->zcd_called); |
| 5553 | } |
| 5554 | |
| 5555 | dmu_tx_abort(tx); |
| 5556 | |
| 5557 | for (i = 0; i < 2; i++) { |
| 5558 | VERIFY(cb_data[i]->zcd_called); |
| 5559 | umem_free(cb_data[i], sizeof (ztest_cb_data_t)); |
| 5560 | } |
| 5561 | |
| 5562 | umem_free(od, sizeof (ztest_od_t)); |
nothing calls this directly
no test coverage detected