mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-30 17:13:08 +08:00
fix(host): add options enabel vendor/device pt usb dev (#25347)
* fix(host): add options enabel vendor/device pt usb dev * fix(host): add audio device for spice driver
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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"`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user