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

[release-1.51] Backport ignore chown errors in additionalimagestore #1990

Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion drivers/aufs/aufs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ func BenchmarkConcurrentAccess(b *testing.B) {
}

parent := ids[1]
ids = append(ids[2:])
ids = ids[2:]

chErr := make(chan error, numConcurrent)
var outerGroup sync.WaitGroup
Expand Down
42 changes: 33 additions & 9 deletions drivers/overlay/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -1670,13 +1670,21 @@ func (d *Driver) get(id string, disableShifting bool, options graphdriver.MountO
}

if err := idtools.MkdirAllAs(diffDir, perms, rootUID, rootGID); err != nil {
return "", err
if !inAdditionalStore {
return "", err
}
// if it is in an additional store, do not fail if the directory already exists
if _, err2 := os.Stat(diffDir); err2 != nil {
return "", err
}
}

mergedDir := path.Join(workDirBase, "merged")
// Create the driver merged dir
if err := idtools.MkdirAs(mergedDir, 0o700, rootUID, rootGID); err != nil && !os.IsExist(err) {
return "", err
// Attempt to create the merged dir only if it doesn't exist.
if _, err := os.Stat(mergedDir); err != nil && os.IsNotExist(err) {
if err := idtools.MkdirAs(mergedDir, 0o700, rootUID, rootGID); err != nil && !os.IsExist(err) {
return "", err
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@giuseppe please eyeball this. In the picked commit, it uses dir instead of workDirBase as listed here in line 1682. I think this is OK, but would like your verification.

}
if count := d.ctr.Increment(mergedDir); count > 1 {
return mergedDir, nil
Expand Down Expand Up @@ -1841,7 +1849,7 @@ func (d *Driver) get(id string, disableShifting bool, options graphdriver.MountO

// Put unmounts the mount path created for the give id.
func (d *Driver) Put(id string) error {
dir := d.dir(id)
dir, _, inAdditionalStore := d.dir2(id)
if _, err := os.Stat(dir); err != nil {
return err
}
Expand Down Expand Up @@ -1902,11 +1910,27 @@ func (d *Driver) Put(id string) error {
}
}

if err := unix.Rmdir(mountpoint); err != nil && !os.IsNotExist(err) {
logrus.Debugf("Failed to remove mountpoint %s overlay: %s - %v", id, mountpoint, err)
return fmt.Errorf("removing mount point %q: %w", mountpoint, err)
}
if !inAdditionalStore {
uid, gid := int(0), int(0)
fi, err := os.Stat(mountpoint)
if err != nil {
return err
}
if stat, ok := fi.Sys().(*syscall.Stat_t); ok {
uid, gid = int(stat.Uid), int(stat.Gid)
}

tmpMountpoint := path.Join(dir, "merged.1")
if err := idtools.MkdirAs(tmpMountpoint, 0o700, uid, gid); err != nil && !errors.Is(err, os.ErrExist) {
return err
}
// rename(2) can be used on an empty directory, as it is the mountpoint after umount, and it retains
// its atomic semantic. In this way the "merged" directory is never removed.
if err := unix.Rename(tmpMountpoint, mountpoint); err != nil {
logrus.Debugf("Failed to replace mountpoint %s overlay: %s - %v", id, mountpoint, err)
return fmt.Errorf("replacing mount point %q: %w", mountpoint, err)
}
}
return nil
}

Expand Down
5 changes: 4 additions & 1 deletion tests/overlay-recreate.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ load helpers
storage unmount "$lowerlayer"
storage mount "$midlayer"
storage unmount "$midlayer"
storage mount "$upperlayer"
run storage --debug=false mount "$upperlayer"
merged_dir="$output"
storage unmount "$upperlayer"
# okay, but how about this?
rm -v ${TESTDIR}/root/overlay/*/link
Expand All @@ -27,6 +28,8 @@ load helpers
storage unmount "$lowerlayer"
storage mount "$midlayer"
storage unmount "$midlayer"
# check it works if we delete the merged directory.
rmdir "$merged_dir"
storage mount "$upperlayer"
storage unmount "$upperlayer"
# okay, not bad, kid.
Expand Down
2 changes: 1 addition & 1 deletion tests/tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ $(BUILDDIR)/git-validation:
$(BUILDDIR)/go-md2man:
$(call go-build,./vendor/github.com/cpuguy83/go-md2man)

$(BUILDDIR)/golangci-lint: VERSION=v1.51.2
$(BUILDDIR)/golangci-lint: VERSION=v1.55.2
$(BUILDDIR)/golangci-lint:
curl -fsSL https://raw.githubusercontent.com/golangci/golangci-lint/$(VERSION)/install.sh | sh -s -- -b ./$(BUILDDIR) $(VERSION)