Skip to content

Automated cherry pick of #22425: fix(host): lvm disk create from esxi #22426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pkg/hostman/guestfs/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,12 @@ func DoDeployGuestFs(rootfs fsdriver.IRootFsDriver, guestDesc *deployapi.GuestDe
}

if err := rootfs.DeployHostname(partition, hn, domain); err != nil {
return nil, errors.Wrap(err, "DeployHostname")
//return nil, errors.Wrap(err, "DeployHostname")
log.Errorf("DeployHostname failed %s", err)
}
if err := rootfs.DeployHosts(partition, hn, domain, ips); err != nil {
return nil, errors.Wrap(err, "DeployHosts")
//return nil, errors.Wrap(err, "DeployHosts")
log.Errorf("DeployHosts failed %s", err)
}

if guestDesc.Hypervisor == comapi.HYPERVISOR_KVM {
Expand Down
21 changes: 20 additions & 1 deletion pkg/hostman/storageman/disk_lvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/cloudcommon/consts"
deployapi "yunion.io/x/onecloud/pkg/hostman/hostdeployer/apis"
"yunion.io/x/onecloud/pkg/hostman/hostdeployer/deployclient"
"yunion.io/x/onecloud/pkg/hostman/hostutils"
"yunion.io/x/onecloud/pkg/hostman/storageman/lvmutils"
"yunion.io/x/onecloud/pkg/hostman/storageman/storageutils"
Expand Down Expand Up @@ -112,11 +113,19 @@ func (d *SLVMDisk) CreateRaw(ctx context.Context, sizeMB int, diskFormat string,

img, err := qemuimg.NewQemuImage(d.GetPath())
if err != nil {
log.Errorln(err)
log.Errorf("NewQemuImage failed %s %s", d.GetPath(), err)
return nil, err
}

qcow2Size := lvmutils.GetQcow2LvSize(int64(sizeMB))
if sizeMB <= 0 && back != "" {
backImg, err := qemuimg.NewQemuImage(back)
if err != nil {
log.Errorf("NewQemuImage failed %s %s", back, err)
return nil, err
}
qcow2Size = lvmutils.GetQcow2LvSize(int64(backImg.GetSizeMB()))
}
err = lvmutils.LvCreate(d.Storage.GetPath(), d.Id, qcow2Size*1024*1024)
if err != nil {
return nil, errors.Wrap(err, "CreateRaw")
Expand Down Expand Up @@ -146,6 +155,16 @@ func (d *SLVMDisk) CreateRaw(ctx context.Context, sizeMB int, diskFormat string,
}

func (d *SLVMDisk) Delete(ctx context.Context, params interface{}) (jsonutils.JSONObject, error) {
p := params.(api.DiskDeleteInput)
if p.EsxiFlatFilePath != "" {
connections := &deployapi.EsxiDisksConnectionInfo{Disks: []*deployapi.EsxiDiskInfo{{DiskPath: p.EsxiFlatFilePath}}}
_, err := deployclient.GetDeployClient().DisconnectEsxiDisks(ctx, connections)
if err != nil {
log.Errorf("Disconnect %s esxi disks failed %s", p.EsxiFlatFilePath, err)
return nil, err
}
}

if err := lvmutils.LvRemove(d.GetLvPath()); err != nil {
return nil, errors.Wrap(err, "Delete lvremove")
}
Expand Down
9 changes: 7 additions & 2 deletions pkg/hostman/storageman/disk_slvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package storageman
import (
"context"
"path"
"strings"

"yunion.io/x/cloudmux/pkg/cloudprovider"
"yunion.io/x/jsonutils"
Expand Down Expand Up @@ -61,14 +62,16 @@ func (d *SSLVMDisk) Probe() error {
}

diskPath := d.GetPath()
storageBasePath := path.Join("/dev", d.Storage.GetPath())
for diskPath != "" {
qemuImg, err := qemuimg.NewQemuImage(diskPath)
if err != nil {
log.Errorln(err)
return err
}
diskPath = qemuImg.BackFilePath
if qemuImg.BackFilePath != "" {

if qemuImg.BackFilePath != "" && strings.HasPrefix(qemuImg.BackFilePath, storageBasePath) {
diskPath = qemuImg.BackFilePath
originActivated, err := lvmutils.LvIsActivated(qemuImg.BackFilePath)
if err != nil {
return errors.Wrap(err, "check lv is activated")
Expand All @@ -78,6 +81,8 @@ func (d *SSLVMDisk) Probe() error {
return errors.Wrap(err, "lv active origin")
}
}
} else {
diskPath = ""
}
}

Expand Down