Skip to content

lklfuse: fix lost appends on FreeBSD - #654

Open
chrislongros wants to merge 2 commits into
lkl:masterfrom
chrislongros:lklfuse-fix-lost-appends
Open

chrislongros wants to merge 2 commits into
lkl:masterfrom
chrislongros:lklfuse-fix-lost-appends

Conversation

@chrislongros

@chrislongros chrislongros commented Nov 30, 2026 •

Copy link
Copy Markdown

On FreeBSD, appending to a file on an lklfuse mount loses the data. This affects ext4, xfs, btrfs and vfat. Linux remains unaffected.

$ printf abc > /mnt/f
$ echo def >> /mnt/f
echo: write error on stdout
$ hexdump -c /mnt/f
0000000   a   b   c  \0  \0  \0  \0
  • Lost appends: FreeBSD's fusefs reads the old block before a partial write. lklfuse opens the file O_WRONLY inside LKL, so the read fails with EBADF and the write is lost. The patch modifies the open flag as O_RDWR for FreeBSD.

Tested on FreeBSD 16.0-CURRENT and 15.1 with both fixes applied to lkl 6.12: The files written through lklfuse on ext4, xfs and btrfs read back identical, and the images pass fsck on Linux.

A second commit introduces a simple FreeBSD CI test for writing and appending into a file.

P.S.: I came across this while trying to update the FreeBSD port of lklfuse, which is stuck on kernel 4.16.

FreeBSD's fusefs reads the old block before a partial write.  On a file
opened O_WRONLY the read fails with EBADF and the write is lost.

Open such files with O_RDWR instead.

Signed-off-by: Christos Longros <longros@FreeBSD.org>
@tavip

tavip commented Nov 30, 2026

Copy link
Copy Markdown
Member

Thanks for the fix, this looks good to me!

Could you also add a small write + append check to lklfuse_basic in tools/lkl/tests/lklfuse.sh so FreeBSD CI covers this going forward?

Minor nit: the PR description also mentions chmod/chown/touch/truncate returning EINVAL and "both fixes". Feel free to clean that up here if that fix is coming in a separate PR.

@tavip
tavip requested a review from ddiss November 30, 2026 19:13
@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Test Results

106 files  ±0  106 suites  ±0   11m 43s ⏱️ + 4m 21s
206 tests ±0  195 ✅ ±0  11 💤 ±0  0 ❌ ±0 
790 runs  ±0  734 ✅ ±0  56 💤 ±0  0 ❌ ±0 

Results for commit f1da0c7. ± Comparison against base commit 2ab931f.

♻️ This comment has been updated with latest results.

lklfuse_basic only creates and removes empty files.  Write to a file,
append to it and check the content, so that the FreeBSD CI job covers
appends.

Signed-off-by: Christos Longros <longros@FreeBSD.org>
@chrislongros

Copy link
Copy Markdown
Author

Thanks for the fix, this looks good to me!

Could you also add a small write + append check to lklfuse_basic in tools/lkl/tests/lklfuse.sh so FreeBSD CI covers this going forward?

Minor nit: the PR description also mentions chmod/chown/touch/truncate returning EINVAL and "both fixes". Feel free to clean that up here if that fix is coming in a separate PR.

I cleaned up the PR body and added a simple test that covers a write and append check.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants