Skip to content

Commit f71e10a

Browse files
committed
fix(rootfs): Ensure the container's rootfs has MS_SHARED flag
Ensure that the container's rootfs has the MS_SHARED propagation flag. THis is necessary in order to propagate any unmounts that might happen later (e.g. in the case of block-based snapshots which are attached to the sandbox) in the mount peer groups (i.e. in the initial mount namespace). THere is no problem to do that for every rootfs, because reexec will later cut off the propagation during the preparation of the monitor;s rootfs. In the future though, we need to move this up in the shim. PR: #572 Signed-off-by: Charalampos Mainas <cmainas@nubificus.co.uk> Reviewed-by: Anastassios Nanos <ananos@nubificus.co.uk> Approved-by: Anastassios Nanos <ananos@nubificus.co.uk>
1 parent a1a4d18 commit f71e10a

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

pkg/unikontainers/unikontainers.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,33 @@ func Get(containerID string, rootDir string) (*Unikontainer, error) {
136136
// creates the Unikernel base directory and
137137
// saves the state.json file with the current Unikernel state
138138
func (u *Unikontainer) InitialSetup() error {
139+
bundleDir := filepath.Clean(u.State.Bundle)
140+
rootfsDir := filepath.Clean(u.Spec.Root.Path)
141+
rootfsDir, err := resolveAgainstBase(bundleDir, rootfsDir)
142+
if err != nil {
143+
uniklog.Errorf("could not resolve rootfs directory %s: %v", rootfsDir, err)
144+
return err
145+
}
146+
147+
// Ensure the container's rootfs has the correct propagation flag
148+
// so if we unmount it later, it gets unmounted from other mount peer
149+
// groups too. We do that regardless of the type of the container's
150+
// rootfs (e.g. block-based, overlay) abd this is ok, because we later
151+
// cut off all propagation from reexec.
152+
// TODO: Move this to the shim, when we finally make it.
153+
err = unix.Mount("", rootfsDir, "", unix.MS_SHARED|unix.MS_REC, "")
154+
if err != nil && !errors.Is(err, unix.EINVAL) {
155+
// An EINVAL error is fine, because it means that the
156+
// rootfs is not really a mountpoint. This could be the case when
157+
// using urunc directly from its cli and the rootfs is a normal
158+
// directory
159+
uniklog.Errorf("could not set propagation flag as shared for container's rootfs: %v", err)
160+
return err
161+
}
162+
139163
u.State.Status = specs.StateCreating
140164
// FIXME: should we really create this base dir
141-
err := os.MkdirAll(u.BaseDir, 0o755)
165+
err = os.MkdirAll(u.BaseDir, 0o755)
142166
if err != nil {
143167
return err
144168
}

0 commit comments

Comments
 (0)