Skip to content

Commit 2857dca

Browse files
authored
fix(host,host-deployer): start deployer guest with all of disk (#21710)
1 parent d463a94 commit 2857dca

File tree

2 files changed

+46
-21
lines changed

2 files changed

+46
-21
lines changed

pkg/hostman/diskutils/qemu_kvm/driver.go

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -301,15 +301,19 @@ func (d *QemuKvmDriver) connect(guestDesc *apis.GuestDesc) error {
301301
var sshport = manager.GetSshFreePort()
302302
defer manager.unsetPort(sshport)
303303

304-
//if guestDesc != nil {
305-
// for i := range guestDesc.Disks {
306-
// disks = append(disks, guestDesc.Disks[i].Path)
307-
// }
308-
//} else {
309-
disks = append(disks, d.imageInfo.Path)
310-
//}
311-
312-
err := d.qemuArchDriver.StartGuest(sshport, ncpu, memSizeMB, manager.hugepage, manager.hugepageSizeKB, d.imageInfo)
304+
if guestDesc != nil && len(guestDesc.Disks) > 0 {
305+
for i := range guestDesc.Disks {
306+
disks = append(disks, guestDesc.Disks[i].Path)
307+
}
308+
} else {
309+
disks = append(disks, d.imageInfo.Path)
310+
}
311+
312+
err := d.qemuArchDriver.StartGuest(
313+
sshport, ncpu, memSizeMB,
314+
manager.hugepage, manager.hugepageSizeKB,
315+
d.imageInfo, disks,
316+
)
313317
if err != nil {
314318
return err
315319
}
@@ -609,7 +613,7 @@ func (d *QemuBaseDriver) CleanGuest() {
609613
}
610614

611615
func (d *QemuBaseDriver) startCmds(
612-
sshPort, ncpu, memSizeMB int, imageInfo qemuimg.SImageInfo,
616+
sshPort, ncpu, memSizeMB int, imageInfo qemuimg.SImageInfo, disksPath []string,
613617
machineOpts, cdromDeviceOpts, fwOpts, socketPath, initrdPath, kernelPath string,
614618
) string {
615619
cmd := manager.qemuCmd
@@ -644,7 +648,10 @@ func (d *QemuBaseDriver) startCmds(
644648

645649
cmd += __("-object %s", imageInfo.SecretOptions())
646650
}
647-
for i, diskPath := range []string{imageInfo.Path} {
651+
if len(disksPath) == 0 {
652+
disksPath = []string{imageInfo.Path}
653+
}
654+
for i, diskPath := range disksPath {
648655
diskDrive := __("-drive file=%s,if=none,id=drive_%d,cache=none", diskPath, i)
649656
if imageInfo.Format != qemuimgfmt.RAW && imageInfo.Encrypted() {
650657
diskDrive += ",encrypt.format=luks,encrypt.key-secret=sec0"
@@ -663,7 +670,7 @@ type QemuX86Driver struct {
663670
QemuBaseDriver
664671
}
665672

666-
func (d *QemuX86Driver) StartGuest(sshPort, ncpu, memSizeMB int, hugePage bool, pageSizeKB int, imageInfo qemuimg.SImageInfo) error {
673+
func (d *QemuX86Driver) StartGuest(sshPort, ncpu, memSizeMB int, hugePage bool, pageSizeKB int, imageInfo qemuimg.SImageInfo, disksPath []string) error {
667674
uuid := stringutils.UUID4()
668675
socketPath := fmt.Sprintf("/opt/cloud/host-deployer/hmp_%s.socket", uuid)
669676
d.pidPath = fmt.Sprintf("/opt/cloud/host-deployer/%s.pid", uuid)
@@ -675,6 +682,7 @@ func (d *QemuX86Driver) StartGuest(sshPort, ncpu, memSizeMB int, hugePage bool,
675682
ncpu,
676683
memSizeMB,
677684
imageInfo,
685+
disksPath,
678686
machineOpts,
679687
cdromDeviceOpts,
680688
"",
@@ -717,7 +725,7 @@ type QemuARMDriver struct {
717725
QemuBaseDriver
718726
}
719727

720-
func (d *QemuARMDriver) StartGuest(sshPort, ncpu, memSizeMB int, hugePage bool, pageSizeKB int, imageInfo qemuimg.SImageInfo) error {
728+
func (d *QemuARMDriver) StartGuest(sshPort, ncpu, memSizeMB int, hugePage bool, pageSizeKB int, imageInfo qemuimg.SImageInfo, disksPath []string) error {
721729
uuid := stringutils.UUID4()
722730
socketPath := fmt.Sprintf("/opt/cloud/host-deployer/hmp_%s.socket", uuid)
723731
d.pidPath = fmt.Sprintf("/opt/cloud/host-deployer/%s.pid", uuid)
@@ -736,6 +744,7 @@ func (d *QemuARMDriver) StartGuest(sshPort, ncpu, memSizeMB int, hugePage bool,
736744
ncpu,
737745
memSizeMB,
738746
imageInfo,
747+
disksPath,
739748
machineOpts,
740749
cdromDeviceOpts,
741750
fwOpts,
@@ -775,7 +784,7 @@ func (d *QemuARMDriver) StartGuest(sshPort, ncpu, memSizeMB int, hugePage bool,
775784
}
776785

777786
type IQemuArchDriver interface {
778-
StartGuest(sshPort, ncpu, memSizeMB int, hugePage bool, pageSizeKB int, imageInfo qemuimg.SImageInfo) error
787+
StartGuest(sshPort, ncpu, memSizeMB int, hugePage bool, pageSizeKB int, imageInfo qemuimg.SImageInfo, disksPath []string) error
779788
CleanGuest()
780789
}
781790

pkg/hostman/guestman/qemu-kvm.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,6 +2092,9 @@ func (s *SKVMGuestInstance) StartGuest(ctx context.Context, userCred mcclient.To
20922092
}
20932093

20942094
func (s *SKVMGuestInstance) DeployFs(ctx context.Context, userCred mcclient.TokenCredential, deployInfo *deployapi.DeployInfo) (jsonutils.JSONObject, error) {
2095+
if len(s.Desc.Disks) == 0 {
2096+
return nil, fmt.Errorf("Guest dosen't have disk ??")
2097+
}
20952098
diskInfo := deployapi.DiskInfo{}
20962099
if s.isEncrypted() {
20972100
ekey, err := s.getEncryptKey(ctx, userCred)
@@ -2102,24 +2105,37 @@ func (s *SKVMGuestInstance) DeployFs(ctx context.Context, userCred mcclient.Toke
21022105
diskInfo.EncryptPassword = ekey.Key
21032106
diskInfo.EncryptAlg = string(ekey.Alg)
21042107
}
2108+
var sysDisk storageman.IDisk
21052109
disks := s.Desc.Disks
2106-
if len(disks) > 0 {
2107-
diskPath := disks[0].Path
2110+
for i := range disks {
2111+
diskPath := disks[i].Path
2112+
// GetDiskByPath will probe disks
21082113
disk, err := storageman.GetManager().GetDiskByPath(diskPath)
21092114
if err != nil {
21102115
return nil, errors.Wrapf(err, "GetDiskByPath(%s)", diskPath)
21112116
}
2112-
diskInfo.Path = disk.GetPath()
2113-
ret, err := disk.DeployGuestFs(&diskInfo, s.Desc, deployInfo)
2117+
if i == 0 {
2118+
// sys disk
2119+
diskInfo.Path = disk.GetPath()
2120+
sysDisk = disk
2121+
}
2122+
}
2123+
2124+
ret, err := sysDisk.DeployGuestFs(&diskInfo, s.Desc, deployInfo)
2125+
for i := range disks {
2126+
diskPath := disks[i].Path
2127+
disk, e := storageman.GetManager().GetDiskByPath(diskPath)
2128+
if e != nil {
2129+
log.Errorf("failed get disk bypath %s %s", diskPath, e)
2130+
}
21142131
if utils.IsInStringArray(disk.GetType(), []string{api.STORAGE_SLVM, api.STORAGE_CLVM}) {
21152132
if errDeactive := lvmutils.LVDeactivate(diskPath); err != nil {
21162133
log.Errorf("failed deactive disk %s: %s", diskPath, errDeactive)
21172134
}
21182135
}
2119-
return ret, err
2120-
} else {
2121-
return nil, fmt.Errorf("Guest dosen't have disk ??")
21222136
}
2137+
2138+
return ret, err
21232139
}
21242140

21252141
// Delay process

0 commit comments

Comments
 (0)