[native] Skip F_FULLFSYNC on macOS for network file systems#130779
[native] Skip F_FULLFSYNC on macOS for network file systems#130779adamsitnik with Copilot wants to merge 7 commits into
Conversation
Don't use F_FULLFSYNC on macOS for network file systems (NFS, SMB, CIFS, SMB2) as it may cause pending writes to be discarded. Use the same detection logic already used by the locking code (fstatfs + FileSystemNameSupportsLocking). Fixes #124722 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
On fstatfs failure, return 1 (treat as network FS) to safely skip F_FULLFSYNC and avoid potential data loss. Also improve comment clarity on return value logic. Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
adamsitnik
left a comment
There was a problem hiding this comment.
@copilot please address my feedback
|
Tagging subscribers to this area: @dotnet/area-system-io |
Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
…pal_io.c Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
adamsitnik
left a comment
There was a problem hiding this comment.
@copilot address my feedback
…ckTheFile in managed code Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
…ix WASM FSync signature Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
…avior Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
| get | ||
| { | ||
| NullableBool useFullFsync = _useFullFsync; | ||
| if (useFullFsync == NullableBool.Undefined && !IsClosed && OperatingSystem.IsApplePlatform()) |
There was a problem hiding this comment.
SystemNative_FSync uses TARGET_OSX only.
| if (useFullFsync == NullableBool.Undefined && !IsClosed && OperatingSystem.IsApplePlatform()) | |
| if (useFullFsync == NullableBool.Undefined && !IsClosed && OperatingSystem.IsMacOS()) |
| NullableBool useFullFsync = _useFullFsync; | ||
| if (useFullFsync == NullableBool.Undefined && !IsClosed && OperatingSystem.IsApplePlatform()) | ||
| { | ||
| _useFullFsync = useFullFsync = Interop.Sys.FileSystemSupportsLocking(this, Interop.Sys.LockOperations.LOCK_SH, accessWrite: true) |
There was a problem hiding this comment.
The PR reuses SystemNative_FileSystemSupportsLocking as a proxy for "is this a network FS," but that function's contract is about locking and its result depends on lockOperation/accessWrite, so it can't simply be renamed to IsNetworkFileSystem. Consider extracting the shared network-FS detection (the FileSystemNameSupportsLocking nfs/cifs/smb/smb2 check) into a dedicated helper.
|
I tried to reproduce #124722 on a macOS client (macOS 26.5, arm64) connecting to a Samba server running in WSL2, but was not able to trigger the truncation. What I tried:
In every case all files came out at their exact expected size — 0 truncated. |
@sschultze is there something more specific required to reproduce the problem (#124722)? |
On macOS,
F_FULLFSYNCon network file systems (NFS, SMB, CIFS, SMB2) can return success while silently discarding pending writes, causing data corruption. The existingfsyncfallback only triggers on failure, so the data loss goes undetected.Changes in
src/native/libs/System.Native/pal_io.c:IsNetworkFileSystem(int fileDescriptor)— macOS-only static helper that callsfstatfsand reuses the existingFileSystemNameSupportsLockinglogic to identify NFS/CIFS/SMB/SMB2 mounts. Conservatively returns1(is network FS) whenfstatfsfails, to skipF_FULLFSYNCand avoid data loss.SystemNative_FSyncto skipF_FULLFSYNCentirely whenIsNetworkFileSystemreturns true, going directly tofsync. Behavior on local file systems is unchanged.This mirrors the approach already used by
CanLockTheFile/SystemNative_FileSystemSupportsLocking, which skip advisory locking on the same set of network file systems for the same category of reasons.