Open aleasims opened 1 month ago
Creation of unnamed temporary files in a 9P filesystem is indeed not supported. As far as I'm aware, this is not supported on Linux either, and when looking at the 9P protocol I couldn't see a way for a 9P client to send commands to the server to create temporary files, so I doubt O_TMPFILE will ever be supported on VirtFS-mounted directories.
@francescolavra thanks for the answer!
As far as I see from Linux man, O_TMPFILE
in Linux is unnamed by default and can be linked with linkat()
if needed.
In that case, probably it is possible to change the error code? From that man page (ERRORS section) I can see these three codes which are treated as "O_TMPFILE files are not supported on the filesystem":
EISDIR
ENOENT
EOPNOTSUPP
Some libraries which work with temp files check for these error codes to decide if they need to fallback to normal named files. So it would be very helpful, if nanos open()
could return one of these error codes.
To be clear, when I said that creation of unnamed temporary files is not supported on Linux, I meant that it's not supported in a 9P filesystem, i.e. a filesystem mounted with the -t 9p
option.
As for the error code, EINVAL is indeed not appropriate, I will change it to EOPNOTSUPP.
As part of a larger refactoring, #2054 changes the error code returned by open(O_TMPFILE) from EINVAL to EOPNOTSUPP.
Description
When I'm trying to create unnamed temporary file
O_TMPFILE
in directory mounted with VirtFS, it fails witherror 22: invalid argument
.Reproduce
Consider following C code :
main.c
:Compile code and run with
ops
, mounting directory through VirtFS:Expected result
Program works successfully, just like on native Linux platform: unnamed tmp file is created and removed at the end of execution. Printed
fd
is positive:Actual result
Returned
fd
is-1
:Setup
I tested the same with --nightly and with local build of master branch and the same error occurs.
What I found
It looks like to me that
open()
syscall results in callingfilesystem_creat_unnamed
function, and 9pfs implementation fails immediately if asked to create unnamed file.But I'm not sure, if 9pfs supports unnamed files at all. In that case this behavior is different from Unix-like, where creating such unnamed tmp files is a normal thing.