diff --git a/pkg/hostman/guestman/qemu/generate.go b/pkg/hostman/guestman/qemu/generate.go index 08ed1a97ff..732da95e79 100644 --- a/pkg/hostman/guestman/qemu/generate.go +++ b/pkg/hostman/guestman/qemu/generate.go @@ -178,10 +178,18 @@ func generateMemoryOption(memDesc *desc.SGuestMem) string { return strings.Join(cmds, " ") } -func generateMachineOption(machine string, machineDesc *desc.SGuestMachine) string { - cmd := fmt.Sprintf("-machine %s,accel=%s", machine, machineDesc.Accel) - if machineDesc.GicVersion != nil { - cmd += fmt.Sprintf(",gic-version=%s", *machineDesc.GicVersion) +func generateMachineOption(drvOpt QemuOptions, desc *desc.SGuestDesc) string { + cmd := fmt.Sprintf("-machine %s,accel=%s", desc.Machine, desc.MachineDesc.Accel) + if desc.MachineDesc.GicVersion != nil { + cmd += fmt.Sprintf(",gic-version=%s", *desc.MachineDesc.GicVersion) + } + if desc.NoHpet != nil && *desc.NoHpet { + machineOpts, noHpetCmd := drvOpt.NoHpet() + if machineOpts { + cmd += fmt.Sprintf(",%s", noHpetCmd) + } else if noHpetCmd != "" { + cmd += fmt.Sprintf(" %s", noHpetCmd) + } } return cmd @@ -714,9 +722,6 @@ func GenerateStartOptions( opts = append(opts, getMonitorOptions(drvOpt, input.QMPMonitor)...) } - if input.GuestDesc.NoHpet != nil && *input.GuestDesc.NoHpet { - opts = append(opts, drvOpt.NoHpet()) - } opts = append(opts, drvOpt.RTC(), // drvOpt.Daemonize(), @@ -724,7 +729,7 @@ func GenerateStartOptions( drvOpt.Nodefconfig(), // drvOpt.NoKVMPitReinjection(), drvOpt.Global(), - generateMachineOption(input.GuestDesc.Machine, input.GuestDesc.MachineDesc), + generateMachineOption(drvOpt, input.GuestDesc), drvOpt.KeyboardLayoutLanguage("en-us"), generateSMPOption(input.GuestDesc), drvOpt.Name(input.GuestDesc.Name), diff --git a/pkg/hostman/guestman/qemu/qemu.go b/pkg/hostman/guestman/qemu/qemu.go index 84c410f3bb..306d3ac3cf 100644 --- a/pkg/hostman/guestman/qemu/qemu.go +++ b/pkg/hostman/guestman/qemu/qemu.go @@ -33,6 +33,7 @@ const ( Version_4_2_0 Version = "4.2.0" Version_4_0_1 Version = "4.0.1" Version_2_12_1 Version = "2.12.1" + Version_9_0_1 Version = "9.0.1" ) type Arch string @@ -87,7 +88,7 @@ type QemuOptions interface { Daemonize() string Nodefaults() string Nodefconfig() string - NoHpet() string + NoHpet() (bool, string) Global() string KeyboardLayoutLanguage(lang string) string Name(name string) string @@ -208,8 +209,8 @@ func (o baseOptions) Nodefaults() string { return "-nodefaults" } -func (o baseOptions) NoHpet() string { - return "-no-hpet" +func (o baseOptions) NoHpet() (bool, string) { + return false, "-no-hpet" } func (o baseOptions) Nodefconfig() string { @@ -356,6 +357,30 @@ func newBaseOptions_x86_64() *baseOptions_x86_64 { } } +// qemu version grate or equal 8.0.0 +type baseOptions_ge_800_x86_64 struct { +} + +func (o baseOptions_ge_800_x86_64) NoHpet() (bool, string) { + return true, "hpet=off" +} + +func newBaseOptionsGE800_x86_64() *baseOptions_ge_800_x86_64 { + return &baseOptions_ge_800_x86_64{} +} + +// qemu version grate or equal 3.1.0 +type baseOptions_ge_310 struct { +} + +func (o baseOptions_ge_310) Nodefconfig() string { + return "-no-user-config" +} + +func newBaseOptionsGE310() *baseOptions_ge_310 { + return &baseOptions_ge_310{} +} + type baseOptions_aarch64 struct { *baseOptions } @@ -370,6 +395,6 @@ func (o baseOptions_aarch64) Global() string { return "" } -func (o baseOptions_aarch64) NoHpet() string { - return "" +func (o baseOptions_aarch64) NoHpet() (bool, string) { + return false, "" } diff --git a/pkg/hostman/guestman/qemu/v4_0_1.go b/pkg/hostman/guestman/qemu/v4_0_1.go index b8239d63b0..337371df2c 100644 --- a/pkg/hostman/guestman/qemu/v4_0_1.go +++ b/pkg/hostman/guestman/qemu/v4_0_1.go @@ -30,18 +30,16 @@ func newCmd_4_0_1_x86_64() QemuCommand { type opt_401_x86_64 struct { *baseOptions_x86_64 + *baseOptions_ge_310 } func newOpt_4_0_1_x86_64() QemuOptions { return &opt_401_x86_64{ baseOptions_x86_64: newBaseOptions_x86_64(), + baseOptions_ge_310: newBaseOptionsGE310(), } } -func (o opt_401_x86_64) Nodefconfig() string { - return "-no-user-config" -} - func newCmd_4_0_1_aarch64() QemuCommand { return newBaseCommand( Version_4_0_1, @@ -51,14 +49,12 @@ func newCmd_4_0_1_aarch64() QemuCommand { type opt_401_aarch64 struct { *baseOptions_aarch64 + *baseOptions_ge_310 } func newOpt_4_0_1_aarch64() QemuOptions { return &opt_401_aarch64{ baseOptions_aarch64: newBaseOptions_aarch64(), + baseOptions_ge_310: newBaseOptionsGE310(), } } - -func (o opt_401_aarch64) Nodefconfig() string { - return "-no-user-config" -} diff --git a/pkg/hostman/guestman/qemu/v4_2_0.go b/pkg/hostman/guestman/qemu/v4_2_0.go index f856c55c4e..d2b9c410df 100644 --- a/pkg/hostman/guestman/qemu/v4_2_0.go +++ b/pkg/hostman/guestman/qemu/v4_2_0.go @@ -30,18 +30,16 @@ func newCmd_4_2_0_x86_64() QemuCommand { type opt_420_x86_64 struct { *baseOptions_x86_64 + *baseOptions_ge_310 } func newOpt_4_2_0_x86_64() QemuOptions { return &opt_420_x86_64{ baseOptions_x86_64: newBaseOptions_x86_64(), + baseOptions_ge_310: newBaseOptionsGE310(), } } -func (o opt_420_x86_64) Nodefconfig() string { - return "-no-user-config" -} - func newCmd_4_2_0_aarch64() QemuCommand { return newBaseCommand( Version_4_2_0, @@ -51,14 +49,12 @@ func newCmd_4_2_0_aarch64() QemuCommand { type opt_420_aarch64 struct { *baseOptions_aarch64 + *baseOptions_ge_310 } func newOpt_4_2_0_aarch64() QemuOptions { return &opt_420_aarch64{ baseOptions_aarch64: newBaseOptions_aarch64(), + baseOptions_ge_310: newBaseOptionsGE310(), } } - -func (o opt_420_aarch64) Nodefconfig() string { - return "-no-user-config" -} diff --git a/pkg/hostman/guestman/qemu/v9_0_1.go b/pkg/hostman/guestman/qemu/v9_0_1.go new file mode 100644 index 0000000000..a5534685b7 --- /dev/null +++ b/pkg/hostman/guestman/qemu/v9_0_1.go @@ -0,0 +1,68 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package qemu + +func init() { + RegisterCmd( + newCmd_9_0_1_x86_64(), + newCmd_9_0_1_aarch64(), + ) +} + +func newOpt_9_0_1_x86_64() QemuOptions { + return &opt_901_x86_64{ + baseOptions_x86_64: newBaseOptions_x86_64(), + baseOptions_ge_800_x86_64: newBaseOptionsGE800_x86_64(), + baseOptions_ge_310: newBaseOptionsGE310(), + } +} + +func newCmd_9_0_1_x86_64() QemuCommand { + return newBaseCommand( + Version_9_0_1, + Arch_x86_64, + newOpt_9_0_1_x86_64(), + ) +} + +type opt_901_x86_64 struct { + *baseOptions_x86_64 + *baseOptions_ge_800_x86_64 + *baseOptions_ge_310 +} + +func (o opt_901_x86_64) NoHpet() (bool, string) { + return true, "hpet=off" +} + +func newCmd_9_0_1_aarch64() QemuCommand { + return newBaseCommand( + Version_9_0_1, + Arch_aarch64, + newOpt_9_0_1_aarch64(), + ) +} + +type opt_901_aarch64 struct { + *baseOptions_aarch64 + *baseOptions_ge_310 +} + +func newOpt_9_0_1_aarch64() QemuOptions { + return &opt_901_aarch64{ + baseOptions_aarch64: newBaseOptions_aarch64(), + baseOptions_ge_310: newBaseOptionsGE310(), + } +}