Skip to content

dmu_tx: rename dmu_tx_assign() flags from TXG_* to DMU_TX_* #17143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions cmd/ztest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1811,7 +1811,8 @@ ztest_zd_fini(ztest_ds_t *zd)
ztest_rll_destroy(&zd->zd_range_lock[l]);
}

#define TXG_MIGHTWAIT (ztest_random(10) == 0 ? TXG_NOWAIT : TXG_WAIT)
#define DMU_TX_MIGHTWAIT \
(ztest_random(10) == 0 ? DMU_TX_NOWAIT : DMU_TX_WAIT)

static uint64_t
ztest_tx_assign(dmu_tx_t *tx, uint64_t txg_how, const char *tag)
Expand All @@ -1825,7 +1826,7 @@ ztest_tx_assign(dmu_tx_t *tx, uint64_t txg_how, const char *tag)
error = dmu_tx_assign(tx, txg_how);
if (error) {
if (error == ERESTART) {
ASSERT3U(txg_how, ==, TXG_NOWAIT);
ASSERT3U(txg_how, ==, DMU_TX_NOWAIT);
dmu_tx_wait(tx);
} else {
ASSERT3U(error, ==, ENOSPC);
Expand Down Expand Up @@ -2072,7 +2073,7 @@ ztest_replay_create(void *arg1, void *arg2, boolean_t byteswap)
dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
}

txg = ztest_tx_assign(tx, TXG_WAIT, FTAG);
txg = ztest_tx_assign(tx, DMU_TX_WAIT, FTAG);
if (txg == 0)
return (ENOSPC);

Expand Down Expand Up @@ -2162,7 +2163,7 @@ ztest_replay_remove(void *arg1, void *arg2, boolean_t byteswap)
dmu_tx_hold_zap(tx, lr->lr_doid, B_FALSE, name);
dmu_tx_hold_free(tx, object, 0, DMU_OBJECT_END);

txg = ztest_tx_assign(tx, TXG_WAIT, FTAG);
txg = ztest_tx_assign(tx, DMU_TX_WAIT, FTAG);
if (txg == 0) {
ztest_object_unlock(zd, object);
return (ENOSPC);
Expand Down Expand Up @@ -2244,7 +2245,7 @@ ztest_replay_write(void *arg1, void *arg2, boolean_t byteswap)
P2PHASE(offset, length) == 0)
abuf = dmu_request_arcbuf(db, length);

txg = ztest_tx_assign(tx, TXG_WAIT, FTAG);
txg = ztest_tx_assign(tx, DMU_TX_WAIT, FTAG);
if (txg == 0) {
if (abuf != NULL)
dmu_return_arcbuf(abuf);
Expand Down Expand Up @@ -2342,7 +2343,7 @@ ztest_replay_truncate(void *arg1, void *arg2, boolean_t byteswap)

dmu_tx_hold_free(tx, lr->lr_foid, lr->lr_offset, lr->lr_length);

txg = ztest_tx_assign(tx, TXG_WAIT, FTAG);
txg = ztest_tx_assign(tx, DMU_TX_WAIT, FTAG);
if (txg == 0) {
ztest_range_unlock(rl);
ztest_object_unlock(zd, lr->lr_foid);
Expand Down Expand Up @@ -2383,7 +2384,7 @@ ztest_replay_setattr(void *arg1, void *arg2, boolean_t byteswap)
tx = dmu_tx_create(os);
dmu_tx_hold_bonus(tx, lr->lr_foid);

txg = ztest_tx_assign(tx, TXG_WAIT, FTAG);
txg = ztest_tx_assign(tx, DMU_TX_WAIT, FTAG);
if (txg == 0) {
dmu_buf_rele(db, FTAG);
ztest_object_unlock(zd, lr->lr_foid);
Expand Down Expand Up @@ -2801,7 +2802,7 @@ ztest_prealloc(ztest_ds_t *zd, uint64_t object, uint64_t offset, uint64_t size)

dmu_tx_hold_write(tx, object, offset, size);

txg = ztest_tx_assign(tx, TXG_WAIT, FTAG);
txg = ztest_tx_assign(tx, DMU_TX_WAIT, FTAG);

if (txg != 0) {
dmu_prealloc(os, object, offset, size, tx);
Expand Down Expand Up @@ -5169,7 +5170,7 @@ ztest_dmu_read_write(ztest_ds_t *zd, uint64_t id)
/* This accounts for setting the checksum/compression. */
dmu_tx_hold_bonus(tx, bigobj);

txg = ztest_tx_assign(tx, TXG_MIGHTWAIT, FTAG);
txg = ztest_tx_assign(tx, DMU_TX_MIGHTWAIT, FTAG);
if (txg == 0) {
umem_free(packbuf, packsize);
umem_free(bigbuf, bigsize);
Expand Down Expand Up @@ -5470,7 +5471,7 @@ ztest_dmu_read_write_zcopy(ztest_ds_t *zd, uint64_t id)
dmu_tx_hold_write(tx, packobj, packoff, packsize);
dmu_tx_hold_write(tx, bigobj, bigoff, bigsize);

txg = ztest_tx_assign(tx, TXG_MIGHTWAIT, FTAG);
txg = ztest_tx_assign(tx, DMU_TX_MIGHTWAIT, FTAG);
if (txg == 0) {
umem_free(packbuf, packsize);
umem_free(bigbuf, bigsize);
Expand Down Expand Up @@ -5690,7 +5691,7 @@ ztest_zap(ztest_ds_t *zd, uint64_t id)
*/
tx = dmu_tx_create(os);
dmu_tx_hold_zap(tx, object, B_TRUE, NULL);
txg = ztest_tx_assign(tx, TXG_MIGHTWAIT, FTAG);
txg = ztest_tx_assign(tx, DMU_TX_MIGHTWAIT, FTAG);
if (txg == 0)
goto out;
for (i = 0; i < 2; i++) {
Expand Down Expand Up @@ -5758,7 +5759,7 @@ ztest_zap(ztest_ds_t *zd, uint64_t id)
*/
tx = dmu_tx_create(os);
dmu_tx_hold_zap(tx, object, B_TRUE, NULL);
txg = ztest_tx_assign(tx, TXG_MIGHTWAIT, FTAG);
txg = ztest_tx_assign(tx, DMU_TX_MIGHTWAIT, FTAG);
if (txg == 0)
goto out;

Expand Down Expand Up @@ -5792,7 +5793,7 @@ ztest_zap(ztest_ds_t *zd, uint64_t id)

tx = dmu_tx_create(os);
dmu_tx_hold_zap(tx, object, B_TRUE, NULL);
txg = ztest_tx_assign(tx, TXG_MIGHTWAIT, FTAG);
txg = ztest_tx_assign(tx, DMU_TX_MIGHTWAIT, FTAG);
if (txg == 0)
goto out;
VERIFY0(zap_remove(os, object, txgname, tx));
Expand Down Expand Up @@ -5835,7 +5836,7 @@ ztest_fzap(ztest_ds_t *zd, uint64_t id)

tx = dmu_tx_create(os);
dmu_tx_hold_zap(tx, object, B_TRUE, name);
txg = ztest_tx_assign(tx, TXG_MIGHTWAIT, FTAG);
txg = ztest_tx_assign(tx, DMU_TX_MIGHTWAIT, FTAG);
if (txg == 0)
goto out;
error = zap_add(os, object, name, sizeof (uint64_t), 1,
Expand Down Expand Up @@ -5906,7 +5907,7 @@ ztest_zap_parallel(ztest_ds_t *zd, uint64_t id)
if (i >= 2) {
tx = dmu_tx_create(os);
dmu_tx_hold_zap(tx, object, B_TRUE, NULL);
txg = ztest_tx_assign(tx, TXG_MIGHTWAIT, FTAG);
txg = ztest_tx_assign(tx, DMU_TX_MIGHTWAIT, FTAG);
if (txg == 0) {
umem_free(od, sizeof (ztest_od_t));
return;
Expand Down Expand Up @@ -6072,7 +6073,7 @@ ztest_dmu_commit_callbacks(ztest_ds_t *zd, uint64_t id)
error = -1;

if (!error)
error = dmu_tx_assign(tx, TXG_NOWAIT);
error = dmu_tx_assign(tx, DMU_TX_NOWAIT);

txg = error ? 0 : dmu_tx_get_txg(tx);

Expand Down
15 changes: 8 additions & 7 deletions include/sys/dmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* Copyright 2013 Saso Kiselkov. All rights reserved.
* Copyright (c) 2017, Intel Corporation.
* Copyright (c) 2022 Hewlett Packard Enterprise Development LP.
* Copyright (c) 2025, Klara, Inc.
*/

/* Portions Copyright 2010 Robert Milkowski */
Expand Down Expand Up @@ -275,13 +276,13 @@ typedef enum dmu_object_type {
} dmu_object_type_t;

/*
* These flags are intended to be used to specify the "txg_how"
* parameter when calling the dmu_tx_assign() function. See the comment
* above dmu_tx_assign() for more details on the meaning of these flags.
* These flags are for the dmu_tx_assign() function and describe what to do if
* the transaction is full. See the comment above dmu_tx_assign() for more
* details on the meaning of these flags.
*/
#define TXG_NOWAIT (0ULL)
#define TXG_WAIT (1ULL<<0)
#define TXG_NOTHROTTLE (1ULL<<1)
#define DMU_TX_NOWAIT (0ULL)
#define DMU_TX_WAIT (1ULL<<0)
#define DMU_TX_NOTHROTTLE (1ULL<<1)

void byteswap_uint64_array(void *buf, size_t size);
void byteswap_uint32_array(void *buf, size_t size);
Expand Down Expand Up @@ -826,7 +827,7 @@ void dmu_tx_hold_spill(dmu_tx_t *tx, uint64_t object);
void dmu_tx_hold_sa(dmu_tx_t *tx, struct sa_handle *hdl, boolean_t may_grow);
void dmu_tx_hold_sa_create(dmu_tx_t *tx, int total_size);
void dmu_tx_abort(dmu_tx_t *tx);
int dmu_tx_assign(dmu_tx_t *tx, uint64_t txg_how);
int dmu_tx_assign(dmu_tx_t *tx, uint64_t flags);
void dmu_tx_wait(dmu_tx_t *tx);
void dmu_tx_commit(dmu_tx_t *tx);
void dmu_tx_mark_netfree(dmu_tx_t *tx);
Expand Down
2 changes: 1 addition & 1 deletion module/os/freebsd/zfs/zfs_acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1997,7 +1997,7 @@ zfs_setacl(znode_t *zp, vsecattr_t *vsecp, boolean_t skipaclchk, cred_t *cr)
}

zfs_sa_upgrade_txholds(tx, zp);
error = dmu_tx_assign(tx, TXG_NOWAIT);
error = dmu_tx_assign(tx, DMU_TX_NOWAIT);
if (error) {
mutex_exit(&zp->z_acl_lock);

Expand Down
8 changes: 4 additions & 4 deletions module/os/freebsd/zfs/zfs_dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ zfs_unlinked_drain(zfsvfs_t *zfsvfs)
if (zp->z_links != 0) {
tx = dmu_tx_create(zfsvfs->z_os);
dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
error = dmu_tx_assign(tx, TXG_WAIT);
error = dmu_tx_assign(tx, DMU_TX_WAIT);
if (error != 0) {
dmu_tx_abort(tx);
vput(ZTOV(zp));
Expand Down Expand Up @@ -400,7 +400,7 @@ zfs_purgedir(znode_t *dzp)
/* Is this really needed ? */
zfs_sa_upgrade_txholds(tx, xzp);
dmu_tx_mark_netfree(tx);
error = dmu_tx_assign(tx, TXG_WAIT);
error = dmu_tx_assign(tx, DMU_TX_WAIT);
if (error) {
dmu_tx_abort(tx);
vput(ZTOV(xzp));
Expand Down Expand Up @@ -502,7 +502,7 @@ zfs_rmnode(znode_t *zp)
dmu_tx_hold_free(tx, acl_obj, 0, DMU_OBJECT_END);

zfs_sa_upgrade_txholds(tx, zp);
error = dmu_tx_assign(tx, TXG_WAIT);
error = dmu_tx_assign(tx, DMU_TX_WAIT);
if (error) {
/*
* Not enough space to delete the file. Leave it in the
Expand Down Expand Up @@ -847,7 +847,7 @@ zfs_make_xattrdir(znode_t *zp, vattr_t *vap, znode_t **xvpp, cred_t *cr)
fuid_dirtied = zfsvfs->z_fuid_dirty;
if (fuid_dirtied)
zfs_fuid_txhold(zfsvfs, tx);
error = dmu_tx_assign(tx, TXG_WAIT);
error = dmu_tx_assign(tx, DMU_TX_WAIT);
if (error) {
zfs_acl_ids_free(&acl_ids);
dmu_tx_abort(tx);
Expand Down
2 changes: 1 addition & 1 deletion module/os/freebsd/zfs/zfs_vfsops.c
Original file line number Diff line number Diff line change
Expand Up @@ -2197,7 +2197,7 @@ zfs_set_version(zfsvfs_t *zfsvfs, uint64_t newvers)
ZFS_SA_ATTRS);
dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, FALSE, NULL);
}
error = dmu_tx_assign(tx, TXG_WAIT);
error = dmu_tx_assign(tx, DMU_TX_WAIT);
if (error) {
dmu_tx_abort(tx);
return (error);
Expand Down
50 changes: 26 additions & 24 deletions module/os/freebsd/zfs/zfs_vnops_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,30 +142,31 @@ typedef ulong_t cookie_t;
* (3) All range locks must be grabbed before calling dmu_tx_assign(),
* as they can span dmu_tx_assign() calls.
*
* (4) If ZPL locks are held, pass TXG_NOWAIT as the second argument to
* (4) If ZPL locks are held, pass DMU_TX_NOWAIT as the second argument to
* dmu_tx_assign(). This is critical because we don't want to block
* while holding locks.
*
* If no ZPL locks are held (aside from zfs_enter()), use TXG_WAIT. This
* reduces lock contention and CPU usage when we must wait (note that if
* throughput is constrained by the storage, nearly every transaction
* must wait).
* If no ZPL locks are held (aside from zfs_enter()), use DMU_TX_WAIT.
* This reduces lock contention and CPU usage when we must wait (note
* that if throughput is constrained by the storage, nearly every
* transaction must wait).
*
* Note, in particular, that if a lock is sometimes acquired before
* the tx assigns, and sometimes after (e.g. z_lock), then failing
* to use a non-blocking assign can deadlock the system. The scenario:
*
* Thread A has grabbed a lock before calling dmu_tx_assign().
* Thread B is in an already-assigned tx, and blocks for this lock.
* Thread A calls dmu_tx_assign(TXG_WAIT) and blocks in txg_wait_open()
* forever, because the previous txg can't quiesce until B's tx commits.
* Thread A calls dmu_tx_assign(DMU_TX_WAIT) and blocks in
* txg_wait_open() forever, because the previous txg can't quiesce
* until B's tx commits.
*
* If dmu_tx_assign() returns ERESTART and zfsvfs->z_assign is TXG_NOWAIT,
* then drop all locks, call dmu_tx_wait(), and try again. On subsequent
* calls to dmu_tx_assign(), pass TXG_NOTHROTTLE in addition to TXG_NOWAIT,
* to indicate that this operation has already called dmu_tx_wait().
* This will ensure that we don't retry forever, waiting a short bit
* each time.
* If dmu_tx_assign() returns ERESTART and zfsvfs->z_assign is
* DMU_TX_NOWAIT, then drop all locks, call dmu_tx_wait(), and try
* again. On subsequent calls to dmu_tx_assign(), pass
* DMU_TX_NOTHROTTLE in addition to DMU_TX_NOWAIT, to indicate that
* this operation has already called dmu_tx_wait(). This will ensure
* that we don't retry forever, waiting a short bit each time.
*
* (5) If the operation succeeded, generate the intent log entry for it
* before dropping locks. This ensures that the ordering of events
Expand All @@ -187,7 +188,8 @@ typedef ulong_t cookie_t;
* rw_enter(...); // grab any other locks you need
* tx = dmu_tx_create(...); // get DMU tx
* dmu_tx_hold_*(); // hold each object you might modify
* error = dmu_tx_assign(tx, (waited ? TXG_NOTHROTTLE : 0) | TXG_NOWAIT);
* error = dmu_tx_assign(tx,
* (waited ? DMU_TX_NOTHROTTLE : 0) | DMU_TX_NOWAIT);
* if (error) {
* rw_exit(...); // drop locks
* zfs_dirent_unlock(dl); // unlock directory entry
Expand Down Expand Up @@ -1044,7 +1046,7 @@ zfs_create(znode_t *dzp, const char *name, vattr_t *vap, int excl, int mode,
dmu_tx_hold_write(tx, DMU_NEW_OBJECT,
0, acl_ids.z_aclp->z_acl_bytes);
}
error = dmu_tx_assign(tx, TXG_WAIT);
error = dmu_tx_assign(tx, DMU_TX_WAIT);
if (error) {
zfs_acl_ids_free(&acl_ids);
dmu_tx_abort(tx);
Expand Down Expand Up @@ -1185,7 +1187,7 @@ zfs_remove_(vnode_t *dvp, vnode_t *vp, const char *name, cred_t *cr)
*/
dmu_tx_mark_netfree(tx);

error = dmu_tx_assign(tx, TXG_WAIT);
error = dmu_tx_assign(tx, DMU_TX_WAIT);
if (error) {
dmu_tx_abort(tx);
zfs_exit(zfsvfs, FTAG);
Expand Down Expand Up @@ -1408,7 +1410,7 @@ zfs_mkdir(znode_t *dzp, const char *dirname, vattr_t *vap, znode_t **zpp,
dmu_tx_hold_sa_create(tx, acl_ids.z_aclp->z_acl_bytes +
ZFS_SA_BASE_ATTR_SIZE);

error = dmu_tx_assign(tx, TXG_WAIT);
error = dmu_tx_assign(tx, DMU_TX_WAIT);
if (error) {
zfs_acl_ids_free(&acl_ids);
dmu_tx_abort(tx);
Expand Down Expand Up @@ -1510,7 +1512,7 @@ zfs_rmdir_(vnode_t *dvp, vnode_t *vp, const char *name, cred_t *cr)
zfs_sa_upgrade_txholds(tx, zp);
zfs_sa_upgrade_txholds(tx, dzp);
dmu_tx_mark_netfree(tx);
error = dmu_tx_assign(tx, TXG_WAIT);
error = dmu_tx_assign(tx, DMU_TX_WAIT);
if (error) {
dmu_tx_abort(tx);
zfs_exit(zfsvfs, FTAG);
Expand Down Expand Up @@ -2542,7 +2544,7 @@ zfs_setattr(znode_t *zp, vattr_t *vap, int flags, cred_t *cr, zidmap_t *mnt_ns)

zfs_sa_upgrade_txholds(tx, zp);

err = dmu_tx_assign(tx, TXG_WAIT);
err = dmu_tx_assign(tx, DMU_TX_WAIT);
if (err)
goto out;

Expand Down Expand Up @@ -3243,7 +3245,7 @@ zfs_do_rename_impl(vnode_t *sdvp, vnode_t **svpp, struct componentname *scnp,

zfs_sa_upgrade_txholds(tx, szp);
dmu_tx_hold_zap(tx, zfsvfs->z_unlinkedobj, FALSE, NULL);
error = dmu_tx_assign(tx, TXG_WAIT);
error = dmu_tx_assign(tx, DMU_TX_WAIT);
if (error) {
dmu_tx_abort(tx);
goto out_seq;
Expand Down Expand Up @@ -3444,7 +3446,7 @@ zfs_symlink(znode_t *dzp, const char *name, vattr_t *vap,
}
if (fuid_dirtied)
zfs_fuid_txhold(zfsvfs, tx);
error = dmu_tx_assign(tx, TXG_WAIT);
error = dmu_tx_assign(tx, DMU_TX_WAIT);
if (error) {
zfs_acl_ids_free(&acl_ids);
dmu_tx_abort(tx);
Expand Down Expand Up @@ -3663,7 +3665,7 @@ zfs_link(znode_t *tdzp, znode_t *szp, const char *name, cred_t *cr,
dmu_tx_hold_zap(tx, tdzp->z_id, TRUE, name);
zfs_sa_upgrade_txholds(tx, szp);
zfs_sa_upgrade_txholds(tx, tdzp);
error = dmu_tx_assign(tx, TXG_WAIT);
error = dmu_tx_assign(tx, DMU_TX_WAIT);
if (error) {
dmu_tx_abort(tx);
zfs_exit(zfsvfs, FTAG);
Expand Down Expand Up @@ -3792,7 +3794,7 @@ zfs_inactive(vnode_t *vp, cred_t *cr, caller_context_t *ct)

dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
zfs_sa_upgrade_txholds(tx, zp);
error = dmu_tx_assign(tx, TXG_WAIT);
error = dmu_tx_assign(tx, DMU_TX_WAIT);
if (error) {
dmu_tx_abort(tx);
} else {
Expand Down Expand Up @@ -4163,7 +4165,7 @@ zfs_putpages(struct vnode *vp, vm_page_t *ma, size_t len, int flags,

dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
zfs_sa_upgrade_txholds(tx, zp);
err = dmu_tx_assign(tx, TXG_WAIT);
err = dmu_tx_assign(tx, DMU_TX_WAIT);
if (err != 0) {
dmu_tx_abort(tx);
goto out;
Expand Down
Loading
Loading