mirror of
https://github.com/aljazceru/kata-containers.git
synced 2026-01-07 16:34:28 +01:00
Fixes #50 Previously the devices are created with device manager and laterly attached to hypervisor with "device.Attach()", this could work, but there's no way to remember the reference count for every device, which means if we plug one device to hypervisor twice, it's truly inserted twice, but actually we only need to insert once but use it in many places. Use device manager as a consolidated entrypoint of device management can give us a way to handle many "references" to single device, because it can save all devices and remember it's use count. Signed-off-by: Wei Zhang <zhangwei555@huawei.com>
62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
// Copyright (c) 2017-2018 Intel Corporation
|
|
// Copyright (c) 2018 Huawei Corporation
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package drivers
|
|
|
|
import (
|
|
"github.com/kata-containers/runtime/virtcontainers/device/api"
|
|
"github.com/kata-containers/runtime/virtcontainers/device/config"
|
|
)
|
|
|
|
// GenericDevice refers to a device that is neither a VFIO device or block device.
|
|
type GenericDevice struct {
|
|
ID string
|
|
DeviceInfo *config.DeviceInfo
|
|
}
|
|
|
|
// NewGenericDevice creates a new GenericDevice
|
|
func NewGenericDevice(devInfo *config.DeviceInfo) *GenericDevice {
|
|
return &GenericDevice{
|
|
ID: devInfo.ID,
|
|
DeviceInfo: devInfo,
|
|
}
|
|
}
|
|
|
|
// Attach is standard interface of api.Device
|
|
func (device *GenericDevice) Attach(devReceiver api.DeviceReceiver) error {
|
|
return nil
|
|
}
|
|
|
|
// Detach is standard interface of api.Device
|
|
func (device *GenericDevice) Detach(devReceiver api.DeviceReceiver) error {
|
|
return nil
|
|
}
|
|
|
|
// IsAttached checks if the device is attached
|
|
func (device *GenericDevice) IsAttached() bool {
|
|
return device.DeviceInfo.Hotplugged
|
|
}
|
|
|
|
// DeviceID returns device ID
|
|
func (device *GenericDevice) DeviceID() string {
|
|
return device.ID
|
|
}
|
|
|
|
// DeviceType is standard interface of api.Device, it returns device type
|
|
func (device *GenericDevice) DeviceType() config.DeviceType {
|
|
return config.DeviceGeneric
|
|
}
|
|
|
|
// GetDeviceInfo returns device information that the device is created based on
|
|
func (device *GenericDevice) GetDeviceInfo() *config.DeviceInfo {
|
|
return device.DeviceInfo
|
|
}
|
|
|
|
// GetDeviceDrive returns device information used for creating
|
|
func (device *GenericDevice) GetDeviceDrive() interface{} {
|
|
return device.DeviceInfo
|
|
}
|