mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-28 08:17:37 +00:00
vhost-user-blk: Use PciPath type for vhost user devices
VhostUserDeviceAttrs::PCIAddr didn't actually store a PCI address
(DDDD:BB:DD.F), but rather a PCI path. Use the PciPath type and
rename things to make that clearer.
TestHandleBlockVolume previously used the bizarre value "0001:01"
which is neither a PCI address nor a PCI path for this value. Change
it to a valid PCI path - it appears the actual value didn't matter for
that test, as long as it was consistent.
Forward port of
3596058c67
fixes #1040
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
74f5b5febe
commit
72cb9287a0
@ -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
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user