-
Notifications
You must be signed in to change notification settings - Fork 19.1k
Use naive diff for overlay2 when opaque copy up bug present #28138
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| // +build linux | ||
|
|
||
| package overlay2 | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "io/ioutil" | ||
| "os" | ||
| "path" | ||
| "path/filepath" | ||
| "syscall" | ||
|
|
||
| "github.com/Sirupsen/logrus" | ||
| "github.com/docker/docker/pkg/system" | ||
| "github.com/pkg/errors" | ||
| ) | ||
|
|
||
| // hasOpaqueCopyUpBug checks whether the filesystem has a bug | ||
| // which copies up the opaque flag when copying up an opaque | ||
| // directory. When this bug exists naive diff should be used. | ||
| func hasOpaqueCopyUpBug(d string) error { | ||
| td, err := ioutil.TempDir(d, "opaque-bug-check") | ||
| if err != nil { | ||
| return err | ||
| } | ||
| defer func() { | ||
| if err := os.RemoveAll(td); err != nil { | ||
| logrus.Warnf("Failed to remove check directory %v: %v", td, err) | ||
| } | ||
| }() | ||
|
|
||
| // Make directories l1/d, l2/d, l3, work, merged | ||
| if err := os.MkdirAll(filepath.Join(td, "l1", "d"), 0755); err != nil { | ||
| return err | ||
| } | ||
| if err := os.MkdirAll(filepath.Join(td, "l2", "d"), 0755); err != nil { | ||
| return err | ||
| } | ||
| if err := os.Mkdir(filepath.Join(td, "l3"), 0755); err != nil { | ||
| return err | ||
| } | ||
| if err := os.Mkdir(filepath.Join(td, "work"), 0755); err != nil { | ||
| return err | ||
| } | ||
| if err := os.Mkdir(filepath.Join(td, "merged"), 0755); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // Mark l2/d as opaque | ||
| if err := system.Lsetxattr(filepath.Join(td, "l2", "d"), "trusted.overlay.opaque", []byte("y"), 0); err != nil { | ||
| return errors.Wrap(err, "failed to set opaque flag on middle layer") | ||
| } | ||
|
|
||
| opts := fmt.Sprintf("lowerdir=%s:%s,upperdir=%s,workdir=%s", path.Join(td, "l2"), path.Join(td, "l1"), path.Join(td, "l3"), path.Join(td, "work")) | ||
| if err := syscall.Mount("overlay", filepath.Join(td, "merged"), "overlay", 0, opts); err != nil { | ||
| return errors.Wrap(err, "failed to mount overlay") | ||
| } | ||
| defer func() { | ||
| if err := syscall.Unmount(filepath.Join(td, "merged"), 0); err != nil { | ||
| logrus.Warnf("Failed to unmount check directory %v: %v", filepath.Join(td, "merged"), err) | ||
| } | ||
| }() | ||
|
|
||
| // Touch file in d to force copy up of opaque directory "d" from "l2" to "l3" | ||
| if err := ioutil.WriteFile(filepath.Join(td, "merged", "d", "f"), []byte{}, 0644); err != nil { | ||
| return errors.Wrap(err, "failed to write to merged directory") | ||
| } | ||
|
|
||
| // Check l3/d does not have opaque flag | ||
| xattrOpaque, err := system.Lgetxattr(filepath.Join(td, "l3", "d"), "trusted.overlay.opaque") | ||
| if err != nil { | ||
| return errors.Wrap(err, "failed to read opaque flag on upper layer") | ||
| } | ||
| if string(xattrOpaque) == "y" { | ||
| return errors.New("opaque flag erroneously copied up, consider update to kernel 4.8 or later to fix") | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
windows fails to compile during UT:
https://jenkins.dockerproject.org/job/Docker-PRs-WoW-RS1/5763/console
Please add the build tag?