MCPcopy
hub / github.com/containerd/containerd / mount

Method mount

core/mount/mount_linux.go:80–219  ·  view source on GitHub ↗

Mount to the provided target path. If m.Type starts with "fuse." or "fuse3.", "mount.fuse" or "mount.fuse3" helper binary is called.

(target string)

Source from the content-addressed store, hash-verified

78// If m.Type starts with "fuse." or "fuse3.", "mount.fuse" or "mount.fuse3"
79// helper binary is called.
80func (m *Mount) mount(target string) (err error) {
81 for _, helperBinary := range allowedHelperBinaries {
82 // helperBinary = "mount.fuse", typePrefix = "fuse."
83 typePrefix := strings.TrimPrefix(helperBinary, "mount.") + "."
84 if strings.HasPrefix(m.Type, typePrefix) {
85 return m.mountWithHelper(helperBinary, typePrefix, target)
86 }
87 }
88 var (
89 chdir string
90 recalcOpt bool
91 usernsFd *os.File
92 options = m.Options
93 )
94
95 opt, err := parseMountOptions(options)
96 if err != nil {
97 return err
98 }
99 // The only remapping of both GID and UID is supported
100 if opt.uidmap != "" && opt.gidmap != "" {
101 if usernsFd, err = GetUsernsFD(opt.uidmap, opt.gidmap); err != nil {
102 return err
103 }
104 defer usernsFd.Close()
105
106 // overlay expects lowerdir's to be remapped instead
107 if m.Type == "overlay" {
108 var (
109 userNsCleanUp func()
110 )
111 options, userNsCleanUp, err = prepareIDMappedOverlay(int(usernsFd.Fd()), options)
112 if err != nil {
113 return fmt.Errorf("failed to prepare idmapped overlay: %w", err)
114 }
115 defer userNsCleanUp()
116
117 // To not meet concurrency issues while using the same lowedirs
118 // for different containers, replace them by temporary directories,
119 if optionsSize(options) >= pagesize-512 {
120 recalcOpt = true
121 } else {
122 opt, err = parseMountOptions(options)
123 if err != nil {
124 return err
125 }
126 }
127 }
128 }
129
130 // avoid hitting one page limit of mount argument buffer
131 //
132 // NOTE: 512 is a buffer during pagesize check.
133 if m.Type == "overlay" && optionsSize(options) >= pagesize-512 {
134 chdir, options = compactLowerdirOption(options)
135 // recalculate opt in case of lowerdirs have been replaced
136 // by idmapped ones OR idmapped mounts' not used/supported.
137 if recalcOpt || (opt.uidmap == "" || opt.gidmap == "") {

Callers 1

MountMethod · 0.95

Calls 14

mountWithHelperMethod · 0.95
parseMountOptionsFunction · 0.85
GetUsernsFDFunction · 0.85
prepareIDMappedOverlayFunction · 0.85
optionsSizeFunction · 0.85
compactLowerdirOptionFunction · 0.85
hasDirectIOFunction · 0.85
SetupLoopFunction · 0.85
mountAtFunction · 0.85
IDMapMountFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected