mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-25 15:02:45 +00:00
runtime/device: Refactor hotplugVFIODevice() to have common exit path
hotplugVFIODevice() has several different paths depending if we're plugging into a root port or a PCIE<->PCI bridge and if we're using a regular or mediated VFIO device. We're going to want some common code on the successful exit path here, so refactor the function to allow that without duplication. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
8bc71105f4
commit
5c2af3e308
@ -1474,39 +1474,42 @@ func (q *qemu) hotplugVFIODevice(ctx context.Context, device *config.VFIODev, op
|
|||||||
|
|
||||||
switch device.Type {
|
switch device.Type {
|
||||||
case config.VFIODeviceNormalType:
|
case config.VFIODeviceNormalType:
|
||||||
return q.qmpMonitorCh.qmp.ExecuteVFIODeviceAdd(q.qmpMonitorCh.ctx, devID, device.BDF, device.Bus, romFile)
|
err = q.qmpMonitorCh.qmp.ExecuteVFIODeviceAdd(q.qmpMonitorCh.ctx, devID, device.BDF, device.Bus, romFile)
|
||||||
case config.VFIODeviceMediatedType:
|
case config.VFIODeviceMediatedType:
|
||||||
if utils.IsAPVFIOMediatedDevice(device.SysfsDev) {
|
if utils.IsAPVFIOMediatedDevice(device.SysfsDev) {
|
||||||
return q.qmpMonitorCh.qmp.ExecuteAPVFIOMediatedDeviceAdd(q.qmpMonitorCh.ctx, device.SysfsDev)
|
err = q.qmpMonitorCh.qmp.ExecuteAPVFIOMediatedDeviceAdd(q.qmpMonitorCh.ctx, device.SysfsDev)
|
||||||
|
} else {
|
||||||
|
err = q.qmpMonitorCh.qmp.ExecutePCIVFIOMediatedDeviceAdd(q.qmpMonitorCh.ctx, devID, device.SysfsDev, "", device.Bus, romFile)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("Incorrect VFIO device type found")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
addr, bridge, err := q.arch.addDeviceToBridge(ctx, devID, types.PCI)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
q.arch.removeDeviceFromBridge(devID)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
switch device.Type {
|
||||||
|
case config.VFIODeviceNormalType:
|
||||||
|
err = q.qmpMonitorCh.qmp.ExecutePCIVFIODeviceAdd(q.qmpMonitorCh.ctx, devID, device.BDF, addr, bridge.ID, romFile)
|
||||||
|
case config.VFIODeviceMediatedType:
|
||||||
|
if utils.IsAPVFIOMediatedDevice(device.SysfsDev) {
|
||||||
|
err = q.qmpMonitorCh.qmp.ExecuteAPVFIOMediatedDeviceAdd(q.qmpMonitorCh.ctx, device.SysfsDev)
|
||||||
|
} else {
|
||||||
|
err = q.qmpMonitorCh.qmp.ExecutePCIVFIOMediatedDeviceAdd(q.qmpMonitorCh.ctx, devID, device.SysfsDev, addr, bridge.ID, romFile)
|
||||||
}
|
}
|
||||||
return q.qmpMonitorCh.qmp.ExecutePCIVFIOMediatedDeviceAdd(q.qmpMonitorCh.ctx, devID, device.SysfsDev, "", device.Bus, romFile)
|
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("Incorrect VFIO device type found")
|
return fmt.Errorf("Incorrect VFIO device type found")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return err
|
||||||
addr, bridge, err := q.arch.addDeviceToBridge(ctx, devID, types.PCI)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
if err != nil {
|
|
||||||
q.arch.removeDeviceFromBridge(devID)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
switch device.Type {
|
|
||||||
case config.VFIODeviceNormalType:
|
|
||||||
return q.qmpMonitorCh.qmp.ExecutePCIVFIODeviceAdd(q.qmpMonitorCh.ctx, devID, device.BDF, addr, bridge.ID, romFile)
|
|
||||||
case config.VFIODeviceMediatedType:
|
|
||||||
if utils.IsAPVFIOMediatedDevice(device.SysfsDev) {
|
|
||||||
return q.qmpMonitorCh.qmp.ExecuteAPVFIOMediatedDeviceAdd(q.qmpMonitorCh.ctx, device.SysfsDev)
|
|
||||||
}
|
|
||||||
return q.qmpMonitorCh.qmp.ExecutePCIVFIOMediatedDeviceAdd(q.qmpMonitorCh.ctx, devID, device.SysfsDev, addr, bridge.ID, romFile)
|
|
||||||
default:
|
|
||||||
return fmt.Errorf("Incorrect VFIO device type found")
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
q.Logger().WithField("dev-id", devID).Info("Start hot-unplug VFIO device")
|
q.Logger().WithField("dev-id", devID).Info("Start hot-unplug VFIO device")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user