More aggressively assert that db_mtx protects db.db_data

db.db_mtx must be held any time that db.db_data is accessed.  All of
these functions do have the lock held by a parent; add assertions to
ensure that it stays that way.

See https://github.com/openzfs/zfs/discussions/17118

* Refactor dbuf_read_bonus to make it obvious why db_rwlock isn't
required.

* Refactor dbuf_hold_copy to eliminate the db_rwlock
Copy data into the newly allocated buffer before assigning it to the db.
That way, there will be no need to take db->db_rwlock.

* Refactor dbuf_read_hole
In the case of an indirect hole, initialize the newly allocated buffer
before assigning it to the dmu_buf_impl_t.

Sponsored by:	ConnectWise
Signed-off-by: Alan Somers <asomers@gmail.com>
Closes #17209
This commit is contained in:
Alan Somers
2025-05-09 07:02:26 -06:00
committed by GitHub
parent 1a8f5ad3b0
commit c17bdc4914
2 changed files with 26 additions and 18 deletions
+3 -1
View File
@@ -2272,8 +2272,10 @@ dmu_objset_userquota_find_data(dmu_buf_impl_t *db, dmu_tx_t *tx)
dbuf_dirty_record_t *dr;
void *data;
if (db->db_dirtycnt == 0)
if (db->db_dirtycnt == 0) {
ASSERT(MUTEX_HELD(&db->db_mtx));
return (db->db.db_data); /* Nothing is changing */
}
dr = dbuf_find_dirty_eq(db, tx->tx_txg);