Merge pull request #3461 from crosbymichael/pid-fastpath
Fast path getting pid from task
This commit is contained in:
		| @@ -33,6 +33,7 @@ type TaskInfo struct { | |||||||
|  |  | ||||||
| // Process is a runtime object for an executing process inside a container | // Process is a runtime object for an executing process inside a container | ||||||
| type Process interface { | type Process interface { | ||||||
|  | 	// ID of the process | ||||||
| 	ID() string | 	ID() string | ||||||
| 	// State returns the process state | 	// State returns the process state | ||||||
| 	State(context.Context) (State, error) | 	State(context.Context) (State, error) | ||||||
| @@ -54,6 +55,8 @@ type Process interface { | |||||||
| type Task interface { | type Task interface { | ||||||
| 	Process | 	Process | ||||||
|  |  | ||||||
|  | 	// PID of the process | ||||||
|  | 	PID() uint32 | ||||||
| 	// Namespace that the task exists in | 	// Namespace that the task exists in | ||||||
| 	Namespace() string | 	Namespace() string | ||||||
| 	// Pause pauses the container process | 	// Pause pauses the container process | ||||||
|   | |||||||
| @@ -84,6 +84,11 @@ func (t *Task) Namespace() string { | |||||||
| 	return t.namespace | 	return t.namespace | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // PID of the task | ||||||
|  | func (t *Task) PID() uint32 { | ||||||
|  | 	return uint32(t.pid) | ||||||
|  | } | ||||||
|  |  | ||||||
| // Delete the task and return the exit status | // Delete the task and return the exit status | ||||||
| func (t *Task) Delete(ctx context.Context) (*runtime.Exit, error) { | func (t *Task) Delete(ctx context.Context) (*runtime.Exit, error) { | ||||||
| 	rsp, err := t.shim.Delete(ctx, empty) | 	rsp, err := t.shim.Delete(ctx, empty) | ||||||
|   | |||||||
| @@ -195,6 +195,11 @@ func (s *shim) ID() string { | |||||||
| 	return s.bundle.ID | 	return s.bundle.ID | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // PID of the task | ||||||
|  | func (s *shim) PID() uint32 { | ||||||
|  | 	return uint32(s.taskPid) | ||||||
|  | } | ||||||
|  |  | ||||||
| func (s *shim) Namespace() string { | func (s *shim) Namespace() string { | ||||||
| 	return s.bundle.Namespace | 	return s.bundle.Namespace | ||||||
| } | } | ||||||
|   | |||||||
| @@ -182,24 +182,23 @@ func (l *local) Create(ctx context.Context, r *api.CreateTaskRequest, _ ...grpc. | |||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 	if _, err := rtime.Get(ctx, r.ContainerID); err != runtime.ErrTaskNotExists { | 	_, err = rtime.Get(ctx, r.ContainerID) | ||||||
|  | 	if err != nil && err != runtime.ErrTaskNotExists { | ||||||
|  | 		return nil, errdefs.ToGRPC(err) | ||||||
|  | 	} | ||||||
|  | 	if err == nil { | ||||||
| 		return nil, errdefs.ToGRPC(fmt.Errorf("task %s already exists", r.ContainerID)) | 		return nil, errdefs.ToGRPC(fmt.Errorf("task %s already exists", r.ContainerID)) | ||||||
| 	} | 	} | ||||||
| 	c, err := rtime.Create(ctx, r.ContainerID, opts) | 	c, err := rtime.Create(ctx, r.ContainerID, opts) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, errdefs.ToGRPC(err) | 		return nil, errdefs.ToGRPC(err) | ||||||
| 	} | 	} | ||||||
| 	// TODO: fast path for getting pid on create |  | ||||||
| 	if err := l.monitor.Monitor(c); err != nil { | 	if err := l.monitor.Monitor(c); err != nil { | ||||||
| 		return nil, errors.Wrap(err, "monitor task") | 		return nil, errors.Wrap(err, "monitor task") | ||||||
| 	} | 	} | ||||||
| 	state, err := c.State(ctx) |  | ||||||
| 	if err != nil { |  | ||||||
| 		log.G(ctx).Error(err) |  | ||||||
| 	} |  | ||||||
| 	return &api.CreateTaskResponse{ | 	return &api.CreateTaskResponse{ | ||||||
| 		ContainerID: r.ContainerID, | 		ContainerID: r.ContainerID, | ||||||
| 		Pid:         state.Pid, | 		Pid:         c.PID(), | ||||||
| 	}, nil | 	}, nil | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Phil Estes
					Phil Estes