Skip to content

Commit 6d0b508

Browse files
committed
daemon: remove setMayDetachMounts (set may_detach_mounts=1 on startup)
This function was added in 83c2152 to automatically set `/proc/sys/fs/may_detach_mounts=1` on startup. This is a kernel config available in RHEL7.4 based kernels that enables mountpoint removal where the mountpoint exists in other namespaces. This setting is the default, and non-configurable, on upstream kernels since 3.15. As this option was only supported in RHEL 7.x systems, which reached EOL, we can remove this code, as it's not doing anything on current kernels. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 733755d commit 6d0b508

3 files changed

Lines changed: 0 additions & 37 deletions

File tree

daemon/daemon.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -857,9 +857,6 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S
857857
return nil, err
858858
}
859859
rootIDs := idMapping.RootPair()
860-
if err := setMayDetachMounts(); err != nil {
861-
log.G(ctx).WithError(err).Warn("Could not set may_detach_mounts kernel parameter")
862-
}
863860

864861
// set up the tmpDir to use a canonical path
865862
tmp, err := prepareTempDir(config.Root)

daemon/daemon_unix.go

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"time"
1919

2020
"github.com/containerd/cgroups/v3"
21-
"github.com/containerd/containerd/pkg/userns"
2221
"github.com/containerd/log"
2322
"github.com/docker/docker/api/types/blkiodev"
2423
pblkiodev "github.com/docker/docker/api/types/blkiodev"
@@ -1403,35 +1402,6 @@ func (daemon *Daemon) setDefaultIsolation(*config.Config) error {
14031402
return nil
14041403
}
14051404

1406-
// This is used to allow removal of mountpoints that may be mounted in other
1407-
// namespaces on RHEL based kernels starting from RHEL 7.4.
1408-
// Without this setting, removals on these RHEL based kernels may fail with
1409-
// "device or resource busy".
1410-
// This setting is not available in upstream kernels as it is not configurable,
1411-
// but has been in the upstream kernels since 3.15.
1412-
func setMayDetachMounts() error {
1413-
f, err := os.OpenFile("/proc/sys/fs/may_detach_mounts", os.O_WRONLY, 0)
1414-
if err != nil {
1415-
if os.IsNotExist(err) {
1416-
return nil
1417-
}
1418-
return errors.Wrap(err, "error opening may_detach_mounts kernel config file")
1419-
}
1420-
defer f.Close()
1421-
1422-
_, err = f.WriteString("1")
1423-
if os.IsPermission(err) {
1424-
// Setting may_detach_mounts does not work in an
1425-
// unprivileged container. Ignore the error, but log
1426-
// it if we appear not to be in that situation.
1427-
if !userns.RunningInUserNS() {
1428-
log.G(context.TODO()).Debugf("Permission denied writing %q to /proc/sys/fs/may_detach_mounts", "1")
1429-
}
1430-
return nil
1431-
}
1432-
return err
1433-
}
1434-
14351405
func (daemon *Daemon) initCPURtController(cfg *config.Config, mnt, path string) error {
14361406
if path == "/" || path == "." {
14371407
return nil

daemon/daemon_windows.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -545,10 +545,6 @@ func (daemon *Daemon) setDefaultIsolation(config *config.Config) error {
545545
return nil
546546
}
547547

548-
func setMayDetachMounts() error {
549-
return nil
550-
}
551-
552548
func (daemon *Daemon) setupSeccompProfile(*config.Config) error {
553549
return nil
554550
}

0 commit comments

Comments
 (0)