Deleted Added
full compact
zfs_vnops.c (260773) zfs_vnops.c (260776)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 93 unchanged lines hidden (view full) ---

102 * pushing cached pages (which acquires range locks) and syncing out
103 * cached atime changes. Third, zfs_zinactive() may require a new tx,
104 * which could deadlock the system if you were already holding one.
105 * If you must call VN_RELE() within a tx then use VN_RELE_ASYNC().
106 *
107 * (3) All range locks must be grabbed before calling dmu_tx_assign(),
108 * as they can span dmu_tx_assign() calls.
109 *
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 93 unchanged lines hidden (view full) ---

102 * pushing cached pages (which acquires range locks) and syncing out
103 * cached atime changes. Third, zfs_zinactive() may require a new tx,
104 * which could deadlock the system if you were already holding one.
105 * If you must call VN_RELE() within a tx then use VN_RELE_ASYNC().
106 *
107 * (3) All range locks must be grabbed before calling dmu_tx_assign(),
108 * as they can span dmu_tx_assign() calls.
109 *
110 * (4) Always pass TXG_NOWAIT as the second argument to dmu_tx_assign().
111 * This is critical because we don't want to block while holding locks.
112 * Note, in particular, that if a lock is sometimes acquired before
113 * the tx assigns, and sometimes after (e.g. z_lock), then failing to
114 * use a non-blocking assign can deadlock the system. The scenario:
110 * (4) If ZPL locks are held, pass TXG_NOWAIT as the second argument to
111 * dmu_tx_assign(). This is critical because we don't want to block
112 * while holding locks.
115 *
113 *
114 * If no ZPL locks are held (aside from ZFS_ENTER()), use TXG_WAIT. This
115 * reduces lock contention and CPU usage when we must wait (note that if
116 * throughput is constrained by the storage, nearly every transaction
117 * must wait).
118 *
119 * Note, in particular, that if a lock is sometimes acquired before
120 * the tx assigns, and sometimes after (e.g. z_lock), then failing
121 * to use a non-blocking assign can deadlock the system. The scenario:
122 *
116 * Thread A has grabbed a lock before calling dmu_tx_assign().
117 * Thread B is in an already-assigned tx, and blocks for this lock.
118 * Thread A calls dmu_tx_assign(TXG_WAIT) and blocks in txg_wait_open()
119 * forever, because the previous txg can't quiesce until B's tx commits.
120 *
121 * If dmu_tx_assign() returns ERESTART and zfsvfs->z_assign is TXG_NOWAIT,
122 * then drop all locks, call dmu_tx_wait(), and try again. On subsequent
123 * calls to dmu_tx_assign(), pass TXG_WAITED rather than TXG_NOWAIT,

--- 841 unchanged lines hidden (view full) ---

