From 8c9c7ddef8a65ce461b071e4fca0a5d5c12e988f Mon Sep 17 00:00:00 2001 From: Julio Montes Date: Tue, 20 Mar 2018 15:28:12 -0600 Subject: [PATCH] virtcontainers: agent: fix CPU hot plug race condition Communicate to the agent the number of vCPUs that were hot added, allowing to the agent wait for the creation of all vCPUs. fixes #90 Signed-off-by: Julio Montes --- virtcontainers/agent.go | 3 ++- virtcontainers/container.go | 2 +- virtcontainers/hyperstart_agent.go | 2 +- virtcontainers/kata_agent.go | 7 +++++-- virtcontainers/noop_agent.go | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/virtcontainers/agent.go b/virtcontainers/agent.go index 52e19dfba5..7a42c0e340 100644 --- a/virtcontainers/agent.go +++ b/virtcontainers/agent.go @@ -175,5 +175,6 @@ type agent interface { // onlineCPUMem will online CPUs and Memory inside the Sandbox. // This function should be called after hot adding vCPUs or Memory. - onlineCPUMem() error + // cpus specifies the number of CPUs that were added and the agent should online + onlineCPUMem(cpus uint32) error } diff --git a/virtcontainers/container.go b/virtcontainers/container.go index bc8f6e0c6d..0593bac439 100644 --- a/virtcontainers/container.go +++ b/virtcontainers/container.go @@ -856,7 +856,7 @@ func (c *Container) addResources() error { return err } - return c.sandbox.agent.onlineCPUMem() + return c.sandbox.agent.onlineCPUMem(uint32(vCPUs)) } return nil diff --git a/virtcontainers/hyperstart_agent.go b/virtcontainers/hyperstart_agent.go index a0a928dfbb..cd76aef18d 100644 --- a/virtcontainers/hyperstart_agent.go +++ b/virtcontainers/hyperstart_agent.go @@ -808,7 +808,7 @@ func (h *hyper) sendCmd(proxyCmd hyperstartProxyCmd) (interface{}, error) { return h.client.HyperWithTokens(proxyCmd.cmd, tokens, proxyCmd.message) } -func (h *hyper) onlineCPUMem() error { +func (h *hyper) onlineCPUMem(cpus uint32) error { // cc-agent uses udev to online CPUs automatically return nil } diff --git a/virtcontainers/kata_agent.go b/virtcontainers/kata_agent.go index 4a70d7ae6d..7dd24fad1e 100644 --- a/virtcontainers/kata_agent.go +++ b/virtcontainers/kata_agent.go @@ -877,8 +877,11 @@ func (k *kataAgent) processListContainer(sandbox Sandbox, c Container, options P return nil, nil } -func (k *kataAgent) onlineCPUMem() error { - req := &grpc.OnlineCPUMemRequest{} +func (k *kataAgent) onlineCPUMem(cpus uint32) error { + req := &grpc.OnlineCPUMemRequest{ + Wait: false, + NbCpus: cpus, + } _, err := k.sendReq(req) return err diff --git a/virtcontainers/noop_agent.go b/virtcontainers/noop_agent.go index 20f923dc33..7071d375bb 100644 --- a/virtcontainers/noop_agent.go +++ b/virtcontainers/noop_agent.go @@ -81,6 +81,6 @@ func (n *noopAgent) processListContainer(sandbox Sandbox, c Container, options P } // onlineCPUMem is the Noop agent Container online CPU and Memory implementation. It does nothing. -func (n *noopAgent) onlineCPUMem() error { +func (n *noopAgent) onlineCPUMem(cpus uint32) error { return nil }