Skip to content

Commit 5ad7e69

Browse files
amotinbehlendorf
authored andcommitted
Make TX abort after assign safer
It is not right, but there are few examples when TX is aborted after being assigned in case of error. To handle it better on production systems add extra cleanup steps. While here, replace couple dmu_tx_abort() in simple cases. Reviewed-by: Rob Norris <robn@despairlabs.com> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Igor Kozhukhov <igor@dilos.org> Signed-off-by: Alexander Motin <mav@FreeBSD.org> Sponsored by: iXsystems, Inc. Closes #17438
1 parent 7119b8f commit 5ad7e69

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

module/zfs/dmu_tx.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,7 @@ dmu_tx_destroy(dmu_tx_t *tx)
13231323
void
13241324
dmu_tx_commit(dmu_tx_t *tx)
13251325
{
1326+
/* This function should only be used on assigned transactions. */
13261327
ASSERT(tx->tx_txg != 0);
13271328

13281329
/*
@@ -1361,14 +1362,22 @@ dmu_tx_commit(dmu_tx_t *tx)
13611362
void
13621363
dmu_tx_abort(dmu_tx_t *tx)
13631364
{
1364-
ASSERT(tx->tx_txg == 0);
1365+
/* This function should not be used on assigned transactions. */
1366+
ASSERT0(tx->tx_txg);
1367+
1368+
/* Should not be needed, but better be safe than sorry. */
1369+
if (tx->tx_tempreserve_cookie)
1370+
dsl_dir_tempreserve_clear(tx->tx_tempreserve_cookie, tx);
13651371

13661372
/*
13671373
* Call any registered callbacks with an error code.
13681374
*/
13691375
if (!list_is_empty(&tx->tx_callbacks))
13701376
dmu_tx_do_callbacks(&tx->tx_callbacks, SET_ERROR(ECANCELED));
13711377

1378+
/* Should not be needed, but better be safe than sorry. */
1379+
dmu_tx_unassign(tx);
1380+
13721381
dmu_tx_destroy(tx);
13731382
}
13741383

module/zfs/zfs_vnops.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1681,7 +1681,7 @@ zfs_clone_range(znode_t *inzp, uint64_t *inoffp, znode_t *outzp,
16811681
*/
16821682
if (inblksz != outzp->z_blksz) {
16831683
error = SET_ERROR(EINVAL);
1684-
dmu_tx_abort(tx);
1684+
dmu_tx_commit(tx);
16851685
break;
16861686
}
16871687

0 commit comments

Comments
 (0)