Skip to content
This repository has been archived by the owner on Apr 3, 2018. It is now read-only.

Commit

Permalink
mounts: Deduce additional information about system mounts
Browse files Browse the repository at this point in the history
We need to pass information about mounts that need special
handling inside the VM to the agent. Deduce all the information
before the container is started by the agent.

Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
  • Loading branch information
amshinde committed Dec 19, 2017
1 parent 2687abf commit bdc815d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
29 changes: 29 additions & 0 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ func (c *ContainerConfig) valid() bool {
return true
}

// SystemMountsInfo describes additional information for system mounts that the agent
// needs to handle
type SystemMountsInfo struct {
// Indicates if /dev has been passed as a bind mount for the host /dev
BindMountDev bool

// Size of /dev/shm assigned on the host.
DevShmSize uint
}

// Container is composed of a set of containers and a runtime environment.
// A Container can be created, deleted, started, stopped, listed, entered, paused and restored.
type Container struct {
Expand All @@ -122,6 +132,8 @@ type Container struct {
mounts []Mount

devices []Device

systemMountsInfo SystemMountsInfo
}

// ID returns the container identifier string.
Expand Down Expand Up @@ -482,6 +494,19 @@ func (c *Container) fetchState(cmd string) (State, error) {
return state, nil
}

func (c *Container) getSystemMountInfo() {
// check if /dev needs to be bind mounted from host /dev
for _, m := range c.mounts {
if m.Source == "/dev" && m.Destination == "/dev" && m.Type == "bind" {
c.systemMountsInfo.BindMountDev = true
} else {
c.systemMountsInfo.BindMountDev = false
}
}

// TODO Deduce /dev/shm size. See https://github.com/clearcontainers/runtime/issues/138
}

func (c *Container) start() error {
state, err := c.fetchState("start")
if err != nil {
Expand Down Expand Up @@ -519,6 +544,10 @@ func (c *Container) start() error {
return err
}

// Deduce additional system mount info that should be handled by the agent
// inside the VM
c.getSystemMountInfo()

if err = c.pod.agent.startContainer(*(c.pod), *c); err != nil {
c.Logger().WithError(err).Error("Failed to start container")

Expand Down
24 changes: 24 additions & 0 deletions container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"strings"
"syscall"
"testing"

"github.com/stretchr/testify/assert"
)

func TestGetAnnotations(t *testing.T) {
Expand All @@ -49,6 +51,28 @@ func TestGetAnnotations(t *testing.T) {
}
}

func TestContainerSystemMountsInfo(t *testing.T) {
mounts := []Mount{
{
Source: "/dev",
Destination: "/dev",
Type: "bind",
},
}

c := Container{
mounts: mounts,
}

assert.False(t, c.systemMountsInfo.BindMountDev)
c.getSystemMountInfo()
assert.True(t, c.systemMountsInfo.BindMountDev)

c.mounts[0].Type = "tmpfs"
c.getSystemMountInfo()
assert.False(t, c.systemMountsInfo.BindMountDev)
}

func TestContainerPod(t *testing.T) {
expectedPod := &Pod{}

Expand Down

0 comments on commit bdc815d

Please sign in to comment.