fix(host): hide kvm only gpu guests (#16974)

Signed-off-by: wanyaoqi <d3lx.yq@gmail.com>
This commit is contained in:
wanyaoqi
2023-05-09 14:45:09 +08:00
committed by GitHub
parent df9e407216
commit 444db7e42e
3 changed files with 20 additions and 5 deletions
+1
View File
@@ -40,6 +40,7 @@ type KVMGuestInstance interface {
CpuMax() (uint, error)
IsNestedVirt() bool
IsKvmSupport() bool
HideKVM() bool
}
func NewArch(arch string) Arch {
+1 -5
View File
@@ -128,11 +128,7 @@ func (*X86) enableHypervFeatures(features map[string]bool) {
}
func (x86 *X86) GenerateCpuDesc(cpus uint, cpuMax uint, s KVMGuestInstance) (*desc.SGuestCpu, error) {
var hideKVM = true
if s.IsNestedVirt() {
hideKVM = false
}
var hideKVM = s.HideKVM()
var hostCPUPassthrough = options.HostOptions.HostCpuPassthrough
var isCPUIntel = sysutils.IsProcessorIntel()
var isCPUAMD = sysutils.IsProcessorAmd()
+18
View File
@@ -130,6 +130,13 @@ func (s *SKVMGuestInstance) GetKernelVersion() string {
return s.manager.host.GetKernelVersion()
}
func (s *SKVMGuestInstance) HideKVM() bool {
if s.hasGPU() {
return true
}
return false
}
func (s *SKVMGuestInstance) CpuMax() (uint, error) {
cpuMax, ok := s.manager.qemuMachineCpuMax[s.Desc.Machine]
if !ok {
@@ -786,6 +793,17 @@ func (s *SKVMGuestInstance) gpusHasVga() bool {
return false
}
func (s *SKVMGuestInstance) hasGPU() bool {
manager := s.manager.GetHost().GetIsolatedDeviceManager()
for i := 0; i < len(s.Desc.IsolatedDevices); i++ {
dev := manager.GetDeviceByAddr(s.Desc.IsolatedDevices[i].Addr)
if dev.GetDeviceType() == api.GPU_VGA_TYPE || dev.GetDeviceType() == api.GPU_HPC_TYPE {
return true
}
}
return false
}
func (s *SKVMGuestInstance) initCpuDesc(cpuMax uint) error {
var err error
s.fixGuestMachineType()