Skip to content

Commit 5a566b9

Browse files
csweichelroboquat
authored andcommitted
[ws-daemon] Umount dangling mask mounts
1 parent cfe4284 commit 5a566b9

File tree

1 file changed

+41
-0
lines changed
  • components/ws-daemon/pkg/iws

1 file changed

+41
-0
lines changed

components/ws-daemon/pkg/iws/iws.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,13 @@ func (wbs *InWorkspaceServiceServer) MountProc(ctx context.Context, req *api.Mou
358358
return nil, err
359359
}
360360

361+
// now that we've moved the mount (which we've done with OPEN_TREE_CLONE), we'll
362+
// need to unmount the mask mounts again to not leave them dangling.
363+
var masks []string
364+
masks = append(masks, procDefaultMaskedPaths...)
365+
masks = append(masks, procDefaultReadonlyPaths...)
366+
cleanupMaskedMount(wbs.Session.OWI(), nodeStaging, masks)
367+
361368
return &api.MountProcResponse{}, nil
362369
}
363370

@@ -571,6 +578,8 @@ func (wbs *InWorkspaceServiceServer) MountSysfs(ctx context.Context, req *api.Mo
571578
return nil, err
572579
}
573580

581+
cleanupMaskedMount(wbs.Session.OWI(), nodeStaging, sysfsDefaultMaskedPaths)
582+
574583
return &api.MountProcResponse{}, nil
575584
}
576585

@@ -594,6 +603,38 @@ func moveMount(instanceID string, targetPid int, source, target string) error {
594603
return nil
595604
}
596605

606+
// cleanupMaskedMount will unmount and remove the paths joined with the basedir.
607+
// Errors are logged instead of returned.
608+
// This is useful for when we've moved the mount (which we've done with OPEN_TREE_CLONE), we'll
609+
// need to unmount the mask mounts again to not leave them dangling.
610+
func cleanupMaskedMount(owi map[string]interface{}, base string, paths []string) {
611+
for _, mask := range paths {
612+
// Note: if errors happen while unmounting or removing the masks this does not mean
613+
// that the final unmount won't happen. I.e. we can ignore those errors here
614+
// because they would not be actionable anyways. Only if the final removal or
615+
// unmount fails did we leak a mount.
616+
617+
fn := filepath.Join(base, mask)
618+
err := unix.Unmount(fn, 0)
619+
if err != nil {
620+
continue
621+
}
622+
_ = os.RemoveAll(fn)
623+
}
624+
625+
err := unix.Unmount(base, 0)
626+
if err != nil {
627+
log.WithError(err).WithField("fn", base).WithFields(owi).Warn("cannot unmount dangling base mount")
628+
return
629+
}
630+
631+
err = os.RemoveAll(base)
632+
if err != nil {
633+
log.WithError(err).WithField("fn", base).WithFields(owi).Warn("cannot remove dangling base mount")
634+
return
635+
}
636+
}
637+
597638
type nsinsiderOpts struct {
598639
MountNS bool
599640
PidNS bool

0 commit comments

Comments
 (0)