diff --git a/src/runtime/virtcontainers/device/config/config.go b/src/runtime/virtcontainers/device/config/config.go index aeacbd98cf..4faf24d7f9 100644 --- a/src/runtime/virtcontainers/device/config/config.go +++ b/src/runtime/virtcontainers/device/config/config.go @@ -250,9 +250,10 @@ type VhostUserDeviceAttrs struct { CacheSize uint32 Cache string - // PCIAddr is the PCI address used to identify the slot at which the drive is attached. - // It is only meaningful for vhost user block devices - PCIAddr string + // PCIPath is the PCI path used to identify the slot at which + // the drive is attached. It is only meaningful for vhost + // user block devices + PCIPath vcTypes.PciPath // Block index of the device if assigned Index int diff --git a/src/runtime/virtcontainers/device/drivers/vhost_user_blk.go b/src/runtime/virtcontainers/device/drivers/vhost_user_blk.go index 22afd58536..e4238fa362 100644 --- a/src/runtime/virtcontainers/device/drivers/vhost_user_blk.go +++ b/src/runtime/virtcontainers/device/drivers/vhost_user_blk.go @@ -164,7 +164,7 @@ func (device *VhostUserBlkDevice) Save() persistapi.DeviceState { DevID: vAttr.DevID, SocketPath: vAttr.SocketPath, Type: string(vAttr.Type), - PCIAddr: vAttr.PCIAddr, + PCIPath: vAttr.PCIPath, Index: vAttr.Index, } } @@ -185,7 +185,7 @@ func (device *VhostUserBlkDevice) Load(ds persistapi.DeviceState) { DevID: dev.DevID, SocketPath: dev.SocketPath, Type: config.DeviceType(dev.Type), - PCIAddr: dev.PCIAddr, + PCIPath: dev.PCIPath, Index: dev.Index, } } diff --git a/src/runtime/virtcontainers/kata_agent.go b/src/runtime/virtcontainers/kata_agent.go index a506d5b74b..9492a2f731 100644 --- a/src/runtime/virtcontainers/kata_agent.go +++ b/src/runtime/virtcontainers/kata_agent.go @@ -1099,7 +1099,7 @@ func (k *kataAgent) appendVhostUserBlkDevice(dev ContainerDevice, c *Container) kataDevice := &grpc.Device{ ContainerPath: dev.ContainerPath, Type: kataBlkDevType, - Id: d.PCIAddr, + Id: d.PCIPath.String(), } return kataDevice @@ -1467,7 +1467,7 @@ func (k *kataAgent) handleVhostUserBlkVolume(c *Container, m Mount, device api.D } vol.Driver = kataBlkDevType - vol.Source = d.PCIAddr + vol.Source = d.PCIPath.String() vol.Fstype = "bind" vol.Options = []string{"bind"} vol.MountPoint = m.Destination diff --git a/src/runtime/virtcontainers/kata_agent_test.go b/src/runtime/virtcontainers/kata_agent_test.go index 226504d0fe..6f1b97958d 100644 --- a/src/runtime/virtcontainers/kata_agent_test.go +++ b/src/runtime/virtcontainers/kata_agent_test.go @@ -353,7 +353,8 @@ func TestHandleBlockVolume(t *testing.T) { vDestination := "/VhostUserBlk/destination" bDestination := "/DeviceBlock/destination" dDestination := "/DeviceDirectBlock/destination" - vPCIAddr := "0001:01" + vPCIPath, err := vcTypes.PciPathFromString("01/02") + assert.NoError(t, err) bPCIPath, err := vcTypes.PciPathFromString("03/04") assert.NoError(t, err) dPCIPath, err := vcTypes.PciPathFromString("04/05") @@ -362,7 +363,7 @@ func TestHandleBlockVolume(t *testing.T) { bDev := drivers.NewBlockDevice(&config.DeviceInfo{ID: bDevID}) dDev := drivers.NewBlockDevice(&config.DeviceInfo{ID: dDevID}) - vDev.VhostUserDeviceAttrs = &config.VhostUserDeviceAttrs{PCIAddr: vPCIAddr} + vDev.VhostUserDeviceAttrs = &config.VhostUserDeviceAttrs{PCIPath: vPCIPath} bDev.BlockDrive = &config.BlockDrive{PCIPath: bPCIPath} dDev.BlockDrive = &config.BlockDrive{PCIPath: dPCIPath} @@ -413,7 +414,7 @@ func TestHandleBlockVolume(t *testing.T) { Fstype: "bind", Options: []string{"bind"}, Driver: kataBlkDevType, - Source: vPCIAddr, + Source: vPCIPath.String(), } bStorage := &pb.Storage{ MountPoint: bDestination, @@ -511,7 +512,7 @@ func TestAppendVhostUserBlkDevices(t *testing.T) { }, VhostUserDeviceAttrs: &config.VhostUserDeviceAttrs{ Type: config.VhostUserBlk, - PCIAddr: testPCIPath.String(), + PCIPath: testPCIPath, }, }, } diff --git a/src/runtime/virtcontainers/persist/api/device.go b/src/runtime/virtcontainers/persist/api/device.go index 9c8b0814ad..204ea7cfa7 100644 --- a/src/runtime/virtcontainers/persist/api/device.go +++ b/src/runtime/virtcontainers/persist/api/device.go @@ -73,9 +73,9 @@ type VhostUserDeviceAttrs struct { // MacAddress is only meaningful for vhost user net device MacAddress string - // PCIAddr is the PCI address used to identify the slot at which the drive is attached. + // PCIPath is the PCI path used to identify the slot at which the drive is attached. // It is only meaningful for vhost user block devices - PCIAddr string + PCIPath vcTypes.PciPath // Block index of the device if assigned Index int diff --git a/src/runtime/virtcontainers/qemu.go b/src/runtime/virtcontainers/qemu.go index e9cfa4c2e0..3760dc3515 100644 --- a/src/runtime/virtcontainers/qemu.go +++ b/src/runtime/virtcontainers/qemu.go @@ -1351,8 +1351,15 @@ func (q *qemu) hotplugAddVhostUserBlkDevice(vAttr *config.VhostUserDeviceAttrs, } }() - // PCI address is in the format bridge-addr/device-addr eg. "03/02" - vAttr.PCIAddr = fmt.Sprintf("%02x", bridge.Addr) + "/" + addr + bridgeSlot, err := vcTypes.PciSlotFromInt(bridge.Addr) + if err != nil { + return err + } + devSlot, err := vcTypes.PciSlotFromString(addr) + if err != nil { + return err + } + vAttr.PCIPath, err = vcTypes.PciPathFromSlots(bridgeSlot, devSlot) if err = q.qmpMonitorCh.qmp.ExecutePCIVhostUserDevAdd(q.qmpMonitorCh.ctx, driver, devID, vAttr.DevID, addr, bridge.ID); err != nil { return err