diff --git a/virtcontainers/device/api/interface.go b/virtcontainers/device/api/interface.go index 6d67d03606..a4874b40d5 100644 --- a/virtcontainers/device/api/interface.go +++ b/virtcontainers/device/api/interface.go @@ -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 } diff --git a/virtcontainers/device/config/config.go b/virtcontainers/device/config/config.go index c6fe712085..d9c3dfe934 100644 --- a/virtcontainers/device/config/config.go +++ b/virtcontainers/device/config/config.go @@ -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 diff --git a/virtcontainers/device/drivers/block.go b/virtcontainers/device/drivers/block.go index 518425f1ee..b7d36a7fd5 100644 --- a/virtcontainers/device/drivers/block.go +++ b/virtcontainers/device/drivers/block.go @@ -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 } diff --git a/virtcontainers/device/drivers/generic.go b/virtcontainers/device/drivers/generic.go index ccb43f34b8..50e65e0908 100644 --- a/virtcontainers/device/drivers/generic.go +++ b/virtcontainers/device/drivers/generic.go @@ -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 } diff --git a/virtcontainers/device/drivers/vfio.go b/virtcontainers/device/drivers/vfio.go index e47e940bb2..72a3cedc89 100644 --- a/virtcontainers/device/drivers/vfio.go +++ b/virtcontainers/device/drivers/vfio.go @@ -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 diff --git a/virtcontainers/device/drivers/vhost_user_blk.go b/virtcontainers/device/drivers/vhost_user_blk.go index ea1a22530e..fea18a36f5 100644 --- a/virtcontainers/device/drivers/vhost_user_blk.go +++ b/virtcontainers/device/drivers/vhost_user_blk.go @@ -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 } diff --git a/virtcontainers/device/drivers/vhost_user_net.go b/virtcontainers/device/drivers/vhost_user_net.go index 663e72a217..5402760516 100644 --- a/virtcontainers/device/drivers/vhost_user_net.go +++ b/virtcontainers/device/drivers/vhost_user_net.go @@ -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 } diff --git a/virtcontainers/device/drivers/vhost_user_scsi.go b/virtcontainers/device/drivers/vhost_user_scsi.go index 98bac82d52..690981b1c5 100644 --- a/virtcontainers/device/drivers/vhost_user_scsi.go +++ b/virtcontainers/device/drivers/vhost_user_scsi.go @@ -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 } diff --git a/virtcontainers/hyperstart_agent.go b/virtcontainers/hyperstart_agent.go index c82610f1d9..43cefc71e0 100644 --- a/virtcontainers/hyperstart_agent.go +++ b/virtcontainers/hyperstart_agent.go @@ -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") } diff --git a/virtcontainers/kata_agent.go b/virtcontainers/kata_agent.go index 9f3c5eb78a..25cd776146 100644 --- a/virtcontainers/kata_agent.go +++ b/virtcontainers/kata_agent.go @@ -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 diff --git a/virtcontainers/network.go b/virtcontainers/network.go index 6381d46201..4ae7cff0b0 100644 --- a/virtcontainers/network.go +++ b/virtcontainers/network.go @@ -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, } diff --git a/virtcontainers/qemu.go b/virtcontainers/qemu.go index 7fb56d4a20..0020bc101f 100644 --- a/virtcontainers/qemu.go +++ b/virtcontainers/qemu.go @@ -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 diff --git a/virtcontainers/qemu_arch_base.go b/virtcontainers/qemu_arch_base.go index 6c556441be..6396cbe1d7 100644 --- a/virtcontainers/qemu_arch_base.go +++ b/virtcontainers/qemu_arch_base.go @@ -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, }, ) diff --git a/virtcontainers/qemu_arch_base_test.go b/virtcontainers/qemu_arch_base_test.go index 3c35c81676..3465f8cdad 100644 --- a/virtcontainers/qemu_arch_base_test.go +++ b/virtcontainers/qemu_arch_base_test.go @@ -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, } diff --git a/virtcontainers/sandbox.go b/virtcontainers/sandbox.go index 44c690c3c7..0e8ae6ca3b 100644 --- a/virtcontainers/sandbox.go +++ b/virtcontainers/sandbox.go @@ -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") }