mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #10286 from zexi/hotfix/windows-umount-leak
fix(hostdeployer): windows rootfs umount leak
This commit is contained in:
@@ -24,7 +24,7 @@ type IDisk interface {
|
||||
Connect() error
|
||||
Disconnect() error
|
||||
MountRootfs() fsdriver.IRootFsDriver
|
||||
UmountRootfs(driver fsdriver.IRootFsDriver)
|
||||
UmountRootfs(driver fsdriver.IRootFsDriver) error
|
||||
ResizePartition() error
|
||||
}
|
||||
|
||||
|
||||
@@ -110,17 +110,18 @@ func (d *SKVMGuestDisk) MountKvmRootfsReadOnly() fsdriver.IRootFsDriver {
|
||||
return d.mountKvmRootfs(true)
|
||||
}
|
||||
|
||||
func (d *SKVMGuestDisk) UmountKvmRootfs(fd fsdriver.IRootFsDriver) {
|
||||
func (d *SKVMGuestDisk) UmountKvmRootfs(fd fsdriver.IRootFsDriver) error {
|
||||
if part := fd.GetPartition(); part != nil {
|
||||
part.Umount()
|
||||
return part.Umount()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *SKVMGuestDisk) UmountRootfs(fd fsdriver.IRootFsDriver) {
|
||||
func (d *SKVMGuestDisk) UmountRootfs(fd fsdriver.IRootFsDriver) error {
|
||||
if fd == nil {
|
||||
return
|
||||
return nil
|
||||
}
|
||||
d.UmountKvmRootfs(fd)
|
||||
return d.UmountKvmRootfs(fd)
|
||||
}
|
||||
|
||||
func (d *SKVMGuestDisk) MakePartition(fs string) error {
|
||||
|
||||
@@ -162,11 +162,11 @@ func (vd *VDDKDisk) MountRootfs() fsdriver.IRootFsDriver {
|
||||
return vd.kvmDisk.MountRootfs()
|
||||
}
|
||||
|
||||
func (vd *VDDKDisk) UmountRootfs(fd fsdriver.IRootFsDriver) {
|
||||
func (vd *VDDKDisk) UmountRootfs(fd fsdriver.IRootFsDriver) error {
|
||||
if vd.kvmDisk == nil {
|
||||
return
|
||||
return nil
|
||||
}
|
||||
vd.kvmDisk.UmountRootfs(fd)
|
||||
return vd.kvmDisk.UmountRootfs(fd)
|
||||
}
|
||||
|
||||
func (vd *VDDKDisk) ParsePartitions(buf string) error {
|
||||
@@ -435,18 +435,18 @@ type VDDKPartition struct {
|
||||
}
|
||||
|
||||
func (vp *VDDKPartition) Mount() bool {
|
||||
log.Debugf("VDDKPartition.Mount not implement")
|
||||
log.Warningf("VDDKPartition.Mount not implement")
|
||||
return true
|
||||
}
|
||||
|
||||
func (vp *VDDKPartition) MountPartReadOnly() bool {
|
||||
log.Debugf("VDDKPartition.MountPartReadOnly not implement")
|
||||
log.Warningf("VDDKPartition.MountPartReadOnly not implement")
|
||||
return true
|
||||
}
|
||||
|
||||
func (vp *VDDKPartition) Umount() bool {
|
||||
log.Debugf("VDDKPartition.Umount not implement")
|
||||
return true
|
||||
func (vp *VDDKPartition) Umount() error {
|
||||
log.Warningf("VDDKPartition.Umount not implement")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (vp *VDDKPartition) IsReadonly() bool {
|
||||
@@ -454,7 +454,7 @@ func (vp *VDDKPartition) IsReadonly() bool {
|
||||
}
|
||||
|
||||
func (vp *VDDKPartition) GetPhysicalPartitionType() string {
|
||||
log.Debugf("VDDKPartition.GetPhysicalPartitionType not implement")
|
||||
log.Warningf("VDDKPartition.GetPhysicalPartitionType not implement")
|
||||
return ""
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ type IDiskPartition interface {
|
||||
IsMounted() bool
|
||||
Mount() bool
|
||||
MountPartReadOnly() bool
|
||||
Umount() bool
|
||||
Umount() error
|
||||
GetMountPath() string
|
||||
IsReadonly() bool
|
||||
GetPhysicalPartitionType() string
|
||||
|
||||
@@ -156,22 +156,25 @@ func (d *SGuestfishDiskPartition) MountPartReadOnly() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (d *SGuestfishDiskPartition) Umount() bool {
|
||||
if d.IsMounted() {
|
||||
var tries = 0
|
||||
for tries < 10 {
|
||||
tries += 1
|
||||
output, err := procutils.NewCommand("umount", d.GetMountPath()).Output()
|
||||
if err != nil {
|
||||
log.Errorf("failed umount %s: %s %s", d.GetMountPath(), output, err)
|
||||
time.Sleep(time.Second * 1)
|
||||
} else {
|
||||
d.mounted = false
|
||||
return true
|
||||
}
|
||||
func (d *SGuestfishDiskPartition) Umount() error {
|
||||
if !d.IsMounted() {
|
||||
return nil
|
||||
}
|
||||
|
||||
var tries = 0
|
||||
var err error
|
||||
for tries < 10 {
|
||||
tries += 1
|
||||
output, err := procutils.NewCommand("umount", d.GetMountPath()).Output()
|
||||
if err != nil {
|
||||
err = errors.Wrapf(err, "failed umount %s: %s %s", d.GetMountPath(), output, err)
|
||||
time.Sleep(time.Second * 1)
|
||||
} else {
|
||||
d.mounted = false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return false
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *SGuestfishDiskPartition) IsReadonly() bool {
|
||||
|
||||
@@ -134,7 +134,7 @@ func (p *SKVMGuestDiskPartition) Mount() bool {
|
||||
p.readonly = true
|
||||
}
|
||||
}
|
||||
log.Infof("mount fs %s on %s success", p.fs, p.partDev)
|
||||
log.Infof("mount fs %s on %s successfully", p.fs, p.partDev)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -245,29 +245,37 @@ func (p *SKVMGuestDiskPartition) IsMounted() bool {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *SKVMGuestDiskPartition) Umount() bool {
|
||||
if p.IsMounted() {
|
||||
var tries = 0
|
||||
for tries < 10 {
|
||||
tries += 1
|
||||
_, err := procutils.NewCommand("umount", p.mountPath).Output()
|
||||
if err == nil {
|
||||
if p.fs == "xfs" {
|
||||
uuids := fileutils2.GetDevUuid(p.partDev)
|
||||
uuid := uuids["UUID"]
|
||||
if len(uuid) > 0 {
|
||||
UnlockXfsPartition(uuid)
|
||||
}
|
||||
func (p *SKVMGuestDiskPartition) Umount() error {
|
||||
if !p.IsMounted() {
|
||||
return nil
|
||||
}
|
||||
|
||||
var tries = 0
|
||||
var err error
|
||||
for tries < 10 {
|
||||
tries += 1
|
||||
_, err = procutils.NewCommand("umount", p.mountPath).Output()
|
||||
if err == nil {
|
||||
if p.fs == "xfs" {
|
||||
uuids := fileutils2.GetDevUuid(p.partDev)
|
||||
uuid := uuids["UUID"]
|
||||
if len(uuid) > 0 {
|
||||
UnlockXfsPartition(uuid)
|
||||
}
|
||||
procutils.NewCommand("blockdev", "--flushbufs", p.partDev).Output()
|
||||
os.Remove(p.mountPath)
|
||||
return true
|
||||
} else {
|
||||
time.Sleep(time.Second * 1)
|
||||
}
|
||||
if _, err := procutils.NewCommand("blockdev", "--flushbufs", p.partDev).Output(); err != nil {
|
||||
log.Warningf("blockdev --flushbufs %s error: %v", p.partDev, err)
|
||||
}
|
||||
if err := os.Remove(p.mountPath); err != nil {
|
||||
log.Warningf("remove mount path %s error: %v", p.mountPath)
|
||||
}
|
||||
log.Infof("umount %s successfully", p.partDev)
|
||||
return nil
|
||||
} else {
|
||||
time.Sleep(time.Second * 1)
|
||||
}
|
||||
}
|
||||
return false
|
||||
return errors.Wrapf(err, "umount %s", p.mountPath)
|
||||
}
|
||||
|
||||
func (p *SKVMGuestDiskPartition) Zerofree() {
|
||||
|
||||
@@ -162,10 +162,10 @@ func (p *SSHPartition) Mount() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (p *SSHPartition) Umount() bool {
|
||||
func (p *SSHPartition) Umount() error {
|
||||
if !p.IsMounted() {
|
||||
log.Errorf("%s is not mounted", p.mountPath)
|
||||
return false
|
||||
log.Warningf("%s is not mounted", p.mountPath)
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
for tries := 0; tries < 10; tries++ {
|
||||
@@ -182,13 +182,12 @@ func (p *SSHPartition) Umount() bool {
|
||||
time.Sleep(1 * time.Second)
|
||||
} else {
|
||||
if err := p.osRmDir(p.mountPath); err != nil {
|
||||
log.Errorf("remove mount path %s: %v", p.mountPath, err)
|
||||
return false
|
||||
log.Warningf("remove mount path %s: %v", p.mountPath, err)
|
||||
}
|
||||
return true
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return err == nil
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *SSHPartition) IsMounted() bool {
|
||||
|
||||
@@ -116,15 +116,29 @@ func (*DeployerServer) ResizeFs(ctx context.Context, req *deployapi.ResizeFsPara
|
||||
return new(deployapi.Empty), errors.Wrap(err, "disk connect failed")
|
||||
}
|
||||
|
||||
unmount := func(root fsdriver.IRootFsDriver) error {
|
||||
if err := disk.UmountRootfs(root); err != nil {
|
||||
return errors.Wrap(err, "unmount rootfs")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
root := disk.MountRootfs()
|
||||
if root != nil && !root.IsResizeFsPartitionSupport() {
|
||||
if err := unmount(root); err != nil {
|
||||
return new(deployapi.Empty), err
|
||||
}
|
||||
return new(deployapi.Empty), errors.ErrNotSupported
|
||||
}
|
||||
|
||||
// must umount rootfs before resize partition
|
||||
disk.UmountRootfs(root)
|
||||
err = disk.ResizePartition()
|
||||
return new(deployapi.Empty), err
|
||||
if err := unmount(root); err != nil {
|
||||
return new(deployapi.Empty), err
|
||||
}
|
||||
if err := disk.ResizePartition(); err != nil {
|
||||
return new(deployapi.Empty), errors.Wrap(err, "resize disk partition")
|
||||
}
|
||||
return new(deployapi.Empty), nil
|
||||
}
|
||||
|
||||
func (*DeployerServer) FormatFs(ctx context.Context, req *deployapi.FormatFsParams) (*deployapi.Empty, error) {
|
||||
|
||||
@@ -22,10 +22,9 @@ import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
@@ -155,7 +154,9 @@ func (d *SLocalDisk) Resize(ctx context.Context, params interface{}) (jsonutils.
|
||||
// d.Fallocate()
|
||||
}
|
||||
|
||||
d.ResizeFs(d.GetPath())
|
||||
if err := d.ResizeFs(d.GetPath()); err != nil {
|
||||
return nil, errors.Wrapf(err, "resize fs %s", d.GetPath())
|
||||
}
|
||||
|
||||
return d.GetDiskDesc(), nil
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
@@ -124,7 +125,10 @@ func (d *SRBDDisk) Resize(ctx context.Context, params interface{}) (jsonutils.JS
|
||||
return nil, err
|
||||
}
|
||||
|
||||
d.ResizeFs(d.GetPath())
|
||||
if err := d.ResizeFs(d.GetPath()); err != nil {
|
||||
return nil, errors.Wrapf(err, "resize fs %s", d.GetPath())
|
||||
}
|
||||
|
||||
return d.GetDiskDesc(), nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user