Stream: git-wasmtime

Topic: wasmtime / issue #7264 File allocation error ?


view this post on Zulip Wasmtime GitHub notifications bot (Oct 17 2023 at 03:57):

orangeC23 added the bug label to Issue #7264.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 17 2023 at 03:57):

orangeC23 opened issue #7264:

Steps to Reproduce

(1) The cfile is :

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>


int main() {
    const char* file_name = "Data/hello.txt";
    int open_style= O_CREAT | O_RDWR;
    int fd = get_fd(file_name, open_style);
    fd_allocateLuGpoE0tKi(fd, file_name);
    snapshot(fd);
    return 0;
}

int fd_allocateLuGpoE0tKi (int fd, const char* file_name){
    off_t start_value = 19;
    off_t len_value = 39;
    return fd_allocate(fd, file_name, start_value, len_value);
}

int get_fd(const char* file_name, int open_style){
    // Open a file for reading
    int fd = open(file_name, open_style);
    if (fd == -1) {
        perror("Failed to open the file");
        return 1;
    }

    return fd;
}

int fd_allocate (int fd, const char* filename, off_t start_value, off_t len_value){
    if (posix_fallocate(fd, start_value, len_value) != 0) {
        perror("Error allocating file space");
        close(fd);
        return 1;
    }

    printf("File '%s' created and allocated with %lld bytes of space.\n", filename, (long long)len_value);
    return fd;
}

int snapshot(int myfd){
    printf("Enter snapshot\n");

    struct stat file_info;
    if (fstat(myfd, &file_info) == -1) {
        perror("Error getting file attributes");
        close(myfd);
        return 1;
    }

    printf("File Size: %lld bytes \n", (long long)file_info.st_size);
    printf("File Permissions: %o \n", file_info.st_mode & ~S_IFMT);
    printf("File Owner UID: %d \n", file_info.st_uid);
    printf("File Group GID: %d \n", file_info.st_gid);


    off_t cur_offset = lseek(myfd, 0, SEEK_CUR);
    if (cur_offset == -1) {
        perror("Error getting current offset");
    }
    printf("Current offset: %lld \n", (long long)cur_offset);

    if (close(myfd) == -1) {
        perror("Error closing file");
        return 1;
    }

    printf("Leave snapshot\n");
}
(2)compile the c file into wasm: `./wasi-sdk-16.0/bin/clang --target=wasm32-unkown-wasi --sysroot=./wasi-sdk-16.0/share/wasi-sysroot test1.c -o test1.wasm`
(3)exeute open.wasm
wasmtime run  --dir=./Data test1.wasm
The permission of Data/hello.txt is 0600, user1 create the Data/hello.txt file before and user1 execute the Wasm file.

Expected Results

Other runtime print:

File 'Data/hello.txt' created and allocated with 39 bytes of space.
Enter snapshot
File Size: 58 bytes
File Permissions: 0
File Owner UID: 0
File Group GID: 0
Current offset: 0
Leave snapshot

And the file size is change into 58.

Actual Results

wasmtime prints:

Error allocating file space: Success
Enter snapshot
Error getting file attributes: Bad file descriptor

And file size remains 30.

Versions and Environment

wasmtime 13.0.0
Operating system: Ubuntu 20.04

Architecture: x86_64

view this post on Zulip Wasmtime GitHub notifications bot (Oct 17 2023 at 03:58):

orangeC23 edited issue #7264:

Steps to Reproduce

(1) The cfile is :

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>


int main() {
    const char* file_name = "Data/hello.txt";
    int open_style= O_CREAT | O_RDWR;
    int fd = get_fd(file_name, open_style);
    fd_allocateLuGpoE0tKi(fd, file_name);
    snapshot(fd);
    return 0;
}

int fd_allocateLuGpoE0tKi (int fd, const char* file_name){
    off_t start_value = 19;
    off_t len_value = 39;
    return fd_allocate(fd, file_name, start_value, len_value);
}

int get_fd(const char* file_name, int open_style){
    // Open a file for reading
    int fd = open(file_name, open_style);
    if (fd == -1) {
        perror("Failed to open the file");
        return 1;
    }

    return fd;
}

