diff --git a/virtcontainers/kata_agent.go b/virtcontainers/kata_agent.go index 305db6ecf..243415fee 100644 --- a/virtcontainers/kata_agent.go +++ b/virtcontainers/kata_agent.go @@ -162,13 +162,14 @@ func ephemeralPath() string { // KataAgentConfig is a structure storing information needed // to reach the Kata Containers agent. type KataAgentConfig struct { - LongLiveConn bool - UseVSock bool - Debug bool - Trace bool - TraceMode string - TraceType string - KernelModules []string + LongLiveConn bool + UseVSock bool + Debug bool + Trace bool + ContainerPipeSize uint32 + TraceMode string + TraceType string + KernelModules []string } // KataAgentState is the structure describing the data stored from this @@ -265,6 +266,11 @@ func KataAgentKernelParams(config KataAgentConfig) []Param { params = append(params, Param{Key: "agent.trace", Value: config.TraceType}) } + if config.ContainerPipeSize > 0 { + containerPipeSize := strconv.FormatUint(uint64(config.ContainerPipeSize), 10) + params = append(params, Param{Key: vcAnnotations.ContainerPipeSizeKernelParam, Value: containerPipeSize}) + } + return params } diff --git a/virtcontainers/kata_agent_test.go b/virtcontainers/kata_agent_test.go index 690bbd105..f13e3277d 100644 --- a/virtcontainers/kata_agent_test.go +++ b/virtcontainers/kata_agent_test.go @@ -9,6 +9,7 @@ import ( "bufio" "context" "fmt" + vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations" "io/ioutil" "net" "os" @@ -923,11 +924,12 @@ func TestKataAgentKernelParams(t *testing.T) { assert := assert.New(t) type testData struct { - debug bool - trace bool - traceMode string - traceType string - expectedParams []Param + debug bool + trace bool + containerPipeSize uint32 + traceMode string + traceType string + expectedParams []Param } debugParam := Param{Key: "agent.log", Value: "debug"} @@ -937,58 +939,64 @@ func TestKataAgentKernelParams(t *testing.T) { traceFooParam := Param{Key: "agent.trace", Value: "foo"} + containerPipeSizeParam := Param{Key: vcAnnotations.ContainerPipeSizeKernelParam, Value: "2097152"} + data := []testData{ - {false, false, "", "", []Param{}}, - {true, false, "", "", []Param{debugParam}}, + {false, false, 0, "", "", []Param{}}, + {true, false, 0, "", "", []Param{debugParam}}, - {false, false, "foo", "", []Param{}}, - {false, false, "foo", "", []Param{}}, - {false, false, "", "foo", []Param{}}, - {false, false, "", "foo", []Param{}}, - {false, false, "foo", "foo", []Param{}}, - {false, true, "foo", "foo", []Param{}}, + {false, false, 0, "foo", "", []Param{}}, + {false, false, 0, "foo", "", []Param{}}, + {false, false, 0, "", "foo", []Param{}}, + {false, false, 0, "", "foo", []Param{}}, + {false, false, 0, "foo", "foo", []Param{}}, + {false, true, 0, "foo", "foo", []Param{}}, - {false, false, agentTraceModeDynamic, "", []Param{}}, - {false, false, agentTraceModeStatic, "", []Param{}}, - {false, false, "", agentTraceTypeIsolated, []Param{}}, - {false, false, "", agentTraceTypeCollated, []Param{}}, - {false, false, "foo", agentTraceTypeIsolated, []Param{}}, - {false, false, "foo", agentTraceTypeCollated, []Param{}}, + {false, false, 0, agentTraceModeDynamic, "", []Param{}}, + {false, false, 0, agentTraceModeStatic, "", []Param{}}, + {false, false, 0, "", agentTraceTypeIsolated, []Param{}}, + {false, false, 0, "", agentTraceTypeCollated, []Param{}}, + {false, false, 0, "foo", agentTraceTypeIsolated, []Param{}}, + {false, false, 0, "foo", agentTraceTypeCollated, []Param{}}, - {false, false, agentTraceModeDynamic, agentTraceTypeIsolated, []Param{}}, - {false, false, agentTraceModeDynamic, agentTraceTypeCollated, []Param{}}, + {false, false, 0, agentTraceModeDynamic, agentTraceTypeIsolated, []Param{}}, + {false, false, 0, agentTraceModeDynamic, agentTraceTypeCollated, []Param{}}, - {false, false, agentTraceModeStatic, agentTraceTypeCollated, []Param{}}, - {false, false, agentTraceModeStatic, agentTraceTypeCollated, []Param{}}, + {false, false, 0, agentTraceModeStatic, agentTraceTypeCollated, []Param{}}, + {false, false, 0, agentTraceModeStatic, agentTraceTypeCollated, []Param{}}, - {false, true, agentTraceModeDynamic, agentTraceTypeIsolated, []Param{}}, - {false, true, agentTraceModeDynamic, agentTraceTypeCollated, []Param{}}, - {true, true, agentTraceModeDynamic, agentTraceTypeCollated, []Param{debugParam}}, + {false, true, 0, agentTraceModeDynamic, agentTraceTypeIsolated, []Param{}}, + {false, true, 0, agentTraceModeDynamic, agentTraceTypeCollated, []Param{}}, + {true, true, 0, agentTraceModeDynamic, agentTraceTypeCollated, []Param{debugParam}}, - {false, true, "", agentTraceTypeIsolated, []Param{}}, - {false, true, "", agentTraceTypeCollated, []Param{}}, - {true, true, "", agentTraceTypeIsolated, []Param{debugParam}}, - {true, true, "", agentTraceTypeCollated, []Param{debugParam}}, - {false, true, "foo", agentTraceTypeIsolated, []Param{}}, - {false, true, "foo", agentTraceTypeCollated, []Param{}}, - {true, true, "foo", agentTraceTypeIsolated, []Param{debugParam}}, - {true, true, "foo", agentTraceTypeCollated, []Param{debugParam}}, + {false, true, 0, "", agentTraceTypeIsolated, []Param{}}, + {false, true, 0, "", agentTraceTypeCollated, []Param{}}, + {true, true, 0, "", agentTraceTypeIsolated, []Param{debugParam}}, + {true, true, 0, "", agentTraceTypeCollated, []Param{debugParam}}, + {false, true, 0, "foo", agentTraceTypeIsolated, []Param{}}, + {false, true, 0, "foo", agentTraceTypeCollated, []Param{}}, + {true, true, 0, "foo", agentTraceTypeIsolated, []Param{debugParam}}, + {true, true, 0, "foo", agentTraceTypeCollated, []Param{debugParam}}, - {false, true, agentTraceModeStatic, agentTraceTypeIsolated, []Param{traceIsolatedParam}}, - {false, true, agentTraceModeStatic, agentTraceTypeCollated, []Param{traceCollatedParam}}, - {true, true, agentTraceModeStatic, agentTraceTypeIsolated, []Param{traceIsolatedParam, debugParam}}, - {true, true, agentTraceModeStatic, agentTraceTypeCollated, []Param{traceCollatedParam, debugParam}}, + {false, true, 0, agentTraceModeStatic, agentTraceTypeIsolated, []Param{traceIsolatedParam}}, + {false, true, 0, agentTraceModeStatic, agentTraceTypeCollated, []Param{traceCollatedParam}}, + {true, true, 0, agentTraceModeStatic, agentTraceTypeIsolated, []Param{traceIsolatedParam, debugParam}}, + {true, true, 0, agentTraceModeStatic, agentTraceTypeCollated, []Param{traceCollatedParam, debugParam}}, - {false, true, agentTraceModeStatic, "foo", []Param{traceFooParam}}, - {true, true, agentTraceModeStatic, "foo", []Param{debugParam, traceFooParam}}, + {false, true, 0, agentTraceModeStatic, "foo", []Param{traceFooParam}}, + {true, true, 0, agentTraceModeStatic, "foo", []Param{debugParam, traceFooParam}}, + + {false, false, 0, "", "", []Param{}}, + {false, false, 2097152, "", "", []Param{containerPipeSizeParam}}, } for i, d := range data { config := KataAgentConfig{ - Debug: d.debug, - Trace: d.trace, - TraceMode: d.traceMode, - TraceType: d.traceType, + Debug: d.debug, + Trace: d.trace, + TraceMode: d.traceMode, + TraceType: d.traceType, + ContainerPipeSize: d.containerPipeSize, } count := len(d.expectedParams) diff --git a/virtcontainers/pkg/annotations/annotations.go b/virtcontainers/pkg/annotations/annotations.go index 14da6eb59..f18e3ffed 100644 --- a/virtcontainers/pkg/annotations/annotations.go +++ b/virtcontainers/pkg/annotations/annotations.go @@ -237,6 +237,11 @@ const ( // AgentTraceMode is a sandbox annotation to specify the trace type for the agent. AgentTraceType = kataAnnotAgentPrefix + "trace_type" + + // AgentContainerPipeSize is an annotation to specify the size of the pipes created for containers + AgentContainerPipeSize = kataAnnotAgentPrefix + ContainerPipeSizeOption + ContainerPipeSizeOption = "container_pipe_size" + ContainerPipeSizeKernelParam = "agent." + ContainerPipeSizeOption ) const ( diff --git a/virtcontainers/pkg/oci/utils.go b/virtcontainers/pkg/oci/utils.go index 9fa517ee4..296f4b059 100644 --- a/virtcontainers/pkg/oci/utils.go +++ b/virtcontainers/pkg/oci/utils.go @@ -775,6 +775,14 @@ func addAgentConfigOverrides(ocispec specs.Spec, config *vc.SandboxConfig) error c.TraceType = value } + if value, ok := ocispec.Annotations[vcAnnotations.AgentContainerPipeSize]; ok { + containerPipeSize, err := strconv.ParseUint(value, 10, 32) + if err != nil { + return fmt.Errorf("Error parsing annotation for %s: Please specify uint32 value", vcAnnotations.AgentContainerPipeSize) + } + c.ContainerPipeSize = uint32(containerPipeSize) + } + config.AgentConfig = c return nil diff --git a/virtcontainers/pkg/oci/utils_test.go b/virtcontainers/pkg/oci/utils_test.go index d8815efa4..c53ca2458 100644 --- a/virtcontainers/pkg/oci/utils_test.go +++ b/virtcontainers/pkg/oci/utils_test.go @@ -701,13 +701,37 @@ func TestAddAgentAnnotations(t *testing.T) { "e1000e InterruptThrottleRate=3000,3000,3000 EEE=1", "i915 enable_ppgtt=0", }, + ContainerPipeSize: 1024, } ocispec.Annotations[vcAnnotations.KernelModules] = strings.Join(expectedAgentConfig.KernelModules, KernelModulesSeparator) + ocispec.Annotations[vcAnnotations.AgentContainerPipeSize] = "1024" addAnnotations(ocispec, &config) assert.Exactly(expectedAgentConfig, config.AgentConfig) } +func TestContainerPipeSizeAnnotation(t *testing.T) { + assert := assert.New(t) + + config := vc.SandboxConfig{ + Annotations: make(map[string]string), + AgentConfig: vc.KataAgentConfig{}, + } + + ocispec := specs.Spec{ + Annotations: make(map[string]string), + } + + expectedAgentConfig := vc.KataAgentConfig{ + ContainerPipeSize: 0, + } + + ocispec.Annotations[vcAnnotations.AgentContainerPipeSize] = "foo" + err := addAnnotations(ocispec, &config) + assert.Error(err) + assert.Exactly(expectedAgentConfig, config.AgentConfig) +} + func TestAddHypervisorAnnotations(t *testing.T) { assert := assert.New(t) diff --git a/virtcontainers/vm_test.go b/virtcontainers/vm_test.go index e449590f5..36fd5c2f0 100644 --- a/virtcontainers/vm_test.go +++ b/virtcontainers/vm_test.go @@ -125,7 +125,7 @@ func TestVMConfigGrpc(t *testing.T) { HypervisorType: QemuHypervisor, HypervisorConfig: newQemuConfig(), AgentType: KataContainersAgent, - AgentConfig: KataAgentConfig{false, true, false, false, "", "", []string{}}, + AgentConfig: KataAgentConfig{false, true, false, false, 0, "", "", []string{}}, ProxyType: NoopProxyType, }