965 /*
966 * Write the file in reasonable size chunks. Each chunk is written
967 * in a separate transaction; this keeps the intent log records small
968 * and allows us to do more fine-grained space accounting.
969 */
970 while (n > 0) {
971 abuf = NULL;
972 woff = uio->uio_loffset;
123 * Thread A has grabbed a lock before calling dmu_tx_assign().
124 * Thread B is in an already-assigned tx, and blocks for this lock.
125 * Thread A calls dmu_tx_assign(TXG_WAIT) and blocks in txg_wait_open()
126 * forever, because the previous txg can't quiesce until B's tx commits.
127 *
128 * If dmu_tx_assign() returns ERESTART and zfsvfs->z_assign is TXG_NOWAIT,
129 * then drop all locks, call dmu_tx_wait(), and try again. On subsequent
130 * calls to dmu_tx_assign(), pass TXG_WAITED rather than TXG_NOWAIT,

--- 841 unchanged lines hidden (view full) ---

972 /*
973 * Write the file in reasonable size chunks. Each chunk is written
974 * in a separate transaction; this keeps the intent log records small
975 * and allows us to do more fine-grained space accounting.
976 */
977 while (n > 0) {
978 abuf = NULL;
979 woff = uio->uio_loffset;
973again:
974 if (zfs_owner_overquota(zfsvfs, zp, B_FALSE) ||
975 zfs_owner_overquota(zfsvfs, zp, B_TRUE)) {
976 if (abuf != NULL)
977 dmu_return_arcbuf(abuf);
978 error = SET_ERROR(EDQUOT);
979 break;
980 }
981

--- 35 unchanged lines hidden (view full) ---

1017
1018 /*
1019 * Start a transaction.
1020 */
1021 tx = dmu_tx_create(zfsvfs->z_os);
1022 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
1023 dmu_tx_hold_write(tx, zp->z_id, woff, MIN(n, max_blksz));
1024 zfs_sa_upgrade_txholds(tx, zp);
980 if (zfs_owner_overquota(zfsvfs, zp, B_FALSE) ||
981 zfs_owner_overquota(zfsvfs, zp, B_TRUE)) {
982 if (abuf != NULL)
983 dmu_return_arcbuf(abuf);
984 error = SET_ERROR(EDQUOT);
985 break;
986 }
987

--- 35 unchanged lines hidden (view full) ---

1023
1024 /*
1025 * Start a transaction.
1026 */
1027 tx = dmu_tx_create(zfsvfs->z_os);
1028 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
1029 dmu_tx_hold_write(tx, zp->z_id, woff, MIN(n, max_blksz));
1030 zfs_sa_upgrade_txholds(tx, zp);
1025 error = dmu_tx_assign(tx, TXG_NOWAIT);
1031 error = dmu_tx_assign(tx, TXG_WAIT);
1026 if (error) {
1032 if (error) {
1027 if (error == ERESTART) {
1028 dmu_tx_wait(tx);
1029 dmu_tx_abort(tx);
1030 goto again;
1031 }
1032 dmu_tx_abort(tx);
1033 if (abuf != NULL)
1034 dmu_return_arcbuf(abuf);
1035 break;
1036 }
1037
1038 /*
1039 * If zfs_range_lock() over-locked we grow the blocksize

--- 2367 unchanged lines hidden (view full) ---

3407 }
3408
3409 fuid_dirtied = zfsvfs->z_fuid_dirty;
3410 if (fuid_dirtied)
3411 zfs_fuid_txhold(zfsvfs, tx);
3412
3413 zfs_sa_upgrade_txholds(tx, zp);
3414
1033 dmu_tx_abort(tx);
1034 if (abuf != NULL)
1035 dmu_return_arcbuf(abuf);
1036 break;
1037 }
1038
1039 /*
1040 * If zfs_range_lock() over-locked we grow the blocksize

--- 2367 unchanged lines hidden (view full) ---

3408 }
3409
3410 fuid_dirtied = zfsvfs->z_fuid_dirty;
3411 if (fuid_dirtied)
3412 zfs_fuid_txhold(zfsvfs, tx);
3413
3414 zfs_sa_upgrade_txholds(tx, zp);
3415
3415 err = dmu_tx_assign(tx, TXG_NOWAIT);
3416 if (err) {
3417 if (err == ERESTART)
3418 dmu_tx_wait(tx);
3416 err = dmu_tx_assign(tx, TXG_WAIT);
3417 if (err)
3419 goto out;
3418 goto out;
3420 }
3421
3422 count = 0;
3423 /*
3424 * Set each attribute requested.
3425 * We group settings according to the locks they need to acquire.
3426 *
3427 * Note: you cannot set ctime directly, although it will be
3428 * updated as a side-effect of calling this function.

--- 1091 unchanged lines hidden (view full) ---

4520 len = zp->z_size - off;
4521 }
4522
4523 if (zfs_owner_overquota(zfsvfs, zp, B_FALSE) ||
4524 zfs_owner_overquota(zfsvfs, zp, B_TRUE)) {
4525 err = SET_ERROR(EDQUOT);
4526 goto out;
4527 }
3419
3420 count = 0;
3421 /*
3422 * Set each attribute requested.
3423 * We group settings according to the locks they need to acquire.
3424 *
3425 * Note: you cannot set ctime directly, although it will be
3426 * updated as a side-effect of calling this function.

--- 1091 unchanged lines hidden (view full) ---

4518 len = zp->z_size - off;
4519 }
4520
4521 if (zfs_owner_overquota(zfsvfs, zp, B_FALSE) ||
4522 zfs_owner_overquota(zfsvfs, zp, B_TRUE)) {
4523 err = SET_ERROR(EDQUOT);
4524 goto out;
4525 }
4528top:
4529 tx = dmu_tx_create(zfsvfs->z_os);
4530 dmu_tx_hold_write(tx, zp->z_id, off, len);
4531
4532 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
4533 zfs_sa_upgrade_txholds(tx, zp);
4526 tx = dmu_tx_create(zfsvfs->z_os);
4527 dmu_tx_hold_write(tx, zp->z_id, off, len);
4528
4529 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
4530 zfs_sa_upgrade_txholds(tx, zp);
4534 err = dmu_tx_assign(tx, TXG_NOWAIT);
4531 err = dmu_tx_assign(tx, TXG_WAIT);
4535 if (err != 0) {
4532 if (err != 0) {
4536 if (err == ERESTART) {
4537 dmu_tx_wait(tx);
4538 dmu_tx_abort(tx);
4539 goto top;
4540 }
4541 dmu_tx_abort(tx);
4542 goto out;
4543 }
4544
4545 if (zp->z_blksz <= PAGESIZE) {
4546 caddr_t va = zfs_map_page(pp, S_READ);
4547 ASSERT3U(len, <=, PAGESIZE);
4548 dmu_write(zfsvfs->z_os, zp->z_id, off, len, va, tx);

--- 2452 unchanged lines hidden ---
4533 dmu_tx_abort(tx);
4534 goto out;
4535 }
4536
4537 if (zp->z_blksz <= PAGESIZE) {
4538 caddr_t va = zfs_map_page(pp, S_READ);
4539 ASSERT3U(len, <=, PAGESIZE);
4540 dmu_write(zfsvfs->z_os, zp->z_id, off, len, va, tx);

--- 2452 unchanged lines hidden ---