X Tutup
Skip to content

Commit e00ebfb

Browse files
authored
Merge pull request containerd#3461 from crosbymichael/pid-fastpath
Fast path getting pid from task
2 parents ab78270 + eb4b3e8 commit e00ebfb

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

runtime/task.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type TaskInfo struct {
3333

3434
// Process is a runtime object for an executing process inside a container
3535
type Process interface {
36+
// ID of the process
3637
ID() string
3738
// State returns the process state
3839
State(context.Context) (State, error)
@@ -54,6 +55,8 @@ type Process interface {
5455
type Task interface {
5556
Process
5657

58+
// PID of the process
59+
PID() uint32
5760
// Namespace that the task exists in
5861
Namespace() string
5962
// Pause pauses the container process

runtime/v1/linux/task.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ func (t *Task) Namespace() string {
8484
return t.namespace
8585
}
8686

87+
// PID of the task
88+
func (t *Task) PID() uint32 {
89+
return uint32(t.pid)
90+
}
91+
8792
// Delete the task and return the exit status
8893
func (t *Task) Delete(ctx context.Context) (*runtime.Exit, error) {
8994
rsp, err := t.shim.Delete(ctx, empty)

runtime/v2/shim.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ func (s *shim) ID() string {
195195
return s.bundle.ID
196196
}
197197

198+
// PID of the task
199+
func (s *shim) PID() uint32 {
200+
return uint32(s.taskPid)
201+
}
202+
198203
func (s *shim) Namespace() string {
199204
return s.bundle.Namespace
200205
}

services/tasks/local.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,24 +182,23 @@ func (l *local) Create(ctx context.Context, r *api.CreateTaskRequest, _ ...grpc.
182182
if err != nil {
183183
return nil, err
184184
}
185-
if _, err := rtime.Get(ctx, r.ContainerID); err != runtime.ErrTaskNotExists {
185+
_, err = rtime.Get(ctx, r.ContainerID)
186+
if err != nil && err != runtime.ErrTaskNotExists {
187+
return nil, errdefs.ToGRPC(err)
188+
}
189+
if err == nil {
186190
return nil, errdefs.ToGRPC(fmt.Errorf("task %s already exists", r.ContainerID))
187191
}
188192
c, err := rtime.Create(ctx, r.ContainerID, opts)
189193
if err != nil {
190194
return nil, errdefs.ToGRPC(err)
191195
}
192-
// TODO: fast path for getting pid on create
193196
if err := l.monitor.Monitor(c); err != nil {
194197
return nil, errors.Wrap(err, "monitor task")
195198
}
196-
state, err := c.State(ctx)
197-
if err != nil {
198-
log.G(ctx).Error(err)
199-
}
200199
return &api.CreateTaskResponse{
201200
ContainerID: r.ContainerID,
202-
Pid: state.Pid,
201+
Pid: c.PID(),
203202
}, nil
204203
}
205204

0 commit comments

Comments
 (0)
X Tutup