mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-19 01:39:48 +00:00
vc: hypervisor: use our own logger
This'll end up moving to hypervisors pkg, but let's stop using virtLog, instead introduce hvLogger. Fixes: #2884 Signed-off-by: Eric Ernst <eric_ernst@apple.com>
This commit is contained in:
parent
4c2883f7e2
commit
2227c46c25
@ -35,7 +35,7 @@ var virtLog = logrus.WithField("source", "virtcontainers")
|
|||||||
func SetLogger(ctx context.Context, logger *logrus.Entry) {
|
func SetLogger(ctx context.Context, logger *logrus.Entry) {
|
||||||
fields := virtLog.Data
|
fields := virtLog.Data
|
||||||
virtLog = logger.WithFields(fields)
|
virtLog = logger.WithFields(fields)
|
||||||
|
SetHypervisorLogger(virtLog) // TODO: this will move to hypervisors pkg
|
||||||
deviceApi.SetLogger(virtLog)
|
deviceApi.SetLogger(virtLog)
|
||||||
compatoci.SetLogger(virtLog)
|
compatoci.SetLogger(virtLog)
|
||||||
deviceConfig.SetLogger(virtLog)
|
deviceConfig.SetLogger(virtLog)
|
||||||
|
@ -813,7 +813,7 @@ func (clh *cloudHypervisor) AddDevice(ctx context.Context, devInfo interface{},
|
|||||||
//###########################################################################
|
//###########################################################################
|
||||||
|
|
||||||
func (clh *cloudHypervisor) Logger() *log.Entry {
|
func (clh *cloudHypervisor) Logger() *log.Entry {
|
||||||
return virtLog.WithField("subsystem", "cloudHypervisor")
|
return hvLogger.WithField("subsystem", "cloudHypervisor")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds all capabilities supported by cloudHypervisor implementation of hypervisor interface
|
// Adds all capabilities supported by cloudHypervisor implementation of hypervisor interface
|
||||||
|
@ -18,6 +18,8 @@ import (
|
|||||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config"
|
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config"
|
||||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
|
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
|
||||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils"
|
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HypervisorType describes an hypervisor type.
|
// HypervisorType describes an hypervisor type.
|
||||||
@ -45,14 +47,10 @@ const (
|
|||||||
|
|
||||||
// MockHypervisor is a mock hypervisor for testing purposes
|
// MockHypervisor is a mock hypervisor for testing purposes
|
||||||
MockHypervisor HypervisorType = "mock"
|
MockHypervisor HypervisorType = "mock"
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
procMemInfo = "/proc/meminfo"
|
procMemInfo = "/proc/meminfo"
|
||||||
procCPUInfo = "/proc/cpuinfo"
|
procCPUInfo = "/proc/cpuinfo"
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
defaultVCPUs = 1
|
defaultVCPUs = 1
|
||||||
// 2 GiB
|
// 2 GiB
|
||||||
defaultMemSzMiB = 2048
|
defaultMemSzMiB = 2048
|
||||||
@ -73,6 +71,10 @@ const (
|
|||||||
MinHypervisorMemory = 256
|
MinHypervisorMemory = 256
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
hvLogger = logrus.WithField("source", "virtcontainers/hypervisor")
|
||||||
|
)
|
||||||
|
|
||||||
// In some architectures the maximum number of vCPUs depends on the number of physical cores.
|
// In some architectures the maximum number of vCPUs depends on the number of physical cores.
|
||||||
var defaultMaxQemuVCPUs = MaxQemuVCPUs()
|
var defaultMaxQemuVCPUs = MaxQemuVCPUs()
|
||||||
|
|
||||||
@ -143,6 +145,12 @@ type MemoryDevice struct {
|
|||||||
Probe bool
|
Probe bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetHypervisorLogger sets up a logger for the hypervisor part of this pkg
|
||||||
|
func SetHypervisorLogger(logger *logrus.Entry) {
|
||||||
|
fields := hvLogger.Data
|
||||||
|
hvLogger = logger.WithFields(fields)
|
||||||
|
}
|
||||||
|
|
||||||
// Set sets an hypervisor type based on the input string.
|
// Set sets an hypervisor type based on the input string.
|
||||||
func (hType *HypervisorType) Set(value string) error {
|
func (hType *HypervisorType) Set(value string) error {
|
||||||
switch value {
|
switch value {
|
||||||
@ -604,7 +612,7 @@ func (conf *HypervisorConfig) AddCustomAsset(a *types.Asset) error {
|
|||||||
return fmt.Errorf("Invalid %s at %s", a.Type(), a.Path())
|
return fmt.Errorf("Invalid %s at %s", a.Type(), a.Path())
|
||||||
}
|
}
|
||||||
|
|
||||||
virtLog.Debugf("Using custom %v asset %s", a.Type(), a.Path())
|
hvLogger.Debugf("Using custom %v asset %s", a.Type(), a.Path())
|
||||||
|
|
||||||
if conf.customAssets == nil {
|
if conf.customAssets == nil {
|
||||||
conf.customAssets = make(map[types.AssetType]*types.Asset)
|
conf.customAssets = make(map[types.AssetType]*types.Asset)
|
||||||
@ -872,7 +880,7 @@ func RunningOnVMM(cpuInfoPath string) (bool, error) {
|
|||||||
return flags["hypervisor"], nil
|
return flags["hypervisor"], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
virtLog.WithField("arch", runtime.GOARCH).Info("Unable to know if the system is running inside a VM")
|
hvLogger.WithField("arch", runtime.GOARCH).Info("Unable to know if the system is running inside a VM")
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@ type qmpLogger struct {
|
|||||||
|
|
||||||
func newQMPLogger() qmpLogger {
|
func newQMPLogger() qmpLogger {
|
||||||
return qmpLogger{
|
return qmpLogger{
|
||||||
logger: virtLog.WithField("subsystem", "qmp"),
|
logger: hvLogger.WithField("subsystem", "qmp"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,7 +163,7 @@ func (l qmpLogger) Errorf(format string, v ...interface{}) {
|
|||||||
|
|
||||||
// Logger returns a logrus logger appropriate for logging qemu messages
|
// Logger returns a logrus logger appropriate for logging qemu messages
|
||||||
func (q *qemu) Logger() *logrus.Entry {
|
func (q *qemu) Logger() *logrus.Entry {
|
||||||
return virtLog.WithField("subsystem", "qemu")
|
return hvLogger.WithField("subsystem", "qemu")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *qemu) kernelParameters() string {
|
func (q *qemu) kernelParameters() string {
|
||||||
|
@ -169,7 +169,7 @@ func (q *qemuAmd64) cpuModel() string {
|
|||||||
// VMX is not migratable yet.
|
// VMX is not migratable yet.
|
||||||
// issue: https://github.com/kata-containers/runtime/issues/1750
|
// issue: https://github.com/kata-containers/runtime/issues/1750
|
||||||
if q.vmFactory {
|
if q.vmFactory {
|
||||||
virtLog.WithField("subsystem", "qemuAmd64").Warn("VMX is not migratable yet: turning it off")
|
hvLogger.WithField("subsystem", "qemuAmd64").Warn("VMX is not migratable yet: turning it off")
|
||||||
cpuModel += ",vmx=off"
|
cpuModel += ",vmx=off"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,7 +200,7 @@ func (q *qemuAmd64) enableProtection() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
logger := virtLog.WithFields(logrus.Fields{
|
logger := hvLogger.WithFields(logrus.Fields{
|
||||||
"subsystem": "qemuAmd64",
|
"subsystem": "qemuAmd64",
|
||||||
"machine": q.qemuMachine,
|
"machine": q.qemuMachine,
|
||||||
"kernel-params-debug": q.kernelParamsDebug,
|
"kernel-params-debug": q.kernelParamsDebug,
|
||||||
|
@ -846,6 +846,6 @@ func (q *qemuArchBase) setPFlash(p []string) {
|
|||||||
|
|
||||||
// append protection device
|
// append protection device
|
||||||
func (q *qemuArchBase) appendProtectionDevice(devices []govmmQemu.Device, firmware string) ([]govmmQemu.Device, string, error) {
|
func (q *qemuArchBase) appendProtectionDevice(devices []govmmQemu.Device, firmware string) ([]govmmQemu.Device, string, error) {
|
||||||
virtLog.WithField("arch", runtime.GOARCH).Warnf("Confidential Computing has not been implemented for this architecture")
|
hvLogger.WithField("arch", runtime.GOARCH).Warnf("Confidential Computing has not been implemented for this architecture")
|
||||||
return devices, firmware, nil
|
return devices, firmware, nil
|
||||||
}
|
}
|
||||||
|
@ -171,6 +171,6 @@ func (q *qemuArm64) enableProtection() error {
|
|||||||
|
|
||||||
func (q *qemuArm64) appendProtectionDevice(devices []govmmQemu.Device, firmware string) ([]govmmQemu.Device, string, error) {
|
func (q *qemuArm64) appendProtectionDevice(devices []govmmQemu.Device, firmware string) ([]govmmQemu.Device, string, error) {
|
||||||
err := q.enableProtection()
|
err := q.enableProtection()
|
||||||
virtLog.WithField("arch", runtime.GOARCH).Warnf("%v", err)
|
hvLogger.WithField("arch", runtime.GOARCH).Warnf("%v", err)
|
||||||
return devices, firmware, err
|
return devices, firmware, err
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ var supportedQemuMachine = govmmQemu.Machine{
|
|||||||
|
|
||||||
// Logger returns a logrus logger appropriate for logging qemu messages
|
// Logger returns a logrus logger appropriate for logging qemu messages
|
||||||
func (q *qemuPPC64le) Logger() *logrus.Entry {
|
func (q *qemuPPC64le) Logger() *logrus.Entry {
|
||||||
return virtLog.WithField("subsystem", "qemuPPC64le")
|
return hvLogger.WithField("subsystem", "qemuPPC64le")
|
||||||
}
|
}
|
||||||
|
|
||||||
// MaxQemuVCPUs returns the maximum number of vCPUs supported
|
// MaxQemuVCPUs returns the maximum number of vCPUs supported
|
||||||
@ -141,7 +141,7 @@ func (q *qemuPPC64le) enableProtection() error {
|
|||||||
q.qemuMachine.Options += ","
|
q.qemuMachine.Options += ","
|
||||||
}
|
}
|
||||||
q.qemuMachine.Options += fmt.Sprintf("confidential-guest-support=%s", pefID)
|
q.qemuMachine.Options += fmt.Sprintf("confidential-guest-support=%s", pefID)
|
||||||
virtLog.WithFields(logrus.Fields{
|
hvLogger.WithFields(logrus.Fields{
|
||||||
"subsystem": "qemuPPC64le",
|
"subsystem": "qemuPPC64le",
|
||||||
"machine": q.qemuMachine,
|
"machine": q.qemuMachine,
|
||||||
"kernel-params": q.kernelParams,
|
"kernel-params": q.kernelParams,
|
||||||
|
@ -324,7 +324,7 @@ func (q *qemuS390x) enableProtection() error {
|
|||||||
q.qemuMachine.Options += ","
|
q.qemuMachine.Options += ","
|
||||||
}
|
}
|
||||||
q.qemuMachine.Options += fmt.Sprintf("confidential-guest-support=%s", secExecID)
|
q.qemuMachine.Options += fmt.Sprintf("confidential-guest-support=%s", secExecID)
|
||||||
virtLog.WithFields(logrus.Fields{
|
hvLogger.WithFields(logrus.Fields{
|
||||||
"subsystem": logSubsystem,
|
"subsystem": logSubsystem,
|
||||||
"machine": q.qemuMachine}).
|
"machine": q.qemuMachine}).
|
||||||
Info("Enabling guest protection with Secure Execution")
|
Info("Enabling guest protection with Secure Execution")
|
||||||
|
@ -216,7 +216,7 @@ func (v *virtiofsd) valid() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v *virtiofsd) Logger() *log.Entry {
|
func (v *virtiofsd) Logger() *log.Entry {
|
||||||
return virtLog.WithField("subsystem", "virtiofsd")
|
return hvLogger.WithField("subsystem", "virtiofsd")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *virtiofsd) kill(ctx context.Context) (err error) {
|
func (v *virtiofsd) kill(ctx context.Context) (err error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user