$ uname -a A_BLOG_ABOUT_UNIX_TOOLS_AND_THE_BEAUTY_OF_SIMPLE_SYSTEMS
SYS.YEAR  2026
← Back to articles
2026-09-26ARTICLE

Zfs Diag

Diagnostic Kernel Plan: Dnode Corruption Writer

Goal and Evidence Boundary

Catch the dnode-slot corruption earlier and retain enough evidence to identify or narrow the responsible write. This is diagnostic instrumentation, not a root-cause fix. No BRT/ARC ownership defect has been established.

The original victim was object 815488, slot zero of dnode block 25484, in TXG 1175694. Its 512-byte physical slot at 0xfffffe00ff36c000 began with two 128-byte file-data block pointers instead of a dnode header. These addresses and object numbers identify the old dump; they must not be hard-coded as the only targets of a future run.

A writer stack belongs to code performing the store. A detection stack belongs to code discovering changed bytes. Checksums at boundaries provide the latter and bracket an interval; they cannot by themselves identify an arbitrary writer. Concurrent writes can invalidate apparent before/after attribution.

1. Establish the Build Baseline

  • Record the source revision, local diff, kernel configuration, and compiler. Start from the source matching the original kernel, then document any changes.
  • Inspect existing DNODE_VERIFY and DBUF_VERIFY checks before adding checks. Review investigation/early-dnode-check.patch as a starting proposal only; applicability does not establish locking correctness or runtime validity.
  • Preserve the current bootable kernel, modules, and matching debug symbols. Build a separately named diagnostic kernel/module set with a unique identifier.

2. Instrument Concrete Writes First

Review callers, locking, and object lifetimes before placing each hook:

Candidate Record or check
dbuf_write_ready() Validate the derived db_blkptr destination against its parent/dnode layout immediately before the BP store. Record destination and BP bytes.
dmu_brt_clone() Validate clone dirty-record identity and capture override-BP destination, object, block ID, and TXG.
dnode_allocate(), dnode_sync(), dnode_sync_free() Record legitimate slot allocation, updates, zeroing, and lifecycle transitions.
dbuf_sync_*() Check physical dnode validity before child syncing and around relevant metadata updates.
ARC/ABD ownership and copy paths Add narrowly filtered hooks only after the first checks identify a useful interval or suspicious ownership transition.

A direct pre-store destination violation is stronger evidence than discovering an invalid header later. Record both the proposed destination and independently derived expected destination. Do not assume that every BP store belongs in a dnode: indirect-block destinations are legitimate too.

3. Track Identity and Legitimate Changes

Start with structural checks and bounded event records. Add slot fingerprints only where a stable baseline and synchronization can be justified.

  • Identify targets by pool/objset, object, dnode block, slot offset, and an allocation generation; include live pointers for correlation.
  • Track allocation, release, reuse, and buffer replacement so recycled addresses do not inherit stale baselines. Monitoring must not accidentally pin buffers indefinitely or conceal the lifetime bug under investigation.
  • Account for valid free slots, multi-slot dnodes, bonus/spill changes, TXG transitions, and raw receive. Skip unsupported states explicitly.
  • A changed hash is not itself corruption: normal dnode writes change bytes. Prefer invalid structure or an independently demonstrated destination mismatch as the panic condition. Do not compare cached and physical fields for equality where deferred sync legitimately makes them differ.
  • Use the locks required by the actual writer paths. A dbuf mutex alone must not be assumed to serialize every write to its data.

4. Preserve Diagnostic Evidence

Use a small preallocated, bounded event buffer. Avoid allocating memory or introducing new lock-order dependencies in tracing/panic paths. Make concurrent record publication explicit so incomplete records can be recognized.

Record event sequence, CPU/thread, object identity, TXG, dbuf/dnode/ARC pointers, write destination and length, relevant old/new bytes or fingerprints, and a bounded stack capture where supported. Include dropped-event counts.

On a confirmed diagnostic invariant violation, print a compact report and relevant recent records into the kernel message buffer before panicking. Label records as candidate writer, detected bad destination, or corruption observer according to the evidence. Missing events do not exclude an uninstrumented or concurrent ZFS writer.

5. Validate Only in test-zfs2

Never run reproduction or intentional crash tests on the host.

ssh -i ~/.ssh/test-zfs2 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@192.168.3.225
  • Compile and verify the diagnostic kernel/module identity after booting the VM.
  • Exercise ordinary writes, allocation/free/reuse, cloning, truncation, and multi-slot dnodes; check for false alarms and event-buffer overhead.
  • Add a disabled-by-default test hook for a controlled invariant violation. In the disposable VM, verify that it records the intended evidence and that automatic dumping/reboot produces a readable minidump.
  • Check that info, kernel message output, event records, and stacks survive, and that kgdb resolves them using the saved exact debug symbols.
  • Keep any synthetic corruption test separate from the real reproducer: reproducing the assertion by injection does not establish the original cause.
  • Avoid broad DTrace/fasttrap instrumentation while validating this patch; the VM already encountered a separate fasttrap Witness panic.

6. Deployment and Interpretation

After VM validation, deploy the reviewed diagnostic build during a planned reboot, preserving rollback access. Minidumps are acceptable once diagnostic record retention is demonstrated; full dumps provide additional surrounding memory when space permits. Retain exact kernel/modules/symbols for every build.

A diagnostic panic has the same remote signs: SSH disconnect, automatic reboot, low uptime, and a new dump. Collect each dump with workload notes and boot/build identity. Compare event sequences across incidents. An observer stack narrows the search; only direct store evidence or a sufficiently synchronized trace supports naming the writer.

Checklist

  • Record and review source/build baseline and existing assertions.
  • Implement minimal destination checks and bounded event recording.
  • Review locking, legitimate transitions, and target lifetime tracking.
  • Build and boot the diagnostic set in test-zfs2.
  • Validate normal workloads and assess overhead/false positives.
  • Verify diagnostic records survive an intentional VM panic/minidump.
  • Review the patch and prepare deployment/rollback instructions.
  • Deploy validated diagnostics and retain subsequent weekly-crash evidence.
  • Identify a proven writer before proposing a root-cause fix.