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

Function MountsToLayer

internal/erofsutils/mount.go:147–189  ·  view source on GitHub ↗

MountsToLayer returns the snapshot layer directory in order to generate EROFS-formatted blobs; The candidate will be checked with ".erofslayer" to make sure this active snapshot is really generated by the EROFS snapshotter instead of others.

(mounts []mount.Mount)

Source from the content-addressed store, hash-verified

145// The candidate will be checked with ".erofslayer" to make sure this active
146// snapshot is really generated by the EROFS snapshotter instead of others.
147func MountsToLayer(mounts []mount.Mount) (string, error) {
148 var layer string
149
150 // If mount[0].Type is prefixed with "mkfs/", it should be always the snapshot layer
151 if strings.HasPrefix(mounts[0].Type, "mkfs/") {
152 layer = filepath.Dir(mounts[0].Source)
153 } else {
154 // Otherwise, let's check the last mount entry
155 mnt := mounts[len(mounts)-1]
156 mt := strings.Split(mnt.Type, "/")
157
158 switch mt[len(mt)-1] {
159 case "bind", "erofs":
160 layer = filepath.Dir(mnt.Source)
161 case "overlay":
162 var topLower string
163 for _, o := range mnt.Options {
164 if k, v, ok := strings.Cut(o, "="); ok {
165 switch k {
166 case "upperdir":
167 layer = filepath.Dir(v)
168 case "lowerdir":
169 // Use the first mount source for the top lower layer
170 topLower = filepath.Dir(mounts[0].Source)
171 }
172 }
173 }
174 if layer == "" {
175 if topLower == "" {
176 return "", fmt.Errorf("unsupported overlay layer for erofs differ: %w", errdefs.ErrNotImplemented)
177 }
178 layer = topLower
179 }
180 default:
181 return "", fmt.Errorf("invalid filesystem type %q for erofs differ: %w", mnt.Type, errdefs.ErrNotImplemented)
182 }
183 }
184 // If the layer is not prepared by the EROFS snapshotter, fall back to the next differ
185 if _, err := os.Stat(filepath.Join(layer, ".erofslayer")); err != nil {
186 return "", fmt.Errorf("mount layer type must be erofs-layer: %w", errdefs.ErrNotImplemented)
187 }
188 return layer, nil
189}
190
191// SupportGenerateFromTar checks if the installed version of mkfs.erofs supports
192// the tar mode (--tar option).

Callers 2

CompareMethod · 0.92
ApplyMethod · 0.92

Calls 2

DirMethod · 0.80
StatMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…