mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-29 12:14:48 +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/pkg/uuid"
|
||||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
|
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
|
||||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils"
|
"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
|
// 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]
|
slot := AcrnBlkdDevSlot[drive.Index]
|
||||||
|
|
||||||
//Explicitly set PCIAddr to NULL, so that VirtPath can be used
|
//Explicitly set PCIPath to NULL, so that VirtPath can be used
|
||||||
drive.PCIAddr = ""
|
drive.PCIPath = vcTypes.PciPath{}
|
||||||
|
|
||||||
args := []string{"blkrescan", a.acrnConfig.Name, fmt.Sprintf("%d,%s", slot, drive.File)}
|
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/device/config"
|
||||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
|
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
|
||||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils"
|
"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)
|
driveID := clhDriveIndexToID(drive.Index)
|
||||||
|
|
||||||
//Explicitly set PCIAddr to NULL, so that VirtPath can be used
|
//Explicitly set PCIPath to NULL, so that VirtPath can be used
|
||||||
drive.PCIAddr = ""
|
drive.PCIPath = vcTypes.PciPath{}
|
||||||
|
|
||||||
if drive.Pmem {
|
if drive.Pmem {
|
||||||
err = fmt.Errorf("pmem device hotplug not supported")
|
err = fmt.Errorf("pmem device hotplug not supported")
|
||||||
|
@ -16,6 +16,7 @@ import (
|
|||||||
|
|
||||||
"github.com/go-ini/ini"
|
"github.com/go-ini/ini"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
|
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DeviceType indicates device type
|
// 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 is used to identify the slot at which the drive is attached (order?).
|
||||||
MmioAddr string
|
MmioAddr 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.
|
||||||
PCIAddr string
|
PCIPath vcTypes.PciPath
|
||||||
|
|
||||||
// SCSI Address of the block device, in case the device is attached using SCSI driver
|
// SCSI Address of the block device, in case the device is attached using SCSI driver
|
||||||
// SCSI address is in the format SCSI-Id:LUN
|
// SCSI address is in the format SCSI-Id:LUN
|
||||||
|
@ -170,7 +170,7 @@ func (device *BlockDevice) Save() persistapi.DeviceState {
|
|||||||
ID: drive.ID,
|
ID: drive.ID,
|
||||||
Index: drive.Index,
|
Index: drive.Index,
|
||||||
MmioAddr: drive.MmioAddr,
|
MmioAddr: drive.MmioAddr,
|
||||||
PCIAddr: drive.PCIAddr,
|
PCIPath: drive.PCIPath,
|
||||||
SCSIAddr: drive.SCSIAddr,
|
SCSIAddr: drive.SCSIAddr,
|
||||||
NvdimmID: drive.NvdimmID,
|
NvdimmID: drive.NvdimmID,
|
||||||
VirtPath: drive.VirtPath,
|
VirtPath: drive.VirtPath,
|
||||||
@ -196,7 +196,7 @@ func (device *BlockDevice) Load(ds persistapi.DeviceState) {
|
|||||||
ID: bd.ID,
|
ID: bd.ID,
|
||||||
Index: bd.Index,
|
Index: bd.Index,
|
||||||
MmioAddr: bd.MmioAddr,
|
MmioAddr: bd.MmioAddr,
|
||||||
PCIAddr: bd.PCIAddr,
|
PCIPath: bd.PCIPath,
|
||||||
SCSIAddr: bd.SCSIAddr,
|
SCSIAddr: bd.SCSIAddr,
|
||||||
NvdimmID: bd.NvdimmID,
|
NvdimmID: bd.NvdimmID,
|
||||||
VirtPath: bd.VirtPath,
|
VirtPath: bd.VirtPath,
|
||||||
|
@ -1074,7 +1074,7 @@ func (k *kataAgent) appendBlockDevice(dev ContainerDevice, c *Container) *grpc.D
|
|||||||
kataDevice.Id = d.DevNo
|
kataDevice.Id = d.DevNo
|
||||||
case config.VirtioBlock:
|
case config.VirtioBlock:
|
||||||
kataDevice.Type = kataBlkDevType
|
kataDevice.Type = kataBlkDevType
|
||||||
kataDevice.Id = d.PCIAddr
|
kataDevice.Id = d.PCIPath.String()
|
||||||
kataDevice.VmPath = d.VirtPath
|
kataDevice.VmPath = d.VirtPath
|
||||||
case config.VirtioSCSI:
|
case config.VirtioSCSI:
|
||||||
kataDevice.Type = kataSCSIDevType
|
kataDevice.Type = kataSCSIDevType
|
||||||
@ -1178,10 +1178,10 @@ func (k *kataAgent) buildContainerRootfs(sandbox *Sandbox, c *Container, rootPat
|
|||||||
rootfs.Source = blockDrive.DevNo
|
rootfs.Source = blockDrive.DevNo
|
||||||
case sandbox.config.HypervisorConfig.BlockDeviceDriver == config.VirtioBlock:
|
case sandbox.config.HypervisorConfig.BlockDeviceDriver == config.VirtioBlock:
|
||||||
rootfs.Driver = kataBlkDevType
|
rootfs.Driver = kataBlkDevType
|
||||||
if blockDrive.PCIAddr == "" {
|
if blockDrive.PCIPath.IsNil() {
|
||||||
rootfs.Source = blockDrive.VirtPath
|
rootfs.Source = blockDrive.VirtPath
|
||||||
} else {
|
} else {
|
||||||
rootfs.Source = blockDrive.PCIAddr
|
rootfs.Source = blockDrive.PCIPath.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
case sandbox.config.HypervisorConfig.BlockDeviceDriver == config.VirtioSCSI:
|
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
|
vol.Source = blockDrive.DevNo
|
||||||
case c.sandbox.config.HypervisorConfig.BlockDeviceDriver == config.VirtioBlock:
|
case c.sandbox.config.HypervisorConfig.BlockDeviceDriver == config.VirtioBlock:
|
||||||
vol.Driver = kataBlkDevType
|
vol.Driver = kataBlkDevType
|
||||||
if blockDrive.PCIAddr == "" {
|
if blockDrive.PCIPath.IsNil() {
|
||||||
vol.Source = blockDrive.VirtPath
|
vol.Source = blockDrive.VirtPath
|
||||||
} else {
|
} else {
|
||||||
vol.Source = blockDrive.PCIAddr
|
vol.Source = blockDrive.PCIPath.String()
|
||||||
}
|
}
|
||||||
case c.sandbox.config.HypervisorConfig.BlockDeviceDriver == config.VirtioMmio:
|
case c.sandbox.config.HypervisorConfig.BlockDeviceDriver == config.VirtioMmio:
|
||||||
vol.Driver = kataMmioBlkDevType
|
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/mock"
|
||||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/rootless"
|
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/rootless"
|
||||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
|
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
|
||||||
|
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -39,7 +40,7 @@ var (
|
|||||||
testBlockDeviceCtrPath = "testBlockDeviceCtrPath"
|
testBlockDeviceCtrPath = "testBlockDeviceCtrPath"
|
||||||
testDevNo = "testDevNo"
|
testDevNo = "testDevNo"
|
||||||
testNvdimmID = "testNvdimmID"
|
testNvdimmID = "testNvdimmID"
|
||||||
testPCIAddr = "04/02"
|
testPCIPath, _ = vcTypes.PciPathFromString("04/02")
|
||||||
testSCSIAddr = "testSCSIAddr"
|
testSCSIAddr = "testSCSIAddr"
|
||||||
testVirtPath = "testVirtPath"
|
testVirtPath = "testVirtPath"
|
||||||
)
|
)
|
||||||
@ -271,13 +272,13 @@ func TestHandleDeviceBlockVolume(t *testing.T) {
|
|||||||
inputMount: Mount{},
|
inputMount: Mount{},
|
||||||
inputDev: &drivers.BlockDevice{
|
inputDev: &drivers.BlockDevice{
|
||||||
BlockDrive: &config.BlockDrive{
|
BlockDrive: &config.BlockDrive{
|
||||||
PCIAddr: testPCIAddr,
|
PCIPath: testPCIPath,
|
||||||
VirtPath: testVirtPath,
|
VirtPath: testVirtPath,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
resultVol: &pb.Storage{
|
resultVol: &pb.Storage{
|
||||||
Driver: kataBlkDevType,
|
Driver: kataBlkDevType,
|
||||||
Source: testPCIAddr,
|
Source: testPCIPath.String(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -353,16 +354,17 @@ func TestHandleBlockVolume(t *testing.T) {
|
|||||||
bDestination := "/DeviceBlock/destination"
|
bDestination := "/DeviceBlock/destination"
|
||||||
dDestination := "/DeviceDirectBlock/destination"
|
dDestination := "/DeviceDirectBlock/destination"
|
||||||
vPCIAddr := "0001:01"
|
vPCIAddr := "0001:01"
|
||||||
bPCIAddr := "0002:01"
|
bPCIPath, err := vcTypes.PciPathFromString("03/04")
|
||||||
dPCIAddr := "0003:01"
|
assert.NoError(t, err)
|
||||||
|
dPCIPath, err := vcTypes.PciPathFromString("04/05")
|
||||||
|
|
||||||
vDev := drivers.NewVhostUserBlkDevice(&config.DeviceInfo{ID: vDevID})
|
vDev := drivers.NewVhostUserBlkDevice(&config.DeviceInfo{ID: vDevID})
|
||||||
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{PCIAddr: vPCIAddr}
|
||||||
bDev.BlockDrive = &config.BlockDrive{PCIAddr: bPCIAddr}
|
bDev.BlockDrive = &config.BlockDrive{PCIPath: bPCIPath}
|
||||||
dDev.BlockDrive = &config.BlockDrive{PCIAddr: dPCIAddr}
|
dDev.BlockDrive = &config.BlockDrive{PCIPath: dPCIPath}
|
||||||
|
|
||||||
var devices []api.Device
|
var devices []api.Device
|
||||||
devices = append(devices, vDev, bDev, dDev)
|
devices = append(devices, vDev, bDev, dDev)
|
||||||
@ -418,14 +420,14 @@ func TestHandleBlockVolume(t *testing.T) {
|
|||||||
Fstype: "bind",
|
Fstype: "bind",
|
||||||
Options: []string{"bind"},
|
Options: []string{"bind"},
|
||||||
Driver: kataBlkDevType,
|
Driver: kataBlkDevType,
|
||||||
Source: bPCIAddr,
|
Source: bPCIPath.String(),
|
||||||
}
|
}
|
||||||
dStorage := &pb.Storage{
|
dStorage := &pb.Storage{
|
||||||
MountPoint: dDestination,
|
MountPoint: dDestination,
|
||||||
Fstype: "ext4",
|
Fstype: "ext4",
|
||||||
Options: []string{"ro"},
|
Options: []string{"ro"},
|
||||||
Driver: kataBlkDevType,
|
Driver: kataBlkDevType,
|
||||||
Source: dPCIAddr,
|
Source: dPCIPath.String(),
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(t, vStorage, volumeStorages[0], "Error while handle VhostUserBlk type block volume")
|
assert.Equal(t, vStorage, volumeStorages[0], "Error while handle VhostUserBlk type block volume")
|
||||||
@ -462,7 +464,7 @@ func TestAppendDevices(t *testing.T) {
|
|||||||
ID: id,
|
ID: id,
|
||||||
},
|
},
|
||||||
BlockDrive: &config.BlockDrive{
|
BlockDrive: &config.BlockDrive{
|
||||||
PCIAddr: testPCIAddr,
|
PCIPath: testPCIPath,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -489,7 +491,7 @@ func TestAppendDevices(t *testing.T) {
|
|||||||
{
|
{
|
||||||
Type: kataBlkDevType,
|
Type: kataBlkDevType,
|
||||||
ContainerPath: testBlockDeviceCtrPath,
|
ContainerPath: testBlockDeviceCtrPath,
|
||||||
Id: testPCIAddr,
|
Id: testPCIPath.String(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
updatedDevList := k.appendDevices(devList, c)
|
updatedDevList := k.appendDevices(devList, c)
|
||||||
@ -509,7 +511,7 @@ func TestAppendVhostUserBlkDevices(t *testing.T) {
|
|||||||
},
|
},
|
||||||
VhostUserDeviceAttrs: &config.VhostUserDeviceAttrs{
|
VhostUserDeviceAttrs: &config.VhostUserDeviceAttrs{
|
||||||
Type: config.VhostUserBlk,
|
Type: config.VhostUserBlk,
|
||||||
PCIAddr: testPCIAddr,
|
PCIAddr: testPCIPath.String(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -537,7 +539,7 @@ func TestAppendVhostUserBlkDevices(t *testing.T) {
|
|||||||
{
|
{
|
||||||
Type: kataBlkDevType,
|
Type: kataBlkDevType,
|
||||||
ContainerPath: testBlockDeviceCtrPath,
|
ContainerPath: testBlockDeviceCtrPath,
|
||||||
Id: testPCIAddr,
|
Id: testPCIPath.String(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
updatedDevList := k.appendDevices(devList, c)
|
updatedDevList := k.appendDevices(devList, c)
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
package persistapi
|
package persistapi
|
||||||
|
|
||||||
|
import vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
|
||||||
|
|
||||||
// ============= sandbox level resources =============
|
// ============= sandbox level resources =============
|
||||||
|
|
||||||
// BlockDrive represents a block storage drive which may be used in case the storage
|
// 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 is used to identify the slot at which the drive is attached (order?).
|
||||||
MmioAddr string
|
MmioAddr 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.
|
||||||
PCIAddr string
|
PCIPath vcTypes.PciPath
|
||||||
|
|
||||||
// SCSI Address of the block device, in case the device is attached using SCSI driver
|
// SCSI Address of the block device, in case the device is attached using SCSI driver
|
||||||
// SCSI address is in the format SCSI-Id:LUN
|
// 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"
|
bridgeSlot, err := vcTypes.PciSlotFromInt(bridge.Addr)
|
||||||
drive.PCIAddr = fmt.Sprintf("%02x", bridge.Addr) + "/" + 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 {
|
if err = q.qmpMonitorCh.qmp.ExecutePCIDeviceAdd(q.qmpMonitorCh.ctx, drive.ID, devID, driver, addr, bridge.ID, romFile, 0, true, defaultDisableModern); err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user