mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-18 01:13:56 +00:00
device: Assign pci address for block devices
Introduce a new field in Drive to store the PCI address if the drive is attached using virtio-blk. Assign PCI address in the format bridge-addr/device-addr. Since we need to assign the address while hotplugging, pass Drive by address. Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
This commit is contained in:
parent
dd927921c1
commit
718dbd2a71
@ -788,7 +788,7 @@ func (c *Container) hotplugDrive() error {
|
|||||||
Index: driveIndex,
|
Index: driveIndex,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.sandbox.hypervisor.hotplugAddDevice(drive, blockDev); err != nil {
|
if err := c.sandbox.hypervisor.hotplugAddDevice(&drive, blockDev); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
c.setStateHotpluggedDrive(true)
|
c.setStateHotpluggedDrive(true)
|
||||||
@ -813,7 +813,7 @@ func (c *Container) removeDrive() (err error) {
|
|||||||
c.Logger().Info("unplugging block device")
|
c.Logger().Info("unplugging block device")
|
||||||
|
|
||||||
devID := makeNameID("drive", c.id)
|
devID := makeNameID("drive", c.id)
|
||||||
drive := Drive{
|
drive := &Drive{
|
||||||
ID: devID,
|
ID: devID,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -334,6 +334,9 @@ type BlockDevice struct {
|
|||||||
|
|
||||||
// Path at which the device appears inside the VM, outside of the container mount namespace
|
// Path at which the device appears inside the VM, outside of the container mount namespace
|
||||||
VirtPath string
|
VirtPath string
|
||||||
|
|
||||||
|
// PCI Slot of the block device
|
||||||
|
PCIAddr string
|
||||||
}
|
}
|
||||||
|
|
||||||
func newBlockDevice(devInfo DeviceInfo) *BlockDevice {
|
func newBlockDevice(devInfo DeviceInfo) *BlockDevice {
|
||||||
@ -380,7 +383,7 @@ func (device *BlockDevice) attach(h hypervisor, c *Container) (err error) {
|
|||||||
|
|
||||||
deviceLogger().WithField("device", device.DeviceInfo.HostPath).Info("Attaching block device")
|
deviceLogger().WithField("device", device.DeviceInfo.HostPath).Info("Attaching block device")
|
||||||
|
|
||||||
if err = h.hotplugAddDevice(drive, blockDev); err != nil {
|
if err = h.hotplugAddDevice(&drive, blockDev); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -404,7 +407,7 @@ func (device BlockDevice) detach(h hypervisor) error {
|
|||||||
if device.DeviceInfo.Hotplugged {
|
if device.DeviceInfo.Hotplugged {
|
||||||
deviceLogger().WithField("device", device.DeviceInfo.HostPath).Info("Unplugging block device")
|
deviceLogger().WithField("device", device.DeviceInfo.HostPath).Info("Unplugging block device")
|
||||||
|
|
||||||
drive := Drive{
|
drive := &Drive{
|
||||||
ID: makeNameID("drive", device.DeviceInfo.ID),
|
ID: makeNameID("drive", device.DeviceInfo.ID),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -593,7 +593,7 @@ func (q *qemu) removeDeviceFromBridge(ID string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *qemu) hotplugBlockDevice(drive Drive, op operation) error {
|
func (q *qemu) hotplugBlockDevice(drive *Drive, op operation) error {
|
||||||
defer func(qemu *qemu) {
|
defer func(qemu *qemu) {
|
||||||
if q.qmpMonitorCh.qmp != nil {
|
if q.qmpMonitorCh.qmp != nil {
|
||||||
q.qmpMonitorCh.qmp.Shutdown()
|
q.qmpMonitorCh.qmp.Shutdown()
|
||||||
@ -621,6 +621,9 @@ func (q *qemu) hotplugBlockDevice(drive Drive, op operation) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PCI address is in the format bridge-addr/device-addr eg. "03/02"
|
||||||
|
drive.PCIAddr = fmt.Sprintf("%02x", bridge.Addr) + "/" + addr
|
||||||
|
|
||||||
if err = q.qmpMonitorCh.qmp.ExecutePCIDeviceAdd(q.qmpMonitorCh.ctx, drive.ID, devID, driver, addr, bridge.ID); err != nil {
|
if err = q.qmpMonitorCh.qmp.ExecutePCIDeviceAdd(q.qmpMonitorCh.ctx, drive.ID, devID, driver, addr, bridge.ID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -700,7 +703,7 @@ func (q *qemu) hotplugVFIODevice(device VFIODevice, op operation) error {
|
|||||||
func (q *qemu) hotplugDevice(devInfo interface{}, devType deviceType, op operation) error {
|
func (q *qemu) hotplugDevice(devInfo interface{}, devType deviceType, op operation) error {
|
||||||
switch devType {
|
switch devType {
|
||||||
case blockDev:
|
case blockDev:
|
||||||
drive := devInfo.(Drive)
|
drive := devInfo.(*Drive)
|
||||||
return q.hotplugBlockDevice(drive, op)
|
return q.hotplugBlockDevice(drive, op)
|
||||||
case cpuDev:
|
case cpuDev:
|
||||||
vcpus := devInfo.(uint32)
|
vcpus := devInfo.(uint32)
|
||||||
|
@ -237,6 +237,9 @@ type Drive struct {
|
|||||||
|
|
||||||
// Index assigned to the drive. In case of virtio-scsi, this is used as SCSI LUN index
|
// Index assigned to the drive. In case of virtio-scsi, this is used as SCSI LUN index
|
||||||
Index int
|
Index int
|
||||||
|
|
||||||
|
// PCIAddr is the PCI address used to identify the slot at which the drive is attached.
|
||||||
|
PCIAddr string
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnvVar is a key/value structure representing a command
|
// EnvVar is a key/value structure representing a command
|
||||||
|
Loading…
Reference in New Issue
Block a user