mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
feat(region,host): support lazy umount for post overlay of container (#21813)
This commit is contained in:
@@ -271,5 +271,6 @@ type ContainerVolumeMountAddPostOverlayInput struct {
|
||||
type ContainerVolumeMountRemovePostOverlayInput struct {
|
||||
Index int `json:"index"`
|
||||
PostOverlay []*apis.ContainerVolumeMountDiskPostOverlay `json:"post_overlay"`
|
||||
UseLazy bool `json:"use_lazy"`
|
||||
ClearLayers bool `json:"clear_layers"`
|
||||
}
|
||||
|
||||
@@ -55,5 +55,5 @@ func Mount(devPath string, mountPoint string, fsType string) error {
|
||||
}
|
||||
|
||||
func Unmount(devPath string) error {
|
||||
return mountutils.Unmount(devPath)
|
||||
return mountutils.Unmount(devPath, false)
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ type IVolumeMountDisk interface {
|
||||
volume_mount.IUsageVolumeMount
|
||||
|
||||
MountPostOverlays(pod volume_mount.IPodInfo, ctrId string, vm *hostapi.ContainerVolumeMount, ovs []*apis.ContainerVolumeMountDiskPostOverlay) error
|
||||
UnmountPostOverlays(pod volume_mount.IPodInfo, ctrId string, vm *hostapi.ContainerVolumeMount, ovs []*apis.ContainerVolumeMountDiskPostOverlay, clearLayers bool) error
|
||||
UnmountPostOverlays(pod volume_mount.IPodInfo, ctrId string, vm *hostapi.ContainerVolumeMount, ovs []*apis.ContainerVolumeMountDiskPostOverlay, useLazy bool, clearLayers bool) error
|
||||
|
||||
GetHostDiskRootPath(pod volume_mount.IPodInfo, vm *hostapi.ContainerVolumeMount) (string, error)
|
||||
|
||||
@@ -237,7 +237,7 @@ func (d disk) Unmount(pod volume_mount.IPodInfo, ctrId string, vm *hostapi.Conta
|
||||
return errors.Wrap(err, "get disk storage driver")
|
||||
}
|
||||
if len(vm.Disk.PostOverlay) != 0 {
|
||||
if err := d.UnmountPostOverlays(pod, ctrId, vm, vm.Disk.PostOverlay, false); err != nil {
|
||||
if err := d.UnmountPostOverlays(pod, ctrId, vm, vm.Disk.PostOverlay, false, false); err != nil {
|
||||
return errors.Wrap(err, "mount post overlay dirs")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,8 +35,8 @@ func (d disk) MountPostOverlays(pod volume_mount.IPodInfo, ctrId string, vm *hos
|
||||
return d.newPostOverlay().mountPostOverlays(pod, ctrId, vm, ovs)
|
||||
}
|
||||
|
||||
func (d disk) UnmountPostOverlays(pod volume_mount.IPodInfo, ctrId string, vm *hostapi.ContainerVolumeMount, ovs []*apis.ContainerVolumeMountDiskPostOverlay, clearLayers bool) error {
|
||||
return d.newPostOverlay().unmountPostOverlays(pod, ctrId, vm, ovs, clearLayers)
|
||||
func (d disk) UnmountPostOverlays(pod volume_mount.IPodInfo, ctrId string, vm *hostapi.ContainerVolumeMount, ovs []*apis.ContainerVolumeMountDiskPostOverlay, useLazy bool, clearLayers bool) error {
|
||||
return d.newPostOverlay().unmountPostOverlays(pod, ctrId, vm, ovs, useLazy, clearLayers)
|
||||
}
|
||||
|
||||
func (d disk) getPostOverlayRootPrefixDir(prefixDir string, pod volume_mount.IPodInfo, vm *hostapi.ContainerVolumeMount, ctrId string) (string, error) {
|
||||
@@ -61,7 +61,7 @@ func (d disk) GetPostOverlayRootUpperDir(pod volume_mount.IPodInfo, vm *hostapi.
|
||||
|
||||
type iDiskPostOverlay interface {
|
||||
mountPostOverlays(pod volume_mount.IPodInfo, ctrId string, vm *hostapi.ContainerVolumeMount, ovs []*apis.ContainerVolumeMountDiskPostOverlay) error
|
||||
unmountPostOverlays(pod volume_mount.IPodInfo, ctrId string, vm *hostapi.ContainerVolumeMount, ovs []*apis.ContainerVolumeMountDiskPostOverlay, clearLayers bool) error
|
||||
unmountPostOverlays(pod volume_mount.IPodInfo, ctrId string, vm *hostapi.ContainerVolumeMount, ovs []*apis.ContainerVolumeMountDiskPostOverlay, useLazy bool, clearLayers bool) error
|
||||
}
|
||||
|
||||
type diskPostOverlay struct {
|
||||
@@ -83,9 +83,9 @@ func (d diskPostOverlay) mountPostOverlays(pod volume_mount.IPodInfo, ctrId stri
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d diskPostOverlay) unmountPostOverlays(pod volume_mount.IPodInfo, ctrId string, vm *hostapi.ContainerVolumeMount, ovs []*apis.ContainerVolumeMountDiskPostOverlay, clearLayers bool) error {
|
||||
func (d diskPostOverlay) unmountPostOverlays(pod volume_mount.IPodInfo, ctrId string, vm *hostapi.ContainerVolumeMount, ovs []*apis.ContainerVolumeMountDiskPostOverlay, useLazy bool, clearLayers bool) error {
|
||||
for _, ov := range ovs {
|
||||
if err := d.unmountPostOverlay(pod, ctrId, vm, ov, clearLayers); err != nil {
|
||||
if err := d.unmountPostOverlay(pod, ctrId, vm, ov, useLazy, clearLayers); err != nil {
|
||||
return errors.Wrapf(err, "unmount container %s post overlay dir: %#v", ctrId, ov)
|
||||
}
|
||||
}
|
||||
@@ -164,12 +164,12 @@ func (d diskPostOverlay) mountPostOverlay(pod volume_mount.IPodInfo, ctrId strin
|
||||
return mountutils.MountOverlay(ov.HostLowerDir, upperDir, workDir, mergedDir)
|
||||
}
|
||||
|
||||
func (d diskPostOverlay) unmountPostOverlay(pod volume_mount.IPodInfo, ctrId string, vm *hostapi.ContainerVolumeMount, ov *apis.ContainerVolumeMountDiskPostOverlay, cleanLayers bool) error {
|
||||
func (d diskPostOverlay) unmountPostOverlay(pod volume_mount.IPodInfo, ctrId string, vm *hostapi.ContainerVolumeMount, ov *apis.ContainerVolumeMountDiskPostOverlay, useLazy bool, cleanLayers bool) error {
|
||||
mergedDir, err := d.getPostOverlayMountpoint(pod, ctrId, vm, ov)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "get post overlay mountpoint for container %s", ctrId)
|
||||
}
|
||||
if err := mountutils.Unmount(mergedDir); err != nil {
|
||||
if err := mountutils.Unmount(mergedDir, useLazy); err != nil {
|
||||
return errors.Wrapf(err, "unmount %s", mergedDir)
|
||||
}
|
||||
if cleanLayers {
|
||||
|
||||
@@ -2216,7 +2216,7 @@ func (s *sPodGuestInstance) DoSnapshot(ctx context.Context, params *SDiskSnapsho
|
||||
for _, vol := range vols {
|
||||
// unbind mount
|
||||
for _, povPath := range povTmpBackRootDir {
|
||||
if err := mountutils.Unmount(povPath); err != nil {
|
||||
if err := mountutils.Unmount(povPath, false); err != nil {
|
||||
return errors.Wrapf(err, "umount bind point %s", povTmpBackRootDir)
|
||||
}
|
||||
}
|
||||
@@ -2224,7 +2224,7 @@ func (s *sPodGuestInstance) DoSnapshot(ctx context.Context, params *SDiskSnapsho
|
||||
if vol.Disk.StorageSizeFile != "" {
|
||||
targetBindMntPath = filepath.Join(tmpBackRootDir, vol.Disk.StorageSizeFile)
|
||||
}
|
||||
if err := mountutils.Unmount(targetBindMntPath); err != nil {
|
||||
if err := mountutils.Unmount(targetBindMntPath, false); err != nil {
|
||||
return errors.Wrapf(err, "umount bind point %s", targetBindMntPath)
|
||||
}
|
||||
}
|
||||
@@ -2473,5 +2473,5 @@ func (s *sPodGuestInstance) RemoveContainerVolumeMountPostOverlay(ctx context.Co
|
||||
if err := drv.Mount(s, ctrId, vol); err != nil {
|
||||
return errors.Wrapf(err, "mount volume %s, ctrId %s", jsonutils.Marshal(vol), ctrId)
|
||||
}
|
||||
return diskDrv.UnmountPostOverlays(s, ctrId, vol, input.PostOverlay, input.ClearLayers)
|
||||
return diskDrv.UnmountPostOverlays(s, ctrId, vol, input.PostOverlay, input.UseLazy, input.ClearLayers)
|
||||
}
|
||||
|
||||
@@ -481,6 +481,7 @@ func (o *ContainerAddVolumeMountPostOverlayOptions) Params() (jsonutils.JSONObje
|
||||
type ContainerRemoveVolumeMountPostOverlayOptions struct {
|
||||
ContainerAddVolumeMountPostOverlayOptions
|
||||
ClearLayers bool `help:"clear overlay upper and work layers"`
|
||||
UseLazy bool `help:"use lazy umount"`
|
||||
}
|
||||
|
||||
func (o *ContainerRemoveVolumeMountPostOverlayOptions) Params() (jsonutils.JSONObject, error) {
|
||||
@@ -491,5 +492,8 @@ func (o *ContainerRemoveVolumeMountPostOverlayOptions) Params() (jsonutils.JSONO
|
||||
if o.ClearLayers {
|
||||
params.(*jsonutils.JSONDict).Add(jsonutils.JSONTrue, "clear_layers")
|
||||
}
|
||||
if o.UseLazy {
|
||||
params.(*jsonutils.JSONDict).Add(jsonutils.JSONTrue, "use_lazy")
|
||||
}
|
||||
return params, nil
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ func DetachAndRemoveDevice(devPath string) error {
|
||||
mntPoints := strings.Split(out, "\n")
|
||||
for _, mntPoint := range mntPoints {
|
||||
if mntPoint != "" {
|
||||
if err := mountutils.Unmount(mntPoint); err != nil {
|
||||
if err := mountutils.Unmount(mntPoint, false); err != nil {
|
||||
return errors.Wrapf(err, "umount %s of dev: %s, part: %s", mntPoint, dev.Name, part)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,7 +286,7 @@ func DetachDevice(devPath string) error {
|
||||
mntPoints := strings.Split(out, "\n")
|
||||
for _, mntPoint := range mntPoints {
|
||||
if mntPoint != "" {
|
||||
if err := mountutils.Unmount(mntPoint); err != nil {
|
||||
if err := mountutils.Unmount(mntPoint, false); err != nil {
|
||||
return errors.Wrapf(err, "umount %s of dev: %s, part: %s", mntPoint, dev.Name, part)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,8 +79,8 @@ func MountBind(src, target string) error {
|
||||
})
|
||||
}
|
||||
|
||||
func Unmount(mountPoint string) error {
|
||||
err := unmount(mountPoint)
|
||||
func Unmount(mountPoint string, useLazy bool) error {
|
||||
err := unmount(mountPoint, useLazy)
|
||||
errs := []error{}
|
||||
if err != nil {
|
||||
errs = append(errs, errors.Wrap(err, "umount firstly"))
|
||||
@@ -90,7 +90,7 @@ func Unmount(mountPoint string) error {
|
||||
errs = append(errs, errors.Wrapf(err, "clean process use mountpoint: %s", mountPoint))
|
||||
}
|
||||
// umount again
|
||||
if err := unmount(mountPoint); err != nil {
|
||||
if err := unmount(mountPoint, useLazy); err != nil {
|
||||
errs = append(errs, errors.Wrapf(err, "unmount %s after clean process using it", mountPoint))
|
||||
return errors.NewAggregate(errs)
|
||||
}
|
||||
@@ -102,10 +102,14 @@ func Unmount(mountPoint string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func unmount(mountPoint string) error {
|
||||
func unmount(mountPoint string, useLazy bool) error {
|
||||
mountOut, err := procutils.NewRemoteCommandAsFarAsPossible("mountpoint", mountPoint).Output()
|
||||
if err == nil {
|
||||
out, err := procutils.NewRemoteCommandAsFarAsPossible("umount", mountPoint).Output()
|
||||
args := []string{mountPoint}
|
||||
if useLazy {
|
||||
args = append([]string{"-l"}, args...)
|
||||
}
|
||||
out, err := procutils.NewRemoteCommandAsFarAsPossible("umount", args...).Output()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "umount %s failed %s", mountPoint, out)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user