Skip to content

feat(ide): add configurable write-through mode for IDE disk writes #605

Description

@LSantha

Summary

Following the FLUSH CACHE deferral in 7baa16d, add a configurable write-through mode that flushes the drive cache after every write operation. This provides data safety by default while allowing write-back for performance when desired.

Background

The previous commit moved FLUSH CACHE from per-write (write-through) to on-demand (write-back). This is faster but creates a window where data sits in the drive's volatile cache. On power loss, cached data is lost. Write-through eliminates this window.

Proposed Implementation

Add a writeThrough boolean field to IDEDiskDriver, defaulting to true. Read override from system property jnode.ide.writethrough at driver start.

// IDEDiskDriver fields
private boolean writeThrough = true;

// In startDevice(), after existing descriptor reads:
writeThrough = !"false".equals(
    VmIOContext.getGlobalProperties().getProperty("jnode.ide.writethrough"));

// In transfer(), after the write loop completes:
if (isWrite && writeThrough) {
    flush();
}

Files to Modify

  • fs/src/driver/org/jnode/driver/block/ide/disk/IDEDiskDriver.java — add field, property read, conditional flush

Testing / Validation

Test 1: Write-through by default

  1. Build: sh build.sh cd-x86-lite
  2. Boot in VirtualBox/QEMU
  3. Mount a FAT filesystem: mount /dev/ide0-auto /mnt
  4. Write a file: echo test > /mnt/test.txt
  5. Verify no crash, file persists after reboot
  6. Verify via serial log that FLUSH CACHE command is issued after write (add debug log in flush())

Test 2: Write-back via property override

  1. Add jnode.ide.writethrough=false to boot command line in GRUB config
  2. Boot, mount, write file
  3. Verify file write completes without FLUSH CACHE (faster)
  4. Verify FLUSH CACHE is only issued on unmount/sync

Test 3: Power loss simulation (write-through)

  1. Boot with write-through (default)
  2. Mount FAT, write large file
  3. Kill VM mid-write (SimulateBox close without save)
  4. Reboot, mount, verify filesystem consistency (no corruption)

Test 4: Power loss simulation (write-back)

  1. Boot with jnode.ide.writethrough=false
  2. Mount FAT, write large file
  3. Kill VM mid-write
  4. Reboot, mount — expect possible partial/corrupted write (acceptable, confirms write-back behavior)

Test 5: Stop device flush

  1. Unmount filesystem
  2. Verify FLUSH CACHE is issued during stopDevice() (already implemented)

Acceptance Criteria

  • Write-through is the default (no property set)
  • Setting jnode.ide.writethrough=false enables write-back
  • No performance regression when write-back is explicitly enabled
  • Existing FLUSH CACHE on unmount/stop still works
  • All three writable filesystems (FAT, jfat, ext2) benefit from the change

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/doneThe agent finished successfully; PR opened or comment posted.enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions