Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/link/internal/ld: fallocate_test.go failed test #50042

Closed
devnull850 opened this issue Dec 8, 2021 · 1 comment
Closed

cmd/link/internal/ld: fallocate_test.go failed test #50042

devnull850 opened this issue Dec 8, 2021 · 1 comment

Comments

@devnull850
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.17.4 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOVERSION="go1.17.4"

What did you do?

I tried compiling Go off of current master on my machine. I followed the directions for compiling from source. I ran into an error when running all.bash in the fallocate_test.go file. I did a bit of research and it appears to be a problem with ZFS and nothing with the Go programming language.

#define _GNU_SOURCE
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

const char FILENAME[] = "/tmp/xxx";
const char FORMAT[] = "st_size/512 = %ld/512 = %ld, st_blocks = %ld\n";
const int FLAGS = O_RDWR | O_CREAT | O_TRUNC;
const mode_t MODE = 0666;

int main(void) {
    int e, fd;
    struct stat st;

    if ((fd = open(FILENAME, FLAGS, MODE)) == -1) {
        fprintf(stderr, "open failed: %d\n", fd);
        exit(EXIT_FAILURE);
    }

    if ((e = fallocate(fd, 0, 0, 1<<20)) == -1) {
        fprintf(stderr, "fallocate failed: %d\n", e);
        exit(EXIT_FAILURE);
    }

    if ((e = fstat(fd, &st)) == -1) {
        fprintf(stderr, "fstat failed: %d\n", e);
        exit(EXIT_FAILURE);
    }

    printf("%zu, %zu, %zu\n", sizeof(long int),
            sizeof(blkcnt_t), sizeof(off_t));
    printf("%zu\n", st.st_blksize);
    printf(FORMAT, st.st_size, st.st_size/512, st.st_blocks);
    printf("%lu, %lu\n", st.st_size, st.st_blksize * st.st_blocks);

    if (close(fd) == -1) {
        fprintf(stderr, "close failed: %d\n", fd);
        exit(EXIT_FAILURE);
    }

    if (remove(FILENAME) == -1) {
        fprintf(stderr, "error removing file [%s]\n", FILENAME);
        exit(EXIT_FAILURE);
    }

    return EXIT_SUCCESS;
}

Running the program above (recommended for debugging in a previous ticket related to this) resulted in

8, 8, 8
131072
st_size/512 = 1048576/512 = 2048, st_blocks = 2
1048576, 262144

The total size in bytes for the file is not equal to the number of 512 byte blocks allocated thus something weird is happening in reporting stats of a file descriptor back. Since this is an issue outside of Go, is there anyway a logic check could be done to not throw the failing test error?

// /src/cmd/link/internal/ld/fallocate_test.go [line 60]

if got, actual, want := stat.Sys().(*syscall.Stat_t).Blocks,
    stat.Sys().(*syscall.Stat_t).Size/512, (sz+511)/512; actual == got && got < want {
    t.Errorf("unexpected disk usage: got %d blocks, want at least %d", got, want)
}

Or leverage the os library to determine if the filesystem is ZFS or something that fallocate does not work well with but that fallocate does not fail with (return -1) as well?

What did you expect to see?

ALL TESTS PASSED

What did you see instead?

--- FAIL: TestFallocate (0.00s)
    fallocate_test.go:61: unexpected disk usage: got 2 blocks, want at least 2048
    fallocate_test.go:61: unexpected disk usage: got 2 blocks, want at least 4096
    fallocate_test.go:61: unexpected disk usage: got 2 blocks, want at least 6144
FAIL
FAIL	cmd/link/internal/ld	20.138s
@devnull850 devnull850 changed the title affected/package: ld cmd/link/internal/ld: fallocate_test.go failed test Dec 8, 2021
@cherrymui
Copy link
Member

Looks like a dup of #42005 . As you said, it is a problem with ZFS.

I tried compiling Go off of current master on my machine

If you just want to build the toolchain, you can just run make.bash instead of all.bash (which include tests).

@golang golang locked and limited conversation to collaborators Dec 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants