Repository navigation
lxutil: allow fdatasync on directories on Windows - #4861
Merged
ggarzia-MSFT merged 4 commits intoNov 4, 2026
Merged
ggarzia-MSFT merged 4 commits into
ggarzia-MSFT merged 4 commits into
Conversation
Co-authored-by: Copilot <[email protected]>
ggarzia-MSFT
requested review from
a team and
Anatol Belski (weltling)
as code owners
November 2, 2026 23:49
3 of 6 tasks
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the directory-sync fix.
No open issues 🎉
What changed in this PR
This PR fixes directory fdatasync() failures on Windows-hosted virtiofs shares by making directory sync requests perform a full flush.
Changes:
- Clear
FUSE_FSYNC_FDATASYNCbefore forwarding directory sync requests tofsync. - Add a regression test covering directory syncs with and without the data-only flag.
| File | Description |
|---|---|
vm/devices/virtio/virtiofs/src/lib.rs |
Force full directory flushes and add regression coverage for both sync modes. |
Review effort: Balanced
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
|
This PR modifies files containing For more on why we check whole files, instead of just diffs, check out the Rustonomicon |
…skip the attribute query Co-authored-by: Copilot <[email protected]>
Daman Mulye (damanm24)
approved these changes
Nov 3, 2026
Sriram Nambakam (snambakam)
pushed a commit
to snambakam/openvmm
that referenced
this pull request
Nov 6, 2026
## Summary Closes: microsoft/WSL#42129 Fix `fdatasync()` on a directory failing with `EINVAL` when the share is backed by a Windows host (virtiofs and plan9). ## Root cause When a Linux guest calls `fdatasync()` on a directory, the request reaches `LxFile::fsync(data_only = true)`. On Windows, that translates to `NtFlushBuffersFileEx` with `FLUSH_FLAGS_FILE_DATA_ONLY`. Windows rejects data-only flushes on directory handles with `STATUS_INVALID_PARAMETER`, which is surfaced to the guest as `EINVAL`. On a native Linux filesystem, the same call succeeds. ## Fix Add `LxFile::fsync_dir` for callers that already know the handle is a directory. - On Windows, `fsync_dir` always does a full flush, which Windows accepts on directories. - On Linux, `fsync_dir` is the same as `fsync`, so behavior on Linux hosts is unchanged. - virtiofs calls `fsync_dir` from its `FUSE_FSYNCDIR` handler, which the guest only sends for directories. - plan9 calls `fsync_dir` when the fid's cached qid marks it as a directory. - `LxFile::fsync` is unchanged, and no extra system call is made to determine the file type. ## Testing - Extended the cross-platform `lxutil` `fsync` test to call `fsync_dir` on a directory, both full and data-only. - Added directory sync tests for virtiofs (`fsync_dir_with_fdatasync`) and plan9 (`fsync_directory`). - Without the fix, all three tests fail on Windows with `EINVAL`; with it, they pass. - `cargo test` on Windows: `lxutil` (68 passed), `virtiofs` (59 passed), `plan9` (11 passed). - Clippy, doc and `cargo xtask fmt` are clean. --------- Co-authored-by: Copilot <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Closes: microsoft/WSL#42129
Fix
fdatasync()on a directory failing withEINVALwhen the share is backed by a Windows host (virtiofs and plan9).Root cause
When a Linux guest calls
fdatasync()on a directory, the request reachesLxFile::fsync(data_only = true). On Windows, that translates toNtFlushBuffersFileExwithFLUSH_FLAGS_FILE_DATA_ONLY. Windows rejects data-only flushes on directory handles withSTATUS_INVALID_PARAMETER, which is surfaced to the guest asEINVAL. On a native Linux filesystem, the same call succeeds.Fix
Add
LxFile::fsync_dirfor callers that already know the handle is a directory.fsync_diralways does a full flush, which Windows accepts on directories.fsync_diris the same asfsync, so behavior on Linux hosts is unchanged.fsync_dirfrom itsFUSE_FSYNCDIRhandler, which the guest only sends for directories.fsync_dirwhen the fid's cached qid marks it as a directory.LxFile::fsyncis unchanged, and no extra system call is made to determine the file type.Testing
lxutilfsynctest to callfsync_diron a directory, both full and data-only.fsync_dir_with_fdatasync) and plan9 (fsync_directory).EINVAL; with it, they pass.cargo teston Windows:lxutil(68 passed),virtiofs(59 passed),plan9(11 passed).cargo xtask fmtare clean.