int fd_allocate (int fd, const char* filename, off_t start_value, off_t len_value){
    if (posix_fallocate(fd, start_value, len_value) != 0) {
        perror("Error allocating file space");
        close(fd);
        return 1;
    }

    printf("File '%s' created and allocated with %lld bytes of space.\n", filename, (long long)len_value);
    return fd;
}

int snapshot(int myfd){
    printf("Enter snapshot\n");

    struct stat file_info;
    if (fstat(myfd, &file_info) == -1) {
        perror("Error getting file attributes");
        close(myfd);
        return 1;
    }

    printf("File Size: %lld bytes \n", (long long)file_info.st_size);
    printf("File Permissions: %o \n", file_info.st_mode & ~S_IFMT);
    printf("File Owner UID: %d \n", file_info.st_uid);
    printf("File Group GID: %d \n", file_info.st_gid);


    off_t cur_offset = lseek(myfd, 0, SEEK_CUR);
    if (cur_offset == -1) {
        perror("Error getting current offset");
    }
    printf("Current offset: %lld \n", (long long)cur_offset);

    if (close(myfd) == -1) {
        perror("Error closing file");
        return 1;
    }

    printf("Leave snapshot\n");
}

(2)compile the c file into wasm: ./wasi-sdk-16.0/bin/clang --target=wasm32-unkown-wasi --sysroot=./wasi-sdk-16.0/share/wasi-sysroot test1.c -o test1.wasm
(3)exeute open.wasm
wasmtime run --dir=./Data test1.wasm
The permission of Data/hello.txt is 0600, user1 create the Data/hello.txt file before and user1 execute the Wasm file.

Expected Results

Other runtime print:

File 'Data/hello.txt' created and allocated with 39 bytes of space.
Enter snapshot
File Size: 58 bytes
File Permissions: 0
File Owner UID: 0
File Group GID: 0
Current offset: 0
Leave snapshot

And the file size is change into 58.

Actual Results

wasmtime prints:

Error allocating file space: Success
Enter snapshot
Error getting file attributes: Bad file descriptor

And file size remains 30.

Versions and Environment

wasmtime 13.0.0
Operating system: Ubuntu 20.04

Architecture: x86_64

view this post on Zulip Wasmtime GitHub notifications bot (Oct 17 2023 at 03:59):

orangeC23 edited issue #7264:

Steps to Reproduce

(1) The cfile is :

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>


int main() {
    const char* file_name = "Data/hello.txt";
    int open_style= O_CREAT | O_RDWR;
    int fd = get_fd(file_name, open_style);
    fd_allocateLuGpoE0tKi(fd, file_name);
    snapshot(fd);
    return 0;
}

int fd_allocateLuGpoE0tKi (int fd, const char* file_name){
    off_t start_value = 19;
    off_t len_value = 39;
    return fd_allocate(fd, file_name, start_value, len_value);
}

int get_fd(const char* file_name, int open_style){
    // Open a file for reading
    int fd = open(file_name, open_style);
    if (fd == -1) {
        perror("Failed to open the file");
        return 1;
    }

    return fd;
}

int fd_allocate (int fd, const char* filename, off_t start_value, off_t len_value){
    if (posix_fallocate(fd, start_value, len_value) != 0) {
        perror("Error allocating file space");
        close(fd);
        return 1;
    }

    printf("File '%s' created and allocated with %lld bytes of space.\n", filename, (long long)len_value);
    return fd;
}

int snapshot(int myfd){
    printf("Enter snapshot\n");

    struct stat file_info;
    if (fstat(myfd, &file_info) == -1) {
        perror("Error getting file attributes");
        close(myfd);
        return 1;
    }

    printf("File Size: %lld bytes \n", (long long)file_info.st_size);
    printf("File Permissions: %o \n", file_info.st_mode & ~S_IFMT);
    printf("File Owner UID: %d \n", file_info.st_uid);
    printf("File Group GID: %d \n", file_info.st_gid);


    off_t cur_offset = lseek(myfd, 0, SEEK_CUR);
    if (cur_offset == -1) {
        perror("Error getting current offset");
    }
    printf("Current offset: %lld \n", (long long)cur_offset);

    if (close(myfd) == -1) {
        perror("Error closing file");
        return 1;
    }

    printf("Leave snapshot\n");
}

