Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
vhost-user-blk: Use PciPath type for vhost user devices
Browse files Browse the repository at this point in the history
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.

fixes #3002

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
  • Loading branch information
dgibson committed Oct 27, 2020
1 parent 64751f3 commit 3596058
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 15 deletions.
7 changes: 4 additions & 3 deletions virtcontainers/device/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,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
Expand Down
4 changes: 2 additions & 2 deletions virtcontainers/device/drivers/vhost_user_blk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand All @@ -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,
}
}
Expand Down
4 changes: 2 additions & 2 deletions virtcontainers/kata_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,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
Expand Down Expand Up @@ -1633,7 +1633,7 @@ func (k *kataAgent) handleVhostUserBlkVolume(c *Container, device api.Device) (*
}

vol.Driver = kataBlkDevType
vol.Source = d.PCIAddr
vol.Source = d.PCIPath.String()

return vol, nil
}
Expand Down
9 changes: 5 additions & 4 deletions virtcontainers/kata_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,14 +526,15 @@ func TestHandleBlockVolume(t *testing.T) {
bDevID := "MockDeviceBlock"
vDestination := "/VhostUserBlk/destination"
bDestination := "/DeviceBlock/destination"
vPCIAddr := "0001:01"
vPCIPath, err := vcTypes.PciPathFromString("01/02")
assert.NoError(t, err)
bPCIPath, err := vcTypes.PciPathFromString("03/04")
assert.NoError(t, err)

vDev := drivers.NewVhostUserBlkDevice(&config.DeviceInfo{ID: vDevID})
bDev := drivers.NewBlockDevice(&config.DeviceInfo{ID: bDevID})

vDev.VhostUserDeviceAttrs = &config.VhostUserDeviceAttrs{PCIAddr: vPCIAddr}
vDev.VhostUserDeviceAttrs = &config.VhostUserDeviceAttrs{PCIPath: vPCIPath}
bDev.BlockDrive = &config.BlockDrive{PCIPath: bPCIPath}

var devices []api.Device
Expand Down Expand Up @@ -575,7 +576,7 @@ func TestHandleBlockVolume(t *testing.T) {
Fstype: "bind",
Options: []string{"bind"},
Driver: kataBlkDevType,
Source: vPCIAddr,
Source: vPCIPath.String(),
}
bStorage := &pb.Storage{
MountPoint: bDestination,
Expand Down Expand Up @@ -665,7 +666,7 @@ func TestAppendVhostUserBlkDevices(t *testing.T) {
},
VhostUserDeviceAttrs: &config.VhostUserDeviceAttrs{
Type: config.VhostUserBlk,
PCIAddr: testPCIPath.String(),
PCIPath: testPCIPath,
},
},
}
Expand Down
4 changes: 2 additions & 2 deletions virtcontainers/persist/api/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions virtcontainers/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -1215,8 +1215,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
Expand Down

0 comments on commit 3596058

Please sign in to comment.