From 2fd2cd4a9b468aaa8a950a8a9f9a2e49a1e90155 Mon Sep 17 00:00:00 2001 From: Hyounggyu Choi Date: Mon, 19 May 2025 13:46:49 +0200 Subject: [PATCH] runtime: Preserve hotplug devices for vfio-coldplug mode Fixes: #11288 This commit appends hotplug devices (e.g., persistent volume) to deviceInfos when `vfio_mod` is `vfio` and `cold_plug_vfio` is set to one except `no-port`. For details, please visit the issue. Signed-off-by: Hyounggyu Choi --- src/runtime/virtcontainers/container.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/runtime/virtcontainers/container.go b/src/runtime/virtcontainers/container.go index b00745b55c..484d9e2452 100644 --- a/src/runtime/virtcontainers/container.go +++ b/src/runtime/virtcontainers/container.go @@ -860,7 +860,7 @@ func (c *Container) createDevices(contConfig *ContainerConfig) error { hotPlugVFIO := (c.sandbox.config.HypervisorConfig.HotPlugVFIO != config.NoPort) hotPlugDevices := []config.DeviceInfo{} - coldPlugDevices := []config.DeviceInfo{} + vfioColdPlugDevices := []config.DeviceInfo{} for i, vfio := range deviceInfos { // If device is already attached during sandbox creation, e.g. @@ -889,7 +889,7 @@ func (c *Container) createDevices(contConfig *ContainerConfig) error { // Device is already cold-plugged at sandbox creation time // ignore it for the container creation if coldPlugVFIO && isVFIODevice { - coldPlugDevices = append(coldPlugDevices, deviceInfos[i]) + vfioColdPlugDevices = append(vfioColdPlugDevices, deviceInfos[i]) continue } hotPlugDevices = append(hotPlugDevices, deviceInfos[i]) @@ -904,7 +904,9 @@ func (c *Container) createDevices(contConfig *ContainerConfig) error { // if vfio_mode is VFIO and coldPlugVFIO is true (e.g. vfio-ap-cold). // This ensures that ociSpec.Linux.Devices is updated with // this information before the container is created on the guest. - deviceInfos = sortContainerVFIODevices(coldPlugDevices) + sortedVFIODevices := sortContainerVFIODevices(vfioColdPlugDevices) + // Combine sorted VFIO devices with hot-plug devices + deviceInfos = append(sortedVFIODevices, hotPlugDevices...) } else { deviceInfos = sortContainerVFIODevices(hotPlugDevices) } @@ -927,7 +929,7 @@ func (c *Container) createDevices(contConfig *ContainerConfig) error { // If we're hot-plugging this will be a no-op because at this stage // no devices are attached to the root-port or switch-port - c.annotateContainerWithVFIOMetadata(coldPlugDevices) + c.annotateContainerWithVFIOMetadata(vfioColdPlugDevices) return nil }