diff --git a/virtcontainers/agent.go b/virtcontainers/agent.go index 2a0acc457a..a25e4d4843 100644 --- a/virtcontainers/agent.go +++ b/virtcontainers/agent.go @@ -172,4 +172,8 @@ type agent interface { // processListContainer will list the processes running inside the container processListContainer(pod Pod, c Container, options ProcessListOptions) (ProcessList, error) + + // onlineCPUMem will online CPUs and Memory inside the Pod. + // This function should be called after hot adding vCPUs or Memory. + onlineCPUMem() error } diff --git a/virtcontainers/container.go b/virtcontainers/container.go index 87ea329dfa..47380131b3 100644 --- a/virtcontainers/container.go +++ b/virtcontainers/container.go @@ -787,6 +787,8 @@ func (c *Container) addResources() error { if err := c.pod.hypervisor.hotplugAddDevice(uint32(vCPUs), cpuDev); err != nil { return err } + + return c.pod.agent.onlineCPUMem() } return nil diff --git a/virtcontainers/hyperstart_agent.go b/virtcontainers/hyperstart_agent.go index 4f0e487ffc..73b3cac688 100644 --- a/virtcontainers/hyperstart_agent.go +++ b/virtcontainers/hyperstart_agent.go @@ -794,3 +794,8 @@ func (h *hyper) sendCmd(proxyCmd hyperstartProxyCmd) (interface{}, error) { return h.client.HyperWithTokens(proxyCmd.cmd, tokens, proxyCmd.message) } + +func (h *hyper) onlineCPUMem() error { + // cc-agent uses udev to online CPUs automatically + return nil +} diff --git a/virtcontainers/kata_agent.go b/virtcontainers/kata_agent.go index 329e576cfa..1350f69f90 100644 --- a/virtcontainers/kata_agent.go +++ b/virtcontainers/kata_agent.go @@ -773,6 +773,13 @@ func (k *kataAgent) processListContainer(pod Pod, c Container, options ProcessLi return nil, nil } +func (k *kataAgent) onlineCPUMem() error { + req := &grpc.OnlineCPUMemRequest{} + + _, err := k.sendReq(req) + return err +} + func (k *kataAgent) connect() error { if k.client != nil { return nil @@ -836,6 +843,8 @@ func (k *kataAgent) sendReq(request interface{}) (interface{}, error) { case *grpc.UpdateInterfaceRequest: ifc, err := k.client.UpdateInterface(context.Background(), req) return ifc, err + case *grpc.OnlineCPUMemRequest: + return k.client.OnlineCPUMem(context.Background(), req) default: return nil, fmt.Errorf("Unknown gRPC type %T", req) } diff --git a/virtcontainers/noop_agent.go b/virtcontainers/noop_agent.go index 136831fc04..13d7a2e78d 100644 --- a/virtcontainers/noop_agent.go +++ b/virtcontainers/noop_agent.go @@ -79,3 +79,8 @@ func (n *noopAgent) killContainer(pod Pod, c Container, signal syscall.Signal, a func (n *noopAgent) processListContainer(pod Pod, c Container, options ProcessListOptions) (ProcessList, error) { return nil, nil } + +// onlineCPUMem is the Noop agent Container online CPU and Memory implementation. It does nothing. +func (n *noopAgent) onlineCPUMem() error { + return nil +}