Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

Commit aee8f28

Browse files
authored
Merge pull request #2742 from amshinde/mystable-1.11
Backports for log fixes
2 parents bd0e55e + a74e194 commit aee8f28

4 files changed

Lines changed: 67 additions & 30 deletions

File tree

virtcontainers/api.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/kata-containers/runtime/virtcontainers/persist"
1717
"github.com/kata-containers/runtime/virtcontainers/pkg/compatoci"
1818
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
19+
"github.com/kata-containers/runtime/virtcontainers/store"
1920
"github.com/kata-containers/runtime/virtcontainers/types"
2021
specs "github.com/opencontainers/runtime-spec/specs-go"
2122
opentracing "github.com/opentracing/opentracing-go"
@@ -50,6 +51,8 @@ func SetLogger(ctx context.Context, logger *logrus.Entry) {
5051

5152
deviceApi.SetLogger(virtLog)
5253
compatoci.SetLogger(virtLog)
54+
store.SetLogger(virtLog)
55+
deviceConfig.SetLogger(virtLog)
5356
}
5457

5558
// CreateSandbox is the virtcontainers sandbox creation entry point.

virtcontainers/device/config/pmem.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ var (
2929
pmemLog = logrus.WithField("source", "virtcontainers/device/config")
3030
)
3131

32+
// SetLogger sets up a logger for this pkg
33+
func SetLogger(logger *logrus.Entry) {
34+
fields := pmemLog.Data
35+
36+
pmemLog = logger.WithFields(fields)
37+
}
38+
3239
// PmemDeviceInfo returns a DeviceInfo if a loop device
3340
// is mounted on source, and the backing file of the loop device
3441
// has the PFN signature.

virtcontainers/kata_agent.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,22 +1130,32 @@ func (k *kataAgent) constraintGRPCSpec(grpcSpec *grpc.Spec, passSeccomp bool) {
11301130
grpcSpec.Linux.Devices = linuxDevices
11311131
}
11321132

