mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-29 12:14:48 +00:00
device: support vfio cold plug
Depending on ColdPlug flag, cold or hot plug vfio devices. The VFIO device won't be hot removed when such flag is false Signed-off-by: Julio Montes <julio.montes@intel.com>
This commit is contained in:
parent
3eb694c518
commit
66219d164f
@ -98,10 +98,20 @@ func (device *VFIODevice) Attach(devReceiver api.DeviceReceiver) (retErr error)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// hotplug a VFIO device is actually hotplugging a group of iommu devices
|
coldPlug := device.DeviceInfo.ColdPlug
|
||||||
if err := devReceiver.HotplugAddDevice(device, config.DeviceVFIO); err != nil {
|
deviceLogger().WithField("cold-plug", coldPlug).Info("Attaching VFIO device")
|
||||||
deviceLogger().WithError(err).Error("Failed to add device")
|
|
||||||
return err
|
if coldPlug {
|
||||||
|
if err := devReceiver.AppendDevice(device); err != nil {
|
||||||
|
deviceLogger().WithError(err).Error("Failed to append device")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// hotplug a VFIO device is actually hotplugging a group of iommu devices
|
||||||
|
if err := devReceiver.HotplugAddDevice(device, config.DeviceVFIO); err != nil {
|
||||||
|
deviceLogger().WithError(err).Error("Failed to add device")
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
deviceLogger().WithFields(logrus.Fields{
|
deviceLogger().WithFields(logrus.Fields{
|
||||||
@ -128,6 +138,15 @@ func (device *VFIODevice) Detach(devReceiver api.DeviceReceiver) (retErr error)
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
if device.GenericDevice.DeviceInfo.ColdPlug {
|
||||||
|
// nothing to detach, device was cold plugged
|
||||||
|
deviceLogger().WithFields(logrus.Fields{
|
||||||
|
"device-group": device.DeviceInfo.HostPath,
|
||||||
|
"device-type": "vfio-passthrough",
|
||||||
|
}).Info("Nothing to detach. VFIO device was cold plugged")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// hotplug a VFIO device is actually hotplugging a group of iommu devices
|
// hotplug a VFIO device is actually hotplugging a group of iommu devices
|
||||||
if err := devReceiver.HotplugRemoveDevice(device, config.DeviceVFIO); err != nil {
|
if err := devReceiver.HotplugRemoveDevice(device, config.DeviceVFIO); err != nil {
|
||||||
deviceLogger().WithError(err).Error("Failed to remove device")
|
deviceLogger().WithError(err).Error("Failed to remove device")
|
||||||
|
@ -1713,7 +1713,16 @@ func (s *Sandbox) AppendDevice(device api.Device) error {
|
|||||||
switch device.DeviceType() {
|
switch device.DeviceType() {
|
||||||
case config.VhostUserSCSI, config.VhostUserNet, config.VhostUserBlk, config.VhostUserFS:
|
case config.VhostUserSCSI, config.VhostUserNet, config.VhostUserBlk, config.VhostUserFS:
|
||||||
return s.hypervisor.addDevice(device.GetDeviceInfo().(*config.VhostUserDeviceAttrs), vhostuserDev)
|
return s.hypervisor.addDevice(device.GetDeviceInfo().(*config.VhostUserDeviceAttrs), vhostuserDev)
|
||||||
|
case config.DeviceVFIO:
|
||||||
|
vfioDevs := device.GetDeviceInfo().([]*config.VFIODev)
|
||||||
|
for _, d := range vfioDevs {
|
||||||
|
return s.hypervisor.addDevice(*d, vfioDev)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
s.Logger().WithField("device-type", device.DeviceType()).
|
||||||
|
Warn("Could not append device: unsupported device type")
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Errorf("unsupported device type")
|
return fmt.Errorf("unsupported device type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user