From 6604ff6c55a51285fb88cc081078ba74785af32d Mon Sep 17 00:00:00 2001 From: Chen Yiyang Date: Sat, 16 Sep 2023 19:33:18 +0800 Subject: [PATCH] containerd-shim-runc-v2: remove unnecessary `s.getContainer()` Previous code has already called `getContainer()`, just pass it into `s.getContainerPids` to reduce unnecessary lock and map lookup. Signed-off-by: Chen Yiyang --- runtime/v2/runc/task/service.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/runtime/v2/runc/task/service.go b/runtime/v2/runc/task/service.go index ff09c045a..060c48774 100644 --- a/runtime/v2/runc/task/service.go +++ b/runtime/v2/runc/task/service.go @@ -462,7 +462,7 @@ func (s *service) Pids(ctx context.Context, r *taskAPI.PidsRequest) (*taskAPI.Pi if err != nil { return nil, err } - pids, err := s.getContainerPids(ctx, r.ID) + pids, err := s.getContainerPids(ctx, container) if err != nil { return nil, errdefs.ToGRPC(err) } @@ -664,16 +664,12 @@ func (s *service) handleProcessExit(e runcC.Exit, c *runc.Container, p process.P }) } -func (s *service) getContainerPids(ctx context.Context, id string) ([]uint32, error) { - container, err := s.getContainer(id) - if err != nil { - return nil, err - } +func (s *service) getContainerPids(ctx context.Context, container *runc.Container) ([]uint32, error) { p, err := container.Process("") if err != nil { return nil, errdefs.ToGRPC(err) } - ps, err := p.(*process.Init).Runtime().Ps(ctx, id) + ps, err := p.(*process.Init).Runtime().Ps(ctx, container.ID) if err != nil { return nil, err }