mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-09-14 13:29:31 +00:00
runtime: fix duplicated devices requested to the agent
By default, when a container is created with the `--privileged` flag, all devices in `/dev` from the host are mounted into the guest. If there is a block device(e.g. `/dev/dm`) followed by a generic device(e.g. `/dev/null`),two identical block devices(`/dev/dm`) would be requested to the kata agent causing the agent to exit with error: > Conflicting device updates for /dev/dm-2 As the generic device type does not hit any cases defined in `switch`, the variable `kataDevice` which is defined outside of the loop is still the value of the previous block device rather than `nil`. Defining `kataDevice` in the loop fixes this bug. Signed-off-by: cncal <flycalvin@qq.com>
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
package virtcontainers
|
package virtcontainers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
b64 "encoding/base64"
|
b64 "encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
@@ -34,8 +35,6 @@ import (
|
|||||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
|
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
|
||||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils"
|
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils"
|
||||||
|
|
||||||
"context"
|
|
||||||
|
|
||||||
ctrAnnotations "github.com/containerd/containerd/pkg/cri/annotations"
|
ctrAnnotations "github.com/containerd/containerd/pkg/cri/annotations"
|
||||||
podmanAnnotations "github.com/containers/podman/v4/pkg/annotations"
|
podmanAnnotations "github.com/containers/podman/v4/pkg/annotations"
|
||||||
"github.com/opencontainers/runtime-spec/specs-go"
|
"github.com/opencontainers/runtime-spec/specs-go"
|
||||||
@@ -1200,8 +1199,6 @@ func (k *kataAgent) appendVfioDevice(dev ContainerDevice, device api.Device, c *
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (k *kataAgent) appendDevices(deviceList []*grpc.Device, c *Container) []*grpc.Device {
|
func (k *kataAgent) appendDevices(deviceList []*grpc.Device, c *Container) []*grpc.Device {
|
||||||
var kataDevice *grpc.Device
|
|
||||||
|
|
||||||
for _, dev := range c.devices {
|
for _, dev := range c.devices {
|
||||||
device := c.sandbox.devManager.GetDeviceByID(dev.ID)
|
device := c.sandbox.devManager.GetDeviceByID(dev.ID)
|
||||||
if device == nil {
|
if device == nil {
|
||||||
@@ -1213,6 +1210,8 @@ func (k *kataAgent) appendDevices(deviceList []*grpc.Device, c *Container) []*gr
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var kataDevice *grpc.Device
|
||||||
|
|
||||||
switch device.DeviceType() {
|
switch device.DeviceType() {
|
||||||
case config.DeviceBlock:
|
case config.DeviceBlock:
|
||||||
kataDevice = k.appendBlockDevice(dev, device, c)
|
kataDevice = k.appendBlockDevice(dev, device, c)
|
||||||
|
@@ -479,16 +479,21 @@ func TestAppendDevicesEmptyContainerDeviceList(t *testing.T) {
|
|||||||
func TestAppendDevices(t *testing.T) {
|
func TestAppendDevices(t *testing.T) {
|
||||||
k := kataAgent{}
|
k := kataAgent{}
|
||||||
|
|
||||||
id := "test-append-block"
|
testBlockDeviceID := "test-block-device"
|
||||||
|
testCharacterDeviceId := "test-character-device"
|
||||||
|
|
||||||
ctrDevices := []api.Device{
|
ctrDevices := []api.Device{
|
||||||
&drivers.BlockDevice{
|
&drivers.BlockDevice{
|
||||||
GenericDevice: &drivers.GenericDevice{
|
GenericDevice: &drivers.GenericDevice{
|
||||||
ID: id,
|
ID: testBlockDeviceID,
|
||||||
},
|
},
|
||||||
BlockDrive: &config.BlockDrive{
|
BlockDrive: &config.BlockDrive{
|
||||||
PCIPath: testPCIPath,
|
PCIPath: testPCIPath,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
&drivers.GenericDevice{
|
||||||
|
ID: testCharacterDeviceId,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
sandboxConfig := &SandboxConfig{
|
sandboxConfig := &SandboxConfig{
|
||||||
@@ -503,10 +508,16 @@ func TestAppendDevices(t *testing.T) {
|
|||||||
config: sandboxConfig,
|
config: sandboxConfig,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
c.devices = append(c.devices, ContainerDevice{
|
c.devices = append(
|
||||||
ID: id,
|
c.devices,
|
||||||
ContainerPath: testBlockDeviceCtrPath,
|
ContainerDevice{
|
||||||
})
|
ID: testBlockDeviceID,
|
||||||
|
ContainerPath: testBlockDeviceCtrPath,
|
||||||
|
},
|
||||||
|
ContainerDevice{
|
||||||
|
ID: testCharacterDeviceId,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
devList := []*pb.Device{}
|
devList := []*pb.Device{}
|
||||||
expected := []*pb.Device{
|
expected := []*pb.Device{
|
||||||
|
Reference in New Issue
Block a user