From f3e49b0cf5b89238acb7749b3a4d4c0590984801 Mon Sep 17 00:00:00 2001 From: Rob Norris Date: Tue, 19 Aug 2025 17:29:43 +1000 Subject: [PATCH] dnode_is_dirty: reimplement in terms of dn_dirtycnt Sponsored-by: Klara, Inc. Sponsored-by: Wasabi Technology, Inc. Reviewed-by: Brian Behlendorf Reviewed-by: Robert Evans Reviewed-by: Adam Moss Reviewed-by: Alexander Motin Signed-off-by: Rob Norris Closes #16297 Closes #17652 Closes #17658 --- module/zfs/dnode.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/module/zfs/dnode.c b/module/zfs/dnode.c index 62e1749a8..0ae88177c 100644 --- a/module/zfs/dnode.c +++ b/module/zfs/dnode.c @@ -1842,31 +1842,20 @@ dnode_try_claim(objset_t *os, uint64_t object, int slots) } /* - * 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. + * Test if the dnode is dirty, or carrying uncommitted records. * - * 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. + * dn_dirtycnt is the number of txgs this dnode is dirty on. It's incremented + * in dnode_setdirty() the first time the dnode is dirtied on a txg, and + * decremented in either dnode_rele_task() or userquota_updates_task() when the + * txg is synced out. */ boolean_t 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]) || - !list_is_empty(&dn->dn_dirty_records[i])) { - mutex_exit(&dn->dn_mtx); - return (B_TRUE); - } - } - + boolean_t dirty = (dn->dn_dirtycnt != 0); mutex_exit(&dn->dn_mtx); - - return (B_FALSE); + return (dirty); } void