mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-29 04:04:45 +00:00
runtime/block: Use PciPath type through block code
BlockDrive::PCIAddr doesn't actually store a PCI address
(DDDD:BB:DD.F) but a PCI path. Use the PciPath type and rename things
to make that clearer.
TestHandleBlockVolume() previously used a bizarre value "0002:01" for
the "PCI address" which was neither an actual PCI address, nor a PCI
path. Update it to use a PCI path - the actual value appears not to
matter in this test, as long as its consistent throughout.
Forward port of
64751f377b
fixes #1040
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
32b40f5fe4
commit
74f5b5febe
@ -28,6 +28,7 @@ import (
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/uuid"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils"
|
||||
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
|
||||
)
|
||||
|
||||
// Since ACRN is using the store in a quite abnormal way, let's first draw it back from store to here
|
||||
@ -550,8 +551,8 @@ func (a *Acrn) updateBlockDevice(drive *config.BlockDrive) error {
|
||||
|
||||
slot := AcrnBlkdDevSlot[drive.Index]
|
||||
|
||||
//Explicitly set PCIAddr to NULL, so that VirtPath can be used
|
||||
drive.PCIAddr = ""
|
||||
//Explicitly set PCIPath to NULL, so that VirtPath can be used
|
||||
drive.PCIPath = vcTypes.PciPath{}
|
||||
|
||||
args := []string{"blkrescan", a.acrnConfig.Name, fmt.Sprintf("%d,%s", slot, drive.File)}
|
||||
|
||||
|
@ -32,6 +32,7 @@ import (
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils"
|
||||
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
|
||||
)
|
||||
|
||||
//
|
||||
@ -439,8 +440,8 @@ func (clh *cloudHypervisor) hotplugAddBlockDevice(drive *config.BlockDrive) erro
|
||||
|
||||
driveID := clhDriveIndexToID(drive.Index)
|
||||
|
||||
//Explicitly set PCIAddr to NULL, so that VirtPath can be used
|
||||
drive.PCIAddr = ""
|
||||
//Explicitly set PCIPath to NULL, so that VirtPath can be used
|
||||
drive.PCIPath = vcTypes.PciPath{}
|
||||
|
||||
if drive.Pmem {
|
||||
err = fmt.Errorf("pmem device hotplug not supported")
|
||||
|
@ -16,6 +16,7 @@ import (
|
||||
|
||||
"github.com/go-ini/ini"
|
||||
"golang.org/x/sys/unix"
|
||||
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
|
||||
)
|
||||
|
||||
// DeviceType indicates device type
|
||||
@ -156,8 +157,8 @@ type BlockDrive struct {
|
||||
// MmioAddr is used to identify the slot at which the drive is attached (order?).
|
||||
MmioAddr string
|
||||
|
||||
// PCIAddr is the PCI address used to identify the slot at which the drive is attached.
|
||||
PCIAddr string
|
||||
// PCIPath is the PCI path used to identify the slot at which the drive is attached.
|
||||
PCIPath vcTypes.PciPath
|
||||
|
||||
// SCSI Address of the block device, in case the device is attached using SCSI driver
|
||||
// SCSI address is in the format SCSI-Id:LUN
|
||||
|
@ -170,7 +170,7 @@ func (device *BlockDevice) Save() persistapi.DeviceState {
|
||||
ID: drive.ID,
|
||||
Index: drive.Index,
|
||||
MmioAddr: drive.MmioAddr,
|
||||
PCIAddr: drive.PCIAddr,
|
||||
PCIPath: drive.PCIPath,
|
||||
SCSIAddr: drive.SCSIAddr,
|
||||
NvdimmID: drive.NvdimmID,
|
||||
VirtPath: drive.VirtPath,
|
||||
@ -196,7 +196,7 @@ func (device *BlockDevice) Load(ds persistapi.DeviceState) {
|
||||
ID: bd.ID,
|
||||
Index: bd.Index,
|
||||
MmioAddr: bd.MmioAddr,
|
||||
PCIAddr: bd.PCIAddr,
|
||||
PCIPath: bd.PCIPath,
|
||||
SCSIAddr: bd.SCSIAddr,
|
||||
NvdimmID: bd.NvdimmID,
|
||||
VirtPath: bd.VirtPath,
|
||||
|
@ -1074,7 +1074,7 @@ func (k *kataAgent) appendBlockDevice(dev ContainerDevice, c *Container) *grpc.D
|
||||
kataDevice.Id = d.DevNo
|
||||
case config.VirtioBlock:
|
||||
kataDevice.Type = kataBlkDevType
|
||||
kataDevice.Id = d.PCIAddr
|
||||
kataDevice.Id = d.PCIPath.String()
|
||||
kataDevice.VmPath = d.VirtPath
|
||||
case config.VirtioSCSI:
|
||||
kataDevice.Type = kataSCSIDevType
|
||||
@ -1178,10 +1178,10 @@ func (k *kataAgent) buildContainerRootfs(sandbox *Sandbox, c *Container, rootPat
|
||||
rootfs.Source = blockDrive.DevNo
|
||||
case sandbox.config.HypervisorConfig.BlockDeviceDriver == config.VirtioBlock:
|
||||
rootfs.Driver = kataBlkDevType
|
||||
if blockDrive.PCIAddr == "" {
|
||||
if blockDrive.PCIPath.IsNil() {
|
||||
rootfs.Source = blockDrive.VirtPath
|
||||
} else {
|
||||
rootfs.Source = blockDrive.PCIAddr
|
||||
rootfs.Source = blockDrive.PCIPath.String()
|
||||
}
|
||||
|
||||
case sandbox.config.HypervisorConfig.BlockDeviceDriver == config.VirtioSCSI:
|
||||
@ -1427,10 +1427,10 @@ func (k *kataAgent) handleDeviceBlockVolume(c *Container, m Mount, device api.De
|
||||
vol.Source = blockDrive.DevNo
|
||||
case c.sandbox.config.HypervisorConfig.BlockDeviceDriver == config.VirtioBlock:
|
||||
vol.Driver = kataBlkDevType
|
||||
if blockDrive.PCIAddr == "" {
|
||||
if blockDrive.PCIPath.IsNil() {
|
||||
vol.Source = blockDrive.VirtPath
|
||||
} else {
|
||||
vol.Source = blockDrive.PCIAddr
|
||||
vol.Source = blockDrive.PCIPath.String()
|
||||
}
|
||||
case c.sandbox.config.HypervisorConfig.BlockDeviceDriver == config.VirtioMmio:
|
||||
vol.Driver = kataMmioBlkDevType
|
||||
|
@ -32,6 +32,7 @@ import (
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/mock"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/rootless"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
|
||||
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -39,7 +40,7 @@ var (
|
||||
testBlockDeviceCtrPath = "testBlockDeviceCtrPath"
|
||||
testDevNo = "testDevNo"
|
||||
testNvdimmID = "testNvdimmID"
|
||||
testPCIAddr = "04/02"
|
||||
testPCIPath, _ = vcTypes.PciPathFromString("04/02")
|
||||
testSCSIAddr = "testSCSIAddr"
|
||||
testVirtPath = "testVirtPath"
|
||||
)
|
||||
@ -271,13 +272,13 @@ func TestHandleDeviceBlockVolume(t *testing.T) {
|
||||
inputMount: Mount{},
|
||||
inputDev: &drivers.BlockDevice{
|
||||
BlockDrive: &config.BlockDrive{
|
||||
PCIAddr: testPCIAddr,
|
||||
PCIPath: testPCIPath,
|
||||
VirtPath: testVirtPath,
|
||||
},
|
||||
},
|
||||
resultVol: &pb.Storage{
|
||||
Driver: kataBlkDevType,
|
||||
Source: testPCIAddr,
|
||||
Source: testPCIPath.String(),
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -353,16 +354,17 @@ func TestHandleBlockVolume(t *testing.T) {
|
||||
bDestination := "/DeviceBlock/destination"
|
||||
dDestination := "/DeviceDirectBlock/destination"
|
||||
vPCIAddr := "0001:01"
|
||||
bPCIAddr := "0002:01"
|
||||
dPCIAddr := "0003:01"
|
||||
bPCIPath, err := vcTypes.PciPathFromString("03/04")
|
||||
assert.NoError(t, err)
|
||||
dPCIPath, err := vcTypes.PciPathFromString("04/05")
|
||||
|
||||
vDev := drivers.NewVhostUserBlkDevice(&config.DeviceInfo{ID: vDevID})
|
||||
bDev := drivers.NewBlockDevice(&config.DeviceInfo{ID: bDevID})
|
||||
dDev := drivers.NewBlockDevice(&config.DeviceInfo{ID: dDevID})
|
||||
|
||||
vDev.VhostUserDeviceAttrs = &config.VhostUserDeviceAttrs{PCIAddr: vPCIAddr}
|
||||
bDev.BlockDrive = &config.BlockDrive{PCIAddr: bPCIAddr}
|
||||
dDev.BlockDrive = &config.BlockDrive{PCIAddr: dPCIAddr}
|
||||
bDev.BlockDrive = &config.BlockDrive{PCIPath: bPCIPath}
|
||||
dDev.BlockDrive = &config.BlockDrive{PCIPath: dPCIPath}
|
||||
|
||||
var devices []api.Device
|
||||
devices = append(devices, vDev, bDev, dDev)
|
||||
@ -418,14 +420,14 @@ func TestHandleBlockVolume(t *testing.T) {
|
||||
Fstype: "bind",
|
||||
Options: []string{"bind"},
|
||||
Driver: kataBlkDevType,
|
||||
Source: bPCIAddr,
|
||||
Source: bPCIPath.String(),
|
||||
}
|
||||
dStorage := &pb.Storage{
|
||||
MountPoint: dDestination,
|
||||
Fstype: "ext4",
|
||||
Options: []string{"ro"},
|
||||
Driver: kataBlkDevType,
|
||||
Source: dPCIAddr,
|
||||
Source: dPCIPath.String(),
|
||||
}
|
||||
|
||||
assert.Equal(t, vStorage, volumeStorages[0], "Error while handle VhostUserBlk type block volume")
|
||||
@ -462,7 +464,7 @@ func TestAppendDevices(t *testing.T) {
|
||||
ID: id,
|
||||
},
|
||||
BlockDrive: &config.BlockDrive{
|
||||
PCIAddr: testPCIAddr,
|
||||
PCIPath: testPCIPath,
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -489,7 +491,7 @@ func TestAppendDevices(t *testing.T) {
|
||||
{
|
||||
Type: kataBlkDevType,
|
||||
ContainerPath: testBlockDeviceCtrPath,
|
||||
Id: testPCIAddr,
|
||||
Id: testPCIPath.String(),
|
||||
},
|
||||
}
|
||||
updatedDevList := k.appendDevices(devList, c)
|
||||
@ -509,7 +511,7 @@ func TestAppendVhostUserBlkDevices(t *testing.T) {
|
||||
},
|
||||
VhostUserDeviceAttrs: &config.VhostUserDeviceAttrs{
|
||||
Type: config.VhostUserBlk,
|
||||
PCIAddr: testPCIAddr,
|
||||
PCIAddr: testPCIPath.String(),
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -537,7 +539,7 @@ func TestAppendVhostUserBlkDevices(t *testing.T) {
|
||||
{
|
||||
Type: kataBlkDevType,
|
||||
ContainerPath: testBlockDeviceCtrPath,
|
||||
Id: testPCIAddr,
|
||||
Id: testPCIPath.String(),
|
||||
},
|
||||
}
|
||||
updatedDevList := k.appendDevices(devList, c)
|
||||
|
@ -6,6 +6,8 @@
|
||||
|
||||
package persistapi
|
||||
|
||||
import vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
|
||||
|
||||
// ============= sandbox level resources =============
|
||||
|
||||
// BlockDrive represents a block storage drive which may be used in case the storage
|
||||
@ -26,8 +28,8 @@ type BlockDrive struct {
|
||||
// MmioAddr is used to identify the slot at which the drive is attached (order?).
|
||||
MmioAddr string
|
||||
|
||||
// PCIAddr is the PCI address used to identify the slot at which the drive is attached.
|
||||
PCIAddr string
|
||||
// PCIPath is the PCI path used to identify the slot at which the drive is attached.
|
||||
PCIPath vcTypes.PciPath
|
||||
|
||||
// SCSI Address of the block device, in case the device is attached using SCSI driver
|
||||
// SCSI address is in the format SCSI-Id:LUN
|
||||
|
@ -1289,8 +1289,18 @@ func (q *qemu) hotplugAddBlockDevice(drive *config.BlockDrive, op operation, dev
|
||||
}
|
||||
}()
|
||||
|
||||
// PCI address is in the format bridge-addr/device-addr eg. "03/02"
|
||||
drive.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
|
||||
}
|
||||
drive.PCIPath, err = vcTypes.PciPathFromSlots(bridgeSlot, devSlot)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = q.qmpMonitorCh.qmp.ExecutePCIDeviceAdd(q.qmpMonitorCh.ctx, drive.ID, devID, driver, addr, bridge.ID, romFile, 0, true, defaultDisableModern); err != nil {
|
||||
return err
|
||||
|
Loading…
Reference in New Issue
Block a user