runtime: Write CIFS file 'permission denied' (Linux)
Dear guys,
I got an error when I use my application write to a CIFS file folder mounted on host machine.
I tried use same user with shell script echo 123 > /mnt/debug/a.txt success.
After application error, there is a 0kb file in the folder, means the file is created but application cannot flush binary content into the file.
Mount options mount -t cifs --verbose -o domain=***,username=***,password='***',dir_mode=0777,file_mode=0777,noperm,rw \ //somehost/folder /mnt
error log
Unhandled exception. System.UnauthorizedAccessException: Access to the path '/mnt/debug/5d256383-48b6-49f3-99b7-d964c4a964f6' is denied.
---> System.IO.IOException: Permission denied
--- End of inner exception stack trace ---
at System.IO.FileStream.WriteNative(ReadOnlySpan`1 source)
at System.IO.FileStream.FlushWriteBuffer()
at System.IO.FileStream.FlushInternalBuffer()
at System.IO.FileStream.Flush(Boolean flushToDisk)
at System.IO.FileStream.Flush()
at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
at System.IO.StreamWriter.Dispose(Boolean disposing)
at System.IO.TextWriter.Dispose()
at System.IO.File.WriteAllText(String path, String contents)
at NasDebugger.Program.Main(String[] args)
Aborted (core dumped)
sample code
static int Main(string[] args)
{
if (args.Length == 0 || string.IsNullOrEmpty(args[0]))
{
Console.WriteLine("please set dir");
return -1;
}
var dir = args[0];
if (!Directory.Exists(dir))
{
Console.WriteLine("please set right dir");
return -1;
}
var id = Guid.NewGuid().ToString();
File.WriteAllText(Path.Combine(dir, id), "123123");
Console.WriteLine(id);
return 0;
}
Right now , I only can reproduce it in my datacenterðŸ˜.
OS Linux version 4.12.14-95.54-default (geeko@buildhost) (gcc version 4.8.5 (SUSE Linux) ) #1 SMP Thu Jun 4 12:49:28 UTC 2020 (892ef1f)
dotnetcore version: 3.1.8
Does anyone have idea about it?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 2
- Comments: 23 (11 by maintainers)
Links to this issue
Commits related to this issue
- Fixed: FolderWritable check for CIFS shares mounted in Unix See https://github.com/dotnet/runtime/issues/42790 Implemented workaround in https://github.com/dotnet/runtime/issues/42790#issuecomment-7... — committed to Radarr/Radarr by ta264 4 years ago
- Fixed: FolderWritable check for CIFS shares mounted in Unix See https://github.com/dotnet/runtime/issues/42790 Implemented workaround in https://github.com/dotnet/runtime/issues/42790#issuecomment-7... — committed to Radarr/Radarr by ta264 4 years ago
- Fixed: FolderWritable check for CIFS shares mounted in Unix See https://github.com/dotnet/runtime/issues/42790 Implemented workaround in https://github.com/dotnet/runtime/issues/42790#issuecomment-7... — committed to Lidarr/Lidarr by ta264 4 years ago
- Fixed: FolderWritable check for CIFS shares mounted in Unix See https://github.com/dotnet/runtime/issues/42790 Implemented workaround in https://github.com/dotnet/runtime/issues/42790#issuecomment-7... — committed to Lidarr/Lidarr by ta264 4 years ago
- Fixed: FolderWritable check for CIFS shares mounted in Unix See https://github.com/dotnet/runtime/issues/42790 Implemented workaround in https://github.com/dotnet/runtime/issues/42790#issuecomment-7... — committed to Lidarr/Lidarr by ta264 4 years ago
- Fixed: FolderWritable check for CIFS shares mounted in Unix See https://github.com/dotnet/runtime/issues/42790 Implemented workaround in https://github.com/dotnet/runtime/issues/42790#issuecomment-7... — committed to Lidarr/Lidarr by ta264 4 years ago
- Fixed: FolderWritable check for CIFS shares mounted in Unix See https://github.com/dotnet/runtime/issues/42790 Implemented workaround in https://github.com/dotnet/runtime/issues/42790#issuecomment-7... — committed to Readarr/Readarr by ta264 4 years ago
I ran into this and wasn’t in a position to change all our code that writes files to CIFS shares. I investigated different kernel versions as it appeared to happen after we upgraded the OS on our hosts. It turned out to be introduced in kernel v5.5.1, in fact this commit: https://github.com/torvalds/linux/commit/d0677992d2af3d65f1c1c21de3323d09d4891537. I managed to work around it by mounting our cifs shares using the
nobrloption. From https://linux.die.net/man/8/mount.cifs:After remounting shares including this option the problem went away.
I also just rant into this after upgrading some linux hosts with a Azure File Share using the 3.1 runtime. Saved me a ton of additional time trying to track down the issue.
Update
thanks @wfurt, I will try as your suggestion, this result tested by single file application.
I tried use 4 ways to write file.
File.WriteAllTextnew StreamWriter(path)new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read)Only 3 works fine, so
FileShareshould impact the result.Sample code
sample log