Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
annotations: add cpu_features
Browse files Browse the repository at this point in the history
So that users can use annotations to set it.

Fixes: #2576

Signed-off-by: Jia He <[email protected]>
  • Loading branch information
justin-he authored and Julio Montes committed May 15, 2020
1 parent 0100af1 commit f03c17d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions virtcontainers/pkg/annotations/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ const (
// MachineAccelerators is a sandbox annotation to specify machine specific accelerators for the hypervisor.
MachineAccelerators = kataAnnotHypervisorPrefix + "machine_accelerators"

// CPUFeatures is a sandbox annotation to specify cpu specific features.
CPUFeatures = kataAnnotHypervisorPrefix + "cpu_features"

// DisableVhostNet is a sandbox annotation to specify if vhost-net is not available on the host.
DisableVhostNet = kataAnnotHypervisorPrefix + "disable_vhost_net"

Expand Down
6 changes: 6 additions & 0 deletions virtcontainers/pkg/oci/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,12 @@ func addHypervisorConfigOverrides(ocispec specs.Spec, config *vc.SandboxConfig)
}
}

if value, ok := ocispec.Annotations[vcAnnotations.CPUFeatures]; ok {
if value != "" {
config.HypervisorConfig.CPUFeatures = value
}
}

if value, ok := ocispec.Annotations[vcAnnotations.DisableVhostNet]; ok {
disableVhostNet, err := strconv.ParseBool(value)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions virtcontainers/pkg/oci/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,7 @@ func TestAddHypervisorAnnotations(t *testing.T) {
ocispec.Annotations[vcAnnotations.Msize9p] = "512"
ocispec.Annotations[vcAnnotations.MachineType] = "q35"
ocispec.Annotations[vcAnnotations.MachineAccelerators] = "nofw"
ocispec.Annotations[vcAnnotations.CPUFeatures] = "pmu=off"
ocispec.Annotations[vcAnnotations.DisableVhostNet] = "true"
ocispec.Annotations[vcAnnotations.GuestHookPath] = "/usr/bin/"
ocispec.Annotations[vcAnnotations.UseVSock] = "true"
Expand Down Expand Up @@ -814,6 +815,7 @@ func TestAddHypervisorAnnotations(t *testing.T) {
assert.Equal(config.HypervisorConfig.Msize9p, uint32(512))
assert.Equal(config.HypervisorConfig.HypervisorMachineType, "q35")
assert.Equal(config.HypervisorConfig.MachineAccelerators, "nofw")
assert.Equal(config.HypervisorConfig.CPUFeatures, "pmu=off")
assert.Equal(config.HypervisorConfig.DisableVhostNet, true)
assert.Equal(config.HypervisorConfig.GuestHookPath, "/usr/bin/")
assert.Equal(config.HypervisorConfig.UseVSock, true)
Expand Down

0 comments on commit f03c17d

Please sign in to comment.