Add DeleteProcess API for removing execs

We need a separate API for handing the exit status and deletion of
Exec'd processes to make sure they are properly cleaned up within the
shim and daemon.

Fixes #973

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby
2017-06-08 11:45:16 -07:00
parent 4e8548cd3f
commit ff598449d1
16 changed files with 646 additions and 225 deletions

View File

@@ -59,6 +59,10 @@ func (c *client) Delete(ctx context.Context, in *shimapi.DeleteRequest, opts ...
return c.s.Delete(ctx, in)
}
func (c *client) DeleteProcess(ctx context.Context, in *shimapi.DeleteProcessRequest, opts ...grpc.CallOption) (*shimapi.DeleteResponse, error) {
return c.s.DeleteProcess(ctx, in)
}
func (c *client) Exec(ctx context.Context, in *shimapi.ExecRequest, opts ...grpc.CallOption) (*shimapi.ExecResponse, error) {
return c.s.Exec(ctx, in)
}

View File

@@ -191,9 +191,16 @@ func (p *initProcess) Exited(status int) {
}
func (p *initProcess) Delete(context context.Context) error {
status, err := p.ContainerStatus(context)
if err != nil {
return err
}
if status != "stopped" {
return fmt.Errorf("cannot delete a running container")
}
p.killAll(context)
p.Wait()
err := p.runc.Delete(context, p.id)
err = p.runc.Delete(context, p.id)
if p.io != nil {
for _, c := range p.closers {
c.Close()

View File

@@ -89,13 +89,29 @@ func (s *Service) Start(ctx context.Context, r *shimapi.StartRequest) (*google_p
}
func (s *Service) Delete(ctx context.Context, r *shimapi.DeleteRequest) (*shimapi.DeleteResponse, error) {
p := s.initProcess
// TODO (@crosbymichael): how to handle errors here
p.Delete(ctx)
s.mu.Lock()
delete(s.processes, p.Pid())
s.mu.Unlock()
return &shimapi.DeleteResponse{
ExitStatus: uint32(p.Status()),
ExitedAt: p.ExitedAt(),
}, nil
}
func (s *Service) DeleteProcess(ctx context.Context, r *shimapi.DeleteProcessRequest) (*shimapi.DeleteResponse, error) {
if int(r.Pid) == s.initProcess.pid {
return nil, fmt.Errorf("cannot delete init process with DeleteProcess")
}
s.mu.Lock()
p, ok := s.processes[int(r.Pid)]
s.mu.Unlock()
if !ok {
p = s.initProcess
return nil, fmt.Errorf("process %d not found", r.Pid)
}
// TODO: how to handle errors here
// TODO (@crosbymichael): how to handle errors here
p.Delete(ctx)
s.mu.Lock()
delete(s.processes, p.Pid())

View File

@@ -158,6 +158,19 @@ func (c *Task) Checkpoint(ctx context.Context, opts plugin.CheckpointOpts) error
return err
}
func (c *Task) DeleteProcess(ctx context.Context, pid uint32) (*plugin.Exit, error) {
r, err := c.shim.DeleteProcess(ctx, &shim.DeleteProcessRequest{
Pid: pid,
})
if err != nil {
return nil, err
}
return &plugin.Exit{
Status: r.ExitStatus,
Timestamp: r.ExitedAt,
}, nil
}
type Process struct {
pid int
c *Task