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

snapshotter: use syncfs system call #2816

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion pkg/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
"sort"
"syscall"

Expand All @@ -31,6 +32,7 @@ import (
"github.com/GoogleContainerTools/kaniko/pkg/util"

"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
)

// For testing
Expand Down Expand Up @@ -155,7 +157,20 @@ func (s *Snapshotter) scanFullFilesystem() ([]string, []string, error) {
// for example the hashing function that determines if files are equal uses the mtime of the files,
// which can lag if sync is not called. Unfortunately there can still be lag if too much data needs
// to be flushed or the disk does its own caching/buffering.
syscall.Sync()
if runtime.GOOS == "linux" {
dir, err := os.Open(s.directory)
if err != nil {
return nil, nil, err
}
defer dir.Close()
_, _, errno := syscall.Syscall(unix.SYS_SYNCFS, dir.Fd(), 0, 0)
if errno != 0 {
return nil, nil, errno
}
} else {
// fallback to full page cache sync
syscall.Sync()
}

s.l.Snapshot()

Expand Down
Loading