MCPcopy
hub / github.com/containerd/containerd / compactLowerdirOption

Function compactLowerdirOption

core/mount/mount_linux.go:408–442  ·  view source on GitHub ↗

compactLowerdirOption updates overlay lowdir option and returns the common dir among all the lowdirs.

(opts []string)

Source from the content-addressed store, hash-verified

406// compactLowerdirOption updates overlay lowdir option and returns the common
407// dir among all the lowdirs.
408func compactLowerdirOption(opts []string) (string, []string) {
409 idx, dirs := findOverlayLowerdirs(opts)
410 if idx == -1 || len(dirs) == 1 {
411 // no need to compact if there is only one lowerdir
412 return "", opts
413 }
414
415 // find out common dir
416 commondir := longestCommonPrefix(dirs)
417 if commondir == "" {
418 return "", opts
419 }
420
421 // NOTE: the snapshot id is based on digits.
422 // in order to avoid to get snapshots/x, should be back to parent dir.
423 // however, there is assumption that the common dir is ${root}/io.containerd.v1.overlayfs/snapshots.
424 commondir = path.Dir(commondir)
425 if commondir == "/" || commondir == "." {
426 return "", opts
427 }
428 commondir = commondir + "/"
429
430 newdirs := make([]string, 0, len(dirs))
431 for _, dir := range dirs {
432 if len(dir) <= len(commondir) {
433 return "", opts
434 }
435 newdirs = append(newdirs, dir[len(commondir):])
436 }
437
438 newopts := copyOptions(opts)
439 newopts = append(newopts[:idx], newopts[idx+1:]...)
440 newopts = append(newopts, fmt.Sprintf("lowerdir=%s", strings.Join(newdirs, ":")))
441 return commondir, newopts
442}
443
444// findOverlayLowerdirs returns the index of lowerdir in mount's options and
445// all the lowerdir target.

Callers 2

mountMethod · 0.85

Calls 4

findOverlayLowerdirsFunction · 0.85
longestCommonPrefixFunction · 0.85
copyOptionsFunction · 0.85
DirMethod · 0.80

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…