git: 685617cf0ebd - releng/15.1 - Fix direct reads of blocks pending free
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 17 Nov 2026 17:07:59 UTC
The branch releng/15.1 has been updated by markj:
URL: https://cgit.FreeBSD.org/src/commit/?id=685617cf0ebddcc68e506f5b28e91dbad336df8e
commit 685617cf0ebddcc68e506f5b28e91dbad336df8e
Author: Wale Zhang <wale.zhang.ftd@gmail.com>
AuthorDate: 2026-11-05 04:31:09 +0000
Commit: Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-11-15 17:57:38 +0000
Fix direct reads of blocks pending free
Direct reads only check the on-disk block pointer for holes, so they
can read stale data after a block has been freed but before the free
has synced. Share buffered read hole detection with direct reads to
honor pending frees as well.
Keep cached data ahead of hole detection and preserve the transaction
ordering of block clone and direct write overrides. Retain the block
pointer recheck after dnode_block_freed() for concurrent syncing.
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Wale Zhang <wale.zhang.ftd@gmail.com>
Closes #19633
Approved by: so
Security: FreeBSD-EN-26:32.zfs
Approved by: kevans (mentor)
(cherry picked from commit 924b8c89c04e324649855b05986f686b58ca4cb9)
(cherry picked from commit afc7fc2abe807780e6f9cba96ab73105ebd2a07f)
---
sys/contrib/openzfs/include/sys/dbuf.h | 1 +
sys/contrib/openzfs/module/zfs/dbuf.c | 28 ++++++++++++++++++++--------
sys/contrib/openzfs/module/zfs/dmu_direct.c | 2 +-
3 files changed, 22 insertions(+), 9 deletions(-)
diff --git a/sys/contrib/openzfs/include/sys/dbuf.h b/sys/contrib/openzfs/include/sys/dbuf.h
index 0b379ee79caa..a583cbb4d95c 100644
--- a/sys/contrib/openzfs/include/sys/dbuf.h
+++ b/sys/contrib/openzfs/include/sys/dbuf.h
@@ -389,6 +389,7 @@ dbuf_dirty_record_t *dbuf_dirty(dmu_buf_impl_t *db, dmu_tx_t *tx);
dbuf_dirty_record_t *dbuf_dirty_lightweight(dnode_t *dn, uint64_t blkid,
dmu_tx_t *tx);
boolean_t dbuf_undirty(dmu_buf_impl_t *db, dmu_tx_t *tx);
+boolean_t dbuf_is_hole(dmu_buf_impl_t *db, dnode_t *dn, blkptr_t *bp);
int dmu_buf_get_bp_from_dbuf(dmu_buf_impl_t *db, blkptr_t **bp);
int dmu_buf_untransform_direct(dmu_buf_impl_t *db, spa_t *spa);
void dmu_buf_write_embedded(dmu_buf_t *dbuf, void *data,
diff --git a/sys/contrib/openzfs/module/zfs/dbuf.c b/sys/contrib/openzfs/module/zfs/dbuf.c
index aeb697eb1645..040924450c3d 100644
--- a/sys/contrib/openzfs/module/zfs/dbuf.c
+++ b/sys/contrib/openzfs/module/zfs/dbuf.c
@@ -1465,17 +1465,15 @@ dbuf_handle_indirect_hole(void *data, dnode_t *dn, blkptr_t *dbbp)
}
/*
- * Handle reads on dbufs that are holes, if necessary. This function
- * requires that the dbuf's mutex is held. Returns success (0) if action
- * was taken, ENOENT if no action was taken.
+ * Check for a hole, including frees which have not yet been synced.
+ * The caller must hold db_mtx to stabilize the dirty records.
*/
-static int
-dbuf_read_hole(dmu_buf_impl_t *db, dnode_t *dn, blkptr_t *bp)
+boolean_t
+dbuf_is_hole(dmu_buf_impl_t *db, dnode_t *dn, blkptr_t *bp)
{
ASSERT(MUTEX_HELD(&db->db_mtx));
- arc_buf_t *db_data;
- int is_hole = bp == NULL || BP_IS_HOLE(bp);
+ boolean_t is_hole = bp == NULL || BP_IS_HOLE(bp);
/*
* For level 0 blocks only, if the above check didn't find a hole,
* consult dnode_block_freed() to check for pending frees.
@@ -1505,7 +1503,21 @@ dbuf_read_hole(dmu_buf_impl_t *db, dnode_t *dn, blkptr_t *bp)
}
}
- if (is_hole) {
+ return (is_hole);
+}
+
+/*
+ * Handle reads on dbufs that are holes, if necessary. This function
+ * requires that the dbuf's mutex is held. Returns success (0) if action
+ * was taken, ENOENT if no action was taken.
+ */
+static int
+dbuf_read_hole(dmu_buf_impl_t *db, dnode_t *dn, blkptr_t *bp)
+{
+ ASSERT(MUTEX_HELD(&db->db_mtx));
+ arc_buf_t *db_data;
+
+ if (dbuf_is_hole(db, dn, bp)) {
db_data = dbuf_alloc_arcbuf(db);
memset(db_data->b_data, 0, db->db.db_size);
diff --git a/sys/contrib/openzfs/module/zfs/dmu_direct.c b/sys/contrib/openzfs/module/zfs/dmu_direct.c
index 5b00698da728..496f4d2afdf2 100644
--- a/sys/contrib/openzfs/module/zfs/dmu_direct.c
+++ b/sys/contrib/openzfs/module/zfs/dmu_direct.c
@@ -298,7 +298,7 @@ dmu_read_abd(dnode_t *dn, uint64_t offset, uint64_t size,
* cached. This will not be considered a direct read for IO
* accounting in the same way that an ARC hit is not counted.
*/
- if (bp == NULL || BP_IS_HOLE(bp) || db->db_state == DB_CACHED) {
+ if (db->db_state == DB_CACHED || dbuf_is_hole(db, dn, bp)) {
size_t aoff = offset < db->db.db_offset ?
db->db.db_offset - offset : 0;
size_t boff = offset > db->db.db_offset ?