mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/yunionio/cloudpods.git
synced 2026-09-20 08:03:53 +08:00
feat(region,host): custom usb controller type
support usb controller type: qemu-xhci, usb-ehci. qemu-xhci is much more virtualization-friendly when compared to EHCI and UHCI. but guest supports XHCI which should be the case for any operating system released around 2010 or later. So sometimes wo need use usb controller type EHCI. Signed-off-by: wanyaoqi <d3lx.yq@gmail.com>
This commit is contained in:
@@ -685,10 +685,11 @@ func init() {
|
||||
})
|
||||
|
||||
type ServerQemuParams struct {
|
||||
ID string `help:"ID or name of VM"`
|
||||
DisableIsaSerial string `help:"disable isa serial device" choices:"true|false"`
|
||||
DisablePvpanic string `help:"disable pvpanic device" choices:"true|false"`
|
||||
DisableUsbKbd string `help:"disable usb kbd" choices:"true|false"`
|
||||
ID string `help:"ID or name of VM"`
|
||||
DisableIsaSerial string `help:"disable isa serial device" choices:"true|false"`
|
||||
DisablePvpanic string `help:"disable pvpanic device" choices:"true|false"`
|
||||
DisableUsbKbd string `help:"disable usb kbd" choices:"true|false"`
|
||||
UsbControllerType string `help:"usb controller type" choices:"usb-ehci|qemu-xhci"`
|
||||
}
|
||||
|
||||
R(&ServerQemuParams{}, "server-set-qemu-params", "config qemu params", func(s *mcclient.ClientSession,
|
||||
@@ -703,6 +704,9 @@ func init() {
|
||||
if len(opts.DisableUsbKbd) > 0 {
|
||||
params.Set("disable_usb_kbd", jsonutils.NewString(opts.DisableUsbKbd))
|
||||
}
|
||||
if len(opts.UsbControllerType) > 0 {
|
||||
params.Set("usb_controller_type", jsonutils.NewString(opts.UsbControllerType))
|
||||
}
|
||||
result, err := modules.Servers.PerformAction(s, opts.ID, "set-qemu-params", params)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -3249,6 +3249,13 @@ func (self *SGuest) PerformSetQemuParams(ctx context.Context, userCred mcclient.
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
usbContType, err := data.GetString("usb_controller_type")
|
||||
if err == nil {
|
||||
err = self.SetMetadata(ctx, "usb_controller_type", usbContType, userCred)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -200,12 +200,15 @@ func (s *SKVMGuestInstance) initRandomDevice(pciRoot *desc.PCIController) {
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) initUsbController(pciRoot *desc.PCIController) {
|
||||
contType := s.getUsbControllerType()
|
||||
s.Desc.Usb = &desc.UsbController{
|
||||
PCIDevice: desc.NewPCIDevice(pciRoot.CType, " qemu-xhci", "usb"),
|
||||
PCIDevice: desc.NewPCIDevice(pciRoot.CType, contType, "usb"),
|
||||
}
|
||||
s.Desc.Usb.Options = map[string]string{
|
||||
"p2": "8", // usb2 port count
|
||||
"p3": "8", // usb3 port count
|
||||
if contType == "qemu-xhci" {
|
||||
s.Desc.Usb.Options = map[string]string{
|
||||
"p2": "8", // usb2 port count
|
||||
"p3": "8", // usb3 port count
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -99,6 +99,15 @@ func (s *SKVMGuestInstance) setPcieExtendBus() {
|
||||
s.Desc.Metadata["__pcie_extend_bus"] = "true"
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) getUsbControllerType() string {
|
||||
usbContType := s.Desc.Metadata["usb_controller_type"]
|
||||
if usbContType == "usb-ehci" {
|
||||
return usbContType
|
||||
} else {
|
||||
return "qemu-xhci"
|
||||
}
|
||||
}
|
||||
|
||||
// is windows prioer to windows server 2003
|
||||
func (s *SKVMGuestInstance) isOldWindows() bool {
|
||||
if s.getOsname() == OS_NAME_WINDOWS {
|
||||
|
||||
Reference in New Issue
Block a user