diff --git a/pkg/hostman/guestman/desc/desc.go b/pkg/hostman/guestman/desc/desc.go index 7dabd7b4b3..b9865b2f6f 100644 --- a/pkg/hostman/guestman/desc/desc.go +++ b/pkg/hostman/guestman/desc/desc.go @@ -266,12 +266,19 @@ type SGuestRng struct { type SoundCard struct { *PCIDevice `json:",omitempty"` Codec *Codec + Audio *AudioDev +} + +type AudioDev struct { + Id string + Type string } type Codec struct { - Id string - Type string - Cad int + Id string + Type string + Cad int + AudioDev string } type SSpiceDesc struct { diff --git a/pkg/hostman/guestman/pci.go b/pkg/hostman/guestman/pci.go index a7a4feadf4..1992976808 100644 --- a/pkg/hostman/guestman/pci.go +++ b/pkg/hostman/guestman/pci.go @@ -531,9 +531,14 @@ func (s *SKVMGuestInstance) initSpiceDevices(pciRoot *desc.PCIController) { spice.IntelHDA = &desc.SoundCard{ PCIDevice: desc.NewPCIDevice(pciRoot.CType, "intel-hda", "sound0"), Codec: &desc.Codec{ - Id: "sound0-codec0", - Type: "hda-duplex", - Cad: 0, + Id: "sound0-codec0", + Type: "hda-duplex", + Cad: 0, + AudioDev: "audio0", + }, + Audio: &desc.AudioDev{ + Id: "audio0", + Type: "spice", }, } var ehciId = "usbspice" diff --git a/pkg/hostman/guestman/qemu/generate.go b/pkg/hostman/guestman/qemu/generate.go index b6662ab389..a51abb2834 100644 --- a/pkg/hostman/guestman/qemu/generate.go +++ b/pkg/hostman/guestman/qemu/generate.go @@ -92,10 +92,14 @@ func generateSpiceOptions(port uint, spice *desc.SSpiceDesc) []string { // intel-hda and codec hda-duplex opts = append(opts, generatePCIDeviceOption(spice.IntelHDA.PCIDevice)) codec := spice.IntelHDA.Codec - opts = append(opts, - fmt.Sprintf("-device %s,id=%s,bus=%s.0,cad=%d", - codec.Type, codec.Id, spice.IntelHDA.Id, codec.Cad), - ) + codecOpts := fmt.Sprintf("-device %s,id=%s,bus=%s.0,cad=%d", codec.Type, codec.Id, spice.IntelHDA.Id, codec.Cad) + if spice.IntelHDA.Audio != nil { + opts = append(opts, + fmt.Sprintf("-audiodev %s,id=%s", spice.IntelHDA.Audio.Type, spice.IntelHDA.Audio.Id), + ) + codecOpts = fmt.Sprintf("%s,audiodev=%s", codecOpts, spice.IntelHDA.Audio.Id) + } + opts = append(opts, codecOpts) // serial port opts = append(opts, generatePCIDeviceOption(spice.VdagentSerial.PCIDevice)) diff --git a/pkg/hostman/isolated_device/usb.go b/pkg/hostman/isolated_device/usb.go index d311650e8d..c197356c2e 100644 --- a/pkg/hostman/isolated_device/usb.go +++ b/pkg/hostman/isolated_device/usb.go @@ -26,6 +26,7 @@ import ( api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/hostman/guestman/desc" + "yunion.io/x/onecloud/pkg/hostman/options" "yunion.io/x/onecloud/pkg/util/regutils2" ) @@ -69,6 +70,21 @@ func GetUSBDevId(vendorId, devId, bus, addr string) string { } func getUSBDevQemuOptions(vendorId, deviceId string, bus, addr, port string) (map[string]interface{}, error) { + vendorIDI, err := strconv.ParseUint(vendorId, 16, 32) + if err != nil { + return nil, errors.Wrapf(err, "parse vendor ID %q", vendorId) + } + productIDI, err := strconv.ParseUint(deviceId, 16, 32) + if err != nil { + return nil, errors.Wrapf(err, "parse product ID %q", deviceId) + } + if !options.HostOptions.DisablePassthroughWithVendorDeviceId { + return map[string]interface{}{ + "vendorid": uint32(vendorIDI), + "productid": uint32(productIDI), + }, nil + } + // id := GetUSBDevId(vendorId, deviceId, bus, addr) busI, err := strconv.Atoi(bus) if err != nil { @@ -85,14 +101,6 @@ func getUSBDevQemuOptions(vendorId, deviceId string, bus, addr, port string) (ma }, nil } - vendorIDI, err := strconv.ParseUint(vendorId, 16, 32) - if err != nil { - return nil, errors.Wrapf(err, "parse vendor ID %q", vendorId) - } - productIDI, err := strconv.ParseUint(deviceId, 16, 32) - if err != nil { - return nil, errors.Wrapf(err, "parse product ID %q", deviceId) - } return map[string]interface{}{ // "id": id, // "bus": "usb.0", diff --git a/pkg/hostman/isolated_device/usb_test.go b/pkg/hostman/isolated_device/usb_test.go index d64dabffba..c928c4d5d1 100644 --- a/pkg/hostman/isolated_device/usb_test.go +++ b/pkg/hostman/isolated_device/usb_test.go @@ -171,8 +171,8 @@ func Test_getUSBDevQemuOptions(t *testing.T) { want: map[string]interface{}{ "vendorid": uint32(0x1d6b), "productid": uint32(0x0001), - "hostbus": uint64(1), - "hostaddr": uint64(9), + //"hostbus": uint64(1), + //"hostaddr": uint64(9), }, }, } diff --git a/pkg/hostman/options/options.go b/pkg/hostman/options/options.go index a4b8d11371..537571a30d 100644 --- a/pkg/hostman/options/options.go +++ b/pkg/hostman/options/options.go @@ -220,14 +220,15 @@ type SHostOptions struct { DisableKVM bool `help:"force disable KVM" default:"false" json:"disable_kvm"` - DisableGPU bool `help:"force disable GPU detect" default:"false" json:"disable_gpu"` - DisableCustomDevice bool `help:"force disable custom pci device detect" default:"false" json:"disable_custom_device"` - DisableUSB bool `help:"force disable USB detect" default:"true" json:"disable_usb"` - SRIOVNics []string `help:"nics enable sriov" json:"sriov_nics"` - OvsOffloadNics []string `help:"nics enable ovs offload" json:"ovs_offload_nics"` - PTNVMEConfigs []string `help:"passthrough nvme disk pci address and size"` - AMDVgpuPFs []string `help:"amd vgpu pf pci addresses"` - NVIDIAVgpuPFs []string `help:"nvidia vgpu pf pci addresses"` + DisableGPU bool `help:"force disable GPU detect" default:"false" json:"disable_gpu"` + DisableCustomDevice bool `help:"force disable custom pci device detect" default:"false" json:"disable_custom_device"` + DisableUSB bool `help:"force disable USB detect" default:"true" json:"disable_usb"` + DisablePassthroughWithVendorDeviceId bool `help:"disable usb passthrough with vendor device id" default:"false" json:"disable_passthrough_with_vendor_device_id"` + SRIOVNics []string `help:"nics enable sriov" json:"sriov_nics"` + OvsOffloadNics []string `help:"nics enable ovs offload" json:"ovs_offload_nics"` + PTNVMEConfigs []string `help:"passthrough nvme disk pci address and size"` + AMDVgpuPFs []string `help:"amd vgpu pf pci addresses"` + NVIDIAVgpuPFs []string `help:"nvidia vgpu pf pci addresses"` EthtoolEnableGso bool `help:"use ethtool to turn on or off GSO(generic segment offloading)" default:"true" json:"ethtool_enable_gso"`