vfio: Fix hotpunplug

We need to remove the device from the tracking map, a container
restart will increment the bus index and we will get out of root-ports
and crash the machine.

Signed-off-by: Zvonko Kaiser <zkaiser@nvidia.com>
This commit is contained in:
Zvonko Kaiser 2024-05-27 14:12:39 +00:00
parent a7931115a0
commit d4832b3b74

View File

@ -141,6 +141,16 @@ func (device *VFIODevice) Detach(ctx context.Context, devReceiver api.DeviceRece
deviceLogger().WithError(err).Error("Failed to remove device") deviceLogger().WithError(err).Error("Failed to remove device")
return err return err
} }
for _, vfio := range device.VfioDevs {
if vfio.IsPCIe {
for ix, dev := range config.PCIeDevicesPerPort[vfio.Port] {
if dev.BDF == vfio.BDF {
config.PCIeDevicesPerPort[vfio.Port] = append(config.PCIeDevicesPerPort[vfio.Port][:ix], config.PCIeDevicesPerPort[vfio.Port][ix+1:]...)
break
}
}
}
}
deviceLogger().WithFields(logrus.Fields{ deviceLogger().WithFields(logrus.Fields{
"device-group": device.DeviceInfo.HostPath, "device-group": device.DeviceInfo.HostPath,