|
|
ccd891 |
From f09346578021c12069b6deb9487a1462b8d28a83 Mon Sep 17 00:00:00 2001
|
|
|
ccd891 |
From: Nalin Dahyabhai <nalin@redhat.com>
|
|
|
ccd891 |
Date: Thu, 21 Nov 2019 15:32:41 -0500
|
|
|
ccd891 |
Subject: [PATCH 1/3] bind: don't complain about missing mountpoints
|
|
|
ccd891 |
|
|
|
ccd891 |
When we go to unmount a tree of mounts, if one of the directories isn't
|
|
|
ccd891 |
there, instead of returning an error as before, log a debug message and
|
|
|
ccd891 |
keep going.
|
|
|
ccd891 |
|
|
|
ccd891 |
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
|
|
|
ccd891 |
---
|
|
|
ccd891 |
bind/mount.go | 4 ++++
|
|
|
ccd891 |
1 file changed, 4 insertions(+)
|
|
|
ccd891 |
|
|
|
ccd891 |
diff --git a/bind/mount.go b/bind/mount.go
|
|
|
73af4c |
index e1ae323b9f..adde901fd1 100644
|
|
|
ccd891 |
--- a/bind/mount.go
|
|
|
ccd891 |
+++ b/bind/mount.go
|
|
|
ccd891 |
@@ -264,6 +264,10 @@ func UnmountMountpoints(mountpoint string, mountpointsToRemove []string) error {
|
|
|
ccd891 |
mount := getMountByID(id)
|
|
|
ccd891 |
// check if this mountpoint is mounted
|
|
|
ccd891 |
if err := unix.Lstat(mount.Mountpoint, &st); err != nil {
|
|
|
ccd891 |
+ if os.IsNotExist(err) {
|
|
|
ccd891 |
+ logrus.Debugf("mountpoint %q is not present(?), skipping", mount.Mountpoint)
|
|
|
ccd891 |
+ continue
|
|
|
ccd891 |
+ }
|
|
|
ccd891 |
return errors.Wrapf(err, "error checking if %q is mounted", mount.Mountpoint)
|
|
|
ccd891 |
}
|
|
|
ccd891 |
if mount.Major != int(unix.Major(st.Dev)) || mount.Minor != int(unix.Minor(st.Dev)) {
|
|
|
ccd891 |
|
|
|
ccd891 |
From c5fb681a6082b78c422eb3531667dc6d607a9355 Mon Sep 17 00:00:00 2001
|
|
|
ccd891 |
From: Nalin Dahyabhai <nalin@redhat.com>
|
|
|
ccd891 |
Date: Fri, 22 Nov 2019 14:22:26 -0500
|
|
|
ccd891 |
Subject: [PATCH 2/3] chroot: Unmount with MNT_DETACH instead of
|
|
|
ccd891 |
UnmountMountpoints()
|
|
|
ccd891 |
|
|
|
ccd891 |
Unmounting the rootfs with MNT_DETACH should unmount everything below
|
|
|
ccd891 |
it, so we don't need to use the more exhaustive method that our bind
|
|
|
ccd891 |
package uses for its bind mounts.
|
|
|
ccd891 |
|
|
|
ccd891 |
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
|
|
|
ccd891 |
---
|
|
|
ccd891 |
chroot/run.go | 25 +++++++++++++++----------
|
|
|
ccd891 |
1 file changed, 15 insertions(+), 10 deletions(-)
|
|
|
ccd891 |
|
|
|
ccd891 |
diff --git a/chroot/run.go b/chroot/run.go
|
|
|
73af4c |
index fbccbcdb0d..76ac78d1ff 100644
|
|
|
ccd891 |
--- a/chroot/run.go
|
|
|
ccd891 |
+++ b/chroot/run.go
|
|
|
ccd891 |
@@ -15,6 +15,7 @@ import (
|
|
|
ccd891 |
"strings"
|
|
|
ccd891 |
"sync"
|
|
|
ccd891 |
"syscall"
|
|
|
ccd891 |
+ "time"
|
|
|
ccd891 |
"unsafe"
|
|
|
ccd891 |
|
|
|
ccd891 |
"github.com/containers/buildah/bind"
|
|
|
ccd891 |
@@ -1002,12 +1003,19 @@ func isDevNull(dev os.FileInfo) bool {
|
|
|
ccd891 |
// callback that will clean up its work.
|
|
|
ccd891 |
func setupChrootBindMounts(spec *specs.Spec, bundlePath string) (undoBinds func() error, err error) {
|
|
|
ccd891 |
var fs unix.Statfs_t
|
|
|
ccd891 |
- removes := []string{}
|
|
|
ccd891 |
undoBinds = func() error {
|
|
|
ccd891 |
- if err2 := bind.UnmountMountpoints(spec.Root.Path, removes); err2 != nil {
|
|
|
ccd891 |
- logrus.Warnf("pkg/chroot: error unmounting %q: %v", spec.Root.Path, err2)
|
|
|
ccd891 |
- if err == nil {
|
|
|
ccd891 |
- err = err2
|
|
|
ccd891 |
+ if err2 := unix.Unmount(spec.Root.Path, unix.MNT_DETACH); err2 != nil {
|
|
|
ccd891 |
+ retries := 0
|
|
|
ccd891 |
+ for (err2 == unix.EBUSY || err2 == unix.EAGAIN) && retries < 50 {
|
|
|
ccd891 |
+ time.Sleep(50 * time.Millisecond)
|
|
|
ccd891 |
+ err2 = unix.Unmount(spec.Root.Path, unix.MNT_DETACH)
|
|
|
ccd891 |
+ retries++
|
|
|
ccd891 |
+ }
|
|
|
ccd891 |
+ if err2 != nil {
|
|
|
ccd891 |
+ logrus.Warnf("pkg/chroot: error unmounting %q (retried %d times): %v", spec.Root.Path, retries, err2)
|
|
|
ccd891 |
+ if err == nil {
|
|
|
ccd891 |
+ err = err2
|
|
|
ccd891 |
+ }
|
|
|
ccd891 |
}
|
|
|
ccd891 |
}
|
|
|
ccd891 |
return err
|
|
|
ccd891 |
@@ -1096,6 +1104,7 @@ func setupChrootBindMounts(spec *specs.Spec, bundlePath string) (undoBinds func(
|
|
|
ccd891 |
// Add /sys/fs/selinux to the set of masked paths, to ensure that we don't have processes
|
|
|
ccd891 |
// attempting to interact with labeling, when they aren't allowed to do so.
|
|
|
ccd891 |
spec.Linux.MaskedPaths = append(spec.Linux.MaskedPaths, "/sys/fs/selinux")
|
|
|
ccd891 |
+
|
|
|
ccd891 |
// Bind mount in everything we've been asked to mount.
|
|
|
ccd891 |
for _, m := range spec.Mounts {
|
|
|
ccd891 |
// Skip anything that we just mounted.
|
|
|
ccd891 |
@@ -1141,13 +1150,11 @@ func setupChrootBindMounts(spec *specs.Spec, bundlePath string) (undoBinds func(
|
|
|
ccd891 |
if !os.IsNotExist(err) {
|
|
|
ccd891 |
return undoBinds, errors.Wrapf(err, "error examining %q for mounting in mount namespace", target)
|
|
|
ccd891 |
}
|
|
|
ccd891 |
- // The target isn't there yet, so create it, and make a
|
|
|
ccd891 |
- // note to remove it later.
|
|
|
ccd891 |
+ // The target isn't there yet, so create it.
|
|
|
ccd891 |
if srcinfo.IsDir() {
|
|
|
ccd891 |
if err = os.MkdirAll(target, 0111); err != nil {
|
|
|
ccd891 |
return undoBinds, errors.Wrapf(err, "error creating mountpoint %q in mount namespace", target)
|
|
|
ccd891 |
}
|
|
|
ccd891 |
- removes = append(removes, target)
|
|
|
ccd891 |
} else {
|
|
|
ccd891 |
if err = os.MkdirAll(filepath.Dir(target), 0111); err != nil {
|
|
|
ccd891 |
return undoBinds, errors.Wrapf(err, "error ensuring parent of mountpoint %q (%q) is present in mount namespace", target, filepath.Dir(target))
|
|
|
ccd891 |
@@ -1157,7 +1164,6 @@ func setupChrootBindMounts(spec *specs.Spec, bundlePath string) (undoBinds func(
|
|
|
ccd891 |
return undoBinds, errors.Wrapf(err, "error creating mountpoint %q in mount namespace", target)
|
|
|
ccd891 |
}
|
|
|
ccd891 |
file.Close()
|
|
|
ccd891 |
- removes = append(removes, target)
|
|
|
ccd891 |
}
|
|
|
ccd891 |
}
|
|
|
ccd891 |
requestFlags := bindFlags
|
|
|
ccd891 |
@@ -1266,7 +1272,6 @@ func setupChrootBindMounts(spec *specs.Spec, bundlePath string) (undoBinds func(
|
|
|
ccd891 |
if err := os.Mkdir(roEmptyDir, 0700); err != nil {
|
|
|
ccd891 |
return undoBinds, errors.Wrapf(err, "error creating empty directory %q", roEmptyDir)
|
|
|
ccd891 |
}
|
|
|
ccd891 |
- removes = append(removes, roEmptyDir)
|
|
|
ccd891 |
}
|
|
|
ccd891 |
|
|
|
ccd891 |
// Set up any masked paths that we need to. If we're running inside of
|
|
|
ccd891 |
|
|
|
ccd891 |
From ec1be6a51941e10b5316c911ef97c88940f7c095 Mon Sep 17 00:00:00 2001
|
|
|
ccd891 |
From: Nalin Dahyabhai <nalin@redhat.com>
|
|
|
ccd891 |
Date: Fri, 22 Nov 2019 14:52:25 -0500
|
|
|
ccd891 |
Subject: [PATCH 3/3] overlay.bats typo: fuse-overlays should be fuse-overlayfs
|
|
|
ccd891 |
|
|
|
ccd891 |
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
|
|
|
ccd891 |
---
|
|
|
ccd891 |
tests/overlay.bats | 4 ++--
|
|
|
ccd891 |
1 file changed, 2 insertions(+), 2 deletions(-)
|
|
|
ccd891 |
|
|
|
ccd891 |
diff --git a/tests/overlay.bats b/tests/overlay.bats
|
|
|
73af4c |
index 04056f6804..7cc2d0c622 100644
|
|
|
ccd891 |
--- a/tests/overlay.bats
|
|
|
ccd891 |
+++ b/tests/overlay.bats
|
|
|
ccd891 |
@@ -3,14 +3,14 @@
|
|
|
ccd891 |
load helpers
|
|
|
ccd891 |
|
|
|
ccd891 |
@test "overlay specific level" {
|
|
|
ccd891 |
- if test \! -e /usr/bin/fuse-overlays -a "$BUILDAH_ISOLATION" = "rootless"; then
|
|
|
ccd891 |
+ if test \! -e /usr/bin/fuse-overlayfs -a "$BUILDAH_ISOLATION" = "rootless"; then
|
|
|
ccd891 |
skip "BUILDAH_ISOLATION = $BUILDAH_ISOLATION" and no /usr/bin/fuse-overlayfs present
|
|
|
ccd891 |
fi
|
|
|
ccd891 |
image=alpine
|
|
|
ccd891 |
mkdir ${TESTDIR}/lower
|
|
|
ccd891 |
touch ${TESTDIR}/lower/foo
|
|
|
ccd891 |
|
|
|
ccd891 |
-cid=$(buildah --log-level=error from -v ${TESTDIR}/lower:/lower:O --quiet --signature-policy ${TESTSDIR}/policy.json $image)
|
|
|
ccd891 |
+ cid=$(buildah --log-level=error from -v ${TESTDIR}/lower:/lower:O --quiet --signature-policy ${TESTSDIR}/policy.json $image)
|
|
|
ccd891 |
|
|
|
ccd891 |
# This should succeed
|
|
|
ccd891 |
run_buildah --log-level=error run $cid ls /lower/foo
|