|
@@ -68,7 +68,7 @@ func setupRootfs(config *configs.Config, console *linuxConsole) (err error) {
|
|
|
return newSystemError(err)
|
|
|
}
|
|
|
if !setupDev {
|
|
|
- if err := reOpenDevNull(config.Rootfs); err != nil {
|
|
|
+ if err := reOpenDevNull(); err != nil {
|
|
|
return newSystemError(err)
|
|
|
}
|
|
|
}
|
|
@@ -106,12 +106,12 @@ func mountToRootfs(m *configs.Mount, rootfs, mountLabel string) error {
|
|
|
if err := os.MkdirAll(dest, 0755); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- return m.MountPropagate(rootfs, mountLabel)
|
|
|
+ return mountPropagate(m, rootfs, mountLabel)
|
|
|
case "mqueue":
|
|
|
if err := os.MkdirAll(dest, 0755); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- if err := m.MountPropagate(rootfs, mountLabel); err != nil {
|
|
|
+ if err := mountPropagate(m, rootfs, mountLabel); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
return label.SetFileLabel(dest, mountLabel)
|
|
@@ -122,7 +122,7 @@ func mountToRootfs(m *configs.Mount, rootfs, mountLabel string) error {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
- if err := m.MountPropagate(rootfs, mountLabel); err != nil {
|
|
|
+ if err := mountPropagate(m, rootfs, mountLabel); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
if stat != nil {
|
|
@@ -135,12 +135,12 @@ func mountToRootfs(m *configs.Mount, rootfs, mountLabel string) error {
|
|
|
if err := os.MkdirAll(dest, 0755); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- return m.MountPropagate(rootfs, mountLabel)
|
|
|
+ return mountPropagate(m, rootfs, mountLabel)
|
|
|
case "securityfs":
|
|
|
if err := os.MkdirAll(dest, 0755); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- return m.MountPropagate(rootfs, mountLabel)
|
|
|
+ return mountPropagate(m, rootfs, mountLabel)
|
|
|
case "bind":
|
|
|
stat, err := os.Stat(m.Source)
|
|
|
if err != nil {
|
|
@@ -158,14 +158,16 @@ func mountToRootfs(m *configs.Mount, rootfs, mountLabel string) error {
|
|
|
if err := checkMountDestination(rootfs, dest); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
+ // update the mount with the correct dest after symlinks are resolved.
|
|
|
+ m.Destination = dest
|
|
|
if err := createIfNotExists(dest, stat.IsDir()); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- if err := m.MountPropagate(rootfs, mountLabel); err != nil {
|
|
|
+ if err := mountPropagate(m, rootfs, mountLabel); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
// bind mount won't change mount options, we need remount to make mount options effective.
|
|
|
- if err := m.Remount(rootfs); err != nil {
|
|
|
+ if err := remount(m, rootfs); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
if m.Relabel != "" {
|
|
@@ -234,7 +236,7 @@ func mountToRootfs(m *configs.Mount, rootfs, mountLabel string) error {
|
|
|
Destination: m.Destination,
|
|
|
Flags: defaultMountFlags | syscall.MS_RDONLY,
|
|
|
}
|
|
|
- if err := mcgrouproot.Remount(rootfs); err != nil {
|
|
|
+ if err := remount(mcgrouproot, rootfs); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
@@ -328,7 +330,7 @@ func setupDevSymlinks(rootfs string) error {
|
|
|
// this method will make them point to `/dev/null` in this container's rootfs. This
|
|
|
// needs to be called after we chroot/pivot into the container's rootfs so that any
|
|
|
// symlinks are resolved locally.
|
|
|
-func reOpenDevNull(rootfs string) error {
|
|
|
+func reOpenDevNull() error {
|
|
|
var stat, devNullStat syscall.Stat_t
|
|
|
file, err := os.Open("/dev/null")
|
|
|
if err != nil {
|
|
@@ -433,7 +435,7 @@ func setupPtmx(config *configs.Config, console *linuxConsole) error {
|
|
|
return fmt.Errorf("symlink dev ptmx %s", err)
|
|
|
}
|
|
|
if console != nil {
|
|
|
- return console.mount(config.Rootfs, config.MountLabel, 0, 0)
|
|
|
+ return console.mount(config.Rootfs, config.MountLabel)
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
@@ -532,3 +534,40 @@ func writeSystemProperty(key, value string) error {
|
|
|
keyPath := strings.Replace(key, ".", "/", -1)
|
|
|
return ioutil.WriteFile(path.Join("/proc/sys", keyPath), []byte(value), 0644)
|
|
|
}
|
|
|
+
|
|
|
+func remount(m *configs.Mount, rootfs string) error {
|
|
|
+ var (
|
|
|
+ dest = m.Destination
|
|
|
+ )
|
|
|
+ if !strings.HasPrefix(dest, rootfs) {
|
|
|
+ dest = filepath.Join(rootfs, dest)
|
|
|
+ }
|
|
|
+
|
|
|
+ if err := syscall.Mount(m.Source, dest, m.Device, uintptr(m.Flags|syscall.MS_REMOUNT), ""); err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+// Do the mount operation followed by additional mounts required to take care
|
|
|
+// of propagation flags.
|
|
|
+func mountPropagate(m *configs.Mount, rootfs string, mountLabel string) error {
|
|
|
+ var (
|
|
|
+ dest = m.Destination
|
|
|
+ data = label.FormatMountLabel(m.Data, mountLabel)
|
|
|
+ )
|
|
|
+ if !strings.HasPrefix(dest, rootfs) {
|
|
|
+ dest = filepath.Join(rootfs, dest)
|
|
|
+ }
|
|
|
+
|
|
|
+ if err := syscall.Mount(m.Source, dest, m.Device, uintptr(m.Flags), data); err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, pflag := range m.PropagationFlags {
|
|
|
+ if err := syscall.Mount("", dest, "", uintptr(pflag), ""); err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|