git: 154870526943 - releng/14.0 - zfs: cherry-pick commit from master

From: Gordon Tetlow <gordon_at_FreeBSD.org>
Date: Fri, 01 Dec 2023 00:38:38 UTC
The branch releng/14.0 has been updated by gordon:

URL: https://cgit.FreeBSD.org/src/commit/?id=1548705269435e980c5984ba87a554d4b329d176

commit 1548705269435e980c5984ba87a554d4b329d176
Author:     Rob N <robn@despairlabs.com>
AuthorDate: 2023-11-28 17:53:04 +0000
Commit:     Gordon Tetlow <gordon@FreeBSD.org>
CommitDate: 2023-11-30 21:34:08 +0000

    zfs: cherry-pick commit from master
    
     #15566 688514e47 dmu_buf_will_clone: fix race in transition back to NOFILL
    
    Obtained from:  OpenZFS
    Approved by:    so
    Security:       FreeBSD-EN-23:16.openzfs
    
    (cherry picked from commit 688514e4704bdee4551d25960febd322ac26f297)
    (cherry picked from commit 99385ec7c2962c2b5e54161aca6ec57546229cb2)
---
 sys/contrib/openzfs/module/zfs/dbuf.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/sys/contrib/openzfs/module/zfs/dbuf.c b/sys/contrib/openzfs/module/zfs/dbuf.c
index f2831a0e8abf..5a7fe42b602a 100644
--- a/sys/contrib/openzfs/module/zfs/dbuf.c
+++ b/sys/contrib/openzfs/module/zfs/dbuf.c
@@ -2700,15 +2700,23 @@ dmu_buf_will_clone(dmu_buf_t *db_fake, dmu_tx_t *tx)
 	 * writes and clones into this block.
 	 */
 	mutex_enter(&db->db_mtx);
+	DBUF_VERIFY(db);
 	VERIFY(!dbuf_undirty(db, tx));
 	ASSERT3P(dbuf_find_dirty_eq(db, tx->tx_txg), ==, NULL);
 	if (db->db_buf != NULL) {
 		arc_buf_destroy(db->db_buf, db);
 		db->db_buf = NULL;
+		dbuf_clear_data(db);
 	}
+
+	db->db_state = DB_NOFILL;
+	DTRACE_SET_STATE(db, "allocating NOFILL buffer for clone");
+
+	DBUF_VERIFY(db);
 	mutex_exit(&db->db_mtx);
 
-	dmu_buf_will_not_fill(db_fake, tx);
+	dbuf_noread(db);
+	(void) dbuf_dirty(db, tx);
 }
 
 void