Skip to content

Commit 6604ff6

Browse files
committed
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 <[email protected]>
1 parent 3a3d5de commit 6604ff6

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

runtime/v2/runc/task/service.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ func (s *service) Pids(ctx context.Context, r *taskAPI.PidsRequest) (*taskAPI.Pi
462462
if err != nil {
463463
return nil, err
464464
}
465-
pids, err := s.getContainerPids(ctx, r.ID)
465+
pids, err := s.getContainerPids(ctx, container)
466466
if err != nil {
467467
return nil, errdefs.ToGRPC(err)
468468
}
@@ -664,16 +664,12 @@ func (s *service) handleProcessExit(e runcC.Exit, c *runc.Container, p process.P
664664
})
665665
}
666666

667-
func (s *service) getContainerPids(ctx context.Context, id string) ([]uint32, error) {
668-
container, err := s.getContainer(id)
669-
if err != nil {
670-
return nil, err
671-
}
667+
func (s *service) getContainerPids(ctx context.Context, container *runc.Container) ([]uint32, error) {
672668
p, err := container.Process("")
673669
if err != nil {
674670
return nil, errdefs.ToGRPC(err)
675671
}
676-
ps, err := p.(*process.Init).Runtime().Ps(ctx, id)
672+
ps, err := p.(*process.Init).Runtime().Ps(ctx, container.ID)
677673
if err != nil {
678674
return nil, err
679675
}

0 commit comments

Comments
 (0)