Skip to content

Commit b876420

Browse files
Merge pull request cri-o#6925 from haircommander/no-lock-pid
server: do not take lock to populate verbose information for containe…
2 parents bdaf393 + c87b111 commit b876420

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

server/container_status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func (s *Server) createContainerInfo(container *oci.Container) (map[string]strin
143143
bytes, err := func(metadata *storage.RuntimeContainerMetadata) ([]byte, error) {
144144
localContainerInfo := containerInfo{
145145
SandboxID: container.Sandbox(),
146-
Pid: container.State().Pid,
146+
Pid: container.StateNoLock().InitPid,
147147
RuntimeSpec: container.Spec(),
148148
Privileged: metadata.Privileged,
149149
}

server/inspect.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (s *Server) getContainerInfo(ctx context.Context, id string, getContainerFu
6969
isInfra = true
7070
}
7171
// TODO(mrunalp): should we call UpdateStatus()?
72-
ctrState := ctr.State()
72+
ctrState := ctr.StateNoLock()
7373
if ctrState == nil {
7474
return types.ContainerInfo{}, errCtrStateNil
7575
}
@@ -79,7 +79,7 @@ func (s *Server) getContainerInfo(ctx context.Context, id string, getContainerFu
7979
return types.ContainerInfo{}, errSandboxNotFound
8080
}
8181

82-
pidToReturn := ctrState.Pid
82+
pidToReturn := ctrState.InitPid
8383
if isInfra && pidToReturn == 0 {
8484
// It is possible the infra container doesn't report a PID.
8585
// That can either happen if we're using a vm based runtime,

server/inspect_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,9 @@ func TestGetContainerInfo(t *testing.T) {
5656
}
5757
container.SetMountPoint("/var/foo/container")
5858
cstate := &oci.ContainerState{}
59-
cstate.State = specs.State{
60-
Pid: 42,
61-
}
59+
cstate.State = specs.State{}
6260
cstate.Created = created
63-
container.SetState(cstate)
61+
container.SetStateAndSpoofPid(cstate)
6462
return container
6563
}
6664
getInfraContainerFunc := func(ctx context.Context, id string) *oci.Container {
@@ -78,8 +76,8 @@ func TestGetContainerInfo(t *testing.T) {
7876
if ci.CreatedTime != created.UnixNano() {
7977
t.Fatalf("expected same created time %d, got %d", created.UnixNano(), ci.CreatedTime)
8078
}
81-
if ci.Pid != 42 {
82-
t.Fatalf("expected pid 42, got %v", ci.Pid)
79+
if ci.Pid != 1 {
80+
t.Fatalf("expected pid 1, got %v", ci.Pid)
8381
}
8482
if ci.Name != "testname" {
8583
t.Fatalf("expected name testname, got %s", ci.Name)

0 commit comments

Comments
 (0)