Skip to content

Commit

Permalink
Merge pull request #19084 from wanyaoqi/automated-cherry-pick-of-#190…
Browse files Browse the repository at this point in the history
…82-upstream-master

Automated cherry pick of #19082: fix(host-deployer): check executor is enabled on init qemu driver
  • Loading branch information
zexi authored Dec 22, 2023
2 parents e240b2f + 01dc0e6 commit f2f5359
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pkg/hostman/diskutils/kvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func NewKVMGuestDisk(imageInfo qemuimg.SImageInfo, driver string, readOnly bool)
}
err = img.CreateQcow2(0, false, imageInfo.Path, imageInfo.Password, imageInfo.EncryptFormat, imageInfo.EncryptAlg)
if err != nil {
log.Errorf("fail to create overlay qcow2 for kvm disk readonly access")
log.Errorf("fail to create overlay qcow2 for kvm disk readonly access: %s", err)
return nil, errors.Wrap(err, "CreateQcow2")
}
originImage = imagePath
Expand Down
38 changes: 20 additions & 18 deletions pkg/hostman/diskutils/qemu_kvm/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ func (m *QemuDeployManager) runOnHost() bool {
return m.qemuCmd != QEMU_KVM_PATH
}

func (m *QemuDeployManager) startQemu(cmd string) ([]byte, error) {
if m.runOnHost() {
return procutils.NewRemoteCommandAsFarAsPossible("bash", "-c", cmd).Output()
} else {
return procutils.NewCommand("bash", "-c", cmd).Output()
}
}

func (m *QemuDeployManager) GetX86InitrdPath() string {
if m.runOnHost() {
return path.Join(RUN_ON_HOST_ROOT_PATH, X86_INITRD_PATH)
Expand Down Expand Up @@ -171,15 +179,23 @@ func tryCleanGuest(hmpPath string) {
}
}

func InitQemuDeployManager(cpuArch, qemuVersion string, hugepage bool, hugepageSizeKB int, deployConcurrent int) error {
func InitQemuDeployManager(
cpuArch, qemuVersion string,
enableRemoteExecutor, hugepage bool,
hugepageSizeKB, deployConcurrent int,
) error {
if deployConcurrent <= 0 {
deployConcurrent = 10
}

if cpuArch == OS_ARCH_AARCH64 {
qemutils.UseAarch64()
}
qemuCmd := qemutils.GetQemu(qemuVersion)

var qemuCmd string
if enableRemoteExecutor {
qemuCmd = qemutils.GetQemu(qemuVersion)
}
if qemuCmd == "" {
qemuCmd = QEMU_KVM_PATH
}
Expand Down Expand Up @@ -624,14 +640,7 @@ func (d *QemuX86Driver) StartGuest(sshPort, ncpu, memSizeMB int, hugePage bool,
cmd += __("-device ide-cd,drive=ide0-cd0,bus=ide.1")

log.Infof("start guest %s", cmd)

var out []byte
var err error
if manager.runOnHost() {
out, err = procutils.NewRemoteCommandAsFarAsPossible("bash", "-c", cmd).Output()
} else {
out, err = procutils.NewCommand("bash", "-c", cmd).Output()
}
out, err := manager.startQemu(cmd)
if err != nil {
log.Errorf("failed start guest %s: %s", out, err)
return errors.Wrapf(err, "failed start guest %s", out)
Expand Down Expand Up @@ -707,14 +716,7 @@ func (d *QemuARMDriver) StartGuest(sshPort, ncpu, memSizeMB int, hugePage bool,
cmd += __("-device scsi-cd,drive=cd0,share-rw=true")

log.Infof("start guest %s", cmd)

var out []byte
var err error
if manager.runOnHost() {
out, err = procutils.NewRemoteCommandAsFarAsPossible("bash", "-c", cmd).Output()
} else {
out, err = procutils.NewCommand("bash", "-c", cmd).Output()
}
out, err := manager.startQemu(cmd)
if err != nil {
log.Errorf("failed start guest %s: %s", out, err)
return errors.Wrapf(err, "failed start guest %s", out)
Expand Down
1 change: 1 addition & 0 deletions pkg/hostman/hostdeployer/deployserver/deployserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ func (s *SDeployService) PrepareEnv() error {
err = qemu_kvm.InitQemuDeployManager(
strings.TrimSpace(string(cpuArch)),
DeployOption.DefaultQemuVersion,
DeployOption.EnableRemoteExecutor,
DeployOption.HugepagesOption == "native",
DeployOption.HugepageSizeMb*1024,
DeployOption.DeployConcurrent,
Expand Down
4 changes: 4 additions & 0 deletions pkg/util/qemuimg/qemuimg.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,10 @@ func (img *SQemuImage) CreateQcow2(sizeMB int, compact bool, backPath string, pa
} else {
extraArgs = append(extraArgs, "-b", backPath)
}
if len(string(backQemu.Format)) > 0 {
extraArgs = append(extraArgs, "-F", string(backQemu.Format))
}

if !compact {
options = append(options, "cluster_size=2M")
}
Expand Down

0 comments on commit f2f5359

Please sign in to comment.