Lines Matching defs:tx

43 typedef void (*dmu_tx_hold_func_t)(dmu_tx_t *tx, struct dnode *dn,
67 dmu_tx_t *tx = kmem_zalloc(sizeof (dmu_tx_t), KM_SLEEP);
68 tx->tx_dir = dd;
70 tx->tx_pool = dd->dd_pool;
71 list_create(&tx->tx_holds, sizeof (dmu_tx_hold_t),
73 list_create(&tx->tx_callbacks, sizeof (dmu_tx_callback_t),
75 tx->tx_start = gethrtime();
76 return (tx);
82 dmu_tx_t *tx = dmu_tx_create_dd(os->os_dsl_dataset->ds_dir);
83 tx->tx_objset = os;
84 return (tx);
90 dmu_tx_t *tx = dmu_tx_create_dd(NULL);
93 tx->tx_pool = dp;
94 tx->tx_txg = txg;
95 tx->tx_anyobj = TRUE;
97 return (tx);
101 dmu_tx_is_syncing(dmu_tx_t *tx)
103 return (tx->tx_anyobj);
107 dmu_tx_private_ok(dmu_tx_t *tx)
109 return (tx->tx_anyobj);
113 dmu_tx_hold_dnode_impl(dmu_tx_t *tx, dnode_t *dn, enum dmu_tx_hold_type type,
119 (void) zfs_refcount_add(&dn->dn_holds, tx);
120 if (tx->tx_txg != 0) {
123 * dn->dn_assigned_txg == tx->tx_txg doesn't pose a
128 dn->dn_assigned_txg = tx->tx_txg;
129 (void) zfs_refcount_add(&dn->dn_tx_holds, tx);
135 txh->txh_tx = tx;
142 list_insert_tail(&tx->tx_holds, txh);
148 dmu_tx_hold_object_impl(dmu_tx_t *tx, objset_t *os, uint64_t object,
158 tx->tx_err = err;
162 txh = dmu_tx_hold_dnode_impl(tx, dn, type, arg1, arg2);
169 dmu_tx_add_new_object(dmu_tx_t *tx, dnode_t *dn)
175 if (!dmu_tx_is_syncing(tx))
176 (void) dmu_tx_hold_dnode_impl(tx, dn, THT_NEWOBJECT, 0, 0);
355 dmu_tx_hold_write(dmu_tx_t *tx, uint64_t object, uint64_t off, int len)
359 ASSERT0(tx->tx_txg);
363 txh = dmu_tx_hold_object_impl(tx, tx->tx_objset,
372 dmu_tx_hold_write_by_dnode(dmu_tx_t *tx, dnode_t *dn, uint64_t off, int len)
376 ASSERT0(tx->tx_txg);
380 txh = dmu_tx_hold_dnode_impl(tx, dn, THT_WRITE, off, len);
393 dmu_tx_hold_append(dmu_tx_t *tx, uint64_t object, uint64_t off, int len)
397 ASSERT0(tx->tx_txg);
400 txh = dmu_tx_hold_object_impl(tx, tx->tx_objset,
409 dmu_tx_hold_append_by_dnode(dmu_tx_t *tx, dnode_t *dn, uint64_t off, int len)
413 ASSERT0(tx->tx_txg);
416 txh = dmu_tx_hold_dnode_impl(tx, dn, THT_APPEND, off, DMU_OBJECT_END);
432 dmu_tx_mark_netfree(dmu_tx_t *tx)
434 tx->tx_netfree = B_TRUE;
440 dmu_tx_t *tx = txh->txh_tx;
444 ASSERT(tx->tx_txg == 0);
491 zio_t *zio = zio_root(tx->tx_pool->dp_spa,
500 tx->tx_err = err;
510 tx->tx_err = err;
517 tx->tx_err = err;
524 dmu_tx_hold_free(dmu_tx_t *tx, uint64_t object, uint64_t off, uint64_t len)
528 txh = dmu_tx_hold_object_impl(tx, tx->tx_objset,
537 dmu_tx_hold_free_by_dnode(dmu_tx_t *tx, dnode_t *dn, uint64_t off, uint64_t len)
541 txh = dmu_tx_hold_dnode_impl(tx, dn, THT_FREE, off, len);
559 dmu_tx_hold_clone_by_dnode(dmu_tx_t *tx, dnode_t *dn, uint64_t off, int len)
563 ASSERT0(tx->tx_txg);
566 txh = dmu_tx_hold_dnode_impl(tx, dn, THT_CLONE, off, len);
576 dmu_tx_t *tx = txh->txh_tx;
580 ASSERT(tx->tx_txg == 0);
594 zap_get_micro_max_size(tx->tx_pool->dp_spa), FTAG);
608 tx->tx_err = err;
618 tx->tx_err = err;
624 dmu_tx_hold_zap(dmu_tx_t *tx, uint64_t object, int add, const char *name)
628 ASSERT0(tx->tx_txg);
630 txh = dmu_tx_hold_object_impl(tx, tx->tx_objset,
637 dmu_tx_hold_zap_by_dnode(dmu_tx_t *tx, dnode_t *dn, int add, const char *name)
641 ASSERT0(tx->tx_txg);
644 txh = dmu_tx_hold_dnode_impl(tx, dn, THT_ZAP, add, (uintptr_t)name);
650 dmu_tx_hold_bonus(dmu_tx_t *tx, uint64_t object)
654 ASSERT(tx->tx_txg == 0);
656 txh = dmu_tx_hold_object_impl(tx, tx->tx_objset,
663 dmu_tx_hold_bonus_by_dnode(dmu_tx_t *tx, dnode_t *dn)
667 ASSERT0(tx->tx_txg);
669 txh = dmu_tx_hold_dnode_impl(tx, dn, THT_BONUS, 0, 0);
675 dmu_tx_hold_space(dmu_tx_t *tx, uint64_t space)
679 ASSERT(tx->tx_txg == 0);
681 txh = dmu_tx_hold_object_impl(tx, tx->tx_objset,
691 dmu_tx_dirty_buf(dmu_tx_t *tx, dmu_buf_impl_t *db)
698 ASSERT(tx->tx_txg != 0);
699 ASSERT(tx->tx_objset == NULL || dn->dn_objset == tx->tx_objset);
702 if (tx->tx_anyobj) {
713 for (dmu_tx_hold_t *txh = list_head(&tx->tx_holds); txh != NULL;
714 txh = list_next(&tx->tx_holds, txh)) {
715 ASSERT3U(dn->dn_assigned_txg, ==, tx->tx_txg);
927 dmu_tx_delay(dmu_tx_t *tx, uint64_t dirty)
929 dsl_pool_t *dp = tx->tx_pool;
965 if (now > tx->tx_start + tx_time)
968 DTRACE_PROBE3(delay__mintime, dmu_tx_t *, tx, uint64_t, dirty,
972 wakeup = MAX(tx->tx_start + tx_time, dp->dp_last_wakeup + tx_time);
1019 dmu_tx_try_assign(dmu_tx_t *tx, uint64_t txg_how)
1021 spa_t *spa = tx->tx_pool->dp_spa;
1023 ASSERT0(tx->tx_txg);
1025 if (tx->tx_err) {
1027 return (tx->tx_err);
1049 if (!tx->tx_dirty_delayed &&
1050 dsl_pool_need_wrlog_delay(tx->tx_pool)) {
1051 tx->tx_wait_dirty = B_TRUE;
1056 if (!tx->tx_dirty_delayed &&
1057 dsl_pool_need_dirty_delay(tx->tx_pool)) {
1058 tx->tx_wait_dirty = B_TRUE;
1063 tx->tx_txg = txg_hold_open(tx->tx_pool, &tx->tx_txgh);
1064 tx->tx_needassign_txh = NULL;
1074 for (dmu_tx_hold_t *txh = list_head(&tx->tx_holds); txh != NULL;
1075 txh = list_next(&tx->tx_holds, txh)) {
1080 * while assigning the tx, because this can lead to
1086 * syncing until its tx can complete (calling
1098 if (dn->dn_assigned_txg == tx->tx_txg - 1) {
1100 tx->tx_needassign_txh = txh;
1105 dn->dn_assigned_txg = tx->tx_txg;
1106 ASSERT3U(dn->dn_assigned_txg, ==, tx->tx_txg);
1107 (void) zfs_refcount_add(&dn->dn_tx_holds, tx);
1115 uint64_t asize = spa_get_worst_case_asize(tx->tx_pool->dp_spa, towrite);
1119 if (tx->tx_dir != NULL && asize != 0) {
1120 int err = dsl_dir_tempreserve_space(tx->tx_dir, memory,
1121 asize, tx->tx_netfree, &tx->tx_tempreserve_cookie, tx);
1132 dmu_tx_unassign(dmu_tx_t *tx)
1134 if (tx->tx_txg == 0)
1137 txg_rele_to_quiesce(&tx->tx_txgh);
1143 for (dmu_tx_hold_t *txh = list_head(&tx->tx_holds);
1144 txh && txh != tx->tx_needassign_txh;
1145 txh = list_next(&tx->tx_holds, txh)) {
1151 ASSERT3U(dn->dn_assigned_txg, ==, tx->tx_txg);
1153 if (zfs_refcount_remove(&dn->dn_tx_holds, tx) == 0) {
1160 txg_rele_to_sync(&tx->tx_txgh);
1162 tx->tx_lasttried_txg = tx->tx_txg;
1163 tx->tx_txg = 0;
1167 * Assign tx to a transaction group; txg_how is a bitmask:
1180 * If TXG_NOTHROTTLE is set, this indicates that this tx should not be
1184 * different tx).
1187 * will assign the tx to monotonically increasing txgs. Of course this is
1203 dmu_tx_assign(dmu_tx_t *tx, uint64_t txg_how)
1207 ASSERT(tx->tx_txg == 0);
1209 ASSERT(!dsl_pool_sync_context(tx->tx_pool));
1212 IMPLY((txg_how & TXG_WAIT), !dsl_pool_config_held(tx->tx_pool));
1215 tx->tx_dirty_delayed = B_TRUE;
1217 while ((err = dmu_tx_try_assign(tx, txg_how)) != 0) {
1218 dmu_tx_unassign(tx);
1223 dmu_tx_wait(tx);
1226 txg_rele_to_quiesce(&tx->tx_txgh);
1232 dmu_tx_wait(dmu_tx_t *tx)
1234 spa_t *spa = tx->tx_pool->dp_spa;
1235 dsl_pool_t *dp = tx->tx_pool;
1238 ASSERT(tx->tx_txg == 0);
1239 ASSERT(!dsl_pool_config_held(tx->tx_pool));
1243 if (tx->tx_wait_dirty) {
1259 dmu_tx_delay(tx, dirty);
1261 tx->tx_wait_dirty = B_FALSE;
1266 * destroy this tx and try again. The common case,
1269 tx->tx_dirty_delayed = B_TRUE;
1270 } else if (spa_suspended(spa) || tx->tx_lasttried_txg == 0) {
1275 * obtain a tx. If that's the case then tx_lasttried_txg
1279 } else if (tx->tx_needassign_txh) {
1280 dnode_t *dn = tx->tx_needassign_txh->txh_dnode;
1283 while (dn->dn_assigned_txg == tx->tx_lasttried_txg - 1)
1286 tx->tx_needassign_txh = NULL;
1300 dmu_tx_destroy(dmu_tx_t *tx)
1304 while ((txh = list_head(&tx->tx_holds)) != NULL) {
1307 list_remove(&tx->tx_holds, txh);
1314 dnode_rele(dn, tx);
1317 list_destroy(&tx->tx_callbacks);
1318 list_destroy(&tx->tx_holds);
1319 kmem_free(tx, sizeof (dmu_tx_t));
1323 dmu_tx_commit(dmu_tx_t *tx)
1325 ASSERT(tx->tx_txg != 0);
1331 for (dmu_tx_hold_t *txh = list_head(&tx->tx_holds); txh != NULL;
1332 txh = list_next(&tx->tx_holds, txh)) {
1339 ASSERT3U(dn->dn_assigned_txg, ==, tx->tx_txg);
1341 if (zfs_refcount_remove(&dn->dn_tx_holds, tx) == 0) {
1348 if (tx->tx_tempreserve_cookie)
1349 dsl_dir_tempreserve_clear(tx->tx_tempreserve_cookie, tx);
1351 if (!list_is_empty(&tx->tx_callbacks))
1352 txg_register_callbacks(&tx->tx_txgh, &tx->tx_callbacks);
1354 if (tx->tx_anyobj == FALSE)
1355 txg_rele_to_sync(&tx->tx_txgh);
1357 dmu_tx_destroy(tx);
1361 dmu_tx_abort(dmu_tx_t *tx)
1363 ASSERT(tx->tx_txg == 0);
1368 if (!list_is_empty(&tx->tx_callbacks))
1369 dmu_tx_do_callbacks(&tx->tx_callbacks, SET_ERROR(ECANCELED));
1371 dmu_tx_destroy(tx);
1375 dmu_tx_get_txg(dmu_tx_t *tx)
1377 ASSERT(tx->tx_txg != 0);
1378 return (tx->tx_txg);
1382 dmu_tx_pool(dmu_tx_t *tx)
1384 ASSERT(tx->tx_pool != NULL);
1385 return (tx->tx_pool);
1396 dmu_tx_callback_register(dmu_tx_t *tx, dmu_tx_callback_func_t *func, void *data)
1405 list_insert_tail(&tx->tx_callbacks, dcb);
1437 dmu_tx_sa_registration_hold(sa_os_t *sa, dmu_tx_t *tx)
1445 dmu_tx_hold_zap(tx, sa->sa_reg_attr_obj,
1448 dmu_tx_hold_zap(tx, DMU_NEW_OBJECT,
1455 dmu_tx_hold_spill(dmu_tx_t *tx, uint64_t object)
1459 txh = dmu_tx_hold_object_impl(tx, tx->tx_objset, object,
1467 dmu_tx_hold_sa_create(dmu_tx_t *tx, int attrsize)
1469 sa_os_t *sa = tx->tx_objset->os_sa;
1471 dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
1473 if (tx->tx_objset->os_sa->sa_master_obj == 0)
1476 if (tx->tx_objset->os_sa->sa_layout_attr_obj) {
1477 dmu_tx_hold_zap(tx, sa->sa_layout_attr_obj, B_TRUE, NULL);
1479 dmu_tx_hold_zap(tx, sa->sa_master_obj, B_TRUE, SA_LAYOUTS);
1480 dmu_tx_hold_zap(tx, sa->sa_master_obj, B_TRUE, SA_REGISTRY);
1481 dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, B_TRUE, NULL);
1482 dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, B_TRUE, NULL);
1485 dmu_tx_sa_registration_hold(sa, tx);
1490 (void) dmu_tx_hold_object_impl(tx, tx->tx_objset, DMU_NEW_OBJECT,
1497 * dmu_tx_hold_sa(dmu_tx_t *tx, sa_handle_t *, attribute, add, size)
1504 dmu_tx_hold_sa(dmu_tx_t *tx, sa_handle_t *hdl, boolean_t may_grow)
1507 sa_os_t *sa = tx->tx_objset->os_sa;
1515 dmu_tx_hold_bonus_by_dnode(tx, DB_DNODE(db));
1518 if (tx->tx_objset->os_sa->sa_master_obj == 0)
1521 if (tx->tx_objset->os_sa->sa_reg_attr_obj == 0 ||
1522 tx->tx_objset->os_sa->sa_layout_attr_obj == 0) {
1523 dmu_tx_hold_zap(tx, sa->sa_master_obj, B_TRUE, SA_LAYOUTS);
1524 dmu_tx_hold_zap(tx, sa->sa_master_obj, B_TRUE, SA_REGISTRY);
1525 dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, B_TRUE, NULL);
1526 dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, B_TRUE, NULL);
1529 dmu_tx_sa_registration_hold(sa, tx);
1531 if (may_grow && tx->tx_objset->os_sa->sa_layout_attr_obj)
1532 dmu_tx_hold_zap(tx, sa->sa_layout_attr_obj, B_TRUE, NULL);
1535 ASSERT(tx->tx_txg == 0);
1536 dmu_tx_hold_spill(tx, object);
1540 ASSERT(tx->tx_txg == 0);
1541 dmu_tx_hold_spill(tx, object);