mirror of
https://github.com/aljazceru/kata-containers.git
synced 2025-12-22 16:54:25 +01:00
Fixes #50 This is done for decoupling device management part from other parts. It seperate device.go to several dirs and files: ``` virtcontainers/device ├── api │ └── interface.go ├── config │ └── config.go ├── drivers │ ├── block.go │ ├── generic.go │ ├── utils.go │ ├── vfio.go │ ├── vhost_user_blk.go │ ├── vhost_user.go │ ├── vhost_user_net.go │ └── vhost_user_scsi.go └── manager ├── manager.go └── utils.go ``` * `api` contains interface definition of device management, so upper level caller should import and use the interface, and lower level should implement the interface. it's bridge to device drivers and callers. * `config` contains structed exported data. * `drivers` contains specific device drivers including block, vfio and vhost user devices. * `manager` exposes an external management package with a `DeviceManager`. Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
63 lines
1.7 KiB
Go
63 lines
1.7 KiB
Go
// Copyright (c) 2017-2018 Intel Corporation
|
|
// Copyright (c) 2018 Huawei Corporation
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package api
|
|
|
|
import (
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/kata-containers/runtime/virtcontainers/device/config"
|
|
)
|
|
|
|
var devLogger = logrus.FieldLogger(logrus.New())
|
|
|
|
// SetLogger sets the logger for virtcontainers package.
|
|
func SetLogger(logger logrus.FieldLogger) {
|
|
devLogger = logger
|
|
}
|
|
|
|
// DeviceLogger returns logger for device management
|
|
func DeviceLogger() *logrus.Entry {
|
|
return devLogger.WithField("subsystem", "device")
|
|
}
|
|
|
|
// DeviceReceiver is an interface used for accepting devices
|
|
// a device should be attached/added/plugged to a DeviceReceiver
|
|
type DeviceReceiver interface {
|
|
HotplugAddDevice(Device, config.DeviceType) error
|
|
HotplugRemoveDevice(Device, config.DeviceType) error
|
|
|
|
// this is only for virtio-blk support
|
|
GetAndSetSandboxBlockIndex() (int, error)
|
|
DecrementSandboxBlockIndex() error
|
|
|
|
// this is for vhost_user devices
|
|
AddVhostUserDevice(VhostUserDevice, config.DeviceType) error
|
|
}
|
|
|
|
// VhostUserDevice represents a vhost-user device. Shared
|
|
// attributes of a vhost-user device can be retrieved using
|
|
// the Attrs() method. Unique data can be obtained by casting
|
|
// the object to the proper type.
|
|
type VhostUserDevice interface {
|
|
Attrs() *config.VhostUserDeviceAttrs
|
|
Type() config.DeviceType
|
|
}
|
|
|
|
// Device is the virtcontainers device interface.
|
|
type Device interface {
|
|
Attach(DeviceReceiver) error
|
|
Detach(DeviceReceiver) error
|
|
DeviceType() config.DeviceType
|
|
}
|
|
|
|
// DeviceManager can be used to create a new device, this can be used as single
|
|
// device management object.
|
|
type DeviceManager interface {
|
|
CreateDevice(devInfo config.DeviceInfo) Device
|
|
NewDevices(devInfos []config.DeviceInfo) ([]Device, error)
|
|
}
|