(2)compile the c file into wasm: ./wasi-sdk-16.0/bin/clang --target=wasm32-unkown-wasi --sysroot=./wasi-sdk-16.0/share/wasi-sysroot test1.c -o test1.wasm
(3)exeute open.wasm
wasmtime run --dir=./Data test1.wasm
The permission of Data/hello.txt is 0600 or 0700, user1 create the Data/hello.txt file before and user1 execute the Wasm file.

Expected Results

Other runtime print:

File 'Data/hello.txt' created and allocated with 39 bytes of space.
Enter snapshot
File Size: 58 bytes
File Permissions: 0
File Owner UID: 0
File Group GID: 0
Current offset: 0
Leave snapshot

And the file size is change into 58.

Actual Results

wasmtime prints:

Error allocating file space: Success
Enter snapshot
Error getting file attributes: Bad file descriptor

And file size remains 30.

Versions and Environment

wasmtime 13.0.0
Operating system: Ubuntu 20.04

Architecture: x86_64

view this post on Zulip Wasmtime GitHub notifications bot (Oct 17 2023 at 05:51):

orangeC23 edited issue #7264:

Steps to Reproduce

(1) The cfile is :

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>


int main() {
    const char* file_name = "Data/hello.txt";
    int open_style= O_CREAT | O_RDWR;
    int fd = get_fd(file_name, open_style);
    fd_allocateLuGpoE0tKi(fd, file_name);
    snapshot(fd);
    return 0;
}

int fd_allocateLuGpoE0tKi (int fd, const char* file_name){
    off_t start_value = 19;
    off_t len_value = 39;
    return fd_allocate(fd, file_name, start_value, len_value);
}

int get_fd(const char* file_name, int open_style){
    // Open a file for reading
    int fd = open(file_name, open_style);
    if (fd == -1) {
        perror("Failed to open the file");
        return 1;
    }

    return fd;
}

int fd_allocate (int fd, const char* filename, off_t start_value, off_t len_value){
    if (posix_fallocate(fd, start_value, len_value) != 0) {
        perror("Error allocating file space");
        close(fd);
        return 1;
    }

    printf("File '%s' created and allocated with %lld bytes of space.\n", filename, (long long)len_value);
    return fd;
}

int snapshot(int myfd){
    printf("Enter snapshot\n");

    struct stat file_info;
    if (fstat(myfd, &file_info) == -1) {
        perror("Error getting file attributes");
        close(myfd);
        return 1;
    }

    printf("File Size: %lld bytes \n", (long long)file_info.st_size);
    printf("File Permissions: %o \n", file_info.st_mode & ~S_IFMT);
    printf("File Owner UID: %d \n", file_info.st_uid);
    printf("File Group GID: %d \n", file_info.st_gid);


    off_t cur_offset = lseek(myfd, 0, SEEK_CUR);
    if (cur_offset == -1) {
        perror("Error getting current offset");
    }
    printf("Current offset: %lld \n", (long long)cur_offset);

    if (close(myfd) == -1) {
        perror("Error closing file");
        return 1;
    }

    printf("Leave snapshot\n");
}

(2)compile the c file into wasm: ./wasi-sdk-16.0/bin/clang --target=wasm32-unkown-wasi --sysroot=./wasi-sdk-16.0/share/wasi-sysroot test1.c -o test1.wasm
(3)exeute open.wasm
wasmtime run --dir=./Data test1.wasm
The permission of Data/hello.txt is 0600 or 0700, user1 create the Data/hello.txt file before and user1 execute the Wasm file.

Expected Results

Other runtime print:

File 'Data/hello.txt' created and allocated with 39 bytes of space.
Enter snapshot
File Size: 58 bytes
File Permissions: 0
File Owner UID: 0
File Group GID: 0
Current offset: 0
Leave snapshot

And the file size is change into 58.

And using gcc test1.c -o test1 and ./test1 to execute also get this result.

Actual Results

wasmtime prints:

Error allocating file space: Success
Enter snapshot
Error getting file attributes: Bad file descriptor

And file size remains 30.

Versions and Environment

