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