1133-
func (k *kataAgent) handleShm(grpcSpec *grpc.Spec, sandbox *Sandbox) {
1134-
for idx, mnt := range grpcSpec.Mounts {
1133+
func (k *kataAgent) handleShm(mounts []specs.Mount, sandbox *Sandbox) {
1134+
for idx, mnt := range mounts {
11351135
if mnt.Destination != "/dev/shm" {
11361136
continue
11371137
}
11381138

1139+
// If /dev/shm for a container is backed by an ephemeral volume, skip
1140+
// bind-mounting it to the sandbox shm.
1141+
// A later call to handleEphemeralStorage should take care of setting up /dev/shm correctly.
1142+
if mnt.Type == KataEphemeralDevType {
1143+
continue
1144+
}
1145+
1146+
// A container shm mount is shared with sandbox shm mount.
11391147
if sandbox.shmSize > 0 {
1140-
grpcSpec.Mounts[idx].Type = "bind"
1141-
grpcSpec.Mounts[idx].Options = []string{"rbind"}
1142-
grpcSpec.Mounts[idx].Source = filepath.Join(kataGuestSandboxDir(), shmDir)
1148+
mounts[idx].Type = "bind"
1149+
mounts[idx].Options = []string{"rbind"}
1150+
mounts[idx].Source = filepath.Join(kataGuestSandboxDir(), shmDir)
11431151
k.Logger().WithField("shm-size", sandbox.shmSize).Info("Using sandbox shm")
11441152
} else {
1153+
// This should typically not happen, as a sandbox shm mount is always set up by the
1154+
// upper stack.
11451155
sizeOption := fmt.Sprintf("size=%d", DefaultShmSize)
1146-
grpcSpec.Mounts[idx].Type = "tmpfs"
1147-
grpcSpec.Mounts[idx].Source = "shm"
1148-
grpcSpec.Mounts[idx].Options = []string{"noexec", "nosuid", "nodev", "mode=1777", sizeOption}
1156+
mounts[idx].Type = "tmpfs"
1157+
mounts[idx].Source = "shm"
1158+
mounts[idx].Options = []string{"noexec", "nosuid", "nodev", "mode=1777", sizeOption}
11491159
k.Logger().WithField("shm-size", sizeOption).Info("Setting up a separate shm for container")
11501160
}
11511161
}
@@ -1382,6 +1392,8 @@ func (k *kataAgent) createContainer(sandbox *Sandbox, c *Container) (p *Process,
13821392
return nil, err
13831393
}
13841394

1395+
k.handleShm(ociSpec.Mounts, sandbox)
1396+
13851397
epheStorages := k.handleEphemeralStorage(ociSpec.Mounts)
13861398
ctrStorages = append(ctrStorages, epheStorages...)
13871399

@@ -1432,8 +1444,6 @@ func (k *kataAgent) createContainer(sandbox *Sandbox, c *Container) (p *Process,
14321444
// irrelevant information to the agent.
14331445
k.constraintGRPCSpec(grpcSpec, passSeccomp)
14341446

1435-
k.handleShm(grpcSpec, sandbox)
1436-
14371447
req := &grpc.CreateContainerRequest{
14381448
ContainerId: c.id,
14391449
ExecId: c.id,

virtcontainers/kata_agent_test.go

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -664,33 +664,50 @@ func TestHandleShm(t *testing.T) {
664664
shmSize: 8192,
665665
}
666666

667-
g := &pb.Spec{
668-
Hooks: &pb.Hooks{},
669-
Mounts: []pb.Mount{
670-
{Destination: "/dev/shm"},
671-
},
667+
var ociMounts []specs.Mount
668+
669+
mount := specs.Mount{
670+
Type: "bind",
671+
Destination: "/dev/shm",
672672
}
673673

674-
k.handleShm(g, sandbox)
674+
ociMounts = append(ociMounts, mount)
675+
k.handleShm(ociMounts, sandbox)
675676

676-
assert.Len(g.Mounts, 1)
677-
assert.NotEmpty(g.Mounts[0].Destination)
678-
assert.Equal(g.Mounts[0].Destination, "/dev/shm")
679-
assert.Equal(g.Mounts[0].Type, "bind")
680-
assert.NotEmpty(g.Mounts[0].Source, filepath.Join(kataGuestSharedDir(), shmDir))
681-
assert.Equal(g.Mounts[0].Options, []string{"rbind"})
677+
assert.Len(ociMounts, 1)
678+
assert.NotEmpty(ociMounts[0].Destination)
679+
assert.Equal(ociMounts[0].Destination, "/dev/shm")
680+
assert.Equal(ociMounts[0].Type, "bind")
681+
assert.NotEmpty(ociMounts[0].Source, filepath.Join(kataGuestSharedDir(), shmDir))
682+
assert.Equal(ociMounts[0].Options, []string{"rbind"})
682683

683684
sandbox.shmSize = 0
684-
k.handleShm(g, sandbox)
685-
686-
assert.Len(g.Mounts, 1)
687-
assert.NotEmpty(g.Mounts[0].Destination)
688-
assert.Equal(g.Mounts[0].Destination, "/dev/shm")
689-
assert.Equal(g.Mounts[0].Type, "tmpfs")
690-
assert.Equal(g.Mounts[0].Source, "shm")
685+
k.handleShm(ociMounts, sandbox)
691686

687+
assert.Len(ociMounts, 1)
688+
assert.Equal(ociMounts[0].Destination, "/dev/shm")
689+
assert.Equal(ociMounts[0].Type, "tmpfs")
690+
assert.Equal(ociMounts[0].Source, "shm")
692691
sizeOption := fmt.Sprintf("size=%d", DefaultShmSize)
693-
assert.Equal(g.Mounts[0].Options, []string{"noexec", "nosuid", "nodev", "mode=1777", sizeOption})
692+
assert.Equal(ociMounts[0].Options, []string{"noexec", "nosuid", "nodev", "mode=1777", sizeOption})
693+
694+
// In case the type of mount is ephemeral, the container mount is not
695+
// shared with the sandbox shm.
696+
ociMounts[0].Type = KataEphemeralDevType
697+
mountSource := "/tmp/mountPoint"
698+
ociMounts[0].Source = mountSource
699+
k.handleShm(ociMounts, sandbox)
700+
701+
assert.Len(ociMounts, 1)
702+
assert.Equal(ociMounts[0].Type, KataEphemeralDevType)
703+
assert.NotEmpty(ociMounts[0].Source, mountSource)
704+
705+
epheStorages := k.handleEphemeralStorage(ociMounts)
706+
epheMountPoint := epheStorages[0].GetMountPoint()
707+
expected := filepath.Join(ephemeralPath(), filepath.Base(mountSource))
708+
assert.Equal(epheMountPoint, expected,
709+
"Ephemeral mount point didn't match: got %s, expecting %s", epheMountPoint, expected)
710+
694711
}
695712

696713
func testIsPidNamespacePresent(grpcSpec *pb.Spec) bool {

0 commit comments

Comments
 (0)