mirror of
https://github.com/aljazceru/kata-containers.git
synced 2026-01-03 22:44:24 +01:00
Now that the `SetLogger()` functions accept a `logrus.Entry`, they can access the fields that have already been set for the logger and re-apply them if `SetLogger()` is called multiple times. This fixes a bug whereby the logger functions -- which are necessarily called multiple times [1] -- previously ended up applying any new fields the specified logger contained, but erroneously removing any additional fields added since `SetLogger()` was last called. Partially fixes #519. -- [1] - https://github.com/kata-containers/runtime/pull/468 Signed-off-by: James O. D. Hunt <james.o.hunt@intel.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.WithField("subsystem", "device")
|
|
|
|
// SetLogger sets the logger for device api package.
|
|
func SetLogger(logger *logrus.Entry) {
|
|
fields := devLogger.Data
|
|
devLogger = logger.WithFields(fields)
|
|
}
|
|
|
|
// DeviceLogger returns logger for device management
|
|
func DeviceLogger() *logrus.Entry {
|
|
return devLogger
|
|
}
|
|
|
|
// 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 and virtio-scsi 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 {
|
|
NewDevices(devInfos []config.DeviceInfo) ([]Device, error)
|
|
}
|