Skip to content

Commit 6982a0d

Browse files
cyyzerothaJeztah
authored andcommitted
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]> (cherry picked from commit 6604ff6) Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 0e23203 commit 6982a0d

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
@@ -461,7 +461,7 @@ func (s *service) Pids(ctx context.Context, r *taskAPI.PidsRequest) (*taskAPI.Pi
461461
if err != nil {
462462
return nil, err
463463
}
464-
pids, err := s.getContainerPids(ctx, r.ID)
464+
pids, err := s.getContainerPids(ctx, container)
465465
if err != nil {
466466
return nil, errdefs.ToGRPC(err)
467467
}
@@ -663,16 +663,12 @@ func (s *service) handleProcessExit(e runcC.Exit, c *runc.Container, p process.P
663663
})
664664
}
665665

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

0 commit comments

Comments
 (0)