mirror of
https://github.com/aljazceru/kata-containers.git
synced 2025-12-18 23:04:20 +01:00
shm: handle shm mount backed by empty-dir memory volumes
[cherry picked from runtime commit 3c4fe035e8041b44e1f3e06d5247938be9a1db15] Check if shm mount is backed by empty-dir memory based volume. If so let the logic to handle epehemeral volumes take care of this mount, so that shm mount within the container is backed by tmpfs mount within the the container in the VM. Fixes: #323 Signed-off-by: Archana Shinde <archana.m.shinde@intel.com> Signed-off-by: Peng Tao <bergwolf@hyper.sh>
This commit is contained in:
@@ -663,33 +663,50 @@ func TestHandleShm(t *testing.T) {
|
||||
shmSize: 8192,
|
||||
}
|
||||
|
||||
g := &pb.Spec{
|
||||
Hooks: &pb.Hooks{},
|
||||
Mounts: []pb.Mount{
|
||||
{Destination: "/dev/shm"},
|
||||
},
|
||||
var ociMounts []specs.Mount
|
||||
|
||||
mount := specs.Mount{
|
||||
Type: "bind",
|
||||
Destination: "/dev/shm",
|
||||
}
|
||||
|
||||
k.handleShm(g, sandbox)
|
||||
ociMounts = append(ociMounts, mount)
|
||||
k.handleShm(ociMounts, sandbox)
|
||||
|
||||
assert.Len(g.Mounts, 1)
|
||||
assert.NotEmpty(g.Mounts[0].Destination)
|
||||
assert.Equal(g.Mounts[0].Destination, "/dev/shm")
|
||||
assert.Equal(g.Mounts[0].Type, "bind")
|
||||
assert.NotEmpty(g.Mounts[0].Source, filepath.Join(kataGuestSharedDir(), shmDir))
|
||||
assert.Equal(g.Mounts[0].Options, []string{"rbind"})
|
||||
assert.Len(ociMounts, 1)
|
||||
assert.NotEmpty(ociMounts[0].Destination)
|
||||
assert.Equal(ociMounts[0].Destination, "/dev/shm")
|
||||
assert.Equal(ociMounts[0].Type, "bind")
|
||||
assert.NotEmpty(ociMounts[0].Source, filepath.Join(kataGuestSharedDir(), shmDir))
|
||||
assert.Equal(ociMounts[0].Options, []string{"rbind"})
|
||||
|
||||
sandbox.shmSize = 0
|
||||
k.handleShm(g, sandbox)
|
||||
|
||||
assert.Len(g.Mounts, 1)
|
||||
assert.NotEmpty(g.Mounts[0].Destination)
|
||||
assert.Equal(g.Mounts[0].Destination, "/dev/shm")
|
||||
assert.Equal(g.Mounts[0].Type, "tmpfs")
|
||||
assert.Equal(g.Mounts[0].Source, "shm")
|
||||
k.handleShm(ociMounts, sandbox)
|
||||
|
||||
assert.Len(ociMounts, 1)
|
||||
assert.Equal(ociMounts[0].Destination, "/dev/shm")
|
||||
assert.Equal(ociMounts[0].Type, "tmpfs")
|
||||
assert.Equal(ociMounts[0].Source, "shm")
|
||||
sizeOption := fmt.Sprintf("size=%d", DefaultShmSize)
|
||||
assert.Equal(g.Mounts[0].Options, []string{"noexec", "nosuid", "nodev", "mode=1777", sizeOption})
|
||||
assert.Equal(ociMounts[0].Options, []string{"noexec", "nosuid", "nodev", "mode=1777", sizeOption})
|
||||
|
||||
// In case the type of mount is ephemeral, the container mount is not
|
||||
// shared with the sandbox shm.
|
||||
ociMounts[0].Type = KataEphemeralDevType
|
||||
mountSource := "/tmp/mountPoint"
|
||||
ociMounts[0].Source = mountSource
|
||||
k.handleShm(ociMounts, sandbox)
|
||||
|
||||
assert.Len(ociMounts, 1)
|
||||
assert.Equal(ociMounts[0].Type, KataEphemeralDevType)
|
||||
assert.NotEmpty(ociMounts[0].Source, mountSource)
|
||||
|
||||
epheStorages := k.handleEphemeralStorage(ociMounts)
|
||||
epheMountPoint := epheStorages[0].MountPoint
|
||||
expected := filepath.Join(ephemeralPath(), filepath.Base(mountSource))
|
||||
assert.Equal(epheMountPoint, expected,
|
||||
"Ephemeral mount point didn't match: got %s, expecting %s", epheMountPoint, expected)
|
||||
|
||||
}
|
||||
|
||||
func testIsPidNamespacePresent(grpcSpec *pb.Spec) bool {
|
||||
|
||||
Reference in New Issue
Block a user