mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-01 01:33:20 +00:00
devices: rename VFIODrive to VFIODev
Rename VFIODrive to VFIODev, also rename device interface "GetDeviceDrive()" to "GetDeviceInfo()". Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
This commit is contained in:
parent
daf5abce2d
commit
04f4f528f7
@ -48,11 +48,11 @@ type Device interface {
|
|||||||
// DeviceType indicates which kind of device it is
|
// DeviceType indicates which kind of device it is
|
||||||
// e.g. block, vfio or vhost user
|
// e.g. block, vfio or vhost user
|
||||||
DeviceType() config.DeviceType
|
DeviceType() config.DeviceType
|
||||||
// GetDeviceDrive returns device specific data used for hotplugging by hypervisor
|
// GetDeviceInfo returns device specific data used for hotplugging by hypervisor
|
||||||
// Caller could cast the return value to device specific struct
|
// Caller could cast the return value to device specific struct
|
||||||
// e.g. Block device returns *config.BlockDrive and
|
// e.g. Block device returns *config.BlockDrive and
|
||||||
// vfio device returns *config.VFIODrive
|
// vfio device returns []*config.VFIODev
|
||||||
GetDeviceDrive() interface{}
|
GetDeviceInfo() interface{}
|
||||||
// IsAttached checks if the device is attached
|
// IsAttached checks if the device is attached
|
||||||
IsAttached() bool
|
IsAttached() bool
|
||||||
}
|
}
|
||||||
|
@ -113,8 +113,8 @@ type BlockDrive struct {
|
|||||||
VirtPath string
|
VirtPath string
|
||||||
}
|
}
|
||||||
|
|
||||||
// VFIODrive represents a VFIO drive used for hotplugging
|
// VFIODev represents a VFIO drive used for hotplugging
|
||||||
type VFIODrive struct {
|
type VFIODev struct {
|
||||||
// ID is used to identify this drive in the hypervisor options.
|
// ID is used to identify this drive in the hypervisor options.
|
||||||
ID string
|
ID string
|
||||||
// BDF (Bus:Device.Function) of the PCI address
|
// BDF (Bus:Device.Function) of the PCI address
|
||||||
|
@ -112,7 +112,7 @@ func (device *BlockDevice) DeviceID() string {
|
|||||||
return device.ID
|
return device.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDeviceDrive returns device information used for creating
|
// GetDeviceInfo returns device information used for creating
|
||||||
func (device *BlockDevice) GetDeviceDrive() interface{} {
|
func (device *BlockDevice) GetDeviceInfo() interface{} {
|
||||||
return device.BlockDrive
|
return device.BlockDrive
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ func (device *GenericDevice) DeviceType() config.DeviceType {
|
|||||||
return config.DeviceGeneric
|
return config.DeviceGeneric
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDeviceDrive returns device information used for creating
|
// GetDeviceInfo returns device information used for creating
|
||||||
func (device *GenericDevice) GetDeviceDrive() interface{} {
|
func (device *GenericDevice) GetDeviceInfo() interface{} {
|
||||||
return device.DeviceInfo
|
return device.DeviceInfo
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ const (
|
|||||||
type VFIODevice struct {
|
type VFIODevice struct {
|
||||||
ID string
|
ID string
|
||||||
DeviceInfo *config.DeviceInfo
|
DeviceInfo *config.DeviceInfo
|
||||||
vfioDrives []*config.VFIODrive
|
vfioDevs []*config.VFIODev
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewVFIODevice create a new VFIO device
|
// NewVFIODevice create a new VFIO device
|
||||||
@ -61,11 +61,11 @@ func (device *VFIODevice) Attach(devReceiver api.DeviceReceiver) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
vfio := &config.VFIODrive{
|
vfio := &config.VFIODev{
|
||||||
ID: utils.MakeNameID("vfio", device.DeviceInfo.ID, maxDevIDSize),
|
ID: utils.MakeNameID("vfio", device.DeviceInfo.ID, maxDevIDSize),
|
||||||
BDF: deviceBDF,
|
BDF: deviceBDF,
|
||||||
}
|
}
|
||||||
device.vfioDrives = append(device.vfioDrives, vfio)
|
device.vfioDevs = append(device.vfioDevs, vfio)
|
||||||
}
|
}
|
||||||
|
|
||||||
// hotplug a VFIO device is actually hotplugging a group of iommu devices
|
// hotplug a VFIO device is actually hotplugging a group of iommu devices
|
||||||
@ -104,9 +104,9 @@ func (device *VFIODevice) DeviceID() string {
|
|||||||
return device.ID
|
return device.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDeviceDrive returns device information used for creating
|
// GetDeviceInfo returns device information used for creating
|
||||||
func (device *VFIODevice) GetDeviceDrive() interface{} {
|
func (device *VFIODevice) GetDeviceInfo() interface{} {
|
||||||
return device.vfioDrives
|
return device.vfioDevs
|
||||||
}
|
}
|
||||||
|
|
||||||
// getBDF returns the BDF of pci device
|
// getBDF returns the BDF of pci device
|
||||||
|
@ -67,8 +67,8 @@ func (device *VhostUserBlkDevice) DeviceType() config.DeviceType {
|
|||||||
return config.VhostUserBlk
|
return config.VhostUserBlk
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDeviceDrive returns device information used for creating
|
// GetDeviceInfo returns device information used for creating
|
||||||
func (device *VhostUserBlkDevice) GetDeviceDrive() interface{} {
|
func (device *VhostUserBlkDevice) GetDeviceInfo() interface{} {
|
||||||
device.Type = device.DeviceType()
|
device.Type = device.DeviceType()
|
||||||
return &device.VhostUserDeviceAttrs
|
return &device.VhostUserDeviceAttrs
|
||||||
}
|
}
|
||||||
|
@ -67,8 +67,8 @@ func (device *VhostUserNetDevice) DeviceType() config.DeviceType {
|
|||||||
return config.VhostUserNet
|
return config.VhostUserNet
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDeviceDrive returns device information used for creating
|
// GetDeviceInfo returns device information used for creating
|
||||||
func (device *VhostUserNetDevice) GetDeviceDrive() interface{} {
|
func (device *VhostUserNetDevice) GetDeviceInfo() interface{} {
|
||||||
device.Type = device.DeviceType()
|
device.Type = device.DeviceType()
|
||||||
return &device.VhostUserDeviceAttrs
|
return &device.VhostUserDeviceAttrs
|
||||||
}
|
}
|
||||||
|
@ -67,8 +67,8 @@ func (device *VhostUserSCSIDevice) DeviceType() config.DeviceType {
|
|||||||
return config.VhostUserSCSI
|
return config.VhostUserSCSI
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDeviceDrive returns device information used for creating
|
// GetDeviceInfo returns device information used for creating
|
||||||
func (device *VhostUserSCSIDevice) GetDeviceDrive() interface{} {
|
func (device *VhostUserSCSIDevice) GetDeviceInfo() interface{} {
|
||||||
device.Type = device.DeviceType()
|
device.Type = device.DeviceType()
|
||||||
return &device.VhostUserDeviceAttrs
|
return &device.VhostUserDeviceAttrs
|
||||||
}
|
}
|
||||||
|
@ -239,7 +239,7 @@ func fsMapFromDevices(c *Container) ([]*hyperstart.FsmapDescriptor, error) {
|
|||||||
return nil, fmt.Errorf("can't find device: %#v", dev)
|
return nil, fmt.Errorf("can't find device: %#v", dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
d, ok := device.GetDeviceDrive().(*config.BlockDrive)
|
d, ok := device.GetDeviceInfo().(*config.BlockDrive)
|
||||||
if !ok || d == nil {
|
if !ok || d == nil {
|
||||||
return nil, fmt.Errorf("can't retrieve block device information")
|
return nil, fmt.Errorf("can't retrieve block device information")
|
||||||
}
|
}
|
||||||
|
@ -733,7 +733,7 @@ func (k *kataAgent) appendDevices(deviceList []*grpc.Device, c *Container) []*gr
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
d, ok := device.GetDeviceDrive().(*config.BlockDrive)
|
d, ok := device.GetDeviceInfo().(*config.BlockDrive)
|
||||||
if !ok || d == nil {
|
if !ok || d == nil {
|
||||||
k.Logger().WithField("device", device).Error("malformed block drive")
|
k.Logger().WithField("device", device).Error("malformed block drive")
|
||||||
continue
|
continue
|
||||||
@ -987,7 +987,7 @@ func (k *kataAgent) handleBlockVolumes(c *Container) []*grpc.Storage {
|
|||||||
k.Logger().WithField("device", id).Error("failed to find device by id")
|
k.Logger().WithField("device", id).Error("failed to find device by id")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
blockDrive, ok := device.GetDeviceDrive().(*config.BlockDrive)
|
blockDrive, ok := device.GetDeviceInfo().(*config.BlockDrive)
|
||||||
if !ok || blockDrive == nil {
|
if !ok || blockDrive == nil {
|
||||||
k.Logger().Error("malformed block drive")
|
k.Logger().Error("malformed block drive")
|
||||||
continue
|
continue
|
||||||
|
@ -345,7 +345,7 @@ func (endpoint *PhysicalEndpoint) Attach(h hypervisor) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: use device manager as general device management entrance
|
// TODO: use device manager as general device management entrance
|
||||||
d := config.VFIODrive{
|
d := config.VFIODev{
|
||||||
BDF: endpoint.BDF,
|
BDF: endpoint.BDF,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -716,7 +716,7 @@ func (q *qemu) hotplugBlockDevice(drive *config.BlockDrive, op operation) error
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *qemu) hotplugVFIODevice(device *config.VFIODrive, op operation) error {
|
func (q *qemu) hotplugVFIODevice(device *config.VFIODev, op operation) error {
|
||||||
err := q.qmpSetup()
|
err := q.qmpSetup()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -755,7 +755,7 @@ func (q *qemu) hotplugDevice(devInfo interface{}, devType deviceType, op operati
|
|||||||
vcpus := devInfo.(uint32)
|
vcpus := devInfo.(uint32)
|
||||||
return q.hotplugCPUs(vcpus, op)
|
return q.hotplugCPUs(vcpus, op)
|
||||||
case vfioDev:
|
case vfioDev:
|
||||||
device := devInfo.(*config.VFIODrive)
|
device := devInfo.(*config.VFIODev)
|
||||||
return nil, q.hotplugVFIODevice(device, op)
|
return nil, q.hotplugVFIODevice(device, op)
|
||||||
case memoryDev:
|
case memoryDev:
|
||||||
memdev := devInfo.(*memoryDevice)
|
memdev := devInfo.(*memoryDevice)
|
||||||
@ -952,7 +952,7 @@ func (q *qemu) addDevice(devInfo interface{}, devType deviceType) error {
|
|||||||
q.qemuConfig.Devices = q.arch.appendBlockDevice(q.qemuConfig.Devices, v)
|
q.qemuConfig.Devices = q.arch.appendBlockDevice(q.qemuConfig.Devices, v)
|
||||||
case config.VhostUserDeviceAttrs:
|
case config.VhostUserDeviceAttrs:
|
||||||
q.qemuConfig.Devices = q.arch.appendVhostUserDevice(q.qemuConfig.Devices, v)
|
q.qemuConfig.Devices = q.arch.appendVhostUserDevice(q.qemuConfig.Devices, v)
|
||||||
case config.VFIODrive:
|
case config.VFIODev:
|
||||||
q.qemuConfig.Devices = q.arch.appendVFIODevice(q.qemuConfig.Devices, v)
|
q.qemuConfig.Devices = q.arch.appendVFIODevice(q.qemuConfig.Devices, v)
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
|
@ -77,7 +77,7 @@ type qemuArch interface {
|
|||||||
appendVhostUserDevice(devices []govmmQemu.Device, drive config.VhostUserDeviceAttrs) []govmmQemu.Device
|
appendVhostUserDevice(devices []govmmQemu.Device, drive config.VhostUserDeviceAttrs) []govmmQemu.Device
|
||||||
|
|
||||||
// appendVFIODevice appends a VFIO device to devices
|
// appendVFIODevice appends a VFIO device to devices
|
||||||
appendVFIODevice(devices []govmmQemu.Device, vfioDevice config.VFIODrive) []govmmQemu.Device
|
appendVFIODevice(devices []govmmQemu.Device, vfioDevice config.VFIODev) []govmmQemu.Device
|
||||||
|
|
||||||
// handleImagePath handles the Hypervisor Config image path
|
// handleImagePath handles the Hypervisor Config image path
|
||||||
handleImagePath(config HypervisorConfig)
|
handleImagePath(config HypervisorConfig)
|
||||||
@ -475,14 +475,14 @@ func (q *qemuArchBase) appendVhostUserDevice(devices []govmmQemu.Device, attr co
|
|||||||
return devices
|
return devices
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *qemuArchBase) appendVFIODevice(devices []govmmQemu.Device, vfioDrive config.VFIODrive) []govmmQemu.Device {
|
func (q *qemuArchBase) appendVFIODevice(devices []govmmQemu.Device, vfioDev config.VFIODev) []govmmQemu.Device {
|
||||||
if vfioDrive.BDF == "" {
|
if vfioDev.BDF == "" {
|
||||||
return devices
|
return devices
|
||||||
}
|
}
|
||||||
|
|
||||||
devices = append(devices,
|
devices = append(devices,
|
||||||
govmmQemu.VFIODevice{
|
govmmQemu.VFIODevice{
|
||||||
BDF: vfioDrive.BDF,
|
BDF: vfioDev.BDF,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@ func testQemuArchBaseAppend(t *testing.T, structure interface{}, expected []govm
|
|||||||
devices = qemuArchBase.appendSocket(devices, s)
|
devices = qemuArchBase.appendSocket(devices, s)
|
||||||
case config.BlockDrive:
|
case config.BlockDrive:
|
||||||
devices = qemuArchBase.appendBlockDevice(devices, s)
|
devices = qemuArchBase.appendBlockDevice(devices, s)
|
||||||
case config.VFIODrive:
|
case config.VFIODev:
|
||||||
devices = qemuArchBase.appendVFIODevice(devices, s)
|
devices = qemuArchBase.appendVFIODevice(devices, s)
|
||||||
case config.VhostUserDeviceAttrs:
|
case config.VhostUserDeviceAttrs:
|
||||||
devices = qemuArchBase.appendVhostUserDevice(devices, s)
|
devices = qemuArchBase.appendVhostUserDevice(devices, s)
|
||||||
@ -406,7 +406,7 @@ func TestQemuArchBaseAppendVFIODevice(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
vfDevice := config.VFIODrive{
|
vfDevice := config.VFIODev{
|
||||||
BDF: bdf,
|
BDF: bdf,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1455,11 +1455,11 @@ func togglePauseSandbox(sandboxID string, pause bool) (*Sandbox, error) {
|
|||||||
func (s *Sandbox) HotplugAddDevice(device api.Device, devType config.DeviceType) error {
|
func (s *Sandbox) HotplugAddDevice(device api.Device, devType config.DeviceType) error {
|
||||||
switch devType {
|
switch devType {
|
||||||
case config.DeviceVFIO:
|
case config.DeviceVFIO:
|
||||||
vfioDevices, ok := device.GetDeviceDrive().([]*config.VFIODrive)
|
vfioDevices, ok := device.GetDeviceInfo().([]*config.VFIODev)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("device type mismatch, expect device type to be %s", devType)
|
return fmt.Errorf("device type mismatch, expect device type to be %s", devType)
|
||||||
}
|
}
|
||||||
addedDev := []*config.VFIODrive{}
|
addedDev := []*config.VFIODev{}
|
||||||
var err error
|
var err error
|
||||||
defer func() {
|
defer func() {
|
||||||
// if err happens,roll back and remove added device!
|
// if err happens,roll back and remove added device!
|
||||||
@ -1511,11 +1511,11 @@ func (s *Sandbox) HotplugAddDevice(device api.Device, devType config.DeviceType)
|
|||||||
func (s *Sandbox) HotplugRemoveDevice(device api.Device, devType config.DeviceType) error {
|
func (s *Sandbox) HotplugRemoveDevice(device api.Device, devType config.DeviceType) error {
|
||||||
switch devType {
|
switch devType {
|
||||||
case config.DeviceVFIO:
|
case config.DeviceVFIO:
|
||||||
vfioDevices, ok := device.GetDeviceDrive().([]*config.VFIODrive)
|
vfioDevices, ok := device.GetDeviceInfo().([]*config.VFIODev)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("device type mismatch, expect device type to be %s", devType)
|
return fmt.Errorf("device type mismatch, expect device type to be %s", devType)
|
||||||
}
|
}
|
||||||
removedDev := []*config.VFIODrive{}
|
removedDev := []*config.VFIODev{}
|
||||||
var err error
|
var err error
|
||||||
defer func() {
|
defer func() {
|
||||||
// if err happens,roll back and add the removed devices back!
|
// if err happens,roll back and add the removed devices back!
|
||||||
@ -1549,7 +1549,7 @@ func (s *Sandbox) HotplugRemoveDevice(device api.Device, devType config.DeviceTy
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
case config.DeviceBlock:
|
case config.DeviceBlock:
|
||||||
blockDrive, ok := device.GetDeviceDrive().(*config.BlockDrive)
|
blockDrive, ok := device.GetDeviceInfo().(*config.BlockDrive)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("device type mismatch, expect device type to be %s", devType)
|
return fmt.Errorf("device type mismatch, expect device type to be %s", devType)
|
||||||
}
|
}
|
||||||
@ -1580,7 +1580,7 @@ func (s *Sandbox) DecrementSandboxBlockIndex() error {
|
|||||||
func (s *Sandbox) AppendDevice(device api.Device) error {
|
func (s *Sandbox) AppendDevice(device api.Device) error {
|
||||||
switch device.DeviceType() {
|
switch device.DeviceType() {
|
||||||
case config.VhostUserSCSI, config.VhostUserNet, config.VhostUserBlk:
|
case config.VhostUserSCSI, config.VhostUserNet, config.VhostUserBlk:
|
||||||
return s.hypervisor.addDevice(device.GetDeviceDrive().(*config.VhostUserDeviceAttrs), vhostuserDev)
|
return s.hypervisor.addDevice(device.GetDeviceInfo().(*config.VhostUserDeviceAttrs), vhostuserDev)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("unsupported device type")
|
return fmt.Errorf("unsupported device type")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user