wasmtime 13.0.0
Operating system: Ubuntu 20.04

Architecture: x86_64

view this post on Zulip Wasmtime GitHub notifications bot (Oct 17 2023 at 14:26):

alexcrichton commented on issue #7264:

Thanks for the report! The reason this is happening is that fd_allocate is no longer supported. That's being removed from WASI and Wasmtime has preemptively adapted to the latest version of WASI. Other runtimes haven't caught up yet I suspect.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 17 2023 at 14:26):

alexcrichton closed issue #7264:

Steps to Reproduce

(1) The cfile is :

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>


int main() {
    const char* file_name = "Data/hello.txt";
    int open_style= O_CREAT | O_RDWR;
    int fd = get_fd(file_name, open_style);
    fd_allocateLuGpoE0tKi(fd, file_name);
    snapshot(fd);
    return 0;
}

int fd_allocateLuGpoE0tKi (int fd, const char* file_name){
    off_t start_value = 19;
    off_t len_value = 39;
    return fd_allocate(fd, file_name, start_value, len_value);
}

int get_fd(const char* file_name, int open_style){
    // Open a file for reading
    int fd = open(file_name, open_style);
    if (fd == -1) {
        perror("Failed to open the file");
        return 1;
    }

    return fd;
}

int fd_allocate (int fd, const char* filename, off_t start_value, off_t len_value){
    if (posix_fallocate(fd, start_value, len_value) != 0) {
        perror("Error allocating file space");
        close(fd);
        return 1;
    }

    printf("File '%s' created and allocated with %lld bytes of space.\n", filename, (long long)len_value);
    return fd;
}

int snapshot(int myfd){
    printf("Enter snapshot\n");

    struct stat file_info;
    if (fstat(myfd, &file_info) == -1) {
        perror("Error getting file attributes");
        close(myfd);
        return 1;
    }

    printf("File Size: %lld bytes \n", (long long)file_info.st_size);
    printf("File Permissions: %o \n", file_info.st_mode & ~S_IFMT);
    printf("File Owner UID: %d \n", file_info.st_uid);
    printf("File Group GID: %d \n", file_info.st_gid);


    off_t cur_offset = lseek(myfd, 0, SEEK_CUR);
    if (cur_offset == -1) {
        perror("Error getting current offset");
    }
    printf("Current offset: %lld \n", (long long)cur_offset);

    if (close(myfd) == -1) {
        perror("Error closing file");
        return 1;
    }

    printf("Leave snapshot\n");
}

(2)compile the c file into wasm: ./wasi-sdk-16.0/bin/clang --target=wasm32-unkown-wasi --sysroot=./wasi-sdk-16.0/share/wasi-sysroot test1.c -o test1.wasm
(3)exeute open.wasm
wasmtime run --dir=./Data test1.wasm
The permission of Data/hello.txt is 0600 or 0700, user1 create the Data/hello.txt file before and user1 execute the Wasm file.

Expected Results

Other runtime print:

File 'Data/hello.txt' created and allocated with 39 bytes of space.
Enter snapshot
File Size: 58 bytes
File Permissions: 0
File Owner UID: 0
File Group GID: 0
Current offset: 0
Leave snapshot

And the file size is change into 58.

And using gcc test1.c -o test1 and ./test1 to execute also get this result.

Actual Results

wasmtime prints:

Error allocating file space: Success
Enter snapshot
Error getting file attributes: Bad file descriptor

And file size remains 30.

Versions and Environment

wasmtime 13.0.0
Operating system: Ubuntu 20.04

Architecture: x86_64

view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2023 at 01:27):

orangeC23 commented on issue #7264:

Thanks for your reply. How can I view the changes in WASI compared to before? Is there any documentation? Thank you!

view this post on Zulip Wasmtime GitHub notifications bot (Oct 18 2023 at 19:08):

alexcrichton commented on issue #7264:

You can follow the https://github.com/WebAssembly/WASI repository, but I don't believe changes are exhaustively mentioned yet. Such processes evolve over time and aren't present immediately.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 20 2023 at 08:50):

orangeC23 commented on issue #7264:

Thanks !


Last updated: Nov 22 2024 at 17:03 UTC