From dd0d35deb098b63f8c5be7ef9d8d63c16760221b Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Wed, 10 Jan 2018 15:58:18 -0500 Subject: Add support for shm-size. Signed-off-by: Daniel J Walsh Closes: #206 Approved by: TomSweeneyRedHat --- cmd/podman/common.go | 3 ++- cmd/podman/create.go | 11 +++++++++-- cmd/podman/inspect.go | 2 +- cmd/podman/run.go | 1 + cmd/podman/spec.go | 18 +++++++++++++++--- 5 files changed, 28 insertions(+), 7 deletions(-) (limited to 'cmd') diff --git a/cmd/podman/common.go b/cmd/podman/common.go index e3997539a..e0ef43782 100644 --- a/cmd/podman/common.go +++ b/cmd/podman/common.go @@ -377,7 +377,8 @@ var createFlags = []cli.Flag{ }, cli.StringFlag{ Name: "shm-size", - Usage: "Size of `/dev/shm`. The format is ``. default is 64 MB", + Usage: "Size of `/dev/shm`. The format is ``.", + Value: "65536k", }, cli.BoolFlag{ Name: "sig-proxy", diff --git a/cmd/podman/create.go b/cmd/podman/create.go index bb9a31467..ce06ac51b 100644 --- a/cmd/podman/create.go +++ b/cmd/podman/create.go @@ -62,7 +62,7 @@ type createResourceConfig struct { MemorySwappiness int // memory-swappiness OomScoreAdj int //oom-score-adj PidsLimit int64 // pids-limit - ShmSize string + ShmSize int64 Ulimit []string //ulimit } @@ -179,6 +179,7 @@ func createCmd(c *cli.Context) error { options = append(options, libpod.WithLabels(createConfig.Labels)) options = append(options, libpod.WithUser(createConfig.User)) options = append(options, libpod.WithShmDir(createConfig.ShmDir)) + options = append(options, libpod.WithShmSize(createConfig.Resources.ShmSize)) ctr, err := runtime.NewContainer(runtimeSpec, options...) if err != nil { return err @@ -524,6 +525,12 @@ func parseCreateOpts(c *cli.Context, runtime *libpod.Runtime) (*createConfig, er return nil, err } + // SHM SIze + shmSize, err := units.FromHumanSize(c.String("shm-size")) + if err != nil { + return nil, errors.Wrapf(err, "unable to translate --shm-size") + } + config := &createConfig{ Runtime: runtime, CapAdd: c.StringSlice("cap-add"), @@ -580,7 +587,7 @@ func parseCreateOpts(c *cli.Context, runtime *libpod.Runtime) (*createConfig, er DeviceWriteBps: c.StringSlice("device-write-bps"), DeviceWriteIOps: c.StringSlice("device-write-iops"), DisableOomKiller: c.Bool("oom-kill-disable"), - ShmSize: c.String("shm-size"), + ShmSize: shmSize, Memory: memoryLimit, MemoryReservation: memoryReservation, MemorySwap: memorySwap, diff --git a/cmd/podman/inspect.go b/cmd/podman/inspect.go index dc5810492..5e9fc53bb 100644 --- a/cmd/podman/inspect.go +++ b/cmd/podman/inspect.go @@ -320,7 +320,7 @@ type HostConfig struct { SecurityOpt []string `json:"SecurityOpt"` UTSMode string `json:"UTSMode"` UsernsMode string `json:"UsernsMode"` - ShmSize string `json:"ShmSize"` + ShmSize int64 `json:"ShmSize"` Runtime string `json:"Runtime"` ConsoleSize *specs.Box `json:"ConsoleSize"` Isolation string `json:"Isolation"` //TODO diff --git a/cmd/podman/run.go b/cmd/podman/run.go index 45a428f39..07af4a6a2 100644 --- a/cmd/podman/run.go +++ b/cmd/podman/run.go @@ -56,6 +56,7 @@ func runCmd(c *cli.Context) error { options = append(options, libpod.WithLabels(createConfig.Labels)) options = append(options, libpod.WithUser(createConfig.User)) options = append(options, libpod.WithShmDir(createConfig.ShmDir)) + options = append(options, libpod.WithShmSize(createConfig.Resources.ShmSize)) ctr, err := runtime.NewContainer(runtimeSpec, options...) if err != nil { return err diff --git a/cmd/podman/spec.go b/cmd/podman/spec.go index 342b80d9e..d630b2f50 100644 --- a/cmd/podman/spec.go +++ b/cmd/podman/spec.go @@ -189,7 +189,13 @@ func addDevice(g *generate.Generator, device string) error { // Parses information needed to create a container into an OCI runtime spec func createConfigToOCISpec(config *createConfig) (*spec.Spec, error) { g := generate.New() - g.AddCgroupsMount("ro") + cgroupMnt := spec.Mount{ + Destination: "/sys/fs/cgroup", + Type: "cgroup", + Source: "cgroup", + Options: []string{"nosuid", "noexec", "nodev", "relatime", "ro"}, + } + g.AddMount(cgroupMnt) g.SetProcessCwd(config.WorkDir) g.SetProcessArgs(config.Command) g.SetProcessTerminal(config.Tty) @@ -273,6 +279,7 @@ func createConfigToOCISpec(config *createConfig) (*spec.Spec, error) { } for _, i := range config.Tmpfs { + // Default options if nothing passed options := []string{"rw", "noexec", "nosuid", "nodev", "size=65536k"} spliti := strings.SplitN(i, ":", 2) if len(spliti) > 1 { @@ -281,8 +288,13 @@ func createConfigToOCISpec(config *createConfig) (*spec.Spec, error) { } options = strings.Split(spliti[1], ",") } - // Default options if nothing passed - g.AddTmpfsMount(spliti[0], append(options, "tmpcopyup")) + tmpfsMnt := spec.Mount{ + Destination: spliti[0], + Type: "tmpfs", + Source: "tmpfs", + Options: append(options, "tmpcopyup"), + } + g.AddMount(tmpfsMnt) } for name, val := range config.Env { -- cgit v1.2.3-54-g00ecf