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:
David Gibson 2020-12-16 13:46:52 +11:00
parent 74f5b5febe
commit 72cb9287a0
6 changed files with 24 additions and 15 deletions

View File

@ -250,9 +250,10 @@ type VhostUserDeviceAttrs struct {
CacheSize uint32 CacheSize uint32
Cache string Cache 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
// It is only meaningful for vhost user block devices // the drive is attached. It is only meaningful for vhost
PCIAddr string // user block devices
PCIPath vcTypes.PciPath
// Block index of the device if assigned // Block index of the device if assigned
Index int Index int

View File

@ -164,7 +164,7 @@ func (device *VhostUserBlkDevice) Save() persistapi.DeviceState {
DevID: vAttr.DevID, DevID: vAttr.DevID,
SocketPath: vAttr.SocketPath, SocketPath: vAttr.SocketPath,
Type: string(vAttr.Type), Type: string(vAttr.Type),
PCIAddr: vAttr.PCIAddr, PCIPath: vAttr.PCIPath,
Index: vAttr.Index, Index: vAttr.Index,
} }
} }
@ -185,7 +185,7 @@ func (device *VhostUserBlkDevice) Load(ds persistapi.DeviceState) {
DevID: dev.DevID, DevID: dev.DevID,
SocketPath: dev.SocketPath, SocketPath: dev.SocketPath,
Type: config.DeviceType(dev.Type), Type: config.DeviceType(dev.Type),
PCIAddr: dev.PCIAddr, PCIPath: dev.PCIPath,
Index: dev.Index, Index: dev.Index,
} }
} }

View File

@ -1099,7 +1099,7 @@ func (k *kataAgent) appendVhostUserBlkDevice(dev ContainerDevice, c *Container)
kataDevice := &grpc.Device{ kataDevice := &grpc.Device{
ContainerPath: dev.ContainerPath, ContainerPath: dev.ContainerPath,
Type: kataBlkDevType, Type: kataBlkDevType,
Id: d.PCIAddr, Id: d.PCIPath.String(),
} }
return kataDevice return kataDevice
@ -1467,7 +1467,7 @@ func (k *kataAgent) handleVhostUserBlkVolume(c *Container, m Mount, device api.D
} }
vol.Driver = kataBlkDevType vol.Driver = kataBlkDevType
vol.Source = d.PCIAddr vol.Source = d.PCIPath.String()
vol.Fstype = "bind" vol.Fstype = "bind"
vol.Options = []string{"bind"} vol.Options = []string{"bind"}
vol.MountPoint = m.Destination vol.MountPoint = m.Destination

View File

@ -353,7 +353,8 @@ func TestHandleBlockVolume(t *testing.T) {
vDestination := "/VhostUserBlk/destination" vDestination := "/VhostUserBlk/destination"
bDestination := "/DeviceBlock/destination" bDestination := "/DeviceBlock/destination"
dDestination := "/DeviceDirectBlock/destination" dDestination := "/DeviceDirectBlock/destination"
vPCIAddr := "0001:01" vPCIPath, err := vcTypes.PciPathFromString("01/02")
assert.NoError(t, err)
bPCIPath, err := vcTypes.PciPathFromString("03/04") bPCIPath, err := vcTypes.PciPathFromString("03/04")
assert.NoError(t, err) assert.NoError(t, err)
dPCIPath, err := vcTypes.PciPathFromString("04/05") dPCIPath, err := vcTypes.PciPathFromString("04/05")
@ -362,7 +363,7 @@ func TestHandleBlockVolume(t *testing.T) {
bDev := drivers.NewBlockDevice(&config.DeviceInfo{ID: bDevID}) bDev := drivers.NewBlockDevice(&config.DeviceInfo{ID: bDevID})
dDev := drivers.NewBlockDevice(&config.DeviceInfo{ID: dDevID}) 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} bDev.BlockDrive = &config.BlockDrive{PCIPath: bPCIPath}
dDev.BlockDrive = &config.BlockDrive{PCIPath: dPCIPath} dDev.BlockDrive = &config.BlockDrive{PCIPath: dPCIPath}
@ -413,7 +414,7 @@ func TestHandleBlockVolume(t *testing.T) {
Fstype: "bind", Fstype: "bind",
Options: []string{"bind"}, Options: []string{"bind"},
Driver: kataBlkDevType, Driver: kataBlkDevType,
Source: vPCIAddr, Source: vPCIPath.String(),
} }
bStorage := &pb.Storage{ bStorage := &pb.Storage{
MountPoint: bDestination, MountPoint: bDestination,
@ -511,7 +512,7 @@ func TestAppendVhostUserBlkDevices(t *testing.T) {
}, },
VhostUserDeviceAttrs: &config.VhostUserDeviceAttrs{ VhostUserDeviceAttrs: &config.VhostUserDeviceAttrs{
Type: config.VhostUserBlk, Type: config.VhostUserBlk,
PCIAddr: testPCIPath.String(), PCIPath: testPCIPath,
}, },
}, },
} }

View File

@ -73,9 +73,9 @@ type VhostUserDeviceAttrs struct {
// MacAddress is only meaningful for vhost user net device // MacAddress is only meaningful for vhost user net device
MacAddress string 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 // It is only meaningful for vhost user block devices
PCIAddr string PCIPath vcTypes.PciPath
// Block index of the device if assigned // Block index of the device if assigned
Index int Index int

View File

@ -1351,8 +1351,15 @@ func (q *qemu) hotplugAddVhostUserBlkDevice(vAttr *config.VhostUserDeviceAttrs,
} }
}() }()
// PCI address is in the format bridge-addr/device-addr eg. "03/02" bridgeSlot, err := vcTypes.PciSlotFromInt(bridge.Addr)
vAttr.PCIAddr = fmt.Sprintf("%02x", bridge.Addr) + "/" + 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 { if err = q.qmpMonitorCh.qmp.ExecutePCIVhostUserDevAdd(q.qmpMonitorCh.ctx, driver, devID, vAttr.DevID, addr, bridge.ID); err != nil {
return err return err