device: Assign pci address to block device for kata_agent

Store PCI address for a block device on hotplugging it via
virtio-blk. This address will be passed by kata agent in the
device "Id" field. The agent within the guest can then use this
to identify the PCI slot in the guest and create the device node
based on it.

Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
This commit is contained in:
Archana Shinde 2018-04-26 10:34:31 -07:00
parent 85865f1a2c
commit da08a65de3
3 changed files with 7 additions and 6 deletions

View File

@ -391,6 +391,7 @@ func (device *BlockDevice) attach(h hypervisor, c *Container) (err error) {
if c.sandbox.config.HypervisorConfig.BlockDeviceDriver == VirtioBlock { if c.sandbox.config.HypervisorConfig.BlockDeviceDriver == VirtioBlock {
device.VirtPath = filepath.Join("/dev", driveName) device.VirtPath = filepath.Join("/dev", driveName)
device.PCIAddr = drive.PCIAddr
} else { } else {
scsiAddr, err := getSCSIAddress(index) scsiAddr, err := getSCSIAddress(index)
if err != nil { if err != nil {

View File

@ -629,7 +629,7 @@ func (k *kataAgent) appendDevices(deviceList []*grpc.Device, devices []Device) [
if d.SCSIAddr == "" { if d.SCSIAddr == "" {
kataDevice.Type = kataBlkDevType kataDevice.Type = kataBlkDevType
kataDevice.VmPath = d.VirtPath kataDevice.Id = d.PCIAddr
} else { } else {
kataDevice.Type = kataSCSIDevType kataDevice.Type = kataSCSIDevType
kataDevice.Id = d.SCSIAddr kataDevice.Id = d.SCSIAddr

View File

@ -24,9 +24,9 @@ import (
) )
var ( var (
testKataProxyURLTempl = "unix://%s/kata-proxy-test.sock" testKataProxyURLTempl = "unix://%s/kata-proxy-test.sock"
testBlockDeviceVirtPath = "testBlockDeviceVirtPath" testBlockDeviceCtrPath = "testBlockDeviceCtrPath"
testBlockDeviceCtrPath = "testBlockDeviceCtrPath" testPCIAddr = "04/02"
) )
func proxyHandlerDiscard(c net.Conn) { func proxyHandlerDiscard(c net.Conn) {
@ -366,16 +366,16 @@ func TestAppendDevices(t *testing.T) {
expected := []*pb.Device{ expected := []*pb.Device{
{ {
Type: kataBlkDevType, Type: kataBlkDevType,
VmPath: testBlockDeviceVirtPath,
ContainerPath: testBlockDeviceCtrPath, ContainerPath: testBlockDeviceCtrPath,
Id: testPCIAddr,
}, },
} }
ctrDevices := []Device{ ctrDevices := []Device{
&BlockDevice{ &BlockDevice{
VirtPath: testBlockDeviceVirtPath,
DeviceInfo: DeviceInfo{ DeviceInfo: DeviceInfo{
ContainerPath: testBlockDeviceCtrPath, ContainerPath: testBlockDeviceCtrPath,
}, },
PCIAddr: testPCIAddr,
}, },
} }