Skip to content

Commit

Permalink
Merge pull request #34886 from cpuguy83/may_detach_mount
Browse files Browse the repository at this point in the history
Automatically set `may_detach_mounts=1` on startup
  • Loading branch information
yongtang authored Sep 20, 2017
2 parents e40d5e6 + 83c2152 commit 7d70d0f
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion daemon/daemon_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,39 @@ func rootFSToAPIType(rootfs *image.RootFS) types.RootFS {
// setupDaemonProcess sets various settings for the daemon's process
func setupDaemonProcess(config *config.Config) error {
// setup the daemons oom_score_adj
return setupOOMScoreAdj(config.OOMScoreAdjust)
if err := setupOOMScoreAdj(config.OOMScoreAdjust); err != nil {
return err
}
return setMayDetachMounts()
}

// This is used to allow removal of mountpoints that may be mounted in other
// namespaces on RHEL based kernels starting from RHEL 7.4.
// Without this setting, removals on these RHEL based kernels may fail with
// "device or resource busy".
// This setting is not available in upstream kernels as it is not configurable,
// but has been in the upstream kernels since 3.15.
func setMayDetachMounts() error {
f, err := os.OpenFile("/proc/sys/fs/may_detach_mounts", os.O_WRONLY, 0)
if err != nil {
if os.IsNotExist(err) {
return nil
}
return errors.Wrap(err, "error opening may_detach_mounts kernel config file")
}
defer f.Close()

_, err = f.WriteString("1")
if os.IsPermission(err) {
// Setting may_detach_mounts does not work in an
// unprivileged container. Ignore the error, but log
// it if we appear not to be in that situation.
if !rsystem.RunningInUserNS() {
logrus.Debugf("Permission denied writing %q to /proc/sys/fs/may_detach_mounts", "1")
}
return nil
}
return err
}

func setupOOMScoreAdj(score int) error {
Expand Down

0 comments on commit 7d70d0f

Please sign in to comment.