annotations: add cpu_features

[ port from runtime commit f03c17d107999fd68da87d98ab3e242ac7843051 ]

So that users can use annotations to set it.

Signed-off-by: Jia He <justin.he@arm.com>
Signed-off-by: Peng Tao <bergwolf@hyper.sh>
This commit is contained in:
Jia He 2020-06-29 20:19:21 -07:00 committed by Peng Tao
parent fa9d619e8a
commit 115dfa19cd
3 changed files with 11 additions and 0 deletions

View File

@ -81,6 +81,9 @@ const (
// MachineAccelerators is a sandbox annotation to specify machine specific accelerators for the hypervisor. // MachineAccelerators is a sandbox annotation to specify machine specific accelerators for the hypervisor.
MachineAccelerators = kataAnnotHypervisorPrefix + "machine_accelerators" 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 is a sandbox annotation to specify if vhost-net is not available on the host.
DisableVhostNet = kataAnnotHypervisorPrefix + "disable_vhost_net" DisableVhostNet = kataAnnotHypervisorPrefix + "disable_vhost_net"

View File

@ -700,6 +700,12 @@ func addHypervisporVirtioFsOverrides(ocispec specs.Spec, sbConfig *vc.SandboxCon
} }
func addHypervisporNetworkOverrides(ocispec specs.Spec, sbConfig *vc.SandboxConfig) error { func addHypervisporNetworkOverrides(ocispec specs.Spec, sbConfig *vc.SandboxConfig) error {
if value, ok := ocispec.Annotations[vcAnnotations.CPUFeatures]; ok {
if value != "" {
sbConfig.HypervisorConfig.CPUFeatures = value
}
}
if value, ok := ocispec.Annotations[vcAnnotations.DisableVhostNet]; ok { if value, ok := ocispec.Annotations[vcAnnotations.DisableVhostNet]; ok {
disableVhostNet, err := strconv.ParseBool(value) disableVhostNet, err := strconv.ParseBool(value)
if err != nil { if err != nil {

View File

@ -784,6 +784,7 @@ func TestAddHypervisorAnnotations(t *testing.T) {
ocispec.Annotations[vcAnnotations.Msize9p] = "512" ocispec.Annotations[vcAnnotations.Msize9p] = "512"
ocispec.Annotations[vcAnnotations.MachineType] = "q35" ocispec.Annotations[vcAnnotations.MachineType] = "q35"
ocispec.Annotations[vcAnnotations.MachineAccelerators] = "nofw" ocispec.Annotations[vcAnnotations.MachineAccelerators] = "nofw"
ocispec.Annotations[vcAnnotations.CPUFeatures] = "pmu=off"
ocispec.Annotations[vcAnnotations.DisableVhostNet] = "true" ocispec.Annotations[vcAnnotations.DisableVhostNet] = "true"
ocispec.Annotations[vcAnnotations.GuestHookPath] = "/usr/bin/" ocispec.Annotations[vcAnnotations.GuestHookPath] = "/usr/bin/"
ocispec.Annotations[vcAnnotations.UseVSock] = "true" ocispec.Annotations[vcAnnotations.UseVSock] = "true"
@ -819,6 +820,7 @@ func TestAddHypervisorAnnotations(t *testing.T) {
assert.Equal(config.HypervisorConfig.Msize9p, uint32(512)) assert.Equal(config.HypervisorConfig.Msize9p, uint32(512))
assert.Equal(config.HypervisorConfig.HypervisorMachineType, "q35") assert.Equal(config.HypervisorConfig.HypervisorMachineType, "q35")
assert.Equal(config.HypervisorConfig.MachineAccelerators, "nofw") assert.Equal(config.HypervisorConfig.MachineAccelerators, "nofw")
assert.Equal(config.HypervisorConfig.CPUFeatures, "pmu=off")
assert.Equal(config.HypervisorConfig.DisableVhostNet, true) assert.Equal(config.HypervisorConfig.DisableVhostNet, true)
assert.Equal(config.HypervisorConfig.GuestHookPath, "/usr/bin/") assert.Equal(config.HypervisorConfig.GuestHookPath, "/usr/bin/")
assert.Equal(config.HypervisorConfig.UseVSock, true) assert.Equal(config.HypervisorConfig.UseVSock, true)