-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Add option to perform syncfs after pull #9401
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,15 +20,18 @@ import ( | |
| "context" | ||
| "fmt" | ||
| "io" | ||
| "os" | ||
| "strings" | ||
|
|
||
| "github.com/containerd/containerd/v2/archive" | ||
| "github.com/containerd/containerd/v2/errdefs" | ||
| "github.com/containerd/containerd/v2/mount" | ||
| "github.com/containerd/containerd/v2/pkg/userns" | ||
|
|
||
| "golang.org/x/sys/unix" | ||
| ) | ||
|
|
||
| func apply(ctx context.Context, mounts []mount.Mount, r io.Reader) error { | ||
| func apply(ctx context.Context, mounts []mount.Mount, r io.Reader, sync bool) (retErr error) { | ||
| switch { | ||
| case len(mounts) == 1 && mounts[0].Type == "overlay": | ||
| // OverlayConvertWhiteout (mknod c 0 0) doesn't work in userns. | ||
|
|
@@ -50,7 +53,18 @@ func apply(ctx context.Context, mounts []mount.Mount, r io.Reader) error { | |
| opts = append(opts, archive.WithParents(parents)) | ||
| } | ||
| _, err = archive.Apply(ctx, path, r, opts...) | ||
| if err == nil && sync { | ||
| err = doSyncFs(path) | ||
| } | ||
| return err | ||
| case sync && len(mounts) == 1 && mounts[0].Type == "bind": | ||
| defer func() { | ||
| if retErr != nil { | ||
| return | ||
| } | ||
|
|
||
| retErr = doSyncFs(mounts[0].Source) | ||
| }() | ||
|
Comment on lines
+60
to
+67
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for my knowledge here, we need this logic because
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. based on test result, yes. The alpine image has only one layer. Based on the following test, the file cache is gone after reboot. |
||
| } | ||
| return mount.WithTempMount(ctx, mounts, func(root string) error { | ||
| _, err := archive.Apply(ctx, root, r) | ||
|
|
@@ -75,3 +89,17 @@ func getOverlayPath(options []string) (upper string, lower []string, err error) | |
|
|
||
| return | ||
| } | ||
|
|
||
| func doSyncFs(file string) error { | ||
| fd, err := os.Open(file) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to open %s: %w", file, err) | ||
| } | ||
| defer fd.Close() | ||
|
|
||
| _, _, errno := unix.Syscall(unix.SYS_SYNCFS, fd.Fd(), 0, 0) | ||
| if errno != 0 { | ||
| return fmt.Errorf("failed to syncfs for %s: %w", file, errno) | ||
| } | ||
| return nil | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,8 @@ import ( | |
| "github.com/containerd/containerd/v2/mount" | ||
| ) | ||
|
|
||
| func apply(ctx context.Context, mounts []mount.Mount, r io.Reader) error { | ||
| func apply(ctx context.Context, mounts []mount.Mount, r io.Reader, _sync bool) error { | ||
| // TODO: for windows, how to sync? | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, let's have an issue to track. Note that _other isn't just Windows; FreeBSD will be in this codepath too (but there's no overlayfs, so there is a mount/umount operation).
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. #9497 PTAL. Thanks |
||
| return mount.WithTempMount(ctx, mounts, func(root string) error { | ||
| _, err := archive.Apply(ctx, root, r) | ||
| return err | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we open an issue to track this TODO?