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

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

URL: https://cgit.FreeBSD.org/src/commit/?id=8c25d614b8c95cb4dfe46d6903b8bb764a30c788

commit 8c25d614b8c95cb4dfe46d6903b8bb764a30c788
Author:     Rob N <robn@despairlabs.com>
AuthorDate: 2023-11-28 17:07:57 +0000
Commit:     Gordon Tetlow <gordon@FreeBSD.org>
CommitDate: 2023-11-30 21:30:04 +0000

    zfs: cherry-pick commit from master
    
     #15571 30d581121 dnode_is_dirty: check dnode and its data for dirtiness
    
    Obtained from:  OpenZFS
    Approved by:    so
    Security:       FreeBSD-EN-23:16.openzfs
    
    (cherry picked from commit 30d581121bb122c90959658e7b28b1672d342897)
    (cherry picked from commit d92e0d62c9e38058fd46c97beb08764538878592)
---
 sys/contrib/openzfs/module/zfs/dnode.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/sys/contrib/openzfs/module/zfs/dnode.c b/sys/contrib/openzfs/module/zfs/dnode.c
index 7cf03264dce2..ad9988366ada 100644
--- a/sys/contrib/openzfs/module/zfs/dnode.c
+++ b/sys/contrib/openzfs/module/zfs/dnode.c
@@ -1764,7 +1764,14 @@ dnode_try_claim(objset_t *os, uint64_t object, int slots)
 }
 
 /*
- * Checks if the dnode contains any uncommitted dirty records.
+ * Checks if the dnode itself is dirty, or is carrying any uncommitted records.
+ * It is important to check both conditions, as some operations (eg appending
+ * to a file) can dirty both as a single logical unit, but they are not synced
+ * out atomically, so checking one and not the other can result in an object
+ * appearing to be clean mid-way through a commit.
+ *
+ * Do not change this lightly! If you get it wrong, dmu_offset_next() can
+ * detect a hole where there is really data, leading to silent corruption.
  */
 boolean_t
 dnode_is_dirty(dnode_t *dn)
@@ -1772,7 +1779,8 @@ dnode_is_dirty(dnode_t *dn)
 	mutex_enter(&dn->dn_mtx);
 
 	for (int i = 0; i < TXG_SIZE; i++) {
-		if (multilist_link_active(&dn->dn_dirty_link[i])) {
+		if (multilist_link_active(&dn->dn_dirty_link[i]) ||
+		    !list_is_empty(&dn->dn_dirty_records[i])) {
 			mutex_exit(&dn->dn_mtx);
 			return (B_TRUE);
 		}