mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-30 01:02:33 +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
|
||||
// e.g. block, vfio or vhost user
|
||||
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
|
||||
// e.g. Block device returns *config.BlockDrive and
|
||||
// vfio device returns *config.VFIODrive
|
||||
GetDeviceDrive() interface{}
|
||||
// vfio device returns []*config.VFIODev
|
||||
GetDeviceInfo() interface{}
|
||||
// IsAttached checks if the device is attached
|
||||
IsAttached() bool
|
||||
}
|
||||
|
@ -113,8 +113,8 @@ type BlockDrive struct {
|
||||
VirtPath string
|
||||
}
|
||||
|
||||
// VFIODrive represents a VFIO drive used for hotplugging
|
||||
type VFIODrive struct {
|
||||
// VFIODev represents a VFIO drive used for hotplugging
|
||||
type VFIODev struct {
|
||||
// ID is used to identify this drive in the hypervisor options.
|
||||
ID string
|
||||
// BDF (Bus:Device.Function) of the PCI address
|
||||
|
@ -112,7 +112,7 @@ func (device *BlockDevice) DeviceID() string {
|
||||
return device.ID
|
||||
}
|
||||
|
||||
// GetDeviceDrive returns device information used for creating
|
||||
func (device *BlockDevice) GetDeviceDrive() interface{} {
|
||||
// GetDeviceInfo returns device information used for creating
|
||||
func (device *BlockDevice) GetDeviceInfo() interface{} {
|
||||
return device.BlockDrive
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ func (device *GenericDevice) DeviceType() config.DeviceType {
|
||||
return config.DeviceGeneric
|
||||
}
|
||||
|
||||
// GetDeviceDrive returns device information used for creating
|
||||
func (device *GenericDevice) GetDeviceDrive() interface{} {
|
||||
// GetDeviceInfo returns device information used for creating
|
||||
func (device *GenericDevice) GetDeviceInfo() interface{} {
|
||||
return device.DeviceInfo
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ const (
|
||||
type VFIODevice struct {
|
||||
ID string
|
||||
DeviceInfo *config.DeviceInfo
|
||||
vfioDrives []*config.VFIODrive
|
||||
vfioDevs []*config.VFIODev
|
||||
}
|
||||
|
||||
// NewVFIODevice create a new VFIO device
|
||||
@ -61,11 +61,11 @@ func (device *VFIODevice) Attach(devReceiver api.DeviceReceiver) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
vfio := &config.VFIODrive{
|
||||
vfio := &config.VFIODev{
|
||||
ID: utils.MakeNameID("vfio", device.DeviceInfo.ID, maxDevIDSize),
|
||||
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
|
||||
@ -104,9 +104,9 @@ func (device *VFIODevice) DeviceID() string {
|
||||
return device.ID
|
||||
}
|
||||
|
||||
// GetDeviceDrive returns device information used for creating
|
||||
func (device *VFIODevice) GetDeviceDrive() interface{} {
|
||||
return device.vfioDrives
|
||||
// GetDeviceInfo returns device information used for creating
|
||||
func (device *VFIODevice) GetDeviceInfo() interface{} {
|
||||
return device.vfioDevs
|
||||
}
|
||||
|
||||
// getBDF returns the BDF of pci device
|
||||
|
@ -67,8 +67,8 @@ func (device *VhostUserBlkDevice) DeviceType() config.DeviceType {
|
||||
return config.VhostUserBlk
|
||||
}
|
||||
|
||||
// GetDeviceDrive returns device information used for creating
|
||||
func (device *VhostUserBlkDevice) GetDeviceDrive() interface{} {
|
||||
// GetDeviceInfo returns device information used for creating
|
||||
func (device *VhostUserBlkDevice) GetDeviceInfo() interface{} {
|
||||
device.Type = device.DeviceType()
|
||||
return &device.VhostUserDeviceAttrs
|
||||
}
|
||||
|
@ -67,8 +67,8 @@ func (device *VhostUserNetDevice) DeviceType() config.DeviceType {
|
||||
return config.VhostUserNet
|
||||
}
|
||||
|
||||
// GetDeviceDrive returns device information used for creating
|
||||
func (device *VhostUserNetDevice) GetDeviceDrive() interface{} {
|
||||
// GetDeviceInfo returns device information used for creating
|
||||
func (device *VhostUserNetDevice) GetDeviceInfo() interface{} {
|
||||
device.Type = device.DeviceType()
|
||||
return &device.VhostUserDeviceAttrs
|
||||
}
|
||||
|
@ -67,8 +67,8 @@ func (device *VhostUserSCSIDevice) DeviceType() config.DeviceType {
|
||||
return config.VhostUserSCSI
|
||||
}
|
||||
|
||||
// GetDeviceDrive returns device information used for creating
|
||||
func (device *VhostUserSCSIDevice) GetDeviceDrive() interface{} {
|
||||
// GetDeviceInfo returns device information used for creating
|
||||
func (device *VhostUserSCSIDevice) GetDeviceInfo() interface{} {
|
||||
device.Type = device.DeviceType()
|
||||
return &device.VhostUserDeviceAttrs
|
||||
}
|
||||
|
@ -239,7 +239,7 @@ func fsMapFromDevices(c *Container) ([]*hyperstart.FsmapDescriptor, error) {
|
||||
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 {
|
||||
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
|
||||
}
|
||||
|
||||
d, ok := device.GetDeviceDrive().(*config.BlockDrive)
|
||||
d, ok := device.GetDeviceInfo().(*config.BlockDrive)
|
||||
if !ok || d == nil {
|
||||
k.Logger().WithField("device", device).Error("malformed block drive")
|
||||
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")
|
||||
return nil
|
||||
}
|
||||
blockDrive, ok := device.GetDeviceDrive().(*config.BlockDrive)
|
||||
blockDrive, ok := device.GetDeviceInfo().(*config.BlockDrive)
|
||||
if !ok || blockDrive == nil {
|
||||
k.Logger().Error("malformed block drive")
|
||||
continue
|
||||
|
@ -345,7 +345,7 @@ func (endpoint *PhysicalEndpoint) Attach(h hypervisor) error {
|
||||
}
|
||||
|
||||
// TODO: use device manager as general device management entrance
|
||||
d := config.VFIODrive{
|
||||
d := config.VFIODev{
|
||||
BDF: endpoint.BDF,
|
||||
}
|
||||
|
||||
|
@ -716,7 +716,7 @@ func (q *qemu) hotplugBlockDevice(drive *config.BlockDrive, op operation) error
|
||||
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()
|
||||
if err != nil {
|
||||
return err
|
||||
@ -755,7 +755,7 @@ func (q *qemu) hotplugDevice(devInfo interface{}, devType deviceType, op operati
|
||||
vcpus := devInfo.(uint32)
|
||||
return q.hotplugCPUs(vcpus, op)
|
||||
case vfioDev:
|
||||
device := devInfo.(*config.VFIODrive)
|
||||
device := devInfo.(*config.VFIODev)
|
||||
return nil, q.hotplugVFIODevice(device, op)
|
||||
case memoryDev:
|
||||
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)
|
||||
case config.VhostUserDeviceAttrs:
|
||||
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)
|
||||
default:
|
||||
break
|
||||
|
@ -77,7 +77,7 @@ type qemuArch interface {
|
||||
appendVhostUserDevice(devices []govmmQemu.Device, drive config.VhostUserDeviceAttrs) []govmmQemu.Device
|
||||
|
||||
// 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(config HypervisorConfig)
|
||||
@ -475,14 +475,14 @@ func (q *qemuArchBase) appendVhostUserDevice(devices []govmmQemu.Device, attr co
|
||||
return devices
|
||||
}
|
||||
|
||||
func (q *qemuArchBase) appendVFIODevice(devices []govmmQemu.Device, vfioDrive config.VFIODrive) []govmmQemu.Device {
|
||||
if vfioDrive.BDF == "" {
|
||||
func (q *qemuArchBase) appendVFIODevice(devices []govmmQemu.Device, vfioDev config.VFIODev) []govmmQemu.Device {
|
||||
if vfioDev.BDF == "" {
|
||||
return devices
|
||||
}
|
||||
|
||||
devices = append(devices,
|
||||
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)
|
||||
case config.BlockDrive:
|
||||
devices = qemuArchBase.appendBlockDevice(devices, s)
|
||||
case config.VFIODrive:
|
||||
case config.VFIODev:
|
||||
devices = qemuArchBase.appendVFIODevice(devices, s)
|
||||
case config.VhostUserDeviceAttrs:
|
||||
devices = qemuArchBase.appendVhostUserDevice(devices, s)
|
||||
@ -406,7 +406,7 @@ func TestQemuArchBaseAppendVFIODevice(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
vfDevice := config.VFIODrive{
|
||||
vfDevice := config.VFIODev{
|
||||
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 {
|
||||
switch devType {
|
||||
case config.DeviceVFIO:
|
||||
vfioDevices, ok := device.GetDeviceDrive().([]*config.VFIODrive)
|
||||
vfioDevices, ok := device.GetDeviceInfo().([]*config.VFIODev)
|
||||
if !ok {
|
||||
return fmt.Errorf("device type mismatch, expect device type to be %s", devType)
|
||||
}
|
||||
addedDev := []*config.VFIODrive{}
|
||||
addedDev := []*config.VFIODev{}
|
||||
var err error
|
||||
defer func() {
|
||||
// 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 {
|
||||
switch devType {
|
||||
case config.DeviceVFIO:
|
||||
vfioDevices, ok := device.GetDeviceDrive().([]*config.VFIODrive)
|
||||
vfioDevices, ok := device.GetDeviceInfo().([]*config.VFIODev)
|
||||
if !ok {
|
||||
return fmt.Errorf("device type mismatch, expect device type to be %s", devType)
|
||||
}
|
||||
removedDev := []*config.VFIODrive{}
|
||||
removedDev := []*config.VFIODev{}
|
||||
var err error
|
||||
defer func() {
|
||||
// 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
|
||||
case config.DeviceBlock:
|
||||
blockDrive, ok := device.GetDeviceDrive().(*config.BlockDrive)
|
||||
blockDrive, ok := device.GetDeviceInfo().(*config.BlockDrive)
|
||||
if !ok {
|
||||
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 {
|
||||
switch device.DeviceType() {
|
||||
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")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user