From 004f3951d5bfbbc2ba30536b97ab519679fcd679 Mon Sep 17 00:00:00 2001 From: Rodrigo Campos Date: Mon, 23 Sep 2024 16:13:08 +0200 Subject: [PATCH] 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 --- core/mount/mount_linux.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/mount/mount_linux.go b/core/mount/mount_linux.go index 330760335..ec5417ed7 100644 --- a/core/mount/mount_linux.go +++ b/core/mount/mount_linux.go @@ -251,7 +251,9 @@ func doPrepareIDMappedOverlay(lowerDirs []string, usernsFd int) (tmpLowerDirs [] } cleanUp := func() { 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) } }