@@ -29,7 +29,6 @@ import (
2929
3030 taskAPI "github.com/containerd/containerd/api/runtime/task/v3"
3131 "github.com/containerd/containerd/api/types"
32- "github.com/containerd/containerd/v2/cmd/containerd-shim-runc-v2/process"
3332 "github.com/containerd/containerd/v2/core/runtime"
3433 "github.com/containerd/containerd/v2/pkg/namespaces"
3534 ptypes "github.com/containerd/containerd/v2/pkg/protobuf/types"
@@ -59,7 +58,7 @@ func NewTaskService(ctx context.Context, vmm vm.Manager, publisher shim.Publishe
5958 s := & service {
6059 context : ctx ,
6160 vmm : vmm ,
62- events : make (chan interface {} , 128 ),
61+ events : make (chan any , 128 ),
6362 containers : make (map [string ]* container ),
6463 initiateShutdown : sd .Shutdown ,
6564 }
@@ -94,9 +93,8 @@ type service struct {
9493 // vm is the VM instance used to run the container
9594 vm vm.Instance
9695
97- context context.Context
98- events chan interface {}
99- platform stdio.Platform
96+ context context.Context
97+ events chan any
10098
10199 containers map [string ]* container
102100
@@ -138,11 +136,6 @@ func (s *service) shutdown(ctx context.Context) error {
138136 return errors .Join (errs ... )
139137}
140138
141- type containerProcess struct {
142- //Container *runc.Container
143- Process process.Process
144- }
145-
146139// transformBindMounts transforms bind mounts
147140func transformBindMounts (ctx context.Context , b * bundle.Bundle ) error {
148141 for i , m := range b .Spec .Mounts {
@@ -292,8 +285,8 @@ func (s *service) Create(ctx context.Context, r *taskAPI.CreateTaskRequest) (_ *
292285 return nil , errgrpc .ToGRPC (err )
293286 }
294287
295- // setupTime is the total time to setup the VM and everything neeeded
296- // to proxy the create task request. This measures the the overall
288+ // setupTime is the total time to setup the VM and everything needed
289+ // to proxy the create task request. This measures the overall
297290 // overhead of creating the container inside the VM.
298291 setupTime := time .Since (presetup )
299292
@@ -640,47 +633,6 @@ func (s *service) Stats(ctx context.Context, r *taskAPI.StatsRequest) (*taskAPI.
640633 return tc .Stats (ctx , r )
641634}
642635
643- /*
644- func (s *service) processExits() {
645- for e := range s.ec {
646- // While unlikely, it is not impossible for a container process to exit
647- // and have its PID be recycled for a new container process before we
648- // have a chance to process the first exit. As we have no way to tell
649- // for sure which of the processes the exit event corresponds to (until
650- // pidfd support is implemented) there is no way for us to handle the
651- // exit correctly in that case.
652-
653- s.lifecycleMu.Lock()
654- // Inform any concurrent s.Start() calls so they can handle the exit
655- // if the PID belongs to them.
656- for subscriber := range s.exitSubscribers {
657- (*subscriber)[e.Pid] = append((*subscriber)[e.Pid], e)
658- }
659- // Handle the exit for a created/started process. If there's more than
660- // one, assume they've all exited. One of them will be the correct
661- // process.
662- var cps []containerProcess
663- for _, cp := range s.running[e.Pid] {
664- _, init := cp.Process.(*process.Init)
665- if init {
666- s.containerInitExit[cp.Container] = e
667- }
668- cps = append(cps, cp)
669- }
670- delete(s.running, e.Pid)
671- s.lifecycleMu.Unlock()
672-
673- for _, cp := range cps {
674- if ip, ok := cp.Process.(*process.Init); ok {
675- s.handleInitExit(e, cp.Container, ip)
676- } else {
677- s.handleProcessExit(e, cp.Container, cp.Process)
678- }
679- }
680- }
681- }
682- */
683-
684636func (s * service ) send (evt interface {}) {
685637 s .events <- evt
686638}
@@ -710,119 +662,3 @@ func (s *service) forward(ctx context.Context, publisher shim.Publisher) {
710662 log .G (ctx ).WithField ("event" , e ).Error ("ignored event after shutdown" )
711663 }
712664}
713-
714- /*
715- // handleInitExit processes container init process exits.
716- // This is handled separately from non-init exits, because there
717- // are some extra invariants we want to ensure in this case, namely:
718- // - for a given container, the init process exit MUST be the last exit published
719- // This is achieved by:
720- // - killing all running container processes (if the container has a shared pid
721- // namespace, otherwise all other processes have been reaped already).
722- // - waiting for the container's running exec counter to reach 0.
723- // - finally, publishing the init exit.
724- func (s *service) handleInitExit(e runcC.Exit, c *runc.Container, p *process.Init) {
725- // kill all running container processes
726- if runc.ShouldKillAllOnExit(s.context, c.Bundle) {
727- if err := p.KillAll(s.context); err != nil {
728- log.G(s.context).WithError(err).WithField("id", p.ID()).
729- Error("failed to kill init's children")
730- }
731- }
732-
733- s.lifecycleMu.Lock()
734- numRunningExecs := s.runningExecs[c]
735- if numRunningExecs == 0 {
736- delete(s.runningExecs, c)
737- s.lifecycleMu.Unlock()
738- s.handleProcessExit(e, c, p)
739- return
740- }
741-
742- events := make(chan int, numRunningExecs)
743- s.execCountSubscribers[c] = events
744-
745- s.lifecycleMu.Unlock()
746-
747- go func() {
748- defer func() {
749- s.lifecycleMu.Lock()
750- defer s.lifecycleMu.Unlock()
751- delete(s.execCountSubscribers, c)
752- delete(s.runningExecs, c)
753- }()
754-
755- // wait for running processes to exit
756- for {
757- if runningExecs := <-events; runningExecs == 0 {
758- break
759- }
760- }
761-
762- // all running processes have exited now, and no new
763- // ones can start, so we can publish the init exit
764- s.handleProcessExit(e, c, p)
765- }()
766- }
767-
768- func (s *service) handleProcessExit(e runcC.Exit, c *runc.Container, p process.Process) {
769- p.SetExited(e.Status)
770- s.send(&eventstypes.TaskExit{
771- ContainerID: c.ID,
772- ID: p.ID(),
773- Pid: uint32(e.Pid),
774- ExitStatus: uint32(e.Status),
775- ExitedAt: protobuf.ToTimestamp(p.ExitedAt()),
776- })
777- if _, init := p.(*process.Init); !init {
778- s.lifecycleMu.Lock()
779- s.runningExecs[c]--
780- if ch, ok := s.execCountSubscribers[c]; ok {
781- ch <- s.runningExecs[c]
782- }
783- s.lifecycleMu.Unlock()
784- }
785- }
786-
787- func (s *service) getContainerPids(ctx context.Context, container *runc.Container) ([]uint32, error) {
788- p, err := container.Process("")
789- if err != nil {
790- return nil, errgrpc.ToGRPC(err)
791- }
792- ps, err := p.(*process.Init).Runtime().Ps(ctx, container.ID)
793- if err != nil {
794- return nil, err
795- }
796- pids := make([]uint32, 0, len(ps))
797- for _, pid := range ps {
798- pids = append(pids, uint32(pid))
799- }
800- return pids, nil
801- }
802-
803-
804- func (s *service) getContainer(id string) (*runc.Container, error) {
805- s.mu.Lock()
806- container := s.containers[id]
807- s.mu.Unlock()
808- if container == nil {
809- return nil, errgrpc.ToGRPCf(errdefs.ErrNotFound, "container not created")
810- }
811- return container, nil
812- }
813-
814- // initialize a single epoll fd to manage our consoles. `initPlatform` should
815- // only be called once.
816- func (s *service) initPlatform() error {
817- if s.platform != nil {
818- return nil
819- }
820- p, err := runc.NewPlatform()
821- if err != nil {
822- return err
823- }
824- s.platform = p
825- s.shutdown.RegisterCallback(func(context.Context) error { return s.platform.Close() })
826- return nil
827- }
828- */
0 commit comments