From 2227c46c25530ce12916bf3d7ac9e6ba46fad003 Mon Sep 17 00:00:00 2001 From: Eric Ernst Date: Thu, 11 Nov 2021 16:46:14 -0800 Subject: [PATCH] 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 --- src/runtime/virtcontainers/api.go | 2 +- src/runtime/virtcontainers/clh.go | 2 +- src/runtime/virtcontainers/hypervisor.go | 20 ++++++++++++++------ src/runtime/virtcontainers/qemu.go | 4 ++-- src/runtime/virtcontainers/qemu_amd64.go | 4 ++-- src/runtime/virtcontainers/qemu_arch_base.go | 2 +- src/runtime/virtcontainers/qemu_arm64.go | 2 +- src/runtime/virtcontainers/qemu_ppc64le.go | 4 ++-- src/runtime/virtcontainers/qemu_s390x.go | 2 +- src/runtime/virtcontainers/virtiofsd.go | 2 +- 10 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/runtime/virtcontainers/api.go b/src/runtime/virtcontainers/api.go index 67e7608ac..14cfbb109 100644 --- a/src/runtime/virtcontainers/api.go +++ b/src/runtime/virtcontainers/api.go @@ -35,7 +35,7 @@ var virtLog = logrus.WithField("source", "virtcontainers") func SetLogger(ctx context.Context, logger *logrus.Entry) { fields := virtLog.Data virtLog = logger.WithFields(fields) - + SetHypervisorLogger(virtLog) // TODO: this will move to hypervisors pkg deviceApi.SetLogger(virtLog) compatoci.SetLogger(virtLog) deviceConfig.SetLogger(virtLog) diff --git a/src/runtime/virtcontainers/clh.go b/src/runtime/virtcontainers/clh.go index e4ca0a006..7fad500f5 100644 --- a/src/runtime/virtcontainers/clh.go +++ b/src/runtime/virtcontainers/clh.go @@ -813,7 +813,7 @@ func (clh *cloudHypervisor) AddDevice(ctx context.Context, devInfo interface{}, //########################################################################### 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 diff --git a/src/runtime/virtcontainers/hypervisor.go b/src/runtime/virtcontainers/hypervisor.go index f446a078b..06a0385c9 100644 --- a/src/runtime/virtcontainers/hypervisor.go +++ b/src/runtime/virtcontainers/hypervisor.go @@ -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/types" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils" + + "github.com/sirupsen/logrus" ) // HypervisorType describes an hypervisor type. @@ -45,14 +47,10 @@ const ( // MockHypervisor is a mock hypervisor for testing purposes MockHypervisor HypervisorType = "mock" -) -const ( procMemInfo = "/proc/meminfo" procCPUInfo = "/proc/cpuinfo" -) -const ( defaultVCPUs = 1 // 2 GiB defaultMemSzMiB = 2048 @@ -73,6 +71,10 @@ const ( MinHypervisorMemory = 256 ) +var ( + hvLogger = logrus.WithField("source", "virtcontainers/hypervisor") +) + // In some architectures the maximum number of vCPUs depends on the number of physical cores. var defaultMaxQemuVCPUs = MaxQemuVCPUs() @@ -143,6 +145,12 @@ type MemoryDevice struct { 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. func (hType *HypervisorType) Set(value string) error { 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()) } - 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 { conf.customAssets = make(map[types.AssetType]*types.Asset) @@ -872,7 +880,7 @@ func RunningOnVMM(cpuInfoPath string) (bool, error) { 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 } diff --git a/src/runtime/virtcontainers/qemu.go b/src/runtime/virtcontainers/qemu.go index 1c1073b24..d0b3bd5c5 100644 --- a/src/runtime/virtcontainers/qemu.go +++ b/src/runtime/virtcontainers/qemu.go @@ -141,7 +141,7 @@ type qmpLogger struct { func newQMPLogger() 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 func (q *qemu) Logger() *logrus.Entry { - return virtLog.WithField("subsystem", "qemu") + return hvLogger.WithField("subsystem", "qemu") } func (q *qemu) kernelParameters() string { diff --git a/src/runtime/virtcontainers/qemu_amd64.go b/src/runtime/virtcontainers/qemu_amd64.go index 689575ab5..c1464809a 100644 --- a/src/runtime/virtcontainers/qemu_amd64.go +++ b/src/runtime/virtcontainers/qemu_amd64.go @@ -169,7 +169,7 @@ func (q *qemuAmd64) cpuModel() string { // VMX is not migratable yet. // issue: https://github.com/kata-containers/runtime/issues/1750 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" } @@ -200,7 +200,7 @@ func (q *qemuAmd64) enableProtection() error { if err != nil { return err } - logger := virtLog.WithFields(logrus.Fields{ + logger := hvLogger.WithFields(logrus.Fields{ "subsystem": "qemuAmd64", "machine": q.qemuMachine, "kernel-params-debug": q.kernelParamsDebug, diff --git a/src/runtime/virtcontainers/qemu_arch_base.go b/src/runtime/virtcontainers/qemu_arch_base.go index 426da6bac..97cd6eb83 100644 --- a/src/runtime/virtcontainers/qemu_arch_base.go +++ b/src/runtime/virtcontainers/qemu_arch_base.go @@ -846,6 +846,6 @@ func (q *qemuArchBase) setPFlash(p []string) { // append protection device 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 } diff --git a/src/runtime/virtcontainers/qemu_arm64.go b/src/runtime/virtcontainers/qemu_arm64.go index 2cd869a8c..452493ce1 100644 --- a/src/runtime/virtcontainers/qemu_arm64.go +++ b/src/runtime/virtcontainers/qemu_arm64.go @@ -171,6 +171,6 @@ func (q *qemuArm64) enableProtection() error { func (q *qemuArm64) appendProtectionDevice(devices []govmmQemu.Device, firmware string) ([]govmmQemu.Device, string, error) { err := q.enableProtection() - virtLog.WithField("arch", runtime.GOARCH).Warnf("%v", err) + hvLogger.WithField("arch", runtime.GOARCH).Warnf("%v", err) return devices, firmware, err } diff --git a/src/runtime/virtcontainers/qemu_ppc64le.go b/src/runtime/virtcontainers/qemu_ppc64le.go index 51c9003ba..00fec3529 100644 --- a/src/runtime/virtcontainers/qemu_ppc64le.go +++ b/src/runtime/virtcontainers/qemu_ppc64le.go @@ -51,7 +51,7 @@ var supportedQemuMachine = govmmQemu.Machine{ // Logger returns a logrus logger appropriate for logging qemu messages func (q *qemuPPC64le) Logger() *logrus.Entry { - return virtLog.WithField("subsystem", "qemuPPC64le") + return hvLogger.WithField("subsystem", "qemuPPC64le") } // MaxQemuVCPUs returns the maximum number of vCPUs supported @@ -141,7 +141,7 @@ func (q *qemuPPC64le) enableProtection() error { q.qemuMachine.Options += "," } q.qemuMachine.Options += fmt.Sprintf("confidential-guest-support=%s", pefID) - virtLog.WithFields(logrus.Fields{ + hvLogger.WithFields(logrus.Fields{ "subsystem": "qemuPPC64le", "machine": q.qemuMachine, "kernel-params": q.kernelParams, diff --git a/src/runtime/virtcontainers/qemu_s390x.go b/src/runtime/virtcontainers/qemu_s390x.go index b7611decc..d6c013156 100644 --- a/src/runtime/virtcontainers/qemu_s390x.go +++ b/src/runtime/virtcontainers/qemu_s390x.go @@ -324,7 +324,7 @@ func (q *qemuS390x) enableProtection() error { q.qemuMachine.Options += "," } q.qemuMachine.Options += fmt.Sprintf("confidential-guest-support=%s", secExecID) - virtLog.WithFields(logrus.Fields{ + hvLogger.WithFields(logrus.Fields{ "subsystem": logSubsystem, "machine": q.qemuMachine}). Info("Enabling guest protection with Secure Execution") diff --git a/src/runtime/virtcontainers/virtiofsd.go b/src/runtime/virtcontainers/virtiofsd.go index d35399bea..baaec862f 100644 --- a/src/runtime/virtcontainers/virtiofsd.go +++ b/src/runtime/virtcontainers/virtiofsd.go @@ -216,7 +216,7 @@ func (v *virtiofsd) valid() error { } 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) {