feat(host): mount post_overlay with metacopy feature (#21880)

This commit is contained in:
Zexi Li
2024-12-23 20:13:15 +08:00
committed by GitHub
parent d9e3d2df25
commit 2466219139
2 changed files with 22 additions and 2 deletions
@@ -161,7 +161,9 @@ func (d diskPostOverlay) mountPostOverlay(pod volume_mount.IPodInfo, ctrId strin
return errors.Wrapf(err, "get post overlay mountpoint for container %s", ctrId)
}
return mountutils.MountOverlay(ov.HostLowerDir, upperDir, workDir, mergedDir)
return mountutils.MountOverlayWithFeatures(ov.HostLowerDir, upperDir, workDir, mergedDir, &mountutils.MountOverlayFeatures{
MetaCopy: true,
})
}
func (d diskPostOverlay) unmountPostOverlay(pod volume_mount.IPodInfo, ctrId string, vm *hostapi.ContainerVolumeMount, ov *apis.ContainerVolumeMountDiskPostOverlay, useLazy bool, cleanLayers bool) error {
+19 -1
View File
@@ -56,10 +56,28 @@ func Mount(devPath string, mountPoint string, fsType string) error {
}
func MountOverlay(lowerDir []string, upperDir string, workDir string, mergedDir string) error {
return mountOverlay(lowerDir, upperDir, workDir, mergedDir, nil)
}
type MountOverlayFeatures struct {
MetaCopy bool
}
func MountOverlayWithFeatures(lowerDir []string, upperDir string, workDir string, mergedDir string, features *MountOverlayFeatures) error {
return mountOverlay(lowerDir, upperDir, workDir, mergedDir, features)
}
func mountOverlay(lowerDir []string, upperDir string, workDir string, mergedDir string, features *MountOverlayFeatures) error {
return mountWrap(mergedDir, func() error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
overlayArgs := []string{"-t", "overlay", "overlay", "-o", fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s", strings.Join(lowerDir, ":"), upperDir, workDir), mergedDir}
optStr := fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s", strings.Join(lowerDir, ":"), upperDir, workDir)
if features != nil {
if features.MetaCopy {
optStr += ",metacopy=on"
}
}
overlayArgs := []string{"-t", "overlay", "overlay", "-o", optStr, mergedDir}
if out, err := procutils.NewRemoteCommandContextAsFarAsPossible(ctx, "mount", overlayArgs...).Output(); err != nil {
return errors.Wrapf(err, "mount %v: %s", overlayArgs, out)
}