Skip to content

Commit

Permalink
Merge pull request #19039 from wanyaoqi/automated-cherry-pick-of-#190…
Browse files Browse the repository at this point in the history
…37-upstream-master

Automated cherry pick of #19037: fix(host): usb device hotplug
  • Loading branch information
zexi authored Dec 18, 2023
2 parents ce7dc3b + 75f0338 commit b6a1f9d
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pkg/hostman/guestman/guesttasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ func (t *SGuestIsolatedDeviceSyncTask) addDevice(dev *desc.SGuestIsolatedDevice)
}
}

opts, err := devObj.GetHotPlugOptions(dev)
opts, err := devObj.GetHotPlugOptions(dev, t.guest.Desc)
if err != nil {
cb(errors.Wrap(err, "GetHotPlugOptions").Error())
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/hostman/guestman/qemu/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ func GetNicDeviceModel(name string) string {
}

func generateUsbDeviceOption(usbControllerId string, usb *desc.UsbDevice) string {
cmd := fmt.Sprintf("-device %s,bus=%s.0", usb.DevType, usbControllerId)
cmd := fmt.Sprintf("-device %s,bus=%s.0,id=%s", usb.DevType, usbControllerId, usb.Id)
cmd += desc.OptionsToString(usb.Options)
return cmd
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/hostman/isolated_device/isolated_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ type IDevice interface {
GetMdevId() string
GetNVIDIAVgpuProfile() map[string]string

GetHotPlugOptions(isolatedDev *desc.SGuestIsolatedDevice) ([]*HotPlugOption, error)
GetHotPlugOptions(isolatedDev *desc.SGuestIsolatedDevice, guestDesc *desc.SGuestDesc) ([]*HotPlugOption, error)
GetHotUnplugOptions(isolatedDev *desc.SGuestIsolatedDevice) ([]*HotUnplugOption, error)

// Get extra PCIE information
Expand Down Expand Up @@ -639,7 +639,7 @@ func (dev *sBaseDevice) CustomProbe(idx int) error {
return nil
}

func (dev *sBaseDevice) GetHotPlugOptions(isolatedDev *desc.SGuestIsolatedDevice) ([]*HotPlugOption, error) {
func (dev *sBaseDevice) GetHotPlugOptions(isolatedDev *desc.SGuestIsolatedDevice, guestDesc *desc.SGuestDesc) ([]*HotPlugOption, error) {
ret := make([]*HotPlugOption, 0)

var masterDevOpt *HotPlugOption
Expand Down
2 changes: 1 addition & 1 deletion pkg/hostman/isolated_device/nvidia_vgpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (dev *sNVIDIAVgpuDevice) GetQemuId() string {
return "dev_" + dev.mdevId
}

func (dev *sNVIDIAVgpuDevice) GetHotPlugOptions(isolatedDev *desc.SGuestIsolatedDevice) ([]*HotPlugOption, error) {
func (dev *sNVIDIAVgpuDevice) GetHotPlugOptions(isolatedDev *desc.SGuestIsolatedDevice, guestDesc *desc.SGuestDesc) ([]*HotPlugOption, error) {
ret := make([]*HotPlugOption, 0)

var masterDevOpt *HotPlugOption
Expand Down
4 changes: 3 additions & 1 deletion pkg/hostman/isolated_device/usb.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,13 @@ func (dev *sUSBDevice) GetPassthroughCmd(index int) string {
return opt
}

func (dev *sUSBDevice) GetHotPlugOptions(*desc.SGuestIsolatedDevice) ([]*HotPlugOption, error) {
func (dev *sUSBDevice) GetHotPlugOptions(isolatedDev *desc.SGuestIsolatedDevice, guestDesc *desc.SGuestDesc) ([]*HotPlugOption, error) {
opts, err := GetUSBDevQemuOptions(dev.dev.GetVendorDeviceId(), dev.dev.Addr)
if err != nil {
return nil, errors.Wrap(err, "GetUSBDevQemuOptions")
}
opts["id"] = isolatedDev.Usb.Id
opts["bus"] = fmt.Sprintf("%s.0", guestDesc.Usb.Id)
return []*HotPlugOption{
{
Device: "usb-host",
Expand Down

0 comments on commit b6a1f9d

Please sign in to comment.