# CuttleFS helper execution

Run with Python 3.8 or later from this directory:

```sh
python3 -B replay.py --check
python3 -B -m unittest -v test_replay.py
```

Download replay.py, fsyncs.py, LICENSE, results.json and test_replay.py together.
No third-party dependency or FUSE mount is needed.

## What ran

Unmodified `cuttlefs/fsyncs.py` from WiscADSL/cuttlefs commit
`8ddc684d4fc9167778bfe1cddfbbae8a3eabe15e`. The upstream MIT license is retained.
The harness verifies its SHA-256 before loading it. Hesela's harness and tests
are also offered under the MIT license.

A fixture starts with one 4096-byte old block and a dirty cached replacement.
A stub block backend rejects the first write and would accept subsequent writes.
Three calls to the upstream `on_fsync` method record return codes, attempted
writes, cached content and referenced backing content. Both fixture sizes resolve
backing content through the serialized metadata file, not the in-memory mapping.
Regression controls deliberately separate those mappings and reject missing or
malformed metadata instead of silently substituting RAM state. The original
unmutated traces remain unchanged. Metadata uses a temporary ordinary file;
its writes do not establish physical durability.

Four modes are exercised, with a no-fault control for each. The ordered/XFS
helpers keep new clean cached bytes while backing bytes remain old. The data-mode
helper delays its error report. The Btrfs helper restores its prior mapping and
removes the cached page. No retry submits the failed bytes in these fixtures.

The errno-only test deliberately lets a write succeed before returning EIO.
It produces the same first return code and cached bytes as a failed write, but
different backing bytes. A dirty-retention mutation instead makes a retry submit
the data. These controls distinguish observables; they do not model every failure.

## Two-page partial-write extension

The additional fixture has two dirty 4096-byte pages, visited at byte offsets
0 then 4096. It rejects attempt 1 or attempt 2, or rejects nothing in controls.
Only that attempt fails; subsequent attempts would succeed. For each of four
helpers, both selected fault positions and the no-fault control are executed:
12 additional fixtures, not a random sample.

Each snapshot resolves backing bytes through the metadata file read after the
call, separately from the in-memory mapping. The export also records attempted
writes, their outcomes and remaining allocated blocks. This avoids mistaking
a written but unreachable copy-on-write block for the file's referenced content.

Ordered, XFS and data-mode helpers attempt both pages. The failed position keeps
old bytes while the other contains new bytes. Retrying makes no further writes.
The Btrfs helper restores both old references and discards the new allocations.
When its second write fails, the first new block was written but is no longer
referenced; when its first fails, the second is not attempted. This early stop
belongs to the sequential helper, not a claim about actual Btrfs I/O scheduling.

The original one-page arrays retain their fields and results. Schema version 1
has two additive arrays: two_page_failed_write_cases and two_page_no_fault_controls.
No result here establishes transaction atomicity on a mounted filesystem.

## Fault-model applicability

A transient rejected write is not the same assumption as permanently unreadable
media. In a 9 February 2024 OpenLDAP post, Howard Chu disputed whether the paper's
LMDB sector-failure scenario represents real storage faults. This is an attributed
methodological objection, not a reproduction or a universal exoneration of LMDB:
https://lists.openldap.org/hyperkitty/list/openldap-devel@openldap.org/thread/YUUKXVYXA347IWW3UKRS6NJHBU4FEE6M/

These whole-page helper fixtures do not test that disputed sector-level scenario
or an LMDB transaction. They cannot settle its physical applicability. The article
separates those scopes and lists the observations a deployment-specific test needs.

## Descriptor notification lifetime

The additive observer_failed_write_cases and observer_no_fault_controls arrays
execute four sequential schedules in each of four helpers: 16 fault cases and
16 matched no-fault controls. Independent descriptors A=7 and B=8 are open
before the single rejected overwrite. A calls twice so its error is consumed
even in the delayed data-mode profile; descriptor C=9 may then open.

- B checks: B still receives EIO after A has consumed its own notification.
- C opens while B remains pending: C receives zero, B later receives EIO.
- B closes without checking, then C opens: C receives EIO, then zero.
- B checks before closing, then C opens: C receives zero.

Every fault schedule attempts only one block write and retains old backing bytes.
Every no-fault schedule has one successful write and only zero sync returns.
Null pending_notifications means no inode entry; [] means an existing empty set.
The distinction is causal: on_close_fd preserves the empty set, and
_should_notify_fd treats that set as notification owed to any caller.
A controlled mutation removing the empty entry changes C's return to zero while
leaving the write events unchanged. No additional storage failure occurred.

This helper is not an errseq emulator. Linux v6.12 errseq_sample initializes a
new observer past an error already marked seen; an unseen error instead yields
a zero initial cursor. In our close-pending schedule A has already observed the
error. The helper's later EIO for C therefore must not be generalized to that
Linux sampling contract. This is a source-level comparison, not native kernel
execution. No dup, fork, descriptor reuse, concurrency or counter wrap is modeled.

Sources:
- Pinned CuttleFS fsyncs.py (link below), on_close_fd and _should_notify_fd.
- https://www.kernel.org/doc/html/v6.12/core-api/errseq.html
- https://github.com/torvalds/linux/blob/adc218676eef25575469234709c2d87185ca223a/lib/errseq.c

## Boundaries

This executes helper code with a synthetic backend, not the complete artifact,
a mounted filesystem, a Linux kernel or a storage device. The original fixtures use one descriptor;
the notification extension uses sequential independent descriptors. There is no
competing access, at most two pages, and no metadata-write faults or power interruption.
The result is not a reproduction of the paper's application experiments or a
statement about current ext4, XFS or Btrfs releases. Zero means no error from this
helper call, not proof of physical persistence.

Source: https://github.com/WiscADSL/cuttlefs/blob/8ddc684d4fc9167778bfe1cddfbbae8a3eabe15e/cuttlefs/fsyncs.py
Paper: https://www.usenix.org/conference/atc20/presentation/rebello
