core/mount: Use MNT_DETACH for umount of tmp layers

Overlayfs needs to do an idmap mount of each layer and the cleanup
function just unmounts and deletes the directories. However, when the
resource is busy, the umount fails.

Let's make the unmount detached so the unmount will eventually be done
when it's not busy anymore. Also, making it detached solves the issues with
the unmount failing because it is busy.

Big kudos to @mbaynton for reporting this issue with lot of details,
nailing it down to containerd lines of code and showing all the log
lines to understand the big picture.

Fixes: #10704

Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
This commit is contained in:
Rodrigo Campos 2024-09-23 16:13:08 +02:00
parent 906c23218c
commit 004f3951d5

View File

@ -251,7 +251,9 @@ func doPrepareIDMappedOverlay(lowerDirs []string, usernsFd int) (tmpLowerDirs []
} }
cleanUp := func() { cleanUp := func() {
for _, lowerDir := range tmpLowerDirs { for _, lowerDir := range tmpLowerDirs {
if err := unix.Unmount(lowerDir, 0); err != nil { // Do a detached unmount so even if the resource is busy, the mount will be
// gone (eventually) and we can safely delete the directory too.
if err := unix.Unmount(lowerDir, unix.MNT_DETACH); err != nil {
log.L.WithError(err).Warnf("failed to unmount temp lowerdir %s", lowerDir) log.L.WithError(err).Warnf("failed to unmount temp lowerdir %s", lowerDir)
} }
} }