Skip to content

Commit

Permalink
feat(host): mount post_overlay with metacopy feature (#21880)
Browse files Browse the repository at this point in the history
  • Loading branch information
zexi authored Dec 23, 2024
1 parent d9e3d2d commit 2466219
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 3 additions & 1 deletion pkg/hostman/container/volume_mount/disk/post_overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 19 additions & 1 deletion pkg/util/mountutils/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 2466219

Please sign in to comment.