Skip to content

Create unnamed O_TMPFILE fails in VirtFS (error 22(EINVAL): Invalid argument) #2051

@aleasims

Description

@aleasims

Description

When I'm trying to create unnamed temporary file O_TMPFILE in directory mounted with VirtFS, it fails with error 22: invalid argument.

Reproduce

Consider following C code :

main.c:

#define _GNU_SOURCE

#include <fcntl.h>
#include <stdio.h>

int main()
{
    int fd = open("/tmp", O_TMPFILE | O_RDWR);
    printf("fd = %d\n", fd);
    return 0;
}

Compile code and run with ops, mounting directory through VirtFS:

gcc -o main main.c && ops run --mounts /tmp:/tmp ./main

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:

running local instance
booting /home/alea/.ops/images/main ...
FS: filesystem_read_entire: t 0x7fc601c4, bufheap 0x00017054, buffer_handler 0x7fbdd000, status_handler 0x7fc609b4
FS: read_entire_complete: status [invalid format %v], addr 0x00000000
en1: assigned 10.0.2.15
fd = 3

Actual result

Returned fd is -1:

running local instance
booting /home/alea/.ops/images/main ...
FS: filesystem_read_entire: t 0x7fc601c4, bufheap 0x00017054, buffer_handler 0x7fbdd000, status_handler 0x7fc609b4
FS: read_entire_complete: status [invalid format %v], addr 0x00000000
en1: assigned 10.0.2.15
fd = -1

Setup

$ ops profile
Ops version: 0.1.41
Nanos version: 0.1.51
Qemu version: 6.2.0
OS: linux
Arch: amd64
Virtualized: false

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 calling filesystem_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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions