MCPcopy Index your code
hub / github.com/containerd/containerd / UnmountRecursive

Function UnmountRecursive

core/mount/mount_unix.go:33–74  ·  view source on GitHub ↗

UnmountRecursive unmounts the target and all mounts underneath, starting with the deepest mount first.

(target string, flags int)

Source from the content-addressed store, hash-verified

31// UnmountRecursive unmounts the target and all mounts underneath, starting
32// with the deepest mount first.
33func UnmountRecursive(target string, flags int) error {
34 if target == "" {
35 return nil
36 }
37
38 target, err := CanonicalizePath(target)
39 if err != nil {
40 if os.IsNotExist(err) {
41 err = nil
42 }
43 return err
44 }
45
46 mounts, err := mountinfo.GetMounts(mountinfo.PrefixFilter(target))
47 if err != nil {
48 return err
49 }
50
51 targetSet := make(map[string]struct{})
52 for _, m := range mounts {
53 targetSet[m.Mountpoint] = struct{}{}
54 }
55
56 var targets []string
57 for m := range targetSet {
58 targets = append(targets, m)
59 }
60
61 // Make the deepest mount be first
62 sort.SliceStable(targets, func(i, j int) bool {
63 return len(targets[i]) > len(targets[j])
64 })
65
66 for i, target := range targets {
67 if err := UnmountAll(target, flags); err != nil {
68 if i == len(targets)-1 { // last mount
69 return err
70 }
71 }
72 }
73 return nil
74}
75
76func unmount(target string, flags int) error {
77 if isFUSE(target) {

Callers 2

TestUnmountRecursiveFunction · 0.70
doPrepareIDMappedOverlayFunction · 0.70

Calls 3

CanonicalizePathFunction · 0.85
UnmountAllFunction · 0.70
GetMountsMethod · 0.65

Tested by 1

TestUnmountRecursiveFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…