Skip to content

Commit

Permalink
hypervisor: add hypervisor_debug_level
Browse files Browse the repository at this point in the history
Implement HypervisorLoglevel config option for clh.

Signed-off-by: Cameron Baird <[email protected]>
  • Loading branch information
Camelron committed Jan 29, 2025
1 parent 1ee72c4 commit 73ace7f
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/runtime/config/configuration-clh-snp.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ block_device_driver = "virtio-blk"
# Default false
#enable_debug = true

# This option specifies the loglevel of the hypervisor
#
# Default 1
#hypervisor_debug_level = 1

# Path to OCI hook binaries in the *guest rootfs*.
# This does not affect host-side hooks which must instead be added to
# the OCI spec passed to the runtime.
Expand Down
5 changes: 5 additions & 0 deletions src/runtime/config/configuration-clh.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ block_device_driver = "virtio-blk"
# Default false
#enable_debug = true

# This option specifies the loglevel of the hypervisor
#
# Default 1
#hypervisor_debug_level = 1

# Enable hot-plugging of VFIO devices to a root-port.
# The default setting is "no-port"
#hot_plug_vfio = "root-port"
Expand Down
1 change: 1 addition & 0 deletions src/runtime/pkg/katautils/config-settings.go.in
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const defaultVCPUCount uint32 = 0
const defaultMaxVCPUCount uint32 = 0
const defaultMemSize uint32 = 2048 // MiB
const defaultMemSlots uint32 = 10
const defaultHypervisorLoglevel uint32 = 1
const defaultMemOffset uint64 = 0 // MiB
const defaultVirtioMem bool = false
const defaultBridgesCount uint32 = 1
Expand Down
16 changes: 16 additions & 0 deletions src/runtime/pkg/katautils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ const (
// the maximum amount of PCI bridges that can be cold plugged in a VM
maxPCIBridges uint32 = 5

// the maximum valid loglevel for the hypervisor
maxHypervisorLoglevel uint32 = 3

errInvalidHypervisorPrefix = "configuration file contains invalid hypervisor section"
)

Expand Down Expand Up @@ -130,6 +133,7 @@ type hypervisor struct {
NetRateLimiterBwOneTimeBurst int64 `toml:"net_rate_limiter_bw_one_time_burst"`
NetRateLimiterOpsMaxRate int64 `toml:"net_rate_limiter_ops_max_rate"`
NetRateLimiterOpsOneTimeBurst int64 `toml:"net_rate_limiter_ops_one_time_burst"`
HypervisorLoglevel uint32 `toml:"hypervisor_debug_level"`
VirtioFSCacheSize uint32 `toml:"virtio_fs_cache_size"`
VirtioFSQueueSize uint32 `toml:"virtio_fs_queue_size"`
DefaultMaxVCPUs uint32 `toml:"default_maxvcpus"`
Expand Down Expand Up @@ -500,6 +504,14 @@ func (h hypervisor) defaultBridges() uint32 {
return h.DefaultBridges
}

func (h hypervisor) defaultHypervisorLoglevel() uint32 {
if h.HypervisorLoglevel > maxHypervisorLoglevel {
return maxHypervisorLoglevel
}

return h.HypervisorLoglevel
}

func (h hypervisor) defaultVirtioFSCache() string {
if h.VirtioFSCache == "" {
return defaultVirtioFSCacheMode
Expand Down Expand Up @@ -906,6 +918,7 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
SharedFS: sharedFS,
VirtioFSDaemon: h.VirtioFSDaemon,
VirtioFSDaemonList: h.VirtioFSDaemonList,
HypervisorLoglevel: h.defaultHypervisorLoglevel(),
VirtioFSCacheSize: h.VirtioFSCacheSize,
VirtioFSCache: h.defaultVirtioFSCache(),
VirtioFSQueueSize: h.VirtioFSQueueSize,
Expand Down Expand Up @@ -1114,6 +1127,7 @@ func newClhHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
SharedFS: sharedFS,
VirtioFSDaemon: h.VirtioFSDaemon,
VirtioFSDaemonList: h.VirtioFSDaemonList,
HypervisorLoglevel: h.defaultHypervisorLoglevel(),
VirtioFSCacheSize: h.VirtioFSCacheSize,
VirtioFSCache: h.VirtioFSCache,
MemPrealloc: h.MemPrealloc,
Expand Down Expand Up @@ -1268,6 +1282,7 @@ func newStratovirtHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
SharedFS: sharedFS,
VirtioFSDaemon: h.VirtioFSDaemon,
VirtioFSDaemonList: h.VirtioFSDaemonList,
HypervisorLoglevel: h.defaultHypervisorLoglevel(),
VirtioFSCacheSize: h.VirtioFSCacheSize,
VirtioFSCache: h.defaultVirtioFSCache(),
VirtioFSExtraArgs: h.VirtioFSExtraArgs,
Expand Down Expand Up @@ -1487,6 +1502,7 @@ func GetDefaultHypervisorConfig() vc.HypervisorConfig {
GuestHookPath: defaultGuestHookPath,
VhostUserStorePath: defaultVhostUserStorePath,
VhostUserDeviceReconnect: defaultVhostUserDeviceReconnect,
HypervisorLoglevel: defaultHypervisorLoglevel,
VirtioFSCache: defaultVirtioFSCacheMode,
DisableImageNvdimm: defaultDisableImageNvdimm,
RxRateLimiterMaxRate: defaultRxRateLimiterMaxRate,
Expand Down
5 changes: 3 additions & 2 deletions src/runtime/virtcontainers/clh.go
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,7 @@ func (clh *cloudHypervisor) launchClh() error {
}

args := []string{cscAPIsocket, clh.state.apiSocket}
if clh.config.Debug {
if clh.config.Debug && clh.config.HypervisorLoglevel > 0 {
// Cloud hypervisor log levels
// 'v' occurrences increase the level
//0 => Warn
Expand All @@ -1466,7 +1466,8 @@ func (clh *cloudHypervisor) launchClh() error {
// output. For further details, see the discussion on:
//
// https://github.com/kata-containers/kata-containers/pull/2751
args = append(args, "-v")
verbosityString := fmt.Sprintf("-%s", strings.Repeat("v", int(clh.config.HypervisorLoglevel)))
args = append(args, verbosityString)
}

// Enable the `seccomp` feature from Cloud Hypervisor by default
Expand Down
4 changes: 4 additions & 0 deletions src/runtime/virtcontainers/hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,10 @@ type HypervisorConfig struct {
// enable debug output where available.
Debug bool

// HypervisorLoglevel determines the level of logging emitted
// from the hypervisor. Accepts values 0-3.
HypervisorLoglevel uint32

// MemPrealloc specifies if the memory should be pre-allocated
MemPrealloc bool

Expand Down

0 comments on commit 73ace7f

Please sign in to comment.